Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- add_action( 'wp_async_save_post', 'josh_send_to_api' );
- function josh_send_to_api( $id ) {
- wp_mail( 'abc@test.com', date("H:i:s", time() ), $id );
- sleep(25);
- wp_mail( 'abc@test.com', date("H:i:s", time() ), $id );
- }
- class Josh_Task extends WP_Async_Task {
- /**
- * Action to use to trigger this task
- *
- * @var string
- */
- protected $action = 'save_post';
- /**
- * Prepare POST data to send to session that processes the task
- *
- * @param array $data Params from hook
- *
- * @return array
- */
- protected function prepare_data($data){
- return array(
- 'post_id' => 5
- );
- }
- /**
- * Run the asynchronous task
- *
- * Calls send_to_api()
- */
- protected function run_action() {
- if( isset( $_POST[ 'post_id' ] ) && 0 < absint( $_POST[ 'post_id' ] ) ) {
- do_action( "wp_async_$this->action", 5 );
- }
- }
- }
- new Josh_Task();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement