*/ $old_scheds = get_option( 'crontrol_schedules', array() ); $old_scheds[ $name ] = array( 'interval' => $interval, 'display' => $display, ); update_option( 'crontrol_schedules', $old_scheds ); /** * Fires after a new cron schedule is added. * * @param string $name The internal name of the schedule. * @param int $interval The interval between executions of the new schedule. * @param string $display The display name of the schedule. */ do_action( 'crontrol/added_new_schedule', $name, $interval, $display ); } /** * Deletes a custom cron schedule. * * @param string $name The internal name of the schedule to delete. * @return void */ function delete( $name ) { /** @var array */ $scheds = get_option( 'crontrol_schedules', array() ); unset( $scheds[ $name ] ); update_option( 'crontrol_schedules', $scheds ); /** * Fires after a cron schedule is deleted. * * @param string $name The internal name of the schedule. */ do_action( 'crontrol/deleted_schedule', $name ); } /** * Gets a sorted (according to interval) list of the cron schedules * * @return array Array of Schedule objects keyed by schedule name. */ function get() { /** * @phpstan-var array $schedules */ $schedules = wp_get_schedules(); uasort( $schedules, fn( array $a, array $b ) => $a['interval'] <=> $b['interval'] ); $result = []; foreach ( $schedules as $name => $schedule ) { $display = $schedule['display'] ?? $name; $result[ $name ] = Schedule::create( $name, $schedule['interval'], $display ); } return $result; } /** * Displays a dropdown filled with the possible schedules, including non-repeating. * * @param ?string $current The currently selected schedule, or null for none. * @return void */ function dropdown( ?string $current = null ) { $schedules = get(); ?>