WordPress.org

Ready to get started?Download WordPress

Forums

Registered users do not require comment moderation (4 posts)

  1. jpat
    Member
    Posted 4 years ago #

    I'm looking for a plug-in that will allow a registered user (subscriber through author) to post comments while logged in without requiring comment moderation. If not logged in, comments require moderation.

    As far as I can tell, there are no settings that expressly permit registered subscribers (only) to comment freely.

    Your ideas and help are appreciated

  2. Justin Tadlock
    Member
    Posted 4 years ago #

    Something like this should work. Drop it in your theme's functions.php file:

    add_action( 'preprocess_comment', 'my_check_comment', 1 );
    
    function my_check_comment( $commentdata ) {
    
    	/* Get the user ID of the comment author. */
    	$user_id = absint( $commentdata['user_ID'] );
    
    	/* If comment author is a registered user, approve the comment. */
    	if ( 0 < $user_id )
    		add_filter( 'pre_comment_approved', 'my_approve_comment' );
    	else
    		add_filter( 'pre_comment_approved', 'my_moderate_comment' );
    
    	return $commentdata;
    }
    
    function my_approve_comment( $approved ) {
    	$approved = 1;
    	return $approved;
    }
    
    function my_moderate_comment( $approved ) {
    	if ( 'spam' !== $approved )
    		$approved = 0;
    	return $approved;
    }
  3. jpat
    Member
    Posted 4 years ago #

    hey, that worked and I appreciate it greatly!

  4. eastwoodarts
    Member
    Posted 3 years ago #

    works great. many thanks.

Topic Closed

This topic has been closed to new replies.

About this Topic