Making WordPress.org

Changeset 7821


Ignore:
Timestamp:
11/04/2018 12:05:24 PM (6 years ago)
Author:
SergeyBiryukov
Message:

Handbook plugin: Correctly determine post type in Handbook Pages widget on search pages with no results.

Fixes #3905.

File:
1 edited

Legend:

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

    r7758 r7821  
    7171        $this->post_types = array_map( array( $this, 'append_suffix' ), $this->post_types );
    7272
    73         if ( in_array( $post->post_type, $this->post_types ) ) {
    74             $args['post_type'] = $post->post_type;
     73        $post_type = '';
     74
     75        if ( $post && in_array( $post->post_type, $this->post_types ) ) {
     76            $post_type = $post->post_type;
     77        } elseif ( is_post_type_archive( $this->post_types ) ) {
     78            $post_type = reset( $this->post_types );
    7579        }
    7680
    77         $post_type_obj = get_post_type_object( $post->post_type );
     81        if ( $post_type ) {
     82            $args['post_type'] = $post_type;
     83        }
     84
     85        $post_type_obj = get_post_type_object( $post_type );
    7886
    7987        if ( current_user_can( $post_type_obj->cap->read_private_posts ) ) {
     
    8290
    8391        // Exclude root handbook page from the table of contents.
    84         $page = get_page_by_path( $this->append_suffix( $post->post_type ), OBJECT, $post->post_type );
     92        $page = get_page_by_path( $this->append_suffix( $post_type ), OBJECT, $post_type );
    8593        if ( ! $page ) {
    86             $slug = substr( $post->post_type, 0, -9 );
    87             $page = get_page_by_path( $slug, OBJECT, $post->post_type );
     94            $slug = substr( $post_type, 0, -9 );
     95            $page = get_page_by_path( $slug, OBJECT, $post_type );
    8896        }
    8997        if ( $page && ! $instance['show_home'] ) {
Note: See TracChangeset for help on using the changeset viewer.