Making WordPress.org


Ignore:
Timestamp:
11/20/2020 12:07:27 AM (6 years ago)
Author:
coreymckrill
Message:

WordPress.org Learn: Sync with GitHub

​https://github.com/WordPress/learn/compare/a6529c2090ca8a1dcc9e36e27460f6cbb84e02ef...2c9bbc5fc4eefb1f1a367f7bb8afcd3da6ef32b0

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-learn/inc/post-meta.php

    r10376 r10458  
    1515 */
    1616add_action( 'init', __NAMESPACE__ . '\register' );
     17add_action( 'add_meta_boxes', __NAMESPACE__ . '\add_lesson_plan_metaboxes' );
    1718add_action( 'add_meta_boxes', __NAMESPACE__ . '\add_workshop_metaboxes' );
    18 add_action( 'save_post_wporg_workshop', __NAMESPACE__ . '\save_workshop_metabox_fields', 10, 2 );
     19add_action( 'save_post_lesson-plan', __NAMESPACE__ . '\save_lesson_plan_metabox_fields' );
     20add_action( 'save_post_wporg_workshop', __NAMESPACE__ . '\save_workshop_metabox_fields' );
    1921
    2022/**
    … …  
    2224 */
    2325function register() {
     26        register_lesson_plan_meta();
    2427        register_workshop_meta();
     28}
     29
     30/**
     31 * Register post meta keys for lesson plans.
     32 */
     33function register_lesson_plan_meta() {
     34        $post_type = 'lesson-plan';
     35
     36        register_post_meta(
     37                $post_type,
     38                'slides_view_url',
     39                array(
     40                        'description'       => __( 'A URL for viewing lesson plan slides.', 'wporg_learn' ),
     41                        'type'              => 'string',
     42                        'single'            => true,
     43                        'default'           => '',
     44                        'sanitize_callback' => 'esc_url_raw',
     45                        'show_in_rest'      => true,
     46                )
     47        );
     48
     49        register_post_meta(
     50                $post_type,
     51                'slides_download_url',
     52                array(
     53                        'description'       => __( 'A URL for downloading lesson plan slides.', 'wporg_learn' ),
     54                        'type'              => 'string',
     55                        'single'            => true,
     56                        'default'           => '',
     57                        'sanitize_callback' => 'esc_url_raw',
     58                        'show_in_rest'      => true,
     59                )
     60        );
    2561}
    2662
    … …  
    189225
    190226/**
     227 * Add meta boxes to the Edit Lesson Plan screen.
     228 *
     229 * Todo these should be replaced with block editor panels.
     230 */
     231function add_lesson_plan_metaboxes() {
     232        add_meta_box(
     233                'lesson-plan-slides',
     234                __( 'Slides', 'wporg_learn' ),
     235                __NAMESPACE__ . '\render_metabox_lesson_plan_slides',
     236                'lesson-plan',
     237                'side'
     238        );
     239}
     240
     241/**
     242 * Render the Lesson Plan Slides metabox.
     243 *
     244 * @param WP_Post $post
     245 */
     246function render_metabox_lesson_plan_slides( WP_Post $post ) {
     247        // The $post var is used in the include file.
     248        require get_views_path() . 'metabox-lesson-plan-slides.php';
     249}
     250
     251/**
     252 * Update the post meta values from the meta box fields when the post is saved.
     253 *
     254 * @param int $post_id
     255 */
     256function save_lesson_plan_metabox_fields( $post_id ) {
     257        if ( wp_is_post_revision( $post_id ) || ! current_user_can( 'edit_post', $post_id ) ) {
     258                return;
     259        }
     260
     261        // This nonce field is rendered in the Lesson Plan Slides metabox.
     262        $nonce = filter_input( INPUT_POST, 'lesson-plan-metabox-nonce' );
     263        if ( ! wp_verify_nonce( $nonce, 'lesson-plan-metaboxes' ) ) {
     264                return;
     265        }
     266
     267        $view_url = filter_input( INPUT_POST, 'slides-view-url', FILTER_VALIDATE_URL ) ?: '';
     268        update_post_meta( $post_id, 'slides_view_url', $view_url );
     269
     270        $download_url = filter_input( INPUT_POST, 'slides-download-url', FILTER_VALIDATE_URL ) ?: '';
     271        update_post_meta( $post_id, 'slides_download_url', $download_url );
     272}
     273
     274/**
    191275 * Add meta boxes to the Edit Workshop screen.
    192276 *
    … …  
    261345 * Update the post meta values from the meta box fields when the post is saved.
    262346 *
    263  * @param int     $post_id
    264  * @param WP_Post $post
    265  */
    266 function save_workshop_metabox_fields( $post_id, WP_Post $post ) {
     347 * @param int $post_id
     348 */
     349function save_workshop_metabox_fields( $post_id ) {
    267350        if ( wp_is_post_revision( $post_id ) || ! current_user_can( 'edit_post', $post_id ) ) {
    268351                return;
Note: See TracChangeset for help on using the changeset viewer.