Verified Commit c9e2dd8d authored by Erick Hitter's avatar Erick Hitter
Browse files

Define certain constants when we can, and log when we can't because the environment is unexpected

parent ba810353
......@@ -36,8 +36,7 @@ class Main extends Singleton {
require __DIR__ . '/functions.php';
// Block normal cron execution
define( 'DISABLE_WP_CRON', true );
define( 'ALTERNATE_WP_CRON', false );
$this->set_constants();
$block_action = did_action( 'muplugins_loaded' ) ? 'plugins_loaded' : 'muplugins_loaded';
add_action( $block_action, array( $this, 'block_direct_cron' ) );
......@@ -46,6 +45,28 @@ class Main extends Singleton {
add_filter( 'cron_request', array( $this, 'block_spawn_cron' ) );
}
/**
* Define constants that block Core's cron
*
* If a constant is already defined and isn't what we expect, log it
*/
private function set_constants() {
$constants = array(
'DISABLE_WP_CRON' => true,
'ALTERNATE_WP_CRON' => false,
);
foreach ( $constants as $constant => $expected_value ) {
if ( defined( $constant ) ) {
if ( constant( $constant ) !== $expected_value ) {
error_log( sprintf( __( '%s: %s set to unexpected value; must be corrected for proper behaviour.', 'wp-cron-control-revisited' ), 'WP-Cron Control Revisited', $constant ) );
}
} else {
define( $constant, $expected_value );
}
}
}
/**
* Block direct cron execution as early as possible
*/
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment