Hooks

Docs Hooks Free · PHP hooks

modal_kit_backdrop_capability

filter

Free

PHP

Change who sees the real homepage behind the modal in the editor’s Site preview. The default, edit_others_posts, covers Editors and Administrators.

With Site preview chosen in the Modal block’s settings, the editor shows the site’s homepage behind the modal, in a frame that runs no JavaScript. The frame’s URL carries modal_kit_backdrop=1 and a nonce. For users with this capability, that request prints no modals, no admin bar and no scripts, isn’t cached or indexed, and fires modal_kit_backdrop_request. Users without it see a sketch of a page instead.

The capability is checked when the editor builds the frame’s URL, and again on the homepage request. For anyone without it the argument does nothing, so visitors can’t use it to switch modals off.

Parameters

Parameter

Description

$capability

string

Default edit_others_posts.

Returns

string A capability for current_user_can(), cast to a string.

Examples

Administrators only

PHP

add_filter( 'modal_kit_backdrop_capability', function () {
  return 'manage_options';
} );

Give Authors the homepage too

Authors can draft modals. With this, they see the real homepage, and their backdrop visits are kept out of caches and server-side analytics as well.

PHP

add_filter( 'modal_kit_backdrop_capability', function () {
  return 'publish_posts';
} );

Good to know

The filter runs whenever the modal editor loads, and on front-end requests that carry the backdrop argument.

Script tags and script preloads are removed from a backdrop request’s HTML, so script-based analytics never run there.

Who may create and publish modals is set separately, with modal_kit_post_type_capabilities.

Applied in modal-kit/includes/Backdrop.php.

Need a hook that isn’t here?