Skip to:
Content

BuddyPress.org

Ticket #5197: 5197.03.diff

File 5197.03.diff, 57.7 KB (added by imath, 11 years ago)
  • bp-blogs/bp-blogs-functions.php

     
    970970add_action( 'wpmu_delete_user',  'bp_blogs_remove_data' );
    971971add_action( 'delete_user',       'bp_blogs_remove_data' );
    972972add_action( 'bp_make_spam_user', 'bp_blogs_remove_data' );
     973
     974/**
     975 * Display the number of blogs in user's Admin Profile.
     976 *
     977 * @param  int $user_id the ID of user displayed.
     978 * @uses bp_blogs_admin_get_profile_stats() to get the stats
     979 */
     980function bp_blogs_admin_profile_stats( $user_id = 0 ) {
     981        echo bp_blogs_admin_get_profile_stats( $user_id );
     982}
     983add_action( 'bp_members_admin_user_stats', 'bp_blogs_admin_profile_stats', 9, 1 );
     984
     985/**
     986 * Return the number of blogs in user's Admin Profile.
     987 *
     988 * @param  int $user_id the ID of user displayed.
     989 * @return string HTML for stats output.
     990 */
     991function bp_blogs_admin_get_profile_stats( $user_id = 0 ) {
     992        if ( ! is_multisite() )
     993                return false;
     994
     995        if ( empty( $user_id ) && is_admin() ){
     996                return false;
     997        } else {
     998                $user_id = bp_displayed_user_id();
     999        }
     1000
     1001        $output = '';
     1002
     1003        if ( $blogs_amount = absint( bp_blogs_total_blogs_for_user( $user_id ) ) ) {
     1004               
     1005                $output = '<li class="bp-blogs-profile-stats">' . sprintf( _n( '1 site', '<strong>%s</strong> sites', $blogs_amount, 'buddypress' ), $blogs_amount ) . '</li>';
     1006               
     1007        }
     1008
     1009        return apply_filters( 'bp_blogs_admin_get_profile_stats', $output, $user_id, $blogs_amount );
     1010}
  • bp-friends/bp-friends-functions.php

     
    546546add_action( 'wpmu_delete_user',  'friends_remove_data' );
    547547add_action( 'delete_user',       'friends_remove_data' );
    548548add_action( 'bp_make_spam_user', 'friends_remove_data' );
     549
     550/**
     551 * Display the number of friends in user's Admin Profile.
     552 *
     553 * @param  int $user_id The ID of user displayed.
     554 * @uses bp_friends_admin_get_profile_stats() to get the stats
     555 */
     556function bp_friends_admin_profile_stats( $user_id = 0 ) {
     557        echo bp_friends_admin_get_profile_stats( $user_id );
     558}
     559add_action( 'bp_members_admin_user_stats', 'bp_friends_admin_profile_stats', 7, 1 );
     560
     561/**
     562 * Return the number of friends in user's Admin Profile.
     563 *
     564 * @param  int $user_id The ID of user displayed.
     565 * @return string HTML for stats output.
     566 */
     567function bp_friends_admin_get_profile_stats( $user_id = 0 ) {
     568        if ( empty( $user_id ) && is_admin() ){
     569                return false;
     570        } else {
     571                $user_id = bp_displayed_user_id();
     572        }
     573
     574        $output = '';
     575
     576        if ( $friends_amount = absint( friends_get_total_friend_count( $user_id ) ) ) {
     577               
     578                $output = '<li class="bp-friends-profile-stats">' . sprintf( _n( '1 friend', '<strong>%s</strong> friends', $friends_amount, 'buddypress' ), $friends_amount ) . '</li>';
     579               
     580        }
     581
     582        return apply_filters( 'bp_friends_admin_get_profile_stats', $output, $user_id, $friends_amount );
     583}
     584
  • bp-groups/bp-groups-functions.php

     
    10561056add_action( 'wpmu_delete_user',  'groups_remove_data_for_user' );
    10571057add_action( 'delete_user',       'groups_remove_data_for_user' );
    10581058add_action( 'bp_make_spam_user', 'groups_remove_data_for_user' );
     1059
     1060/**
     1061 * Display the number of groups in user's Admin Profile.
     1062 *
     1063 * @param  int $user_id The ID of user displayed.
     1064 * @uses bp_groups_admin_get_profile_stats() to get the stats
     1065 */
     1066function bp_groups_admin_profile_stats( $user_id = 0 ) {
     1067        echo bp_groups_admin_get_profile_stats( $user_id );
     1068}
     1069add_action( 'bp_members_admin_user_stats', 'bp_groups_admin_profile_stats', 8, 1 );
     1070
     1071/**
     1072 * Return the number of groups in user's Admin Profile.
     1073 *
     1074 * @param  int $user_id The ID of user displayed.
     1075 * @return string HTML for stats output.
     1076 */
     1077function bp_groups_admin_get_profile_stats( $user_id = 0 ) {
     1078        if ( empty( $user_id ) && is_admin() ){
     1079                return false;
     1080        } else {
     1081                $user_id = bp_displayed_user_id();
     1082        }
     1083
     1084        $output = '';
     1085
     1086        if ( $groups_amount = absint( bp_get_total_group_count_for_user( $user_id ) ) ) {
     1087               
     1088                $output = '<li class="bp-groups-profile-stats">' . sprintf( _n( '1 group', '<strong>%s</strong> groups', $groups_amount, 'buddypress' ), $groups_amount ) . '</li>';
     1089               
     1090        }
     1091
     1092        return apply_filters( 'bp_groups_admin_get_profile_stats', $output, $user_id, $groups_amount );
     1093}
  • bp-members/admin/css/admin.css

     
     1/**** BP Members Profile Administration Screens ****/
     2
     3div#profile-page.wrap form#your-profile {
     4        position:relative;
     5}
     6
     7div#profile-page.wrap form#your-profile h3:first-of-type {
     8        margin-top:6em;
     9}
     10
     11div#profile-page.wrap form#your-profile ul#profile-nav {
     12        position:absolute;
     13        top:-6em;
     14        border-bottom:solid 1px #ccc;
     15        width:100%;
     16}
     17
     18div#community-profile-page h2:first-of-type {
     19        margin-bottom:1em;
     20}
     21
     22div#community-profile-page  h2.profile-section {
     23        border-bottom:dotted 1px #ccc;
     24}
     25
     26div#community-profile-page ul#profile-nav {
     27        border-bottom:solid 1px #ccc;
     28        width:100%;
     29        margin-top:1em;
     30        margin-bottom:1em;
     31        padding:1em 0;
     32        padding-bottom: 0;
     33        height:2.4em;
     34}
     35
     36form#your-profile ul#profile-nav li,
     37div#community-profile-page ul#profile-nav li {
     38        margin-left:0.4em;
     39        float:left;
     40        font-weight: bold;
     41        font-size: 15px;
     42        line-height: 24px;
     43}
     44
     45form#your-profile ul#profile-nav li a,
     46div#community-profile-page ul#profile-nav li a {
     47        text-decoration: none;
     48        color:#888;
     49}
     50
     51form#your-profile ul#profile-nav li a:hover,
     52form#your-profile ul#profile-nav li.nav-tab-active a,
     53div#community-profile-page ul#profile-nav li a:hover,
     54div#community-profile-page ul#profile-nav li.nav-tab-active a {
     55        text-decoration: none;
     56        color:#000;
     57}
     58
     59div#community-profile-page li.bp-members-profile-stats:before,
     60div#community-profile-page li.bp-friends-profile-stats:before,
     61div#community-profile-page li.bp-groups-profile-stats:before,
     62div#community-profile-page li.bp-blogs-profile-stats:before,
     63div#community-profile-page a.bp-xprofile-avatar-user-admin:before {
     64        font-family: 'dashicons';
     65        font-size: 18px;
     66        vertical-align: bottom;
     67        margin-right:5px;
     68}
     69
     70div#community-profile-page li.bp-members-profile-stats:before {
     71        content: "\f130";
     72}
     73
     74div#community-profile-page li.bp-friends-profile-stats:before {
     75        content: "\f454";
     76}
     77
     78div#community-profile-page li.bp-groups-profile-stats:before {
     79        content: "\f456";
     80}
     81
     82div#community-profile-page li.bp-blogs-profile-stats:before {
     83        content: "\f120";
     84}
     85
     86div#community-profile-page a.bp-xprofile-avatar-user-admin:before {
     87        content:"\f182";
     88}
     89
     90div#community-profile-page div#bp_xprofile_user_admin_avatar div.avatar {
     91        width:150px;
     92        margin:0 auto;
     93}
     94
     95div#community-profile-page div#bp_xprofile_user_admin_avatar a {
     96        display:block;
     97        margin:1em 0;
     98        text-decoration:none;
     99        color:#888;
     100}
     101
     102div#community-profile-page p.not-activated {
     103        margin:1em 1em 0;
     104        color:red;
     105}
     106
     107div#community-profile-page .form-table td.admin-field-visibility-td {
     108        padding:5px 5px 15px 5px;
     109}
     110
     111div#community-profile-page .form-table tr.admin-field-visibility-tr {
     112        border-bottom:dotted 1px #ccc;
     113}
     114
     115div#community-profile-page .form-table tr.admin-field-visibility-tr:last-child{
     116        border:none;
     117}
     118
     119div#community-profile-page .field-visibility-settings legend,
     120div#community-profile-page .field-visibility-settings-notoggle {
     121        font-size: 14px;
     122        font-style: italic;
     123        color:#666;
     124}
     125
     126div#community-profile-page .field-visibility-settings ul {
     127        margin:0;
     128        font-size: 13px;
     129}
     130
     131div#community-profile-page .field-visibility-settings ul li {
     132        display:inline-block;
     133        margin-right:1em;
     134}
     135
     136div#community-profile-page .form-table td.admin-field-radio label,
     137div#community-profile-page .form-table td.admin-field-checkbox label {
     138        display:block;
     139}
  • bp-members/admin/css/admin.min.css

     
     1div#profile-page.wrap form#your-profile{position:relative}div#profile-page.wrap form#your-profile h3:first-of-type{margin-top:6em}div#profile-page.wrap form#your-profile ul#profile-nav{position:absolute;top:-6em;border-bottom:solid 1px #ccc;width:100%}div#community-profile-page h2:first-of-type{margin-bottom:1em}div#community-profile-page h2.profile-section{border-bottom:dotted 1px #ccc}div#community-profile-page ul#profile-nav{border-bottom:solid 1px #ccc;width:100%;margin-top:1em;margin-bottom:1em;padding:1em 0;padding-bottom:0;height:2.4em}div#community-profile-page ul#profile-nav li,form#your-profile ul#profile-nav li{margin-left:.4em;float:left;font-weight:700;font-size:15px;line-height:24px}div#community-profile-page ul#profile-nav li a,form#your-profile ul#profile-nav li a{text-decoration:none;color:#888}div#community-profile-page ul#profile-nav li a:hover,div#community-profile-page ul#profile-nav li.nav-tab-active a,form#your-profile ul#profile-nav li a:hover,form#your-profile ul#profile-nav li.nav-tab-active a{text-decoration:none;color:#000}div#community-profile-page a.bp-xprofile-avatar-user-admin:before,div#community-profile-page li.bp-blogs-profile-stats:before,div#community-profile-page li.bp-friends-profile-stats:before,div#community-profile-page li.bp-groups-profile-stats:before,div#community-profile-page li.bp-members-profile-stats:before{font-family:dashicons;font-size:18px;vertical-align:bottom;margin-right:5px}div#community-profile-page li.bp-members-profile-stats:before{content:"\f130"}div#community-profile-page li.bp-friends-profile-stats:before{content:"\f454"}div#community-profile-page li.bp-groups-profile-stats:before{content:"\f456"}div#community-profile-page li.bp-blogs-profile-stats:before{content:"\f120"}div#community-profile-page a.bp-xprofile-avatar-user-admin:before{content:"\f182"}div#community-profile-page div#bp_xprofile_user_admin_avatar div.avatar{width:150px;margin:0 auto}div#community-profile-page div#bp_xprofile_user_admin_avatar a{display:block;margin:1em 0;text-decoration:none;color:#888}div#community-profile-page p.not-activated{margin:1em 1em 0;color:red}div#community-profile-page .form-table td.admin-field-visibility-td{padding:5px 5px 15px}div#community-profile-page .form-table tr.admin-field-visibility-tr{border-bottom:dotted 1px #ccc}div#community-profile-page .form-table tr.admin-field-visibility-tr:last-child{border:0}div#community-profile-page .field-visibility-settings legend,div#community-profile-page .field-visibility-settings-notoggle{font-size:14px;font-style:italic;color:#666}div#community-profile-page .field-visibility-settings ul{margin:0;font-size:13px}div#community-profile-page .field-visibility-settings ul li{display:inline-block;margin-right:1em}div#community-profile-page .form-table td.admin-field-checkbox label,div#community-profile-page .form-table td.admin-field-radio label{display:block}
     2 No newline at end of file
  • bp-members/admin/js/admin.js

     
     1(function( $ ) {
     2
     3        /** Profile Visibility Settings *********************************/
     4        $('.field-visibility-settings').hide();
     5        $('.visibility-toggle-link').on( 'click', function( event ) {
     6
     7                event.preventDefault();
     8
     9                var toggle_div = $(this).parent();
     10
     11                $(toggle_div).fadeOut( 600, function(){
     12                        $(toggle_div).siblings('.field-visibility-settings').slideDown(400);
     13                });
     14
     15        } );
     16
     17        $('.field-visibility-settings-close').on( 'click', function( event ) {
     18
     19                event.preventDefault();
     20
     21                var settings_div = $(this).parent();
     22                var vis_setting_text = settings_div.find('input:checked').parent().text();
     23
     24                settings_div.slideUp( 400, function() {
     25                        settings_div.siblings('.field-visibility-settings-toggle').fadeIn(800);
     26                        settings_div.siblings('.field-visibility-settings-toggle').children('.current-visibility-level').html(vis_setting_text);
     27                } );
     28
     29                return false;
     30        } );
     31
     32})(jQuery);
     33
     34
     35function clear(container) {
     36        if( !document.getElementById(container) ) return;
     37
     38        var container = document.getElementById(container);
     39
     40        if ( radioButtons = container.getElementsByTagName('INPUT') ) {
     41                for(var i=0; i<radioButtons.length; i++) {
     42                        radioButtons[i].checked = '';
     43                }
     44        }
     45
     46        if ( options = container.getElementsByTagName('OPTION') ) {
     47                for(var i=0; i<options.length; i++) {
     48                        options[i].selected = false;
     49                }
     50        }
     51
     52        return;
     53}
     54 No newline at end of file
  • bp-members/admin/js/admin.min.js

     
     1function clear(e){if(!document.getElementById(e))return;var e=document.getElementById(e);if(radioButtons=e.getElementsByTagName("INPUT")){for(var t=0;t<radioButtons.length;t++){radioButtons[t].checked=""}}if(options=e.getElementsByTagName("OPTION")){for(var t=0;t<options.length;t++){options[t].selected=false}}return}(function(e){e(".field-visibility-settings").hide();e(".visibility-toggle-link").on("click",function(t){t.preventDefault();var n=e(this).parent();e(n).fadeOut(600,function(){e(n).siblings(".field-visibility-settings").slideDown(400)})});e(".field-visibility-settings-close").on("click",function(t){t.preventDefault();var n=e(this).parent();var r=n.find("input:checked").parent().text();n.slideUp(400,function(){n.siblings(".field-visibility-settings-toggle").fadeIn(800);n.siblings(".field-visibility-settings-toggle").children(".current-visibility-level").html(r)});return false})})(jQuery)
     2 No newline at end of file
  • bp-members/bp-members-admin.php

     
     1<?php
     2// Exit if accessed directly
     3if ( !defined( 'ABSPATH' ) ) exit;
     4
     5if ( !class_exists( 'BP_Members_Admin' ) ) :
     6/**
     7 * Load Members admin area.
     8 *
     9 * @package BuddyPress
     10 * @subpackage membersAdministration
     11 *
     12 * @since BuddyPress (2.0.0)
     13 */
     14class BP_Members_Admin {
     15
     16        /** Directory *************************************************************/
     17
     18        /**
     19         * Path to the BP Members Admin directory.
     20         *
     21         * @var string $admin_dir
     22         */
     23        public $admin_dir = '';
     24
     25        /** URLs ******************************************************************/
     26
     27        /**
     28         * URL to the BP Members Admin directory.
     29         *
     30         * @var string $admin_url
     31         */
     32        public $admin_url = '';
     33
     34        /**
     35         * URL to the BP Members Admin CSS directory.
     36         *
     37         * @var string $css_url
     38         */
     39        public $css_url = '';
     40
     41        /**
     42         * URL to the BP Members Admin JS directory.
     43         *
     44         * @var string
     45         */
     46        public $js_url = '';
     47
     48        /** Other *****************************************************************/
     49
     50        /**
     51         * Screen id for edit user's profile page.
     52         *
     53         * @access public
     54         * @var string
     55         */
     56        public $user_page = '';
     57
     58        /**
     59         * Setup BP Members Admin.
     60         *
     61         * @access public
     62         * @since BuddyPress (2.0.0)
     63         *
     64         * @uses buddypress() to get BuddyPress main instance
     65         */
     66        public static function register_members_admin() {
     67                if( ! is_admin() )
     68                        return;
     69
     70                $bp = buddypress();
     71
     72                if( empty( $bp->members->admin ) ) {
     73                        $bp->members->admin = new self;
     74                }
     75
     76                return $bp->members->admin;
     77        }
     78
     79        /**
     80         * Constructor method.
     81         *
     82         * @access public
     83         * @since BuddyPress (2.0.0)
     84         */
     85        public function __construct() {
     86                $this->setup_globals();
     87                $this->setup_actions();
     88        }
     89
     90        /**
     91         * Set admin-related globals.
     92         *
     93         * @access private
     94         * @since BuddyPress (2.0.0)
     95         */
     96        private function setup_globals() {
     97                $bp = buddypress();
     98
     99                // Paths and URLs
     100                $this->admin_dir = trailingslashit( $bp->plugin_dir  . 'bp-members/admin' ); // Admin path
     101                $this->admin_url = trailingslashit( $bp->plugin_url  . 'bp-members/admin' ); // Admin URL
     102                $this->css_url   = trailingslashit( $this->admin_url . 'css' ); // Admin CSS URL
     103                $this->js_url    = trailingslashit( $this->admin_url . 'js'  ); // Admin CSS URL
     104
     105                // The Edit Profile Screen id
     106                $this->user_page = '';
     107
     108                // The screen ids to load specific css for
     109                $this->screen_id = array();
     110
     111                // The stats metabox default position
     112                $this->stats_metabox = new StdClass();
     113
     114                // The WordPress edit user url
     115                $this->edit_url = bp_get_admin_url( 'user-edit.php' );
     116
     117                // BuddyPress edit user's profile url
     118                $this->edit_profile_url = add_query_arg( 'page', 'bp-profile-edit', bp_get_admin_url( 'users.php' ) );
     119        }
     120
     121        /**
     122         * Set admin-related actions and filters.
     123         *
     124         * @access private
     125         * @since BuddyPress (2.0.0)
     126         */
     127        private function setup_actions() {
     128
     129                /** Actions ***************************************************/
     130
     131                // Add some page specific output to the <head>
     132                add_action( 'bp_admin_head',            array( $this, 'admin_head'      ), 999    );
     133
     134                // Add menu item to all users menu
     135                add_action( bp_core_admin_hook(),       array( $this, 'admin_menus'     ),   5    );
     136
     137                // Enqueue all admin JS and CSS
     138                add_action( 'bp_admin_enqueue_scripts', array( $this, 'enqueue_scripts' )         );
     139
     140                // Create the Profile Navigation (WordPress/Community)
     141                add_action( 'edit_user_profile',        array( $this, 'profile_nav'     ),  99, 1 );
     142
     143
     144                /** Filters ***************************************************/
     145
     146                // Add a row action to users listing
     147                add_filter( bp_core_do_network_admin() ? 'ms_user_row_actions' : 'user_row_actions', array( $this, 'row_actions' ), 10, 2 );
     148
     149        }
     150
     151        /**
     152         * Create the All Users > Edit Profile submenu.
     153         *
     154         * @access public
     155         * @since BuddyPress (2.0.0)
     156         *
     157         * @uses add_users_page() To add the Edit Profile page in Users section.
     158         */
     159        public function admin_menus() {
     160
     161                // Manage user's profile
     162                $hook = $this->user_page = add_users_page(
     163                        __( 'Edit Profile',  'buddypress' ),
     164                        __( 'Edit Profile',  'buddypress' ),
     165                        'bp_moderate',
     166                        'bp-profile-edit',
     167                        array( &$this, 'user_admin' )
     168                );
     169
     170                $edit_page = 'user-edit';
     171
     172                if ( bp_core_do_network_admin() ) {
     173                        $edit_page       .= '-network';
     174                        $this->user_page .= '-network';
     175                }
     176
     177                $this->screen_id = array( $edit_page, $this->user_page );
     178
     179                add_action( "admin_head-$hook", array( $this, 'modify_admin_menu_highlight' ) );
     180                add_action( "load-$hook",       array( $this, 'user_admin_load' ) );
     181
     182        }
     183
     184        /**
     185         * Add some specific styling to the Edit User and Edit User's Profile page.
     186         *
     187         * @access public
     188         * @since BuddyPress (2.0.0)
     189         */
     190        public function enqueue_scripts() {
     191                if ( ! in_array( get_current_screen()->id, $this->screen_id ) ) {
     192                        return;
     193                }
     194
     195                $min = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
     196
     197                $css = $this->css_url . "admin{$min}.css";
     198                $css = apply_filters( 'bp_members_admin_css', $css );
     199                wp_enqueue_style( 'bp-members-css', $css, array(), bp_get_version() );
     200
     201                $js = $this->js_url . "admin{$min}.js";
     202                $js = apply_filters( 'bp_members_admin_js', $js );
     203                wp_enqueue_script( 'bp-members-js', $js, array( 'jquery' ), bp_get_version(), true );
     204
     205                // Plugins may want to hook here to load some css/js
     206                do_action( 'bp_members_admin_enqueue_scripts', get_current_screen()->id, $this->screen_id );
     207        }
     208
     209        /**
     210         * Create the Profile navigation in Edit User & Edit Profile pages.
     211         *
     212         * @access public
     213         * @since BuddyPress (2.0.0)
     214         */
     215        public function profile_nav( $user = null, $active = 'WordPress' ) {
     216
     217                if ( empty( $user->ID ) ) {
     218                        return;
     219                }
     220
     221                $query_args = array( 'user_id' => $user->ID );
     222
     223                if ( ! empty( $_REQUEST['wp_http_referer'] ) ) {
     224                        $query_args['wp_http_referer'] = urlencode( wp_unslash( $_REQUEST['wp_http_referer'] ) );
     225                }
     226
     227                $community_url = add_query_arg( $query_args, $this->edit_profile_url );
     228                $wordpress_url = add_query_arg( $query_args, $this->edit_url );
     229
     230                $bp_active = false;
     231                $wp_active = ' nav-tab-active';
     232                if ( 'BuddyPress' == $active ) {
     233                        $bp_active = ' nav-tab-active';
     234                        $wp_active = false;
     235                }
     236
     237                ?>
     238                <ul id="profile-nav" class="nav-tab-wrapper">
     239                        <li class="nav-tab<?php echo $wp_active;?>"><a href="<?php echo esc_url( $wordpress_url );?>"><?php _e( 'WordPress Profile' ); ?></a></li>
     240                        <li class="nav-tab<?php echo $bp_active;?>"><a href="<?php echo esc_url( $community_url );?>"><?php _e( 'Community Profile' ); ?></a></li>
     241
     242                        <?php do_action( 'bp_members_admin_profile_nav', $active, $user ); ?>
     243                </ul>
     244                <?php
     245        }
     246
     247        /**
     248         * Highlight the Users menu if on Edit Profile pages.
     249         *
     250         * @access public
     251         * @since BuddyPress (2.0.0)
     252         */
     253        public function modify_admin_menu_highlight() {
     254                global $plugin_page, $submenu_file;
     255
     256                // Only Show the All users menu
     257                if ( 'bp-profile-edit' ==  $plugin_page ) {
     258                        $submenu_file = 'users.php';
     259                }
     260        }
     261
     262        /**
     263         * Remove the Edit Profile submenu page.
     264         *
     265         * @access public
     266         * @since BuddyPress (2.0.0)
     267         */
     268        public function admin_head() {
     269                // Remove submenu to force using Profile Navigation
     270                remove_submenu_page( 'users.php', 'bp-profile-edit' );
     271        }
     272
     273        /**
     274         * Set up the user's profile admin page.
     275         *
     276         * Loaded before the page is rendered, this function does all initial
     277         * setup, including: processing form requests, registering contextual
     278         * help, and setting up screen options.
     279         *
     280         * @access public
     281         * @since BuddyPress (2.0.0)
     282         */
     283        public function user_admin_load() {
     284
     285                if ( ! $user_id = intval( $_GET['user_id'] ) ) {
     286                        wp_die( __( 'No users were found', 'buddypress' ) );
     287                }
     288
     289                $bp = buddypress();
     290
     291                // Build redirection URL
     292                $redirect_to = remove_query_arg( array( 'action', 'error', 'updated', 'spam', 'ham', 'delete_avatar' ), $_SERVER['REQUEST_URI'] );
     293                $doaction = ! empty( $_REQUEST['action'] ) ? $_REQUEST['action'] : false;
     294
     295                if ( ! empty( $_REQUEST['user_status'] ) ) {
     296                        $spam = ( 'spam' == $_REQUEST['user_status'] ) ? true : false ;
     297
     298                        if ( $spam != bp_is_user_spammer( $user_id ) ) {
     299                                $doaction = $_REQUEST['user_status'];
     300                        }
     301                }
     302
     303                // Call an action for plugins to hook in early
     304                do_action_ref_array( 'bp_members_admin_load', array( $doaction, $_REQUEST ) );
     305
     306                // Allowed actions
     307                $allowed_actions = apply_filters( 'bp_members_admin_allowed_actions', array( 'update', 'delete_avatar', 'spam', 'ham' ) );
     308
     309                // Prepare the display of the Community Profile screen
     310                if ( ! in_array( $doaction, $allowed_actions ) ) {
     311                        add_screen_option( 'layout_columns', array( 'default' => 2, 'max' => 2, ) );
     312
     313                        get_current_screen()->add_help_tab( array(
     314                                'id'      => 'bp-profile-edit-overview',
     315                                'title'   => __( 'Overview', 'buddypress' ),
     316                                'content' =>
     317                                '<p>' . __( 'This is the admin view of a user&#39;s profile.', 'buddypress' ) . '</p>' .
     318                                '<p>' . __( 'You can edit the different fields of his extended profile from the main metabox', 'buddypress' ) . '</p>' .
     319                                '<p>' . __( 'You can get some interesting informations about him on right side metaboxes', 'buddypress' ) . '</p>'
     320                        ) );
     321
     322                        // Help panel - sidebar links
     323                        get_current_screen()->set_help_sidebar(
     324                                '<p><strong>' . __( 'For more information:', 'buddypress' ) . '</strong></p>' .
     325                                '<p>' . __( '<a href="http://codex.buddypress.org/buddypress-site-administration/managing-user-profiles/">Managing Profiles</a>', 'buddypress' ) . '</p>' .
     326                                '<p>' . __( '<a href="http://buddypress.org/support/">Support Forums</a>', 'buddypress' ) . '</p>'
     327                        );
     328
     329                        // Register metaboxes for the edit screen.
     330                        add_meta_box( 'submitdiv', _x( 'Status', 'members user-admin edit screen', 'buddypress' ), array( &$this, 'user_admin_status_metabox' ), get_current_screen()->id, 'side', 'core' );
     331
     332                        // In case xprofile is not active
     333                        $this->stats_metabox->context = 'normal';
     334                        $this->stats_metabox->priority = 'core';
     335
     336                        /**
     337                         * xProfile Hooks to load the profile fields if component is active
     338                         * Plugins should not use this hook, please use 'bp_members_admin_user_metaboxes' instead
     339                         */
     340                        do_action_ref_array( 'bp_members_admin_xprofile_metabox', array( $user_id, get_current_screen()->id, $this->stats_metabox ) );
     341
     342                        // If xProfile is inactive, difficult to know what's profile we're on
     343                        $display_name = false;
     344                        if ( 'normal' == $this->stats_metabox->context ) {
     345                                $display_name = ' - ' . esc_html( bp_core_get_user_displayname( $user_id ) );
     346                        }
     347
     348                        // User Stat metabox
     349                        add_meta_box( 'bp_members_admin_user_stats',    _x( 'Stats' . $display_name, 'members user-admin edit screen', 'buddypress' ), array( &$this, 'user_admin_stats_metabox' ), get_current_screen()->id, sanitize_key( $this->stats_metabox->context ), sanitize_key( $this->stats_metabox->priority ) );
     350
     351                        // Custom metabox ?
     352                        do_action( 'bp_members_admin_user_metaboxes' );
     353
     354                        // Enqueue javascripts
     355                        wp_enqueue_script( 'postbox' );
     356                        wp_enqueue_script( 'dashboard' );
     357                        wp_enqueue_script( 'comment' );
     358
     359                // Spam or Ham user
     360                } else if ( in_array( $doaction, array( 'spam', 'ham' ) ) ) {
     361
     362                        check_admin_referer( 'edit-bp-profile_' . $user_id );
     363
     364                        if ( bp_core_process_spammer_status( $user_id, $doaction ) ) {
     365                                $redirect_to = add_query_arg( 'updated', $doaction, $redirect_to );
     366                        } else {
     367                                $redirect_to = add_query_arg( 'error', $doaction, $redirect_to );
     368                        }
     369
     370                        bp_core_redirect( $redirect_to );
     371
     372                // Update other stuff once above ones are done
     373                } else {
     374                        $this->redirect = $redirect_to;
     375
     376                        do_action_ref_array( 'bp_members_admin_update_user', array( $doaction, $user_id, $_REQUEST, $this->redirect ) );
     377
     378                        bp_core_redirect( $this->redirect );
     379                }
     380        }
     381
     382        /**
     383         * Display the user's profile.
     384         *
     385         * @access public
     386         * @since BuddyPress (2.0.0)
     387         */
     388        public function user_admin() {
     389
     390                if ( ! current_user_can( 'bp_moderate' ) ) {
     391                        die( '-1' );
     392                }
     393
     394                $user = get_user_to_edit( $_GET['user_id'] );
     395
     396                // Construct URL for form
     397                $form_url        = remove_query_arg( array( 'action', 'error', 'updated', 'spam', 'ham' ), $_SERVER['REQUEST_URI'] );
     398                $form_url        = esc_url( add_query_arg( 'action', 'update', $form_url ) );
     399                $wp_http_referer = remove_query_arg( array( 'action', 'updated' ), $_REQUEST['wp_http_referer'] );
     400
     401                // Prepare notice for admin
     402                $notice = array();
     403
     404                if ( ! empty( $_REQUEST['updated'] ) ) {
     405                        switch ( $_REQUEST['updated'] ) {
     406                        case 'avatar':
     407                                $notice = array(
     408                                        'class'   => 'updated',
     409                                        'message' => esc_html__( 'Avatar was deleted successfully!', 'buddypress' )
     410                                );
     411                                break;
     412                        case 'ham' :
     413                                $notice = array(
     414                                        'class'   => 'updated',
     415                                        'message' => esc_html__( 'User removed as spammer.', 'buddypress' )
     416                                );
     417                                break;
     418                        case 'spam' :
     419                                $notice = array(
     420                                        'class'   => 'updated',
     421                                        'message' => esc_html__( 'User marked as spammer. Spam users are visible only to site admins.', 'buddypress' )
     422                                );
     423                                break;
     424                        case 1 :
     425                                $notice = array(
     426                                        'class'   => 'updated',
     427                                        'message' => esc_html__( 'Profile updated.', 'buddypress' )
     428                                );
     429                                break;
     430                        }
     431                }
     432
     433                if ( ! empty( $_REQUEST['error'] ) ) {
     434                        switch ( $_REQUEST['error'] ) {
     435                        case 'avatar':
     436                                $notice = array(
     437                                        'class'   => 'error',
     438                                        'message' => esc_html__( 'There was a problem deleting that avatar, please try again.', 'buddypress' )
     439                                );
     440                                break;
     441                        case 'ham' :
     442                                $notice = array(
     443                                        'class'   => 'error',
     444                                        'message' => esc_html__( 'User could not be removed as spammer.', 'buddypress' )
     445                                );
     446                                break;
     447                        case 'spam' :
     448                                $notice = array(
     449                                        'class'   => 'error',
     450                                        'message' => esc_html__( 'User could not be marked as spammer.', 'buddypress' )
     451                                );
     452                                break;
     453                        case 1 :
     454                                $notice = array(
     455                                        'class'   => 'error',
     456                                        'message' => esc_html__( 'An error occured while trying to update the profile.', 'buddypress' )
     457                                );
     458                                break;
     459                        case 2:
     460                                $notice = array(
     461                                        'class'   => 'error',
     462                                        'message' => esc_html__( 'Please make sure you fill in all required fields in this profile field group before saving.', 'buddypress' )
     463                                );
     464                                break;
     465                        case 3:
     466                                $notice = array(
     467                                        'class'   => 'error',
     468                                        'message' => esc_html__( 'There was a problem updating some of your profile information, please try again.', 'buddypress' )
     469                                );
     470                                break;
     471                        }
     472                }
     473
     474                if ( ! empty( $notice ) ) :
     475                        if ( 'updated' === $notice['class'] ) : ?>
     476                                <div id="message" class="<?php echo esc_attr( $notice['class'] ); ?>">
     477                        <?php else: ?>
     478                                <div class="<?php echo esc_attr( $notice['class'] ); ?>">
     479                        <?php endif; ?>
     480                                <p><?php echo $notice['message']; ?></p>
     481                                <?php if ( !empty( $wp_http_referer ) && ( 'updated' === $notice['class'] ) ) : ?>
     482                                        <p><a href="<?php echo esc_url( $wp_http_referer ); ?>"><?php _e( '&larr; Back to Users', 'buddypress' ); ?></a></p>
     483                                <?php endif; ?>
     484                        </div>
     485                <?php endif; ?>
     486
     487                <div class="wrap"  id="community-profile-page">
     488                        <?php screen_icon( 'users' ); ?>
     489                        <h2>
     490                                <?php
     491                                _e( 'Edit User', 'buddypress' );
     492                                if ( current_user_can( 'create_users' ) ) { ?>
     493                                        <a href="user-new.php" class="add-new-h2"><?php echo esc_html_x( 'Add New', 'user', 'buddypress' ); ?></a>
     494                                <?php } elseif ( is_multisite() && current_user_can( 'promote_users' ) ) { ?>
     495                                        <a href="user-new.php" class="add-new-h2"><?php echo esc_html_x( 'Add Existing', 'user', 'buddypress' ); ?></a>
     496                                <?php }
     497                                ?>
     498                        </h2>
     499
     500                        <?php if ( ! empty( $user ) ) :
     501
     502                                $this->profile_nav( $user, 'BuddyPress' ); ?>
     503
     504                                <form action="<?php echo esc_attr( $form_url ); ?>" id="your-profile" method="post">
     505                                        <div id="poststuff">
     506
     507                                                <div id="post-body" class="metabox-holder columns-<?php echo 1 == get_current_screen()->get_columns() ? '1' : '2'; ?>">
     508                                                        <div id="post-body-content">
     509                                                        </div><!-- #post-body-content -->
     510
     511                                                        <div id="postbox-container-1" class="postbox-container">
     512                                                                <?php do_meta_boxes( get_current_screen()->id, 'side', $user ); ?>
     513                                                        </div>
     514
     515                                                        <div id="postbox-container-2" class="postbox-container">
     516                                                                <?php do_meta_boxes( get_current_screen()->id, 'normal',   $user ); ?>
     517                                                                <?php do_meta_boxes( get_current_screen()->id, 'advanced', $user ); ?>
     518                                                        </div>
     519                                                </div><!-- #post-body -->
     520
     521                                        </div><!-- #poststuff -->
     522
     523                                        <?php wp_nonce_field( 'closedpostboxes', 'closedpostboxesnonce', false ); ?>
     524                                        <?php wp_nonce_field( 'meta-box-order',  'meta-box-order-nonce', false ); ?>
     525                                        <?php wp_nonce_field( 'edit-bp-profile_' . $user->ID ); ?>
     526
     527                                </form>
     528
     529                        <?php else : ?>
     530                                <p><?php printf( __( 'No user found with this ID. <a href="%s">Go back and try again</a>.', 'buddypress' ), esc_url( bp_get_admin_url( 'users.php' ) ) ); ?></p>
     531                        <?php endif; ?>
     532
     533                </div><!-- .wrap -->
     534                <?php
     535        }
     536
     537        /**
     538         * Render the Status metabox for user's profile screen.
     539         *
     540         * Actions are:
     541         * - Update profile fields if xProfile component is active
     542         * - Spam/Unspam user
     543         *
     544         * @access public
     545         * @since BuddyPress (2.0.0)
     546         *
     547         * @param WP_User $user The WP_User object to be edited.
     548         */
     549        public function user_admin_status_metabox( $user = null ) {
     550
     551                // bail if no user id or if the user has not activated his account yet..
     552                if ( empty( $user->ID ) ) {
     553                        return;
     554                }
     555
     556                if ( ( isset( $user->user_status ) && 2 == $user->user_status ) ) {
     557                        echo '<p class="not-activated">' . esc_html__( 'User has not activated his account yet', 'buddypress' ) . '</p><br/>';
     558                        return;
     559                }
     560                ?>
     561
     562                <div class="submitbox" id="submitcomment">
     563                        <div id="minor-publishing">
     564                                <div id="minor-publishing-actions">
     565                                        <div id="preview-action">
     566                                                <a class="button preview" href="<?php echo esc_attr( bp_core_get_user_domain( $user->ID ) ); ?>" target="_blank"><?php esc_html_e( 'View Profile', 'buddypress' ); ?></a>
     567                                        </div>
     568
     569                                        <div class="clear"></div>
     570                                </div><!-- #minor-publishing-actions -->
     571
     572                                <div id="misc-publishing-actions">
     573                                        <div class="misc-pub-section" id="comment-status-radio">
     574                                                <label class="approved"><input type="radio" name="user_status" value="ham" <?php checked( bp_is_user_spammer( $user->ID ), false ); ?>><?php esc_html_e( 'Active', 'buddypress' ); ?></label><br />
     575                                                <label class="spam"><input type="radio" name="user_status" value="spam" <?php checked( bp_is_user_spammer( $user->ID ), true ); ?>><?php esc_html_e( 'Spammer', 'buddypress' ); ?></label>
     576                                        </div>
     577
     578                                        <div class="misc-pub-section curtime misc-pub-section-last">
     579                                                <?php
     580                                                // translators: Publish box date format, see http://php.net/date
     581                                                $datef = __( 'M j, Y @ G:i', 'buddypress' );
     582                                                $date  = date_i18n( $datef, strtotime( $user->user_registered ) );
     583                                                ?>
     584                                                <span id="timestamp"><?php printf( __( 'Registered on: <strong>%1$s</strong>', 'buddypress' ), $date ); ?></span>
     585                                        </div>
     586                                </div> <!-- #misc-publishing-actions -->
     587
     588                                <div class="clear"></div>
     589                        </div><!-- #minor-publishing -->
     590
     591                        <div id="major-publishing-actions">
     592                                <div id="publishing-action">
     593                                        <?php submit_button( esc_html__( 'Update Profile', 'buddypress' ), 'primary', 'save', false, array( 'tabindex' => '4' ) ); ?>
     594                                </div>
     595                                <div class="clear"></div>
     596                        </div><!-- #major-publishing-actions -->
     597
     598                </div><!-- #submitcomment -->
     599
     600                <?php
     601        }
     602
     603        /**
     604         * Render the fallback metabox in case a user has been marked as a spammer.
     605         *
     606         * @access public
     607         * @since BuddyPress (2.0.0)
     608         *
     609         * @param WP_User $user The WP_User object to be edited.
     610         */
     611        public function user_admin_spammer_metabox( $user = null ) {
     612                ?>
     613                <p><?php printf( __( '%s has been marked as a spammer, this user&#39;s BuddyPress datas were removed', 'buddypress' ), esc_html( bp_core_get_user_displayname( $user->ID ) ) ) ;?></p>
     614                <?php
     615        }
     616
     617        /**
     618         * Render the Stats metabox to moderate inappropriate images.
     619         *
     620         * @access public
     621         * @since BuddyPress (2.0.0)
     622         *
     623         * @param WP_User $user The WP_User object to be edited.
     624         */
     625        public function user_admin_stats_metabox( $user = null ) {
     626
     627                if ( empty( $user->ID ) ) {
     628                        return;
     629                }
     630
     631                // If account is not activated last activity is the time user registered
     632                if ( isset( $user->user_status ) && 2 == $user->user_status ) {
     633                        $last_active = $user->user_registered;
     634                // Account is activated, getting user's last activity
     635                } else {
     636                        $last_active = bp_get_user_last_activity( $user->ID );
     637                }
     638
     639                $datef = __( 'M j, Y @ G:i', 'buddypress' );
     640                $date  = date_i18n( $datef, strtotime( $last_active ) ); ?>
     641
     642                <ul>
     643                        <li class="bp-members-profile-stats"><?php printf( __( 'Last active: <strong>%1$s</strong>', 'buddypress' ), $date ); ?></li>
     644
     645                        <?php
     646                        // Loading other stats only if user has activated his account
     647                        if ( empty( $user->user_status ) ) {
     648                                do_action( 'bp_members_admin_user_stats', $user->ID, $user );
     649                        }
     650                        ?>
     651                </ul>
     652                <?php
     653        }
     654
     655        /**
     656         * Add a link to Profile in Users listing row actions.
     657         *
     658         * @access public
     659         * @since BuddyPress (2.0.0)
     660         *
     661         * @param array $actions WordPress row actions (edit, delete).
     662         * @param object $user The object for the user row.
     663         * @return array Merged actions.
     664         */
     665        public function row_actions( $actions = '', $user = null ) {
     666
     667                $edit_profile = add_query_arg( array(
     668                        'user_id'         => $user->ID,
     669                        'wp_http_referer' => urlencode( wp_unslash( $_SERVER['REQUEST_URI'] ) ),
     670                ), $this->edit_profile_url );
     671
     672                $edit_action = $actions['edit'];
     673                unset( $actions['edit'] );
     674
     675                $new_edit_actions = array(
     676                        'edit'         => $edit_action,
     677                        'edit-profile' => '<a href="' . esc_url( $edit_profile ) . '">' . esc_html__( 'Profile', 'buddypress' ) . '</a>'
     678                );
     679
     680                return array_merge( $new_edit_actions, $actions );
     681        }
     682
     683}
     684endif; // class_exists check
     685
     686// Load the BP Members admin
     687add_action( 'bp_init', array( 'BP_Members_Admin','register_members_admin' ) );
  • bp-members/bp-members-functions.php

     
    563563        remove_action( 'make_spam_user', 'bp_core_mark_user_spam_admin' );
    564564        remove_action( 'make_ham_user',  'bp_core_mark_user_ham_admin'  );
    565565
     566        // Determine if we are on an admin page
     567        $is_admin = is_admin();
     568        if ( $is_admin && ! defined( 'DOING_AJAX' ) ) {
     569                $is_admin = (bool) ( buddypress()->members->admin->user_page !== get_current_screen()->id );
     570        }
     571
    566572        // When marking as spam in the Dashboard, these actions are handled by WordPress
    567         if ( !is_admin() ) {
     573        if ( ! $is_admin ) {
    568574
    569575                // Get the blogs for the user
    570576                $blogs = get_blogs_of_user( $user_id, true );
  • bp-members/bp-members-loader.php

     
    4545                        'functions',
    4646                        'notifications',
    4747                );
     48
     49                if ( is_admin() ) {
     50                        $includes[] = 'admin';
     51                }
     52
    4853                parent::includes( $includes );
    4954        }
    5055
  • bp-xprofile/bp-xprofile-admin.php

     
    466466
    467467<?php
    468468}
     469
     470if ( ! class_exists( 'BP_XProfile_User_Admin' ) ) :
     471/**
     472 * Load xProfile Profile admin area.
     473 *
     474 * @package BuddyPress
     475 * @subpackage xProfileAdministration
     476 *
     477 * @since BuddyPress (2.0.0)
     478 */
     479class BP_XProfile_User_Admin {
     480
     481        /**
     482         * Setup xProfile User Admin.
     483         *
     484         * @access public
     485         * @since BuddyPress (2.0.0)
     486         *
     487         * @uses buddypress() to get BuddyPress main instance
     488         */
     489        public static function register_xprofile_user_admin() {
     490                if( ! is_admin() )
     491                        return;
     492
     493                $bp = buddypress();
     494
     495                if( empty( $bp->profile->admin ) ) {
     496                        $bp->profile->admin = new self;
     497                }
     498
     499                return $bp->profile->admin;
     500        }
     501
     502        /**
     503         * Constructor method.
     504         *
     505         * @access public
     506         * @since BuddyPress (2.0.0)
     507         */
     508        public function __construct() {
     509                $this->setup_actions();
     510        }
     511
     512        /**
     513         * Set admin-related actions and filters.
     514         *
     515         * @access private
     516         * @since BuddyPress (2.0.0)
     517         */
     518        private function setup_actions() {
     519
     520                /** Actions ***************************************************/
     521
     522                // Register the metabox in Member's community admin profile
     523                add_action( 'bp_members_admin_xprofile_metabox', array( $this, 'register_metaboxes' ), 10, 3 );
     524
     525                // Saves the profile actions for user ( avatar, profile fields )
     526                add_action( 'bp_members_admin_update_user',      array( $this, 'user_admin_load' ),    10, 4 );
     527
     528        }
     529
     530        /**
     531         * Register the xProfile metabox on Community Profile admin page.
     532         *
     533         * @access public
     534         * @since BuddyPress (2.0.0)
     535         *
     536         * @param int $user_id ID of the user being edited.
     537         * @param string $screen_id Screen ID to load the metabox in.
     538         * @param object $stats_metabox Context and priority for the stats metabox.
     539         */
     540        public function register_metaboxes( $user_id = 0, $screen_id = '', $stats_metabox = null ) {
     541
     542                if ( empty( $screen_id ) ) {
     543                        $screen_id = buddypress()->members->admin->user_page;
     544                }
     545
     546                if ( empty( $stats_metabox ) ) {
     547                        $stats_metabox = new StdClass();
     548                }
     549
     550                // Moving the Stats Metabox
     551                $stats_metabox->context = 'side';
     552                $stats_metabox->priority = 'low';
     553
     554                // Each Group of fields will have his own metabox
     555                if ( false == bp_is_user_spammer( $user_id ) && bp_has_profile( array( 'fetch_fields' => false ) ) ) {
     556                        while ( bp_profile_groups() ) : bp_the_profile_group();
     557                                add_meta_box( 'bp_xprofile_user_admin_fields_' . sanitize_key( bp_get_the_profile_group_slug() ), esc_html( bp_get_the_profile_group_name() ), array( &$this, 'user_admin_profile_metaboxes' ), $screen_id, 'normal', 'core', array( 'profile_group_id' => absint( bp_get_the_profile_group_id() ) ) );
     558                        endwhile;
     559
     560                // if a user has been mark as a spammer, his BuddyPress datas are removed !
     561                } else {
     562                        add_meta_box( 'bp_xprofile_user_admin_empty_profile', _x( 'User marked as a spammer', 'xprofile user-admin edit screen', 'buddypress' ), array( &$this, 'user_admin_spammer_metabox' ), $screen_id, 'normal', 'core' );
     563                }
     564
     565                // Avatar Metabox
     566                add_meta_box( 'bp_xprofile_user_admin_avatar',  _x( 'Avatar', 'xprofile user-admin edit screen', 'buddypress' ), array( &$this, 'user_admin_avatar_metabox' ), $screen_id, 'side', 'low' );
     567
     568        }
     569
     570        /**
     571         * Save the profile fields in Members community profile page.
     572         *
     573         * Loaded before the page is rendered, this function is processing form
     574         * requests.
     575         *
     576         * @access public
     577         * @since BuddyPress (2.0.0)
     578         */
     579        public function user_admin_load( $doaction = '', $user_id = 0, $request = array(), $redirect_to = '' ) {
     580
     581                // Eventually delete avatar
     582                if ( 'delete_avatar' == $doaction ) {
     583
     584                        check_admin_referer( 'delete_avatar' );
     585
     586                        $redirect_to = remove_query_arg( '_wpnonce', $redirect_to );
     587
     588                        if ( bp_core_delete_existing_avatar( array( 'item_id' => $user_id ) ) ) {
     589                                $redirect_to = add_query_arg( 'updated', 'avatar', $redirect_to );
     590                        } else {
     591                                $redirect_to = add_query_arg( 'error', 'avatar', $redirect_to );
     592                        }
     593
     594                        bp_core_redirect( $redirect_to );
     595
     596                // Update profile fields
     597                } else {
     598                        // Check to see if any new information has been submitted
     599                        if ( isset( $_POST['field_ids'] ) ) {
     600
     601                                // Check the nonce
     602                                check_admin_referer( 'edit-bp-profile_' . $user_id );
     603
     604                                // Check we have field ID's
     605                                if ( empty( $_POST['field_ids'] ) ) {
     606                                        $redirect_to = add_query_arg( 'error', '1', $redirect_to );
     607                                        bp_core_redirect( $redirect_to );
     608                                }
     609
     610                                $merge_ids = '';
     611                                foreach ( $_POST['field_ids'] as $ids ) {
     612                                        $merge_ids .= $ids . ',';
     613                                }
     614
     615                                // Explode the posted field IDs into an array so we know which
     616                                // fields have been submitted
     617                                $posted_field_ids = array_filter( wp_parse_id_list( $merge_ids ) );
     618                                $is_required      = array();
     619
     620                                // Loop through the posted fields formatting any datebox values
     621                                // then validate the field
     622                                foreach ( (array) $posted_field_ids as $field_id ) {
     623                                        if ( ! isset( $_POST['field_' . $field_id] ) ) {
     624                                                if ( ! empty( $_POST['field_' . $field_id . '_day'] ) && ! empty( $_POST['field_' . $field_id . '_month'] ) && ! empty( $_POST['field_' . $field_id . '_year'] ) ) {
     625                                                        // Concatenate the values
     626                                                        $date_value =   $_POST['field_' . $field_id . '_day'] . ' ' . $_POST['field_' . $field_id . '_month'] . ' ' . $_POST['field_' . $field_id . '_year'];
     627
     628                                                        // Turn the concatenated value into a timestamp
     629                                                        $_POST['field_' . $field_id] = date( 'Y-m-d H:i:s', strtotime( $date_value ) );
     630                                                }
     631                                        }
     632
     633                                        $is_required[ $field_id ] = xprofile_check_is_required_field( $field_id );
     634                                        if ( $is_required[ $field_id ] && empty( $_POST['field_' . $field_id] ) ) {
     635                                                $redirect_to = add_query_arg( 'error', '2', $redirect_to );
     636                                                bp_core_redirect( $redirect_to );
     637                                        }
     638                                }
     639
     640                                // Set the errors var
     641                                $errors = false;
     642
     643                                // Now we've checked for required fields, lets save the values.
     644                                foreach ( (array) $posted_field_ids as $field_id ) {
     645
     646                                        // Certain types of fields (checkboxes, multiselects) may come through empty. Save them as an empty array so that they don't get overwritten by the default on the next edit.
     647                                        if ( empty( $_POST['field_' . $field_id] ) ) {
     648                                                $value = array();
     649                                        } else {
     650                                                $value = $_POST['field_' . $field_id];
     651                                        }
     652
     653                                        if ( ! xprofile_set_field_data( $field_id, $user_id, $value, $is_required[ $field_id ] ) ) {
     654                                                $errors = true;
     655                                        } else {
     656                                                do_action( 'xprofile_profile_field_data_updated', $field_id, $value );
     657                                        }
     658
     659                                        // Save the visibility level
     660                                        $visibility_level = ! empty( $_POST['field_' . $field_id . '_visibility'] ) ? $_POST['field_' . $field_id . '_visibility'] : 'public';
     661                                        xprofile_set_field_visibility_level( $field_id, $user_id, $visibility_level );
     662                                }
     663
     664                                do_action( 'xprofile_updated_profile', $user_id, $posted_field_ids, $errors );
     665
     666                                // Set the feedback messages
     667                                if ( ! empty( $errors ) ) {
     668                                        $redirect_to = add_query_arg( 'error', '3', $redirect_to );
     669                                } else {
     670                                        $redirect_to = add_query_arg( 'updated', '1', $redirect_to );
     671                                }
     672
     673                                bp_core_redirect( $redirect_to );
     674                        }
     675                }
     676        }
     677
     678        /**
     679         * Render the xprofile metabox for Community Profile screen.
     680         *
     681         * @access public
     682         * @since BuddyPress (2.0.0)
     683         *
     684         * @param WP_User $user The WP_User object for the user being edited.
     685         */
     686        public function user_admin_profile_metaboxes( $user = null, $args = array() ) {
     687
     688                if ( empty( $user->ID ) ) {
     689                        return;
     690                }
     691
     692                $r = bp_parse_args( $args['args'], array(
     693                        'profile_group_id' => 0,
     694                        'user_id'          => $user->ID
     695                ), 'bp_xprofile_user_admin_profile_loop_args' );
     696
     697                // We really need these args
     698                if ( empty( $r['profile_group_id'] ) || empty( $r['user_id'] ) ) {
     699                        return;
     700                }
     701
     702                if ( bp_has_profile( $r ) ) :
     703
     704                        while ( bp_profile_groups() ) : bp_the_profile_group(); ?>
     705
     706                                <p class="description"><?php bp_the_profile_group_description(); ?></p>
     707
     708                                <table class="form-table">
     709                                        <tbody>
     710
     711                                        <?php while ( bp_profile_fields() ) : bp_the_profile_field(); ?>
     712
     713                                                <tr>
     714
     715                                                        <?php if ( 'textbox' === bp_get_the_profile_field_type() ) : ?>
     716
     717                                                                <th><label for="<?php bp_the_profile_field_input_name(); ?>"><?php bp_the_profile_field_name(); ?> <?php if ( bp_get_the_profile_field_is_required() ) : ?><?php _e( '(required)', 'buddypress' ); ?><?php endif; ?></label></th>
     718                                                                <td class="admin-field-<?php bp_the_profile_field_type();?>">
     719                                                                        <input type="text" name="<?php bp_the_profile_field_input_name(); ?>" id="<?php bp_the_profile_field_input_name(); ?>" value="<?php bp_the_profile_field_edit_value(); ?>" <?php if ( bp_get_the_profile_field_is_required() ) : ?>aria-required="true"<?php endif; ?>/>
     720                                                                        <span class="description"><?php bp_the_profile_field_description(); ?></span>
     721                                                                </td>
     722
     723                                                        <?php endif; ?>
     724
     725                                                        <?php if ( 'textarea' === bp_get_the_profile_field_type() ) : ?>
     726
     727                                                                <th><label for="<?php bp_the_profile_field_input_name(); ?>"><?php bp_the_profile_field_name(); ?> <?php if ( bp_get_the_profile_field_is_required() ) : ?><?php _e( '(required)', 'buddypress' ); ?><?php endif; ?></label></th>
     728                                                                <td class="admin-field-<?php bp_the_profile_field_type();?>">
     729                                                                        <textarea rows="5" cols="40" name="<?php bp_the_profile_field_input_name(); ?>" id="<?php bp_the_profile_field_input_name(); ?>" <?php if ( bp_get_the_profile_field_is_required() ) : ?>aria-required="true"<?php endif; ?>><?php bp_the_profile_field_edit_value(); ?></textarea>
     730                                                                        <p class="description"><?php bp_the_profile_field_description(); ?></p>
     731                                                                </td>
     732
     733                                                        <?php endif; ?>
     734
     735                                                        <?php if ( 'selectbox' === bp_get_the_profile_field_type() ) : ?>
     736
     737                                                                <th><label for="<?php bp_the_profile_field_input_name(); ?>"><?php bp_the_profile_field_name(); ?> <?php if ( bp_get_the_profile_field_is_required() ) : ?><?php _e( '(required)', 'buddypress' ); ?><?php endif; ?></label></th>
     738                                                                <td class="admin-field-<?php bp_the_profile_field_type();?>">
     739                                                                        <select name="<?php bp_the_profile_field_input_name(); ?>" id="<?php bp_the_profile_field_input_name(); ?>" <?php if ( bp_get_the_profile_field_is_required() ) : ?>aria-required="true"<?php endif; ?>>
     740                                                                                <?php bp_the_profile_field_options( array( 'user_id' => $r['user_id'], ) ); ?>
     741                                                                        </select>
     742                                                                        <span class="description"><?php bp_the_profile_field_description(); ?></span>
     743                                                                </td>
     744
     745                                                        <?php endif; ?>
     746
     747                                                        <?php if ( 'multiselectbox' === bp_get_the_profile_field_type() ) : ?>
     748
     749                                                                <th><label for="<?php bp_the_profile_field_input_name(); ?>"><?php bp_the_profile_field_name(); ?> <?php if ( bp_get_the_profile_field_is_required() ) : ?><?php _e( '(required)', 'buddypress' ); ?><?php endif; ?></label></th>
     750                                                                <td class="admin-field-<?php bp_the_profile_field_type();?>">
     751                                                                        <select name="<?php bp_the_profile_field_input_name(); ?>" id="<?php bp_the_profile_field_input_name(); ?>" multiple="multiple" <?php if ( bp_get_the_profile_field_is_required() ) : ?>aria-required="true"<?php endif; ?>>
     752
     753                                                                                <?php bp_the_profile_field_options( array( 'user_id' => $r['user_id'], ) ); ?>
     754
     755                                                                        </select>
     756
     757
     758                                                                        <?php if ( !bp_get_the_profile_field_is_required() ) : ?>
     759
     760                                                                                <p><a class="clear-value" href="javascript:clear( '<?php bp_the_profile_field_input_name(); ?>' );"><?php _e( 'Clear', 'buddypress' ); ?></a></p>
     761
     762                                                                        <?php endif; ?>
     763                                                                        <p class="description"><?php bp_the_profile_field_description(); ?></p>
     764                                                                </td>
     765
     766                                                        <?php endif; ?>
     767
     768                                                        <?php if ( 'radio' === bp_get_the_profile_field_type() ) : ?>
     769
     770                                                                <th>
     771                                                                        <span class="label"><?php bp_the_profile_field_name(); ?> <?php if ( bp_get_the_profile_field_is_required() ) : ?><?php _e( '(required)', 'buddypress' ); ?><?php endif; ?></span>
     772                                                                </th>
     773                                                                <td class="admin-field-<?php bp_the_profile_field_type();?>">
     774                                                                        <fieldset>
     775                                                                                <legend class="screen-reader-text"><span><?php bp_the_profile_field_name(); ?></span></legend>
     776                                                                                <?php bp_the_profile_field_options( array( 'user_id' => $r['user_id'], ) ); ?>
     777                                                                        </fieldset>
     778
     779                                                                        <?php if ( !bp_get_the_profile_field_is_required() ) : ?>
     780
     781                                                                                <p><a class="clear-value" href="javascript:clear( '<?php bp_the_profile_field_input_name(); ?>' );"><?php _e( 'Clear', 'buddypress' ); ?></a></p>
     782
     783                                                                        <?php endif; ?>
     784                                                                        <p class="description"><?php bp_the_profile_field_description(); ?></p>
     785                                                                </td>
     786
     787                                                        <?php endif; ?>
     788
     789                                                        <?php if ( 'checkbox' === bp_get_the_profile_field_type() ) : ?>
     790
     791                                                                <th>
     792                                                                        <span class="label"><?php bp_the_profile_field_name(); ?> <?php if ( bp_get_the_profile_field_is_required() ) : ?><?php _e( '(required)', 'buddypress' ); ?><?php endif; ?></span>
     793                                                                </th>
     794                                                                <td class="admin-field-<?php bp_the_profile_field_type();?>">
     795                                                                        <?php bp_the_profile_field_options( array( 'user_id' => $r['user_id'], ) ); ?>
     796                                                                        <p class="description"><?php bp_the_profile_field_description(); ?></p>
     797                                                                </td>
     798
     799                                                        <?php endif; ?>
     800
     801                                                        <?php if ( 'datebox' === bp_get_the_profile_field_type() ) : ?>
     802
     803                                                                <th>
     804                                                                        <label for="<?php bp_the_profile_field_input_name(); ?>_day"><?php bp_the_profile_field_name(); ?> <?php if ( bp_get_the_profile_field_is_required() ) : ?><?php _e( '(required)', 'buddypress' ); ?><?php endif; ?></label>
     805                                                                </th>
     806                                                                <td class="admin-field-<?php bp_the_profile_field_type();?>">
     807                                                                        <select name="<?php bp_the_profile_field_input_name(); ?>_day" id="<?php bp_the_profile_field_input_name(); ?>_day" <?php if ( bp_get_the_profile_field_is_required() ) : ?>aria-required="true"<?php endif; ?>>
     808
     809                                                                                <?php bp_the_profile_field_options( array( 'user_id' => $r['user_id'], 'type' => 'day', ) ); ?>
     810
     811                                                                        </select>
     812
     813                                                                        <select name="<?php bp_the_profile_field_input_name(); ?>_month" id="<?php bp_the_profile_field_input_name(); ?>_month" <?php if ( bp_get_the_profile_field_is_required() ) : ?>aria-required="true"<?php endif; ?>>
     814
     815                                                                                <?php bp_the_profile_field_options( array( 'user_id' => $r['user_id'], 'type' => 'month', ) ); ?>
     816
     817                                                                        </select>
     818
     819                                                                        <select name="<?php bp_the_profile_field_input_name(); ?>_year" id="<?php bp_the_profile_field_input_name(); ?>_year" <?php if ( bp_get_the_profile_field_is_required() ) : ?>aria-required="true"<?php endif; ?>>
     820
     821                                                                                <?php bp_the_profile_field_options( array( 'user_id' => $r['user_id'], 'type' => 'year', ) ); ?>
     822
     823                                                                        </select>
     824                                                                        <p class="description"><?php bp_the_profile_field_description(); ?></p>
     825                                                                </td>
     826
     827                                                        <?php endif; ?>
     828
     829                                                </tr>
     830
     831                                                <tr class="admin-field-visibility-tr">
     832                                                        <td class="admin-field-visibility-td">&nbsp;</td>
     833                                                        <td class="admin-field-visibility-td">
     834
     835                                                                <?php do_action( 'bp_custom_profile_edit_fields_pre_visibility' ); ?>
     836
     837                                                                <?php if ( bp_current_user_can( 'bp_xprofile_change_field_visibility' ) ) : ?>
     838                                                                        <p class="description field-visibility-settings-toggle" id="field-visibility-settings-toggle-<?php bp_the_profile_field_id() ?>">
     839                                                                                <?php printf( __( 'This field can be seen by: <span class="current-visibility-level">%s</span>', 'buddypress' ), bp_get_the_profile_field_visibility_level_label() ) ?> <a href="#" class="visibility-toggle-link"><?php _e( 'Change', 'buddypress' ); ?></a>
     840                                                                        </p>
     841
     842                                                                        <div class="field-visibility-settings" id="field-visibility-settings-<?php bp_the_profile_field_id() ?>">
     843                                                                                <fieldset>
     844                                                                                        <legend><?php esc_html_e( 'Who can see this field?', 'buddypress' ) ?></legend>
     845
     846                                                                                        <?php bp_profile_visibility_radio_buttons() ?>
     847
     848                                                                                </fieldset>
     849                                                                                <a class="field-visibility-settings-close" href="#"><?php esc_html_e( 'Close', 'buddypress' ) ?></a>
     850                                                                        </div>
     851                                                                <?php else : ?>
     852                                                                        <div class="field-visibility-settings-notoggle" id="field-visibility-settings-toggle-<?php bp_the_profile_field_id() ?>">
     853                                                                                <?php printf( __( 'This field can be seen by: <span class="current-visibility-level">%s</span>', 'buddypress' ), bp_get_the_profile_field_visibility_level_label() ) ?>
     854                                                                        </div>
     855                                                                <?php endif ?>
     856
     857                                                        </td>
     858                                                </tr>
     859
     860                                        <?php endwhile; ?>
     861                                        </tbody>
     862
     863                                </table>
     864                                <input type="hidden" name="field_ids[]" id="field_ids_<?php bp_the_profile_group_slug(); ?>" value="<?php bp_the_profile_group_field_ids(); ?>" />
     865                        <?php endwhile;
     866                endif;
     867        }
     868
     869        /**
     870         * Render the fallback metabox in case a user has been marked as a spammer.
     871         *
     872         * @access public
     873         * @since BuddyPress (2.0.0)
     874         *
     875         * @param WP_User $user The WP_User object for the user being edited.
     876         */
     877        public function user_admin_spammer_metabox( $user = null ) {
     878                ?>
     879                <p><?php printf( __( '%s has been marked as a spammer, this user&#39;s BuddyPress datas were removed', 'buddypress' ), esc_html( bp_core_get_user_displayname( $user->ID ) ) ) ;?></p>
     880                <?php
     881        }
     882
     883        /**
     884         * Render the Avatar metabox to moderate inappropriate images.
     885         *
     886         * @access public
     887         * @since BuddyPress (2.0.0)
     888         *
     889         * @param WP_User $user The WP_User object for the user being edited.
     890         */
     891        public function user_admin_avatar_metabox( $user = null ) {
     892
     893                if ( empty( $user->ID ) ) {
     894                        return;
     895                }
     896
     897                $args = array(
     898                        'item_id' => $user->ID,
     899                        'object'  => 'user',
     900                        'type'    => 'full',
     901                        'title'   => $user->display_name
     902                );
     903
     904                ?>
     905
     906                <div class="avatar">
     907
     908                        <?php echo bp_core_fetch_avatar( $args ); ?>
     909
     910                        <?php if ( bp_get_user_has_avatar( $user->ID ) ) :
     911
     912                                $query_args = array(
     913                                        'user_id' => $user->ID,
     914                                        'action'  => 'delete_avatar'
     915                                );
     916
     917                                if ( ! empty( $_REQUEST['wp_http_referer'] ) )
     918                                        $query_args['wp_http_referer'] = urlencode( wp_unslash( $_REQUEST['wp_http_referer'] ) );
     919
     920                                        $community_url = add_query_arg( $query_args, buddypress()->members->admin->edit_profile_url );
     921                                        $delete_link   = wp_nonce_url( $community_url, 'delete_avatar' ); ?>
     922
     923                                <a href="<?php echo esc_url( $delete_link ); ?>" title="<?php esc_attr_e( 'Delete Avatar', 'buddypress' ); ?>" class="bp-xprofile-avatar-user-admin"><?php esc_html_e( 'Delete Avatar', 'buddypress' ); ?></a></li>
     924
     925                        <?php endif; ?>
     926
     927                </div>
     928                <?php
     929        }
     930
     931}
     932endif; // class_exists check
     933
     934// Load the xprofile user admin
     935add_action( 'bp_init', array( 'BP_XProfile_User_Admin', 'register_xprofile_user_admin' ), 11 );
  • bp-xprofile/bp-xprofile-filters.php

     
    247247function bp_xprofile_filter_user_query_populate_extras( BP_User_Query $user_query, $user_ids_sql ) {
    248248        global $bp, $wpdb;
    249249
    250         if ( bp_is_active( 'xprofile' ) ) {
    251                 $fullname_field_id = $wpdb->get_var( $wpdb->prepare( "SELECT id FROM {$bp->profile->table_name_fields} WHERE name = %s", bp_xprofile_fullname_field_name() ) );
    252                 $user_id_names     = $wpdb->get_results( $wpdb->prepare( "SELECT user_id, value as fullname FROM {$bp->profile->table_name_data} WHERE user_id IN ({$user_ids_sql}) AND field_id = %d", $fullname_field_id ) );
     250        if ( ! bp_is_active( 'xprofile' ) ) {
     251                return;
     252        }
    253253
    254                 // Loop through names and override each user's fullname
    255                 foreach ( $user_id_names as $user ) {
    256                         if ( isset( $user_query->results[ $user->user_id ] ) ) {
    257                                 $user_query->results[ $user->user_id ]->fullname = $user->fullname;
    258                         }
     254        $fullname_field_id = $wpdb->get_var( $wpdb->prepare( "SELECT id FROM {$bp->profile->table_name_fields} WHERE name = %s", bp_xprofile_fullname_field_name() ) );
     255        $user_id_names     = $wpdb->get_results( $wpdb->prepare( "SELECT user_id, value as fullname FROM {$bp->profile->table_name_data} WHERE user_id IN ({$user_ids_sql}) AND field_id = %d", $fullname_field_id ) );
     256
     257        // Loop through names and override each user's fullname
     258        foreach ( $user_id_names as $user ) {
     259                if ( isset( $user_query->results[ $user->user_id ] ) ) {
     260                        $user_query->results[ $user->user_id ]->fullname = $user->fullname;
    259261                }
    260262        }
    261263}
  • bp-xprofile/bp-xprofile-template.php

     
    5151        function next_group() {
    5252                $this->current_group++;
    5353
    54                 $this->group         = $this->groups[$this->current_group];
    55                 $this->group->fields = apply_filters( 'xprofile_group_fields', $this->group->fields, $this->group->id );
    56                 $this->field_count   = count( $this->group->fields );
     54                $this->group       = $this->groups[$this->current_group];
     55                $this->field_count = 0;
    5756
     57                if( ! empty( $this->group->fields ) ) {
     58                        $this->group->fields = apply_filters( 'xprofile_group_fields', $this->group->fields, $this->group->id );
     59                        $this->field_count   = count( $this->group->fields );
     60                }
     61
    5862                return $this->group;
    5963        }
    6064