| 1 | <?php
|
|---|
| 2 |
|
|---|
| 3 | if ( !defined( 'BP_SETTINGS_SLUG' ) )
|
|---|
| 4 | define( 'BP_SETTINGS_SLUG', 'settings' );
|
|---|
| 5 |
|
|---|
| 6 | function bp_core_add_settings_nav() {
|
|---|
| 7 | global $bp;
|
|---|
| 8 |
|
|---|
| 9 | /* Set up settings as a sudo-component for identification and nav selection */
|
|---|
| 10 | $bp->settings->id = 'settings';
|
|---|
| 11 | $bp->settings->slug = BP_SETTINGS_SLUG;
|
|---|
| 12 |
|
|---|
| 13 | /* Register this in the active components array */
|
|---|
| 14 | $bp->active_components[$bp->settings->slug] = $bp->settings->id;
|
|---|
| 15 |
|
|---|
| 16 | /* 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() ) );
|
|---|
| 23 |
|
|---|
| 24 | if ( !is_super_admin() && !(int) $bp->site_options['bp-disable-account-deletion'] )
|
|---|
| 25 | bp_core_new_subnav_item( array( 'name' => __( 'Delete Account', 'buddypress' ), 'slug' => 'delete-account', 'parent_url' => $settings_link, 'parent_slug' => $bp->settings->slug, 'screen_function' => 'bp_core_screen_delete_account', 'position' => 90, 'user_has_access' => bp_is_my_profile() ) );
|
|---|
| 26 | }
|
|---|
| 27 | add_action( 'bp_setup_nav', 'bp_core_add_settings_nav' );
|
|---|
| 28 |
|
|---|
| 29 | /**** GENERAL SETTINGS ****/
|
|---|
| 30 |
|
|---|
| 31 | function bp_core_screen_general_settings() {
|
|---|
| 32 | global $current_user, $bp_settings_updated, $pass_error;
|
|---|
| 33 |
|
|---|
| 34 | $bp_settings_updated = false;
|
|---|
| 35 | $pass_error = false;
|
|---|
| 36 |
|
|---|
| 37 | if ( isset($_POST['submit']) ) {
|
|---|
| 38 | check_admin_referer('bp_settings_general');
|
|---|
| 39 |
|
|---|
| 40 | require_once( ABSPATH . WPINC . '/registration.php' );
|
|---|
| 41 |
|
|---|
| 42 | // Form has been submitted and nonce checks out, lets do it.
|
|---|
| 43 |
|
|---|
| 44 | if ( $_POST['email'] != '' )
|
|---|
| 45 | $current_user->user_email = wp_specialchars( trim( $_POST['email'] ) );
|
|---|
| 46 |
|
|---|
| 47 | if ( $_POST['pass1'] != '' && $_POST['pass2'] != '' ) {
|
|---|
| 48 | if ( $_POST['pass1'] == $_POST['pass2'] && !strpos( " " . $_POST['pass1'], "\\" ) )
|
|---|
| 49 | $current_user->user_pass = $_POST['pass1'];
|
|---|
| 50 | else
|
|---|
| 51 | $pass_error = true;
|
|---|
| 52 | } else if ( empty( $_POST['pass1'] ) && !empty( $_POST['pass2'] ) || !empty( $_POST['pass1'] ) && empty( $_POST['pass2'] ) ) {
|
|---|
| 53 | $pass_error = true;
|
|---|
| 54 | } else {
|
|---|
| 55 | unset( $current_user->user_pass );
|
|---|
| 56 | }
|
|---|
| 57 |
|
|---|
| 58 | if ( !$pass_error && wp_update_user( get_object_vars( $current_user ) ) )
|
|---|
| 59 | $bp_settings_updated = true;
|
|---|
| 60 | }
|
|---|
| 61 |
|
|---|
| 62 | add_action( 'bp_template_title', 'bp_core_screen_general_settings_title' );
|
|---|
| 63 | add_action( 'bp_template_content', 'bp_core_screen_general_settings_content' );
|
|---|
| 64 |
|
|---|
| 65 | bp_core_load_template( apply_filters( 'bp_core_template_plugin', 'members/single/plugins' ) );
|
|---|
| 66 | }
|
|---|
| 67 |
|
|---|
| 68 | function bp_core_screen_general_settings_title() {
|
|---|
| 69 | _e( 'General Settings', 'buddypress' );
|
|---|
| 70 | }
|
|---|
| 71 |
|
|---|
| 72 | function bp_core_screen_general_settings_content() {
|
|---|
| 73 | global $bp, $current_user, $bp_settings_updated, $pass_error; ?>
|
|---|
| 74 |
|
|---|
| 75 | <?php if ( $bp_settings_updated && !$pass_error ) { ?>
|
|---|
| 76 | <div id="message" class="updated fade">
|
|---|
| 77 | <p><?php _e( 'Changes Saved.', 'buddypress' ) ?></p>
|
|---|
| 78 | </div>
|
|---|
| 79 | <?php } ?>
|
|---|
| 80 |
|
|---|
| 81 | <?php if ( $pass_error && !$bp_settings_updated ) { ?>
|
|---|
| 82 | <div id="message" class="error fade">
|
|---|
| 83 | <p><?php _e( 'Your passwords did not match', 'buddypress' ) ?></p>
|
|---|
| 84 | </div>
|
|---|
| 85 | <?php } ?>
|
|---|
| 86 |
|
|---|
| 87 | <form action="<?php echo $bp->loggedin_user->domain . BP_SETTINGS_SLUG . '/general' ?>" method="post" class="standard-form" id="settings-form">
|
|---|
| 88 | <label for="email"><?php _e( 'Account Email', 'buddypress' ) ?></label>
|
|---|
| 89 | <input type="text" name="email" id="email" value="<?php echo esc_attr( $current_user->user_email ); ?>" class="settings-input" />
|
|---|
| 90 |
|
|---|
| 91 | <label for="pass1"><?php _e( 'Change Password <span>(leave blank for no change)</span>', 'buddypress' ) ?></label>
|
|---|
| 92 | <input type="password" name="pass1" id="pass1" size="16" value="" class="settings-input small" /> <?php _e( 'New Password', 'buddypress' ) ?><br />
|
|---|
| 93 | <input type="password" name="pass2" id="pass2" size="16" value="" class="settings-input small" /> <?php _e( 'Repeat New Password', 'buddypress' ) ?>
|
|---|
| 94 |
|
|---|
| 95 | <div class="submit">
|
|---|
| 96 | <input type="submit" name="submit" value="<?php _e( 'Save Changes', 'buddypress' ) ?>" id="submit" class="auto" />
|
|---|
| 97 | </div>
|
|---|
| 98 |
|
|---|
| 99 | <?php wp_nonce_field('bp_settings_general') ?>
|
|---|
| 100 | </form>
|
|---|
| 101 | <?php
|
|---|
| 102 | }
|
|---|
| 103 |
|
|---|
| 104 | /***** NOTIFICATION SETTINGS ******/
|
|---|
| 105 |
|
|---|
| 106 | function bp_core_screen_notification_settings() {
|
|---|
| 107 | global $current_user, $bp_settings_updated;
|
|---|
| 108 |
|
|---|
| 109 | $bp_settings_updated = false;
|
|---|
| 110 |
|
|---|
| 111 | if ( $_POST['submit'] ) {
|
|---|
| 112 | check_admin_referer('bp_settings_notifications');
|
|---|
| 113 |
|
|---|
| 114 | if ( $_POST['notifications'] ) {
|
|---|
| 115 | foreach ( (array)$_POST['notifications'] as $key => $value ) {
|
|---|
| 116 | update_user_meta( (int)$current_user->id, $key, $value );
|
|---|
| 117 | }
|
|---|
| 118 | }
|
|---|
| 119 |
|
|---|
| 120 | $bp_settings_updated = true;
|
|---|
| 121 | }
|
|---|
| 122 |
|
|---|
| 123 | add_action( 'bp_template_title', 'bp_core_screen_notification_settings_title' );
|
|---|
| 124 | add_action( 'bp_template_content', 'bp_core_screen_notification_settings_content' );
|
|---|
| 125 |
|
|---|
| 126 | bp_core_load_template( apply_filters( 'bp_core_template_plugin', 'members/single/plugins' ) );
|
|---|
| 127 | }
|
|---|
| 128 |
|
|---|
| 129 | function bp_core_screen_notification_settings_title() {
|
|---|
| 130 | _e( 'Notification Settings', 'buddypress' );
|
|---|
| 131 | }
|
|---|
| 132 |
|
|---|
| 133 | function bp_core_screen_notification_settings_content() {
|
|---|
| 134 | global $bp, $current_user, $bp_settings_updated; ?>
|
|---|
| 135 |
|
|---|
| 136 | <?php if ( $bp_settings_updated ) { ?>
|
|---|
| 137 | <div id="message" class="updated fade">
|
|---|
| 138 | <p><?php _e( 'Changes Saved.', 'buddypress' ) ?></p>
|
|---|
| 139 | </div>
|
|---|
| 140 | <?php } ?>
|
|---|
| 141 |
|
|---|
| 142 | <form action="<?php echo $bp->loggedin_user->domain . BP_SETTINGS_SLUG . '/notifications' ?>" method="post" id="settings-form">
|
|---|
| 143 | <h3><?php _e( 'Email Notifications', 'buddypress' ) ?></h3>
|
|---|
| 144 | <p><?php _e( 'Send a notification by email when:', 'buddypress' ) ?></p>
|
|---|
| 145 |
|
|---|
| 146 | <?php do_action( 'bp_notification_settings' ) ?>
|
|---|
| 147 |
|
|---|
| 148 | <div class="submit">
|
|---|
| 149 | <input type="submit" name="submit" value="<?php _e( 'Save Changes', 'buddypress' ) ?>" id="submit" class="auto" />
|
|---|
| 150 | </div>
|
|---|
| 151 |
|
|---|
| 152 | <?php wp_nonce_field('bp_settings_notifications') ?>
|
|---|
| 153 |
|
|---|
| 154 | </form>
|
|---|
| 155 | <?php
|
|---|
| 156 | }
|
|---|
| 157 |
|
|---|
| 158 | /**** DELETE ACCOUNT ****/
|
|---|
| 159 |
|
|---|
| 160 | function bp_core_screen_delete_account() {
|
|---|
| 161 | if ( isset( $_POST['delete-account-understand'] ) ) {
|
|---|
| 162 | check_admin_referer( 'delete-account' );
|
|---|
| 163 |
|
|---|
| 164 | // delete the users account
|
|---|
| 165 | if ( bp_core_delete_account() )
|
|---|
| 166 | bp_core_redirect( site_url() );
|
|---|
| 167 | }
|
|---|
| 168 |
|
|---|
| 169 | add_action( 'bp_template_title', 'bp_core_screen_delete_account_title' );
|
|---|
| 170 | add_action( 'bp_template_content', 'bp_core_screen_delete_account_content' );
|
|---|
| 171 |
|
|---|
| 172 | bp_core_load_template( apply_filters( 'bp_core_template_plugin', 'members/single/plugins' ) );
|
|---|
| 173 | }
|
|---|
| 174 |
|
|---|
| 175 | function bp_core_screen_delete_account_title() {
|
|---|
| 176 | _e( 'Delete Account', 'buddypress' );
|
|---|
| 177 | }
|
|---|
| 178 |
|
|---|
| 179 | function bp_core_screen_delete_account_content() {
|
|---|
| 180 | global $bp, $current_user, $bp_settings_updated, $pass_error; ?>
|
|---|
| 181 |
|
|---|
| 182 | <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">
|
|---|
| 183 |
|
|---|
| 184 | <div id="message" class="info">
|
|---|
| 185 | <p><?php _e( 'WARNING: Deleting your account will completely remove ALL content associated with it. There is no way back, please be careful with this option.', 'buddypress' ); ?></p>
|
|---|
| 186 | </div>
|
|---|
| 187 |
|
|---|
| 188 | <input type="checkbox" name="delete-account-understand" id="delete-account-understand" value="1" onclick="if(this.checked) { document.getElementById('delete-account-button').disabled = ''; } else { document.getElementById('delete-account-button').disabled = 'disabled'; }" /> <?php _e( 'I understand the consequences of deleting my account.', 'buddypress' ); ?>
|
|---|
| 189 |
|
|---|
| 190 | <div class="submit">
|
|---|
| 191 | <input type="submit" disabled="disabled" value="<?php _e( 'Delete My Account', 'buddypress' ) ?> →" id="delete-account-button" name="delete-account-button" />
|
|---|
| 192 | </div>
|
|---|
| 193 |
|
|---|
| 194 | <?php wp_nonce_field('delete-account') ?>
|
|---|
| 195 | </form>
|
|---|
| 196 | <?php
|
|---|
| 197 | }
|
|---|