Filter & Slot Reference


Please note that this documentation is under active development.

Block Visibility includes 12+ way to conditionally display block content. That said, there are plenty of additional features and integrations that could be added. This article details the filters and slots available in Block Visibility, which allow you to extend the plugin with your own visibility controls.

JavaScript Filters

Editor

📁 src → 📁 editor → index.js

Filter the blockvisibility attribute specification (schema). Use this filter to add sub-attributes to the main blockvisibility attribute. Otherwise, a block error will likely occur.

ParametersDescription
attributes(Object) The blockvisibility attribute specification

📁 src → 📁 editor → index.js

Use for blocks that are not compatible with visibility controls or when you want to manually restrict block types from having visibility controls.

ParametersDescription
blocks(Array) All blocks that should have visibility controls disabled

📁 src → 📁 editor → index.js

Used for blocks that are not compatible with visibility controls when the blocks are used as Widgets.

ParametersDescription
blocks(Array) All blocks that should have visibility controls disabled

Inspector Controls

📁 src → 📁 editor → 📁 inspector-controls → index.js

Filter used to add additional top-level visibility controls and functionality. For example, the Hide Block control is registered at this level.

This filter should not be used to add controls that need to be part of a control set. Use blockVisibility.addControlSetControls instead.

ParametersDescription
blockAtts(Object) The current attributes of the block
enabledControls(Array) Array of all enabled visibility controls
...props(Object) All the other props passed to the VisibilityInspectorControls component

📁 src → 📁 editor → 📁 inspector-controls → controls-panel.js

Filter used to add additional visibility controls and functionality at the control set level. Controls added using this filter will appear at the block level and in Visibility Presets.

PropertiesDescription
uniqueIndex(String) A unique index for the control set
enabledControls(Array) All enabled visibility controls
setControlAtts(Function) Update the control set attributes
...props(Object) All additional props passed to the ControlSet component

Visibility Controls

📁 src → 📁 controls → 📁 screen-size → index.js

Use for blocks that are not compatible with the Screen Size control. Typically this occurs when blocks do not support CSS classes.

ParametersDescription
blocks(Array) All blocks that should have visibility controls disabled

Conditional Indicators

📁 src → 📁 editor → 📁 contextual-indicators → index.js

Filter the object of active visibility controls used to display contextual indicators.

ParametersDescription
activeControls(Object) All active visibility controls on the block
blockVisibility(Object) The blockVisibility attribute
controls(Object) All visibility controls available to the selected block
hasControlSets(Boolean) Whether or not the block has a control set
enabledControls(Array) Array of all enabled visibility controls
variables(Object) All plugin variables

📁 src → 📁 editor → 📁 contextual-indicators → index.js

Filter the CSS indicator classes that are added to each block based on the individual indicator tests.

ParametersDescription
classes(String) The current indicator classes applied to the block

Settings

📁 src → 📁 settings → 📁 visibility-controls → index.js

Allows you to add additional content to the Plugin Settings tab.

PropertiesDescription
pluginSettings(Object) Current plugin settings
setPluginSettings(Function) Update the plugin settings
...props(Object) All additional props passed to this component

📁 src → 📁 settings → 📁 visibility-controls → index.js

Allows you to add additional content to the Visibility Controls tab.

PropertiesDescription
visibilityControls(Object) Current visibility control settings
setVisibilityControls(Function) Update the visibility control settings
...props(Object) All additional props passed to this component

Global Utilities

📁 src → 📁 utils → get-enabled-controls.js

Filters the array of all available visibility controls, including those added by third-party extensions. Use this filter to register your own custom controls.

ParametersDescription
controls(Array) All available visibility controls

📁 src → 📁 utils → get-enabled-controls.js

Filters the array of all enabled visibility controls, including those added by third-party extensions. Enabled controls are ones that have not been disabled in the plugin settings. For third-party integration controls, we also make sure that the respective plugins are installed and activated. Use this filter to override enabled controls.

ParametersDescription
enabledControls(Array) All enabled controls
settings(Object) All available plugin settings
variables(Object) All available plugin variables

PHP Filters

Frontend Tests

📁 includes → 📁 frontend → render-block.php

Filter whether or not a block should be visible. All the frontend visibility tests are run through this filter, which returns true or false. When writing your own frontend tests, if is_visible is already false, this means another active test indicated the block should be hidden. In this case you should return false as well.

ParametersDescription
is_visible(Boolean) Should the block be visible
settings(Object) All available plugin settings
attributes(Object) All available plugin attributes

Settings

📁 includes → register-settings.php

Use this filter to add custom plugin settings.

ParametersDescription
settings(Array) All available plugin settings

📁 includes → register-settings.php

Use this filter to add default values for custom plugin settings.

ParametersDescription
defaults(Array) Default values for all plugin settings

Slots

Inspector Controls

📁 src → 📁 editor → 📁 inspector-controls → controls-panel.js

📁 src → 📁 editor → 📁 preset-manager → controls-set.js

Use this slot to render custom visibility control UI.

PropertiesDescription
uniqueIndex(String) A unique index for the control set
enabledControls(Array) All enabled visibility controls
setControlAtts(Function) Update the control set attributes
...props(Object) All additional props passed to the ControlSet component

📁 src → 📁 editor → 📁 inspector-controls → controls-panel.js

📁 src → 📁 editor → 📁 preset-manager → controls-set.js

Use this slot to render custom visibility control UI for third-party integrations.

PropertiesDescription
uniqueIndex(String) A unique index for the control set
enabledControls(Array) All enabled visibility controls
setControlAtts(Function) Update the control set attributes
...props(Object) All additional props passed to the ControlSet component

Settings

📁 src → 📁 settings → 📁 plugin-settings → index.js

Use this slot to add custom UI to the “General Settings” tab on the Block Visibility plugin settings page.

PropertiesDescription
pluginSettings(Object) Current plugin settings
setPluginSettings(Function) Update the plugin settings
...props(Object) All additional props passed to this component

📁 src → 📁 settings → 📁 visibility-controls → index.js

Use this slot to add custom UI to the “Visibility Controls” tab on the Block Visibility plugin settings page. Content will appear above the Integration Controls section.

PropertiesDescription
visibilityControls(Object) Current visibility control settings
setVisibilityControls(Function) Update the visibility control settings
...props(Object) All additional props passed to this component

📁 src → 📁 settings → 📁 visibility-controls → 📁 general → index.js

Use this slot to add custom UI to the “General” panel on the “Visibility Controls” tab on the Block Visibility plugin settings page. Content will appear at the bottom of the panel.

PropertiesDescription
visibilityControls(Object) Current visibility control settings
setVisibilityControls(Function) Update the visibility control settings
...props(Object) All additional props passed to this component

📁 src → 📁 settings → 📁 visibility-controls → 📁 integrations → index.js

Use this slot to add custom UI to the “Visibility Controls” tab on the Block Visibility plugin settings page. Content will appear at the bottom of the Integration Controls section.

PropertiesDescription
visibilityControls(Object) Current visibility control settings
setVisibilityControls(Function) Update the visibility control settings
...props(Object) All additional props passed to this component

Ready to try Block Visibility?

Unlock the power of the Block Editor with location controls, advanced block scheduling, and more!