I am trying to pass an argument (say $arg) to the second parameter/callback of add_action() using do_action() in WordPress.

do_action( 'my_hook',  $arg);

the 'my_hook' in do_action() will refer to the below add_action()

class My_Class {

    public function __construct () {
        add_action( 'my_hook', array( $this, 'my_method ($arg)' ) );

    public function my_method ($arg) {
         some_function ($arg);
        // some code here....

Note: I am not trying this in fuctions.php. Trying to modify core files. I know modifying core files is not recommended. But, I want to explore the horizons (I will return back to the home though)

Please provide a way to pass the argument into my_method(). Thanks in advance.

Read more here: Passing argument to a method in callback array in add_action() – WordPress


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

Wordpress related questions and answers: