Make WordPress Core

Ticket #58291: 58291.4.patch

File 58291.4.patch, 6.7 KB (added by bor0, 21 months ago)

Update phpdoc and fix a parse issue

  • src/wp-includes/class-wp-hook.php

     
    7272         * @param int      $accepted_args The number of arguments the function accepts.
    7373         */
    7474        public function add_filter( $hook_name, $callback, $priority, $accepted_args ) {
    75                 $idx = _wp_filter_build_unique_id( $hook_name, $callback, $priority );
     75                $idx = self::build_unique_id( $callback );
    7676
     77                if ( ! $idx ) {
     78                        return false;
     79                }
     80
    7781                $priority_existed = isset( $this->callbacks[ $priority ] );
    7882
    7983                $this->callbacks[ $priority ][ $idx ] = array(
     
    177181         * @return bool Whether the callback existed before it was removed.
    178182         */
    179183        public function remove_filter( $hook_name, $callback, $priority ) {
    180                 $function_key = _wp_filter_build_unique_id( $hook_name, $callback, $priority );
     184                $function_key = self::build_unique_id( $callback );
    181185
    182186                $exists = isset( $this->callbacks[ $priority ][ $function_key ] );
    183187
     
    217221                        return $this->has_filters();
    218222                }
    219223
    220                 $function_key = _wp_filter_build_unique_id( $hook_name, $callback, false );
     224                $function_key = self::build_unique_id( $callback );
    221225
    222226                if ( ! $function_key ) {
    223227                        return false;
     
    433437        }
    434438
    435439        /**
     440         * Builds a unique string ID for a hook callback function.
     441         *
     442         * Functions and static method callbacks are just returned as strings and
     443         * shouldn't have any speed penalty.
     444         *
     445         * @since 6.3.0
     446         *
     447         * @param callable|string|array $callback  The callback to generate ID for. The callback may
     448         *                                         or may not exist.
     449         * @return string Unique function ID for usage as array key.
     450         */
     451        private static function build_unique_id( $callback ) {
     452                if ( is_string( $callback ) ) {
     453                        return $callback;
     454                }
     455
     456                if ( is_object( $callback ) ) {
     457                        return spl_object_id( $callback );
     458                }
     459
     460                $callback = (array) $callback;
     461
     462                if ( is_object( $callback[0] ) ) {
     463                        // Object class calling.
     464                        return spl_object_id( $callback[0] ) . $callback[1];
     465                } elseif ( is_string( $callback[0] ) ) {
     466                        // Static calling.
     467                        return $callback[0] . $callback[1];
     468                }
     469        }
     470
     471        /**
    436472         * Determines whether an offset value exists.
    437473         *
    438474         * @since 4.7.0
  • src/wp-includes/compat.php

     
    492492        }
    493493}
    494494
     495if ( ! function_exists( 'spl_object_id' ) ) {
     496        /**
     497         * Polyfill for `spl_object_id()` function added in PHP 7.2.
     498         *
     499         * @since 6.3.0
     500         *
     501         * @param object $object The object.
     502         * @return int An integer identifier that is unique for each currently existing object and is always the same for each object.
     503         */
     504        function spl_object_id( $object ) {
     505                return hexdec( substr( spl_object_hash( $x ), 0, 16 ) );
     506        }
     507}
     508
    495509// IMAGETYPE_WEBP constant is only defined in PHP 7.1 or later.
    496510if ( ! defined( 'IMAGETYPE_WEBP' ) ) {
    497511        define( 'IMAGETYPE_WEBP', 18 );
  • src/wp-includes/deprecated.php

     
    46394639function wlwmanifest_link() {
    46404640        _deprecated_function( __FUNCTION__, '6.3.0' );
    46414641}
     4642
     4643/**
     4644 * Builds a unique string ID for a hook callback function.
     4645 *
     4646 * Functions and static method callbacks are just returned as strings and
     4647 * shouldn't have any speed penalty.
     4648 *
     4649 * @link https://core.trac.wordpress.org/ticket/3875
     4650 *
     4651 * @since 2.2.3
     4652 * @since 5.3.0 Removed workarounds for spl_object_hash().
     4653 *              `$hook_name` and `$priority` are no longer used,
     4654 *              and the function always returns a string.
     4655 * @deprecated 6.3.0
     4656 *
     4657 * @access private
     4658 *
     4659 * @param string                $hook_name Unused. The name of the filter to build ID for.
     4660 * @param callable|string|array $callback  The callback to generate ID for. The callback may
     4661 *                                         or may not exist.
     4662 * @param int                   $priority  Unused. The order in which the functions
     4663 *                                         associated with a particular action are executed.
     4664 * @return string Unique function ID for usage as array key.
     4665 */
     4666function _wp_filter_build_unique_id( $hook_name, $callback, $priority ) {
     4667        _deprecated_function( __FUNCTION__, '6.3.0' );
     4668
     4669        if ( is_string( $callback ) ) {
     4670                return $callback;
     4671        }
     4672
     4673        if ( is_object( $callback ) ) {
     4674                // Closures are currently implemented as objects.
     4675                $callback = array( $callback, '' );
     4676        } else {
     4677                $callback = (array) $callback;
     4678        }
     4679
     4680        if ( is_object( $callback[0] ) ) {
     4681                // Object class calling.
     4682                return spl_object_hash( $callback[0] ) . $callback[1];
     4683        } elseif ( is_string( $callback[0] ) ) {
     4684                // Static calling.
     4685                return $callback[0] . '::' . $callback[1];
     4686        }
     4687}
  • src/wp-includes/plugin.php

     
    962962
    963963        $wp_filter['all']->do_all_hook( $args );
    964964}
    965 
    966 /**
    967  * Builds a unique string ID for a hook callback function.
    968  *
    969  * Functions and static method callbacks are just returned as strings and
    970  * shouldn't have any speed penalty.
    971  *
    972  * @link https://core.trac.wordpress.org/ticket/3875
    973  *
    974  * @since 2.2.3
    975  * @since 5.3.0 Removed workarounds for spl_object_hash().
    976  *              `$hook_name` and `$priority` are no longer used,
    977  *              and the function always returns a string.
    978  *
    979  * @access private
    980  *
    981  * @param string                $hook_name Unused. The name of the filter to build ID for.
    982  * @param callable|string|array $callback  The callback to generate ID for. The callback may
    983  *                                         or may not exist.
    984  * @param int                   $priority  Unused. The order in which the functions
    985  *                                         associated with a particular action are executed.
    986  * @return string Unique function ID for usage as array key.
    987  */
    988 function _wp_filter_build_unique_id( $hook_name, $callback, $priority ) {
    989         if ( is_string( $callback ) ) {
    990                 return $callback;
    991         }
    992 
    993         if ( is_object( $callback ) ) {
    994                 // Closures are currently implemented as objects.
    995                 $callback = array( $callback, '' );
    996         } else {
    997                 $callback = (array) $callback;
    998         }
    999 
    1000         if ( is_object( $callback[0] ) ) {
    1001                 // Object class calling.
    1002                 return spl_object_hash( $callback[0] ) . $callback[1];
    1003         } elseif ( is_string( $callback[0] ) ) {
    1004                 // Static calling.
    1005                 return $callback[0] . '::' . $callback[1];
    1006         }
    1007 }