WP_Sync_Post_Meta_Storage::add_updatepublicWP 7.0.0

Adds a sync update to a given room.

Method of the class: WP_Sync_Post_Meta_Storage{}

No Hooks.

Returns

true|false. True on success, false on failure.

Usage

$WP_Sync_Post_Meta_Storage = new WP_Sync_Post_Meta_Storage();
$WP_Sync_Post_Meta_Storage->add_update( $room, $update ): bool;
$room(string) (required)
Room identifier.
$update(mixed) (required)
Sync update.

Notes

  • Global. wpdb. $wpdb WordPress database abstraction object.

Changelog

Since 7.0.0 Introduced.

WP_Sync_Post_Meta_Storage::add_update() code WP 7.0

public function add_update( string $room, $update ): bool {
	global $wpdb;

	$post_id = $this->get_storage_post_id( $room );
	if ( null === $post_id ) {
		return false;
	}

	// Use direct database operation to avoid cache invalidation performed by
	// post meta functions (`wp_cache_set_posts_last_changed()` and direct
	// `wp_cache_delete()` calls).
	return (bool) $wpdb->insert(
		$wpdb->postmeta,
		array(
			'post_id'    => $post_id,
			'meta_key'   => self::SYNC_UPDATE_META_KEY,
			'meta_value' => wp_json_encode( $update ),
		),
		array( '%d', '%s', '%s' )
	);
}