| @@ -1,8 +1,8 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | /** |
| 4 | - * Main bbPress Akismet Class. | |
| 4 | + * Main bbPress Akismet Class | |
| 5 | 5 | * |
| 6 | 6 | * @package bbPress |
| 7 | 7 | * @subpackage Akismet |
| 8 | 8 | */ |
| @@ -11,9 +11,9 @@ | ||
| 11 | 11 | defined( 'ABSPATH' ) || exit; |
| 12 | 12 | |
| 13 | 13 | if ( ! class_exists( 'BBP_Akismet' ) ) : |
| 14 | 14 | /** |
| 15 | - * Loads Akismet extension. | |
| 15 | + * Loads Akismet extension | |
| 16 | 16 | * |
| 17 | 17 | * @since 2.0.0 bbPress (r3278) |
| 18 | 18 | * |
| 19 | 19 | * @package bbPress |
| @@ -23,9 +23,9 @@ | ||
| 23 | 23 | |
| 24 | 24 | /** |
| 25 | 25 | * The last post checked by Akismet. |
| 26 | 26 | * |
| 27 | - * @since 2.0.0 bbPress (r7268) | |
| 27 | + * @since 2.6.10 bbPress (r7252) | |
| 28 | 28 | * |
| 29 | 29 | * @var array $last_post Default empty array. |
| 30 | 30 | */ |
| 31 | 31 | protected $last_post = array(); |
| @@ -30,9 +30,9 @@ | ||
| 30 | 30 | */ |
| 31 | 31 | protected $last_post = array(); |
| 32 | 32 | |
| 33 | 33 | /** |
| 34 | - * The main bbPress Akismet loader. | |
| 34 | + * The main bbPress Akismet loader | |
| 35 | 35 | * |
| 36 | 36 | * @since 2.0.0 bbPress (r3278) |
| 37 | 37 | */ |
| 38 | 38 | public function __construct() { |
| @@ -39,9 +39,9 @@ | ||
| 39 | 39 | $this->setup_actions(); |
| 40 | 40 | } |
| 41 | 41 | |
| 42 | 42 | /** |
| 43 | - * Setup the admin hooks. | |
| 43 | + * Setup the admin hooks | |
| 44 | 44 | * |
| 45 | 45 | * @since 2.0.0 bbPress (r3376) |
| 46 | 46 | * |
| 47 | 47 | * @access private |
| @@ -85,23 +85,18 @@ | ||
| 85 | 85 | // Admin |
| 86 | 86 | if ( is_admin() ) { |
| 87 | 87 | add_action( 'add_meta_boxes', array( $this, 'add_metaboxes' ) ); |
| 88 | 88 | } |
| 89 | - | |
| 90 | - /** Dependencies ******************************************************/ | |
| 91 | - | |
| 92 | - // Allow plugins to modify these actions | |
| 93 | - do_action_ref_array( 'bbp_extend_akismet_loaded', array( &$this ) ); | |
| 94 | 89 | } |
| 95 | 90 | |
| 96 | 91 | /** |
| 97 | - * Converts topic/reply data into Akismet comment checking format. | |
| 92 | + * Converts topic/reply data into Akismet comment checking format | |
| 98 | 93 | * |
| 99 | 94 | * @since 2.0.0 bbPress (r3278) |
| 100 | 95 | * |
| 101 | 96 | * @param array $post_data |
| 102 | 97 | * |
| 103 | - * @return array Array of post data. | |
| 98 | + * @return array Array of post data | |
| 104 | 99 | */ |
| 105 | 100 | public function check_post( $post_data = array() ) { |
| 106 | 101 | |
| 107 | 102 | // Define local variables |
| @@ -115,9 +110,9 @@ | ||
| 115 | 110 | |
| 116 | 111 | /** Author ************************************************************/ |
| 117 | 112 | |
| 118 | 113 | $user_data['last_active'] = ''; |
| 119 | - $user_data['registered'] = gmdate( 'Y-m-d H:i:s' ); | |
| 114 | + $user_data['registered'] = date( 'Y-m-d H:i:s' ); // phpcs:ignore WordPress.DateTime.RestrictedFunctions.date_date | |
| 120 | 115 | $user_data['total_posts'] = (int) bbp_get_user_post_count( $post_data['post_author'] ); |
| 121 | 116 | |
| 122 | 117 | // Get user data |
| 123 | 118 | $userdata = get_userdata( $post_data['post_author'] ); |
| @@ -147,9 +142,9 @@ | ||
| 147 | 142 | |
| 148 | 143 | // Use post parent to get datetime of last reply on this topic |
| 149 | 144 | $reply_id = bbp_get_topic_last_reply_id( $post_data['post_parent'] ); |
| 150 | 145 | if ( ! empty( $reply_id ) ) { |
| 151 | - $user_data['last_active'] = get_post_field( 'post_date_gmt', $reply_id ); | |
| 146 | + $user_data['last_active'] = get_post_field( 'post_date', $reply_id ); | |
| 152 | 147 | } |
| 153 | 148 | } |
| 154 | 149 | |
| 155 | 150 | // Pass title & content together into comment content |
| @@ -250,17 +245,10 @@ | ||
| 250 | 245 | |
| 251 | 246 | // Result is spam, so set the status as such |
| 252 | 247 | if ( 'true' === $post_data['bbp_akismet_result'] ) { |
| 253 | 248 | |
| 254 | - /** | |
| 255 | - * Hook that fires after Akismet has caught a post as spammy and | |
| 256 | - * immediately before its status is set to spam. | |
| 257 | - * | |
| 258 | - * @since 2.0.0 bbPress (r3308) | |
| 259 | - * | |
| 260 | - * @param array $post_data Post data. | |
| 261 | - */ | |
| 262 | - do_action( 'bbp_akismet_spam_caught', $post_data ); | |
| 249 | + // Let plugins do their thing | |
| 250 | + do_action( 'bbp_akismet_spam_caught' ); | |
| 263 | 251 | |
| 264 | 252 | // Set post_status to spam |
| 265 | 253 | $post_data['post_status'] = bbp_get_spam_status_id(); |
| 266 | 254 | |
| @@ -272,13 +260,13 @@ | ||
| 272 | 260 | return $post_data; |
| 273 | 261 | } |
| 274 | 262 | |
| 275 | 263 | /** |
| 276 | - * Submit a post for spamming or hamming. | |
| 264 | + * Submit a post for spamming or hamming | |
| 277 | 265 | * |
| 278 | 266 | * @since 2.0.0 bbPress (r3308) |
| 279 | 267 | * |
| 280 | - * @param int $post_id Post id. | |
| 268 | + * @param int $post_id | |
| 281 | 269 | * |
| 282 | 270 | * @global string $akismet_api_host |
| 283 | 271 | * @global string $akismet_api_port |
| 284 | 272 | * @global object $current_user |
| @@ -283,9 +271,9 @@ | ||
| 283 | 271 | * @global string $akismet_api_port |
| 284 | 272 | * @global object $current_user |
| 285 | 273 | * @global object $current_site |
| 286 | 274 | * |
| 287 | - * @return array Array of existing topic terms. | |
| 275 | + * @return array Array of existing topic terms | |
| 288 | 276 | */ |
| 289 | 277 | public function submit_post( $post_id = 0 ) { |
| 290 | 278 | global $current_user, $current_site; |
| 291 | 279 | |
| @@ -438,20 +426,20 @@ | ||
| 438 | 426 | do_action( 'bbp_akismet_submit_' . $request_type . '_post', $post_id, $post_data['bbp_akismet_result'] ); |
| 439 | 427 | } |
| 440 | 428 | |
| 441 | 429 | /** |
| 442 | - * Ping Akismet service and check for spam/ham response. | |
| 430 | + * Ping Akismet service and check for spam/ham response | |
| 443 | 431 | * |
| 444 | 432 | * @since 2.0.0 bbPress (r3278) |
| 445 | 433 | * |
| 446 | 434 | * @param array $post_data |
| 447 | - * @param string $check Accepts check|submit. | |
| 448 | - * @param string $spam Accepts spam|ham. | |
| 435 | + * @param string $check Accepts check|submit | |
| 436 | + * @param string $spam Accepts spam|ham | |
| 449 | 437 | * |
| 450 | 438 | * @global string $akismet_api_host |
| 451 | 439 | * @global string $akismet_api_port |
| 452 | 440 | * |
| 453 | - * @return array Array of post data. | |
| 441 | + * @return array Array of post data | |
| 454 | 442 | */ |
| 455 | 443 | private function maybe_spam( $post_data = array(), $check = 'check', $spam = 'spam' ) { |
| 456 | 444 | global $akismet_api_host, $akismet_api_port; |
| 457 | 445 | |
| @@ -531,9 +519,9 @@ | ||
| 531 | 519 | |
| 532 | 520 | /** |
| 533 | 521 | * Check whether a server key may contain credentials. |
| 534 | 522 | * |
| 535 | - * @since 2.6.19 bbPress (r7638) | |
| 523 | + * @since 2.6.19 bbPress (r7639) | |
| 536 | 524 | * |
| 537 | 525 | * @param string $key Server key. |
| 538 | 526 | * @return bool Whether the key should be omitted. |
| 539 | 527 | */ |
| @@ -542,9 +530,9 @@ | ||
| 542 | 530 | |
| 543 | 531 | /** |
| 544 | 532 | * Filters whether a server field is omitted from Akismet requests. |
| 545 | 533 | * |
| 546 | - * @since 2.6.19 bbPress (r7638) | |
| 534 | + * @since 2.6.19 bbPress (r7639) | |
| 547 | 535 | * |
| 548 | 536 | * @param bool $sensitive Whether the field may contain credentials. |
| 549 | 537 | * @param string $key Server key. |
| 550 | 538 | */ |
| @@ -551,13 +539,13 @@ | ||
| 551 | 539 | return (bool) apply_filters( 'bbp_akismet_is_sensitive_server_key', $sensitive, $key ); |
| 552 | 540 | } |
| 553 | 541 | |
| 554 | 542 | /** |
| 555 | - * Update post meta after a spam check. | |
| 543 | + * Update post meta after a spam check | |
| 556 | 544 | * |
| 557 | 545 | * @since 2.0.0 bbPress (r3308) |
| 558 | 546 | * |
| 559 | - * @param int $post_id Post id. | |
| 547 | + * @param int $post_id | |
| 560 | 548 | * @param object $_post |
| 561 | 549 | * |
| 562 | 550 | * @global object $this->last_post |
| 563 | 551 | */ |
| @@ -582,19 +570,8 @@ | ||
| 582 | 570 | // wp_insert_post() might be called in other contexts. Ensure this is |
| 583 | 571 | // the same topic/reply as was checked by BBP_Akismet::check_post() |
| 584 | 572 | if ( is_object( $_post ) && ! empty( $this->last_post ) && is_array( $as_submitted ) ) { |
| 585 | 573 | |
| 586 | - /** | |
| 587 | - * Fires immediately before post meta is updated on a bbPress post | |
| 588 | - * that Akismet has checked. | |
| 589 | - * | |
| 590 | - * @since 2.7.0 bbPress (r7356) | |
| 591 | - * | |
| 592 | - * @param int $post_id | |
| 593 | - * @param object $_post | |
| 594 | - */ | |
| 595 | - do_action( 'bbp_akismet_before_update_post_meta', $post_id, $_post ); | |
| 596 | - | |
| 597 | 574 | // Get user data |
| 598 | 575 | $userdata = get_userdata( $_post->post_author ); |
| 599 | 576 | if ( ! empty( $userdata ) ) { |
| 600 | 577 | $name = $userdata->display_name; |
| @@ -633,9 +610,9 @@ | ||
| 633 | 610 | // Leave a trail so other's know what we did |
| 634 | 611 | update_post_meta( $post_id, '_bbp_akismet_result', 'true' ); |
| 635 | 612 | $this->update_post_history( |
| 636 | 613 | $post_id, |
| 637 | - esc_html__( 'Akismet caught this post as spam.', 'bbpress' ), | |
| 614 | + esc_html__( 'Akismet caught this post as spam', 'bbpress' ), | |
| 638 | 615 | 'check-spam' |
| 639 | 616 | ); |
| 640 | 617 | |
| 641 | 618 | // If post_status isn't the spam status, as expected, leave a note |
| @@ -657,9 +634,9 @@ | ||
| 657 | 634 | // Leave a trail so other's know what we did |
| 658 | 635 | update_post_meta( $post_id, '_bbp_akismet_result', 'false' ); |
| 659 | 636 | $this->update_post_history( |
| 660 | 637 | $post_id, |
| 661 | - esc_html__( 'Akismet cleared this post as not spam.', 'bbpress' ), | |
| 638 | + esc_html__( 'Akismet cleared this post as not spam', 'bbpress' ), | |
| 662 | 639 | 'check-ham' |
| 663 | 640 | ); |
| 664 | 641 | |
| 665 | 642 | // If post_status is the spam status, which isn't expected, leave a note |
| @@ -698,33 +675,21 @@ | ||
| 698 | 675 | $this->last_post['bbp_post_as_submitted'] |
| 699 | 676 | ); |
| 700 | 677 | } |
| 701 | 678 | } |
| 702 | - | |
| 703 | - /** | |
| 704 | - * Fires immediately after post meta is updated on a bbPress post | |
| 705 | - * that Akismet has checked. | |
| 706 | - * | |
| 707 | - * @since 2.7.0 bbPress (r7356) | |
| 708 | - * | |
| 709 | - * @param int $post_id | |
| 710 | - * @param object $_post | |
| 711 | - */ | |
| 712 | - do_action( 'bbp_akismet_after_update_post_meta', $post_id, $_post ); | |
| 713 | 679 | } |
| 714 | 680 | } |
| 715 | 681 | |
| 716 | 682 | /** |
| 717 | - * Update Akismet history of a Post. | |
| 683 | + * Update Akismet history of a Post | |
| 718 | 684 | * |
| 719 | 685 | * @since 2.0.0 bbPress (r3308) |
| 720 | - * @since 2.7.0 bbPress (r7356) Changed from private to public. | |
| 721 | 686 | * |
| 722 | 687 | * @param int $post_id |
| 723 | 688 | * @param string $message |
| 724 | 689 | * @param string $event |
| 725 | 690 | */ |
| 726 | - public function update_post_history( $post_id = 0, $message = null, $event = null ) { | |
| 691 | + private function update_post_history( $post_id = 0, $message = null, $event = null ) { | |
| 727 | 692 | |
| 728 | 693 | // Define local variable(s) |
| 729 | 694 | $user = ''; |
| 730 | 695 | |
| @@ -735,11 +700,15 @@ | ||
| 735 | 700 | if ( is_object( $current_user ) && isset( $current_user->user_login ) ) { |
| 736 | 701 | $user = $current_user->user_login; |
| 737 | 702 | } |
| 738 | 703 | |
| 704 | + // This used to be akismet_microtime() but it was removed in 3.0 | |
| 705 | + $mtime = explode( ' ', microtime() ); | |
| 706 | + $message_time = $mtime[1] + $mtime[0]; | |
| 707 | + | |
| 739 | 708 | // Setup the event to be saved |
| 740 | 709 | $event = array( |
| 741 | - 'time' => time(), | |
| 710 | + 'time' => $message_time, | |
| 742 | 711 | 'message' => $message, |
| 743 | 712 | 'event' => $event, |
| 744 | 713 | 'user' => $user, |
| 745 | 714 | ); |
| @@ -744,24 +713,24 @@ | ||
| 744 | 713 | 'user' => $user, |
| 745 | 714 | ); |
| 746 | 715 | |
| 747 | 716 | // Save the event data |
| 748 | - add_post_meta( $post_id, '_bbp_akismet_history', $event, false ); | |
| 717 | + add_post_meta( $post_id, '_bbp_akismet_history', $event ); | |
| 749 | 718 | } |
| 750 | 719 | |
| 751 | 720 | /** |
| 752 | - * Get the Akismet history of a Post. | |
| 721 | + * Get the Akismet history of a Post | |
| 753 | 722 | * |
| 754 | 723 | * @since 2.0.0 bbPress (r3308) |
| 755 | 724 | * |
| 756 | 725 | * @param int $post_id |
| 757 | 726 | * |
| 758 | - * @return array Array of Akismet history. | |
| 727 | + * @return array Array of Akismet history | |
| 759 | 728 | */ |
| 760 | 729 | public function get_post_history( $post_id = 0 ) { |
| 761 | 730 | |
| 762 | 731 | // Retrieve any previous history |
| 763 | - $history = get_post_meta( $post_id, '_bbp_akismet_history', false ); | |
| 732 | + $history = get_post_meta( $post_id, '_bbp_akismet_history' ); | |
| 764 | 733 | |
| 765 | 734 | // Sort it by the time recorded |
| 766 | 735 | usort( $history, 'akismet_cmp_time' ); |
| 767 | 736 | |
| @@ -768,17 +737,17 @@ | ||
| 768 | 737 | return $history; |
| 769 | 738 | } |
| 770 | 739 | |
| 771 | 740 | /** |
| 772 | - * Handle any terms submitted with a post flagged as spam. | |
| 741 | + * Handle any terms submitted with a post flagged as spam | |
| 773 | 742 | * |
| 774 | 743 | * @since 2.0.0 bbPress (r3308) |
| 775 | 744 | * |
| 776 | - * @param string $terms Comma-separated list of terms. | |
| 745 | + * @param string $terms Comma-separated list of terms | |
| 777 | 746 | * @param int $topic_id |
| 778 | 747 | * @param int $reply_id |
| 779 | 748 | * |
| 780 | - * @return array Array of existing topic terms. | |
| 749 | + * @return array Array of existing topic terms | |
| 781 | 750 | */ |
| 782 | 751 | public function filter_post_terms( $terms = '', $topic_id = 0, $reply_id = 0 ) { |
| 783 | 752 | |
| 784 | 753 | // Validate the reply_id and topic_id |
| @@ -797,9 +766,9 @@ | ||
| 797 | 766 | return $existing_terms; |
| 798 | 767 | } |
| 799 | 768 | |
| 800 | 769 | /** |
| 801 | - * Submit data to Akismet service with unique bbPress User Agent. | |
| 770 | + * Submit data to Akismet service with unique bbPress User Agent | |
| 802 | 771 | * |
| 803 | 772 | * This code is directly taken from the akismet_http_post() function and |
| 804 | 773 | * documented to bbPress 2.0 standard. |
| 805 | 774 | * |
| @@ -804,14 +773,14 @@ | ||
| 804 | 773 | * documented to bbPress 2.0 standard. |
| 805 | 774 | * |
| 806 | 775 | * @since 2.0.0 bbPress (r3467) |
| 807 | 776 | * |
| 808 | - * @param string $request The request we are sending. | |
| 809 | - * @param string $host The host to send our request to. | |
| 810 | - * @param string $path The path from the host. | |
| 811 | - * @param string $port The port to use. | |
| 812 | - * @param string $ip Optional Override $host with an IP address. | |
| 813 | - * @return mixed WP_Error on error, array on success, empty on failure. | |
| 777 | + * @param string $request The request we are sending | |
| 778 | + * @param string $host The host to send our request to | |
| 779 | + * @param string $path The path from the host | |
| 780 | + * @param string $port The port to use | |
| 781 | + * @param string $ip Optional Override $host with an IP address | |
| 782 | + * @return mixed WP_Error on error, array on success, empty on failure | |
| 814 | 783 | */ |
| 815 | 784 | private function http_post( $request, $host, $path, $port = 80, $ip = '' ) { |
| 816 | 785 | |
| 817 | 786 | // Preload required variables |
| @@ -847,12 +816,12 @@ | ||
| 847 | 816 | |
| 848 | 817 | /** |
| 849 | 818 | * Handles the repeated calls to wp_remote_post(), including SSL support. |
| 850 | 819 | * |
| 851 | - * @since 2.6.7 bbPress (r7196) | |
| 820 | + * @since 2.6.7 bbPress (r7195) | |
| 852 | 821 | * |
| 853 | - * @param string $host_and_path Scheme-less URL. | |
| 854 | - * @param array $http_args Array of arguments for wp_remote_post(). | |
| 822 | + * @param string $host_and_path Scheme-less URL | |
| 823 | + * @param array $http_args Array of arguments for wp_remote_post() | |
| 855 | 824 | * @return array |
| 856 | 825 | */ |
| 857 | 826 | private function get_response( $host_and_path = '', $http_args = array() ) { |
| 858 | 827 | |
| @@ -915,13 +884,13 @@ | ||
| 915 | 884 | ); |
| 916 | 885 | } |
| 917 | 886 | |
| 918 | 887 | /** |
| 919 | - * Return a user's roles on this site (including super_admin). | |
| 888 | + * Return a user's roles on this site (including super_admin) | |
| 920 | 889 | * |
| 921 | 890 | * @since 2.3.0 bbPress (r4813) |
| 922 | 891 | * |
| 923 | - * @param int $user_id User id. | |
| 892 | + * @param int $user_id | |
| 924 | 893 | * |
| 925 | 894 | * @return boolean |
| 926 | 895 | */ |
| 927 | 896 | private function get_user_roles( $user_id = 0 ) { |
| @@ -950,9 +919,9 @@ | ||
| 950 | 919 | |
| 951 | 920 | /** Admin *****************************************************************/ |
| 952 | 921 | |
| 953 | 922 | /** |
| 954 | - * Add Aksimet History meta-boxes to topics and replies. | |
| 923 | + * Add Aksimet History meta-boxes to topics and replies | |
| 955 | 924 | * |
| 956 | 925 | * @since 2.4.0 bbPress (r5050) |
| 957 | 926 | */ |
| 958 | 927 | public function add_metaboxes() { |
| @@ -959,9 +928,9 @@ | ||
| 959 | 928 | |
| 960 | 929 | // Topics |
| 961 | 930 | add_meta_box( |
| 962 | 931 | 'bbp_akismet_topic_history', |
| 963 | - __( 'History', 'bbpress' ), | |
| 932 | + __( 'Akismet History', 'bbpress' ), | |
| 964 | 933 | array( $this, 'history_metabox' ), |
| 965 | 934 | bbp_get_topic_post_type(), |
| 966 | 935 | 'normal', |
| 967 | 936 | 'core' |
| @@ -969,9 +938,9 @@ | ||
| 969 | 938 | |
| 970 | 939 | // Replies |
| 971 | 940 | add_meta_box( |
| 972 | 941 | 'bbp_akismet_reply_history', |
| 973 | - __( 'History', 'bbpress' ), | |
| 942 | + __( 'Akismet History', 'bbpress' ), | |
| 974 | 943 | array( $this, 'history_metabox' ), |
| 975 | 944 | bbp_get_reply_post_type(), |
| 976 | 945 | 'normal', |
| 977 | 946 | 'core' |
| @@ -978,9 +947,9 @@ | ||
| 978 | 947 | ); |
| 979 | 948 | } |
| 980 | 949 | |
| 981 | 950 | /** |
| 982 | - * Output for Akismet History meta-box. | |
| 951 | + * Output for Akismet History meta-box | |
| 983 | 952 | * |
| 984 | 953 | * @since 2.4.0 bbPress (r5050) |
| 985 | 954 | */ |
| 986 | 955 | public function history_metabox() { |
| @@ -998,10 +967,10 @@ | ||
| 998 | 967 | <?php foreach ( $history as $row ) : ?> |
| 999 | 968 | |
| 1000 | 969 | <tr> |
| 1001 | 970 | <td style="color: #999; text-align: right; white-space: nowrap;"> |
| 1002 | - <span title="<?php echo esc_attr( gmdate( 'D d M Y @ h:i:m a', (int) $row['time'] ) . ' GMT' ); ?>"> | |
| 1003 | - <?php bbp_time_since( (int) $row['time'], false, true ); ?> | |
| 971 | + <span title="<?php echo esc_attr( date( 'D d M Y @ h:i:m a', $row['time'] ) . ' GMT' ); // phpcs:ignore WordPress.DateTime.RestrictedFunctions.date_date ?>"> | |
| 972 | + <?php bbp_time_since( $row['time'], false, true ); ?> | |
| 1004 | 973 | </span> |
| 1005 | 974 | </td> |
| 1006 | 975 | <td style="padding-left: 5px;"> |
| 1007 | 976 | <?php echo esc_html( $row['message'] ); ?> |
| @@ -1025,9 +994,9 @@ | ||
| 1025 | 994 | |
| 1026 | 995 | /** |
| 1027 | 996 | * Get the number of rows to delete in a single clean-up query. |
| 1028 | 997 | * |
| 1029 | - * @since 2.6.9 bbPress (r7226) | |
| 998 | + * @since 2.6.9 bbPress (r7227) | |
| 1030 | 999 | * |
| 1031 | 1000 | * @param string $filter The name of the filter to run. |
| 1032 | 1001 | * @return int |
| 1033 | 1002 | */ |
| @@ -1051,9 +1020,9 @@ | ||
| 1051 | 1020 | |
| 1052 | 1021 | /** |
| 1053 | 1022 | * Get the interval (in days) for spam to remain in the queue. |
| 1054 | 1023 | * |
| 1055 | - * @since 2.6.9 bbPress (r7226) | |
| 1024 | + * @since 2.6.9 bbPress (r7227) | |
| 1056 | 1025 | * |
| 1057 | 1026 | * @param string $filter The name of the filter to run. |
| 1058 | 1027 | * @return int |
| 1059 | 1028 | */ |
| @@ -1080,9 +1049,9 @@ | ||
| 1080 | 1049 | * Deletes old spam topics & replies from the queue after 15 days |
| 1081 | 1050 | * (determined by `_bbp_akismet_delete_spam_interval` filter) |
| 1082 | 1051 | * since they are not useful in the long term. |
| 1083 | 1052 | * |
| 1084 | - * @since 2.6.7 bbPress (r7204) | |
| 1053 | + * @since 2.6.7 bbPress (r7203) | |
| 1085 | 1054 | * |
| 1086 | 1055 | * @global wpdb $wpdb |
| 1087 | 1056 | */ |
| 1088 | 1057 | public function delete_old_spam() { |
| @@ -1131,10 +1100,8 @@ | ||
| 1131 | 1100 | // Run the delete queries |
| 1132 | 1101 | $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->posts} WHERE ID IN ( {$format_string} )", $spam_ids ) ); |
| 1133 | 1102 | $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->postmeta} WHERE post_id IN ( {$format_string} )", $spam_ids ) ); |
| 1134 | 1103 | |
| 1135 | - // phpcs:enable | |
| 1136 | - | |
| 1137 | 1104 | // Clean the post cache for these topics & replies |
| 1138 | 1105 | clean_post_cache( $spam_ids ); |
| 1139 | 1106 | |
| 1140 | 1107 | /** |
| @@ -1151,9 +1118,9 @@ | ||
| 1151 | 1118 | * Determines whether tables should be optimized. |
| 1152 | 1119 | * |
| 1153 | 1120 | * @param int Random number between 1 and 5000. |
| 1154 | 1121 | */ |
| 1155 | - $optimize = (int) apply_filters( '_bbp_akismet_optimize_tables', wp_rand( 1, 5000 ), array( $wpdb->posts, $wpdb->postmeta ) ); | |
| 1122 | + $optimize = (int) apply_filters( '_bbp_akismet_optimize_tables', mt_rand( 1, 5000 ), array( $wpdb->posts, $wpdb->postmeta ) ); | |
| 1156 | 1123 | |
| 1157 | 1124 | // Lucky number 11 |
| 1158 | 1125 | if ( 11 === $optimize ) { |
| 1159 | 1126 | $wpdb->query( "OPTIMIZE TABLE {$wpdb->posts}" ); |
| @@ -1165,9 +1132,9 @@ | ||
| 1165 | 1132 | * Deletes `_bbp_akismet_as_submitted` meta keys after 15 days |
| 1166 | 1133 | * (determined by `_bbp_akismet_delete_spam_meta_interval` filter) |
| 1167 | 1134 | * since they are large and not useful in the long term. |
| 1168 | 1135 | * |
| 1169 | - * @since 2.6.7 bbPress (r7204) | |
| 1136 | + * @since 2.6.7 bbPress (r7203) | |
| 1170 | 1137 | * |
| 1171 | 1138 | * @global wpdb $wpdb |
| 1172 | 1139 | */ |
| 1173 | 1140 | public function delete_old_spam_meta() { |
| @@ -1225,9 +1192,9 @@ | ||
| 1225 | 1192 | * Clears post meta that no longer has corresponding posts in the database |
| 1226 | 1193 | * (determined by `_bbp_akismet_delete_spam_orphaned_limit` filter) |
| 1227 | 1194 | * since it is not useful in the long term. |
| 1228 | 1195 | * |
| 1229 | - * @since 2.6.7 bbPress (r7204) | |
| 1196 | + * @since 2.6.7 bbPress (r7203) | |
| 1230 | 1197 | * |
| 1231 | 1198 | * @global wpdb $wpdb |
| 1232 | 1199 | */ |
| 1233 | 1200 | public function delete_orphaned_spam_meta() { |
| @@ -1247,17 +1214,17 @@ | ||
| 1247 | 1214 | // Maximum time |
| 1248 | 1215 | $max_exec_time = (float) max( ini_get( 'max_execution_time' ) - 5, 3 ); |
| 1249 | 1216 | |
| 1250 | 1217 | // Setup the query |
| 1251 | - $sql = "SELECT m.meta_id, m.post_id, m.meta_key | |
| 1252 | - FROM {$wpdb->postmeta} as m | |
| 1253 | - LEFT JOIN {$wpdb->posts} as p | |
| 1254 | - ON m.post_id = p.ID | |
| 1255 | - WHERE p.ID IS NULL | |
| 1256 | - AND m.meta_id > %d | |
| 1257 | - AND m.meta_key LIKE 'akismet\\_%' | |
| 1258 | - ORDER BY m.meta_id | |
| 1259 | - LIMIT %d"; | |
| 1218 | + $sql = 'SELECT m.meta_id, m.post_id, m.meta_key' | |
| 1219 | + . " FROM {$wpdb->postmeta} as m" | |
| 1220 | + . " LEFT JOIN {$wpdb->posts} as p" | |
| 1221 | + . ' ON m.post_id = p.ID' | |
| 1222 | + . ' WHERE p.ID IS NULL' | |
| 1223 | + . ' AND m.meta_id > %d' | |
| 1224 | + . " AND m.meta_key LIKE 'akismet\\_%'" | |
| 1225 | + . ' ORDER BY m.meta_id' | |
| 1226 | + . ' LIMIT %d'; | |
| 1260 | 1227 | |
| 1261 | 1228 | // Query loop of topic & reply IDs |
| 1262 | 1229 | while ( $spam_meta_results = $wpdb->get_results( $wpdb->prepare( $sql, $last_meta_id, $delete_limit ) ) ) { // phpcs:ignore |
| 1263 | 1230 | |
| @@ -1317,9 +1284,9 @@ | ||
| 1317 | 1284 | |
| 1318 | 1285 | /** |
| 1319 | 1286 | * Maybe OPTIMIZE the _postmeta database table. |
| 1320 | 1287 | * |
| 1321 | - * @since 2.7.0 bbPress (r7204) | |
| 1288 | + * @since 2.6.7 bbPress (r7203) | |
| 1322 | 1289 | * |
| 1323 | 1290 | * @global wpdb $wpdb |
| 1324 | 1291 | */ |
| 1325 | 1292 | private function maybe_optimize_postmeta() { |
| @@ -1329,9 +1296,9 @@ | ||
| 1329 | 1296 | * Determines whether tables should be optimized. |
| 1330 | 1297 | * |
| 1331 | 1298 | * @param int Random number between 1 and 5000. |
| 1332 | 1299 | */ |
| 1333 | - $optimize = (int) apply_filters( '_bbp_akismet_optimize_table', wp_rand( 1, 5000 ), $wpdb->postmeta ); | |
| 1300 | + $optimize = (int) apply_filters( '_bbp_akismet_optimize_table', mt_rand( 1, 5000 ), $wpdb->postmeta ); | |
| 1334 | 1301 | |
| 1335 | 1302 | // Lucky number 11 |
| 1336 | 1303 | if ( 11 === $optimize ) { |
| 1337 | 1304 | $wpdb->query( "OPTIMIZE TABLE {$wpdb->postmeta}" ); |