[wp-trac] [WordPress Trac] #50925: Function is_page() produce error on the front pages
WordPress Trac
noreply at wordpress.org
Wed Aug 12 06:43:05 UTC 2020
#50925: Function is_page() produce error on the front pages
--------------------------+-----------------------------
Reporter: ivijanstefan | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: General | Version: 5.4.2
Severity: normal | Keywords: has-patch
Focuses: |
--------------------------+-----------------------------
The **''is_page()''** function suddenly creates a problem on certain
installations because it does not find the ''ID'', ''post_title'', and
''post_name'' objects.
{{{
Notice: Trying to get property 'ID' of non-object in /home/wp-includes
/class-wp-query.php on line 3996
Notice: Trying to get property 'post_title' of non-object in /home/wp-
includes/class-wp-query.php on line 3998
Notice: Trying to get property 'post_name' of non-object in /home/wp-
includes/class-wp-query.php on line 4000
}}}
This means that the object from **''get_queried_object()''** was NULL.
It would be good to fix it like this:
{{{#!php
<?php
public function is_page( $page = '' ) {
if ( ! $this->is_page ) {
return false;
}
if ( empty( $page ) ) {
return true;
}
$page_obj = $this->get_queried_object();
if(!$page_obj) return false; /*** FIX ***/
$page = array_map( 'strval', (array) $page );
if ( in_array( (string) $page_obj->ID, $page ) ) {
return true;
} elseif ( in_array( $page_obj->post_title, $page ) ) {
return true;
} elseif ( in_array( $page_obj->post_name, $page ) ) {
return true;
} else {
foreach ( $page as $pagepath ) {
if ( ! strpos( $pagepath, '/' ) ) {
continue;
}
$pagepath_obj = get_page_by_path( $pagepath );
if ( $pagepath_obj && ( $pagepath_obj->ID ==
$page_obj->ID ) ) {
return true;
}
}
}
return false;
}
}}}
This problem is only shown on the front page, while all other pages are
working normally.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/50925>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list