WordPress.org

Make WordPress Core

Opened 6 years ago

Closed 6 years ago

#27087 closed defect (bug) (invalid)

wp_schedule_event will not accept class hook

Reported by: jonshipman Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.8.1
Component: Cron API Keywords:
Focuses: administration Cc:
PR Number:

Description (last modified by TobiasBg)

wp_schedule_event will not accept array() for the hook (must be string). As such, wp_schedule_event( time(), 'daily', array($this,'hook') ); will not work, however, moving the hook method outside of the class will work as the $hook is no longer an array.

Change History (1)

#1 @TobiasBg
6 years ago

  • Description modified (diff)
  • Milestone Awaiting Review deleted
  • Resolution set to invalid
  • Status changed from new to closed

You are mixing up "hook" and "callback" here.
wp_schedule_event indeed requires a string as the "hook", in the sense of plugin action hook. You can then attach a "callback" (usually a function or class method) to that action hook:

wp_schedule_event( time(), 'daily', 'my_unique_plugin_event_hook' );
add_action( 'my_unique_plugin_event_hook', array( $this,'hook' ) );
Note: See TracTickets for help on using tickets.