$settings['sheet_url'], 'total' => 0, 'trigger' => 'scheduled', ) ); SteadyPost_History::add( $run_id, array( array( 'row' => 0, 'status' => 'error', 'title' => __( 'Could not read the sheet', 'steadypost' ), 'post_id' => 0, 'message' => $sheet->get_error_message(), 'notes' => array(), ), ), true ); return; } $rows = array_values( array_filter( $sheet['rows'], function ( $row ) use ( $settings ) { $gate = SteadyPost_Importer::gate_check( $row, $settings ); return $gate['ok']; } ) ); $run_id = wp_generate_uuid4(); SteadyPost_History::start( $run_id, array( 'source' => $settings['sheet_url'], 'total' => count( $rows ), 'trigger' => 'scheduled', ) ); set_transient( self::RUN_PREFIX . $run_id, $rows, DAY_IN_SECONDS ); self::resume( $run_id, 0 ); } public static function resume( $run_id, $offset ) { $rows = get_transient( self::RUN_PREFIX . $run_id ); if ( ! is_array( $rows ) ) { return; } $settings = SteadyPost_Settings::all(); $settings['skip_unchanged'] = ! empty( $settings['sync_skip_unchanged'] ); // Cron runs without a logged-in user, but the importer checks // capabilities (edit_post on a targeted post, unfiltered_html for // content). Act as the configured default author. wp_set_current_user( (int) $settings['default_author'] ); $started = microtime( true ); $total = count( $rows ); $results = array(); while ( $offset < $total && ( microtime( true ) - $started ) < self::TIME_BUDGET ) { $results[] = SteadyPost_Importer::import_row( $rows[ $offset ], $settings ); ++$offset; } $done = $offset >= $total; SteadyPost_History::add( $run_id, $results, $done ); if ( $done ) { delete_transient( self::RUN_PREFIX . $run_id ); return; } wp_schedule_single_event( time() + 30, self::CONTINUE_HOOK, array( $run_id, $offset ) ); } }