| 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 | | * |
| 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 ); |
| | 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 | */ |
| | 770 | function _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 | */ |
| | 786 | function 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 | */ |
| | 813 | function _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 |