From 09847fdc92faa82ab4ddd9375b17aaebb1aec580 Mon Sep 17 00:00:00 2001 From: Leon Date: Fri, 17 Apr 2020 14:45:49 +0930 Subject: [PATCH] add queueing actions only when required --- readme.txt | 2 +- src/Controller.php | 2 +- src/CoreOptions.php | 37 +++++++++++++++++++++++++++++++++---- src/WordPressAdmin.php | 16 ---------------- wp2static.php | 2 +- 5 files changed, 36 insertions(+), 23 deletions(-) diff --git a/readme.txt b/readme.txt index 5503e0603..7f5a1c649 100755 --- a/readme.txt +++ b/readme.txt @@ -4,7 +4,7 @@ Tags: security, performance, static Requires at least: 4.0 Tested up to: 5.4 Requires PHP: 7.2 -Stable tag: 7.0-alpha-006 +Stable tag: 7.0-alpha-007 Static site generator functionality for WordPress. diff --git a/src/Controller.php b/src/Controller.php index 06330e591..1bfa8e282 100755 --- a/src/Controller.php +++ b/src/Controller.php @@ -8,7 +8,7 @@ use WP_Post; class Controller { - const WP2STATIC_VERSION = '7.0-alpha-006'; + const WP2STATIC_VERSION = '7.0-alpha-007'; /** * @var string diff --git a/src/CoreOptions.php b/src/CoreOptions.php index c2cf17dc1..e609c937a 100755 --- a/src/CoreOptions.php +++ b/src/CoreOptions.php @@ -406,18 +406,49 @@ public static function savePosted( string $screen = 'core' ) : void { break; case 'jobs': + $queue_on_post_save = isset( $_POST['queueJobOnPostSave'] ) ? 1 : 0; + $queue_on_post_delete = isset( $_POST['queueJobOnPostDelete'] ) ? 1 : 0; + $wpdb->update( $table_name, - [ 'value' => isset( $_POST['queueJobOnPostSave'] ) ? 1 : 0 ], + [ 'value' => $queue_on_post_save ], [ 'name' => 'queueJobOnPostSave' ] ); $wpdb->update( $table_name, - [ 'value' => isset( $_POST['queueJobOnPostDelete'] ) ? 1 : 0 ], + [ 'value' => $queue_on_post_delete ], [ 'name' => 'queueJobOnPostDelete' ] ); + if ( $queue_on_post_save ) { + add_action( + 'save_post', + [ 'WP2Static\Controller', 'wp2static_save_post_handler' ], + 0 + ); + } else { + remove_action( + 'save_post', + [ 'WP2Static\Controller', 'wp2static_save_post_handler' ], + 0 + ); + } + + if ( $queue_on_post_delete ) { + add_action( + 'trashed_post', + [ 'WP2Static\Controller', 'wp2static_trashed_post_handler' ], + 0 + ); + } else { + remove_action( + 'trashed_post', + [ 'WP2Static\Controller', 'wp2static_trashed_post_handler' ], + 0 + ); + } + $process_queue_interval = isset( $_POST['processQueueInterval'] ) ? $_POST['processQueueInterval'] : 0; @@ -428,8 +459,6 @@ public static function savePosted( string $screen = 'core' ) : void { [ 'name' => 'processQueueInterval' ] ); - // TODO: this looks like odd value passed in - // TODO: this WPCron method prints output in error_log WPCron::setRecurringEvent( $process_queue_interval ); $wpdb->update( diff --git a/src/WordPressAdmin.php b/src/WordPressAdmin.php index d89a0f331..f0da27c6f 100755 --- a/src/WordPressAdmin.php +++ b/src/WordPressAdmin.php @@ -202,22 +202,6 @@ public static function registerHooks( string $bootstrap_file ) : void { 2 ); } - - if ( CoreOptions::getValue( 'queueJobOnPostSave' ) ) { - add_action( - 'save_post', - [ 'WP2Static\Controller', 'wp2static_save_post_handler' ], - 0 - ); - } - - if ( CoreOptions::getValue( 'queueJobOnPostDelete' ) ) { - add_action( - 'trashed_post', - [ 'WP2Static\Controller', 'wp2static_trashed_post_handler' ], - 0 - ); - } } /** diff --git a/wp2static.php b/wp2static.php index 2df4e0c58..2ed8854ae 100755 --- a/wp2static.php +++ b/wp2static.php @@ -3,7 +3,7 @@ * Plugin Name: WP2Static * Plugin URI: https://wp2static.com * Description: Static site generator functionality for WordPress. - * Version: 7.0-alpha-006 + * Version: 7.0-alpha-007 * Author: WP2Static * Author URI: https://wp2static.com * Text Domain: static-html-output-plugin