wpsc_preload_settings()WPSCache 1.0

No Hooks.

Return

null. Nothing (null).

Usage

wpsc_preload_settings( $min_refresh_interval );
$min_refresh_interval **
-
Default: 'NA'

wpsc_preload_settings() code WPSCache 1.12.1

<?php
function wpsc_preload_settings( $min_refresh_interval = 'NA' ) {
	global $wp_cache_preload_interval, $wp_cache_preload_on, $wp_cache_preload_taxonomies, $wp_cache_preload_email_me, $wp_cache_preload_email_volume, $wp_cache_preload_posts, $wpdb;

	if ( isset( $_POST[ 'action' ] ) == false || $_POST[ 'action' ] != 'preload' )
		return;

	if ( isset( $_POST[ 'preload_off' ] ) ) {
		wpsc_cancel_preload();
		return;
	} elseif ( isset( $_POST[ 'preload_now' ] ) ) {
		wpsc_enable_preload();
		wpsc_update_idle_preload();
		?>
		<div class="notice notice-warning">
			<h4><?php esc_html_e( 'Preload has been activated', 'wp-super-cache' ); ?></h4>
		</div>
		<?php
		return;
	}

	if ( $min_refresh_interval == 'NA' ) {
		$count = wpsc_post_count();
		if ( $count > 1000 ) {
			$min_refresh_interval = 720;
		} else {
			$min_refresh_interval = 30;
		}
	}

	// Set to true if the preload interval is changed, and a reschedule is required.
	$force_preload_reschedule = false;

	if ( isset( $_POST[ 'wp_cache_preload_interval' ] ) && ( $_POST[ 'wp_cache_preload_interval' ] == 0 || $_POST[ 'wp_cache_preload_interval' ] >= $min_refresh_interval ) ) {
		$_POST[ 'wp_cache_preload_interval' ] = (int)$_POST[ 'wp_cache_preload_interval' ];
		if ( $wp_cache_preload_interval != $_POST[ 'wp_cache_preload_interval' ] ) {
			$force_preload_reschedule = true;
		}

		// phpcs:ignore WordPress.Security.NonceVerification.Missing
		$wp_cache_preload_interval = (int) $_POST['wp_cache_preload_interval'];
		wp_cache_setting( 'wp_cache_preload_interval', $wp_cache_preload_interval );
	}

	if ( $_POST[ 'wp_cache_preload_posts' ] == 'all' ) {
		$wp_cache_preload_posts = 'all';
	} else {
		$wp_cache_preload_posts = (int)$_POST[ 'wp_cache_preload_posts' ];
	}
	wp_cache_setting( 'wp_cache_preload_posts', $wp_cache_preload_posts );

	if ( isset( $_POST[ 'wp_cache_preload_email_volume' ] ) && in_array( $_POST[ 'wp_cache_preload_email_volume' ], array( 'none', 'less', 'medium', 'many' ) ) ) {
		$wp_cache_preload_email_volume = $_POST[ 'wp_cache_preload_email_volume' ];
	} else {
		$wp_cache_preload_email_volume = 'none';
	}
	wp_cache_setting( 'wp_cache_preload_email_volume', $wp_cache_preload_email_volume );

	if ( $wp_cache_preload_email_volume == 'none' )
		wp_cache_setting( 'wp_cache_preload_email_me', 0 );
	else
		wp_cache_setting( 'wp_cache_preload_email_me', 1 );

	if ( isset( $_POST[ 'wp_cache_preload_taxonomies' ] ) ) {
		$wp_cache_preload_taxonomies = 1;
	} else {
		$wp_cache_preload_taxonomies = 0;
	}
	wp_cache_setting( 'wp_cache_preload_taxonomies', $wp_cache_preload_taxonomies );

	if ( isset( $_POST[ 'wp_cache_preload_on' ] ) ) {
		$wp_cache_preload_on = 1;
	} else {
		$wp_cache_preload_on = 0;
	}
	wp_cache_setting( 'wp_cache_preload_on', $wp_cache_preload_on );

	// Ensure that preload settings are applied to scheduled cron.
	$next_preload    = wp_next_scheduled( 'wp_cache_full_preload_hook' );
	$should_schedule = ( $wp_cache_preload_on === 1 && $wp_cache_preload_interval > 0 );

	// If forcing a reschedule, or preload is disabled, clear the next scheduled event.
	if ( $next_preload && ( ! $should_schedule || $force_preload_reschedule ) ) {
		wp_cache_debug( 'Clearing old preload event' );
		wpsc_reset_preload_counter();
		wpsc_create_stop_preload_flag();
		wp_unschedule_event( $next_preload, 'wp_cache_full_preload_hook' );

		$next_preload = 0;
	}

	// Ensure a preload is scheduled if it should be.
	if ( ! $next_preload && $should_schedule ) {
		wp_cache_debug( 'Scheduling new preload event' );
		wp_schedule_single_event( time() + ( $wp_cache_preload_interval * 60 ), 'wp_cache_full_preload_hook' );
	}
}