Changeset 12570 for sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-learn/inc/post-meta.php
- Timestamp:
- 05/03/2023 11:33:44 PM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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
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)