Making WordPress.org


Ignore:
Timestamp:
09/24/2020 02:21:07 AM (4 years ago)
Author:
dd32
Message:

WordPress.org Learn: Sync with GitHub

https://github.com/WordPress/learn/compare/078146d2be1cadea501a2132d5cfc7c964f7647f...1d7ba6d647dca8345507f2a7ad22179513047909

File:
1 edited

Legend:

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

    r10237 r10283  
    33namespace WPOrg_Learn\Post_Type;
    44
     5use function WordPressdotorg\Locales\get_locale_name_from_code;
     6
    57defined( 'WPINC' ) || die();
    68
     
    911 */
    1012add_action( 'init', __NAMESPACE__ . '\register' );
     13add_filter( 'manage_wporg_workshop_posts_columns', __NAMESPACE__ . '\add_workshop_list_table_columns' );
     14add_action( 'manage_wporg_workshop_posts_custom_column', __NAMESPACE__ . '\render_workshop_list_table_columns', 10, 2 );
     15add_filter( 'jetpack_sitemap_post_types', __NAMESPACE__ . '\jetpack_sitemap_post_types' );
    1116
    1217/**
     
    219224    register_post_type( 'wporg_workshop', $args );
    220225}
     226
     227/**
     228 * Add additional columns to the post list table for workshops.
     229 *
     230 * @param array $columns
     231 *
     232 * @return array
     233 */
     234function 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 */
     251function 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 */
     281function 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.