'The cron defined in the plugin does not work
I'm defining a cron task in the plugin I'm developing. However, this is not working. I don't see this in the WP-Control plugin. Similar problems have been encountered in the past, but this was not a solution for me. I have no idea where I went wrong. Due to the code structure, I have to define it in different classes. However, I couldn't find a solution. My work is below:
<?php
//File Path: ...plugins/x
require_once X_PLUGIN_DIR . 'includes/m.php';
function activePluginX(){
if ( ! wp_next_scheduled( 'x_action_cron' ) ) {
wp_schedule_event( time(), 'new_daily', 'x_action_cron' );
}
}
register_activation_hook(__FILE__, 'activePluginX');
function x_start(){
$abc = new ABC();
}
add_action('plugins_loaded', 'x_start');
//File Path: ...plugins/x/includes/m.php
defined( 'ABSPATH' ) || exit;
if(!defined('ABC') ) {
class ABC {
public function __construct() {
add_filter( 'cron_schedules', array($this,'x_action_cron'));
add_action( 'x_action_cron', array($this,'x_action' ));
}
public function x_action_cron($schedules){
$schedules[ 'new_daily'] = array( 'interval' => 86400, 'display' => '1 Time' );
return $schedules;
}
public function x_action(){
//do something...
}
} //end of class
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
