I am trying to learn how to use the action scheduler so I am hoping somehow can give me some good pointers. I've got this code:
<?php
add_action( 'init', array( $this, 'wootomation_schedule' ) );
add_action( 'wootomation_import', array( $this, 'wootomation_do_action' ) );
function wootomation_schedule() {
// if ( false === as_next_scheduled_action( 'wootomation_import' ) ) {
// as_schedule_recurring_action( time(), 30, 'wootomation_import' );
// }
if ( false === as_next_scheduled_action( 'wootomation_import' ) ) {
as_enqueue_async_action( 'wootomation_import' );
}
}
function wootomation_do_action() {
var_dump('test');
wp_mail( '[email protected]', 'test AS', 'Action schedule completed' );
}
Which appears to create the action but it never runs. I tried refreshing the front end of the website but didn't help.
Can anyone tell me how to get it to run?
And the 2nd question would be, is this the right approach for breaking up some heavy indexing, maybe with args such as page: "0-100", page: "101-200", etc.
Thanks, Dragos
I am trying to learn how to use the action scheduler so I am hoping somehow can give me some good pointers. I've got this code:
<?php
add_action( 'init', array( $this, 'wootomation_schedule' ) );
add_action( 'wootomation_import', array( $this, 'wootomation_do_action' ) );
function wootomation_schedule() {
// if ( false === as_next_scheduled_action( 'wootomation_import' ) ) {
// as_schedule_recurring_action( time(), 30, 'wootomation_import' );
// }
if ( false === as_next_scheduled_action( 'wootomation_import' ) ) {
as_enqueue_async_action( 'wootomation_import' );
}
}
function wootomation_do_action() {
var_dump('test');
wp_mail( '[email protected]', 'test AS', 'Action schedule completed' );
}
Which appears to create the action but it never runs. I tried refreshing the front end of the website but didn't help.
Can anyone tell me how to get it to run?
And the 2nd question would be, is this the right approach for breaking up some heavy indexing, maybe with args such as page: "0-100", page: "101-200", etc.
Thanks, Dragos
Share Improve this question asked Jun 5, 2020 at 13:40 Dragos MicuDragos Micu 2132 silver badges9 bronze badges1 Answer
Reset to default 1require_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_log_action_data() {
if ( false === as_next_scheduled_action( 'eg_midnight_log' ) ) {
as_schedule_recurring_action( strtotime( 'midnight tonight' ), DAY_IN_SECONDS, 'eg_midnight_log' );
}
}
add_action( 'init', 'eg_log_action_data' );
/**
* 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' );
Docs Link: https://actionscheduler/usage/#scheduling-an-action
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742311070a4419905.html
评论列表(0条)