Changeset 12174
- Timestamp:
- 11/01/2022 02:36:20 AM (18 months ago)
- Location:
- sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-learn
- Files:
-
- 5 added
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-learn/inc/admin.php
r11772 r12174 4 4 5 5 use WP_Query; 6 use function WordPressdotorg\Locales\get_locales_with_english_names; 6 7 use function WordPressdotorg\Locales\get_locale_name_from_code; 7 8 use function WPOrg_Learn\Post_Meta\get_available_workshop_locales; … … 14 15 add_action( 'admin_notices', __NAMESPACE__ . '\show_term_translation_notice' ); 15 16 add_filter( 'manage_wporg_workshop_posts_columns', __NAMESPACE__ . '\add_workshop_list_table_columns' ); 17 foreach ( array( 'lesson-plan', 'meeting', 'course', 'lesson' ) as $pt ) { 18 add_filter( 'manage_' . $pt . '_posts_columns', __NAMESPACE__ . '\add_list_table_language_column' ); 19 } 16 20 add_action( 'manage_wporg_workshop_posts_custom_column', __NAMESPACE__ . '\render_workshop_list_table_columns', 10, 2 ); 21 foreach ( array( 'lesson-plan', 'meeting', 'course', 'lesson' ) as $pt ) { 22 add_filter( 'manage_' . $pt . '_posts_custom_column', __NAMESPACE__ . '\render_list_table_language_column', 10, 2 ); 23 } 17 24 add_filter( 'manage_edit-wporg_workshop_sortable_columns', __NAMESPACE__ . '\add_workshop_list_table_sortable_columns' ); 18 25 add_action( 'restrict_manage_posts', __NAMESPACE__ . '\add_workshop_list_table_filters', 10, 2 ); … … 23 30 } 24 31 add_action( 'pre_get_posts', __NAMESPACE__ . '\handle_list_table_views' ); 32 add_action( 'bulk_edit_custom_box', __NAMESPACE__ . '\add_language_bulk_edit_field', 10, 2 ); 33 add_action( 'save_post', __NAMESPACE__ . '\language_bulk_edit_save' ); 25 34 26 35 /** … … 80 89 function add_workshop_list_table_columns( $columns ) { 81 90 $columns = array_slice( $columns, 0, -2, true ) 82 + array( 'video_language' => __( ' Language', 'wporg-learn' ) )91 + array( 'video_language' => __( 'Video Language', 'wporg-learn' ) ) 83 92 + array( 'video_caption_language' => __( 'Subtitles', 'wporg-learn' ) ) 93 + array( 'language' => __( 'Language', 'wporg-learn' ) ) 94 + array_slice( $columns, -2, 2, true ); 95 96 return $columns; 97 } 98 99 /** 100 * Add a language column to the post list table. 101 * 102 * @param array $columns 103 * 104 * @return array 105 */ 106 function add_list_table_language_column( $columns ) { 107 $columns = array_slice( $columns, 0, -2, true ) 108 + array( 'language' => __( 'Language', 'wporg-learn' ) ) 84 109 + array_slice( $columns, -2, 2, true ); 85 110 … … 99 124 100 125 switch ( $column_name ) { 126 case 'language': 127 $language = get_post_meta( get_the_ID(), 'language', true ); 128 129 printf( 130 '%s [%s]', 131 esc_html( get_locale_name_from_code( $language, 'english' ) ), 132 esc_html( $language ) 133 ); 134 break; 101 135 case 'video_language': 102 136 printf( … … 123 157 124 158 /** 159 * Render the cell contents for the additional language columns in the post list table. 160 * 161 * @param string $column_name 162 * @param int $post_id 163 * 164 * @return void 165 */ 166 function render_list_table_language_column( $column_name, $post_id ) { 167 $language = get_post_meta( get_the_ID(), 'language', true ); 168 169 if ( 'language' === $column_name ) { 170 printf( 171 '%s [%s]', 172 esc_html( get_locale_name_from_code( $language, 'english' ) ), 173 esc_html( $language ) 174 ); 175 } 176 } 177 178 /** 125 179 * Make additional columns sortable. 126 180 * … … 156 210 </label> 157 211 <select id="filter-by-language" name="language"> 158 <option value=""<?php selected( ! $language ); ?>><?php esc_html_e( 'Any language', 'wporg-learn' ); ?></option>212 <option value=""<?php selected( ! $language ); ?>><?php esc_html_e( 'Any video language', 'wporg-learn' ); ?></option> 159 213 <?php foreach ( $available_locales as $code => $name ) : ?> 160 214 <option value="<?php echo esc_attr( $code ); ?>"<?php selected( $code, $language ); ?>> … … 339 393 } 340 394 } 395 396 /** 397 * Render a field for the additional language meta field on the bulk edit screen. 398 * 399 * @param string $column_name 400 * @param string $post_type 401 * 402 * @return void 403 */ 404 function add_language_bulk_edit_field( $column_name, $post_type ) { 405 $post_types_with_language = array( 'lesson-plan', 'wporg_workshop', 'meeting', 'course', 'lesson' ); 406 if ( in_array( $post_type, $post_types_with_language, true ) && 'language' === $column_name ) { 407 $locales = get_locales_with_english_names(); 408 ?> 409 <fieldset class="inline-edit-col-right"> 410 <div class="inline-edit-group wp-clearfix"> 411 <label class="inline-edit-status alignleft"> 412 <span class="title">Language</span> 413 <select name="language"> 414 <option value="0" selected>— No Change —</option> 415 <?php foreach ( $locales as $code => $label ) : ?> 416 <option value="<?php echo esc_attr( $code ); ?>"> 417 <?php echo esc_html( $label ); ?> 418 </option> 419 <?php endforeach; ?> 420 </select> 421 </label> 422 </div> 423 </fieldset> 424 <?php 425 } 426 } 427 428 /** 429 * Update the language meta field when bulk editing. 430 * 431 * @param int $post_id 432 * 433 * @return void 434 */ 435 function language_bulk_edit_save( $post_id ) { 436 if ( ! wp_verify_nonce( $_REQUEST['_wpnonce'], 'bulk-posts' ) || empty( $_REQUEST['language'] ) ) { 437 return; 438 } 439 440 update_post_meta( $post_id, 'language', $_REQUEST['language'] ); 441 } -
sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-learn/inc/post-meta.php
r11294 r12174 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( 'admin_footer', __NAMESPACE__ . '\render_locales_list' ); 21 22 add_action( 'enqueue_block_editor_assets', __NAMESPACE__ . '\enqueue_editor_assets' ); 22 23 … … 178 179 ); 179 180 } 181 182 // Language field. 183 $post_types = array( 'lesson-plan', 'wporg_workshop', 'meeting', 'course', 'lesson' ); 184 foreach ( $post_types as $post_type ) { 185 register_post_meta( 186 $post_type, 187 'language', 188 array( 189 'description' => __( 'The language for the content.', 'wporg_learn' ), 190 'type' => 'string', 191 'single' => true, 192 'default' => 'en_US', 193 'sanitize_callback' => __NAMESPACE__ . '\sanitize_locale', 194 'show_in_rest' => true, 195 ) 196 ); 197 } 180 198 } 181 199 … … 191 209 */ 192 210 function sanitize_locale( $meta_value, $meta_key, $object_type, $object_subtype ) { 193 if ( 'wporg_workshop' !== $object_subtype ) {194 return $meta_value;195 }196 197 211 $meta_value = trim( $meta_value ); 198 212 $locales = array_keys( get_locales_with_english_names() ); … … 500 514 501 515 /** 516 * Render the locales list for the language meta block. 517 */ 518 function render_locales_list() { 519 global $typenow; 520 521 $post_types_with_language = array( 'lesson-plan', 'wporg_workshop', 'meeting', 'course', 'lesson' ); 522 if ( in_array( $typenow, $post_types_with_language, true ) ) { 523 $locales = get_locales_with_english_names(); 524 525 require get_views_path() . 'locales-list.php'; 526 } 527 } 528 529 /** 502 530 * Enqueue scripts for the block editor. 503 531 */ 504 532 function enqueue_editor_assets() { 533 enqueue_expiration_date_assets(); 534 enqueue_language_meta_assets(); 535 } 536 537 /** 538 * Enqueue scripts for the expiration data block. 539 */ 540 function enqueue_expiration_date_assets() { 505 541 global $typenow; 506 542 … … 524 560 } 525 561 } 562 563 564 /** 565 * Enqueue scripts for the language meta block. 566 */ 567 function enqueue_language_meta_assets() { 568 global $typenow; 569 570 $post_types_with_language = array( 'lesson-plan', 'wporg_workshop', 'meeting', 'course', 'lesson' ); 571 if ( in_array( $typenow, $post_types_with_language, true ) ) { 572 $script_asset_path = get_build_path() . 'language-meta.asset.php'; 573 if ( ! file_exists( $script_asset_path ) ) { 574 wp_die( 'You need to run `yarn start` or `yarn build` to build the required assets.' ); 575 } 576 577 $script_asset = require( $script_asset_path ); 578 wp_enqueue_script( 579 'wporg-learn-language-meta', 580 get_build_url() . 'language-meta.js', 581 $script_asset['dependencies'], 582 $script_asset['version'], 583 true 584 ); 585 586 wp_set_script_translations( 'wporg-learn-language-meta', 'wporg-learn' ); 587 } 588 } -
sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-learn/inc/taxonomy.php
r12067 r12174 22 22 register_lesson_plan_series(); 23 23 register_workshop_series(); 24 register_workshop_topic();25 24 register_workshop_type(); 26 25 register_wp_version(); 27 26 register_included_content(); 27 register_topic(); 28 28 } 29 29 … … 234 234 ); 235 235 236 $args 236 $args = array( 237 237 'labels' => $labels, 238 238 'hierarchical' => true, … … 298 298 299 299 /** 300 * Register the WorkshopSeries taxonomy.300 * Register the Lesson Plan Series taxonomy. 301 301 */ 302 302 function register_lesson_plan_series() { … … 387 387 388 388 /** 389 * Register the WorkshopTopic taxonomy.390 */ 391 function register_ workshop_topic() {392 $labels = array( 393 'name' => _x( 'Topics', 'Topic Plans associated to tutorial.', 'wporg-learn' ),389 * Register the Topic taxonomy. 390 */ 391 function register_topic() { 392 $labels = array( 393 'name' => _x( 'Topics', 'Topics associated with the content.', 'wporg-learn' ), 394 394 'singular_name' => _x( 'Topic', 'Taxonomy Singular Name', 'wporg-learn' ), 395 395 'menu_name' => __( 'Topics', 'wporg-learn' ), … … 411 411 'items_list' => __( 'Topic list', 'wporg-learn' ), 412 412 'items_list_navigation' => __( 'Topic list navigation', 'wporg-learn' ), 413 'back_to_items' => __( '← Back to topics', 'wporg-learn' ), 413 414 ); 414 415 … … 424 425 'show_in_rest' => true, 425 426 'capabilities' => array( 426 'assign_terms' => 'edit_ workshops',427 ), 428 ); 429 430 register_taxonomy( 'topic', array( ' wporg_workshop' ), $args );427 'assign_terms' => 'edit_any_learn_content', // See \WPOrg_Learn\Capabilities\map_meta_caps. 428 ), 429 ); 430 431 register_taxonomy( 'topic', array( 'lesson-plan', 'wporg_workshop', 'course', 'lesson', 'meeting' ), $args ); 431 432 } 432 433 -
sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-learn/package.json
r12130 r12174 15 15 }, 16 16 "dependencies": { 17 "@wordpress/block-editor": "^10.3.0", 18 "@wordpress/blocks": "11.17.0", 17 19 "@wordpress/components": "12.0.5", 20 "@wordpress/core-data": "^5.3.0", 18 21 "@wordpress/data": "4.26.5", 19 22 "@wordpress/date": "4.18.0", 20 "@wordpress/i18n": "3.18.0",21 "@wordpress/url": "3.19.0",22 23 "@wordpress/edit-post": "3.25.3", 23 24 "@wordpress/element": "2.19.1", 25 "@wordpress/i18n": "3.18.0", 24 26 "@wordpress/plugins": "2.24.5", 25 "@wordpress/ blocks": "11.17.0"27 "@wordpress/url": "3.19.0" 26 28 }, 27 29 "devDependencies": { -
sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-learn/views/metabox-workshop-details.php
r11294 r12174 67 67 68 68 <p> 69 <label for="workshop-video-language"><?php esc_html_e( ' Language', 'wporg_learn' ); ?></label>69 <label for="workshop-video-language"><?php esc_html_e( 'Video Language', 'wporg_learn' ); ?></label> 70 70 <select id="workshop-video-language" name="video-language" style="width: 100%;"> 71 71 <?php foreach ( $locales as $code => $label ) : ?> -
sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-learn/webpack.config.js
r12130 r12174 14 14 'lesson-plan-actions': './js/lesson-plan-actions/src/index.js', 15 15 'lesson-plan-details': './js/lesson-plan-details/src/index.js', 16 'language-meta': './js/language-meta/index.js', 16 17 }; 17 18
Note: See TracChangeset
for help on using the changeset viewer.