• Resolved shanebb

    (@shanebb)


    Is it possible make voting only available to logged in users, redirecting non-users to either login or create an account?

Viewing 1 replies (of 1 total)
  • Plugin Author Pixelbart

    (@pixelbart)

    @shanebb

    You can set in the Helpful settings under Details that Helpful is not automatically inserted and then use the shortcode to determine when Helpful is shown.

    This can be done with the code below. This code inserts Helpful below the content when the user is logged in. If not, Helpful will not be inserted.

    
    add_filter( 'the_content', function( $content ) {
    
    	/* user is not logged in */
    	if ( ! is_user_logged_in() ) {
    		return $content;
    	}
    
    	/* is not post type: post */
    	if ( ! is_singular( 'post' ) ) {
    		return $content;
    	}
    
    	global $post;
    
    	/* is post */
    	if ( isset( $post->ID ) ) {
    		$content .= do_shortcode( '[helpful post_id="' . $post->ID . '"]' );
    	}
    
    	return $content;
    });
    

    You can add this code to your functions.php or read the post:

    https://helpful-plugin.info/documentation/execute-php-code/

    • This reply was modified 4 years, 2 months ago by Pixelbart.
Viewing 1 replies (of 1 total)
  • The topic ‘Only allow logged in users to vote’ is closed to new replies.