is_guest && $current_user->user->has_cap( 'manage_options' ) ) ) {
return;
}
// return if there is no task scheduled or it is not for manual.
$task = self::get_scheduled_task();
if ( false === $task || 0 == $task->is_manual ) {
return;
}
// do not show notice on scheduler page.
if ( isset( $_REQUEST['page'] ) && $_REQUEST['page'] == 'wpsc-task-manager' ) { // phpcs:ignore
return;
}
// show notice.
$nonce = wp_create_nonce( 'wpsc_manual_task_manager_' . $task->id );
?>
1,
)
);
return $tasks['total_items'] > 0 ? $tasks['results'][0] : false;
}
/**
* Execute current task
*
* @param WPSC_Scheduled_Task $task - task object.
* @return void
*/
public static function execute_scheduled_task( $task ) {
if ( ! class_exists( $task->class ) || ! method_exists( $task->class, $task->method ) ) {
return;
}
if ( 'yes' === get_transient( 'wpsc_executing_scheduled_task' ) ) {
return;
}
set_transient( 'wpsc_executing_scheduled_task', 'yes', MINUTE_IN_SECONDS * 10 );
call_user_func( array( $task->class, $task->method ), $task );
delete_transient( 'wpsc_executing_scheduled_task' );
}
/**
* Perform manual scheduled task
*
* @return void
*/
public static function perform_manual_scheduler() {
$task_id = isset( $_REQUEST['task'] ) ? intval( $_REQUEST['task'] ) : 0;
check_admin_referer( 'wpsc_manual_task_manager_' . $task_id );
?>
is_manual || $id != $task->id ) {
wp_send_json(
array(
'nonce' => '',
'status' => 'unavailable',
),
200
);
}
// check whether it is already running by background process.
if ( 'yes' === get_transient( 'wpsc_executing_scheduled_task' ) ) {
wp_send_json(
array(
'nonce' => wp_create_nonce( 'wpsc_initialize_scheduled_task' ),
'status' => 'busy',
),
200
);
}
set_transient( 'wpsc_executing_manual_task', 'yes', MINUTE_IN_SECONDS * 10 );
// get page count if count is 0.
if ( $task->pages == 0 ) {
do_action( 'wpsc_execute_scheduled_task', $task );
$task = new WPSC_Scheduled_Task( $id );
if ( ! $task->id ) {
delete_transient( 'wpsc_executing_manual_task' );
wp_send_json(
array(
'nonce' => '',
'status' => 'unavailable',
),
200
);
}
}
// return pages.
wp_send_json(
array(
'nonce' => wp_create_nonce( 'wpsc_run_manual_task' ),
'status' => 'success',
'pages' => $task->pages,
'pbText' => $task->progressbar_text,
),
200
);
}
/**
* Run manual task callback
*
* @return void
*/
public static function run_manual_task() {
if ( check_ajax_referer( 'wpsc_run_manual_task', '_ajax_nonce', false ) != 1 ) {
wp_send_json_error( 'Unauthorized request!', 400 );
}
if ( ! WPSC_Functions::is_site_admin() ) {
wp_send_json_error( 'Unauthorized access!', 401 );
}
$id = isset( $_POST['task_id'] ) ? intval( $_POST['task_id'] ) : 0;
if ( ! $id ) {
wp_send_json_error( 'Incorrect request!', 400 );
}
// return if there is no task scheduled or it is not for manual or task does not match.
$task = self::get_scheduled_task();
if ( false === $task || 0 == $task->is_manual || $id != $task->id ) {
delete_transient( 'wpsc_executing_manual_task' );
wp_send_json(
array(
'nonce' => '',
'status' => 'unavailable',
),
200
);
}
// execute task.
do_action( 'wpsc_execute_scheduled_task', $task );
// check whether it is finished.
$task = new WPSC_Scheduled_Task( $id );
if ( ! $task->id ) {
delete_transient( 'wpsc_executing_manual_task' );
wp_send_json(
array(
'nonce' => '',
'status' => 'unavailable',
),
200
);
}
// return success.
wp_send_json(
array(
'nonce' => wp_create_nonce( 'wpsc_run_manual_task' ),
'status' => 'success',
),
200
);
}
}
endif;
WPSC_Task_Scheduler::init();