[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

title

Body

[close]

/wp-includes/ -> class-wp-entity-actions-registry.php (summary)

Entity Actions API: WP_Entity_Actions_Registry class

File Size: 741 lines (24 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class

WP_Entity_Actions_Registry:: (16 methods):
  get_instance()
  register()
  report_invalid_values()
  unregister()
  get_registered()
  get_all_registered()
  get_registered_action_modules()
  get_all_registered_action_modules()
  initialize()
  doing_entity_actions_api_init()
  validate_arguments()
  validate_entity()
  skip_invalid_definitions()
  skip_invalid_ids()
  add_action_module()
  forget_empty_entity()


Class: WP_Entity_Actions_Registry  - X-Ref

Holds the actions registered for entities.

The registry maps an entity, identified by its kind and name, to its
registered action definitions keyed by id, in registration order, each
with the origin that registered it, and to the script modules registered
for it, each with the ids of the actions it applies to. register() adds
actions and validates the definitions before storing them: an action
that cannot be stored is reported and skipped, and the rest of the call
is stored. To change a registered action, unregister it and register it
again.

Actions are registered on the `wp_entity_actions_api_init` action, and only
there, with wp_register_entity_actions() and wp_unregister_entity_actions():
register() and unregister() refuse to run while the action is not
firing.

The registry is filled lazily: the first time its actions are read, it
fires the `wp_entity_actions_api_init` action, on which the actions of every
entity are registered. A read before `init` has completed is refused,
see initialize().

Once the action has fired the registry does not change: every reader of
a request, the REST controller as well as the import map of the editor
script, sees the same actions.

get_instance()   X-Ref
Returns the singleton instance.

return: WP_Entity_Actions_Registry The registry.

register( $origin, $kind, $name, $actions, $script_module = null )   X-Ref
Registers actions for an entity.

The actions must be new: an action with the id of a registered action
is reported and skipped, and so is every definition after the first of
an id that appears more than once in the call. The rest of the actions
of the call are registered: an action another plugin got to first does
not cost a plugin the others. A definition that is not an array with a
non-empty string `id` is reported and skipped the same way. To replace
a registered action, unregister it first. The script module, if any,
applies to every action the call registers.

A value DataViews does not support is reported, and a property only a
script module can provide is reported and removed, see
report_invalid_values().

The origin is stored as the `origin` property of each action, as
`registeredBy`, replacing any `origin` the definition sets.

param: string      $origin        Who registers the actions: `core`, or
param: string      $kind          The entity kind (e.g. `postType`).
param: string      $name          The entity name (e.g. `page`).
param: array[]     $actions       The list of action definitions, each with an `id`.
param: string|null $script_module The id of the script module providing
return: string[] The ids of the actions registered, in the order of the

report_invalid_values( $method, $kind, $name, $actions )   X-Ref
Reports the values of action definitions that DataViews does not
support, and the properties only a script module can provide, with
_doing_it_wrong().

A value DataViews does not support is otherwise silent: an action
whose `context` is not `list` or `single` shows on no screen. Such a
value is kept, like the field types the fields registry reports.
`callback`, `RenderModal`, and `isEligible` are functions and
components, which only a script module can provide: a value set on
the server would be called on the client and fail, so it is removed.

param: string  $method  The calling method, for the notice.
param: string  $kind    The entity kind.
param: string  $name    The entity name.
param: array[] $actions The action definitions, keyed by id.
return: array[] The definitions, without the properties only a script

unregister( $kind, $name, $ids = null )   X-Ref
Unregisters actions of an entity.

Unregistering an action removes its registered definition and drops
it from the script modules that applied to it (a module left with no
action is forgotten). Unregistering every action forgets the entity:
its registered actions and script modules.

Like register(), it only runs on the `wp_entity_actions_api_init` action, and
an invalid entity is reported and unregisters nothing. An id that is
not a non-empty string is reported and skipped, like a definition
register() cannot store.

param: string        $kind The entity kind (e.g. `postType`).
param: string        $name The entity name (e.g. `page`).
param: string[]|null $ids  The ids of the actions to unregister.
return: array[] The list of the definitions unregistered, in

get_registered( $kind, $name )   X-Ref
Returns the actions registered for an entity.

param: string $kind The entity kind (e.g. `postType`).
param: string $name The entity name (e.g. `page`).
return: array[] The list of action definitions, in registration order.

get_all_registered()   X-Ref
Returns the actions registered for every entity.

return: array<string, array<string, array[]>> The lists of action

get_registered_action_modules( $kind, $name )   X-Ref
No description

get_all_registered_action_modules()   X-Ref
Returns the ids of the script modules registered for every entity.

return: array<string, array<string, string[]>> The lists of module ids,

initialize()   X-Ref
No description

doing_entity_actions_api_init( $method )   X-Ref
Checks that the registry is firing the `wp_entity_actions_api_init` action,
as register() and unregister() require.

Outside the action a registration would either come before the
registrations made on it, and take the ids they register, or after
the actions have been read and the import map of the editor script
built from them. Refusing keeps the registry immutable once read,
even when the action is fired again with do_action(), which is why
the registry tracks its own firing rather than check doing_action().

param: string $method The calling method, for the notice.
return: bool Whether the action is firing.

validate_arguments( $method, $origin, $kind, $name, $actions, $script_module )   X-Ref
Validates the arguments of register().

param: string $method        The calling method, for the notice.
param: mixed  $origin        The origin.
param: mixed  $kind          The entity kind.
param: mixed  $name          The entity name.
param: mixed  $actions       The action definitions.
param: mixed  $script_module The script module id, if any.
return: bool Whether the call may proceed: the `wp_entity_actions_api_init`

validate_entity( $method, $kind, $name )   X-Ref
Checks that the entity kind and name are non-empty strings, reporting
them with _doing_it_wrong() otherwise.

param: string $method The calling method, for the notice.
param: mixed  $kind   The entity kind.
param: mixed  $name   The entity name.
return: bool Whether both are valid.

skip_invalid_definitions( $method, $kind, $name, $actions )   X-Ref
Drops the definitions that are not an array with a non-empty string
`id`, reporting their positions in the call with _doing_it_wrong():
like a duplicated action, an invalid definition does not cost the call
its other actions.

param: string  $method  The calling method, for the notice.
param: string  $kind    The entity kind.
param: string  $name    The entity name.
param: array[] $actions The list of action definitions.
return: array[] The valid definitions, in the order of the call.

skip_invalid_ids( $method, $kind, $name, $ids )   X-Ref
Drops the ids that are not a non-empty string, reporting their
positions in the call with _doing_it_wrong(): like an invalid
definition, an invalid id does not cost the call its other ids.

param: string $method The calling method, for the notice.
param: string $kind   The entity kind.
param: string $name   The entity name.
param: array  $ids    The ids of the actions.
return: string[] The valid ids, in the order of the call.

add_action_module( $kind, $name, $ids, $script_module )   X-Ref
Applies a script module to actions of an entity, after the actions it
already applies to.

param: string      $kind          The entity kind.
param: string      $name          The entity name.
param: string[]    $ids           The ids of the actions.
param: string|null $script_module The id of the script module, if any.

forget_empty_entity( $kind, $name )   X-Ref
Forgets an entity left without actions or script modules, and its kind
once no entity of the kind is left, so the registry only lists
entities that have some.

param: string $kind The entity kind.
param: string $name The entity name.



Generated : Tue Oct 20 08:20:34 2026 Cross-referenced by PHPXref