Skip to:
Content

bbPress.org

Changeset 7129


Ignore:
Timestamp:
08/12/2020 07:11:47 PM (4 months ago)
Author:
johnjamesjacoby
Message:

Akismet: fix spam check not sending author info for logged in users

This commit uses bbp_has_errors() to catch whether anonymous information exists or not, and falls back to the currently logged in user otherwise (anonymous has priority due to moderator ability to edit topics & replies).

This commit also improves the readability of a few lengthy function calls, and adds empty() checks to all of the related array key touches.

In trunk, for 2.7.

Props procifer.

See #3368.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/includes/extend/akismet.php

    r7126 r7129  
    8080     * @since 2.0.0 bbPress (r3277)
    8181     *
    82      * @param string $post_data
     82     * @param array $post_data
    8383     *
    8484     * @return array Array of post data
    8585     */
    86     public function check_post( $post_data ) {
     86    public function check_post( $post_data = array() ) {
    8787
    8888        // Define local variables
     
    111111
    112112        // Author is anonymous
    113         if ( ! empty( $anonymous_data ) ) {
     113        if ( ! bbp_has_errors() ) {
    114114            $user_data['name']    = $anonymous_data['bbp_anonymous_name'];
    115115            $user_data['email']   = $anonymous_data['bbp_anonymous_email'];
     
    525525
    526526        // Set up Akismet last post data
    527         if ( ! empty( $this->last_post ) ) {
     527        if ( ! empty( $this->last_post['bbp_post_as_submitted'] ) ) {
    528528            $as_submitted = $this->last_post['bbp_post_as_submitted'];
    529529        }
     
    537537            $anonymous_data = bbp_filter_anonymous_post_data();
    538538
     539            // Which name?
     540            $name = ! empty( $anonymous_data['bbp_anonymous_name'] )
     541                ? $anonymous_data['bbp_anonymous_name']
     542                : $userdata->display_name;
     543
     544            // Which email?
     545            $email = ! empty( $anonymous_data['bbp_anonymous_email'] )
     546                ? $anonymous_data['bbp_anonymous_email']
     547                : $userdata->user_email;
     548
    539549            // More checks
    540             if (    intval( $as_submitted['comment_post_ID'] )    === intval( $_post->post_parent )
    541                     &&      $as_submitted['comment_author']       === ( $anonymous_data ? $anonymous_data['bbp_anonymous_name']  : $userdata->display_name )
    542                     &&      $as_submitted['comment_author_email'] === ( $anonymous_data ? $anonymous_data['bbp_anonymous_email'] : $userdata->user_email   )
    543                 ) {
     550            if (
     551
     552                // Post matches
     553                ( intval( $as_submitted['comment_post_ID'] ) === intval( $_post->post_parent ) )
     554
     555                &&
     556
     557                // Name matches
     558                ( $as_submitted['comment_author'] === $name )
     559
     560                &&
     561
     562                // Email matches
     563                ( $as_submitted['comment_author_email'] === $email )
     564            ) {
    544565
    545566                // Normal result: true
    546                 if ( $this->last_post['bbp_akismet_result'] === 'true' ) {
     567                if ( ! empty( $this->last_post['bbp_akismet_result'] ) && ( $this->last_post['bbp_akismet_result'] === 'true' ) ) {
    547568
    548569                    // Leave a trail so other's know what we did
    549570                    update_post_meta( $post_id, '_bbp_akismet_result', 'true' );
    550                     $this->update_post_history( $post_id, esc_html__( 'Akismet caught this post as spam', 'bbpress' ), 'check-spam' );
     571                    $this->update_post_history(
     572                        $post_id,
     573                        esc_html__( 'Akismet caught this post as spam', 'bbpress' ),
     574                        'check-spam'
     575                    );
    551576
    552577                    // If post_status isn't the spam status, as expected, leave a note
    553578                    if ( bbp_get_spam_status_id() !== $_post->post_status ) {
    554                         $this->update_post_history( $post_id, sprintf( esc_html__( 'Post status was changed to %s', 'bbpress' ), $_post->post_status ), 'status-changed-' . $_post->post_status );
     579                        $this->update_post_history(
     580                            $post_id,
     581                            sprintf(
     582                                esc_html__( 'Post status was changed to %s', 'bbpress' ),
     583                                $_post->post_status
     584                            ),
     585                            'status-changed-' . $_post->post_status
     586                        );
    555587                    }
    556588
    557589                // Normal result: false
    558                 } elseif ( $this->last_post['bbp_akismet_result'] === 'false' ) {
     590                } elseif ( ! empty( $this->last_post['bbp_akismet_result'] ) && ( $this->last_post['bbp_akismet_result'] === 'false' ) ) {
    559591
    560592                    // Leave a trail so other's know what we did
    561593                    update_post_meta( $post_id, '_bbp_akismet_result', 'false' );
    562                     $this->update_post_history( $post_id, esc_html__( 'Akismet cleared this post as not spam', 'bbpress' ), 'check-ham' );
     594                    $this->update_post_history(
     595                        $post_id,
     596                        esc_html__( 'Akismet cleared this post as not spam', 'bbpress' ),
     597                        'check-ham'
     598                    );
    563599
    564600                    // If post_status is the spam status, which isn't expected, leave a note
    565601                    if ( bbp_get_spam_status_id() === $_post->post_status ) {
    566                         $this->update_post_history( $post_id, sprintf( esc_html__( 'Post status was changed to %s', 'bbpress' ), $_post->post_status ), 'status-changed-' . $_post->post_status );
     602                        $this->update_post_history(
     603                            $post_id,
     604                            sprintf(
     605                                esc_html__( 'Post status was changed to %s', 'bbpress' ),
     606                                $_post->post_status
     607                            ),
     608                            'status-changed-' . $_post->post_status
     609                        );
    567610                    }
    568611
     
    571614                    // Leave a trail so other's know what we did
    572615                    update_post_meta( $post_id, '_bbp_akismet_error', time() );
    573                     $this->update_post_history( $post_id, sprintf( esc_html__( 'Akismet was unable to check this post (response: %s), will automatically retry again later.', 'bbpress' ), $this->last_post['bbp_akismet_result'] ), 'check-error' );
     616                    $this->update_post_history(
     617                        $post_id,
     618                        sprintf(
     619                            esc_html__( 'Akismet was unable to check this post (response: %s), will automatically retry again later.', 'bbpress' ),
     620                            $this->last_post['bbp_akismet_result']
     621                        ),
     622                        'check-error'
     623                    );
    574624                }
    575625
    576626                // Record the complete original data as submitted for checking
    577627                if ( isset( $this->last_post['bbp_post_as_submitted'] ) ) {
    578                     update_post_meta( $post_id, '_bbp_akismet_as_submitted', $this->last_post['bbp_post_as_submitted'] );
     628                    update_post_meta(
     629                        $post_id,
     630                        '_bbp_akismet_as_submitted',
     631                        $this->last_post['bbp_post_as_submitted']
     632                    );
    579633                }
    580634            }
Note: See TracChangeset for help on using the changeset viewer.