Making WordPress.org

Changeset 7319


Ignore:
Timestamp:
06/19/2018 09:44:33 AM (8 years ago)
Author:
obenland
Message:

Developer: Use query_vars correctly.

Props grapplerulrich, johnbillion, SergeyBiryukov.
Fixes #2882.

Location:
sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/inc/extras.php

    r5598 r7319  
    9797 */
    9898function wporg_filter_archive_excerpt( $excerpt ) {
    99         if ( ! is_single() && ! get_query_var( 'is_handbook' ) && 'command' !== get_query_var( 'post_type' ) ) {
     99        if ( ! is_single() && ! $GLOBALS['wp_query']->is_handbook && 'command' !== get_query_var( 'post_type' ) ) {
    100100
    101101                $post_id = get_the_ID();
    … …  
    201201}
    202202add_filter( 'loop_pagination', 'wporg_loop_pagination' );
    203 
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/inc/handbooks.php

    r5681 r7319  
    6363         */
    6464        public static function add_query_vars( $public_query_vars ) {
    65                 $public_query_vars['is_handbook'] = false;
    66                 $public_query_vars['current_handbook'] = false;
    67                 $public_query_vars['current_handbook_home_url'] = false;
    68                 $public_query_vars['current_handbook_name'] = '';
     65                $public_query_vars[] = 'current_handbook';
     66                $public_query_vars[] = 'current_handbook_home_url';
     67                $public_query_vars[] = 'current_handbook_name';
    6968
    7069                return $public_query_vars;
    … …  
    7776         */
    7877        public static function pre_get_posts( $query ) {
    79                 $is_handbook = function_exists( 'wporg_is_handbook' ) ? wporg_is_handbook() : false;
    80                 $query->set( 'is_handbook', $is_handbook );
    81 
    82                 $current_handbook = function_exists( 'wporg_get_current_handbook' ) ? wporg_get_current_handbook() : false;
     78                $query->is_handbook = function_exists( 'wporg_is_handbook' ) && wporg_is_handbook();
     79
     80                $current_handbook = function_exists( 'wporg_get_current_handbook' ) ? (string) wporg_get_current_handbook() : '';
    8381                $query->set( 'current_handbook', $current_handbook );
    8482
    85                 $current_handbook_home_url = function_exists( 'wporg_get_current_handbook_home_url' ) ? wporg_get_current_handbook_home_url() : false;
     83                $current_handbook_home_url = function_exists( 'wporg_get_current_handbook_home_url' ) ? (string) wporg_get_current_handbook_home_url() : '';
    8684                $query->set( 'current_handbook_home_url', $current_handbook_home_url );
    8785
    88                 $current_handbook_name = function_exists( 'wporg_get_current_handbook_name' ) ? wporg_get_current_handbook_name() : '';
     86                $current_handbook_name = function_exists( 'wporg_get_current_handbook_name' ) ? (string) wporg_get_current_handbook_name() : '';
    8987                $query->set( 'current_handbook_name', $current_handbook_name );
    9088        }
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/inc/redirects.php

    r4709 r7319  
    3131        /**
    3232         * Redirects a search query with only one result directly to that result.
     33         *
     34         * @globals \WP_Query $wp_query Global WP_Query instance.
    3335         */
    3436        public static function redirect_single_search_match() {
    35                 if ( is_search() && ! get_query_var( 'is_handbook' ) && 1 == $GLOBALS['wp_query']->found_posts ) {
     37                global $wp_query;
     38
     39                if ( is_search() && ! $wp_query->is_handbook && 1 == $wp_query->found_posts ) {
    3640                        wp_redirect( get_permalink( get_post() ) );
    3741                        exit();
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/inc/search.php

    r5432 r7319  
    2525                add_filter( 'posts_orderby', array( __CLASS__, 'search_posts_orderby' ), 10, 2 );
    2626                add_filter( 'the_posts',     array( __CLASS__, 'rerun_empty_exact_search' ), 10, 2 );
    27                 add_filter( 'query_vars',    array( __CLASS__, 'default_qv_empty_post_type_search' ) );
    28         }
    29 
    30         /**
    31          * Add query var to indicate if no post type filters were explicitly used for
    32          * a search.
    33          *
    34          * Defaults the query var 'empty_post_type_search' to false. It is potentially
    35          * set to true elsewhere.
    36          *
    37          * @param array $public_query_vars The array of whitelisted query variables.
    38          * @return array
    39          */
    40         public static function default_qv_empty_post_type_search( $public_query_vars ) {
    41                 $public_query_vars['empty_post_type_search'] = false;
    42                 return $public_query_vars;
    4327        }
    4428
    … …  
    6044                // Separates searches for handbook pages from non-handbook pages depending on
    6145                // whether the search was performed within context of a handbook page or not.
    62                 if ( get_query_var( 'is_handbook' ) ) {
     46                if ( $query->is_handbook ) {
    6347                        // Search only in current handbook post type.
    6448                        // Just to make sure. post type should already be set.
    … …  
    8367                if ( ! $qv_post_types ) {
    8468                        // Record the fact no post types were explicitly supplied.
    85                         $query->set( 'empty_post_type_search', true );
     69                        $query->is_empty_post_type_search = true;
    8670
    8771                        // Not a handbook page, or exact search, or filters used.
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/search.php

    r3380 r7319  
    1414                        <span><a href="<?php echo home_url( '/' ); ?>"><?php _e( 'Home', 'wporg' ); ?></a></span>
    1515                        <span class="sep">/</span>
    16                         <?php if ( get_query_var( 'is_handbook' ) ) : ?>
     16                        <?php if ( $GLOBALS['wp_query']->is_handbook ) : ?>
    1717                        <span><a href="<?php echo esc_url( get_query_var( 'current_handbook_home_url' ) ); ?>"><?php echo get_query_var( 'current_handbook_name' ); ?></a></span>
    1818                        <?php elseif ( $reference_page = get_page_by_path( 'reference' ) ) : ?>
    … …  
    3232                        <?php while ( have_posts() ) : the_post(); ?>
    3333
    34                                 <?php get_template_part( 'content', get_query_var( 'is_handbook' ) ? 'handbook-archive' : 'reference-archive' ); ?>
     34                                <?php get_template_part( 'content', $GLOBALS['wp_query']->is_handbook ? 'handbook-archive' : 'reference-archive' ); ?>
    3535
    3636                        <?php endwhile; ?>
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/searchform.php

    r4551 r7319  
    3535
    3636        <?php
    37                 $is_handbook = get_query_var( 'is_handbook' );
     37                $is_handbook = $GLOBALS['wp_query']->is_handbook;
    3838                $search_url  = get_query_var( 'current_handbook_home_url' );
    3939                $search_url  = $search_url ? $search_url : home_url( '/' );
    … …  
    6060                                        'wp-parser-method'   => __( 'Methods',   'wporg' ),
    6161                                );
    62                                
    63                                 $qv_post_type = array_filter( (array) get_query_var( 'post_type' ) );   
    64                                 $no_filters   = get_query_var( 'empty_post_type_search' );
     62
     63                                $qv_post_type = array_filter( (array) get_query_var( 'post_type' ) );
     64                                $no_filters   = $GLOBALS['wp_query']->is_empty_post_type_search;
    6565
    6666                                if ( ! is_search() || in_array( 'any', $qv_post_type ) || $no_filters ) {
    … …  
    6868                                        $qv_post_type = array();
    6969                                }
    70                                                
     70
    7171                                foreach ( $search_post_types as $post_type => $label ) {
    7272                                        $checked = checked( in_array( $post_type, $qv_post_type ), true, false );
Note: See TracChangeset for help on using the changeset viewer.