Skip to:
Content

BuddyPress.org

Changeset 10859


Ignore:
Timestamp:
06/01/2016 09:12:44 PM (3 years ago)
Author:
r-a-y
Message:

Moderation: Add WP error handling.

bp_core_check_for_moderation() and bp_core_check_for_blacklist() now
supports returning WP errors.

See #6719.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-core/bp-core-moderation.php

    r10825 r10859  
    4848 *
    4949 * @since 1.6.0
    50  *
    51  * @param int    $user_id Topic or reply author ID.
    52  * @param string $title   The title of the content.
    53  * @param string $content The content being posted.
     50 * @since 2.6.0 Added $error_type parameter.
     51 *
     52 * @param int    $user_id    User ID.
     53 * @param string $title      The title of the content.
     54 * @param string $content    The content being posted.
     55 * @param string $error_type The error type to return. Either 'bool' or 'wp_error'.
    5456 * @return bool True if test is passed, false if fail.
    5557 */
    56 function bp_core_check_for_moderation( $user_id = 0, $title = '', $content = '' ) {
     58function bp_core_check_for_moderation( $user_id = 0, $title = '', $content = '', $error_type = 'bool' ) {
    5759
    5860    /**
     
    128130        // Das ist zu viele links!
    129131        if ( $num_links >= $max_links ) {
    130             return false;
     132            if ( 'bool' === $error_type ) {
     133                return false;
     134            } else {
     135                return new WP_Error( 'bp_moderation_too_many_links', __( 'You have inputted too many links', 'buddypress' ) );
     136            }
    131137        }
    132138    }
     
    165171                // Check each user data for current word.
    166172                if ( preg_match( $pattern, $post_data ) ) {
    167 
    168                     // Post does not pass.
    169                     return false;
     173                    if ( 'bool' === $error_type ) {
     174                        return false;
     175                    } else {
     176                        return new WP_Error( 'bp_moderation_word_match', _x( 'You have inputted an inappropriate word.', 'Comment moderation', 'buddypress' ) );
     177                    }
    170178                }
    171179            }
     
    181189 *
    182190 * @since 1.6.0
    183  *
    184  * @param int    $user_id Topic or reply author ID.
    185  * @param string $title   The title of the content.
    186  * @param string $content The content being posted.
     191 * @since 2.6.0 Added $error_type parameter.
     192 *
     193 * @todo Why don't we use wp_blacklist_check() for this?
     194 *
     195 * @param int    $user_id    User ID.
     196 * @param string $title      The title of the content.
     197 * @param string $content    The content being posted.
     198 * @param string $error_type The error type to return. Either 'bool' or 'wp_error'.
    187199 * @return bool True if test is passed, false if fail.
    188200 */
    189 function bp_core_check_for_blacklist( $user_id = 0, $title = '', $content = '' ) {
     201function bp_core_check_for_blacklist( $user_id = 0, $title = '', $content = '', $error_type = 'bool' ) {
    190202
    191203    /**
     
    272284            // Check each user data for current word.
    273285            if ( preg_match( $pattern, $post_data ) ) {
    274 
    275                 // Post does not pass.
    276                 return false;
     286                if ( 'bool' === $error_type ) {
     287                    return false;
     288                } else {
     289                    return new WP_Error( 'bp_moderation_blacklist_match', _x( 'You have inputted an inappropriate word.', 'Comment blacklist', 'buddypress' ) );
     290                }
    277291            }
    278292        }
Note: See TracChangeset for help on using the changeset viewer.