[BUG] Attempt to read property “id” on null – media-modal.php on line 102

I have Meta Box 5.7.1 installed as a requirement of a WordPress theme.

error_log has lots of lines like this:

PHP Warning: Attempt to read property “id” on null in /{path}/wp-content/plugins/meta-box/inc/media-modal.php on line 102

I don’t know whether this is due to how the theme is using the plugin or a bug in the plugin. However from the WordPress documentation get_current_screen() can return null or WP_Screen and it seems that the plugin code is not allowing for null. As a temporary fix I have changed the code to:

private function is_attachment_edit_screen(): bool {
if (get_current_screen()) {
return get_current_screen()->id === ‘attachment’;
}
return false;
}

Hopefully this can be fixed in a future release. Thank you.

  • This topic was modified 17 hours, 45 minutes ago by paulstenning. Reason: Added [BUG] to title
  • This topic was modified 17 hours, 45 minutes ago by paulstenning.

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer