• Resolved formalxcom

    (@formalxcom)


    I have install this plugin on my site, but how can I use it to schedule a function or script to run daily at midnight??

Viewing 3 replies - 1 through 3 (of 3 total)
  • @formalxcom The documentation for Action Scheduler describes several functions to use to schedule actions.

    I installed this plugin & added this into my custom wp plugin:

    require_once( plugin_dir_path( __FILE__ ) . '/libraries/action-scheduler/action-scheduler.php' );
    
    /**
     * Schedule an action with the hook 'eg_midnight_log' to run at midnight each day
     * so that our callback is run then.
     */
    function eg_schedule_midnight_log() {
    	if ( false === as_next_scheduled_action( 'eg_midnight_log' ) ) {
    		as_schedule_recurring_action( strtotime( 'tomorrow' ), DAY_IN_SECONDS, 'eg_midnight_log' );
    	}
    }
    add_action( 'init', 'eg_schedule_midnight_log' );
    
    /**
     * A callback to run when the 'eg_midnight_log' scheduled action is run.
     */
    function eg_log_action_data() {
    	error_log( 'It is just after midnight on ' . date( 'Y-m-d' ) );
    }
    add_action( 'eg_midnight_log', 'eg_log_action_data' );

    But its not working.

    //https://actionscheduler.org/usage/

    • This reply was modified 4 years, 5 months ago by Yui.
    • This reply was modified 4 years, 5 months ago by Yui. Reason: please use CODE button for proper formatting
    Plugin Contributor Ron Rennick

    (@wpmuguru)

    @procontentxyz If you change this hook to init does your message get logged to the error log?

    
    add_action( 'eg_midnight_log', 'eg_log_action_data' );
    

    Also, it’s better to start your own forum thread with a question vs jumping into another person’s issue.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘How to use this plugin to schedule and action or hook’ is closed to new replies.