Skip to content

How to use this, exactly? #20

Description

@Luc45

Hey, great code, thanks!

I'm having some trouble using it, though. Here's a quick test I'm doing:

add_action( 'wp_async_shutdown', [$this, 'testing_async'], 10, 1 );

I expect this to run public function testing_async() asynchronously when WordPress be shutting down, right?

public function testing_async() {
    error_log('test', 1, 'someemail@gmail.com');
}

But this is never called. OK, this didn't work. Let's try the "extend class" approach.

public function testing_async() {
    $test = new WP_Async_Test();
}

WP_Async_Test.php:

<?php

class WP_Async_Test extends WP_Async_Task {

    //protected $action = 'shutdown';
    protected $action = 'testing_async';

    /**
     * Prepare data for the asynchronous request
     *
     * @throws Exception If for any reason the request should not happen
     *
     * @param array $data An array of data sent to the hook
     *
     * @return array
     */
    protected function prepare_data( $data ) {

    }

    /**
     * Run the async task action
     */
    protected function run_action() {
        error_log('hi', 1, 'someemail@gmail.com');
    }

}

This didn't work either... What am I doing wrong?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions