BuddyDev

Search

[Resolved] Buddyblog min and max words

  • Participant
    Level: Guru
    Posts: 900
    Tosin on #40710

    Hi,

    Can you add a settings feature to enable minimum and maximum words count restrictions in the post editor, kindly note that im using the medium editor.

    Recently some of my site members have been submitting low quality content with just 25 words or less, this feature will help to direct human spammers creating low quality content with few words. Restricting and preventing users from publishing until their post has a minimum threshold of 400 words would be very helpful.

    when the user clicks the publish button a popup notification should appear showing the message (Your post must have a minimum of 400 words)

    Thanks

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 3115
    Ravi on #40712

    Hello Tosin,

    Thank you for posting and suggesting this feature. We will include this feature in future versions. For now, You can use the following code to prevent users from publishing content less than 400 words.

    
    add_filter( 'bblpro_validation_errors', function ( $errors, $data ) {
    
    	if ( $errors->has_errors() ) {
    		return $errors;
    	}
    
    	$content     = empty( $data['bbl_post_content'] ) ? '' : $data['bbl_post_content'];
    	$words_count = (int) str_word_count( $content );
    
    	if ( $words_count < 400 ) {
    		$errors->add( 'bbl_post_content', _x( 'Minimum 400 words required to publish.', 'Post form validation message', 'buddyblog-pro' ) );
    	}
    
    	return $errors;
    }, 10, 2 );
    
    

    Please let me know if this helps you or not.

    Regards
    Ravi

  • Participant
    Level: Guru
    Posts: 900
    Tosin on #40717

    Thanks the code worked perfectly.

    Note: when adding this feature a words counter might be helpful in the editor so users can know how many words is stil required for publishing.

    Thanks

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 3115
    Ravi on #40734

    Hello Tosin,

    Thank you for the acknowledgment. Okay, We will check the feasibility for the word’s counter with both the editors.

    Regards
    Ravi

The topic ‘ [Resolved] Buddyblog min and max words’ is closed to new replies.

This topic is: resolved