Describe the bug
CRP triggers a warning when using the network admin panel.
PHP Warning: Attempt to read property "settings_page" on null in /var/www/public/wp-content/plugins/contextual-related-posts/includes/admin/settings/class-settings.php on line 1303
To Reproduce
Steps to reproduce the behavior:
Open Network Admin (Multisite)
observe error logs
Expected behavior
No warning should be triggered.
The problem stems from settings_api being initalized in initialise_settings() which is hooked to admin_menu. admin_menu is not being fired on network admin requests, it's called network_admin_menu in that context. However, admin_enqueue_scripts still fires in network admin, which leaves us with an uninitialized settings_api, generating a warning in if ( $this->settings_api->settings_page !== $hook ) {.
I suggest to either initialize the settings also on network_admin_menu if there might be any settings in network admin, to check for the environment (i.e. if ( is_multisite() && is_network_admin() ) { return; } in admin_enqueue_scripts($hook), or to check whether settings_api is defined, i.e. if ( $this->settings_api && $this->settings_api->settings_page !== $hook ) {.
Describe the bug CRP triggers a warning when using the network admin panel.
PHP Warning: Attempt to read property "settings_page" on null in /var/www/public/wp-content/plugins/contextual-related-posts/includes/admin/settings/class-settings.php on line 1303
To Reproduce Steps to reproduce the behavior:
Expected behavior No warning should be triggered.
The problem stems from settings_api being initalized in
initialise_settings()
which is hooked toadmin_menu
.admin_menu
is not being fired on network admin requests, it's callednetwork_admin_menu
in that context. However,admin_enqueue_scripts
still fires in network admin, which leaves us with an uninitialized settings_api, generating a warning inif ( $this->settings_api->settings_page !== $hook ) {
.I suggest to either initialize the settings also on
network_admin_menu
if there might be any settings in network admin, to check for the environment (i.e.if ( is_multisite() && is_network_admin() ) { return; }
inadmin_enqueue_scripts($hook)
, or to check whether settings_api is defined, i.e.if ( $this->settings_api && $this->settings_api->settings_page !== $hook ) {
.