Make WordPress Core

Opened 8 years ago

Closed 8 years ago

#41095 closed feature request (invalid)

wp_schedule_single_event should support any callable

Reported by: danrossiter's profile dan.rossiter Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Cron API Keywords:
Focuses: Cc:

Description

Hooking/filtering in WP core generally supports any callable variable, but wp_schedule_single_event only supports strings. I can see how instance methods wouldn't make sense here, but the static class methods in the array notation still make sense and should be supported.

Since the minimum PHP version for WP is earlier than support for namespaces, static class methods are often used to keep methods from cluttering the global method space. Preventing this use case here seems arbitrary and seems like an easy fix.

Change History (2)

#1 @westonruter
8 years ago

  • Component changed from Customize to Cron API

#2 @dd32
8 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to invalid
  • Status changed from new to closed

This is a remarkably common misconception of how the CRON system actually works, but this is supported already.

wp_schedule_single_event() does not accept a callable at all, it accept an action name. Often the hook specified is the same as the function being called, which doesn't help people realise what's actually being specified.

wp_schedule_single_event( time() + 3600, 'my_plugin_func' ); does not work, it doesn't do anything without an additional add_action().

It's used like this:

wp_schedule_single_event( time() + 3600, 'my_plugin_function_hook_name', array( $arg1, $arg2, $arg3) );

add_action( 'my_plugin_function_hook_name', function( $arg1, $arg2, $arg3 ) {
    // I'm running in a CRON request!
}, 10, 3 );

Note: See TracTickets for help on using tickets.