Check is_single() outside loop

How can I check if an Id is_single() outside the loop in a plugin?

When I try it I always get a fatal error
The code

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

function pmc_update_notification($new_status, $old_status, $post) {
 if ( $old_status == 'publish' && $new_status == 'publish' ) {
 $post_id = get_the_ID($post);
  if (is_single($post_id)){
 $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);
     }
    }
   }

Related posts

Leave a Reply

1 comment

  1. In your example, you can’t.

    Per the Codex,

    [is_single()] checks if a single post of any post type except attachment and page post types is being displayed.

    You’re trying to use it on the transition_post_status hook, which is not related to page display, and so is_single() has no meaning.

    The Solution

    Instead of using is_single(), use get_post_type():

    if( 'post' == get_post_type( $post ) ) {
        // code goes here
    }