Make WordPress Core

Changeset 54496

Timestamp:
10/11/2022 06:13:34 PM (22 months ago)
Author:
SergeyBiryukov
Message:

Query: Avoid PHP notices when get_queried_object() returns null.

WP_Query methods assume that get_queried_object() would return a non-null value, which is not always the case.

This commit resolves various warnings in WP_Query along the lines of:

Attempt to read property "post_type" on null in wp-includes/class-wp-query.php on line 4338

Follow-up to [1728], [3639], [8807], [49119].

Props dd32, yellyc, boonebgorges, darkskipper, Howdy_McGee, swissspidy, nacin, mikeschroder, mikejolley, sterlo, datainterlock, utsavmadaan823, kanlukasz, woji29911, hellofromTonya, zikubd, deksar, bwbama, noplanman, nouarah, SergeyBiryukov.
Fixes #29660.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-query.php

    r54464 r54496  
    39643964
    39653965        $post_obj = $this->get_queried_object();
     3966
     3967
     3968
    39663969
    39673970        if ( in_array( (string) $post_obj->ID, $attachment, true ) ) {
     
    39974000
    39984001        $author_obj = $this->get_queried_object();
     4002
     4003
     4004
    39994005
    40004006        $author = array_map( 'strval', (array) $author );
     
    40334039
    40344040        $cat_obj = $this->get_queried_object();
     4041
     4042
     4043
    40354044
    40364045        $category = array_map( 'strval', (array) $category );
     
    40694078
    40704079        $tag_obj = $this->get_queried_object();
     4080
     4081
     4082
    40714083
    40724084        $tag = array_map( 'strval', (array) $tag );
     
    43164328
    43174329        $page_obj = $this->get_queried_object();
     4330
     4331
     4332
    43184333
    43194334        $page = array_map( 'strval', (array) $page );
     
    44234438
    44244439        $post_obj = $this->get_queried_object();
     4440
     4441
     4442
    44254443
    44264444        $post = array_map( 'strval', (array) $post );
     
    44704488
    44714489        $post_obj = $this->get_queried_object();
     4490
     4491
     4492
    44724493
    44734494        return in_array( $post_obj->post_type, (array) $post_types, true );
  • trunk/tests/phpunit/tests/query.php

    r54464 r54496  
    789789        $this->assertFalse( is_post_type_archive( $post_type ) );
    790790    }
     791
     792
     793
     794
     795
     796
     797
     798
     799
     800
     801
     802
     803
     804
     805
     806
     807
     808
     809
     810
     811
     812
     813
     814
     815
     816
     817
     818
     819
     820
     821
     822
     823
     824
     825
     826
     827
     828
     829
     830
     831
     832
     833
     834
     835
     836
     837
     838
     839
     840
     841
     842
     843
     844
     845
     846
     847
     848
     849
     850
     851
     852
     853
     854
     855
     856
     857
     858
     859
     860
     861
     862
     863
     864
     865
     866
     867
     868
     869
     870
     871
     872
     873
     874
     875
     876
     877
     878
     879
     880
     881
     882
     883
     884
     885
     886
     887
     888
     889
     890
     891
     892
     893
     894
     895
     896
     897
     898
     899
    791900}
Note: See TracChangeset for help on using the changeset viewer.