Skip to content
WP Engine Developers

Live

MediaPress Live provides an interface and functionality to support live content publishing in WordPress.

Defines the post types on which the live functionality will be enabled.

Default Value

[ 'post' ]

Parameters

NameTypeDescription
post_typesarrayArray of post type slugs

Usage

add_filter( 'mediapress_live_supported_post_types', 'my_plugin_add_live_support' );
function my_plugin_add_live_support( array $post_types ): array {
$post_types[] = 'my_custom_post_type';
return $post_types;
}

Controls which block types are available in the live entry editor.

Parameters

NameTypeDescription
block_typesarrayArray of block type slugs

Usage

add_filter( 'mediapress_live_allowed_block_types', 'my_plugin_add_button_support' );
function my_plugin_add_button_support( array $block_types ): array {
$block_types[] = 'core/buttons';
$block_types[] = 'core/button';
return $block_types;
}

Customize the PHP date format used to display Live entry timestamps.

Default format: site time format + space + site date format + T.

Parameters

NameTypeDescription
formatstringThe current PHP date format string
postarray<string,mixed>The Live entry REST post data passed to filter

Usage

add_filter( 'mediapress_live_entry_timestamp_format', 'my_plugin_custom_timestamp_format', 10, 2 );
function my_plugin_custom_timestamp_format( string $format, array $post ): string {
$custom_format = 'g:i A T';
return $custom_format;
}

Fires when a post is toggled to be “live” within the block editor.

This is useful if you want to insert a block or alter the post template automatically when a post is made live.

Parameters

NameTypeDescription
isLivebooleantrue if the post is being made live, false otherwise
postIdnumberThe ID of the post being toggled
postTypestringThe post type of the post being toggled

Usage

addAction(
'mediaPressLive.toggleLive',
'my-plugin/switch-live-post-template',
(isLive, postType, postId) => {
if (!isLive) {
return;
}
dispatch(coreStore).editEntityRecord('postType', postType, postId, {
template: 'template-live',
});
},
);

Live data loading functionality is implemented using the WordPress Interactivity API and custom REST API endpoints for retrieving data.

This works by building a local store of entities (i.e: posts) that are being subscribed to for updates. By storing the REST API response data for each entity, we can use the data to render items in a declarative manner compatible with the Interactivity API. Then, when the store is updated with new data via subsequent REST API requests, the Interactivity API will handle rendering any changes to the UI.

To make polling for updates more performant, we use a dedicated REST API endpoint to ‘subscribe’ to updates related to a specific post ID. The response from this request will contain an array of objects that include post IDs and modified timestamps, amongst other data, e.g:

// REST API response from `wp-json/mediapress-live/v1/posts/3642/subscribe`
{
"3642": {
// entries are keyed by post ID for easier retrieval
"modified": 1741102923, // the timestamp this post was last updated
"restBase": "posts", // used to allow us to make the correct API call if we need to fetch data for this item
"entityType": "parent" // used to tie this item to a specific piece of state in the local store
},
"3655": {
"modified": 1741102926,
"restBase": "live-entry",
"entityType": "entries"
},
"3658": {
"modified": 1741102042,
"restBase": "live-entry",
"entityType": "entries"
},
"3656": {
"modified": 1741102049,
"restBase": "live-entry",
"entityType": "entries"
}
}

To build the above list of relevant subscriptions, we maintain a piece of post meta - _mediapress_live_subscriptions. Every time a relevant post is updated, it will push an update to it’s entry in this meta field. For example, each live-entry post will update it’s parent post meta, and the parent will update it’s own meta. Therefore, the subscribe endpoint simply needs to return this meta value during polling, rather then query the database for all relevant entries.

On the client, this data is continually compared against the local state, and any changes will result in either an updated fetch for a specific entity, or the removal of the entity from the local state.

If an entity needs to be fetched, this is done via a custom REST API endpoint which includes the modified timestamp in the URL. This simply calls the parent controller, and is only necessary since appending ?modified as a query param may not bypass caching in all instances, e.g:

// REST API response from `wp-json/mediapress-live/v1/live-entry/3656/modified/1741102049`
{
"id": 3658,
"date": "2025-03-03T08:15:14"
// etc. see WP_REST_Posts_Controller
}

Last updated: