WordPress.org

Make WordPress Core

Ticket #21267: 21267.diff

File 21267.diff, 5.1 KB (added by wonderboymusic, 5 years ago)
  • wp-includes/plugin.php

    diff --git wp-includes/plugin.php wp-includes/plugin.php
    index c2aebf2..3df0181 100644
    function _wp_call_all_hook($args) { 
    725725/**
    726726 * Build Unique ID for storage and retrieval.
    727727 *
    728  * The old way to serialize the callback caused issues and this function is the
    729  * solution. It works by checking for objects and creating an a new property in
    730  * the class to keep track of the object and new objects of the same class that
    731  * need to be added.
    732  *
    733  * It also allows for the removal of actions and filters for objects after they
    734  * change class properties. It is possible to include the property $wp_filter_id
    735  * in your class and set it to "null" or a number to bypass the workaround.
    736  * However this will prevent you from adding new classes and any new classes
    737  * will overwrite the previous hook by the same class.
    738  *
    739728 * Functions and static method callbacks are just returned as strings and
    740729 * shouldn't have any speed penalty.
    741730 *
    function _wp_call_all_hook($args) { 
    751740 * @param int|bool $priority Used in counting how many hooks were applied. If === false and $function is an object reference, we return the unique id only if it already has one, false otherwise.
    752741 * @return string|bool Unique ID for usage as array key or false if $priority === false and $function is an object reference, and it does not already have a unique id.
    753742 */
    754 function _wp_filter_build_unique_id($tag, $function, $priority) {
    755         global $wp_filter;
    756         static $filter_id_count = 0;
    757 
    758         if ( is_string($function) )
     743function _wp_filter_build_unique_id( $tag, $function, $priority ) {
     744        if ( is_string( $function ) )
    759745                return $function;
    760746
    761         if ( is_object($function) ) {
    762                 // Closures are currently implemented as objects
    763                 $function = array( $function, '' );
    764         } else {
    765                 $function = (array) $function;
    766         }
     747        if ( is_object( $function ) && 'Closure' === get_class( $function ) )
     748                return _wp_build_unique_closure_id( $function );
    767749
    768         if (is_object($function[0]) ) {
    769                 // Object Class Calling
    770                 if ( function_exists('spl_object_hash') ) {
    771                         return spl_object_hash($function[0]) . $function[1];
    772                 } else {
    773                         $obj_idx = get_class($function[0]).$function[1];
    774                         if ( !isset($function[0]->wp_filter_id) ) {
    775                                 if ( false === $priority )
    776                                         return false;
    777                                 $obj_idx .= isset($wp_filter[$tag][$priority]) ? count((array)$wp_filter[$tag][$priority]) : $filter_id_count;
    778                                 $function[0]->wp_filter_id = $filter_id_count;
    779                                 ++$filter_id_count;
    780                         } else {
    781                                 $obj_idx .= $function[0]->wp_filter_id;
    782                         }
     750        $function = array_filter( (array) $function );
    783751
    784                         return $obj_idx;
    785                 }
    786         } else if ( is_string($function[0]) ) {
     752        if ( is_object( $function[0] ) ) {
     753                return spl_object_hash( $function[0] ) . '~' . get_class( $function[0] ) . '::' . $function[1];
     754        } else if ( is_string( $function[0] ) ) {
    787755                // Static Calling
    788                 return $function[0] . '::' . $function[1];
     756                return join( '::', $function );
    789757        }
    790758}
     759
     760/**
     761 * Build Unique ID for Closure
     762 *
     763 * @package WordPress
     764 * @subpackage Plugin
     765 * @since 3.7
     766 *
     767 * @param callback $function Used for creating unique id
     768 * @return string Unique ID for usage as array key
     769 */
     770function _wp_build_unique_closure_id( $function ) {
     771        ob_start();
     772        echo new ReflectionFunction( $function );
     773        $source = ob_get_clean();
     774        return md5( $source );
     775}
     776/**
     777 * Build Unique ID for list of callbacks
     778 *
     779 * @package WordPress
     780 * @subpackage Plugin
     781 * @since 3.7
     782 *
     783 * @param string $tag Name of filter
     784 * @return string Unique ID representing hash of filter callback array keys (hashes)
     785 */
     786function wp_filter_callbacks_hash( $tag ) {
     787        global $wp_filter;
     788
     789        if ( ! has_filter( $tag ) )
     790                return '';
     791
     792        $hashes = array();
     793
     794        foreach ( $wp_filter[$tag] as $priority )
     795                $hashes = array_merge( $hashes, array_keys( $priority ) );
     796
     797        $hashes = array_map( '_dehash_filter_callback_object', $hashes );
     798
     799        return md5( join( '', $hashes ) );
     800 }
     801
     802/**
     803 * Remove the spl_object_hash portion of the filter callback key
     804 * This will allow persistence between requests
     805 *
     806 * @package WordPress
     807 * @subpackage Plugin
     808 * @since 3.7
     809 *
     810 * @param string $hash
     811 * @return string
     812 */
     813function _dehash_filter_callback_object( $hash ) {
     814        if ( strstr( $hash, '~' ) ) {
     815                $bits = explode( '~', $hash, 2 );
     816                return $bits[1];
     817        }
     818        return $hash;
     819 }
     820 No newline at end of file
  • wp-includes/taxonomy.php

    diff --git wp-includes/taxonomy.php wp-includes/taxonomy.php
    index 955369e..e094daf 100644
    function get_terms($taxonomies, $args = '') { 
    12471247        }
    12481248
    12491249        // $args can be whatever, only use the args defined in defaults to compute the key
    1250         $filter_key = ( has_filter('list_terms_exclusions') ) ? serialize($GLOBALS['wp_filter']['list_terms_exclusions']) : '';
    1251         $key = md5( serialize( compact(array_keys($defaults)) ) . serialize( $taxonomies ) . $filter_key );
     1250        $filter_key = wp_filter_callbacks_hash( 'list_terms_exclusions' );
     1251        $key = md5( serialize( compact( array_keys( $defaults ) ) ) . serialize( $taxonomies ) . $filter_key );
    12521252        $last_changed = wp_cache_get( 'last_changed', 'terms' );
    12531253        if ( ! $last_changed ) {
    12541254                $last_changed = microtime();