Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: WordPress/WordPress
...
head fork: scribu/WordPress
Checking mergeability… Don’t worry, you can still create the pull request.
  • 3 commits
  • 1 file changed
  • 0 commit comments
  • 1 contributor
Showing with 59 additions and 10 deletions.
  1. +59 −10 wp-includes/plugin.php
View
69 wp-includes/plugin.php
@@ -65,8 +65,14 @@
function add_filter($tag, $function_to_add, $priority = 10, $accepted_args = 1) {
global $wp_filter, $merged_filters;
+ list( $tag, $namespace ) = _parse_hook_name( $tag );
+
$idx = _wp_filter_build_unique_id($tag, $function_to_add, $priority);
- $wp_filter[$tag][$priority][$idx] = array('function' => $function_to_add, 'accepted_args' => $accepted_args);
+ $wp_filter[$tag][$priority][$idx] = array(
+ 'function' => $function_to_add,
+ 'accepted_args' => $accepted_args,
+ 'namespace' => $namespace
+ );
unset( $merged_filters[ $tag ] );
return true;
}
@@ -257,19 +263,52 @@ function apply_filters_ref_array($tag, $args) {
* @param int $accepted_args optional. The number of arguments the function accepts (default: 1).
* @return boolean Whether the function existed before it was removed.
*/
-function remove_filter( $tag, $function_to_remove, $priority = 10 ) {
- $function_to_remove = _wp_filter_build_unique_id($tag, $function_to_remove, $priority);
+function remove_filter( $tag, $function_to_remove = null, $priority = 10 ) {
+ global $wp_filter, $merged_filters;
+
+ list( $tag, $namespace ) = _parse_hook_name( $tag );
+
+ if ( !$namespace ) {
+ $function_to_remove = _wp_filter_build_unique_id( $tag, $function_to_remove, $priority );
+
+ $r = isset( $wp_filter[$tag][$priority][$function_to_remove] );
+
+ if ( true === $r ) {
+ unset( $wp_filter[$tag][$priority][$function_to_remove] );
+ if ( empty( $wp_filter[$tag][$priority] ) )
+ unset( $wp_filter[$tag][$priority] );
+ unset( $merged_filters[$tag] );
+ }
+
+ return $r;
+ }
- $r = isset($GLOBALS['wp_filter'][$tag][$priority][$function_to_remove]);
+ $found = false;
- if ( true === $r) {
- unset($GLOBALS['wp_filter'][$tag][$priority][$function_to_remove]);
- if ( empty($GLOBALS['wp_filter'][$tag][$priority]) )
- unset($GLOBALS['wp_filter'][$tag][$priority]);
- unset($GLOBALS['merged_filters'][$tag]);
+ if ( '*' == $tag ) {
+ foreach ( $wp_filter as $tag => $_ ) {
+ _remove_namespaced_hook( $tag, $namespace, $found );
+ }
+ } else {
+ _remove_namespaced_hook( $tag, $namespace, $found );
}
- return $r;
+ return $found;
+}
+
+function _remove_namespaced_hook( $tag, $namespace, &$found ) {
+ global $wp_filter;
+
+ foreach ( $wp_filter[$tag] as $priority => &$callbacks ) {
+ foreach ( $callbacks as $idx => $cb ) {
+ if ( $cb['namespace'] === $namespace ) {
+ $found = true;
+ unset( $callbacks[$idx] );
+ }
+ }
+ if ( empty( $callbacks ) )
+ unset( $wp_filter[$tag] );
+ }
}
/**
@@ -787,3 +826,13 @@ function _wp_filter_build_unique_id($tag, $function, $priority) {
return $function[0].$function[1];
}
}
+
+function _parse_hook_name( $tag ) {
+ $rest = explode( ':', $tag, 2 );
+ $tag = array_shift( $rest );
+
+ $namespace = isset( $rest[0] ) ? $rest[0] : false;
+
+ return array( $tag, $namespace );
+}
+

No commit comments for this range

Something went wrong with that request. Please try again.