Skip to content

Instantly share code, notes, and snippets.

@kucrut

kucrut/gist:5110603

Created Mar 7, 2013
Embed
What would you like to do?
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
@ghost

This comment has been minimized.

Copy link

@ghost ghost commented Mar 7, 2013

Beautiful! Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.