Changeset 14195
- Timestamp:
- 01/02/2026 07:10:26 PM (11 days ago)
- Location:
- trunk
- Files:
-
- 3 edited
-
src/bp-core/deprecated/15.0.php (modified) (1 diff)
-
src/bp-members/bp-members-functions.php (modified) (7 diffs)
-
tests/phpunit/testcases/members/functions.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bp-core/deprecated/15.0.php
r14187 r14195 107 107 return bp_activity_delete( array( 'id' => $activity_id ) ); 108 108 } 109 110 /** 111 * Update the spam status of the member on multisite configs. 112 * 113 * @since 5.0.0 114 * @deprecated 15.0.0 115 * 116 * @param int $user_id The user ID to spam or ham. 117 * @param string $value '0' to mark the user as `ham`, '1' to mark as `spam`. 118 * @return bool 119 */ 120 function bp_core_update_member_status( $user_id = 0, $value = 0 ) { 121 _deprecated_function( __FUNCTION__, '15.0.0' ); 122 123 if ( ! is_multisite() || ! $user_id ) { 124 return false; 125 } 126 127 /** 128 * The `update_user_status()` function is deprecated since WordPress 5.3.0. 129 * Continue to use it if WordPress current major version is lower than 5.3. 130 */ 131 if ( bp_get_major_wp_version() < 5.3 ) { 132 return update_user_status( $user_id, 'spam', $value ); 133 } 134 135 if ( $value ) { 136 $value = '1'; 137 } 138 139 // Otherwise use the replacement function. 140 $user = wp_update_user( 141 array( 142 'ID' => $user_id, 143 'spam' => $value, 144 ) 145 ); 146 147 if ( is_wp_error( $user ) ) { 148 return false; 149 } 150 151 return true; 152 } -
trunk/src/bp-members/bp-members-functions.php
r14077 r14195 644 644 645 645 /** 646 * Update the spam status of the member on multisite configs.647 *648 * @since 5.0.0649 *650 * @param int $user_id The user ID to spam or ham.651 * @param string $value '0' to mark the user as `ham`, '1' to mark as `spam`.652 * @return bool True if the spam status of the member changed.653 * False otherwise.654 */655 function bp_core_update_member_status( $user_id = 0, $value = 0 ) {656 if ( ! is_multisite() || ! $user_id ) {657 return false;658 }659 660 /**661 * The `update_user_status()` function is deprecated since WordPress 5.3.0.662 * Continue to use it if WordPress current major version is lower than 5.3.663 */664 if ( bp_get_major_wp_version() < 5.3 ) {665 return update_user_status( $user_id, 'spam', $value );666 }667 668 if ( $value ) {669 $value = '1';670 }671 672 // Otherwise use the replacement function.673 $user = wp_update_user(674 array(675 'ID' => $user_id,676 'spam' => $value,677 )678 );679 680 if ( is_wp_error( $user ) ) {681 return false;682 }683 684 return true;685 }686 687 /**688 646 * Process a spammed or unspammed user. 689 647 * … … 712 670 // Bail if no user ID. 713 671 if ( empty( $user_id ) ) { 714 return ;672 return false; 715 673 } 716 674 717 675 // Bail if user ID is super admin. 718 676 if ( is_super_admin( $user_id ) ) { 719 return ;677 return false; 720 678 } 721 679 722 680 // Get the functions file. 723 681 if ( is_multisite() ) { 724 require_once ( ABSPATH . 'wp-admin/includes/ms.php' );725 } 726 727 $is_spam = ( 'spam' == $status );682 require_once ABSPATH . 'wp-admin/includes/ms.php'; 683 } 684 685 $is_spam = 'spam' === $status; 728 686 729 687 // Only you can prevent infinite loops. 730 688 remove_action( 'make_spam_user', 'bp_core_mark_user_spam_admin' ); 731 remove_action( 'make_ham_user', 'bp_core_mark_user_ham_admin' );689 remove_action( 'make_ham_user', 'bp_core_mark_user_ham_admin' ); 732 690 733 691 // Force the cleanup of WordPress content and status for multisite configs. … … 778 736 } 779 737 } 780 781 // Finally, mark this user as a spammer. 782 bp_core_update_member_status( $user_id, $is_spam ); 783 } 784 785 // Update the user status. 786 $wpdb->update( $wpdb->users, array( 'user_status' => $is_spam ), array( 'ID' => $user_id ) ); 787 788 // Clean user cache. 789 clean_user_cache( $user_id ); 790 791 if ( ! is_multisite() ) { 738 } 739 740 // Update user status on multisite configs. 741 if ( is_multisite() ) { 742 $updated_user = wp_update_user( 743 array( 744 'ID' => $user_id, 745 'spam' => $is_spam ? '1' : '0', 746 ) 747 ); 748 749 if ( is_wp_error( $updated_user ) ) { 750 return false; 751 } 752 } else { 753 // We need to perform the query as WordPress sends an error when using `wp_update_user()` for non-multisite configs. 754 $wpdb->update( $wpdb->users, array( 'user_status' => $is_spam ), array( 'ID' => $user_id ) ); 755 756 // Clean user cache. 757 clean_user_cache( $user_id ); 758 792 759 // Call multisite actions in single site mode for good measure. 793 760 if ( true === $is_spam ) { 794 761 795 762 /** 796 * Fires at end of processing spammer in Dashboard if not multisite and user isspam.763 * Fires at end of processing spammer in Dashboard if not multisite and user IS spam. 797 764 * 798 765 * @since 1.5.0 799 766 * 800 * @param int $ valueuser ID.767 * @param int $user_id user ID. 801 768 */ 802 769 do_action( 'make_spam_user', $user_id ); … … 804 771 805 772 /** 806 * Fires at end of processing spammer in Dashboard if not multisite and user is notspam.773 * Fires at end of processing spammer in Dashboard if not multisite and user IS NOT spam. 807 774 * 808 775 * @since 1.5.0 809 776 * 810 * @param int $ valueuser ID.777 * @param int $user_id user ID. 811 778 */ 812 779 do_action( 'make_ham_user', $user_id ); … … 827 794 * @since 1.5.0 828 795 * 829 * @param int $ valueDisplayed user ID.796 * @param int $user_id Displayed user ID. 830 797 */ 831 798 do_action( 'bp_make_spam_user', $user_id ); … … 837 804 * @since 1.5.0 838 805 * 839 * @param int $ valueDisplayed user ID.806 * @param int $user_id Displayed user ID. 840 807 */ 841 808 do_action( 'bp_make_ham_user', $user_id ); … … 858 825 return true; 859 826 } 827 860 828 /** 861 829 * Hook to WP's make_spam_user and run our custom BP spam functions. -
trunk/tests/phpunit/testcases/members/functions.php
r14071 r14195 478 478 479 479 // Bulk spam in network admin uses update_user_status 480 bp_core_update_member_status( $u1, '1' ); 480 wp_update_user( 481 array( 482 'ID' => $u1, 483 'spam' => '1', 484 ) 485 ); 481 486 482 487 $this->assertTrue( bp_is_user_spammer( $u1 ) ); … … 509 514 510 515 // Bulk unspam in network admin uses update_user_status 511 bp_core_update_member_status( $u1, '0' ); 516 wp_update_user( 517 array( 518 'ID' => $u1, 519 'spam' => '0', 520 ) 521 ); 512 522 513 523 $this->assertFalse( bp_is_user_spammer( $u1 ) );
Note: See TracChangeset
for help on using the changeset viewer.