How does priority order effect a chain of add_action’s and do_action’s in WordPr
-
I have two “chains” of actions in WordPress (
add_action
‘s anddo_action
‘s linked together) and I need all of the first chain to complete before starting the second chain.Using
priority
order I can trigger the start of each chain one after the other, but I am worried that a large loop in the middle of the first chain will still be running when the second chain starts.EXAMPLE:
Since the
first_chain_first_loop
action has a priority of10
, andsecond_chain_first_loop
action has a priority of11
, will the entire first chain of actions (first_chain_first_loop
+first_chain_second_loop
) be processed beforesecond_chain_first_loop
starts?Or does
second_chain_first_loop
start immediately afterfirst_chain_first_loop
is complete? And if this is the case, how can I ensure the second chain will wait for the first chain to complete (including the large loop) before triggering the second chain.//First chain of actions - Has early priority but a large loop in the middle add_action( 'init', 'first_chain_first_loop', 10 ); function first_chain_first_loop() { for ( $i=0; $i < 10; ++$i ) { do_action( 'first_chain_second_loop_action', $i ); } } add_action( 'first_chain_second_loop_action', 'first_chain_second_loop', 10, 1 ); function first_chain_second_loop( $i ) { for ( $i=0; $i < 1000000000; ++$i ) { do_action( 'first_chain_logic_function_action', $i ); } } add_action( 'first_chain_logic_function_action', 'first_chain_logic_function', 10, 1 ); function first_chain_logic_function( $i ) { //Do stuff here } //Second chain of actions - Has later priority add_action( 'init', 'second_chain_first_loop', 11 ); function second_chain_first_loop() { for ( $i=0; $i < 10; ++$i ) { do_action( 'second_chain_second_loop_action', $i ); } } add_action( 'second_chain_second_loop_action', 'second_chain_second_loop', 10, 1 ); function second_chain_second_loop( $i ) { for ( $i=0; $i < 10; ++$i ) { do_action( 'second_chain_logic_function_action', $i ); } } add_action( 'second_chain_logic_function_action', 'second_chain_logic_function', 10, 1 ); function second_chain_logic_function( $i ) { //Do stuff here }
- The topic ‘How does priority order effect a chain of add_action’s and do_action’s in WordPr’ is closed to new replies.