Repository navigation
Stop loading Action Scheduler and turn off Stream's auto-purge #489
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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -39,41 +39,14 @@ function bootstrap() { | |
| add_filter( 'site_option_wp_stream_network', __NAMESPACE__ . '\\default_stream_network_options' ); | ||
| add_filter( 'default_site_option_wp_stream_network', __NAMESPACE__ . '\\default_stream_network_options' ); | ||
| add_action( 'network_admin_menu', __NAMESPACE__ . '\\remove_stream_admin_pages', 11 ); | ||
| add_action( 'admin_menu', __NAMESPACE__ . '\\remove_action_scheduler_menu', 11 ); | ||
| add_action( 'admin_bar_menu', __NAMESPACE__ . '\\override_network_admin_bar_menu', 100 ); | ||
| add_filter( 'wp_stream_record_array', __NAMESPACE__ . '\\filter_wp_stream_record_array', 10, 1 ); | ||
|
|
||
| // Initialise Action Scheduler so Stream can use its API functions (e.g. as_enqueue_async_action). | ||
| // Requiring action-scheduler.php adds hooks on plugins_loaded at priority 0, | ||
| // but we're already past that, so we must manually trigger registration and initialization. | ||
| // The register function name includes the version number (e.g. action_scheduler_register_3_dot_9_dot_3) | ||
| // and changes with each release, so we find it dynamically to avoid breakage on updates. | ||
| require_once Altis\ROOT_DIR . '/vendor/xwp/stream/vendor/woocommerce/action-scheduler/action-scheduler.php'; | ||
| $as_versions = \ActionScheduler_Versions::instance(); | ||
| if ( ! $as_versions->latest_version() ) { | ||
| foreach ( get_defined_functions()['user'] as $func ) { | ||
| if ( strpos( $func, 'action_scheduler_register_' ) === 0 ) { | ||
| call_user_func( $func ); | ||
| break; | ||
| } | ||
| } | ||
| } | ||
| \ActionScheduler_Versions::initialize_latest_version(); | ||
|
|
||
| // Disable the Action Scheduler queue runner cron event unless another plugin needs it. | ||
| // AS is only needed here for Stream's API functions, not for processing queued actions. | ||
| $config = Altis\get_config()['modules']['security']; | ||
| if ( $config['disable-action-scheduler-cron'] ?? true ) { | ||
| add_action( 'init', function () { | ||
| if ( class_exists( 'ActionScheduler', false ) ) { | ||
| remove_action( 'init', [ \ActionScheduler::runner(), 'init' ], 1 ); | ||
| $timestamp = wp_next_scheduled( 'action_scheduler_run_queue', [ 'WP Cron' ] ); | ||
| if ( $timestamp ) { | ||
| wp_unschedule_event( $timestamp, 'action_scheduler_run_queue', [ 'WP Cron' ] ); | ||
| } | ||
| } | ||
| }, 0 ); | ||
| } | ||
| // Records are kept indefinitely in a write-only log, so Stream's purge job has nothing to | ||
| // delete. Stop it being scheduled and don't load Action Scheduler. | ||
| // Stream reads these filters when its plugin file loads, so they must be added first. | ||
| add_filter( 'wp_stream_enable_auto_purge', '__return_false' ); | ||
| add_filter( 'wp_stream_use_action_scheduler', '__return_false' ); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sites that set Could we clear it once, only when no other plugin provides Action Scheduler? The If we鈥檇 rather not ship cleanup code, an upgrade note with Related, and lower impact: the description says Stream clears purge jobs that earlier versions scheduled. That鈥檚 true for WP-Cron. For jobs stored in Action Scheduler鈥檚 tables, Stream only clears them when Action Scheduler鈥檚 functions are loaded (class-admin.php#L1104). Since we no longer load it, those rows stay in the
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The reason someone might set
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I changed the comment above to make it clearer we are disabling the loading of Action scheduler only. The fact we disable auto purge means WP Cron won't get used either, but we don't need to say that.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fair point. Any site that set that flag has its own Action Scheduler handling the event, so it won鈥檛 be orphaned. Happy to drop this. |
||
|
|
||
| require_once Altis\ROOT_DIR . '/vendor/xwp/stream/stream.php'; | ||
| } | ||
|
|
@@ -117,13 +90,6 @@ function remove_stream_admin_pages() { | |
| remove_submenu_page( $wp_stream->admin->records_page_slug, $wp_stream->admin->network->network_settings_page_slug ); | ||
| } | ||
|
|
||
| /** | ||
| * Remove the Action Scheduler admin page. | ||
| */ | ||
| function remove_action_scheduler_menu() { | ||
| remove_submenu_page( 'tools.php', 'action-scheduler' ); | ||
| } | ||
|
|
||
| /** | ||
| * Override the Stream admin bar menu. | ||
| * | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: this is only true of
wp_stream_use_action_scheduler.wp_stream_enable_auto_purgeis read later, on wp_loaded (class-admin.php#L273) and when the purge runs. Maybe: