NF_Step_Processing

Class for performing actions incrementally.

Defined (2)

The class is defined in the following location(s).

/deprecated/classes/step-processing.php  
  1. class NF_Step_Processing 
  2.  
  3. /** 
  4. * @var action 
  5. */ 
  6. var $action = ''; 
  7.  
  8. /** 
  9. * @var step 
  10. */ 
  11. var $step = ''; 
  12.  
  13. /** 
  14. * @var total_steps 
  15. */ 
  16. var $total_steps = ''; 
  17.  
  18. /** 
  19. * @var redirect 
  20. */ 
  21. var $redirect = ''; 
  22.  
  23. /** 
  24. * @var array 
  25. */ 
  26. var $errors = array(); 
  27.  
  28. /** 
  29. * @var args 
  30. */ 
  31. var $args = array(); 
  32.  
  33. /** 
  34. * Get things rolling 
  35. *  
  36. * @since 2.7.4 
  37. * @return void 
  38. */ 
  39. function __construct() { 
  40.  
  41. //Bail if we aren't in the admin. 
  42. if ( ! is_admin() ) 
  43. return false; 
  44.  
  45. if ( function_exists( 'ignore_user_abort' ) && ! nf_is_func_disabled( 'ignore_user_abort' ) ) { 
  46. ignore_user_abort( true ); 
  47.  
  48. if ( ! nf_is_func_disabled( 'set_time_limit' ) && ! ini_get( 'safe_mode' ) ) { 
  49. //set_time_limit( 0 ); 
  50.  
  51. add_action( 'wp_ajax_nf_' . $this->action, array( $this, 'processing' ) ); 
  52.  
  53. /** 
  54. * Process our request. 
  55. * Call the appropriate loading or step functions. 
  56. *  
  57. * @since 2.7.6 
  58. * @return void 
  59. */ 
  60. public function processing() { 
  61.  
  62. // Get our passed arguments. These come from the querysting of the processing page. 
  63. if ( isset ( $_REQUEST['args'] ) ) { 
  64. $this->args = $_REQUEST['args']; 
  65. if ( isset ( $this->args['redirect'] ) ) { 
  66. $this->redirect = $this->args['redirect']; 
  67. } else { 
  68. $this->args = array(); 
  69. }  
  70.  
  71. // Get our current step. 
  72. $this->step = isset ( $_REQUEST['step'] )? esc_html( $_REQUEST['step'] ) : 'loading'; 
  73.  
  74. // Get our total steps 
  75. $this->total_steps = isset ( $_REQUEST['total_steps'] )? esc_html( $_REQUEST['total_steps'] ) : 0; 
  76.  
  77. // If our step is loading, then we need to return how many total steps there are along with the next step, which is 1. 
  78. if ( 'loading' == $this->step ) { 
  79. $return = $this->loading(); 
  80. if ( ! isset ( $return['step'] ) ) { 
  81. $saved_step = get_user_option( 'nf_step_processing_' . $this->action . '_step' ); 
  82. if ( ! empty ( $saved_step ) ) { 
  83. $this->step = $saved_step; 
  84. } else { 
  85. $this->step = 1; 
  86.  
  87. $return['step'] = $this->step; 
  88. if ( ! isset ( $return['complete'] ) ) { 
  89. $return['complete'] = false; 
  90. } else { // We aren't on the loading step, so do our processing. 
  91. $return = $this->step(); 
  92. if ( ! isset ( $return['step'] ) ) { 
  93. $this->step++; 
  94. $return['step'] = $this->step; 
  95.  
  96. if ( ! isset ( $return['complete'] ) ) { 
  97. if ( $this->step > $this->total_steps ) { 
  98. $complete = true; 
  99. } else { 
  100. $complete = false; 
  101. $return['complete'] = $complete; 
  102.  
  103. $return['total_steps'] = $this->total_steps; 
  104.  
  105. $user_id = get_current_user_id(); 
  106.  
  107. if ( $return['complete'] ) { 
  108. // Delete our step option 
  109. delete_user_option( $user_id, 'nf_step_processing_' . $this->action . '_step' ); 
  110. // Set our redirect variable. 
  111. $return['redirect'] = $this->redirect; 
  112. // Run our complete function 
  113. $this->complete(); 
  114. } else { 
  115. // Save our current step so that we can resume if necessary 
  116. update_user_option( $user_id, 'nf_step_processing_' . $this->action . '_step', $this->step ); 
  117.  
  118. if ( isset ( $this->redirect ) && ! empty ( $this->redirect ) ) { 
  119. $this->args['redirect'] = $this->redirect; 
  120.  
  121. $return['errors'] = ( $this->errors ) ? $this->errors : FALSE; 
  122.  
  123. $return['args'] = $this->args; 
  124.  
  125. echo json_encode( $return ); 
  126. die(); 
  127.  
  128.  
  129. /** 
  130. * Run our loading process. 
  131. * This function should be overwritten in child classes. 
  132. *  
  133. * @since 2.7.4 
  134. * @return array $args 
  135. */ 
  136. public function loading() { 
  137. // This space left intentionally blank. 
  138.  
  139. /** 
  140. * This function is called for every step. 
  141. * This function should be overwritten in child classes. 
  142. *  
  143. * @since 2.7.4 
  144. * @return array $args 
  145. */ 
  146. public function step() { 
  147. // This space left intentionally blank. 
  148. }  
  149.  
  150. /** 
  151. * This function is called for every step. 
  152. * This function should be overwritten in child classes. 
  153. *  
  154. * @since 2.7.4 
  155. * @return array $args 
  156. */ 
  157. public function complete() { 
  158. // This space left intentionally blank. 
  159.  
  160.  
  161.  
/lib/StepProcessing/step-processing.php  
  1. class NF_Step_Processing 
  2.  
  3. /** 
  4. * @var action 
  5. */ 
  6. var $action = ''; 
  7.  
  8. /** 
  9. * @var step 
  10. */ 
  11. var $step = ''; 
  12.  
  13. /** 
  14. * @var total_steps 
  15. */ 
  16. var $total_steps = ''; 
  17.  
  18. /** 
  19. * @var redirect 
  20. */ 
  21. var $redirect = ''; 
  22.  
  23. /** 
  24. * @var array 
  25. */ 
  26. var $errors = array(); 
  27.  
  28. /** 
  29. * @var args 
  30. */ 
  31. var $args = array(); 
  32.  
  33. /** 
  34. * Get things rolling 
  35. * @since 2.7.4 
  36. * @return void 
  37. */ 
  38. function __construct() { 
  39.  
  40. //Bail if we aren't in the admin. 
  41. if ( ! is_admin() ) 
  42. return false; 
  43.  
  44. if ( ! WPN_Helper::is_func_disabled( 'ignore_user_abort' ) ) { 
  45. ignore_user_abort( true ); 
  46.  
  47. // if ( ! nf_is_func_disabled( 'set_time_limit' ) && ! ini_get( 'safe_mode' ) ) { 
  48. // //set_time_limit( 0 ); 
  49. // } 
  50.  
  51. add_action( 'wp_ajax_nf_' . $this->action, array( $this, 'processing' ) ); 
  52.  
  53. /** 
  54. * Process our request. 
  55. * Call the appropriate loading or step functions. 
  56. * @since 2.7.6 
  57. * @return void 
  58. */ 
  59. public function processing() { 
  60.  
  61. // Get our passed arguments. These come from the querysting of the processing page. 
  62. if ( isset ( $_REQUEST['args'] ) ) { 
  63. $this->args = $_REQUEST['args']; 
  64. if ( isset ( $this->args['redirect'] ) ) { 
  65. $this->redirect = $this->args['redirect']; 
  66. } else { 
  67. $this->args = array(); 
  68.  
  69. // Get our current step. 
  70. $this->step = isset ( $_REQUEST['step'] )? esc_html( $_REQUEST['step'] ) : 'loading'; 
  71.  
  72. // Get our total steps 
  73. $this->total_steps = isset ( $_REQUEST['total_steps'] )? esc_html( $_REQUEST['total_steps'] ) : 0; 
  74.  
  75. // If our step is loading, then we need to return how many total steps there are along with the next step, which is 1. 
  76. if ( 'loading' == $this->step ) { 
  77. $return = $this->loading(); 
  78. if ( ! isset ( $return['step'] ) ) { 
  79. $saved_step = get_user_option( 'nf_step_processing_' . $this->action . '_step' ); 
  80. if ( ! empty ( $saved_step ) ) { 
  81. $this->step = $saved_step; 
  82. } else { 
  83. $this->step = 1; 
  84.  
  85. $return['step'] = $this->step; 
  86. if ( ! isset ( $return['complete'] ) ) { 
  87. $return['complete'] = false; 
  88. } else { // We aren't on the loading step, so do our processing. 
  89. $return = $this->step(); 
  90. if ( ! isset ( $return['step'] ) ) { 
  91. $this->step++; 
  92. $return['step'] = $this->step; 
  93.  
  94. if ( ! isset ( $return['complete'] ) ) { 
  95. if ( $this->step > $this->total_steps ) { 
  96. $complete = true; 
  97. } else { 
  98. $complete = false; 
  99. $return['complete'] = $complete; 
  100.  
  101. $return['total_steps'] = $this->total_steps; 
  102.  
  103. $user_id = get_current_user_id(); 
  104.  
  105. if ( $return['complete'] ) { 
  106. // Delete our step option 
  107. delete_user_option( $user_id, 'nf_step_processing_' . $this->action . '_step' ); 
  108. // Set our redirect variable. 
  109. $return['redirect'] = $this->redirect; 
  110. // Run our complete function 
  111. $this->complete(); 
  112. } else { 
  113. // Save our current step so that we can resume if necessary 
  114. update_user_option( $user_id, 'nf_step_processing_' . $this->action . '_step', $this->step ); 
  115.  
  116. if ( isset ( $this->redirect ) && ! empty ( $this->redirect ) ) { 
  117. $this->args['redirect'] = $this->redirect; 
  118.  
  119. $return['errors'] = ( $this->errors ) ? $this->errors : FALSE; 
  120.  
  121. $return['args'] = $this->args; 
  122.  
  123. echo json_encode( $return ); 
  124. die(); 
  125.  
  126.  
  127. /** 
  128. * Run our loading process. 
  129. * This function should be overwritten in child classes. 
  130. * @since 2.7.4 
  131. * @return array $args 
  132. */ 
  133. public function loading() { 
  134. // This space left intentionally blank. 
  135.  
  136. /** 
  137. * This function is called for every step. 
  138. * This function should be overwritten in child classes. 
  139. * @since 2.7.4 
  140. * @return array $args 
  141. */ 
  142. public function step() { 
  143. // This space left intentionally blank. 
  144.  
  145. /** 
  146. * This function is called for every step. 
  147. * This function should be overwritten in child classes. 
  148. * @since 2.7.4 
  149. * @return array $args 
  150. */ 
  151. public function complete() { 
  152. // This space left intentionally blank. 
  153.  
  154.  
  155.