Opened 4 years ago
Closed 4 years ago
#49934 closed defect (bug) (fixed)
PHP Notice: Trying to get property 'name' of non-object in wp-admin/includes/class-wp-site-health.php on line 636
Reported by: | juanlopez4691 | Owned by: | SergeyBiryukov |
---|---|---|---|
Milestone: | 5.5 | Priority: | normal |
Severity: | normal | Version: | 5.2 |
Component: | Site Health | Keywords: | has-patch needs-testing |
Focuses: | Cc: |
Description
Changes in method get_test_theme_version
from class WP_Site_Health
introduced an issue that causes a PHP Notice to be thrown in admin page Tools > Site Health
:
PHP Notice: Trying to get property 'name' of non-object in wp-admin/includes/class-wp-site-health.php on line 636
This could be solved changing line 617 from
$active_theme->parent()->name
To
$active_theme->parent() ? $active_theme->parent()->name : ''
Or to
$active_theme->parent_theme
Same problem happens in line 636, same solution applies.
Attachments (1)
Change History (10)
#2
@
4 years ago
Ah! Thanks a lot @davidbaumwald. Sorry, this is my first attempt to contribute a fix.
But, why the change of version? The reported issue happens because of a change introduced in version 5.4.
#3
@
4 years ago
- Keywords has-patch added; needs-patch removed
- Summary changed from PHP Notice: Trying to get property 'name' of non-object in wp-admin/includes/class-wp-site-health.php on line 636 to PHP Notice: Trying to get property 'name' of non-object in wp-admin/includes/class-wp-site-health.php on line 636
Hi there!
Replicated the same issue when anyone removes the parent theme from the theme directory.
@juanlopez4691 get_test_theme_version() function introduce in version 5.2 that's why @davidbaumwald updated the version.
Added initial patch.
This ticket was mentioned in Slack in #core-site-health by afragen. View the logs.
4 years ago
#7
@
4 years ago
Is the conditional in the patch the best way to test or would it be better as
property_exists( $active_theme, 'parent_theme' ) ? $active_theme->parent_theme : $active_theme->template;
#8
@
4 years ago
It would be helpful to know the exact steps to reproduce the issue, as this code branch only runs if is_child_theme()
is true, but WP_Theme::parent()
only returns false if the current theme is not a child theme.
So it seems like the notice is only issued if the current theme is either broken or not properly configured.
Still, it seems like a good idea to avoid the PHP notice here, as the Themes screen should already give a proper error message for this case.
Hi @juanlopez4691 and welcome to Trac!
I'm removing the
needs-testing
keyword as testing is requested once a patch has been submitted.