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
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_notice
in settings.php the first if statement callsstrpos
with 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:
https://github.com/10up/distributor/blob/14b56e62e5c0dbef76be206b52101e5025131958/includes/settings.php#L122-L128
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 theadmin_notices
action earlier than usual because the$current_screen
global only gets constructed after theadmin_head
action is triggered (and beforeadmin_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 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.php
to 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:
https://github.com/10up/distributor/assets/6644396/e774a11a-b097-4950-bd34-4a9bf4c29fbc
Environment information
WordPress information
Code of Conduct