WP_Sync_Post_Meta_Storage::get_storage_post_id( string $room ): int|null

This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only by core. It is listed here for completeness.

Gets or creates the storage post for a given room.

Description

Each room gets its own dedicated post so that post meta cache invalidation is scoped to a single room rather than all of them.

Parameters

$roomstringrequired
Room identifier.

Return

int|null Post ID.

Source

private function get_storage_post_id( string $room ): ?int {
	$room_hash = md5( $room );

	if ( isset( self::$storage_post_ids[ $room_hash ] ) ) {
		return self::$storage_post_ids[ $room_hash ];
	}

	// Try to find an existing post for this room.
	$posts = get_posts(
		array(
			'post_type'      => self::POST_TYPE,
			'posts_per_page' => 1,
			'post_status'    => 'publish',
			'name'           => $room_hash,
			'fields'         => 'ids',
			'orderby'        => 'ID',
			'order'          => 'ASC',
		)
	);

	$post_id = array_first( $posts );
	if ( is_int( $post_id ) ) {
		self::$storage_post_ids[ $room_hash ] = $post_id;
		return $post_id;
	}

	// Create new post for this room.
	$post_id = wp_insert_post(
		array(
			'post_type'   => self::POST_TYPE,
			'post_status' => 'publish',
			'post_title'  => 'Sync Storage',
			'post_name'   => $room_hash,
		)
	);

	if ( is_int( $post_id ) ) {
		self::$storage_post_ids[ $room_hash ] = $post_id;
		return $post_id;
	}

	return null;
}

Changelog

VersionDescription
7.0.0Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.