WORDPRESS add_filter('cron_schedules', ...) not working in a PHP class - Stack Overflow

PHOTO EMBED

Sun Jun 11 2023 04:37:53 GMT+0000 (Coordinated Universal Time)

Saved by @leninzapata #php

 if (!defined('ABSPATH')) exit;

    new My_Cron();

    class My_Cron {

        public function __construct() {
            add_filter('cron_schedules', array($this, 'cron_time_intervals'));
            add_action( 'wp',  array($this, 'cron_scheduler'));
            add_action( 'cast_my_spell', array( $this, 'auto_spell_cast' ) );
        }

        public function cron_time_intervals($schedules)
        {
            $schedules['minutes_10'] = array(
                'interval' => 10 * 60,
                'display' => 'Once 10 minutes'
            );
            return $schedules;
        }

        function cron_scheduler() {
            if ( ! wp_next_scheduled( 'cast_my_spell' ) ) {
                wp_schedule_event( time(), 'minutes_10', 'cast_my_spell');
            }
        }

        function auto_spell_cast(){
            My_Plugin_Class::instance()->launch_spell();
        }
    }
content_copyCOPY

https://stackoverflow.com/questions/30408882/wordpress-add-filtercron-schedules-not-working-in-a-php-class