wp_schedule_single_event

Definition:
function wp_schedule_single_event( $timestamp, $hook, $args = array() {}

Schedules a hook to run only once.
Schedules a hook which will be executed once by the WordPress actions core at a time which you specify. The action will fire off when someone visits your WordPress site, if the schedule time has passed.

Parameters

  • int $timestamp: Timestamp for when to run the event.
  • string $hook: Action hook to execute when cron is run.
  • array $args: Optional. Arguments to pass to the hook’s callback function.

Defined filters

  • schedule_event
    apply_filters('schedule_event', $event)

Source code

function wp_schedule_single_event( $timestamp, $hook, $args = array()) {

	// don't schedule a duplicate if there's already an identical event due in the next 10 minutes

	$next = wp_next_scheduled($hook, $args);

	if ( $next && $next <= $timestamp + 600 )

		return;



	$crons = _get_cron_array();

	$event = (object) array( 'hook' => $hook, 'timestamp' => $timestamp, 'schedule' => false, 'args' => $args );

	$event = apply_filters('schedule_event', $event);



	// A plugin disallowed this event

	if ( ! $event )

		return false;



	$key = md5(serialize($event->args));



	$crons[$event->timestamp][$event->hook][$key] = array( 'schedule' => $event->schedule, 'args' => $event->args );

	uksort( $crons, "strnatcasecmp" );

	_set_cron_array( $crons );

}

4089

wp_schedule_event

Definition:
function wp_schedule_event( $timestamp, $recurrence, $hook, $args = array() {}

Schedule a periodic event.
Schedules a hook which will be executed by the WordPress actions core on a specific interval, specified by you. The action will trigger when someone visits your WordPress site, if the scheduled time has passed.

Parameters

  • int $timestamp: Timestamp for when to run the event.
  • string $recurrence: How often the event should recur.
  • string $hook: Action hook to execute when cron is run.
  • array $args: Optional. Arguments to pass to the hook’s callback function.

Return values

returns:False on failure, null when complete with scheduling event.

Defined filters

  • schedule_event
    apply_filters('schedule_event', $event)

Source code

function wp_schedule_event( $timestamp, $recurrence, $hook, $args = array()) {

	$crons = _get_cron_array();

	$schedules = wp_get_schedules();



	if ( !isset( $schedules[$recurrence] ) )

		return false;



	$event = (object) array( 'hook' => $hook, 'timestamp' => $timestamp, 'schedule' => $recurrence, 'args' => $args, 'interval' => $schedules[$recurrence]['interval'] );

	$event = apply_filters('schedule_event', $event);



	// A plugin disallowed this event

	if ( ! $event )

		return false;



	$key = md5(serialize($event->args));



	$crons[$event->timestamp][$event->hook][$key] = array( 'schedule' => $event->schedule, 'args' => $event->args, 'interval' => $event->interval );

	uksort( $crons, "strnatcasecmp" );

	_set_cron_array( $crons );

}

4087

wp_scheduled_delete

Definition:
function wp_scheduled_delete() {}

Permanently deletes posts, pages, attachments, and comments which have been in the trash for EMPTY_TRASH_DAYS.

Source code

function wp_scheduled_delete() {

	global $wpdb;



	$delete_timestamp = time() - (60*60*24*EMPTY_TRASH_DAYS);



	$posts_to_delete = $wpdb->get_results($wpdb->prepare("SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wp_trash_meta_time' AND meta_value < '%d'", $delete_timestamp), ARRAY_A);



	foreach ( (array) $posts_to_delete as $post ) {

		$post_id = (int) $post['post_id'];

		if ( !$post_id )

			continue;



		$del_post = get_post($post_id);



		if ( !$del_post || 'trash' != $del_post->post_status ) {

			delete_post_meta($post_id, '_wp_trash_meta_status');

			delete_post_meta($post_id, '_wp_trash_meta_time');

		} else {

			wp_delete_post($post_id);

		}

	}



	$comments_to_delete = $wpdb->get_results($wpdb->prepare("SELECT comment_id FROM $wpdb->commentmeta WHERE meta_key = '_wp_trash_meta_time' AND meta_value < '%d'", $delete_timestamp), ARRAY_A);



	foreach ( (array) $comments_to_delete as $comment ) {

		$comment_id = (int) $comment['comment_id'];

		if ( !$comment_id )

			continue;



		$del_comment = get_comment($comment_id);



		if ( !$del_comment || 'trash' != $del_comment->comment_approved ) {

			delete_comment_meta($comment_id, '_wp_trash_meta_time');

			delete_comment_meta($comment_id, '_wp_trash_meta_status');

		} else {

			wp_delete_comment($comment_id);

		}

	}

}

4085

wp_save_post_revision

Definition:
function wp_save_post_revision( $post_id ) {}

Saves an already existing post as a post revision.
Typically used immediately prior to post updates.

Parameters

  • int $post_id: The ID of the post to save as a revision.

Return values

returns:Null or 0 if error, new revision ID, if success.

Source code

function wp_save_post_revision( $post_id ) {

	// We do autosaves manually with wp_create_post_autosave()

	if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )

		return;



	// WP_POST_REVISIONS = 0, false

	if ( ! WP_POST_REVISIONS )

		return;



	if ( !$post = get_post( $post_id, ARRAY_A ) )

		return;



	if ( !post_type_supports($post['post_type'], 'revisions') )

		return;



	$return = _wp_put_post_revision( $post );



	// WP_POST_REVISIONS = true (default), -1

	if ( !is_numeric( WP_POST_REVISIONS ) || WP_POST_REVISIONS < 0 )

		return $return;



	// all revisions and (possibly) one autosave

	$revisions = wp_get_post_revisions( $post_id, array( 'order' => 'ASC' ) );



	// WP_POST_REVISIONS = (int) (# of autosaves to save)

	$delete = count($revisions) - WP_POST_REVISIONS;



	if ( $delete < 1 )

		return $return;



	$revisions = array_slice( $revisions, 0, $delete );



	for ( $i = 0; isset($revisions[$i]); $i++ ) {

		if ( false !== strpos( $revisions[$i]->post_name, 'autosave' ) )

			continue;

		wp_delete_post_revision( $revisions[$i]->ID );

	}



	return $return;

}

4083

wp_save_nav_menu_items

Definition:
function wp_save_nav_menu_items( $menu_id = 0, $menu_data = array() {}

Save posted nav menu item data.

Parameters

  • int $menu_id: The menu ID for which to save this item. $menu_id of 0 makes a draft, orphaned menu item.
  • array $menu_data: The unsanitized posted menu item data.

Return values

returns:The database IDs of the items saved

Source code

function wp_save_nav_menu_items( $menu_id = 0, $menu_data = array() ) {

	$menu_id = (int) $menu_id;

	$items_saved = array();



	if ( 0 == $menu_id || is_nav_menu( $menu_id ) ) {



		// Loop through all the menu items' POST values

		foreach( (array) $menu_data as $_possible_db_id => $_item_object_data ) {

			if (

				empty( $_item_object_data['menu-item-object-id'] ) && // checkbox is not checked

				(

					! isset( $_item_object_data['menu-item-type'] ) || // and item type either isn't set

					in_array( $_item_object_data['menu-item-url'], array( 'http://', '' ) ) || // or URL is the default

					! ( 'custom' == $_item_object_data['menu-item-type'] && ! isset( $_item_object_data['menu-item-db-id'] ) ) ||  // or it's not a custom menu item (but not the custom home page)

					! empty( $_item_object_data['menu-item-db-id'] ) // or it *is* a custom menu item that already exists

				)

			) {

				continue; // then this potential menu item is not getting added to this menu

			}



			// if this possible menu item doesn't actually have a menu database ID yet

			if (

				empty( $_item_object_data['menu-item-db-id'] ) ||

				( 0 > $_possible_db_id ) ||

				$_possible_db_id != $_item_object_data['menu-item-db-id']

			) {

				$_actual_db_id = 0;

			} else {

				$_actual_db_id = (int) $_item_object_data['menu-item-db-id'];

			}



			$args = array(

				'menu-item-db-id' => ( isset( $_item_object_data['menu-item-db-id'] ) ? $_item_object_data['menu-item-db-id'] : '' ),

				'menu-item-object-id' => ( isset( $_item_object_data['menu-item-object-id'] ) ? $_item_object_data['menu-item-object-id'] : '' ),

				'menu-item-object' => ( isset( $_item_object_data['menu-item-object'] ) ? $_item_object_data['menu-item-object'] : '' ),

				'menu-item-parent-id' => ( isset( $_item_object_data['menu-item-parent-id'] ) ? $_item_object_data['menu-item-parent-id'] : '' ),

				'menu-item-position' => ( isset( $_item_object_data['menu-item-position'] ) ? $_item_object_data['menu-item-position'] : '' ),

				'menu-item-type' => ( isset( $_item_object_data['menu-item-type'] ) ? $_item_object_data['menu-item-type'] : '' ),

				'menu-item-title' => ( isset( $_item_object_data['menu-item-title'] ) ? $_item_object_data['menu-item-title'] : '' ),

				'menu-item-url' => ( isset( $_item_object_data['menu-item-url'] ) ? $_item_object_data['menu-item-url'] : '' ),

				'menu-item-description' => ( isset( $_item_object_data['menu-item-description'] ) ? $_item_object_data['menu-item-description'] : '' ),

				'menu-item-attr-title' => ( isset( $_item_object_data['menu-item-attr-title'] ) ? $_item_object_data['menu-item-attr-title'] : '' ),

				'menu-item-target' => ( isset( $_item_object_data['menu-item-target'] ) ? $_item_object_data['menu-item-target'] : '' ),

				'menu-item-classes' => ( isset( $_item_object_data['menu-item-classes'] ) ? $_item_object_data['menu-item-classes'] : '' ),

				'menu-item-xfn' => ( isset( $_item_object_data['menu-item-xfn'] ) ? $_item_object_data['menu-item-xfn'] : '' ),

			);



			$items_saved[] = wp_update_nav_menu_item( $menu_id, $_actual_db_id, $args );



		}

	}

	return $items_saved;

}

4081