Cron Control Tester
The snippet can be accessed without any authentication.
Authored by
Erick Hitter
Edited
<?php
/**
* TO TEST:
*
* 1. Update config below
* 2. Run `while sleep 60; do php cron-control-tester.php; done`
*/
// Config
$endpoint = 'http://localhost/wp-json/cron-control/v1/events';
$ssl = false;
$secret = 'waffle'; // Value of WP_CRON_CONTROL_SECRET
// Do the stuff
$curl = curl_init();
$body = json_encode( array( 'secret' => $secret, ) );
curl_setopt_array(
$curl, array(
CURLOPT_URL => $endpoint,
CURLOPT_SSL_VERIFYHOST => false,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_TIMEOUT => 10,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS => $body,
CURLOPT_HTTPHEADER => array(
'Content-Type: application/json',
'Content-Length: ' . strlen( $body ),
),
)
);
$results = curl_exec( $curl );
$err = curl_error( $curl );
if ( ! empty( $err ) ) {
var_export( $err );
die;
}
$results = json_decode( $results, true );
curl_close( $curl );
if ( ! is_array( $results ) || ! isset( $results['endpoint'] ) || empty( $results['events'] ) ) {
die;
}
if ( ! $ssl ) {
$results['endpoint'] = preg_replace( '#^https://#i', 'http://', $results['endpoint'] );
}
foreach ( $results['events'] as $event ) {
$curl = curl_init();
$put_data = json_encode( array_merge( array( 'secret' => $secret, ), $event ) );
curl_setopt_array(
$curl, array(
CURLOPT_URL => $results['endpoint'],
CURLOPT_SSL_VERIFYHOST => false,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_TIMEOUT => 0,
CURLOPT_ENCODING => '',
CURLOPT_CUSTOMREQUEST => 'PUT',
CURLOPT_POSTFIELDS => $put_data,
CURLOPT_HTTPHEADER => array(
'Content-Type: application/json',
'Content-Length: ' . strlen( $put_data ),
),
)
);
$result = curl_exec( $curl );
$err = curl_error( $curl );
curl_close( $curl );
if ( ! empty( $err ) ) {
var_export( $err );
continue;
}
$result = json_decode( $result, true );
var_export( $result );
echo "\n";
}
Please register or sign in to comment