Changeset 10272 for sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-learn/inc/post-meta.php
- Timestamp:
- 09/16/2020 10:07:05 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-learn/inc/post-meta.php
r10237 r10272 5 5 use DateTime, DateInterval; 6 6 use WP_Post; 7 use function WordPressdotorg\Locales\{ get_locales_with_english_names }; 7 8 8 9 defined( 'WPINC' ) || die(); … … 59 60 'type' => 'string', 60 61 'single' => true, 61 'sanitize_callback' => '', // todo 62 'default' => 'en_US', 63 'sanitize_callback' => __NAMESPACE__ . '\sanitize_locale', 62 64 'show_in_rest' => true, 63 65 ) … … 71 73 'type' => 'string', 72 74 'single' => false, 73 'sanitize_callback' => '', // todo 74 'show_in_rest' => true, 75 ) 76 ); 75 'sanitize_callback' => __NAMESPACE__ . '\sanitize_locale', 76 'show_in_rest' => true, 77 ) 78 ); 79 } 80 81 /** 82 * Sanitize a locale value. 83 * 84 * @param string $meta_value 85 * @param string $meta_key 86 * @param string $object_type 87 * @param string $object_subtype 88 * 89 * @return string 90 */ 91 function sanitize_locale( $meta_value, $meta_key, $object_type, $object_subtype ) { 92 if ( 'wporg_workshop' !== $object_subtype ) { 93 return $meta_value; 94 } 95 96 $meta_value = trim( $meta_value ); 97 $locales = array_keys( get_locales_with_english_names() ); 98 99 if ( ! in_array( $meta_value, $locales, true ) ) { 100 return ''; 101 } 102 103 return $meta_value; 77 104 } 78 105 … … 127 154 128 155 /** 156 * Get a list of locales that are associated with at least one workshop. 157 * 158 * @param string $meta_key 159 * @param string $label_language 160 * 161 * @return array 162 */ 163 function get_available_workshop_locales( $meta_key, $label_language = 'english' ) { 164 global $wpdb; 165 166 $results = $wpdb->get_col( $wpdb->prepare( 167 " 168 SELECT DISTINCT meta_value 169 FROM $wpdb->postmeta 170 WHERE meta_key = %s 171 ORDER BY meta_value ASC 172 ", 173 $meta_key 174 ) ); 175 176 if ( empty( $results ) ) { 177 return array(); 178 } 179 180 $available_locales = array_fill_keys( $results, '' ); 181 182 $locale_fn = "\WordPressdotorg\Locales\get_locales_with_{$label_language}_names"; 183 $locales = $locale_fn(); 184 185 return array_intersect_key( $locales, $available_locales ); 186 } 187 188 /** 129 189 * Add meta boxes to the Edit Workshop screen. 130 190 * … … 156 216 function render_metabox_workshop_details( WP_Post $post ) { 157 217 $duration_interval = get_workshop_duration( $post, 'interval' ); 218 $locales = get_locales_with_english_names(); 158 219 $captions = get_post_meta( $post->ID, 'video_caption_language' ) ?: array(); 159 220 … … 199 260 update_post_meta( $post_id, 'video_language', $video_language ); 200 261 201 $video_caption_language = filter_input( INPUT_POST, 'video-caption-language' ); 202 $captions = array_map( 'trim', explode( ',', $video_caption_language ) ); 203 delete_post_meta( $post_id, 'video_caption_language' ); 204 foreach ( $captions as $caption ) { 205 add_post_meta( $post_id, 'video_caption_language', $caption ); 206 } 207 } 262 $captions = filter_input( INPUT_POST, 'video-caption-language', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY ); 263 if ( is_array( $captions ) ) { 264 delete_post_meta( $post_id, 'video_caption_language' ); 265 foreach ( $captions as $caption ) { 266 add_post_meta( $post_id, 'video_caption_language', $caption ); 267 } 268 } 269 }
Note: See TracChangeset
for help on using the changeset viewer.