mirror of
https://github.com/WordPress/WordPress.git
synced 2025-02-16 19:46:21 +00:00
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. Built from https://develop.svn.wordpress.org/trunk@54496 git-svn-id: http://core.svn.wordpress.org/trunk@54055 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
1f002b93fe
commit
c11ce53dce
@ -3963,6 +3963,9 @@ class WP_Query {
|
||||
$attachment = array_map( 'strval', (array) $attachment );
|
||||
|
||||
$post_obj = $this->get_queried_object();
|
||||
if ( ! $post_obj ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( in_array( (string) $post_obj->ID, $attachment, true ) ) {
|
||||
return true;
|
||||
@ -3996,6 +3999,9 @@ class WP_Query {
|
||||
}
|
||||
|
||||
$author_obj = $this->get_queried_object();
|
||||
if ( ! $author_obj ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$author = array_map( 'strval', (array) $author );
|
||||
|
||||
@ -4032,6 +4038,9 @@ class WP_Query {
|
||||
}
|
||||
|
||||
$cat_obj = $this->get_queried_object();
|
||||
if ( ! $cat_obj ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$category = array_map( 'strval', (array) $category );
|
||||
|
||||
@ -4068,6 +4077,9 @@ class WP_Query {
|
||||
}
|
||||
|
||||
$tag_obj = $this->get_queried_object();
|
||||
if ( ! $tag_obj ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$tag = array_map( 'strval', (array) $tag );
|
||||
|
||||
@ -4315,6 +4327,9 @@ class WP_Query {
|
||||
}
|
||||
|
||||
$page_obj = $this->get_queried_object();
|
||||
if ( ! $page_obj ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$page = array_map( 'strval', (array) $page );
|
||||
|
||||
@ -4422,6 +4437,9 @@ class WP_Query {
|
||||
}
|
||||
|
||||
$post_obj = $this->get_queried_object();
|
||||
if ( ! $post_obj ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$post = array_map( 'strval', (array) $post );
|
||||
|
||||
@ -4469,6 +4487,9 @@ class WP_Query {
|
||||
}
|
||||
|
||||
$post_obj = $this->get_queried_object();
|
||||
if ( ! $post_obj ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return in_array( $post_obj->post_type, (array) $post_types, true );
|
||||
}
|
||||
|
@ -16,7 +16,7 @@
|
||||
*
|
||||
* @global string $wp_version
|
||||
*/
|
||||
$wp_version = '6.1-beta3-54495';
|
||||
$wp_version = '6.1-beta3-54496';
|
||||
|
||||
/**
|
||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||
|
Loading…
x
Reference in New Issue
Block a user