WP_Sync_Post_Meta_Storage::remove_updates_before_cursorpublicWP 7.0.0

Removes updates from a room that are older than the given cursor.

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->remove_updates_before_cursor( $room, $cursor ): bool;
$room(string) (required)
Room identifier.
$cursor(int) (required)
Remove updates with meta_id < this cursor.

Notes

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

Changelog

Since 7.0.0 Introduced.

WP_Sync_Post_Meta_Storage::remove_updates_before_cursor() code WP 7.0

public function remove_updates_before_cursor( string $room, int $cursor ): bool {
	global $wpdb;

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

	$deleted_rows = $wpdb->query(
		$wpdb->prepare(
			"DELETE FROM {$wpdb->postmeta} WHERE post_id = %d AND meta_key = %s AND meta_id < %d",
			$post_id,
			self::SYNC_UPDATE_META_KEY,
			$cursor
		)
	);

	if ( false === $deleted_rows ) {
		return false;
	}

	return true;
}