Changeset 10458 for sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-learn/inc/post-meta.php
- Timestamp:
- 11/20/2020 12:07:27 AM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-learn/inc/post-meta.php
r10376 r10458 15 15 */ 16 16 add_action( 'init', __NAMESPACE__ . '\register' ); 17 add_action( 'add_meta_boxes', __NAMESPACE__ . '\add_lesson_plan_metaboxes' ); 17 18 add_action( 'add_meta_boxes', __NAMESPACE__ . '\add_workshop_metaboxes' ); 18 add_action( 'save_post_wporg_workshop', __NAMESPACE__ . '\save_workshop_metabox_fields', 10, 2 ); 19 add_action( 'save_post_lesson-plan', __NAMESPACE__ . '\save_lesson_plan_metabox_fields' ); 20 add_action( 'save_post_wporg_workshop', __NAMESPACE__ . '\save_workshop_metabox_fields' ); 19 21 20 22 /** … … 22 24 */ 23 25 function register() { 26 register_lesson_plan_meta(); 24 27 register_workshop_meta(); 28 } 29 30 /** 31 * Register post meta keys for lesson plans. 32 */ 33 function 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 ); 25 61 } 26 62 … … 189 225 190 226 /** 227 * Add meta boxes to the Edit Lesson Plan screen. 228 * 229 * Todo these should be replaced with block editor panels. 230 */ 231 function 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 */ 246 function 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 */ 256 function 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 /** 191 275 * Add meta boxes to the Edit Workshop screen. 192 276 * … … 261 345 * Update the post meta values from the meta box fields when the post is saved. 262 346 * 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 */ 349 function save_workshop_metabox_fields( $post_id ) { 267 350 if ( wp_is_post_revision( $post_id ) || ! current_user_can( 'edit_post', $post_id ) ) { 268 351 return;
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)