What is the problem with these lines of code?

I would recommend trying to add an output buffer. I find a lot of times if I’m echoing something in WordPress and it doesn’t show up, adding the output buffering does the trick. <?php add_action(‘woocommerce_archive_description’ , ‘sample’ ); function sample(){ ob_start(); echo “Hello World”; return ob_get_clean(); } ?>

How to call do_action() to pass arguments to hooked functions that take different number of args?

All the additional arguments passed to do_action() are passed as arguments, in order, to any hooked callback function. The callback functions can only choose how many of them to use, by setting the $accepted_args parameter of add_action(). They can’t choose which arguments to accept. So you would need to do something like this: add_action(‘myaction’, ‘my_multiplication’, … Read more

WordPress Custom Hook with Class method

You can use an anonymous function with PHP’s use statement like so: function mycars($mycarsclass){ $args = array( ‘car1’ => ‘Volvo’, ‘car2’ => ‘Toyota’ ); $mycarsclass->add_node($args); } add_action(‘mycarsaction’, function () use ($mycarsclass) { mycars($mycarsclass); }); do_action(‘mycarsaction’); or declare a separate function and pass that: function mycars($mycarsclass){ $args = array( ‘car1’ => ‘Volvo’, ‘car2’ => ‘Toyota’ ); … Read more

template_redirect hooks redirect wrong URL

The code adds the functions like this: add_action (‘template_redirect’, array( ‘loginForm’, ‘set_submit_login_func’)); Which tells PHP to do this when template_redirect happens: loginForm::set_submit_login_func(); But we can see set_submit_login_func in the questions code and it is clear that it is not a static function: public function set_submit_login_func(){ What you want is a dynamic callable, e.g. class MyClass … Read more