public function run( $args, $assoc_args ) {

		if ( empty( $args ) && ! Utils\get_flag_value( $assoc_args, 'due-now' ) && ! Utils\get_flag_value( $assoc_args, 'all' ) ) {
			WP_CLI::error( 'Please specify one or more cron events, or use --due-now/--all.' );
		}

		$events = self::get_cron_events();

		if ( is_wp_error( $events ) ) {
			WP_CLI::error( $events );
		}

		$hooks = wp_list_pluck( $events, 'hook' );
		foreach ( $args as $hook ) {
			if ( ! in_array( $hook, $hooks, true ) ) {
				WP_CLI::error( sprintf( "Invalid cron event '%s'", $hook ) );
			}
		}

		if ( Utils\get_flag_value( $assoc_args, 'due-now' ) ) {
			$due_events = array();
			foreach ( $events as $event ) {
				if ( ! empty( $args ) && ! in_array( $event->hook, $args, true ) ) {
					continue;
				}
				if ( time() >= $event->time ) {
					$due_events[] = $event;
				}
			}
			$events = $due_events;
		} elseif ( ! Utils\get_flag_value( $assoc_args, 'all' ) ) {
			$due_events = array();
			foreach ( $events as $event ) {
				if ( in_array( $event->hook, $args, true ) ) {
					$due_events[] = $event;
				}
			}
			$events = $due_events;
		}

		$executed = 0;
		foreach ( $events as $event ) {
			$start  = microtime( true );
			$result = self::run_event( $event );
			$total  = round( microtime( true ) - $start, 3 );
			$executed++;
			WP_CLI::log( sprintf( "Executed the cron event '%s' in %ss.", $event->hook, $total ) );
		}

		$message = ( 1 === $executed ) ? 'Executed a total of %d cron event.' : 'Executed a total of %d cron events.';
		WP_CLI::success( sprintf( $message, $executed ) );
	}
public function run( $args, $assoc_args ) {

		if ( empty( $args ) && ! Utils\get_flag_value( $assoc_args, 'due-now' ) && ! Utils\get_flag_value( $assoc_args, 'all' ) ) {
			WP_CLI::error( 'Please specify one or more cron events, or use --due-now/--all.' );
		}

		$events = self::get_cron_events();

		if ( is_wp_error( $events ) ) {
			WP_CLI::error( $events );
		}

		$hooks = wp_list_pluck( $events, 'hook' );
		foreach ( $args as $hook ) {
			if ( ! in_array( $hook, $hooks, true ) ) {
				WP_CLI::error( sprintf( "Invalid cron event '%s'", $hook ) );
			}
		}

		if ( Utils\get_flag_value( $assoc_args, 'due-now' ) ) {
			$due_events = array();
			foreach ( $events as $event ) {
				if ( ! empty( $args ) && ! in_array( $event->hook, $args, true ) ) {
					continue;
				}
				if ( time() >= $event->time ) {
					$due_events[] = $event;
				}
			}
			$events = $due_events;
		} elseif ( ! Utils\get_flag_value( $assoc_args, 'all' ) ) {
			$due_events = array();
			foreach ( $events as $event ) {
				if ( in_array( $event->hook, $args, true ) ) {
					$due_events[] = $event;
				}
			}
			$events = $due_events;
		}

		$executed = 0;
		foreach ( $events as $event ) {
			$start  = microtime( true );
			$result = self::run_event( $event );
			$total  = round( microtime( true ) - $start, 3 );
			$executed++;
			WP_CLI::log( sprintf( "Executed the cron event '%s' in %ss.", $event->hook, $total ) );
		}

		$message = ( 1 === $executed ) ? 'Executed a total of %d cron event.' : 'Executed a total of %d cron events.';
		WP_CLI::success( sprintf( $message, $executed ) );
	}
public function run ( $ args , $ assoc_args ) { if ( empty ( $ args ) && ! Utils \ get_flag_value ( $ assoc_args , 'due-now' ) && ! Utils \ get_flag_value ( $ assoc_args , 'all' ) ) { WP_CLI :: error ( 'Please specify one or more cron events, or use --due-now/--all.' ) ; } $ events = self :: get_cron_events ( ) ; if ( is_wp_error ( $ events ) ) { WP_CLI :: error ( $ events ) ; } $ hooks = wp_list_pluck ( $ events , 'hook' ) ; foreach ( $ args as $ hook ) { if ( ! in_array ( $ hook , $ hooks , true ) ) { WP_CLI :: error ( sprintf ( "Invalid cron event '%s'" , $ hook ) ) ; } } if ( Utils \ get_flag_value ( $ assoc_args , 'due-now' ) ) { $ due_events = array ( ) ; foreach ( $ events as $ event ) { if ( ! empty ( $ args ) && ! in_array ( $ event -> hook , $ args , true ) ) { continue ; } if ( time ( ) >= $ event -> time ) { $ due_events [ ] = $ event ; } } $ events = $ due_events ; } elseif ( ! Utils \ get_flag_value ( $ assoc_args , 'all' ) ) { $ due_events = array ( ) ; foreach ( $ events as $ event ) { if ( in_array ( $ event -> hook , $ args , true ) ) { $ due_events [ ] = $ event ; } } $ events = $ due_events ; } $ executed = 0 ; foreach ( $ events as $ event ) { $ start = microtime ( true ) ; $ result = self :: run_event ( $ event ) ; $ total = round ( microtime ( true ) - $ start , 3 ) ; $ executed ++ ; WP_CLI :: log ( sprintf ( "Executed the cron event '%s' in %ss." , $ event -> hook , $ total ) ) ; } $ message = ( 1 === $ executed ) ? 'Executed a total of %d cron event.' : 'Executed a total of %d cron events.' ; WP_CLI :: success ( sprintf ( $ message , $ executed ) ) ; }
Runs the next scheduled cron event for the given hook.

## OPTIONS

[<hook>...]
: One or more hooks to run.

[--due-now]
: Run all hooks due right now.

[--all]
: Run all hooks.

## EXAMPLES

# Run all cron events due right now
$ wp cron event run --due-now
Success: Executed a total of 2 cron events.
Runs the next scheduled cron event for the given hook .