update_meta_cache

Definition:
function update_meta_cache($meta_type, $object_ids) {}

Update the metadata cache for the specified objects.

Parameters

  • string $meta_type: Type of object metadata is for (e.g., comment, post, or user)
  • int|array $object_ids: array or comma delimited list of object IDs to update cache for

Return values

returns:Metadata cache for the specified objects, or false on failure.

Source code

function update_meta_cache($meta_type, $object_ids) {

	if ( empty( $meta_type ) || empty( $object_ids ) )

		return false;



	if ( ! $table = _get_meta_table($meta_type) )

		return false;



	$column = esc_sql($meta_type . '_id');



	global $wpdb;



	if ( !is_array($object_ids) ) {

		$object_ids = preg_replace('|[^0-9,]|', '', $object_ids);

		$object_ids = explode(',', $object_ids);

	}



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



	$cache_key = $meta_type . '_meta';

	$ids = array();

	$cache = array();

	foreach ( $object_ids as $id ) {

		$cached_object = wp_cache_get( $id, $cache_key );

		if ( false === $cached_object )

			$ids[] = $id;

		else

			$cache[$id] = $cached_object;

	}



	if ( empty( $ids ) )

		return $cache;



	// Get meta info

	$id_list = join(',', $ids);

	$meta_list = $wpdb->get_results( $wpdb->prepare("SELECT $column, meta_key, meta_value FROM $table WHERE $column IN ($id_list)",

		$meta_type), ARRAY_A );



	if ( !empty($meta_list) ) {

		foreach ( $meta_list as $metarow) {

			$mpid = intval($metarow[$column]);

			$mkey = $metarow['meta_key'];

			$mval = $metarow['meta_value'];



			// Force subkeys to be array type:

			if ( !isset($cache[$mpid]) || !is_array($cache[$mpid]) )

				$cache[$mpid] = array();

			if ( !isset($cache[$mpid][$mkey]) || !is_array($cache[$mpid][$mkey]) )

				$cache[$mpid][$mkey] = array();



			// Add a value to the current pid/key:

			$cache[$mpid][$mkey][] = $mval;

		}

	}



	foreach ( $ids as $id ) {

		if ( ! isset($cache[$id]) )

			$cache[$id] = array();

		wp_cache_add( $id, $cache[$id], $cache_key );

	}



	return $cache;

}

3179

update_home_siteurl

Definition:
function update_home_siteurl( $old_value, $value ) {}

If siteurl or home changed, flush rewrite rules.

Parameters

  • unknown_type $old_value
  • unknown_type $value

Source code

function update_home_siteurl( $old_value, $value ) {

	global $wp_rewrite;



	if ( defined( "WP_INSTALLING" ) )

		return;



	// If home changed, write rewrite rules to new location.

	$wp_rewrite->flush_rules();

}

3173

update_gallery_tab

Definition:
function update_gallery_tab($tabs) {}

Parameters

  • unknown_type $tabs

Source code

function update_gallery_tab($tabs) {

	global $wpdb;



	if ( !isset($_REQUEST['post_id']) ) {

		unset($tabs['gallery']);

		return $tabs;

	}



	$post_id = intval($_REQUEST['post_id']);



	if ( $post_id )

		$attachments = intval( $wpdb->get_var( $wpdb->prepare( "SELECT count(*) FROM $wpdb->posts WHERE post_type = 'attachment' AND post_status != 'trash' AND post_parent = %d", $post_id ) ) );



	if ( empty($attachments) ) {

		unset($tabs['gallery']);

		return $tabs;

	}



	$tabs['gallery'] = sprintf(__('Gallery (%s)'), "<span id='attachments-count'>$attachments</span>");



	return $tabs;

}

3171