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);
}
}
}
In your example, you can’t.
Per the Codex,
You’re trying to use it on the
transition_post_status
hook, which is not related to page display, and sois_single()
has no meaning.The Solution
Instead of using
is_single()
, useget_post_type()
: