For Alex: Passing Arguments to Callback Functions
/** | |
* Example class | |
* | |
* This class demonstrates how to pass data to a callback function | |
* without using global varaibles. | |
*/ | |
class Example_Class { | |
public function __construct( $strings ) { | |
$this->strings = $strings; | |
foreach( $this->strings as $string ) { | |
add_action( $string[ 'hook' ], array( $this, 'echo_strings' ) ); | |
} | |
} // End function __construct() | |
public function echo_strings() { | |
$hook = current_filter(); | |
foreach ( $this->strings as $string ) { | |
if ( $string['hook'] == $hook ) { | |
echo $string['message'] . "<br />\n"; | |
} | |
} | |
} | |
} // End class Example_Class |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This comment has been minimized.
Beautiful! Thanks.