Making WordPress.org

Ticket #1921: 1921.diff

File 1921.diff, 9.3 KB (added by hlashbrooke, 6 years ago)

Displaying all session meta data on sinlge session page

  • wordcamp.org/public_html/wp-content/plugins/wc-post-types/wc-post-types.php

    diff --git wordcamp.org/public_html/wp-content/plugins/wc-post-types/wc-post-types.php wordcamp.org/public_html/wp-content/plugins/wc-post-types/wc-post-types.php
    index dd19064..1ffd325 100644
    class WordCamp_Post_Types_Plugin { 
    5252
    5353                add_filter( 'body_class', array( $this, 'session_category_slugs_to_body_tag' ) );
    5454
     55                add_filter( 'the_content', array( $this, 'add_session_info_to_session_posts' ) );
    5556                add_filter( 'the_content', array( $this, 'add_avatar_to_speaker_posts' ) );
    56                 add_filter( 'the_content', array( $this, 'add_speaker_info_to_session_posts' ) );
    57                 add_filter( 'the_content', array( $this, 'add_slides_info_to_session_posts' ) );
    58                 add_filter( 'the_content', array( $this, 'add_video_info_to_session_posts' ) );
    59                 add_filter( 'the_content', array( $this, 'add_session_categories_to_session_posts' ) );
    6057                add_filter( 'the_content', array( $this, 'add_session_info_to_speaker_posts' ) );
    6158
    6259                add_filter( 'dashboard_glance_items', array( $this, 'glance_items' ) );
    class WordCamp_Post_Types_Plugin { 
    12681265        }
    12691266
    12701267        /**
    1271          * Add speaker information to Session posts
     1268         * Add session information to Session posts
    12721269         *
    12731270         * We don't enable it for sites that were created before it was committed, because some will have already
    12741271         * crafted the bio to include this content, so duplicating it would look wrong, but we still allow older
    class WordCamp_Post_Types_Plugin { 
    12781275         *
    12791276         * @return string
    12801277         */
    1281         function add_speaker_info_to_session_posts( $content ) {
     1278        function add_session_info_to_session_posts( $content ) {
    12821279                global $post;
    12831280                $enabled_site_ids = apply_filters( 'wcpt_session_post_speaker_info_enabled_site_ids', array( 364 ) );    // 2014.sf
    12841281
    class WordCamp_Post_Types_Plugin { 
    12911288                        return $content;
    12921289                }
    12931290
     1291                // Get the list of speakers
    12941292                $speaker_ids = (array) get_post_meta( $post->ID, '_wcpt_speaker_id' );
    1295 
    1296                 if ( empty ( $speaker_ids ) ) {
    1297                         return $content;
    1298                 }
    1299 
    13001293                $speaker_args = array(
    13011294                        'post_type'      => 'wcb_speaker',
    13021295                        'posts_per_page' => -1,
    class WordCamp_Post_Types_Plugin { 
    13071300
    13081301                $speakers = new WP_Query( $speaker_args );
    13091302
    1310                 if ( ! $speakers->have_posts() ) {
    1311                         return $content;
    1312                 }
    1313 
    1314                 $speakers_html = sprintf(
    1315                         '<h2 class="session-speakers">%s</h2>',
     1303                $speaker_html = sprintf(
     1304                        '<li class="session-speakers"><strong>%s',
    13161305                        _n(
    13171306                                __( 'Speaker', 'wordcamporg' ),
    13181307                                __( 'Speakers', 'wordcamporg' ),
    class WordCamp_Post_Types_Plugin { 
    13201309                        )
    13211310                );
    13221311
    1323                 $speakers_html .= '<ul id="session-speaker-names">';
     1312                $speakers_array = array();
    13241313                while ( $speakers->have_posts() ) {
    13251314                        $speakers->the_post();
    1326                         $speakers_html .= sprintf( '<li><a href="%s">%s</a></li>', get_the_permalink(), get_the_title() );
     1315                        $speakers_array[] = sprintf( '<a href="%s">%s</a>', get_the_permalink(), get_the_title() );
    13271316                }
    1328                 $speakers_html .= '</ul>';
    13291317
    13301318                wp_reset_postdata();
    13311319
    1332                 return $content . $speakers_html;
    1333         }
    1334 
    1335         /**
    1336          * Add Slides link to Session posts
    1337          *
    1338          * We don't enable it for sites that were created before it was committed, because some will have already
    1339          * crafted the session to include this content, so duplicating it would look wrong, but we still allow older
    1340          * sites to opt-in.
    1341          *
    1342          * @param string $content
    1343          *
    1344          * @return string
    1345          */
    1346         function add_slides_info_to_session_posts( $content ) {
    1347                 global $post;
    1348                 $enabled_site_ids = apply_filters( 'wcpt_session_post_slides_info_enabled_site_ids', array(
    1349                         206,  // testing.wordcamp.org
    1350                         648,  // 2016.asheville
    1351                         651,  // 2016.kansascity
    1352                         623,  // 2016.tampa
    1353                 ) );
    1354 
    1355                 if ( ! $this->is_single_cpt_post( 'wcb_session' ) ) {
    1356                         return $content;
     1320                $speakers_list = join( ', ', $speakers_array );
     1321                if( $speakers_list ) {
     1322                        $speaker_html .= ':</strong> ' . $speakers_list . '</li>';
     1323                } else {
     1324                        $speaker_html = '';
    13571325                }
    13581326
    1359                 $site_id = get_current_blog_id();
    1360                 if ( $site_id <= apply_filters( 'wcpt_session_post_slides_info_min_site_id', 699 ) && ! in_array( $site_id, $enabled_site_ids ) ) {
    1361                         return $content;
    1362                 }
     1327                // Get the time and date of the session
     1328                $time = absint( get_post_meta( $post->ID, '_wcpt_session_time', true ) );
     1329                $time_html = '';
     1330                if( $time ) {
     1331                        $time_format = get_option( 'time_format', 'g:i a' );
     1332                        $date_format = get_option( 'date_format', 'F j, Y' );
    13631333
    1364                 $session_slides = get_post_meta( $post->ID, '_wcpt_session_slides', true );
     1334                        $time_string = esc_html( date( $time_format, $time ) );
     1335                        $date_string = esc_html( date( $date_format, $time ) );
    13651336
    1366                 if ( empty ( $session_slides ) ) {
    1367                         return $content;
     1337                        $time_html = '<li class="session-time"><strong>' . __( 'Time', 'wordcamporg' ) . ':</strong> ' . $date_string . ' @ ' . $time_string . '</li>';
    13681338                }
    13691339
    1370                 $session_slides_html  = '<div class="session-video">';
    1371                 $session_slides_html .= sprintf( __( '<a href="%s" target="_blank">View Session Slides</a>', 'wordcamporg' ), esc_url( $session_slides ) );
    1372                 $session_slides_html .= '</div>';
    1373 
    1374                 return $content . $session_slides_html;
    1375         }
     1340                //  Get a list of the session tracks
     1341                $tracks = get_the_terms( $post->ID, 'wcb_track' );
     1342                $tracks_array = array();
     1343                foreach ( $tracks as $track ) {
     1344                        $tracks_array[] = $track->name;
     1345                }
    13761346
    1377         /**
    1378          * Add Video link to Session posts
    1379          *
    1380          * We don't enable it for sites that were created before it was committed, because some will have already
    1381          * crafted the session to include this content, so duplicating it would look wrong, but we still allow older
    1382          * sites to opt-in.
    1383          *
    1384          * @param string $content
    1385          *
    1386          * @return string
    1387          */
    1388         function add_video_info_to_session_posts( $content ) {
    1389                 global $post;
    1390                 $enabled_site_ids = apply_filters( 'wcpt_session_post_video_info_enabled_site_ids', array(
    1391                         206,  // testing.wordcamp.org
    1392                         648,  // 2016.asheville
    1393                         623,  // 2016.tampa
    1394                 ) );
     1347                $num_tracks = count ( $tracks_array );
     1348                $tracks_html = '';
     1349                if( $num_tracks ) {
    13951350
    1396                 if ( ! $this->is_single_cpt_post( 'wcb_session' ) ) {
    1397                         return $content;
     1351                        $tracks_html = sprintf(
     1352                                '<li class="session-tracks"><strong>%s',
     1353                                _n(
     1354                                        __( 'Track', 'wordcamporg' ),
     1355                                        __( 'Tracks', 'wordcamporg' ),
     1356                                        $speakers->post_count
     1357                                )
     1358                        );
     1359                        $tracks_list = join( ", ", $tracks_array );
     1360                        $tracks_html .= ':</strong> ' . $tracks_list . '</li>';
    13981361                }
    13991362
    1400                 $site_id = get_current_blog_id();
    1401                 if ( $site_id <= apply_filters( 'wcpt_session_post_video_info_min_site_id', 699 ) && ! in_array( $site_id, $enabled_site_ids ) ) {
    1402                         return $content;
     1363                // Get the link to the session slides
     1364                $session_slides = get_post_meta( $post->ID, '_wcpt_session_slides', true );
     1365                $slides_html = '';
     1366                if ( $session_slides ) {
     1367                        $slides_html = sprintf( __( '<li class="session-slides"><a href="%s" target="_blank">View Session Slides</a></li>', 'wordcamporg' ), esc_url( $session_slides ) );
    14031368                }
    14041369
     1370                // Get the link to the session video
    14051371                $session_video = get_post_meta( $post->ID, '_wcpt_session_video', true );
    1406 
    1407                 if ( empty ( $session_video ) ) {
    1408                         return $content;
    1409                 }
    1410 
    1411                 $session_video_html  = '<div class="session-video">';
    1412                 $session_video_html .= sprintf( __( '<a href="%s" target="_blank">View Session Video</a>', 'wordcamporg' ), esc_url( $session_video ) );
    1413                 $session_video_html .= '</div>';
    1414 
    1415                 return $content . $session_video_html;
    1416         }
    1417 
    1418         /**
    1419          * Append a session's categories to its post content.
    1420          *
    1421          * @param string $content
    1422          *
    1423          * @return string
    1424          */
    1425         function add_session_categories_to_session_posts( $content ) {
    1426                 global $post;
    1427 
    1428                 if ( ! $this->is_single_cpt_post( 'wcb_session' ) ) {
    1429                         return $content;
     1372                $video_html = '';
     1373                if( $session_video ) {
     1374                        $video_html = sprintf( __( '<li class="session-video"><a href="%s" target="_blank">View Session Video</a></li>', 'wordcamporg' ), esc_url( $session_video ) );
    14301375                }
    14311376
    1432                 $session_categories_html = '';
    1433 
    1434                 $session_categories_list = get_the_term_list( $post->ID, 'wcb_session_category', '', _x( ', ', 'Used between list items, there is a space after the comma.', 'wordcamporg' ) );
    1435                 if ( $session_categories_list ) {
    1436                         $session_categories_html = sprintf(
    1437                                 '<span class="session-categories-links"><span class="screen-reader-text">%1$s </span>%2$s</span>',
     1377                // Get the list of session categories
     1378                $categories_list = get_the_term_list( $post->ID, 'wcb_session_category', '', _x( ', ', 'Used between list items, there is a space after the comma.', 'wordcamporg' ) );
     1379                $categories_html = '';
     1380                if ( $categories_list ) {
     1381                        $categories_html = sprintf(
     1382                                '<li class="session-categories"><span class="screen-reader-text">%1$s </span>%2$s</span>',
    14381383                                _x( 'Categories', 'Used before session category names.', 'wordcamporg' ),
    1439                                 $session_categories_list
     1384                                $categories_list
    14401385                        );
    14411386                }
    14421387
    1443                 return $content . $session_categories_html;
     1388                // Generate meta list for display
     1389                $meta_html = '';
     1390                if( $speaker_html || $time_html || $tracks_html || $slides_html || $video_html || $categories_html ) {
     1391                        $meta_html = '<ul class="session-info">';
     1392                        $meta_html .= $speaker_html . $time_html . $tracks_html . $slides_html . $video_html . $categories_html;
     1393                        $meta_html .= '</ul>';
     1394                }
     1395
     1396                return $content . $meta_html;
    14441397        }
    14451398
     1399
    14461400        /**
    14471401         * Add the sessions's category slugs to the body tag.
    14481402         *