Making WordPress.org


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

Learn: Sync with git WordPress/learn@83713e4

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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
Note: See TracChangeset for help on using the changeset viewer.