I have created a class from within which I would like to call a private method (from within the same class) from the __construct method as an action callback.

When I would like to use a public method I can access it by:

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

However, this causes an error when the method is private. I have also tried unsuccessfully:

add_action('init', $this->action_callback() );

How do I access a private method?

The class looks something like:

class My_class {
    public function __construct() {
        add_action( 'init', array( $this, 'action_callback' ) );
    private function action_callback() {
        // do something

Read more here: Using a private method as an action callback from within a class


If you know the solution of this issue, please leave us a reply in Comment section, to update the question.

Related Wordpress search:

, , , ,

Wordpress related questions and answers: