Making WordPress.org

Ticket #1921: 1921.1.diff

File 1921.1.diff, 10.9 KB (added by hlashbrooke, 6 years ago)

Moving meta list into separate view

  • new file wordcamp.org/public_html/wp-content/plugins/wc-post-types/views/common/session-meta-data-list.php

    diff --git wordcamp.org/public_html/wp-content/plugins/wc-post-types/views/common/session-meta-data-list.php wordcamp.org/public_html/wp-content/plugins/wc-post-types/views/common/session-meta-data-list.php
    new file mode 100644
    index 0000000..374144a
    - +  
     1<?php
     2/* @var string $speaker_text */
     3/* @var string $time_text */
     4/* @var string $tracks_text */
     5/* @var string $slides_text */
     6/* @var string $video_text */
     7/* @var string $categories_text */
     8?>
     9
     10<ul class="session-info">
     11
     12        <?php if ( $speaker_text ) : ?>
     13                <li class="session-speakers"><?php echo $speaker_text; ?></li>
     14        <?php endif; ?>
     15
     16        <?php if ( $time_text ) : ?>
     17                <li class="session-time"><?php echo $time_text; ?></li>
     18        <?php endif; ?>
     19
     20        <?php if ( $tracks_text ) : ?>
     21                <li class="session-tracks"><?php echo $tracks_text; ?></li>
     22        <?php endif; ?>
     23
     24        <?php if ( $slides_text ) : ?>
     25                <li class="session-slides"><?php echo $slides_text; ?></li>
     26        <?php endif; ?>
     27
     28        <?php if ( $video_text ) : ?>
     29                <li class="session-video"><?php echo $video_text; ?></li>
     30        <?php endif; ?>
     31
     32        <?php if ( $categories_text ) : ?>
     33                <li class="session-categories"><?php echo $categories_text; ?></li>
     34        <?php endif; ?>
     35
     36</ul>
     37 No newline at end of file
  • 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..824552c 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 { 
    12871284                }
    12881285
    12891286                $site_id = get_current_blog_id();
    1290                 if ( $site_id <= apply_filters( 'wcpt_session_post_speaker_info_min_site_id', 463 ) && ! in_array( $site_id, $enabled_site_ids ) ) {
    1291                         return $content;
    1292                 }
     1287                // if ( $site_id <= apply_filters( 'wcpt_session_post_speaker_info_min_site_id', 463 ) && ! in_array( $site_id, $enabled_site_ids ) ) {
     1288                //      return $content;
     1289                // }
    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>',
    1316                         _n(
    1317                                 __( 'Speaker', 'wordcamporg' ),
    1318                                 __( 'Speakers', 'wordcamporg' ),
    1319                                 $speakers->post_count
    1320                         )
     1303                $speaker_text = _n(
     1304                        __( 'Speaker', 'wordcamporg' ),
     1305                        __( 'Speakers', 'wordcamporg' ),
     1306                        $speakers->post_count,
     1307                        'wordcamporg'
    13211308                );
    13221309
    1323                 $speakers_html .= '<ul id="session-speaker-names">';
     1310                $speakers_array = array();
    13241311                while ( $speakers->have_posts() ) {
    13251312                        $speakers->the_post();
    1326                         $speakers_html .= sprintf( '<li><a href="%s">%s</a></li>', get_the_permalink(), get_the_title() );
     1313                        $speakers_array[] = sprintf( '<a href="%s">%s</a>', get_the_permalink(), get_the_title() );
    13271314                }
    1328                 $speakers_html .= '</ul>';
    13291315
    13301316                wp_reset_postdata();
    13311317
    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;
     1318                $speakers_list = join( ', ', $speakers_array );
     1319                if( $speakers_list ) {
     1320                        $speaker_text .= ': ' . $speakers_list;
     1321                } else {
     1322                        $speaker_text = '';
    13571323                }
    13581324
    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                 }
     1325                // Get the time and date of the session
     1326                $time = absint( get_post_meta( $post->ID, '_wcpt_session_time', true ) );
     1327                $time_text = '';
     1328                if( $time ) {
     1329                        $time_format = get_option( 'time_format', 'g:i a' );
     1330                        $date_format = get_option( 'date_format', 'F j, Y' );
    13631331
    1364                 $session_slides = get_post_meta( $post->ID, '_wcpt_session_slides', true );
     1332                        $time_string = esc_html( date( $time_format, $time ) );
     1333                        $date_string = esc_html( date( $date_format, $time ) );
    13651334
    1366                 if ( empty ( $session_slides ) ) {
    1367                         return $content;
     1335                        $time_text = __( 'Time', 'wordcamporg' ) . ': ' . $date_string . ' @ ' . $time_string . '</li>';
    13681336                }
    13691337
    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>';
     1338                //  Get a list of the session tracks
     1339                $tracks = get_the_terms( $post->ID, 'wcb_track' );
     1340                $tracks_array = array();
     1341                foreach ( $tracks as $track ) {
     1342                        $tracks_array[] = $track->name;
     1343                }
    13731344
    1374                 return $content . $session_slides_html;
    1375         }
     1345                $num_tracks = count ( $tracks_array );
     1346                $tracks_text = '';
     1347                if( $num_tracks ) {
    13761348
    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                 ) );
     1349                        $tracks_text = _n(
     1350                                __( 'Track', 'wordcamporg' ),
     1351                                __( 'Tracks', 'wordcamporg' ),
     1352                                $num_tracks,
     1353                                'wordcamporg'
     1354                        );
    13951355
    1396                 if ( ! $this->is_single_cpt_post( 'wcb_session' ) ) {
    1397                         return $content;
     1356                        $tracks_list = join( ", ", $tracks_array );
     1357                        $tracks_text .= ': ' . $tracks_list . '</li>';
    13981358                }
    13991359
    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;
     1360                // Get the link to the session slides
     1361                $session_slides = get_post_meta( $post->ID, '_wcpt_session_slides', true );
     1362                $slides_text = '';
     1363                if ( $session_slides ) {
     1364                        $slides_text = sprintf( __( '<a href="%s" target="_blank">View Session Slides</a>', 'wordcamporg' ), esc_url( $session_slides ) );
    14031365                }
    14041366
     1367                // Get the link to the session video
    14051368                $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;
     1369                $video_text = '';
     1370                if( $session_video ) {
     1371                        $video_text = sprintf( __( '<a href="%s" target="_blank">View Session Video</a>', 'wordcamporg' ), esc_url( $session_video ) );
     1372                }
     1373
     1374                // Get the list of session categories
     1375                $categories_list = get_the_term_list( $post->ID, 'wcb_session_category', '', _x( ', ', 'Used between list items, there is a space after the comma.', 'wordcamporg' ) );
     1376                $categories_text = '';
     1377                if ( $categories_list ) {
     1378                        $num_categories = count( explode( ', ', $categories_list ) );
     1379                        $categories_text = _n(
     1380                                __( 'Category', 'wordcamporg' ),
     1381                                __( 'Categories', 'wordcamporg' ),
     1382                                $num_categories,
     1383                                'wordcamporg'
     1384                        );
     1385                        $categories_text .= ': ' . $categories_list;
    14301386                }
    14311387
    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>',
    1438                                 _x( 'Categories', 'Used before session category names.', 'wordcamporg' ),
    1439                                 $session_categories_list
    1440                         );
     1388                // Generate meta list for display
     1389                $meta_html = '';
     1390                if( $speaker_text || $time_text || $tracks_text || $slides_text || $video_text || $categories_text ) {
     1391                        ob_start();
     1392                        require_once( __DIR__ . '/views/common/session-meta-data-list.php' );
     1393                        $meta_html = ob_get_clean();
    14411394                }
    14421395
    1443                 return $content . $session_categories_html;
     1396                // Append meta list to the end of the content
     1397                return $content . $meta_html;
    14441398        }
    14451399
     1400
    14461401        /**
    14471402         * Add the sessions's category slugs to the body tag.
    14481403         *