Changeset 8174 for trunk/bp-core/admin/bp-core-functions.php
- Timestamp:
- 03/27/2014 06:02:00 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/bp-core/admin/bp-core-functions.php
r8119 r8174 826 826 bp_core_install_signups(); 827 827 } 828 829 /** 830 * Add "Mark as Spam/Ham" button to user row actions. 831 * 832 * @since BuddyPress (2.0.0) 833 * 834 * @param array $actions User row action links. 835 * @param object $user_object Current user information. 836 * @return array $actions User row action links. 837 */ 838 function bp_core_admin_user_row_actions( $actions, $user_object ) { 839 840 if ( current_user_can( 'edit_user', $user_object->ID ) && bp_loggedin_user_id() != $user_object->ID ) { 841 842 $url = bp_get_admin_url( 'users.php' ); 843 844 if ( bp_is_user_spammer( $user_object->ID ) ) { 845 $actions['ham'] = "<a href='" . wp_nonce_url( $url . "?action=ham&user=$user_object->ID", 'bp-spam-user' ) . "'>" . __( 'Not Spam' ) . "</a>"; 846 } else { 847 $actions['spam'] = "<a class='submitdelete' href='" . wp_nonce_url( $url . "?action=spam&user=$user_object->ID", 'bp-spam-user' ) . "'>" . __( 'Mark as Spam' ) . "</a>"; 848 } 849 } 850 851 return $actions; 852 } 853 854 /** 855 * Catch requests to mark individual users as spam/ham from users.php. 856 * 857 * @since BuddyPress (2.0.0) 858 */ 859 function bp_core_admin_user_manage_spammers() { 860 861 // Print our inline scripts on non-Multisite 862 add_action( 'admin_footer', 'bp_core_admin_user_spammed_js' ); 863 864 $action = isset( $_REQUEST['action'] ) ? $_REQUEST['action'] : false; 865 $updated = isset( $_REQUEST['updated'] ) ? $_REQUEST['updated'] : false; 866 $mode = isset( $_POST['mode'] ) ? $_POST['mode'] : false; 867 868 // if this is a multisite, bulk request, stop now! 869 if ( 'list' == $mode ) { 870 return; 871 } 872 873 // Process a spam/ham request 874 if ( ! empty( $action ) && in_array( $action, array( 'spam', 'ham' ) ) ) { 875 876 check_admin_referer( 'bp-spam-user' ); 877 878 $user_id = ! empty( $_REQUEST['user'] ) ? intval( $_REQUEST['user'] ) : false; 879 880 if ( empty( $user_id ) ) { 881 return; 882 } 883 884 $redirect = wp_get_referer(); 885 886 $status = ( $action == 'spam' ) ? 'spam' : 'ham'; 887 888 // Process the user 889 bp_core_process_spammer_status( $user_id, $status ); 890 891 $redirect = add_query_arg( array( 'updated' => 'marked-' . $status ), $redirect); 892 893 wp_redirect( $redirect ); 894 } 895 896 // Display feedback 897 if ( ! empty( $updated ) && in_array( $updated, array( 'marked-spam', 'marked-ham' ) ) ) { 898 899 if ( 'marked-spam' === $updated ) { 900 $notice = __( 'User marked as spammer. Spam users are visible only to site admins.', 'buddypress' ); 901 } else { 902 $notice = __( 'User removed from spam.', 'buddypress' ); 903 } 904 905 bp_core_add_admin_notice( $notice ); 906 } 907 } 908 909 /** 910 * Inline script that adds the 'site-spammed' class to spammed users. 911 * 912 * @since BuddyPress (2.0.0) 913 */ 914 function bp_core_admin_user_spammed_js() { 915 ?> 916 <script type="text/javascript"> 917 jQuery( document ).ready( function($) { 918 $( '.row-actions .ham' ).each( function() { 919 $( this ).closest( 'tr' ).addClass( 'site-spammed' ); 920 }); 921 }); 922 </script> 923 <?php 924 }
Note: See TracChangeset
for help on using the changeset viewer.