What is the difference between following two codes? (Directly call a function and call a function using add_action)

function pp_submit__link_form(){
      if(isset( $_POST['action']) && $_POST['action']="submit_link" ){
          echo "Hello";
      }
    }
add_action( 'init', 'pp_submit__link_form' );

function pp_submit__link_form(){
  if(isset( $_POST['pp_action']) && $_POST['pp_action']="submit_link" ){
      echo "Hello";
  }
}
pp_submit__link_form();

4 Answers
4

In the first block of code, pp_submit__link_form() will be fired on the init action in WordPress.

In the second block of code, pp_submit__link_form() will be fired immediately at the time the function is called.

Leave a Reply

Your email address will not be published. Required fields are marked *