Skip to main content
the ampersand is for PHP4 compat, removed it, this isn't the 90's
Source Link
Tom J Nowell
  • 60.6k
  • 7
  • 77
  • 147

Generally speaking, you wouldn't add an entire class to a hook. The add_action()/add_filter() hooks expect callback functions, which can be referenced from within a class.

Let's say that you have an init() function inside your class, that you want to hook into the WordPress init hook.

Put your add_action() call inside your class, and then identify the callback like so:

add_action( 'init', array( &$this$this, 'init' ) );

(Note: I'm assuming your class is properly namespaced; otherwise, be sure to namespace your callback functions.)

Generally speaking, you wouldn't add an entire class to a hook. The add_action()/add_filter() hooks expect callback functions, which can be referenced from within a class.

Let's say that you have an init() function inside your class, that you want to hook into the WordPress init hook.

Put your add_action() call inside your class, and then identify the callback like so:

add_action( 'init', array( &$this, 'init' ) );

(Note: I'm assuming your class is properly namespaced; otherwise, be sure to namespace your callback functions.)

Generally speaking, you wouldn't add an entire class to a hook. The add_action()/add_filter() hooks expect callback functions, which can be referenced from within a class.

Let's say that you have an init() function inside your class, that you want to hook into the WordPress init hook.

Put your add_action() call inside your class, and then identify the callback like so:

add_action( 'init', array( $this, 'init' ) );

(Note: I'm assuming your class is properly namespaced; otherwise, be sure to namespace your callback functions.)

Source Link
Chip Bennett
  • 55.1k
  • 8
  • 90
  • 170

Generally speaking, you wouldn't add an entire class to a hook. The add_action()/add_filter() hooks expect callback functions, which can be referenced from within a class.

Let's say that you have an init() function inside your class, that you want to hook into the WordPress init hook.

Put your add_action() call inside your class, and then identify the callback like so:

add_action( 'init', array( &$this, 'init' ) );

(Note: I'm assuming your class is properly namespaced; otherwise, be sure to namespace your callback functions.)