Making WordPress.org


Ignore:
Timestamp:
04/26/2021 11:09:28 PM (6 years ago)
Author:
coreymckrill
Message:

WordPress.org Learn: Sync with GitHub

​https://github.com/WordPress/learn/commit/5133da6d34c524f7b4685400c8359842153fbf17

File:
1 edited

Legend:

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

    r10866 r10926  
    218218 * Get a list of locales that are associated with at least one workshop.
    219219 *
     220 * Optionally only published workshops.
     221 *
    220222 * @param string $meta_key
    221223 * @param string $label_language
     224 * @param bool   $published_only
    222225 *
    223226 * @return array
    224227 */
    225 function get_available_workshop_locales( $meta_key, $label_language = 'english' ) {
     228function get_available_workshop_locales( $meta_key, $label_language = 'english', $published_only = true ) {
    226229        global $wpdb;
    227230
     231        $and_post_status = '';
     232        if ( $published_only ) {
     233                $and_post_status = "AND posts.post_status = 'publish'";
     234        }
     235
    228236        $results = $wpdb->get_col( $wpdb->prepare(
     237                // phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- $and_post_status contains no user input.
    229238                "
    230                         SELECT DISTINCT meta_value
    231                         FROM $wpdb->postmeta
    232                         WHERE meta_key = %s
    233                         ORDER BY meta_value ASC
     239                        SELECT DISTINCT postmeta.meta_value
     240                        FROM {$wpdb->postmeta} postmeta
     241                                JOIN {$wpdb->posts} posts ON posts.ID = postmeta.post_id $and_post_status
     242                        WHERE postmeta.meta_key = %s
    234243                ",
    235244                $meta_key
     245                // phpcs:enable WordPress.DB.PreparedSQL.InterpolatedNotPrepared
    236246        ) );
    237247
Note: See TracChangeset for help on using the changeset viewer.