i am coding a plugin, where user can subscribe to a indvidual author of post (like we do on YouTube). I want to display the subscribe link to all logged in users, but not the author of post.
my plugin gets the author id for each post and display's the link. Problem is author would not subscribe to his own self,
So in short i want a way to echo a link, if current user is NOT the author of the post.
i am coding a plugin, where user can subscribe to a indvidual author of post (like we do on YouTube). I want to display the subscribe link to all logged in users, but not the author of post.
my plugin gets the author id for each post and display's the link. Problem is author would not subscribe to his own self,
So in short i want a way to echo a link, if current user is NOT the author of the post.
Try something like this in your template tags (or wherever in your theme):
function should_display_link() {
$post = get_post();
// Something went wrong, bail. (You should always have a post, in theory)
if ( ! $post ) {
return false;
}
$current_user = get_current_user_id();
// Assuming only logged-in users can subscribe.
if ( ! $current_user ) {
return false;
}
return absint( $post->post_author ) !== absint( $current_user );
}
In your template, you can use it like this:
<?php if ( should_display_link() ) : ?>
<!-- Your link code here -->
<?php endif; ?>