I have been trying to write a reusable modular options class and I am stuck at this specific point.
How do i define hooks within php classes?
Try 1 :
class super_options {
// ..........................
function render_options_page ()
{
//....................
$this->top_page_hook();
//....................
}
// ..........................
function top_page_hook() {
do_action( array( &$this, 'top_page_hook') );
}
}
and when hooking to the above, add_action( array( &$plugs, 'top_page_hook' ), 'stuff_for_top_hook' );
This doesn't work.
Try 2 :
- Replacing the
$this->top_page_hook();, withdo_action( 'top_page_hook' ); - Calling
add_action( 'top_page_hook', 'stuff_for_top_hook' ); - Works, but the class loses its reusability.
So how do i take care of this? Please share your wisdom. Thanks.