Created
July 29, 2014 11:31
-
-
Save thefuxia/04d13547915a8d2f64b2 to your computer and use it in GitHub Desktop.
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 | |
/** | |
* Remove callbacks for problematic hooks. | |
* | |
* Many plugins and themes do not check for a switched site context, they will | |
* save $_POST data to the wrong site. This class tries to remove all those | |
* callbacks. | |
* | |
* @version 2014.07.23 | |
* @author Inpsyde GmbH, toscho | |
* @license GPL | |
*/ | |
class Mlp_Unhook { | |
/** | |
* Register the unregister callback. | |
* | |
* @return void | |
*/ | |
public function setup() { | |
$hooks = $this->get_hooks(); | |
foreach ( $hooks as $hook ) | |
add_filter( $hook, array ( $this, 'remove_all_callbacks' ), -1 ); | |
} | |
/** | |
* Runs on every single hooks and removes everything attached to it. | |
* | |
* @param mixed $input Any parameter provided as the first one. | |
* @return mixed | |
*/ | |
public function remove_all_callbacks( $input ) { | |
if ( ms_is_switched() ) | |
remove_all_filters( current_filter() ); // covers actions too. | |
return $input; | |
} | |
/** | |
* Collect all possible hooks. | |
* | |
* @return array | |
*/ | |
private function get_hooks() { | |
$hooks = array ( | |
'pre_post_update', | |
'save_post', | |
'wp_insert_post', | |
'pre_insert_term', | |
'edit_terms', | |
'edited_terms', | |
'edit_terms', | |
'edited_terms', | |
'create_term', | |
'term_id_filter', | |
'created_term', | |
'add_term_relationship', | |
'added_term_relationship', | |
'set_object_terms', | |
'edit_term_taxonomy', | |
'edited_term_taxonomy', | |
'wp_update_term_parent' | |
); | |
$post_types = get_post_types(); | |
foreach ( $post_types as $post_type ) | |
$hooks[] = "save_post_$post_type"; | |
$taxonomies = get_taxonomies(); | |
foreach ( $taxonomies as $taxonomy ) { | |
$hooks[] = "create_$taxonomy"; | |
$hooks[] = "created_$taxonomy"; | |
} | |
return $hooks; | |
} | |
} |
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 | |
add_action( 'plugins_loaded', [ new Mlp_Unhook, 'setup' ] ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment