wp_update_term_count_now

Definition:
function wp_update_term_count_now( $terms, $taxonomy ) {}

Perform term count update immediately.

Parameters

  • array $terms: The term_taxonomy_id of terms to update.
  • string $taxonomy: The context of the term.

Return values

returns:Always true when complete.

Source code

function wp_update_term_count_now( $terms, $taxonomy ) {

	global $wpdb;



	$terms = array_map('intval', $terms);



	$taxonomy = get_taxonomy($taxonomy);

	if ( !empty($taxonomy->update_count_callback) ) {

		call_user_func($taxonomy->update_count_callback, $terms, $taxonomy);

	} else {

		$object_types = (array) $taxonomy->object_type;

		foreach ( $object_types as &$object_type ) {

			if ( 0 === strpos( $object_type, 'attachment:' ) )

				list( $object_type ) = explode( ':', $object_type );

		}



		if ( $object_types == array_filter( $object_types, 'post_type_exists' ) ) {

			// Only post types are attached to this taxonomy

			_update_post_term_count( $terms, $taxonomy );

		} else {

			// Default count updater

			_update_generic_term_count( $terms, $taxonomy );

		}

	}



	clean_term_cache($terms, '', false);



	return true;

}

4239

wp_update_term_count

Definition:
function wp_update_term_count( $terms, $taxonomy, $do_deferred=false ) {}

Updates the amount of terms in taxonomy.
If there is a taxonomy callback applied, then it will be called for updating the count.

Parameters

  • int|array $terms: The term_taxonomy_id of the terms
  • string $taxonomy: The context of the term.
  • $do_deferred

Return values

returns:If no terms will return false, and if successful will return true.

Source code

function wp_update_term_count( $terms, $taxonomy, $do_deferred=false ) {

	static $_deferred = array();



	if ( $do_deferred ) {

		foreach ( (array) array_keys($_deferred) as $tax ) {

			wp_update_term_count_now( $_deferred[$tax], $tax );

			unset( $_deferred[$tax] );

		}

	}



	if ( empty($terms) )

		return false;



	if ( !is_array($terms) )

		$terms = array($terms);



	if ( wp_defer_term_counting() ) {

		if ( !isset($_deferred[$taxonomy]) )

			$_deferred[$taxonomy] = array();

		$_deferred[$taxonomy] = array_unique( array_merge($_deferred[$taxonomy], $terms) );

		return true;

	}



	return wp_update_term_count_now( $terms, $taxonomy );

}

4237

wp_update_term

