<?php if ( ! defined( 'ABSPATH' ) ) exit;
* Class for performing actions incrementally. Internally used for converting submissions, exporting submissions, etc.
* Very useful when interacting with large amounts of data.
* @subpackage Classes/Step Processing
* @copyright Copyright (c) 2014, WPNINJAS
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
//Bail if we aren't in the admin.
if ( ! WPN_Helper::is_func_disabled( 'ignore_user_abort' ) ) {
ignore_user_abort( true );
// if ( ! nf_is_func_disabled( 'set_time_limit' ) && ! ini_get( 'safe_mode' ) ) {
// //set_time_limit( 0 );
// Ajax call handled in 'processing' in this file
add_action( 'wp_ajax_nf_' . $this->action, array( $this, 'processing' ) );
* Call the appropriate loading or step functions.
public function processing() {
// Get our passed arguments. These come from the querysting of the processing page.
if ( isset ( $_REQUEST['args'] ) ) {
$this->args = WPN_Helper::sanitize_text_field($_REQUEST['args']);
if ( isset ( $this->args['redirect'] ) ) {
if( wp_validate_redirect( $this->args['redirect'] ) ){
$this->redirect = wp_sanitize_redirect( $this->args['redirect'] );
$this->step = isset ( $_REQUEST['step'] )? esc_html( $_REQUEST['step'] ) : 'loading';
$this->total_steps = isset ( $_REQUEST['total_steps'] )? esc_html( $_REQUEST['total_steps'] ) : 0;
// If our step is loading, then we need to return how many total steps there are along with the next step, which is 1.
if ( 'loading' == $this->step ) {
$return = $this->loading();
if ( ! isset ( $return['step'] ) ) {
$saved_step = get_user_option( 'nf_step_processing_' . $this->action . '_step' );
if ( ! empty ( $saved_step ) ) {
$this->step = $saved_step;
$return['step'] = $this->step;
if ( ! isset ( $return['complete'] ) ) {
$return['complete'] = false;
} else { // We aren't on the loading step, so do our processing.
if ( ! isset ( $return['step'] ) ) {
$return['step'] = $this->step;
if ( ! isset ( $return['complete'] ) ) {
if ( $this->step > $this->total_steps ) {
$return['complete'] = $complete;
$return['total_steps'] = $this->total_steps;
$user_id = get_current_user_id();
if ( $return['complete'] ) {
// Delete our step option
delete_user_option( $user_id, 'nf_step_processing_' . $this->action . '_step' );
// Set our redirect variable.
$return['redirect'] = $this->redirect;
// Run our complete function
// Save our current step so that we can resume if necessary
update_user_option( $user_id, 'nf_step_processing_' . $this->action . '_step', $this->step );
if ( isset ( $this->redirect ) && ! empty ( $this->redirect ) ) {
$this->args['redirect'] = $this->redirect;
$return['errors'] = ( $this->errors ) ? $this->errors : FALSE;
$return['args'] = $this->args;
echo json_encode( $return );
* Run our loading process.
* This function should be overwritten in child classes.
public function loading() {
// This space left intentionally blank.
* This function is called for every step.
* This function should be overwritten in child classes.
// This space left intentionally blank.
* This function is called for every step.
* This function should be overwritten in child classes.
public function complete() {
// This space left intentionally blank.