Make WordPress Core


Ignore:
Timestamp:
05/26/2026 08:14:49 AM (4 months ago)
Author:
gziolo
Message:

Abilities API: Add wp_ability_invoked action

Introduces a new wp_ability_invoked action that fires at the start of WP_Ability::execute(), before input normalization, validation, or permission checks. This gives observers a reliable entry point for every invocation regardless of outcome (short-circuit, validation failure, permission denial, or successful execution).

Also extends the existing wp_before_execute_ability and wp_after_execute_ability actions with a new $ability parameter exposing the WP_Ability instance.

Follow-up for #64989.

Props sukhendu2002, peterwilsoncc, gziolo.
Fixes #65248.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/abilities-api/class-wp-ability.php

    r62401 r62418  
    726726         *
    727727         * @since 6.9.0
     728         * @since 7.1.0 Added the `wp_ability_invoked` action.
    728729         * @since 7.1.0 Added the `wp_pre_execute_ability` filter.
    729730         *
    … …  
    732733         */
    733734        public function execute( $input = null ) {
     735                /**
     736                 * Fires when an ability is invoked, before any processing takes place.
     737                 *
     738                 * This action fires for every call regardless of outcome (validation failure,
     739                 * permission denial, short-circuit, or successful execution), and before input
     740                 * normalization so the raw input is captured as-is.
     741                 *
     742                 * @since 7.1.0
     743                 *
     744                 * @param string     $ability_name The name of the ability.
     745                 * @param mixed      $input        The raw input data for the ability, before normalization.
     746                 * @param WP_Ability $ability      The ability instance.
     747                 */
     748                do_action( 'wp_ability_invoked', $this->name, $input, $this );
     749
    734750                /**
    735751                 * Filters whether to short-circuit ability execution.
    … …  
    792808                 *
    793809                 * @since 6.9.0
    794                  *
    795                  * @param string $ability_name The name of the ability.
    796                  * @param mixed  $input        The input data for the ability.
    797                  */
    798                 do_action( 'wp_before_execute_ability', $this->name, $input );
     810                 * @since 7.1.0 Added the `$ability` parameter.
     811                 *
     812                 * @param string     $ability_name The name of the ability.
     813                 * @param mixed      $input        The input data for the ability.
     814                 * @param WP_Ability $ability      The ability instance.
     815                 */
     816                do_action( 'wp_before_execute_ability', $this->name, $input, $this );
    799817
    800818                $result = $this->do_execute( $input );
    … …  
    812830                 *
    813831                 * @since 6.9.0
    814                  *
    815                  * @param string $ability_name The name of the ability.
    816                  * @param mixed  $input        The input data for the ability.
    817                  * @param mixed  $result       The result of the ability execution.
    818                  */
    819                 do_action( 'wp_after_execute_ability', $this->name, $input, $result );
     832                 * @since 7.1.0 Added the `$ability` parameter.
     833                 *
     834                 * @param string     $ability_name The name of the ability.
     835                 * @param mixed      $input        The input data for the ability.
     836                 * @param mixed      $result       The result of the ability execution.
     837                 * @param WP_Ability $ability      The ability instance.
     838                 */
     839                do_action( 'wp_after_execute_ability', $this->name, $input, $result, $this );
    820840
    821841                return $result;
Note: See TracChangeset for help on using the changeset viewer.