Definition:
function wp_update_term( $term_id, $taxonomy, $args = array() {}

Update term based on arguments provided.
The $args will indiscriminately override all values with the same field name. Care must be taken to not override important information need to update or update will fail (or perhaps create a new term, neither would be acceptable).

Parameters

  • int $term_id: The ID of the term
  • string $taxonomy: The context in which to relate the term to the object.
  • array|string $args: Overwrite term field values

Return values

returns:Returns Term ID and Taxonomy Term ID

Defined filters

  • wp_update_term_parent
    apply_filters( 'wp_update_term_parent', $parent, $term_id, $taxonomy, compact( array_keys( $args )
  • term_id_filter
    apply_filters('term_id_filter', $term_id, $tt_id)

Defined actions

  • edit_terms
    do_action( 'edit_terms', $alias->term_id );
  • edited_terms
    do_action( 'edited_terms', $alias->term_id );
  • edit_terms
    do_action( 'edit_terms', $term_id );
  • edited_terms
    do_action( 'edited_terms', $term_id );
  • edit_term_taxonomy
    do_action( 'edit_term_taxonomy', $tt_id, $taxonomy );
  • edited_term_taxonomy
    do_action( 'edited_term_taxonomy', $tt_id, $taxonomy );
  • edit_term
    do_action("edit_term", $term_id, $tt_id, $taxonomy);
  • edit_$taxonomy
    do_action("edit_$taxonomy", $term_id, $tt_id);
  • edited_term
    do_action("edited_term", $term_id, $tt_id, $taxonomy);
  • edited_$taxonomy
    do_action("edited_$taxonomy", $term_id, $tt_id);

Source code

function wp_update_term( $term_id, $taxonomy, $args = array() ) {

	global $wpdb;



	if ( ! taxonomy_exists($taxonomy) )

		return new WP_Error('invalid_taxonomy', __('Invalid taxonomy'));



	$term_id = (int) $term_id;



	// First, get all of the original args

	$term = get_term ($term_id, $taxonomy, ARRAY_A);



	if ( is_wp_error( $term ) )

		return $term;



	// Escape data pulled from DB.

	$term = add_magic_quotes($term);



	// Merge old and new args with new args overwriting old ones.

	$args = array_merge($term, $args);



	$defaults = array( 'alias_of' => '', 'description' => '', 'parent' => 0, 'slug' => '');

	$args = wp_parse_args($args, $defaults);

	$args = sanitize_term($args, $taxonomy, 'db');

	extract($args, EXTR_SKIP);



	// expected_slashed ($name)

	$name = stripslashes($name);

	$description = stripslashes($description);



	if ( '' == trim($name) )

		return new WP_Error('empty_term_name', __('A name is required for this term'));



	$empty_slug = false;

	if ( empty($slug) ) {

		$empty_slug = true;

		$slug = sanitize_title($name);

	}



	if ( $alias_of ) {

		$alias = $wpdb->get_row( $wpdb->prepare( "SELECT term_id, term_group FROM $wpdb->terms WHERE slug = %s", $alias_of) );

		if ( $alias->term_group ) {

			// The alias we want is already in a group, so let's use that one.

			$term_group = $alias->term_group;

		} else {

			// The alias isn't in a group, so let's create a new one and firstly add the alias term to it.

			$term_group = $wpdb->get_var("SELECT MAX(term_group) FROM $wpdb->terms") + 1;

			do_action( 'edit_terms', $alias->term_id );

			$wpdb->update( $wpdb->terms, compact('term_group'), array( 'term_id' => $alias->term_id ) );

			do_action( 'edited_terms', $alias->term_id );

		}

	}



	// Check $parent to see if it will cause a hierarchy loop

	$parent = apply_filters( 'wp_update_term_parent', $parent, $term_id, $taxonomy, compact( array_keys( $args ) ), $args );



	// Check for duplicate slug

	$id = $wpdb->get_var( $wpdb->prepare( "SELECT term_id FROM $wpdb->terms WHERE slug = %s", $slug ) );

	if ( $id && ($id != $term_id) ) {

		// If an empty slug was passed or the parent changed, reset the slug to something unique.

		// Otherwise, bail.

		if ( $empty_slug || ( $parent != $term['parent']) )

			$slug = wp_unique_term_slug($slug, (object) $args);

		else

			return new WP_Error('duplicate_term_slug', sprintf(__('The slug “%s” is already in use by another term'), $slug));

	}

	do_action( 'edit_terms', $term_id );

	$wpdb->update($wpdb->terms, compact( 'name', 'slug', 'term_group' ), compact( 'term_id' ) );

	if ( empty($slug) ) {

		$slug = sanitize_title($name, $term_id);

		$wpdb->update( $wpdb->terms, compact( 'slug' ), compact( 'term_id' ) );

	}

	do_action( 'edited_terms', $term_id );



	$tt_id = $wpdb->get_var( $wpdb->prepare( "SELECT tt.term_taxonomy_id FROM $wpdb->term_taxonomy AS tt INNER JOIN $wpdb->terms AS t ON tt.term_id = t.term_id WHERE tt.taxonomy = %s AND t.term_id = %d", $taxonomy, $term_id) );

	do_action( 'edit_term_taxonomy', $tt_id, $taxonomy );

	$wpdb->update( $wpdb->term_taxonomy, compact( 'term_id', 'taxonomy', 'description', 'parent' ), array( 'term_taxonomy_id' => $tt_id ) );

	do_action( 'edited_term_taxonomy', $tt_id, $taxonomy );



	do_action("edit_term", $term_id, $tt_id, $taxonomy);

	do_action("edit_$taxonomy", $term_id, $tt_id);



	$term_id = apply_filters('term_id_filter', $term_id, $tt_id);



	clean_term_cache($term_id, $taxonomy);



	do_action("edited_term", $term_id, $tt_id, $taxonomy);

	do_action("edited_$taxonomy", $term_id, $tt_id);



	return array('term_id' => $term_id, 'term_taxonomy_id' => $tt_id);

}

4235

wp_update_post

Definition:
function wp_update_post($postarr = array() {}

Update a post with new post data.
The date does not have to be set for drafts. You can set the date and it will not be overridden.

Parameters

  • array|object $postarr: Post data. Arrays are expected to be escaped, objects are not.

Return values

returns:0 on failure, Post ID on success.

Source code

function wp_update_post($postarr = array()) {

	if ( is_object($postarr) ) {

		// non-escaped post was passed

		$postarr = get_object_vars($postarr);

		$postarr = add_magic_quotes($postarr);

	}



	// First, get all of the original fields

	$post = wp_get_single_post($postarr['ID'], ARRAY_A);



	// Escape data pulled from DB.

	$post = add_magic_quotes($post);



	// Passed post category list overwrites existing category list if not empty.

	if ( isset($postarr['post_category']) && is_array($postarr['post_category'])

			 && 0 != count($postarr['post_category']) )

		$post_cats = $postarr['post_category'];

	else

		$post_cats = $post['post_category'];



	// Drafts shouldn't be assigned a date unless explicitly done so by the user

	if ( isset( $post['post_status'] ) && in_array($post['post_status'], array('draft', 'pending', 'auto-draft')) && empty($postarr['edit_date']) &&

			 ('0000-00-00 00:00:00' == $post['post_date_gmt']) )

		$clear_date = true;

	else

		$clear_date = false;



	// Merge old and new fields with new fields overwriting old ones.

	$postarr = array_merge($post, $postarr);

	$postarr['post_category'] = $post_cats;

	if ( $clear_date ) {

		$postarr['post_date'] = current_time('mysql');

		$postarr['post_date_gmt'] = '';

	}



	if ($postarr['post_type'] == 'attachment')

		return wp_insert_attachment($postarr);



	return wp_insert_post($postarr);

}

4233

wp_update_plugins

Definition:
function wp_update_plugins() {}

Check plugin versions against the latest versions hosted on WordPress.org.
The WordPress version, PHP version, and Locale is sent along with a list of all plugins installed. Checks against the WordPress server at api.wordpress.org. Will only check if WordPress isn’t installing.

Return values

returns:Returns null if update is unsupported. Returns false if check is too soon.

Source code

function wp_update_plugins() {

	include ABSPATH . WPINC . '/version.php'; // include an unmodified $wp_version



	if ( defined('WP_INSTALLING') )

		return false;



	// If running blog-side, bail unless we've not checked in the last 12 hours

	if ( !function_exists( 'get_plugins' ) )

		require_once( ABSPATH . 'wp-admin/includes/plugin.php' );



	$plugins = get_plugins();

	$active  = get_option( 'active_plugins', array() );

	$current = get_site_transient( 'update_plugins' );

	if ( ! is_object($current) )

		$current = new stdClass;



	$new_option = new stdClass;

	$new_option->last_checked = time();

	// Check for updated every 60 minutes if hitting update pages; else, check every 12 hours.

	$timeout = in_array( current_filter(), array( 'load-plugins.php', 'load-update.php', 'load-update-core.php' ) ) ? 3600 : 43200;

	$time_not_changed = isset( $current->last_checked ) && $timeout > ( time() - $current->last_checked );



	$plugin_changed = false;

	foreach ( $plugins as $file => $p ) {

		$new_option->checked[ $file ] = $p['Version'];



		if ( !isset( $current->checked[ $file ] ) || strval($current->checked[ $file ]) !== strval($p['Version']) )

			$plugin_changed = true;

	}



	if ( isset ( $current->response ) && is_array( $current->response ) ) {

		foreach ( $current->response as $plugin_file => $update_details ) {

			if ( ! isset($plugins[ $plugin_file ]) ) {

				$plugin_changed = true;

				break;

			}

		}

	}



	// Bail if we've checked in the last 12 hours and if nothing has changed

	if ( $time_not_changed && !$plugin_changed )

		return false;



	// Update last_checked for current to prevent multiple blocking requests if request hangs

	$current->last_checked = time();

	set_site_transient( 'update_plugins', $current );



	$to_send = (object) compact('plugins', 'active');



	$options = array(

		'timeout' => ( ( defined('DOING_CRON') && DOING_CRON ) ? 30 : 3),

		'body' => array( 'plugins' => serialize( $to_send ) ),

		'user-agent' => 'WordPress/' . $wp_version . '; ' . get_bloginfo( 'url' )

	);



	$raw_response = wp_remote_post('http://api.wordpress.org/plugins/update-check/1.0/', $options);



	if ( is_wp_error( $raw_response ) || 200 != wp_remote_retrieve_response_code( $raw_response ) )

		return false;



	$response = unserialize( wp_remote_retrieve_body( $raw_response ) );



	if ( false !== $response )

		$new_option->response = $response;

	else

		$new_option->response = array();



	set_site_transient( 'update_plugins', $new_option );

}

4231