Created
July 21, 2021 18:08
-
-
Save lgedeon/7b33ea518ca9e31223175046b62a8103 to your computer and use it in GitHub Desktop.
When you need to know what filter is changing your content, try adding this to wp-includes/class-wp-hook.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Calls the callback functions that have been added to a filter hook. | |
* | |
* @since 4.7.0 | |
* | |
* @param mixed $value The value to filter. | |
* @param array $args Additional parameters to pass to the callback functions. | |
* This array is expected to include $value at index 0. | |
* @return mixed The filtered value after all hooked functions are applied to it. | |
*/ | |
public function apply_filters( $value, $args ) { | |
if ( ! $this->callbacks ) { | |
return $value; | |
} | |
$nesting_level = $this->nesting_level++; | |
$this->iterations[ $nesting_level ] = array_keys( $this->callbacks ); | |
$num_args = count( $args ); | |
do { | |
$this->current_priority[ $nesting_level ] = current( $this->iterations[ $nesting_level ] ); | |
$priority = $this->current_priority[ $nesting_level ]; | |
foreach ( $this->callbacks[ $priority ] as $the_ ) { | |
if ( ! $this->doing_action ) { | |
$args[0] = $value; | |
} | |
// Add this: | |
if ( doing_filter( 'filter_to_test' ) ) { | |
echo "\nStarting with: "; | |
var_export( $value ); | |
echo "\n"; | |
} | |
// Avoid the array_slice() if possible. | |
if ( 0 == $the_['accepted_args'] ) { | |
$value = call_user_func( $the_['function'] ); | |
} elseif ( $the_['accepted_args'] >= $num_args ) { | |
$value = call_user_func_array( $the_['function'], $args ); | |
} else { | |
$value = call_user_func_array( $the_['function'], array_slice( $args, 0, (int) $the_['accepted_args'] ) ); | |
} | |
// And this: | |
if ( doing_filter( 'filter_to_test' ) ) { | |
echo "\nFunction: "; | |
var_export( $the_['function'] ); | |
echo "\nReturned: "; | |
var_export( $value ); | |
echo "\n"; | |
} | |
} | |
} while ( false !== next( $this->iterations[ $nesting_level ] ) ); | |
unset( $this->iterations[ $nesting_level ] ); | |
unset( $this->current_priority[ $nesting_level ] ); | |
$this->nesting_level--; | |
return $value; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment