Making WordPress.org

Changeset 6227


Ignore:
Timestamp:
12/03/2017 10:25:24 PM (9 years ago)
Author:
coreymckrill
Message:

WordCamp Post Types: Append session categories to their post content.

Also add session category term slugs to body classes.

Props Kau-Boy
Fixes #3035

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordcamp.org/public_html/wp-content/plugins/wc-post-types/wc-post-types.php

    r6213 r6227  
    5151                add_shortcode( 'schedule', array( $this, 'shortcode_schedule' ) );
    5252
     53                add_filter( 'body_class', array( $this, 'session_category_slugs_to_body_tag' ) );
     54
    5355                add_filter( 'the_content', array( $this, 'add_avatar_to_speaker_posts' ) );
    5456                add_filter( 'the_content', array( $this, 'add_speaker_info_to_session_posts' ) );
    5557                add_filter( 'the_content', array( $this, 'add_slides_info_to_session_posts' ) );
    5658                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' ) );
    5760                add_filter( 'the_content', array( $this, 'add_session_info_to_speaker_posts' ) );
    5861
    … …  
    14111414
    14121415                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;
     1430                }
     1431
     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                        );
     1441                }
     1442
     1443                return $content . $session_categories_html;
     1444        }
     1445
     1446        /**
     1447         * Add the sessions's category slugs to the body tag.
     1448         *
     1449         * @param array $body_classes
     1450         *
     1451         * @return array
     1452         */
     1453        function session_category_slugs_to_body_tag( $body_classes ) {
     1454                if ( 'wcb_session' === get_post_type() ) {
     1455                        $session_categories = get_the_terms( get_post(), 'wcb_session_category' );
     1456
     1457                        if ( is_array( $session_categories ) ) {
     1458                                foreach ( $session_categories as $session_category ) {
     1459                                        $body_classes[] = 'wcb_session_category-' . $session_category->slug;
     1460                                }
     1461                        }
     1462                }
     1463
     1464                return $body_classes;
    14131465        }
    14141466
    … …  
    21472199                register_taxonomy( 'wcb_session_category', 'wcb_session', array(
    21482200                        'labels'       => $labels,
    2149                         'rewrite'      => array( 'slug' => 'session_category' ),
     2201                        'rewrite'      => array( 'slug' => 'session-category' ),
    21502202                        'query_var'    => 'session_category',
    21512203                        'hierarchical' => true,
Note: See TracChangeset for help on using the changeset viewer.