Skip to content

Instantly share code, notes, and snippets.

@kucrut
Created March 7, 2013 18:42
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 kucrut/5110603 to your computer and use it in GitHub Desktop.
Save kucrut/5110603 to your computer and use it in GitHub Desktop.
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
@themefoundation
Copy link

Beautiful! Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment