WordPress.org

Make WordPress Core

#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)

49934.patch (1.2 KB) - added by mukesh27 20 months ago.
Initial patch.

Download all attachments as: .zip

Change History (10)

#1 @davidbaumwald
20 months ago

  • Keywords needs-testing removed
  • Version changed from 5.4 to 5.2

Hi @juanlopez4691 and welcome to Trac!

I'm removing the needs-testing keyword as testing is requested once a patch has been submitted.

#2 @juanlopez4691
20 months ago

Ah! Thanks a lot @davidbaumwald. Sorry, this is my first attempt to contribute a fix.

But, why the change of version? This happens because of a change introduced in version 5.4.

Version 2, edited 20 months ago by juanlopez4691 (previous) (next) (diff)

#3 @mukesh27
20 months 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.

@mukesh27
20 months ago

Initial patch.

#4 @mukesh27
20 months ago

  • Keywords needs-testing added

#5 @SergeyBiryukov
20 months ago

  • Milestone changed from Awaiting Review to 5.5

This ticket was mentioned in Slack in #core-site-health by afragen. View the logs.


19 months ago

#7 @afragen
19 months 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 @SergeyBiryukov
19 months 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.

#9 @SergeyBiryukov
19 months ago

  • Owner set to SergeyBiryukov
  • Resolution set to fixed
  • Status changed from new to closed

In 47815:

Site Health: Use WP_Theme::parent() in the inactive themes test as a more reliable check that the parent theme exists.

This is also more consistent with the other instances of directly referencing WP_Theme::parent() properties or methods in core.

Props mukesh27, juanlopez4691, davidbaumwald, afragen, SergeyBiryukov.
Fixes #49934.

Note: See TracTickets for help on using tickets.