Astra_Theme_Background_Updater::test_cron()

Check Cron Status


Description

Gets the current cron status by performing a test spawn. Cached for one hour when all is well.


Return

(bool) true if there is a problem spawning a call to WP-Cron system, else false.


Source

File: inc/theme-update/class-astra-theme-background-updater.php

		public function test_cron() {

			global $wp_version;

			if ( defined( 'DISABLE_WP_CRON' ) && DISABLE_WP_CRON ) {
				return true;
			}

			if ( defined( 'ALTERNATE_WP_CRON' ) && ALTERNATE_WP_CRON ) {
				return true;
			}

			$cached_status = get_transient( 'astra-theme-cron-test-ok' );

			if ( $cached_status ) {
				return false;
			}

			$sslverify     = version_compare( $wp_version, 4.0, '<' );
			$doing_wp_cron = sprintf( '%.22F', microtime( true ) );

			$cron_request = apply_filters(
				'cron_request',
				array(
					'url'  => site_url( 'wp-cron.php?doing_wp_cron=' . $doing_wp_cron ),
					'args' => array(
						'timeout'   => 3,
						'blocking'  => true,
						'sslverify' => apply_filters( 'https_local_ssl_verify', $sslverify ),
					),
				)
			);

			$result = wp_remote_post( $cron_request['url'], $cron_request['args'] );

			if ( wp_remote_retrieve_response_code( $result ) >= 300 ) {
				return true;
			} else {
				set_transient( 'astra-theme-cron-test-ok', 1, 3600 );
				return false;
			}

			return $migration_fallback;
		}

Changelog

Changelog
Version Description
2.3.0 Introduced.


User Contributed Notes

You must log in before being able to contribute a note or feedback.