Changeset 1718 for trunk/bp-core/bp-core-settings.php
- Timestamp:
- 08/27/2009 09:18:10 PM (16 years ago)
- File:
-
- 1 edited
-
trunk/bp-core/bp-core-settings.php (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/bp-core/bp-core-settings.php
r1687 r1718 1 1 <?php 2 3 if ( !defined( 'BP_SETTINGS_SLUG' ) ) 4 define( 'BP_SETTINGS_SLUG', 'settings' ); 5 2 6 function bp_core_add_settings_nav() { 3 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; 4 15 5 16 /* Add the settings navigation item */ 6 bp_core_new_nav_item( array( 'name' => __('Settings', 'buddypress'), 'slug' => 'settings', 'position' => 100, 'show_for_displayed_user' => false, 'screen_function' => 'bp_core_screen_general_settings', 'default_subnav_slug' => 'general' ) );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' ) ); 7 18 8 19 $settings_link = $bp->loggedin_user->domain . 'settings/'; 9 20 10 bp_core_new_subnav_item( array( 'name' => __( 'General', 'buddypress' ), 'slug' => 'general', 'parent_url' => $settings_link, 'parent_slug' => 'settings', 'screen_function' => 'bp_core_screen_general_settings', 'position' => 10, 'user_has_access' => bp_is_home() ) );11 bp_core_new_subnav_item( array( 'name' => __( 'Notifications', 'buddypress' ), 'slug' => 'notifications', 'parent_url' => $settings_link, 'parent_slug' => 'settings', 'screen_function' => 'bp_core_screen_notification_settings', 'position' => 20, 'user_has_access' => bp_is_home() ) );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_home() ) ); 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_home() ) ); 12 23 13 24 if ( !is_site_admin() ) 14 bp_core_new_subnav_item( array( 'name' => __( 'Delete Account', 'buddypress' ), 'slug' => 'delete-account', 'parent_url' => $settings_link, 'parent_slug' => 'settings', 'screen_function' => 'bp_core_screen_delete_account', 'position' => 90, 'user_has_access' => bp_is_home() ) );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_home() ) ); 15 26 } 16 27 add_action( 'wp', 'bp_core_add_settings_nav', 2 ); … … 21 32 function bp_core_screen_general_settings() { 22 33 global $current_user, $bp_settings_updated, $pass_error; 34 35 $bp_settings_updated = false; 36 $pass_error = false; 37 38 if ( isset($_POST['submit']) && check_admin_referer('bp_settings_general') ) { 39 require_once( WPINC . '/registration.php' ); 40 41 // Form has been submitted and nonce checks out, lets do it. 42 43 if ( $_POST['email'] != '' ) 44 $current_user->user_email = wp_specialchars( trim( $_POST['email'] ) ); 45 46 if ( $_POST['pass1'] != '' && $_POST['pass2'] != '' ) { 47 if ( $_POST['pass1'] == $_POST['pass2'] && !strpos( " " . $_POST['pass1'], "\\" ) ) 48 $current_user->user_pass = $_POST['pass1']; 49 else 50 $pass_error = true; 51 } else if ( empty( $_POST['pass1'] ) && !empty( $_POST['pass2'] ) || !empty( $_POST['pass1'] ) && empty( $_POST['pass2'] ) ) { 52 $pass_error = true; 53 } else { 54 unset( $current_user->user_pass ); 55 } 56 57 if ( !$pass_error && wp_update_user( get_object_vars( $current_user ) ) ) 58 $bp_settings_updated = true; 59 } 60 61 add_action( 'bp_template_title', 'bp_core_screen_general_settings_title' ); 62 add_action( 'bp_template_content', 'bp_core_screen_general_settings_content' ); 63 64 bp_core_load_template( apply_filters( 'bp_core_template_plugin', 'plugin-template' ) ); 65 } 66 67 function bp_core_screen_general_settings_title() { 68 _e( 'General Settings', 'buddypress' ); 69 } 70 71 function bp_core_screen_general_settings_content() { 72 global $bp, $current_user, $bp_settings_updated, $pass_error; ?> 73 74 <?php if ( $bp_settings_updated && !$pass_error ) { ?> 75 <div id="message" class="updated fade"> 76 <p><?php _e( 'Changes Saved.', 'buddypress' ) ?></p> 77 </div> 78 <?php } ?> 79 80 <?php if ( $pass_error && !$bp_settings_updated ) { ?> 81 <div id="message" class="error fade"> 82 <p><?php _e( 'Your passwords did not match', 'buddypress' ) ?></p> 83 </div> 84 <?php } ?> 85 86 <form action="<?php echo $bp->loggedin_user->domain . 'settings/general' ?>" method="post" class="standard-form" id="settings-form"> 87 <label for="email"><?php _e( 'Account Email', 'buddypress' ) ?></label> 88 <input type="text" name="email" id="email" value="<?php echo attribute_escape( $current_user->user_email ); ?>" class="settings-input" /> 89 90 <label for="pass1"><?php _e( 'Change Password <span>(leave blank for no change)</span>', 'buddypress' ) ?></label> 91 <input type="password" name="pass1" id="pass1" size="16" value="" class="settings-input small" /> <?php _e( 'New Password', 'buddypress' ) ?> 92 <input type="password" name="pass2" id="pass2" size="16" value="" class="settings-input small" /> <?php _e( 'Repeat New Password', 'buddypress' ) ?> 93 94 <p class="submit"><input type="submit" name="submit" value="<?php _e( 'Save Changes', 'buddypress' ) ?>" id="submit" class="auto"/></p> 95 <?php wp_nonce_field('bp_settings_general') ?> 96 </form> 97 <?php 98 } 99 100 /***** NOTIFICATION SETTINGS ******/ 101 102 function bp_core_screen_notification_settings() { 103 global $current_user, $bp_settings_updated; 104 105 $bp_settings_updated = false; 106 107 if ( $_POST['submit'] && check_admin_referer('bp_settings_notifications') ) { 108 if ( $_POST['notifications'] ) { 109 foreach ( $_POST['notifications'] as $key => $value ) { 110 update_usermeta( (int)$current_user->id, $key, $value ); 111 } 112 } 113 114 $bp_settings_updated = true; 115 } 116 117 add_action( 'bp_template_title', 'bp_core_screen_notification_settings_title' ); 118 add_action( 'bp_template_content', 'bp_core_screen_notification_settings_content' ); 119 120 bp_core_load_template( apply_filters( 'bp_core_template_plugin', 'plugin-template' ) ); 121 } 122 123 function bp_core_screen_notification_settings_title() { 124 _e( 'Notification Settings', 'buddypress' ); 125 } 126 127 function bp_core_screen_notification_settings_content() { 128 global $bp, $current_user, $bp_settings_updated; ?> 129 130 <?php if ( $bp_settings_updated ) { ?> 131 <div id="message" class="updated fade"> 132 <p><?php _e( 'Changes Saved.', 'buddypress' ) ?></p> 133 </div> 134 <?php } ?> 135 136 <form action="<?php echo $bp->loggedin_user->domain . 'settings/notifications' ?>" method="post" id="settings-form"> 137 <h3><?php _e( 'Email Notifications', 'buddypress' ) ?></h3> 138 <p><?php _e( 'Send a notification by email when:', 'buddypress' ) ?></p> 139 140 <?php do_action( 'bp_notification_settings' ) ?> 141 142 <p class="submit"><input type="submit" name="submit" value="<?php _e( 'Save Changes', 'buddypress' ) ?>" id="submit" class="auto"/></p> 143 144 <?php wp_nonce_field('bp_settings_notifications') ?> 145 146 </form> 147 <?php 148 } 149 150 /**** DELETE ACCOUNT ****/ 151 152 function bp_core_screen_delete_account() { 153 global $current_user, $bp_settings_updated, $pass_error; 154 155 if ( isset( $_POST['delete-account-button'] ) && check_admin_referer('delete-account') ) { 156 if ( !check_admin_referer( 'delete-account' ) ) 157 return false; 158 159 // delete the users account 160 if ( bp_core_delete_account() ) 161 bp_core_redirect( site_url() ); 162 } 23 163 24 164 $bp_settings_updated = false; … … 50 190 } 51 191 52 add_action( 'bp_template_title', 'bp_core_screen_general_settings_title' );53 add_action( 'bp_template_content', 'bp_core_screen_general_settings_content' );54 55 bp_core_load_template( apply_filters( 'bp_core_template_plugin', 'plugin-template' ) );56 }57 58 function bp_core_screen_general_settings_title() {59 _e( 'General Settings', 'buddypress' );60 }61 62 function bp_core_screen_general_settings_content() {63 global $bp, $current_user, $bp_settings_updated, $pass_error; ?>64 65 <?php if ( $bp_settings_updated && !$pass_error ) { ?>66 <div id="message" class="updated fade">67 <p><?php _e( 'Changes Saved.', 'buddypress' ) ?></p>68 </div>69 <?php } ?>70 71 <?php if ( $pass_error && !$bp_settings_updated ) { ?>72 <div id="message" class="error fade">73 <p><?php _e( 'Your passwords did not match', 'buddypress' ) ?></p>74 </div>75 <?php } ?>76 77 <form action="<?php echo $bp->loggedin_user->domain . 'settings/general' ?>" method="post" class="standard-form" id="settings-form">78 <label for="email"><?php _e( 'Account Email', 'buddypress' ) ?></label>79 <input type="text" name="email" id="email" value="<?php echo attribute_escape( $current_user->user_email ); ?>" class="settings-input" />80 81 <label for="pass1"><?php _e( 'Change Password <span>(leave blank for no change)</span>', 'buddypress' ) ?></label>82 <input type="password" name="pass1" id="pass1" size="16" value="" class="settings-input small" /> <?php _e( 'New Password', 'buddypress' ) ?>83 <input type="password" name="pass2" id="pass2" size="16" value="" class="settings-input small" /> <?php _e( 'Repeat New Password', 'buddypress' ) ?>84 85 <p class="submit"><input type="submit" name="submit" value="<?php _e( 'Save Changes', 'buddypress' ) ?>" id="submit" class="auto"/></p>86 <?php wp_nonce_field('bp_settings_general') ?>87 </form>88 <?php89 }90 91 /***** NOTIFICATION SETTINGS ******/92 93 function bp_core_screen_notification_settings() {94 global $current_user, $bp_settings_updated;95 96 $bp_settings_updated = false;97 98 if ( $_POST['submit'] && check_admin_referer('bp_settings_notifications') ) {99 if ( $_POST['notifications'] ) {100 foreach ( $_POST['notifications'] as $key => $value ) {101 update_usermeta( (int)$current_user->id, $key, $value );102 }103 }104 105 $bp_settings_updated = true;106 }107 108 add_action( 'bp_template_title', 'bp_core_screen_notification_settings_title' );109 add_action( 'bp_template_content', 'bp_core_screen_notification_settings_content' );110 111 bp_core_load_template( apply_filters( 'bp_core_template_plugin', 'plugin-template' ) );112 }113 114 function bp_core_screen_notification_settings_title() {115 _e( 'Notification Settings', 'buddypress' );116 }117 118 function bp_core_screen_notification_settings_content() {119 global $bp, $current_user, $bp_settings_updated; ?>120 121 <?php if ( $bp_settings_updated ) { ?>122 <div id="message" class="updated fade">123 <p><?php _e( 'Changes Saved.', 'buddypress' ) ?></p>124 </div>125 <?php } ?>126 127 <form action="<?php echo $bp->loggedin_user->domain . 'settings/notifications' ?>" method="post" id="settings-form">128 <h3><?php _e( 'Email Notifications', 'buddypress' ) ?></h3>129 <p><?php _e( 'Send a notification by email when:', 'buddypress' ) ?></p>130 131 <?php do_action( 'bp_notification_settings' ) ?>132 133 <p class="submit"><input type="submit" name="submit" value="<?php _e( 'Save Changes', 'buddypress' ) ?>" id="submit" class="auto"/></p>134 135 <?php wp_nonce_field('bp_settings_notifications') ?>136 137 </form>138 <?php139 }140 141 /**** DELETE ACCOUNT ****/142 143 function bp_core_screen_delete_account() {144 global $current_user, $bp_settings_updated, $pass_error;145 146 if ( isset( $_POST['delete-account-button'] ) && check_admin_referer('delete-account') ) {147 if ( !check_admin_referer( 'delete-account' ) )148 return false;149 150 // delete the users account151 if ( bp_core_delete_account() )152 bp_core_redirect( site_url() );153 }154 155 $bp_settings_updated = false;156 $pass_error = false;157 158 if ( isset($_POST['submit']) && check_admin_referer('bp_settings_general') ) {159 require_once( WPINC . '/registration.php' );160 161 // Form has been submitted and nonce checks out, lets do it.162 163 if ( $_POST['email'] != '' ) {164 $current_user->user_email = wp_specialchars( trim( $_POST['email'] ));165 }166 167 if ( $_POST['pass1'] != '' && $_POST['pass2'] != '' ) {168 if ( $_POST['pass1'] == $_POST['pass2'] && !strpos( " " . $_POST['pass1'], "\\" ) ) {169 $current_user->user_pass = $_POST['pass1'];170 } else {171 $pass_error = true;172 }173 } else if ( empty( $_POST['pass1'] ) && !empty( $_POST['pass2'] ) || !empty( $_POST['pass1'] ) && empty( $_POST['pass2'] ) ) {174 $pass_error = true;175 } else {176 unset( $current_user->user_pass );177 }178 179 if ( !$pass_error && wp_update_user( get_object_vars( $current_user ) ) )180 $bp_settings_updated = true;181 }182 183 192 add_action( 'bp_template_title', 'bp_core_screen_delete_account_title' ); 184 193 add_action( 'bp_template_content', 'bp_core_screen_delete_account_content' );
Note: See TracChangeset
for help on using the changeset viewer.