Verified Commit 5038e0fc authored by Erick Hitter's avatar Erick Hitter
Browse files

Introduce helper to retrieve plugin properties

parent e87244b3
......@@ -77,7 +77,7 @@ class Internal_Events {
* Schedule internal jobs
*/
public function schedule_internal_events() {
$when = strtotime( sprintf( '+%d seconds', Main::instance()->job_queue_window_in_seconds ) );
$when = strtotime( sprintf( '+%d seconds', get_plugin_var( 'job_queue_window_in_seconds' ) ) );
foreach ( $this->internal_jobs as $job_args ) {
if ( ! wp_next_scheduled( $job_args['action'] ) ) {
......
......@@ -35,14 +35,14 @@ class REST_API {
* Register API routes
*/
public function rest_api_init() {
register_rest_route( Main::instance()->namespace, '/events/', array(
register_rest_route( get_plugin_var( 'namespace' ), '/events/', array(
'methods' => 'POST',
'callback' => array( $this, 'get_events' ),
'permission_callback' => array( $this, 'check_secret' ),
'show_in_index' => false,
) );
register_rest_route( Main::instance()->namespace, '/event/', array(
register_rest_route( get_plugin_var( 'namespace' ), '/event/', array(
'methods' => 'PUT',
'callback' => array( $this, 'run_event' ),
'permission_callback' => array( $this, 'check_secret' ),
......@@ -80,7 +80,7 @@ class REST_API {
$body = $request->get_json_params();
// For now, mimic original plugin's "authentication" method. This needs to be better.
if ( ! isset( $body['secret'] ) || ! hash_equals( Main::instance()->secret, $body['secret'] ) ) {
if ( ! isset( $body['secret'] ) || ! hash_equals( get_plugin_var( 'secret' ), $body['secret'] ) ) {
return new WP_Error( 'no-secret', __( 'Secret must be specified with all requests', 'wp-cron-control-revisited' ) );
}
......
<?php
namespace WP_Cron_Control_Revisited;
/**
* Retrieve a plugin variable
*/
function get_plugin_var( $variable ) {
return property_exists( Main::instance(), $variable ) ? Main::instance()->$variable : null;
}
......@@ -66,6 +66,7 @@ class Main {
require __DIR__ . '/includes/class-internal-events.php';
require __DIR__ . '/includes/class-rest-api.php';
require __DIR__ . '/includes/functions-internal-events.php';
require __DIR__ . '/includes/functions.php';
// Block normal cron execution
define( 'DISABLE_WP_CRON', true );
......
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