WordPress.org

Forums

Post Ratings
Option to disalow authors to vote in their own posts (2 posts)

  1. BornKillaz
    Member
    Posted 3 years ago #

    Hi!

    Love your plugin, great code that really respects wordpress parameters.

    However I have a small feature request, can you please add an option to disallow post authors to vote in their own posts?

    This is a very important option to the site I'm working on, so I've done this manually, but an option in the admin panel would avoid code changes on every plugin update.

    Thank you!

    http://wordpress.org/extend/plugins/post-ratings/

  2. digitalnature
    Member
    Plugin Author

    Posted 2 years ago #

    I don't think a plugin option is necessary for this. But if more people request it, I'll add one.

    To disallow post authors to vote on their own posts, drop this code in the .php file that you use for your customizations (theme functions.php?)

    add_filter('post_ratings_access_check', 'no_ratings_for_authors', 10, 2);
    
    function no_ratings_for_authors($passed_checks, $post_id){
    
      // not a logged in user, or default checks failed
      if(!$passed_checks || !is_user_logged_in())
        return $passed_checks;
    
      $current_user = wp_get_current_user();
      $post = &get_post($post_id);
    
      // the post doesn't belong to this user
      if($current_user->ID != $post->post_author)
        return true;
    
      // it does, disallow ratings
      return false;
    }

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Post Ratings
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic