WP action is not triggering a do_action() call within?

Question

Okay, so I have a plugin on my site that triggers a do_action().

In a second plugin, my custom plugin, I hook into this action and end up calling a do_action() for another custom action of my own. This second action is never firing, but…I can’t see why the code doesn’t “see” it?

Here is a simple example:

OTHER PLUGIN, the trigger

static function doSomething()
{
  do_action( 'my_action_1' );
  do_action( 'my_action_2' );
}

MY PLUGIN

construtor
{
  add_action( 'my_action_2', myAction2 );
  add_action( 'my_action_1', myAction1 );
}

myAction1()
{
  print( 'print from action1' );
  do_action( 'my_action_2' ); // this is the call that never executes
}

myAction2()
{
  print( 'print from action2' );
}

Output as it is now:

print from action1
print from action2

What it SHOULD be…because myAction1() calls do_action for myAction2():

print from action1
print from action2
print from action2

For some reason, action1 cannot “see” action2 as if it doesn’t exist. But, I don’t know how to make it exist any more than it does?

Bonus points, adding has_action( ‘my_action2‘ ); under the line commented up above produces 1 when the add_action() exists. If I comment it out, it is 0. So it KNOWS the action/hook is there, it’s just not firing?

0
FTLRalph 4 years 2020-03-26T16:52:44-05:00 0 Answers 86 views 0

Leave an answer

Browse
Browse