Making WordPress.org


Ignore:
Timestamp:
04/07/2016 08:54:17 PM (8 years ago)
Author:
iandunn
Message:

WordCamp Post Type: Only query the public post statuses on archives and feeds.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordcamp.org/public_html/wp-content/plugins/wcpt/wcpt-wordcamp/wordcamp-loader.php

    r2898 r2918  
    2525        add_action( 'init',           array( $this, 'register_post_types'    ) );
    2626        add_action( 'init',           array( $this, 'register_post_statuses' ) );
     27        add_filter( 'pre_get_posts',  array( $this, 'query_public_statuses_on_archives' ) );
     28
     29        // todo re-align
    2730    }
    2831
     
    116119            ) );
    117120        }
     121    }
     122
     123    /**
     124     * Only query the public post statuses on WordCamp archives and feeds
     125     *
     126     * By default, any public post statuses are queried when the `post_status` parameter is not explicitly passed
     127     * to WP_Query. This causes central.wordcamp.org/wordcamps/ and central.wordcamp.org/wordcamps/feed/ to display
     128     * camps that are `needs-vetting`, etc, which is not desired.
     129     *
     130     * Another way to fix this would have been to register some of the posts statuses as `private`, but they're not
     131     * consistently used in a public or private way, so that would have had more side effects.
     132     *
     133     * @param WP_Query $query
     134     */
     135    public function query_public_statuses_on_archives( $query ) {
     136        if ( ! $query->is_post_type_archive( WCPT_POST_TYPE_ID ) ) {
     137            return;
     138        }
     139
     140        if ( is_admin() ) {
     141            return;
     142        }
     143
     144        if ( ! empty( $query->query_vars['post_status'] ) ) {
     145            return;
     146        }
     147
     148        $query->query_vars['post_status'] = self::get_public_post_statuses();
    118149    }
    119150
Note: See TracChangeset for help on using the changeset viewer.