bbp_check_for_moderation( array $anonymous_data = false, int $author_id, string $title = '', string $content = '' )

Checks topics and replies against the discussion moderation of blocked keys

Description

Parameters

$anonymous_data

(Optional) Anonymous user data

Default value: false

$author_id

(Required) Topic or reply author ID

$title

(Optional) The title of the content

Default value: ''

$content

(Optional) The content being posted

Default value: ''

Return

(bool) True if test is passed, false if fail

Source

File: bp-forums/common/functions.php

818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
function bbp_check_for_moderation( $anonymous_data = false, $author_id = 0, $title = '', $content = '' ) {
 
    // Allow for moderation check to be skipped
    if ( apply_filters( 'bbp_bypass_check_for_moderation', false, $anonymous_data, $author_id, $title, $content ) )
        return true;
 
    // Bail if keymaster is author
    if ( !empty( $author_id ) && bbp_is_user_keymaster( $author_id ) )
        return true;
 
    // Define local variable(s)
    $_post     = array();
    $match_out = '';
 
    /** Blacklist *************************************************************/
 
    // Get the moderation keys
    $blacklist = trim( get_option( 'moderation_keys' ) );
 
    // Bail if blacklist is empty
    if ( empty( $blacklist ) )
        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;
 
    /** Max Links *************************************************************/
 
    $max_links = get_option( 'comment_max_links' );
    if ( !empty( $max_links ) ) {
 
        // How many links?
        $num_links = preg_match_all( '/<a [^>]*href/i', $content, $match_out );
 
        // Allow for bumping the max to include the user's URL
        $num_links = apply_filters( 'comment_max_links_url', $num_links, $_post['url'] );
 
        // Das ist zu viele links!
        if ( $num_links >= $max_links ) {
            return false;
        }
    }
 
    /** Words *****************************************************************/
 
    // Get words separated by new lines
    $words = explode( "\n", $blacklist );
 
    // 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;
}

Changelog

Changelog
Version Description
bbPress (r3581) Introduced.

Questions?

We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.