Skip to content

Instantly share code, notes, and snippets.

@joeyyax
Created February 4, 2015 18:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joeyyax/898da5ee2c6c6e42aa7e to your computer and use it in GitHub Desktop.
Save joeyyax/898da5ee2c6c6e42aa7e to your computer and use it in GitHub Desktop.
<?php
//
// Original
//
class Plugin_Class {
public function __construct() {
add_action( 'my_action', array( $this, 'action_method' ), 10 );
}
public function action_method() {
echo "<p>I'm in a class!<p>";
}
}
$pluginClass = new Plugin_Class();
// output
do_action( 'my_action' );
//
// Modified action
//
remove_action( 'my_action', array( $pluginClass, 'action_method' ), 10); // unload class action
// add new action
add_action( 'my_action', function() {
echo "<p>I'm the replacement!</p>";
} );
// output with modification
do_action( 'my_action' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment