API Documentation
Table of Contents
Namespaces
Constants
- JPKCOM_ALLOW_BLOCKS_IMPORT_MAX_BYTES : mixed = 1048576
- JPKCOM_ALLOW_BLOCKS_PATH : mixed = \plugin_dir_path(__FILE__)
- JPKCOM_ALLOW_BLOCKS_VERSION : mixed = '3.1.1'
- JPKCOM_ALLOWBLOCKS_ABILITY_CATEGORY : mixed = 'jpkcom-content'
- Ability category.
- JPKCOM_ALLOWBLOCKS_ABILITY_INPUT_KEYS : mixed = ['jpkcom-allow-blocks/list-allowed-blocks' => []]
- Top-level input keys the ability declares.
Functions
- jpkcom_allow_blocks_abilities_enabled() : bool
- Decide whether the ability should be registered at all.
- jpkcom_allow_blocks_ability_log() : void
- Write a debug line, and only with WP_DEBUG.
- jpkcom_allow_blocks_ability_error() : WP_Error
- Build a WP_Error carrying an HTTP status.
- jpkcom_allow_blocks_ability_boundary() : array<string, mixed>|WP_Error
- Turn a Throwable out of the callback into a WP_Error.
- jpkcom_allow_blocks_ability_capability() : bool
- Check the capability required to run the ability.
- jpkcom_allow_blocks_ability_meta() : array<string, mixed>
- Build the meta array for the ability.
- jpkcom_allow_blocks_ability_normalise_input() : array<string, mixed>|null
- Bring the value core hands the callback into array form.
- jpkcom_allow_blocks_ability_validate_input_keys() : true|WP_Error
- Refuse a top-level input key the ability does not declare.
- jpkcom_allow_blocks_ability_list_inner() : array<string, mixed>|WP_Error
- Report which blocks the calling user may insert, and how roles are configured.
- jpkcom_allow_blocks_ability_permission() : bool
- Permission callback.
- jpkcom_allow_blocks_ability_list() : array<string, mixed>|WP_Error
- Execute callback.
- jpkcom_allow_blocks_get_ability_definitions() : array<string, array<string, mixed>>
- Build the registration arguments.
- jpkcom_allow_blocks_register_ability_category() : void
- Register the shared category, unless a sibling plugin already did.
- jpkcom_allow_blocks_register_abilities() : void
- Register the ability.
- jpkcom_allow_blocks_menu_slug() : string
- Slug of the settings page.
- jpkcom_allow_blocks_editable_roles() : array<string, string>
- Roles that can be restricted from the settings screen.
- jpkcom_allow_blocks_block_rows() : array<int, array{name: string, title: string, category: string, registered: bool}>
- Rows for the block matrix.
- jpkcom_allow_blocks_render_import_preview() : void
- Render the pending import preview, if a valid one exists.
- jpkcom_allow_blocks_import_error_message() : string
- Translated message for a known import error code.
- jpkcom_allow_blocks_render_page() : void
- Render the settings screen.
- jpkcom_allow_blocks_apply_form() : array<string|int, mixed>
- Compute new settings from a settings-screen submission.
- jpkcom_allow_blocks_is_exempt() : bool
- Whether the current user is exempt from any restriction.
- jpkcom_allow_blocks_current_role_slugs() : array<string|int, string>
- Role slugs of the current user.
- jpkcom_allow_blocks_all_block_names() : array<string|int, string>
- Every block name this site knows about.
- jpkcom_allow_blocks_filter_allowed() : mixed
- Remove the blocked block types from the allowed list.
- jpkcom_allow_blocks_export_payload() : array<string|int, mixed>
- Build the exportable payload for a settings structure.
- jpkcom_allow_blocks_export_filename() : string
- Filename offered for a downloaded export.
- jpkcom_allow_blocks_parse_import() : array{ok: bool, error: string, rejected: int, settings: array}
- Decode and validate an import payload.
- jpkcom_allow_blocks_merge_import() : array<string|int, mixed>
- Merge an imported settings structure into the current one.
- jpkcom_allow_blocks_import_preview() : array{roles_changed: int, blocks_changed: int, unknown_roles: string[], unknown_blocks: string[]}
- Describe what an import would change, before anything is written.
- jpkcom_allow_blocks_import_error_redirect() : never
- Redirect back to the settings page with an import error notice.
- jpkcom_allow_blocks_option_name() : string
- Name of the option holding all settings.
- jpkcom_allow_blocks_is_valid_block_name() : bool
- Whether a string is a syntactically valid block name.
-
jpkcom_allow_blocks_empty_settings()
: array{schema: int, updated: string, roles: array
, labels: array } - The empty settings structure.
- jpkcom_allow_blocks_sanitize_settings() : array<string|int, mixed>
- Coerce any input into a valid settings structure.
- jpkcom_allow_blocks_count_rejected() : int
- Count how many entries a sanitised import or save would discard.
- jpkcom_allow_blocks_get_settings() : array<string|int, mixed>
- Read the validated settings.
- jpkcom_allow_blocks_save_settings() : bool
- Validate and store the settings.
- jpkcom_allow_blocks_blocked_for_roles() : array<string|int, string>
- Block names blocked for every one of the given roles.
Constants
JPKCOM_ALLOW_BLOCKS_IMPORT_MAX_BYTES
public
mixed
JPKCOM_ALLOW_BLOCKS_IMPORT_MAX_BYTES
= 1048576
JPKCOM_ALLOW_BLOCKS_PATH
public
mixed
JPKCOM_ALLOW_BLOCKS_PATH
= \plugin_dir_path(__FILE__)
JPKCOM_ALLOW_BLOCKS_VERSION
public
mixed
JPKCOM_ALLOW_BLOCKS_VERSION
= '3.1.1'
JPKCOM_ALLOWBLOCKS_ABILITY_CATEGORY
Ability category.
public
mixed
JPKCOM_ALLOWBLOCKS_ABILITY_CATEGORY
= 'jpkcom-content'
Categories are global and registration is FIRST-WINS, so this goes through wp_has_ability_category() rather than assuming.
Tags
JPKCOM_ALLOWBLOCKS_ABILITY_INPUT_KEYS
Top-level input keys the ability declares.
public
mixed
JPKCOM_ALLOWBLOCKS_ABILITY_INPUT_KEYS
= ['jpkcom-allow-blocks/list-allowed-blocks' => []]
Cross-checked against the registered schema by tests/test-abilities.php.
Tags
Functions
jpkcom_allow_blocks_abilities_enabled()
Decide whether the ability should be registered at all.
jpkcom_allow_blocks_abilities_enabled() : bool
Both spellings of the kill switch are honoured. README.md and CLAUDE.md have always documented the separated JPKCOM_ALLOW_BLOCKS_ABILITIES, but 3.1.0 shipped a check for the run-together JPKCOM_ALLOWBLOCKS_ABILITIES, so the documented constant did nothing and only the undocumented one worked. Accepting both keeps a 3.1.0 workaround working while making the documented spelling authoritative.
The plugin's constant naming is genuinely split, which is how the slip survived review: the main file uses JPKCOM_ALLOW_BLOCKS_* (VERSION, PATH, IMPORT_MAX_BYTES), while the two other constants in THIS file run the words together (JPKCOM_ALLOWBLOCKS_ABILITY_CATEGORY, _ABILITY_INPUT_KEYS). Writing the local spelling here was the natural mistake to make.
Tags
Return values
bool —True when registration should proceed.
jpkcom_allow_blocks_ability_log()
Write a debug line, and only with WP_DEBUG.
jpkcom_allow_blocks_ability_log(string $message) : void
Parameters
- $message : string
-
Message.
Tags
jpkcom_allow_blocks_ability_error()
Build a WP_Error carrying an HTTP status.
jpkcom_allow_blocks_ability_error(string $code, string $message[, int $status = 400 ]) : WP_Error
Without data['status'] rest_ensure_response() defaults to 500, and a 5xx tells an agent "transient fault, retry unchanged" - the opposite of what a caller mistake needs to hear.
Parameters
- $code : string
-
Error code.
- $message : string
-
Message.
- $status : int = 400
-
HTTP status.
Tags
Return values
WP_Error —Error.
jpkcom_allow_blocks_ability_boundary()
Turn a Throwable out of the callback into a WP_Error.
jpkcom_allow_blocks_ability_boundary(callable $body, string $ability) : array<string, mixed>|WP_Error
Parameters
- $body : callable
-
Callback.
- $ability : string
-
Ability name.
Tags
Return values
array<string, mixed>|WP_Error —Result or error.
jpkcom_allow_blocks_ability_capability()
Check the capability required to run the ability.
jpkcom_allow_blocks_ability_capability(string $ability) : bool
edit_posts: the answer is only meaningful to someone who edits content,
and it reports how the site restricts every role, which is configuration
rather than visitor-facing content.
Parameters
- $ability : string
-
Ability name.
Tags
Return values
bool —True when the current user may run it.
jpkcom_allow_blocks_ability_meta()
Build the meta array for the ability.
jpkcom_allow_blocks_ability_meta(string $ability) : array<string, mixed>
All three annotations explicit: they default to null and the REST run controller derives the HTTP verb from them, so without readonly the run route would be POST-only.
Parameters
- $ability : string
-
Ability name.
Tags
Return values
array<string, mixed> —Meta array.
jpkcom_allow_blocks_ability_normalise_input()
Bring the value core hands the callback into array form.
jpkcom_allow_blocks_ability_normalise_input(mixed $input) : array<string, mixed>|null
normalize_input() substitutes the schema's top-level default when the input is exactly null, and that default is a stdClass - so the callback receives an object and must read it.
Parameters
- $input : mixed
-
Raw input.
Tags
Return values
array<string, mixed>|null —Array form, or null when unusable.
jpkcom_allow_blocks_ability_validate_input_keys()
Refuse a top-level input key the ability does not declare.
jpkcom_allow_blocks_ability_validate_input_keys(array<string, mixed> $input, array<string|int, string> $allowed) : true|WP_Error
Parameters
- $input : array<string, mixed>
-
Raw input.
- $allowed : array<string|int, string>
-
Declared keys.
Tags
Return values
true|WP_Error —True when every key is declared.
jpkcom_allow_blocks_ability_list_inner()
Report which blocks the calling user may insert, and how roles are configured.
jpkcom_allow_blocks_ability_list_inner([mixed $input = null ]) : array<string, mixed>|WP_Error
The effective list comes from running the plugin's OWN filter with true
as the incoming value - "everything is allowed so far" - so the answer is
whatever the editor would actually be handed. It is not re-derived from the
option, and that matters twice over:
- The blocked set for a user is the INTERSECTION across their roles. A user with two roles is blocked only from what both block, and one role with an empty list lifts the restriction entirely. A union would be the opposite answer.
- The exemption is
manage_optionsand is itself filterable, so a site can move it somewhere this ability has no way to predict.
Parameters
- $input : mixed = null
-
Ability input.
Tags
Return values
array<string, mixed>|WP_Error —Result.
jpkcom_allow_blocks_ability_permission()
Permission callback.
jpkcom_allow_blocks_ability_permission([mixed $input = null ]) : bool
Parameters
- $input : mixed = null
-
Validated input, unused.
Tags
Return values
bool —True when the current user may run the ability.
jpkcom_allow_blocks_ability_list()
Execute callback.
jpkcom_allow_blocks_ability_list([mixed $input = null ]) : array<string, mixed>|WP_Error
Parameters
- $input : mixed = null
-
Ability input.
Tags
Return values
array<string, mixed>|WP_Error —Result.
jpkcom_allow_blocks_get_ability_definitions()
Build the registration arguments.
jpkcom_allow_blocks_get_ability_definitions() : array<string, array<string, mixed>>
Reads no WordPress state and touches no registry, which is what lets the CI harness assert the shape without a WordPress installation.
Tags
Return values
array<string, array<string, mixed>> —Ability name => registration args.
jpkcom_allow_blocks_register_ability_category()
Register the shared category, unless a sibling plugin already did.
jpkcom_allow_blocks_register_ability_category() : void
Tags
jpkcom_allow_blocks_register_abilities()
Register the ability.
jpkcom_allow_blocks_register_abilities() : void
wp_register_ability() returns null on EVERY failure path and reports only through _doing_it_wrong(), which is silent in production - and so is the debug log without WP_DEBUG.
Tags
jpkcom_allow_blocks_menu_slug()
Slug of the settings page.
jpkcom_allow_blocks_menu_slug() : string
Tags
Return values
string —Menu slug.
jpkcom_allow_blocks_editable_roles()
Roles that can be restricted from the settings screen.
jpkcom_allow_blocks_editable_roles([bool $include_non_editing = false ]) : array<string, string>
Administrators are never offered: they always bypass the filter, so a
checkbox for them would be a lie. Roles without edit_posts never see
the block editor, so they are hidden by default and only surfaced when
explicitly asked for. A slug the store would refuse (anything
sanitize_key() would change, e.g. a custom role registered with
upper case or spaces) is never offered either: the UI must not put a
column on screen whose ticks jpkcom_allow_blocks_sanitize_settings()
would silently discard on save.
Parameters
- $include_non_editing : bool = false
-
Whether to also include roles that cannot edit posts.
Tags
Return values
array<string, string> —Role slug to display name.
jpkcom_allow_blocks_block_rows()
Rows for the block matrix.
jpkcom_allow_blocks_block_rows(array<string|int, mixed> $settings) : array<int, array{name: string, title: string, category: string, registered: bool}>
The union of the registered blocks and every block name mentioned in the settings, so a block from a deactivated plugin still shows up instead of silently vanishing from the screen that would otherwise unblock it.
Parameters
- $settings : array<string|int, mixed>
-
Validated settings.
Tags
Return values
array<int, array{name: string, title: string, category: string, registered: bool}> —Rows, sorted by category then title.
jpkcom_allow_blocks_render_import_preview()
Render the pending import preview, if a valid one exists.
jpkcom_allow_blocks_render_import_preview() : void
Reads the token the preview handler put in the jpkcom-ab-import query
argument, fetches the parsed settings it stashed in a transient under
that token, and renders a confirmation block inside the caller's
.wrap - never a standalone document, so the import flow never leaves
the admin chrome. A missing or expired transient renders an
explanatory notice instead and the normal screen still renders
underneath it.
Tags
jpkcom_allow_blocks_import_error_message()
Translated message for a known import error code.
jpkcom_allow_blocks_import_error_message(string $code) : string
The error travels through the query string as a short code rather than free text, so a crafted link cannot put arbitrary words in front of an administrator. A code this function does not recognise is ignored - the caller shows no notice at all rather than falling back to something generic.
Parameters
- $code : string
-
Error code produced by includes/import-export.php.
Tags
Return values
string —Translated message, or '' when the code is unknown.
jpkcom_allow_blocks_render_page()
Render the settings screen.
jpkcom_allow_blocks_render_page() : void
Emits the controls, the save form with its checkbox matrix, and the import/export section, in that order. A checkbox is checked when the block is not blocked for that role, i.e. it reflects the allow list rather than the stored deny list.
Tags
jpkcom_allow_blocks_apply_form()
Compute new settings from a settings-screen submission.
jpkcom_allow_blocks_apply_form(array<string|int, mixed> $settings, array<string|int, string> $rendered, array<string, array<string, mixed>> $allowed[, array<string, mixed> $forget = array() ][, array<string|int, string>|null $roles = null ]) : array<string|int, mixed>
The difference is taken over the rendered rows only: names the form did not show keep whatever they had. A save while the table is filtered must not wipe the rows that were scrolled out of view.
An unregistered row can be dropped for good in two ways: ticking
forget[<name>] removes it from every role the stored settings
currently know about and from labels unconditionally, regardless
of the per-role checkboxes on the same row and regardless of whether
a given role was even rendered this save (see below); and, even
without ticking it, a row that ends up blocked by no role at all
after this save has its label dropped automatically once the block
is not registered - a name nobody blocks and nothing registers has
no reason to persist. A registered block's label is always refreshed
from its current title, never from the block name: a block without a
real title in its registration is not given one here either.
Forget deliberately purges more broadly than the checkbox diff does.
The checkbox diff below is scoped to $roles because that has to
match exactly what was rendered - see the parameter doc. But "forget
this block" is a stronger promise than "uncheck every box I can see":
a role hidden by the "show roles without edit_posts" toggle can still
block the same name, and if forget only cleared the rendered roles,
the name would keep blocking silently in the hidden role while
disappearing from labels - unregistered, unreachable, and still
growing the option, the exact failure this mechanism exists to close.
$rendered is only deduplicated here, not validated: an invalid name
moving through this function does no harm because
jpkcom_allow_blocks_sanitize_settings() always filters the role
lists and labels it returns against the block-name grammar, so a
second filter pass here would be provably redundant rather than a
second line of defence.
Parameters
- $settings : array<string|int, mixed>
-
Current validated settings.
- $rendered : array<string|int, string>
-
Block names the form rendered.
- $allowed : array<string, array<string, mixed>>
-
Ticked boxes, keyed role then block name.
- $forget : array<string, mixed> = array()
-
Rows whose "forget this block" box was ticked, keyed by block name.
- $roles : array<string|int, string>|null = null
-
Role slugs the checkbox diff processes, matching what was rendered. Defaults to every editable role, including ones that cannot edit posts. Does not limit the forget purge, which always reaches every role already present in
$settings['roles']in addition to these.
Tags
Return values
array<string|int, mixed> —New settings, not yet stored.
jpkcom_allow_blocks_is_exempt()
Whether the current user is exempt from any restriction.
jpkcom_allow_blocks_is_exempt() : bool
Expressed as a capability rather than a role slug so multisite super admins are covered. Administrators are never restricted.
Tags
Return values
bool —True when no restriction applies.
jpkcom_allow_blocks_current_role_slugs()
Role slugs of the current user.
jpkcom_allow_blocks_current_role_slugs() : array<string|int, string>
Tags
Return values
array<string|int, string> —Role slugs, empty when there is no user.
jpkcom_allow_blocks_all_block_names()
Every block name this site knows about.
jpkcom_allow_blocks_all_block_names(array<string|int, mixed> $settings) : array<string|int, string>
The server-side registry, plus every name mentioned in the settings so a deactivated plugin's blocks are not silently forgotten, plus whatever the extension filter adds.
Blocks registered only in JavaScript are invisible to PHP. Sites using
such blocks can add their names through
jpkcom_allow_blocks_extra_block_names.
Parameters
- $settings : array<string|int, mixed>
-
Validated settings.
Tags
Return values
array<string|int, string> —Unique block names.
jpkcom_allow_blocks_filter_allowed()
Remove the blocked block types from the allowed list.
jpkcom_allow_blocks_filter_allowed(mixed $allowed, mixed $context) : mixed
Returns the incoming value untouched whenever nothing is blocked, so an active but unconfigured plugin has no effect at all. An incoming array is only ever reduced, never extended, so restrictions set by other plugins are respected instead of overwritten.
Parameters
- $allowed : mixed
-
Incoming value: true, false or an array of names.
- $context : mixed
-
The block editor context. Unused.
Tags
Return values
mixed —The allowed block types.
jpkcom_allow_blocks_export_payload()
Build the exportable payload for a settings structure.
jpkcom_allow_blocks_export_payload(array<string|int, mixed> $settings) : array<string|int, mixed>
Adds provenance fields so an import can tell where a file came from: which plugin version wrote it, which site it was exported from, and when.
Parameters
- $settings : array<string|int, mixed>
-
Validated settings.
Tags
Return values
array<string|int, mixed> —The settings plus plugin_version, site_url and exported.
jpkcom_allow_blocks_export_filename()
Filename offered for a downloaded export.
jpkcom_allow_blocks_export_filename() : string
Includes the site's host so two exports made on the same day from different sites do not collide once both files sit in the same downloads folder.
Tags
Return values
string —Filename ending in .json.
jpkcom_allow_blocks_parse_import()
Decode and validate an import payload.
jpkcom_allow_blocks_parse_import(string $json) : array{ok: bool, error: string, rejected: int, settings: array}
Every rejection path leaves settings empty and carries a short error
code rather than a translated message: the code travels through a
redirect's query string, and a free-text message there would let a
crafted link put arbitrary words in front of an administrator.
includes/admin-page.php's jpkcom_allow_blocks_import_error_message()
maps each code to its translated text. Nothing here writes anything.
Parameters
- $json : string
-
Raw file contents.
Tags
Return values
array{ok: bool, error: string, rejected: int, settings: array} —Parse result. error is
a stable code ('invalid-json', 'bad-schema', 'no-roles') on failure, empty on
success. rejected counts entries the raw payload contained that did not survive
sanitising, always 0 on failure since nothing is sanitised on that path.
jpkcom_allow_blocks_merge_import()
Merge an imported settings structure into the current one.
jpkcom_allow_blocks_merge_import(array<string|int, mixed> $current, array<string|int, mixed> $incoming) : array<string|int, mixed>
The unit is the role, not the individual block: a role present in
$incoming replaces that role's whole list, a role absent from it is
left completely untouched. A role that does not exist on this site is
stored anyway - it may be created later, or come from a plugin that is
currently deactivated - which mirrors why this plugin stores a deny
list at all: nothing is ever pruned. Labels are merged with the
incoming file winning for keys it contains.
Parameters
- $current : array<string|int, mixed>
-
Current validated settings.
- $incoming : array<string|int, mixed>
-
Validated settings decoded from an import file.
Tags
Return values
array<string|int, mixed> —Merged settings, not yet stored.
jpkcom_allow_blocks_import_preview()
Describe what an import would change, before anything is written.
jpkcom_allow_blocks_import_preview(array<string|int, mixed> $current, array<string|int, mixed> $incoming, array<string|int, string> $known_roles[, array<string|int, string> $known_blocks = array() ]) : array{roles_changed: int, blocks_changed: int, unknown_roles: string[], unknown_blocks: string[]}
Counts are taken per role: a role counts as changed when its list
would differ from what is currently stored, whether or not the role
exists on this site. unknown_roles names incoming roles absent from
$known_roles so the import is not silently doing more than it
appears to. unknown_blocks names blocks the incoming file mentions
that are not in $known_blocks - the live block registry, passed in
rather than read here so this stays a pure, testable function. That
includes a block already present in $current: a plugin that is
currently switched off still leaves its block name in the stored
settings, and the whole point of this count is to surface exactly
that "this install cannot currently offer it" case.
Parameters
- $current : array<string|int, mixed>
-
Current validated settings.
- $incoming : array<string|int, mixed>
-
Validated settings decoded from an import file.
- $known_roles : array<string|int, string>
-
Role slugs that exist on this site.
- $known_blocks : array<string|int, string> = array()
-
Block names registered on this site. Defaults to empty, which marks every incoming block unknown; callers should always pass the real registry list.
Tags
Return values
array{roles_changed: int, blocks_changed: int, unknown_roles: string[], unknown_blocks: string[]} —Preview summary.
jpkcom_allow_blocks_import_error_redirect()
Redirect back to the settings page with an import error notice.
jpkcom_allow_blocks_import_error_redirect(string $code, string $back_url) : never
Used in place of wp_die() for anything short of a failed capability or
nonce check, so a rejected upload never throws the user out of the
admin interface - they land back on the settings screen with an
explanation instead of a bare error page. Carries a short error code
rather than a translated message: admin-page.php maps the code to
text, and ignores anything it does not recognise, so a crafted link
cannot put arbitrary words in front of an administrator through this
query argument.
Parameters
- $code : string
-
Error code, one of the keys
jpkcom_allow_blocks_import_error_message()understands. - $back_url : string
-
Settings page URL to redirect to.
Tags
Return values
neverjpkcom_allow_blocks_option_name()
Name of the option holding all settings.
jpkcom_allow_blocks_option_name() : string
Tags
Return values
string —Option name.
jpkcom_allow_blocks_is_valid_block_name()
Whether a string is a syntactically valid block name.
jpkcom_allow_blocks_is_valid_block_name(string $name) : bool
Follows the WordPress block name grammar: a lowercase namespace and name separated by exactly one slash.
Parameters
- $name : string
-
Candidate block name.
Tags
Return values
bool —True when the name may be stored.
jpkcom_allow_blocks_empty_settings()
The empty settings structure.
jpkcom_allow_blocks_empty_settings() : array{schema: int, updated: string, roles: array, labels: array}
Tags
Return values
array{schema: int, updated: string, roles: arrayjpkcom_allow_blocks_sanitize_settings()
Coerce any input into a valid settings structure.
jpkcom_allow_blocks_sanitize_settings(mixed $raw) : array<string|int, mixed>
Entries that fail validation are dropped rather than stored. Never throws, so a corrupt option can only ever mean "nothing is blocked".
Parameters
- $raw : mixed
-
Value from the database, an import file or a form.
Tags
Return values
array<string|int, mixed> —The validated structure.
jpkcom_allow_blocks_count_rejected()
Count how many entries a sanitised import or save would discard.
jpkcom_allow_blocks_count_rejected(mixed $raw) : int
Walks the same validation rules as jpkcom_allow_blocks_sanitize_settings()
without mutating anything, so a caller can tell the user "N entries were
invalid and will be ignored" instead of silently dropping them. A
companion function rather than a change to the sanitiser's signature,
so every existing caller of jpkcom_allow_blocks_sanitize_settings()
keeps working unchanged.
Counts, added together:
- one for every
rolesentry whose value is not an array (the entry cannot be walked further, so it counts as a single rejection), - one for every role whose slug does not survive
sanitize_key()unchanged (the whole role is dropped), - one for every block name within an otherwise valid role that is not a string or fails the block-name grammar,
- one for every
labelsentry whose key is not a valid block name or whose value is not a string.
Parameters
- $raw : mixed
-
Value from an import file or a form, same input the sanitiser would receive.
Tags
Return values
int —Number of entries the sanitiser would discard.
jpkcom_allow_blocks_get_settings()
Read the validated settings.
jpkcom_allow_blocks_get_settings() : array<string|int, mixed>
Tags
Return values
array<string|int, mixed> —The validated structure.
jpkcom_allow_blocks_save_settings()
Validate and store the settings.
jpkcom_allow_blocks_save_settings(array<string|int, mixed> $settings) : bool
Autoload is off: the option is only read in the admin area, so the front end should not carry it on every request.
Parameters
- $settings : array<string|int, mixed>
-
Structure to store.
Tags
Return values
bool —True when the option was written.
jpkcom_allow_blocks_blocked_for_roles()
Block names blocked for every one of the given roles.
jpkcom_allow_blocks_blocked_for_roles(array<string|int, string> $role_slugs[, array<string|int, mixed>|null $settings = null ]) : array<string|int, string>
The intersection, not the union: a block is blocked only when all of the user's roles block it. This mirrors WordPress capability semantics, where holding more roles never means holding fewer rights. A role with no entry blocks nothing, so it empties the intersection.
Parameters
- $role_slugs : array<string|int, string>
-
Roles of the user.
- $settings : array<string|int, mixed>|null = null
-
Settings to use, or null to read them.
Tags
Return values
array<string|int, string> —Blocked block names, re-indexed.