Changeset 12570
- Timestamp:
- 05/03/2023 11:33:44 PM (3 years ago)
- Location:
- sites/trunk/wordpress.org/public_html/wp-content
- Files:
-
- 5 edited
-
plugins/wporg-learn/inc/admin.php (modified) (7 diffs)
-
plugins/wporg-learn/inc/post-meta.php (modified) (2 diffs)
-
themes/pub/wporg-learn-2020/functions.php (modified) (1 diff)
-
themes/pub/wporg-learn-2020/template-parts/component-lesson-filters.php (modified) (2 diffs)
-
themes/pub/wporg-learn-2020/template-parts/component-workshop-filters.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-learn/inc/admin.php
r12276 r12570 6 6 use function WordPressdotorg\Locales\get_locales_with_english_names; 7 7 use function WordPressdotorg\Locales\get_locale_name_from_code; 8 use function WPOrg_Learn\Post_Meta\get_available_ workshop_locales;8 use function WPOrg_Learn\Post_Meta\get_available_post_type_locales; 9 9 10 10 defined( 'WPINC' ) || die(); … … 25 25 } 26 26 add_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' );27 add_action( 'restrict_manage_posts', __NAMESPACE__ . '\add_admin_list_table_filters', 10, 2 ); 28 add_action( 'pre_get_posts', __NAMESPACE__ . '\handle_admin_list_table_filters' ); 29 29 add_filter( 'display_post_states', __NAMESPACE__ . '\add_post_states', 10, 2 ); 30 30 foreach ( array( 'lesson-plan', 'wporg_workshop', 'course', 'lesson' ) as $pt ) { … … 224 224 225 225 /** 226 * Add filtering controls for the workshops list table.226 * Add filtering controls for the tutorial and lesson plan list tables. 227 227 * 228 228 * @param string $post_type … … 231 231 * @return void 232 232 */ 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 ); 233 function 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 ); 239 240 $language = filter_input( INPUT_GET, 'language', FILTER_SANITIZE_STRING ); 240 241 … … 261 262 262 263 /** 263 * Alter the query to include workshoplist table filters.264 * Alter the query to include tutorial and lesson plan list table filters. 264 265 * 265 266 * @param WP_Query $query … … 267 268 * @return void 268 269 */ 269 function handle_ workshop_list_table_filters( WP_Query $query ) {270 function handle_admin_list_table_filters( WP_Query $query ) { 270 271 if ( ! is_admin() || ! function_exists( 'get_current_screen' ) ) { 271 272 return; … … 278 279 } 279 280 280 if ( 'edit-wporg_workshop' === $current_screen->id ) {281 if ( 'edit-wporg_workshop' === $current_screen->id || 'edit-lesson-plan' === $current_screen->id ) { 281 282 $language = filter_input( INPUT_GET, 'language', FILTER_SANITIZE_STRING ); 282 283 -
sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-learn/inc/post-meta.php
r12371 r12570 258 258 259 259 /** 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. 263 261 * 264 262 * @param string $meta_key 263 * @param string $post_type 264 * @param string $post_status 265 265 * @param string $label_language 266 * @param bool $published_only267 266 * 268 267 * @return array 269 268 */ 270 function get_available_ workshop_locales( $meta_key, $label_language = 'english', $published_only = true) {269 function get_available_post_type_locales( $meta_key, $post_type, $post_status, $label_language = 'english' ) { 271 270 global $wpdb; 272 271 273 272 $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'"; 276 275 } 277 276 278 277 $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. 280 279 " 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, 286 286 $meta_key 287 287 // phpcs:enable WordPress.DB.PreparedSQL.InterpolatedNotPrepared … … 346 346 $download_url = filter_input( INPUT_POST, 'slides-download-url', FILTER_VALIDATE_URL ) ?: ''; 347 347 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 } 348 357 } 349 358 -
sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-learn-2020/functions.php
r12473 r12570 708 708 709 709 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 ); 711 720 break; 712 721 -
sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-learn-2020/template-parts/component-lesson-filters.php
r11697 r12570 32 32 ), 33 33 ); 34 35 $locales = \WPOrg_Learn\Post_Meta\get_available_post_type_locales( 'language', 'lesson-plan', 'publish', 'native' ); 34 36 ?> 35 37 … … 41 43 <?php esc_html_e( 'Apply Filters', 'wporg-learn' ); ?> 42 44 </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"> 44 46 <?php esc_html_e( 'Clear All Filters', 'wporg-learn' ); ?> 45 47 </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> 46 69 </div> 47 70 -
sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-learn-2020/template-parts/component-workshop-filters.php
r12276 r12570 24 24 'label' => __( 'Language', 'wporg-learn' ), 25 25 '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' ), 27 27 ), 28 28 array( 29 29 'label' => __( 'Subtitles', 'wporg-learn' ), 30 30 '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' ), 32 32 ), 33 33 array(
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)