Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
12/30/2010 08:30:39 PM (14 years ago)
Author:
boonebgorges
Message:

Allows super admins to edit user settings. Fixes #965. Props johnjamesjacoby and sorich87 for initial patches.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-core/bp-core-settings.php

    r3592 r3620  
    1515
    1616    /* Add the settings navigation item */
    17     bp_core_new_nav_item( array( 'name' => __('Settings', 'buddypress'), 'slug' => $bp->settings->slug, 'position' => 100, 'show_for_displayed_user' => false, 'screen_function' => 'bp_core_screen_general_settings', 'default_subnav_slug' => 'general' ) );
    18 
    19     $settings_link = $bp->loggedin_user->domain . $bp->settings->slug . '/';
    20 
    21     bp_core_new_subnav_item( array( 'name' => __( 'General', 'buddypress' ), 'slug' => 'general', 'parent_url' => $settings_link, 'parent_slug' => $bp->settings->slug, 'screen_function' => 'bp_core_screen_general_settings', 'position' => 10, 'user_has_access' => bp_is_my_profile() ) );
    22     bp_core_new_subnav_item( array( 'name' => __( 'Notifications', 'buddypress' ), 'slug' => 'notifications', 'parent_url' => $settings_link, 'parent_slug' => $bp->settings->slug, 'screen_function' => 'bp_core_screen_notification_settings', 'position' => 20, 'user_has_access' => bp_is_my_profile() ) );
     17    bp_core_new_nav_item( array( 'name' => __('Settings', 'buddypress'), 'slug' => $bp->settings->slug, 'position' => 100, 'show_for_displayed_user' => bp_core_can_edit_settings(), 'screen_function' => 'bp_core_screen_general_settings', 'default_subnav_slug' => 'general' ) );
     18
     19    $settings_link = $bp->displayed_user->domain . $bp->settings->slug . '/';
     20
     21    bp_core_new_subnav_item( array( 'name' => __( 'General', 'buddypress' ), 'slug' => 'general', 'parent_url' => $settings_link, 'parent_slug' => $bp->settings->slug, 'screen_function' => 'bp_core_screen_general_settings', 'position' => 10, 'user_has_access' => bp_core_can_edit_settings() ) );
     22    bp_core_new_subnav_item( array( 'name' => __( 'Notifications', 'buddypress' ), 'slug' => 'notifications', 'parent_url' => $settings_link, 'parent_slug' => $bp->settings->slug, 'screen_function' => 'bp_core_screen_notification_settings', 'position' => 20, 'user_has_access' => bp_core_can_edit_settings() ) );
    2323
    2424    if ( !is_super_admin() && empty( $bp->site_options['bp-disable-account-deletion'] ) )
     
    2929add_action( 'bp_setup_nav', 'bp_core_add_settings_nav' );
    3030
     31function bp_core_can_edit_settings() {
     32    if ( bp_is_my_profile() )
     33        return true;
     34   
     35    if ( is_super_admin() )
     36        return true;
     37   
     38    return false;
     39}
     40
    3141/**** GENERAL SETTINGS ****/
    3242
    3343function bp_core_screen_general_settings() {
    34     global $current_user, $bp_settings_updated, $pass_error, $email_error, $pwd_error;
     44    global $bp, $current_user, $bp_settings_updated, $pass_error, $email_error, $pwd_error;
    3545
    3646    $bp_settings_updated = false;
     
    4757
    4858        // Validate the user again for the current password when making a big change
    49         if ( !empty( $_POST['pwd'] ) && $_POST['pwd'] != '' && wp_check_password($_POST['pwd'], $current_user->user_pass, $current_user->ID) ) {
     59        if ( is_super_admin() || ( !empty( $_POST['pwd'] ) && $_POST['pwd'] != '' && wp_check_password($_POST['pwd'], $current_user->user_pass, $current_user->ID ) ) ) {
     60       
     61            $update_user = get_userdata( $bp->displayed_user->id );
    5062
    5163            // Make sure changing an email address does not already exist
     
    5365
    5466                // What is missing from the profile page vs signup - lets double check the goodies
    55                 $user_email = sanitize_email( wp_specialchars( trim( $_POST['email'] ) ) );
     67                $user_email = sanitize_email( esc_html( trim( $_POST['email'] ) ) );
    5668
    5769                if ( !is_email( $user_email ) )
     
    6577                    if ( in_array( $emaildomain, (array)$limited_email_domains ) == false ) {
    6678                        $email_error = true;
    67 
    6879                    }
    6980                }
    7081
    71                 if ( !$email_error && $current_user->user_email != $user_email  ) {
     82                if ( !$email_error && $bp->displayed_user->userdata->user_email != $user_email  ) {
    7283
    7384                    //we don't want email dups in the system
     
    7586                        $email_error = true;
    7687
    77                     if (!$email_error)
    78                         $current_user->user_email = $user_email;
     88                    if ( !$email_error )
     89                        $update_user->user_email = $user_email;
    7990                }
    8091            }
     
    8293            if ( $_POST['pass1'] != '' && $_POST['pass2'] != '' ) {
    8394
    84                 if ( $_POST['pass1'] == $_POST['pass2'] && !strpos( " " . $_POST['pass1'], "\\" ) )
    85                     $current_user->user_pass = $_POST['pass1'];
    86                 else
     95                if ( $_POST['pass1'] == $_POST['pass2'] && !strpos( " " . $_POST['pass1'], "\\" ) ) {
     96                    $update_user->user_pass = $_POST['pass1'];
     97                } else {
    8798                    $pass_error = true;
     99                }
    88100
    89101            } else if ( empty( $_POST['pass1'] ) && !empty( $_POST['pass2'] ) || !empty( $_POST['pass1'] ) && empty( $_POST['pass2'] ) ) {
    90102                $pass_error = true;
    91103            } else {
    92                 unset( $current_user->user_pass );
     104                unset( $update_user->user_pass );
    93105            }
    94106
    95             if ( !$email_error && !$pass_error && wp_update_user( get_object_vars( $current_user ) ) )
     107            if ( !$email_error && !$pass_error && wp_update_user( get_object_vars( $update_user ) ) ) {
     108                // Make sure these changes are in $bp for the current page load
     109                $bp->displayed_user->userdata = bp_core_get_core_userdata( $bp->displayed_user->id );
    96110                $bp_settings_updated = true;
     111            }
    97112
    98113        } else {
     
    114129
    115130function bp_core_screen_general_settings_content() {
    116     global $bp, $current_user, $bp_settings_updated, $pass_error, $pwd_error, $email_error; ?>
     131    global $bp, $bp_settings_updated, $pass_error, $pwd_error, $email_error; ?>
    117132
    118133    <?php if ( $bp_settings_updated && !$pass_error ) { ?>
     
    142157
    143158
    144     <form action="<?php echo $bp->loggedin_user->domain . BP_SETTINGS_SLUG . '/general' ?>" method="post" class="standard-form" id="settings-form">
    145 
    146         <label for="pwd"><?php _e( 'Current Password <span>(required to update email or change current password)</span>', 'buddypress' ) ?></label>
    147         <input type="password" name="pwd" id="pwd" size="16" value="" class="settings-input small" /> &nbsp;<a href="<?php echo site_url('wp-login.php?action=lostpassword', 'login') ?>" title="<?php _e('Password Lost and Found') ?>"><?php _e('Lost your password?') ?></a>
     159    <form action="<?php echo $bp->displayed_user->domain . BP_SETTINGS_SLUG . '/general' ?>" method="post" class="standard-form" id="settings-form">
     160
     161        <?php if ( empty( $bp->loggedin_user->is_super_admin ) ) : ?>
     162            <label for="pwd"><?php _e( 'Current Password <span>(required to update email or change current password)</span>', 'buddypress' ) ?></label>
     163            <input type="password" name="pwd" id="pwd" size="16" value="" class="settings-input small" /> &nbsp;<a href="<?php echo site_url('wp-login.php?action=lostpassword', 'login') ?>" title="<?php _e('Password Lost and Found') ?>"><?php _e('Lost your password?') ?></a>
     164        <?php endif ?>
    148165
    149166        <label for="email"><?php _e( 'Account Email', 'buddypress' ) ?></label>
    150         <input type="text" name="email" id="email" value="<?php echo esc_attr( $current_user->user_email ); ?>" class="settings-input" />
     167        <input type="text" name="email" id="email" value="<?php echo esc_attr( $bp->displayed_user->userdata->user_email ); ?>" class="settings-input" />
    151168
    152169        <label for="pass1"><?php _e( 'Change Password <span>(leave blank for no change)</span>', 'buddypress' ) ?></label>
     
    170187
    171188function bp_core_screen_notification_settings() {
    172     global $current_user, $bp_settings_updated;
     189    global $bp, $bp_settings_updated;
    173190
    174191    $bp_settings_updated = false;
     
    179196        if ( isset( $_POST['notifications'] ) ) {
    180197            foreach ( (array)$_POST['notifications'] as $key => $value ) {
    181                 update_user_meta( (int)$current_user->id, $key, $value );
     198                update_user_meta( (int)$bp->displayed_user->id, $key, $value );
    182199            }
    183200        }
     
    199216
    200217function bp_core_screen_notification_settings_content() {
    201     global $bp, $current_user, $bp_settings_updated; ?>
     218    global $bp, $bp_settings_updated; ?>
    202219
    203220    <?php if ( $bp_settings_updated ) { ?>
     
    207224    <?php } ?>
    208225
    209     <form action="<?php echo $bp->loggedin_user->domain . BP_SETTINGS_SLUG . '/notifications' ?>" method="post" id="settings-form">
     226    <form action="<?php echo $bp->displayed_user->domain . BP_SETTINGS_SLUG . '/notifications' ?>" method="post" id="settings-form">
    210227        <p><?php _e( 'Send a notification by email when:', 'buddypress' ) ?></p>
    211228
     
    227244
    228245function bp_core_screen_delete_account() {
     246    global $bp;
     247   
    229248    if ( isset( $_POST['delete-account-understand'] ) ) {
    230249        check_admin_referer( 'delete-account' );
    231250
    232251        // delete the users account
    233         if ( bp_core_delete_account() )
     252        if ( bp_core_delete_account( $bp->displayed_user->id ) )
    234253            bp_core_redirect( site_url() );
    235254    }
     
    246265
    247266function bp_core_screen_delete_account_content() {
    248     global $bp, $current_user, $bp_settings_updated, $pass_error;   ?>
    249 
    250     <form action="<?php echo $bp->loggedin_user->domain .  BP_SETTINGS_SLUG . '/delete-account'; ?>" name="account-delete-form" id="account-delete-form" class="standard-form" method="post">
     267    global $bp, $bp_settings_updated, $pass_error;  ?>
     268
     269    <form action="<?php echo $bp->displayed_user->domain .  BP_SETTINGS_SLUG . '/delete-account'; ?>" name="account-delete-form" id="account-delete-form" class="standard-form" method="post">
    251270
    252271        <div id="message" class="info">
Note: See TracChangeset for help on using the changeset viewer.