Making WordPress.org

Changeset 1295


Ignore:
Timestamp:
02/23/2015 11:42:33 PM (10 years ago)
Author:
iandunn
Message:

WordCamp Post Types: Prevent duplicate avatars on [speakers] page.

r933 and r935 added functionality to display extra information on single speaker/session posts, and attempted to make sure that it only appeared on those posts by checking $post->post_type.

That resulted in a bug where the extra info would also be added to regular pages that contained the [speakers] or [sessions] shortcodes, because in that context $post would refer to the current post in the secondary loop, rather than the page from the main loop.

File:
1 edited

Legend:

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

    r1292 r1295  
    10591059
    10601060    /**
     1061     * Determine if the current loop is just a single page, or a loop of posts within a page
     1062     *
     1063     * For example, this helps to target a single wcb_speaker post vs a page containing the [speakers] shortcode,
     1064     * which loops through wcb_speaker posts. Using functions like is_single() don't work, because they reference
     1065     * the main query instead of the $speakers query.
     1066     *
     1067     * @param string $post_type
     1068     *
     1069     * @return bool
     1070     */
     1071    protected function is_single_cpt_post( $post_type ) {
     1072        global $wp_query;
     1073
     1074        return isset( $wp_query->query[ $post_type ] ) && $post_type == $wp_query->query['post_type'];
     1075    }
     1076
     1077    /**
    10611078     * Add the speaker's avatar to their post
    10621079     *
     
    10721089        $enabled_site_ids = apply_filters( 'wcpt_speaker_post_avatar_enabled_site_ids', array( 364 ) );    // 2014.sf
    10731090
    1074         if ( 'wcb_speaker' !== $post->post_type ) {
     1091        if ( ! $this->is_single_cpt_post( 'wcb_speaker') ) {
    10751092            return $content;
    10761093        }
     
    11001117        $enabled_site_ids = apply_filters( 'wcpt_session_post_speaker_info_enabled_site_ids', array( 364 ) );    // 2014.sf
    11011118
    1102         if ( 'wcb_session' !== $post->post_type ) {
     1119        if ( ! $this->is_single_cpt_post( 'wcb_session') ) {
    11031120            return $content;
    11041121        }
     
    11651182        $enabled_site_ids = apply_filters( 'wcpt_speaker_post_session_info_enabled_site_ids', array( 364 ) );    // 2014.sf
    11661183
    1167         if ( 'wcb_speaker' !== $post->post_type ) {
     1184        if ( ! $this->is_single_cpt_post( 'wcb_speaker') ) {
    11681185            return $content;
    11691186        }
Note: See TracChangeset for help on using the changeset viewer.