Skip to content

Commit

Permalink
using maybe_handle() while checking to see if it is ajax or not seems…
Browse files Browse the repository at this point in the history
… to fix the issue that caused us to need a fork
  • Loading branch information
jonathanstegall committed Sep 9, 2016
1 parent ce39371 commit 6199c58
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 21 deletions.
32 changes: 27 additions & 5 deletions classes/schedule.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function __construct( $wpdb, $version, $login_credentials, $text_domain,
$this->schedulable_classes = $schedulable_classes;

$this->add_filters();
add_action( $this->schedule_name, array( $this, 'call_handler' ) ); // run the handle method
add_action( $this->schedule_name, array( $this, 'maybe_handle' ) ); // run the handle method

}

Expand Down Expand Up @@ -156,10 +156,32 @@ protected function task( $data ) {
return false;
}

public function call_handler() {
// call the handle method in the cron so we can run the queue periodically
$handle = $this->handle();
}
/**
* Maybe process queue
*
* Checks whether data exists within the queue and that
* the process is not already running.
*/
public function maybe_handle( $ajax = FALSE ) {
if ( $this->is_process_running() ) {
// Background process already running.
wp_die();
}

if ( $this->is_queue_empty() ) {
// No data to process.
wp_die();
}

if ( $ajax === TRUE ) {
check_ajax_referer( $this->identifier, 'nonce' );
}

error_log('try to handle it');
$this->handle();

wp_die();
}

/**
* Complete
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
"type": "git"
},
{
"url": "https://github.com/MinnPost/wp-background-processing",
"type": "vcs"
"url": "https://github.com/A5hleyRich/wp-background-processing",
"type": "git"
}
],
"require": {
Expand Down
19 changes: 5 additions & 14 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 6199c58

Please sign in to comment.