Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHP Warning when $this->push_syndicate_settings is still set to null #162

Open
terriann opened this issue Sep 28, 2022 · 0 comments
Open

Comments

@terriann
Copy link

Description:

There is an assumption that the init hook will run before the cron_schedules hook, but if another plugin, the theme or an mu-plugin calls the function wp_get_schedules() before the the init hook fires (typically by calling it outside of the context of any hooks), the following warning gets logged:

PHP message: Warning: Trying to access array offset on value of type null in /var/www/wp-content/plugins/push-syndication/includes/class-wp-push-syndication-server.php on line 1227

The cause is $this->push_syndicate_settings being null when WP_Push_Syndication_Server::cron_add_pull_time_interval() is called

public function cron_add_pull_time_interval( $schedules ) {
// Adds the custom time interval to the existing schedules.
$schedules['syn_pull_time_interval'] = array(
'interval' => intval( $this->push_syndicate_settings['pull_time_interval'] ),
'display' => __( 'Pull Time Interval', 'push-syndication' )
);

As far as I can tell this does not create a functional problem with the Syndication plugin, but the warning can cause noise in logs which can make it more difficult to find important log messages.

Workaround:

As a workaround, a defensive check can be added to the plugin:

	public function cron_add_pull_time_interval( $schedules ) {

+		// Only add custom interval if syndication settings are defined.
+		if (
+  		  empty( $this->push_syndicate_settings )
+		  || ! array_key_exists( 'pull_time_interval', $this->push_syndicate_settings )
+		) {
+			return $schedules;
+		}
+
		// Adds the custom time interval to the existing schedules.
		$schedules['syn_pull_time_interval'] = array(
			'interval' => intval( $this->push_syndicate_settings['pull_time_interval'] ),
			'display' => __( 'Pull Time Interval', 'push-syndication' )
		);

		return $schedules;

	}

Steps to Reproduce:

This can be reproduced when installing the Syndication plugin on a plain WordPress installation and calling the wp_get_schedules(); outside of any hooks in the default theme's functions.php. Then load any front or backend page and the error will be logged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant