Making WordPress.org


Ignore:
Timestamp:
03/04/2021 11:40:35 PM (6 years ago)
Author:
coffee2code
Message:

Handbooks, Handbook: Fix logic for determining if page is handbook landing pages.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/handbook/inc/handbook.php

    r10755 r10763  
    112112                add_filter( 'template_include',                   [ $this, 'template_include' ] );
    113113                add_filter( 'pre_get_posts',                      [ $this, 'pre_get_posts' ] );
     114                add_filter( 'posts_pre_query',                    [ $this, 'posts_pre_query' ], 10, 2 );
    114115                add_action( 'widgets_init',                       [ $this, 'handbook_sidebar' ], 11 ); // After P2
    115116                add_action( 'wporg_email_changes_for_post_types', [ $this, 'wporg_email_changes_for_post_types' ] );
     
    391392
    392393        /**
     394         * Pre-emptively sets the query posts to the handbook landing page when
     395         * appropriate.
     396         *
     397         * @param array $posts    Posts.
     398         * @param WP_Query $query Query object.
     399         * @return array
     400         */
     401        public function posts_pre_query( $posts, $query ) {
     402                if ( $query->is_main_query() && ! $query->is_admin && ! $query->is_search && $query->is_handbook_root ) {
     403                        $posts = [ $query->is_handbook_root ];
     404                }
     405
     406                return $posts;
     407        }
     408
     409        /**
    393410         * Performs query object adjustments for handbook requests prior to querying
    394411         * for posts.
     
    422439                        if ( $page ) {
    423440                                $query->set( 'page_id', $page->ID );
    424                                 $query->is_handbook_root     = true;
     441                                $query->is_handbook_root     = $page;
    425442
    426443                                $query->is_archive           = false;
Note: See TracChangeset for help on using the changeset viewer.