Skip to main content

System Filters

This page documents filters for plugin options, filesystem access, and admin scripts.

FilterDescription
unblock/admin/localize_scriptAdmin JavaScript data
unblock/defaults/optionsDefault plugin options
unblock/filesystemFilesystem access control

admin/localize_script

Filter the data passed to the admin JavaScript.

ParameterTypeDescription
$dataarrayData to be localized for admin scripts

Example: Add Custom Data

add_filter( 'unblock/admin/localize_script', function ( $data ) {

$data['myPlugin'] = [
'apiUrl' => rest_url( 'my-plugin/v1' ),
'nonce' => wp_create_nonce( 'my-plugin' ),
];

return $data;

} );

defaults/options

Modify default plugin option values before they are merged with saved options.

ParameterTypeDescription
$defaultsarrayDefault options

Example: Set Default Value

add_filter( 'unblock/defaults/options', function ( $defaults ) {

$defaults['my_option'] = 'custom_value';

return $defaults;

} );

filesystem

Control whether the plugin can access the filesystem.

ParameterTypeDescription
$enabledboolWhether filesystem is enabled

Default: true

Example: Disable for Restricted Environments

add_filter( 'unblock/filesystem', function ( $enabled ) {

if ( defined( 'DISALLOW_FILE_MODS' ) && DISALLOW_FILE_MODS ) {
return false;
}

return $enabled;

} );

Example: Environment-Based Control

add_filter( 'unblock/filesystem', function ( $enabled ) {

// Disable filesystem in production.
if ( wp_get_environment_type() === 'production' ) {
return false;
}

return $enabled;

} );

Next steps