Making WordPress.org

Changeset 12174


Ignore:
Timestamp:
11/01/2022 02:36:20 AM (18 months ago)
Author:
adamwood
Message:

Learn: Sync with git WordPress/learn@b3bf342

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  
    44
    55use WP_Query;
     6use function WordPressdotorg\Locales\get_locales_with_english_names;
    67use function WordPressdotorg\Locales\get_locale_name_from_code;
    78use function WPOrg_Learn\Post_Meta\get_available_workshop_locales;
     
    1415add_action( 'admin_notices', __NAMESPACE__ . '\show_term_translation_notice' );
    1516add_filter( 'manage_wporg_workshop_posts_columns', __NAMESPACE__ . '\add_workshop_list_table_columns' );
     17foreach ( array( 'lesson-plan', 'meeting', 'course', 'lesson' ) as $pt ) {
     18    add_filter( 'manage_' . $pt . '_posts_columns', __NAMESPACE__ . '\add_list_table_language_column' );
     19}
    1620add_action( 'manage_wporg_workshop_posts_custom_column', __NAMESPACE__ . '\render_workshop_list_table_columns', 10, 2 );
     21foreach ( 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}
    1724add_filter( 'manage_edit-wporg_workshop_sortable_columns', __NAMESPACE__ . '\add_workshop_list_table_sortable_columns' );
    1825add_action( 'restrict_manage_posts', __NAMESPACE__ . '\add_workshop_list_table_filters', 10, 2 );
     
    2330}
    2431add_action( 'pre_get_posts', __NAMESPACE__ . '\handle_list_table_views' );
     32add_action( 'bulk_edit_custom_box', __NAMESPACE__ . '\add_language_bulk_edit_field', 10, 2 );
     33add_action( 'save_post', __NAMESPACE__ . '\language_bulk_edit_save' );
    2534
    2635/**
     
    8089function add_workshop_list_table_columns( $columns ) {
    8190    $columns = array_slice( $columns, 0, -2, true )
    82                 + array( 'video_language' => __( 'Language', 'wporg-learn' ) )
     91                + array( 'video_language' => __( 'Video Language', 'wporg-learn' ) )
    8392                + 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 */
     106function add_list_table_language_column( $columns ) {
     107    $columns = array_slice( $columns, 0, -2, true )
     108                + array( 'language' => __( 'Language', 'wporg-learn' ) )
    84109                + array_slice( $columns, -2, 2, true );
    85110
     
    99124
    100125    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;
    101135        case 'video_language':
    102136            printf(
     
    123157
    124158/**
     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 */
     166function 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/**
    125179 * Make additional columns sortable.
    126180 *
     
    156210    </label>
    157211    <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>
    159213        <?php foreach ( $available_locales as $code => $name ) : ?>
    160214            <option value="<?php echo esc_attr( $code ); ?>"<?php selected( $code, $language ); ?>>
     
    339393    }
    340394}
     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 */
     404function 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 */
     435function 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  
    1919add_action( 'save_post_lesson-plan', __NAMESPACE__ . '\save_lesson_plan_metabox_fields' );
    2020add_action( 'save_post_wporg_workshop', __NAMESPACE__ . '\save_workshop_metabox_fields' );
     21add_action( 'admin_footer', __NAMESPACE__ . '\render_locales_list' );
    2122add_action( 'enqueue_block_editor_assets', __NAMESPACE__ . '\enqueue_editor_assets' );
    2223
     
    178179        );
    179180    }
     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    }
    180198}
    181199
     
    191209 */
    192210function sanitize_locale( $meta_value, $meta_key, $object_type, $object_subtype ) {
    193     if ( 'wporg_workshop' !== $object_subtype ) {
    194         return $meta_value;
    195     }
    196 
    197211    $meta_value = trim( $meta_value );
    198212    $locales = array_keys( get_locales_with_english_names() );
     
    500514
    501515/**
     516 * Render the locales list for the language meta block.
     517 */
     518function 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/**
    502530 * Enqueue scripts for the block editor.
    503531 */
    504532function 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 */
     540function enqueue_expiration_date_assets() {
    505541    global $typenow;
    506542
     
    524560    }
    525561}
     562
     563
     564/**
     565 * Enqueue scripts for the language meta block.
     566 */
     567function 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  
    2222    register_lesson_plan_series();
    2323    register_workshop_series();
    24     register_workshop_topic();
    2524    register_workshop_type();
    2625    register_wp_version();
    2726    register_included_content();
     27    register_topic();
    2828}
    2929
     
    234234    );
    235235
    236     $args   = array(
     236    $args = array(
    237237        'labels'            => $labels,
    238238        'hierarchical'      => true,
     
    298298
    299299/**
    300  * Register the Workshop Series taxonomy.
     300 * Register the Lesson Plan Series taxonomy.
    301301 */
    302302function register_lesson_plan_series() {
     
    387387
    388388/**
    389  * Register the Workshop Topic 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 */
     391function register_topic() {
     392    $labels = array(
     393        'name'                       => _x( 'Topics', 'Topics associated with the content.', 'wporg-learn' ),
    394394        'singular_name'              => _x( 'Topic', 'Taxonomy Singular Name', 'wporg-learn' ),
    395395        'menu_name'                  => __( 'Topics', 'wporg-learn' ),
     
    411411        'items_list'                 => __( 'Topic list', 'wporg-learn' ),
    412412        'items_list_navigation'      => __( 'Topic list navigation', 'wporg-learn' ),
     413        'back_to_items'              => __( '&larr; Back to topics', 'wporg-learn' ),
    413414    );
    414415
     
    424425        'show_in_rest'      => true,
    425426        '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 );
    431432}
    432433
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-learn/package.json

    r12130 r12174  
    1515    },
    1616    "dependencies": {
     17        "@wordpress/block-editor": "^10.3.0",
     18        "@wordpress/blocks": "11.17.0",
    1719        "@wordpress/components": "12.0.5",
     20        "@wordpress/core-data": "^5.3.0",
    1821        "@wordpress/data": "4.26.5",
    1922        "@wordpress/date": "4.18.0",
    20         "@wordpress/i18n": "3.18.0",
    21         "@wordpress/url": "3.19.0",
    2223        "@wordpress/edit-post": "3.25.3",
    2324        "@wordpress/element": "2.19.1",
     25        "@wordpress/i18n": "3.18.0",
    2426        "@wordpress/plugins": "2.24.5",
    25         "@wordpress/blocks": "11.17.0"
     27        "@wordpress/url": "3.19.0"
    2628    },
    2729    "devDependencies": {
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-learn/views/metabox-workshop-details.php

    r11294 r12174  
    6767
    6868<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>
    7070    <select id="workshop-video-language" name="video-language" style="width: 100%;">
    7171        <?php foreach ( $locales as $code => $label ) : ?>
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-learn/webpack.config.js

    r12130 r12174  
    1414    'lesson-plan-actions': './js/lesson-plan-actions/src/index.js',
    1515    'lesson-plan-details': './js/lesson-plan-details/src/index.js',
     16    'language-meta': './js/language-meta/index.js',
    1617};
    1718
Note: See TracChangeset for help on using the changeset viewer.