Changeset 14012 for sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-learn/inc/post-meta.php
- Timestamp:
- 09/01/2024 11:46:40 PM (17 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-learn/inc/post-meta.php
r13981 r14012 23 23 add_action( 'admin_footer', __NAMESPACE__ . '\render_locales_list' ); 24 24 add_action( 'enqueue_block_editor_assets', __NAMESPACE__ . '\enqueue_editor_assets' ); 25 add_action( 'wp_insert_post', __NAMESPACE__ . '\set_default_lesson_preview', 10, 3 ); 25 26 26 27 /** … … 52 53 ), 53 54 ); 55 } 56 57 /** 58 * Set public preview to be enabled on lessons created within a course by default. 59 * This post meta is registered by Sensei with no default value, so we set it here on lesson creation. 60 * 61 * @param int $post_ID Post ID. 62 * @param WP_Post $post Post object. 63 * @param bool $update Whether this is an existing post being updated. 64 */ 65 function set_default_lesson_preview( $post_ID, $post, $update ) { 66 // Only run for new lessons. 67 if ( $update || 'lesson' !== $post->post_type ) { 68 return; 69 } 70 71 // Check if the lesson belongs to a course. 72 $course_id = get_post_meta( $post_ID, '_lesson_course', true ); 73 74 if ( empty( $course_id ) ) { 75 return; 76 } 77 78 $existing_value = get_post_meta( $post_ID, '_lesson_preview', true ); 79 80 if ( '' === $existing_value ) { 81 update_post_meta( $post_ID, '_lesson_preview', 'preview' ); 82 } 54 83 } 55 84
Note: See TracChangeset
for help on using the changeset viewer.