Changeset 11225 for sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-learn/inc/post-meta.php
- Timestamp:
- 09/10/2021 10:25:05 PM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-learn/inc/post-meta.php
r10926 r11225 6 6 use WP_Post; 7 7 use function WordPressdotorg\Locales\{ get_locales_with_english_names }; 8 use function WPOrg_Learn\ get_views_path;8 use function WPOrg_Learn\{ get_build_path, get_build_url, get_views_path }; 9 9 use function WPOrg_Learn\Form\get_workshop_application_field_schema; 10 10 … … 19 19 add_action( 'save_post_lesson-plan', __NAMESPACE__ . '\save_lesson_plan_metabox_fields' ); 20 20 add_action( 'save_post_wporg_workshop', __NAMESPACE__ . '\save_workshop_metabox_fields' ); 21 add_action( 'enqueue_block_editor_assets', __NAMESPACE__ . '\enqueue_editor_assets' ); 21 22 22 23 /** … … 26 27 register_lesson_plan_meta(); 27 28 register_workshop_meta(); 29 register_misc_meta(); 28 30 } 29 31 … … 139 141 ) 140 142 ); 143 } 144 145 /** 146 * Register other post meta keys. 147 * 148 * For multiple post types, for example. 149 */ 150 function register_misc_meta() { 151 // Expiration field. 152 $post_types = array( 'lesson-plan', 'wporg_workshop', 'course', 'lesson' ); 153 foreach ( $post_types as $post_type ) { 154 register_post_meta( 155 $post_type, 156 'expiration_date', 157 array( 158 'description' => __( 'The date when the content of the post may be obsolete.', 'wporg_learn' ), 159 'type' => 'string', 160 'single' => true, 161 'sanitize_callback' => function( $value ) { 162 return filter_var( $value, FILTER_SANITIZE_STRING ); 163 }, 164 'show_in_rest' => true, 165 ) 166 ); 167 } 141 168 } 142 169 … … 431 458 } 432 459 } 460 461 /** 462 * Enqueue scripts for the block editor. 463 */ 464 function enqueue_editor_assets() { 465 global $typenow; 466 467 $post_types_with_expiration = array( 'lesson-plan', 'wporg_workshop', 'course', 'lesson' ); 468 if ( in_array( $typenow, $post_types_with_expiration, true ) ) { 469 $script_asset_path = get_build_path() . 'expiration-date.asset.php'; 470 if ( ! file_exists( $script_asset_path ) ) { 471 wp_die( 'You need to run `yarn start` or `yarn build` to build the required assets.' ); 472 } 473 474 $script_asset = require( $script_asset_path ); 475 wp_enqueue_script( 476 'wporg-learn-expiration-date', 477 get_build_url() . 'expiration-date.js', 478 $script_asset['dependencies'], 479 $script_asset['version'], 480 true 481 ); 482 483 wp_set_script_translations( 'wporg-learn-expiration-date', 'wporg-learn' ); 484 } 485 }
Note: See TracChangeset
for help on using the changeset viewer.