Changeset 10283 for sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-learn/inc/post-type.php
- Timestamp:
- 09/24/2020 02:21:07 AM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-learn/inc/post-type.php
r10237 r10283 3 3 namespace WPOrg_Learn\Post_Type; 4 4 5 use function WordPressdotorg\Locales\get_locale_name_from_code; 6 5 7 defined( 'WPINC' ) || die(); 6 8 … … 9 11 */ 10 12 add_action( 'init', __NAMESPACE__ . '\register' ); 13 add_filter( 'manage_wporg_workshop_posts_columns', __NAMESPACE__ . '\add_workshop_list_table_columns' ); 14 add_action( 'manage_wporg_workshop_posts_custom_column', __NAMESPACE__ . '\render_workshop_list_table_columns', 10, 2 ); 15 add_filter( 'jetpack_sitemap_post_types', __NAMESPACE__ . '\jetpack_sitemap_post_types' ); 11 16 12 17 /** … … 219 224 register_post_type( 'wporg_workshop', $args ); 220 225 } 226 227 /** 228 * Add additional columns to the post list table for workshops. 229 * 230 * @param array $columns 231 * 232 * @return array 233 */ 234 function add_workshop_list_table_columns( $columns ) { 235 $columns = array_slice( $columns, 0, -2, true ) 236 + array( 'video_language' => __( 'Language', 'wporg-learn' ) ) 237 + array( 'video_caption_language' => __( 'Captions', 'wporg-learn' ) ) 238 + array_slice( $columns, -2, 2, true ); 239 240 return $columns; 241 } 242 243 /** 244 * Render the cell contents for the additional columns in the post list table for workshops. 245 * 246 * @param string $column_name 247 * @param int $post_id 248 * 249 * @return void 250 */ 251 function render_workshop_list_table_columns( $column_name, $post_id ) { 252 $post = get_post( $post_id ); 253 254 switch ( $column_name ) { 255 case 'video_language': 256 echo esc_html( get_locale_name_from_code( $post->video_language, 'english' ) ); 257 break; 258 case 'video_caption_language': 259 $captions = get_post_meta( $post->ID, 'video_caption_language' ); 260 261 echo esc_html( implode( 262 ', ', 263 array_map( 264 function( $caption_lang ) { 265 return get_locale_name_from_code( $caption_lang, 'english' ); 266 }, 267 $captions 268 ) 269 ) ); 270 break; 271 } 272 } 273 274 /** 275 * Register our post types with Jetpack Sitemaps. 276 * @link https://developer.jetpack.com/hooks/jetpack_sitemap_post_types/ 277 * 278 * @param array $post_types 279 * @return array 280 */ 281 function jetpack_sitemap_post_types( $post_types ) { 282 $post_types[] = 'lesson-plan'; 283 $post_types[] = 'wporg_workshop'; 284 285 return $post_types; 286 }
Note: See TracChangeset
for help on using the changeset viewer.