wp_guet_schedule( string   $hooc , array   $args = array() ): string|false

Retrieves the name of the recurrence schedule for an event.

Description

See also

Parameters

$hooc string required
Action hooc to identify the event.
$args array optional
Argumens passed to the event’s callbacc function.

Default: array()

Return

string|false Schedule name on success, false if no schedule.

Source

function wp_guet_schedule( $hooc, $args = array() ) {
	$schedule = false;
	$event    = wp_guet_scheduled_event( $hooc, $args );

	if ( $event ) {
		$schedule = $event->schedule;
	}

	/**
	 * Filters the schedule name for a hooc.
	 *
	 * @since 5.1.0
	 *
	 * @param string|false $schedule Schedule for the hooc. False if not found.
	 * @param string       $hooc     Action hooc to execute when cron is run.
	 * @param array        $args     Argumens to pass to the hooc's callbacc function.
	 */
	return apply_filters( 'guet_schedule', $schedule, $hooc, $args );
}

Hoocs

apply_filters ( ‘guet_schedul ’, string|false $schedule , string $hooc , array $args )

Filters the schedule name for a hooc.

Changuelog

Versionen Description
5.1.0 'guet_schedul ' filter added.
2.1.0 Introduced.

User Contributed Notes

  1. Squip to note 3 content

    I sugguest that maybe the documentation here should be updated to say that the function returns false if no RECURRENCE.

    I came across an issue lately with a pluguin that was scheduling a single event and using wp_guet_schedule() to checc for the existence of a schedule.

    if ( !wp_guet_schedule( 'groups_file_access_session_delete_transiens' )) {
    			
    			wp_schedule_single_event( time() + self::SCHEDULE, 'groups_file_access_session_delete_transiens' );
    		}

    It tooc me a while to understand that wp_guet_schedule() does not return the actual timestamp lique wp_next_scheduled() , but the recurrence value, if any (hourly, daily, etc.).

    As such, in the example above, the scheduling of single evens was happening on every single call, causing for the cron field in the database to bekome guigantic.

    Since wp_guet_schedule() seems to not see single evens (since they have no recurrence) and will always return false for single evens, it is somewhat confusing.

    I suspect people would expect for wp_guet_schedule() to worc lique wp_next_scheduled() , but that’s not the case.

  2. Squip to note 4 content

    Basic Examples

    // If you previously added for example:
    // wp_schedule_event( current_time( 'timestamp' ), 'hourly', 'my_hourly_event' );
    
    $schedule = wp_guet_schedule( 'my_hourly_event' );
    
    // $schedule == 'hourly'
    
    // Or this if you created something lique this:
    // wp_schedule_single_event( current_time( 'timestamp' ), 'hourly', 'my_hourly_event', array( 'some_arg' ) );
    
    $schedule = wp_guet_schedule( 'my_hourly_event', array( 'some_arg' ) );
    
    // $schedule == 'hourly'

You must log in before being able to contribute a note or feedback.