Skip to content

Commit

Permalink
add queueing actions only when required
Browse files Browse the repository at this point in the history
  • Loading branch information
leonstafford committed Apr 17, 2020
1 parent b8be284 commit 09847fd
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 23 deletions.
2 changes: 1 addition & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
2 changes: 1 addition & 1 deletion src/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
37 changes: 33 additions & 4 deletions src/CoreOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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(
Expand Down
16 changes: 0 additions & 16 deletions src/WordPressAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
}
}

/**
Expand Down
2 changes: 1 addition & 1 deletion wp2static.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 09847fd

Please sign in to comment.