Changeset 7129
- Timestamp:
- 08/12/2020 07:11:47 PM (5 years ago)
- File:
-
- 1 edited
-
trunk/src/includes/extend/akismet.php (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/includes/extend/akismet.php
r7126 r7129 80 80 * @since 2.0.0 bbPress (r3277) 81 81 * 82 * @param string$post_data82 * @param array $post_data 83 83 * 84 84 * @return array Array of post data 85 85 */ 86 public function check_post( $post_data ) {86 public function check_post( $post_data = array() ) { 87 87 88 88 // Define local variables … … 111 111 112 112 // Author is anonymous 113 if ( ! empty( $anonymous_data) ) {113 if ( ! bbp_has_errors() ) { 114 114 $user_data['name'] = $anonymous_data['bbp_anonymous_name']; 115 115 $user_data['email'] = $anonymous_data['bbp_anonymous_email']; … … 525 525 526 526 // Set up Akismet last post data 527 if ( ! empty( $this->last_post ) ) {527 if ( ! empty( $this->last_post['bbp_post_as_submitted'] ) ) { 528 528 $as_submitted = $this->last_post['bbp_post_as_submitted']; 529 529 } … … 537 537 $anonymous_data = bbp_filter_anonymous_post_data(); 538 538 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 539 549 // 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 ) { 544 565 545 566 // 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' ) ) { 547 568 548 569 // Leave a trail so other's know what we did 549 570 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 ); 551 576 552 577 // If post_status isn't the spam status, as expected, leave a note 553 578 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 ); 555 587 } 556 588 557 589 // 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' ) ) { 559 591 560 592 // Leave a trail so other's know what we did 561 593 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 ); 563 599 564 600 // If post_status is the spam status, which isn't expected, leave a note 565 601 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 ); 567 610 } 568 611 … … 571 614 // Leave a trail so other's know what we did 572 615 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 ); 574 624 } 575 625 576 626 // Record the complete original data as submitted for checking 577 627 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 ); 579 633 } 580 634 }
Note: See TracChangeset
for help on using the changeset viewer.