You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In the function maybe_notice in settings.php the first if statement calls strpos with the first parameter being the result of a call to get_current_screen(), however since get_current_screen()can return null and this call has no null coalescing operator it can lead to this deprecation notice on WordPress admin pages:
PHP Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in <abspath>/wp-content/plugins/distributor/includes/settings.php on line 128
if ( 0 === strpos( get_current_screen()->parent_base, 'distributor' ) ) {
This issue only occurs when certain plugins & themes (specifically GravityForms 2.8.1, for me in this case) hook into the admin_head action and trigger the admin_notices action earlier than usual because the $current_screen global only gets constructed after the admin_head action is triggered (and before admin_notices is triggered).
A quick & dirty fix is to add a null coalescing fallback to empty string on that first parameter like below, however something more robust can be discussed in a PR:
I'm unsure how many other plugins & themes trigger this issue or if it's just GravityForms, regardless since null is a documented return value for get_current_screen() that if statement should be refactored to account for it. I can create a PR for that fix & follow-up if this sounds like a valid issue.
Steps to Reproduce
To trigger this issue without a specific plugin/theme:
Install & activate Distributor (v2.0.2)
Add the following to your theme's functions.php to simulate an early call admin_notices:
Describe the bug
In the function
maybe_noticein settings.php the first if statement callsstrposwith the first parameter being the result of a call toget_current_screen(), however sinceget_current_screen()can return null and this call has no null coalescing operator it can lead to this deprecation notice on WordPress admin pages:Code in question:
distributor/includes/settings.php
Lines 122 to 128 in 14b56e6
This issue only occurs when certain plugins & themes (specifically GravityForms 2.8.1, for me in this case) hook into the
admin_headaction and trigger theadmin_noticesaction earlier than usual because the$current_screenglobal only gets constructed after theadmin_headaction is triggered (and beforeadmin_noticesis triggered).A quick & dirty fix is to add a null coalescing fallback to empty string on that first parameter like below, however something more robust can be discussed in a PR:
I'm unsure how many other plugins & themes trigger this issue or if it's just GravityForms, regardless since
nullis a documented return value forget_current_screen()that if statement should be refactored to account for it. I can create a PR for that fix & follow-up if this sounds like a valid issue.Steps to Reproduce
To trigger this issue without a specific plugin/theme:
functions.phpto simulate an early calladmin_notices:To trigger this issue with GravityForms:
/wp-admin/admin.php?page=gf_edit_forms)Screenshots, screen recording, code snippet
Issue demonstration with GravityForms:
distributor-issue-gravityforms.mp4
Environment information
WordPress information
Code of Conduct