'finish' ) ); } if ( false === ( $current_array = get_transient( 'batch_' . $id ) ) ) { wp_send_json( array( 'do' => 'finish' ) ); } $result['do'] = ''; $start = time() + 1; $flag = true; while ($flag) { //make array of parameters for function $parameters_array = array(); if ( isset( $current_array['operations'][0][1] ) ) { $parameters_array = $current_array['operations'][0][1]; } $parameters_array[] = &$current_array['context']; //run function call_user_func_array( $current_array['operations'][0][0], $parameters_array ); if ( true == $current_array['context']['finished'] ) { $current_array['context']['sandbox'] = array(); array_splice( $current_array['operations'], 0, 1 ); $current_array['current']++; } if ( time() > $start || 0 == count( $current_array['operations'] ) ) { $flag=false; } } if ( 0 == count( $current_array['operations'] ) ) { $result['do']='finish'; } $result['percent'] = round( $current_array['current'] / ($current_array['count'] / 100 ) ); $result['progress_message'] = str_replace( array( '%current%', '%total%' ), array( $current_array['current'], $current_array['count'] ), __( $current_array['progress_message'], 'batch-operations') ); $result['message'] = $current_array['context']['message']; if ( '' == $result['do'] ) { set_transient( 'batch_' . $id, $current_array , WEEK_IN_SECONDS ); } else { delete_transient( 'batch_' . $id ); } wp_send_json( $result ); } /** * Start batch operations * *
 * $batch = array(
 *   'title' => t('Exporting'),
 *   'operations' => array(
 *     array('my_function_1', array(123, 'qwe')),
 *     array('my_function_2', array()),
 *   ),
 *   'finished' => 'my_finished_callback',
 * );
 *
 * batch_operations_start($batch);
 * 
* *