727 | | * @param string $tag Used in counting how many hooks were applied |
728 | | * @param callback $function Used for creating unique id |
729 | | * @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. |
730 | | * @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 uniqe id. |
| 724 | * @param string $tag Obsolete, kept for backwards compability. |
| 725 | * @param callback $function Callback to create Unique ID of. |
| 726 | * @param int|bool $priority Obsolete, kept for backwards compability. |
| 727 | * @return string|bool Unique ID (string), or false on failure |
739 | | if ( is_object($function) ) { |
740 | | // Closures are currently implemented as objects |
741 | | $function = array( $function, '' ); |
742 | | } else { |
743 | | $function = (array) $function; |
| 739 | // Closures are currently implemented as objects |
| 740 | is_object( $function ) && $function = array( $function, '' ); |
| 741 | |
| 742 | // Object Instance / Closure Hook |
| 743 | if ( is_object( $function[0] ) && $object_id = wp_object_hash( $function[0] ) ) |
| 744 | return $object_id . '->' . $function[1]; |
| 745 | |
| 746 | // Static Class Hook |
| 747 | return $callable_name; |
| 748 | } |
| 749 | |
| 750 | /** |
| 751 | * get object hash |
| 752 | * |
| 753 | * Returns a unique hash per object. |
| 754 | * |
| 755 | * Proxy function for wordpress installments on servers |
| 756 | * with a PHP version < 5.2.0. |
| 757 | * |
| 758 | * @since 3.0.2 |
| 759 | * @note Become deprecated with version 3.2.0 (PHP 5.2 requirements) |
| 760 | * @param object $object |
| 761 | * @return string unique object hash |
| 762 | */ |
| 763 | function wp_object_hash( &$object ) { |
| 764 | static $prefix, $count = 0, $property = '__wphookobjhash__', $spl_function_exists; |
| 765 | |
| 766 | isset( $spl_function_exists ) || $spl_function_exists = function_exists( 'spl_object_hash' ); |
| 767 | |
| 768 | // prefer spl_object_hash if available |
| 769 | if ( $spl_function_exists ) |
| 770 | return spl_object_hash( $object ); |
| 771 | |
| 772 | // validate input |
| 773 | if ( !is_object( $object ) ) { |
| 774 | trigger_error( __FUNCTION__ . '() expects parameter 1 to be object', E_USER_WARNING ); |
| 775 | return null; |
746 | | if (is_object($function[0]) ) { |
747 | | // Object Class Calling |
748 | | if ( function_exists('spl_object_hash') ) { |
749 | | return spl_object_hash($function[0]) . $function[1]; |
750 | | } else { |
751 | | $obj_idx = get_class($function[0]).$function[1]; |
752 | | if ( !isset($function[0]->wp_filter_id) ) { |
753 | | if ( false === $priority ) |
754 | | return false; |
755 | | $obj_idx .= isset($wp_filter[$tag][$priority]) ? count((array)$wp_filter[$tag][$priority]) : $filter_id_count; |
756 | | $function[0]->wp_filter_id = $filter_id_count; |
757 | | ++$filter_id_count; |
758 | | } else { |
759 | | $obj_idx .= $function[0]->wp_filter_id; |
760 | | } |
| 778 | // setup prefix and counter to generate object hash, set it to object if not set |
| 779 | isset( $prefix ) || ( ( $prefix = uniqid( '' ) ) && $property .= $prefix . '__' ); |
| 780 | isset( $object->$property ) || ( $object->$property = sprintf( '%s-%08d', $prefix , ++$count ) ); |