Forum Replies Created

Viewing 1 replies (of 1 total)
  • After long searching the solution of @andfinally got me on the right track. It was the hint about the namespacing, though it’s not a namespacing problem. But it got me thinking about instances ??

    What happens:
    -you go to a page
    -the php script runs and creates instances of classes
    -in add_action when you add your callback something like this:
    add_action( ‘process_something’, [$this, ‘process_something’], 10, 3 );
    -and then you call wp_schedule_single_event with this action
    -then the script finishes

    Then later the WP Cron is executed. It’s a total different run of the script. The instance that was registered with the callback does not exist, so it can never be called.

    So the add_action with the callback should indeed be registered in for example the init hook. Or anything that is also executed / instantiated when wp-cron runs. And then it can be perfectly fine in an instance of a namespaced class

Viewing 1 replies (of 1 total)