Making WordPress.org

Changeset 12570


Ignore:
Timestamp:
05/03/2023 11:33:44 PM (3 years ago)
Author:
adamwood
Message:

Learn: Sync with git WordPress/learn@83713e4

Location:
sites/trunk/wordpress.org/public_html/wp-content
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-learn/inc/admin.php

    r12276 r12570  
    66use function WordPressdotorg\Locales\get_locales_with_english_names;
    77use function WordPressdotorg\Locales\get_locale_name_from_code;
    8 use function WPOrg_Learn\Post_Meta\get_available_workshop_locales;
     8use function WPOrg_Learn\Post_Meta\get_available_post_type_locales;
    99
    1010defined( 'WPINC' ) || die();
     
    2525}
    2626add_filter( 'manage_edit-wporg_workshop_sortable_columns', __NAMESPACE__ . '\add_workshop_list_table_sortable_columns' );
    27 add_action( 'restrict_manage_posts', __NAMESPACE__ . '\add_workshop_list_table_filters', 10, 2 );
    28 add_action( 'pre_get_posts', __NAMESPACE__ . '\handle_workshop_list_table_filters' );
     27add_action( 'restrict_manage_posts', __NAMESPACE__ . '\add_admin_list_table_filters', 10, 2 );
     28add_action( 'pre_get_posts', __NAMESPACE__ . '\handle_admin_list_table_filters' );
    2929add_filter( 'display_post_states', __NAMESPACE__ . '\add_post_states', 10, 2 );
    3030foreach ( array( 'lesson-plan', 'wporg_workshop', 'course', 'lesson' ) as $pt ) {
     
    224224
    225225/**
    226  * Add filtering controls for the workshops list table.
     226 * Add filtering controls for the tutorial and lesson plan list tables.
    227227 *
    228228 * @param string $post_type
     
    231231 * @return void
    232232 */
    233 function add_workshop_list_table_filters( $post_type, $which ) {
    234         if ( 'wporg_workshop' !== $post_type || 'top' !== $which ) {
    235                 return;
    236         }
    237 
    238         $available_locales = get_available_workshop_locales( 'language', 'english', false );
     233function add_admin_list_table_filters( $post_type, $which ) {
     234        if ( ( 'wporg_workshop' !== $post_type && 'lesson-plan' !== $post_type ) || 'top' !== $which ) {
     235                return;
     236        }
     237
     238        $post_status       = filter_input( INPUT_GET, 'post_status', FILTER_SANITIZE_STRING );
     239        $available_locales = get_available_post_type_locales( 'language', $post_type, $post_status );
    239240        $language          = filter_input( INPUT_GET, 'language', FILTER_SANITIZE_STRING );
    240241
     
    261262
    262263/**
    263  * Alter the query to include workshop list table filters.
     264 * Alter the query to include tutorial and lesson plan list table filters.
    264265 *
    265266 * @param WP_Query $query
     
    267268 * @return void
    268269 */
    269 function handle_workshop_list_table_filters( WP_Query $query ) {
     270function handle_admin_list_table_filters( WP_Query $query ) {
    270271        if ( ! is_admin() || ! function_exists( 'get_current_screen' ) ) {
    271272                return;
     
    278279        }
    279280
    280         if ( 'edit-wporg_workshop' === $current_screen->id ) {
     281        if ( 'edit-wporg_workshop' === $current_screen->id || 'edit-lesson-plan' === $current_screen->id ) {
    281282                $language = filter_input( INPUT_GET, 'language', FILTER_SANITIZE_STRING );
    282283
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-learn/inc/post-meta.php

    r12371 r12570  
    258258
    259259/**
    260  * Get a list of locales that are associated with at least one workshop.
    261  *
    262  * Optionally only published workshops.
     260 * Get a list of locales that are associated with at least one post of the specified type.
    263261 *
    264262 * @param string $meta_key
     263 * @param string $post_type
     264 * @param string $post_status
    265265 * @param string $label_language
    266  * @param bool   $published_only
    267266 *
    268267 * @return array
    269268 */
    270 function get_available_workshop_locales( $meta_key, $label_language = 'english', $published_only = true ) {
     269function get_available_post_type_locales( $meta_key, $post_type, $post_status, $label_language = 'english' ) {
    271270        global $wpdb;
    272271
    273272        $and_post_status = '';
    274         if ( $published_only ) {
    275                 $and_post_status = "AND posts.post_status = 'publish'";
     273        if ( in_array( $post_status, get_post_stati(), true ) ) {
     274                $and_post_status = "AND posts.post_status = '$post_status'";
    276275        }
    277276
    278277        $results = $wpdb->get_col( $wpdb->prepare(
    279                 // phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- $and_post_status contains no user input.
     278                // phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- $and_post_status only includes $post_status if it matches an allowed string.
    280279                "
    281                         SELECT DISTINCT postmeta.meta_value
    282                         FROM {$wpdb->postmeta} postmeta
    283                                 JOIN {$wpdb->posts} posts ON posts.ID = postmeta.post_id $and_post_status
    284                         WHERE postmeta.meta_key = %s
    285                 ",
     280                SELECT DISTINCT postmeta.meta_value
     281                FROM {$wpdb->postmeta} postmeta
     282                        JOIN {$wpdb->posts} posts ON posts.ID = postmeta.post_id AND posts.post_type = %s $and_post_status
     283                WHERE postmeta.meta_key = %s
     284        ",
     285                $post_type,
    286286                $meta_key
    287287                // phpcs:enable WordPress.DB.PreparedSQL.InterpolatedNotPrepared
     
    346346        $download_url = filter_input( INPUT_POST, 'slides-download-url', FILTER_VALIDATE_URL ) ?: '';
    347347        update_post_meta( $post_id, 'slides_download_url', $download_url );
     348
     349        // This language meta field is rendered in the editor sidebar using a PluginDocumentSettingPanel block,
     350        // which won't save the field on publish if it has the default value.
     351        // Our filtering by locale depends on it being set, so we force it to be updated after saving:
     352        $language         = get_post_meta( $post_id, 'language', true );
     353        $language_default = 'en_US';
     354        if ( ! isset( $language ) || $language_default === $language ) {
     355                update_post_meta( $post_id, 'language', $language_default );
     356        }
    348357}
    349358
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-learn-2020/functions.php

    r12473 r12570  
    708708
    709709                case 'lesson-plan':
    710                         $args['meta']  = wporg_learn_get_lesson_plan_taxonomy_data( $post_id, 'archive' );
     710                        $args['meta'] = array_merge(
     711                                wporg_learn_get_lesson_plan_taxonomy_data( $post_id, 'archive' ),
     712                                array(
     713                                        array(
     714                                                'icon'  => 'admin-site-alt3',
     715                                                'label' => __( 'Language:', 'wporg-learn' ),
     716                                                'value' => \WordPressdotorg\Locales\get_locale_name_from_code( $post->language, 'native' ),
     717                                        ),
     718                                )
     719                        );
    711720                        break;
    712721
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-learn-2020/template-parts/component-lesson-filters.php

    r11697 r12570  
    3232        ),
    3333);
     34
     35$locales = \WPOrg_Learn\Post_Meta\get_available_post_type_locales( 'language', 'lesson-plan', 'publish', 'native' );
    3436?>
    3537
     
    4143                        <?php esc_html_e( 'Apply Filters', 'wporg-learn' ); ?>
    4244                </button>
    43                 <a href="<?php echo esc_url( get_post_type_archive_link( 'lesson-plan' ) ); ?>" class="clear-filters">
     45                <a href="<?php echo esc_url( get_post_type_archive_link( 'lesson-plan' ) . '?_view=all' ); ?>" class="clear-filters">
    4446                        <?php esc_html_e( 'Clear All Filters', 'wporg-learn' ); ?>
    4547                </a>
     48        </div>
     49
     50        <h4 class="h5" id="lp-filters-language-heading"><?php esc_html_e( 'Language', 'wporg-learn' ); ?></h4>
     51        <div class="filter-group">
     52                <select
     53                        id="<?php echo esc_attr( 'language' ); ?>"
     54                        class="filter-group-select"
     55                        name="<?php echo esc_attr( 'language' ); ?>"
     56                        data-placeholder="<?php esc_attr_e( 'Select', 'wporg-learn' ); ?>"
     57                        aria-labelledby="lp-filters-language-heading"
     58                >
     59                        <option value=""><?php esc_html_e( 'Select', 'wporg-learn' ); ?></option>
     60                        <?php foreach ( $locales as $locale_value => $locale_label ) : ?>
     61                                <option
     62                                        value="<?php echo esc_attr( $locale_value ); ?>"
     63                                        <?php selected( $locale_value, filter_input( INPUT_GET, 'language' ) ); ?>
     64                                >
     65                                        <?php printf( '%s [%s]', esc_html( $locale_label ), esc_html( $locale_value ) ); ?>
     66                                </option>
     67                        <?php endforeach; ?>
     68                </select>
    4669        </div>
    4770
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-learn-2020/template-parts/component-workshop-filters.php

    r12276 r12570  
    2424                'label' => __( 'Language', 'wporg-learn' ),
    2525                'name'  => 'language',
    26                 'items' => \WPOrg_Learn\Post_Meta\get_available_workshop_locales( 'language', 'native' ),
     26                'items' => \WPOrg_Learn\Post_Meta\get_available_post_type_locales( 'language', 'wporg_workshop', 'publish', 'native' ),
    2727        ),
    2828        array(
    2929                'label' => __( 'Subtitles', 'wporg-learn' ),
    3030                'name'  => 'captions',
    31                 'items' => \WPOrg_Learn\Post_Meta\get_available_workshop_locales( 'video_caption_language', 'native' ),
     31                'items' => \WPOrg_Learn\Post_Meta\get_available_post_type_locales( 'video_caption_language', 'wporg_workshop', 'publish', 'native' ),
    3232        ),
    3333        array(
Note: See TracChangeset for help on using the changeset viewer.