Embargoed Content
Embargoed Content attempts to prevent embargoed posts from being published, exposed via queries, or read by unauthorized users until the embargo lifts. It does this through two layers: publishing guards (which try to prevent invalid states) and display and capability guards (which try to hide embargoed content from queries and capability checks). All of these protections are best-effort attempts rather than guarantees: themes, plugins, custom code, caching, other WordPress behavior, and direct database access may bypass them.
Who can view embargoed content
Section titled “Who can view embargoed content”Access is decided in two stages. A bypass skips the guards entirely (for every embargoed post); a per-post exemption lifts only the one post that carries the granting meta. Anonymous visitors (logged out, user ID 0) are never exempt: neither a bypass nor a per-post exemption applies to them.
Bypass — Helpers::can_user_bypass_guards() (skips the display and capability guards for all embargoed posts):
- User’s ID is in the site-wide allowed-users setting (
mediapress_embargoed_content_settings_allowed_users). - User holds a role in the site-wide allowed-roles setting (
mediapress_embargoed_content_settings_allowed_roles).
Per-post exemption — Helpers::is_post_viewable_by_user() (applies to the single embargoed post carrying the meta):
- Post author — the user authored the post.
- Allowed users — the user’s ID is in the post’s
allowed_usersmeta. - Allowed roles — the user holds a role in the post’s
allowed_rolesmeta. - Allow everyone — the post’s
allowed_alltoggle is enabled (grants any logged-in user whose role can edit others’ posts, editors and administrators by default; anonymous visitors remain embargoed).
Publishing guards apply to every user, whatever their capability, bypass, or exemption.
How an embargo is defined
Section titled “How an embargo is defined”- Date — the post is embargoed until its UTC lift date (
mediapress_embargoed_content_lift_date_utc) passes, after which the guards step aside. - Indefinitely — setting
mediapress_embargoed_content_is_indefinitelytotruerestricts the post with no expiry. It is blocked from being published, scheduled, or made private, and is hidden from users without access where the display and capability guards apply, until the flag is cleared.
Embargoed media indicator
Section titled “Embargoed media indicator”Embargoed attachments are flagged with a lock badge in the MediaPress media UI — on grid items, list items, and in the media info panel. This is a visual cue only; access is enforced by the display and capability guards.
The badge is registered by consuming two JavaScript extension points exposed by the core media package (documented under Filters/Actions → JavaScript → Filters in the Media docs):
mediaPress.media.mediaItem— HOC wrapping each grid/list item; readsmediaItemfrom props.mediaPress.media.mediaInfo— HOC wrapping the info panel; the record isn’t passed as a prop, so the callback re-fetches it withuseEntityRecordusing theattachmentIdprop (core-data caches it, so no extra request).
Both callbacks render the badge when the attachment’s mediapress_embargoed_content_is_embargoed field (returned in edit context) is true. The badge component and all positioning styles live in Embargoed Content — the Media package references the badge nowhere, keeping the dependency direction one-way (Embargoed Content → Media).
Media lifecycle
Section titled “Media lifecycle”When an embargoed post is trashed, restored, or permanently deleted, the package propagates that operation to all attachments whose post_parent is the affected post. This keeps media consistent with its parent and prevents orphaned files from lingering after the parent is removed.
| Action on embargoed post | Effect on attachments | WordPress action hook | Condition |
|---|---|---|---|
| Trashed | Attachments are moved to trash | trashed_post |
EMPTY_TRASH_DAYS and MEDIA_TRASH are set |
| Restored from trash | Trashed attachments are restored | untrashed_post |
EMPTY_TRASH_DAYS and MEDIA_TRASH are set |
| Permanently deleted | Attachments are permanently deleted | before_delete_post |
Always |
mediapress_embargoed_content_post_types
Section titled “mediapress_embargoed_content_post_types”Maps each post type slug to the embargo supports it declares.
Default
[ 'post' => [ 'self' ], 'page' => [ 'self' ],]Supported values for the supports array:
'self'— the post type carries its own embargo meta.'parent'— the post type inherits its embargo from itspost_parent(most-restrictive wins). Only the direct post parent is checked;parenttypes are not resolved recursively through otherparenttypes.
Usage
add_filter( 'mediapress_embargoed_content_post_types', function ( $post_types ) { $post_types['mediapress_custom_post_type'] = [ 'self' ];
return $post_types;});The revision and attachment post types are always appended as [ 'parent' ] after the filter runs and cannot be removed or overridden. They carry no embargo meta of their own; their embargoed state is inherited entirely from their parent post.
Publishing guards
Section titled “Publishing guards”Publishing guards block attempts to publish or make private embargoed posts, to schedule them to publish before the embargo lifts, or to write contradictory embargo metadata. They aim to cover as much of the standard publishing surface as possible: block editor, quick edit, REST API, WP-CLI, programmatic calls, and cron.
Display and capability guards
Section titled “Display and capability guards”Display and capability guards attempt to hide embargoed content from queries and block unauthorized access via capability checks. Queries from logged-in admin and REST requests are filtered via pre_get_posts, other queries according to the query guard setting, and frontend singular views via template_redirect when the single post view guard is on.
Query guard setting
Section titled “Query guard setting”Admin and REST requests from a logged-in user, such as admin screens, the media modal, and the block editor, are guarded in every mode. Other queries for post types that use embargoes are guarded according to MediaPress → Settings → Embargoed Content → Query guard. Every mode other than Off adds work to these requests; the performance cost depends on your site, so performance testing on a staging site is advisable before enabling one on a live site.
| Mode | Queries guarded | Statuses guarded | Performance cost |
|---|---|---|---|
| Off (default) | None | None | - |
| Light | Main query only | Non-public | Unknown |
| Moderate | Main and secondary | Non-public | Unknown; higher than Light |
| Strict | All | All | Unknown; higher than Moderate |
A query counts as non-public when it explicitly requests a status such as draft, inherit, or any (for example get_children(), gallery and attachment queries).
Light checks only the page’s main query, so it skips secondary queries such as widgets, related posts, and galleries, and does not apply to requests with no main query (logged-out admin-ajax.php, admin-post.php, REST, WP-CLI, and cron). Strict also covers published content, so it attempts to hide a post that ends up published despite the publishing guards.
Capabilities are checked by map_meta_cap in every mode.
Single post view guard setting
Section titled “Single post view guard setting”MediaPress → Settings → Embargoed Content → Single post view guard (off by default) hooks template_redirect and attempts to return a 404 when a user who can’t view an embargoed post opens it on the frontend, including a published post still carrying an active embargo, in case one ends up published despite the publishing guards. It adds a small amount of work to single post views of post types that use embargoes; the performance cost is unknown and varies by site.
Coverage matrix
Section titled “Coverage matrix”| Entry point | Guard | Result when blocked |
|---|---|---|
wp_insert_post(), wp_update_post() |
wp_insert_post_data |
Status forced to draft / previous |
REST POST /wp/v2/posts[/{id}] |
rest_pre_insert_{post_type} |
400 WP_Error |
wp_publish_post() |
transition_post_status |
Reverted via wp_update_post |
| WP-Cron publishing a scheduled post | publish_future_post |
Moved to draft before publishing |
update_post_meta() / add_post_meta() on embargoed keys |
update_post_metadata / add_post_metadata |
Returns false, meta unchanged |
WP_Query, logged-in admin and REST |
pre_get_posts |
Embargoed IDs excluded |
WP_Query, everything else |
pre_get_posts, per the query guard mode |
Embargoed IDs excluded |
| Singular frontend view | template_redirect, if the setting is on |
404 + exit |
user_can( 'read_post' / 'edit_post' / 'delete_post' / 'read_page' / 'edit_page' / 'delete_page' ) |
map_meta_cap |
do_not_allow |