I am trying to write a class that adds an action to the save_post hook, but the post_updated function never gets called. I tried some variations, but it never gets called. Am I doing something wrong?

class automatic_forwarder {
 function __construct() {
     add_action( 'save_post', array( $this, 'post_updated' ) );

 function post_updated() {
     echo "Working";

Then in the index.php file of the plugin I am writing the following code:


$mypluginclass = new automatic_forwarder();
  • 1
    Are you instantiating automatic_forwarder? i.e. new automatic_forwarder; – TheDeadMedic Mar 1 '15 at 14:12
  • I have added the initiation code. – sogathon Mar 1 '15 at 14:14
  • 1
    At what point are you loading/instantiating the class? In your theme's functions.php? In your main plugin file? In a function attached to another hook? – TheDeadMedic Mar 1 '15 at 14:15
  • In the index.php of the current plugin. – sogathon Mar 1 '15 at 14:16
  • 2
    Are you sure it never gets called? Your echo is probably working but never seen. Try wp_die( 'Working' ); instead. – TheDeadMedic Mar 1 '15 at 14:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.