0

I have a plugin which uses the transition_post_status hook, to fire a custom function on post update. But I don't know why its not working. Here is the code

 add_action('transition_post_status', 'pmc_update_notification',10,3);

function pmc_update_notification($new_status, $old_status, $post) {
echo 'function checkpoint 1';
$options = get_option('pmc_setting');
if($options['snpi'] != false && is_single()){
   if ( $old_status == 'publish' && $new_status == 'publish' ) {
  echo 'function checkpoint 2';
$post_title = get_the_title($post);
$post_url = get_permalink($post);
$message = __('Post updated','pmc').":\n";
$message .= $post_title . ": " . $post_url;

// Send notification
pmc_send($message);
  }
 }
}
7
  • any error ? activate debug mode
    – Farzad
    Apr 2, 2014 at 18:00
  • Debug mode is activated but no error is showen
    – Deniz C.
    Apr 2, 2014 at 18:01
  • do you have called this function ? wp_head
    – Farzad
    Apr 2, 2014 at 18:03
  • No. Why should i ?
    – Deniz C.
    Apr 2, 2014 at 18:04
  • Check my answer.
    – Farzad
    Apr 2, 2014 at 18:07

2 Answers 2

0

You have to called this function in your header.php (your wp theme) :

<?php wp_head(); ?>

And this one into your Footer.php :

<?php wp_footer(); ?>

Because you are adding action to your Wordpress, so you have to call that function in your theme.

5
  • I am using this in a plugin, not a theme as i said in my question
    – Deniz C.
    Apr 2, 2014 at 18:09
  • I know, but this works when your them call that functions, without them, plugin won't work
    – Farzad
    Apr 2, 2014 at 18:09
  • Of course the theme calls that. I am using twenty twelve
    – Deniz C.
    Apr 2, 2014 at 18:11
  • @user2761273 so, better to wait for others answer.
    – Farzad
    Apr 2, 2014 at 18:15
  • 1
    Ok, but anyway thanks for your help
    – Deniz C.
    Apr 2, 2014 at 18:17
0

Found the problem!

It was the is_single() line. It's not working because its outside the loop.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.