Opened 5 years ago
Last modified 18 months ago
#3352 new idea
Consider creating separate moderation settings
Reported by: | r-a-y | Owned by: | |
---|---|---|---|
Milestone: | Awaiting Review | Priority: | normal |
Severity: | normal | Version: | 2.6.0 |
Component: | API - Moderation | Keywords: | dev-feedback |
Cc: |
Description
Blog comment moderation settings such as link limit and word moderatioon are now inherited in bbPress 2.6 (see #2861, #3266).
However, by default, WordPress sets the comment link limit to 2. Meaning if a user enters in two or more links, their forum post is held for moderation. This number is way too low for usage in forums. When combined with #3349, this can be a big problem.
We're currently working around this by using the 'bbp_bypass_check_for_moderation'
filter, but some sites might not be aware of this change.
IMO, a forum post is different enough from a blog comment to have separate moderation settings. Especially since forum posts are mostly for logged-in users and blog comments are mostly for anonymous users.
Would be interesting to hear feedback from others.
Attachments (1)
Change History (6)
#1
@
5 years ago
#2
@
5 years ago
I think the link limit should be a separate option at the very least. If this is under consideration, the default link limit should be higher. However, if it's too high, then there isn't really much of a point in having this option to begin with. Or maybe the link limit should be obeyed, but only for anonymous users?
The comment word moderation option is less severe as admins are probably using the comment word blacklist more, and I can see this being useful for both blog comments and forum posts.
#3
@
18 months ago
Adding additional input.
As a co-author of the bbPress Style Pack plugin, I've run across an issue with allowing quotes within bbPress topics/replies.
Each quote is linked to the quoted user's profile page. AND as it stands now, even those links are counted against the comment_max_links setting in WP core.
Nested quotes are allowed, and that's a common situation where a topic/reply may have 2, 3, 5, or 10+ links within the content, but ALL of them are local links on the local site itself, and yet all of them are also counted against the comment_max_links setting in WP core.
Yes, you can increase this number in the WP core settings, but it affects content site-wide and as others have pointed out, what makes sense for comments to posts does not make sense for topics/replies in the forum.
Yes, you can bypass this setting with the 'bbp_bypass_check_for_moderation' filter, but that removes the moderation checks altogether.
I propose 2 changes:
1.) Don't count local site links against the comment_max_links value period.
&
2.) Add a filter to allow a custom max_links value to set for bbPress separately. Even if it's not implemented as a separate option in the admin interface, the filter could be leveraged to set this value with a simple code snippet.
Here's my proposed revision to the bbp_check_for_moderation function in /includes/common/functions.php
It does not count the current site's URL links against the number of max_links, and it includes the 'bbp_comment_max_links' filter to allow for a custom link count and/or use the WP core value by default.
If these changes make sense, I'll submit an official diff patch file.
/** * Checks topics and replies against the discussion moderation of blocked keys * * @since 2.1.0 bbPress (r3581) * * @param array $anonymous_data Optional - if it's an anonymous post. Do not * supply if supplying $author_id. Should be * sanitized (see {@link bbp_filter_anonymous_post_data()} * @param int $author_id Topic or reply author ID * @param string $title The title of the content * @param string $content The content being posted * @param mixed $strict False for moderation_keys. True for blacklist_keys. * String for custom keys. * @return bool True if test is passed, false if fail */ function bbp_check_for_moderation( $anonymous_data = array(), $author_id = 0, $title = '', $content = '', $strict = false ) { // Custom moderation option key if ( is_string( $strict ) ) { $strict = sanitize_key( $strict ); // Use custom key if ( ! empty( $strict ) ) { $hook_name = $strict; $option_name = "{$strict}_keys"; // Key was invalid, so default to moderation keys } else { $strict = false; } } // Strict mode uses WordPress "blacklist" settings if ( true === $strict ) { $hook_name = 'blacklist'; $option_name = 'blacklist_keys'; // Non-strict uses WordPress "moderation" settings } elseif ( false === $strict ) { $hook_name = 'moderation'; $option_name = 'moderation_keys'; } // Allow for moderation check to be skipped if ( apply_filters( "bbp_bypass_check_for_{$hook_name}", false, $anonymous_data, $author_id, $title, $content, $strict ) ) { return true; } // Maybe perform some author-specific capability checks if ( ! empty( $author_id ) ) { // Bail if user is a keymaster if ( bbp_is_user_keymaster( $author_id ) ) { return true; // Bail if user can moderate // https://bbpress.trac.wordpress.org/ticket/2726 } elseif ( ( false === $strict ) && user_can( $author_id, 'moderate' ) ) { return true; } } // Define local variable(s) $_post = array(); $match_out = ''; /** Max Links *************************************************************/ // Only check max_links when not being strict if ( false === $strict ) { $max_links = apply_filters( 'bbp_comment_max_links', get_option( 'comment_max_links' ) ); if ( ! empty( $max_links ) ) { // How many links? $num_links = preg_match_all( '/(http|ftp|https):\/\//i', $content, $match_out ); // Neutralize the current site's URL. if ( isset( $match_out[0] ) && is_array( $match_out[0] ) ) { foreach ( $match_out[0] as $found_url ) { if ( 0 === strpos( $found_url, home_url() ) ) { $num_links -=1; } } } // Allow for bumping the max to include the user's URL if ( ! empty( $_post['url'] ) ) { $num_links = apply_filters( 'comment_max_links_url', $num_links, $_post['url'], $content ); } // Das ist zu viele links! if ( $num_links >= $max_links ) { return false; } } } /** Moderation ************************************************************/ /** * Filters the bbPress moderation keys. * * @since 2.6.0 bbPress (r6050) * * @param string $moderation List of moderation keys. One per new line. */ $moderation = apply_filters( "bbp_{$hook_name}_keys", trim( get_option( $option_name ) ) ); // Bail if no words to look for if ( empty( $moderation ) ) { return true; } /** User Data *************************************************************/ // Map anonymous user data if ( ! empty( $anonymous_data ) ) { $_post['author'] = $anonymous_data['bbp_anonymous_name']; $_post['email'] = $anonymous_data['bbp_anonymous_email']; $_post['url'] = $anonymous_data['bbp_anonymous_website']; // Map current user data } elseif ( ! empty( $author_id ) ) { // Get author data $user = get_userdata( $author_id ); // If data exists, map it if ( ! empty( $user ) ) { $_post['author'] = $user->display_name; $_post['email'] = $user->user_email; $_post['url'] = $user->user_url; } } // Current user IP and user agent $_post['user_ip'] = bbp_current_author_ip(); $_post['user_ua'] = bbp_current_author_ua(); // Post title and content $_post['title'] = $title; $_post['content'] = $content; // Ensure HTML tags are not being used to bypass the moderation list. $_post['comment_without_html'] = wp_strip_all_tags( $content ); /** Words *****************************************************************/ // Get words separated by new lines $words = explode( "\n", $moderation ); // Loop through words foreach ( (array) $words as $word ) { // Trim the whitespace from the word $word = trim( $word ); // Skip empty lines if ( empty( $word ) ) { continue; } // Do some escaping magic so that '#' chars in the // spam words don't break things: $word = preg_quote( $word, '#' ); $pattern = "#{$word}#i"; // Loop through post data foreach ( $_post as $post_data ) { // Check each user data for current word if ( preg_match( $pattern, $post_data ) ) { // Post does not pass return false; } } } // Check passed successfully return true; }
#4
@
18 months ago
unofficial diff for comparison:
856c856 < $max_links = get_option( 'comment_max_links' ); --- > $max_links = apply_filters( 'bbp_comment_max_links', get_option( 'comment_max_links' ) ); 860a861,869 > > // Neutralize the current site's URL. > if ( isset( $match_out[0] ) && is_array( $match_out[0] ) ) { > foreach ( $match_out[0] as $found_url ) { > if ( 0 === strpos( $found_url, home_url() ) ) { > $num_links -=1; > } > } > }
#5
@
18 months ago
My proposed revisions above only address the # of links within topic/reply content.
To address the other part of this topic related to moderation key words, a hook is already available within the code that will allow for custom word lists separate from (or joined to) the WP core moderation_keys value. That's why I'm not addressing it, and put all of my focus on the greatly lacking # of links issue.
filter hook: 'bbp_moderation_keys'
Use it like so:
// custom moderation key word list for bbPress function custom_bbp_moderation_keys( $keys ) { // $keys is the current value of key words from the WP core setting. // You can append onto it, alter it, or overwrite it completely as you see fit. // The single quotes with one word per-line is intentional to match the required format // append example: /* $keys = $keys . ' first_appended_word second_appended_word third_appended_word'; */ //alter example: /* $keys = str_replace( 'original_word_to_replace', 'new_word', $keys ); */ // overwrite example: /* $keys = 'first_word second_word third_word fourth_word fifth_word'; */ return $keys; } add_filter( 'bbp_moderation_keys', 'custom_bbp_moderation_keys', 10, 1 );
Topics and Replies going into moderation because of the link count setting has increased support requests a bit. I believe that’s due in part to the setting connection not being obvious enough, and also like you suggest, that forums could very easily have different expectations.
Adding new forum-specific options for moderation settings is relatively easily achieved. The only caveat being that eventually there will be quite a bit of overlap between them and the regular Discussion settings, and maintaining 2 separate dictionaries of disallowed words doesn’t seem beneficial, for example.