Changeset 10524
- Timestamp:
- 02/05/2016 05:28:55 AM (9 years ago)
- Location:
- trunk/src/bp-settings
- Files:
-
- 1 added
- 1 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bp-settings/bp-settings-loader.php
r10498 r10524 11 11 defined( 'ABSPATH' ) || exit; 12 12 13 /** 14 * Creates our Settings component. 15 * 16 * @since 1.5.0 17 */ 18 class BP_Settings_Component extends BP_Component { 19 20 /** 21 * Start the settings component creation process. 22 * 23 * @since 1.5.0 24 */ 25 public function __construct() { 26 parent::start( 27 'settings', 28 __( 'Settings', 'buddypress' ), 29 buddypress()->plugin_dir, 30 array( 31 'adminbar_myaccount_order' => 100 32 ) 33 ); 34 } 35 36 /** 37 * Include files. 38 * 39 * @since 1.5.0 40 * 41 * @param array $includes Array of values to include. Not used. 42 */ 43 public function includes( $includes = array() ) { 44 parent::includes( array( 45 'actions', 46 'screens', 47 'template', 48 'functions', 49 ) ); 50 } 51 52 /** 53 * Setup globals. 54 * 55 * The BP_SETTINGS_SLUG constant is deprecated, and only used here for 56 * backwards compatibility. 57 * 58 * @since 1.5.0 59 * 60 * @param array $args Array of arguments. 61 */ 62 public function setup_globals( $args = array() ) { 63 64 // Define a slug, if necessary. 65 if ( ! defined( 'BP_SETTINGS_SLUG' ) ) { 66 define( 'BP_SETTINGS_SLUG', $this->id ); 67 } 68 69 // All globals for settings component. 70 parent::setup_globals( array( 71 'slug' => BP_SETTINGS_SLUG, 72 'has_directory' => false, 73 ) ); 74 } 75 76 /** 77 * Set up navigation. 78 * 79 * @since 1.5.0 80 * 81 * @param array $main_nav Array of main nav items. 82 * @param array $sub_nav Array of sub nav items. 83 */ 84 public function setup_nav( $main_nav = array(), $sub_nav = array() ) { 85 86 // Determine user to use. 87 if ( bp_displayed_user_domain() ) { 88 $user_domain = bp_displayed_user_domain(); 89 } elseif ( bp_loggedin_user_domain() ) { 90 $user_domain = bp_loggedin_user_domain(); 91 } else { 92 return; 93 } 94 95 $access = bp_core_can_edit_settings(); 96 $slug = bp_get_settings_slug(); 97 $settings_link = trailingslashit( $user_domain . $slug ); 98 99 // Add the settings navigation item. 100 $main_nav = array( 101 'name' => __( 'Settings', 'buddypress' ), 102 'slug' => $slug, 103 'position' => 100, 104 'show_for_displayed_user' => $access, 105 'screen_function' => 'bp_settings_screen_general', 106 'default_subnav_slug' => 'general' 107 ); 108 109 // Add General Settings nav item. 110 $sub_nav[] = array( 111 'name' => __( 'General', 'buddypress' ), 112 'slug' => 'general', 113 'parent_url' => $settings_link, 114 'parent_slug' => $slug, 115 'screen_function' => 'bp_settings_screen_general', 116 'position' => 10, 117 'user_has_access' => $access 118 ); 119 120 // Add Email nav item. Formerly called 'Notifications', we 121 // retain the old slug and function names for backward compat. 122 $sub_nav[] = array( 123 'name' => __( 'Email', 'buddypress' ), 124 'slug' => 'notifications', 125 'parent_url' => $settings_link, 126 'parent_slug' => $slug, 127 'screen_function' => 'bp_settings_screen_notification', 128 'position' => 20, 129 'user_has_access' => $access 130 ); 131 132 // Add Spam Account nav item. 133 if ( bp_current_user_can( 'bp_moderate' ) ) { 134 $sub_nav[] = array( 135 'name' => __( 'Capabilities', 'buddypress' ), 136 'slug' => 'capabilities', 137 'parent_url' => $settings_link, 138 'parent_slug' => $slug, 139 'screen_function' => 'bp_settings_screen_capabilities', 140 'position' => 80, 141 'user_has_access' => ! bp_is_my_profile() 142 ); 143 } 144 145 // Add Delete Account nav item. 146 if ( ( ! bp_disable_account_deletion() && bp_is_my_profile() ) || bp_current_user_can( 'delete_users' ) ) { 147 $sub_nav[] = array( 148 'name' => __( 'Delete Account', 'buddypress' ), 149 'slug' => 'delete-account', 150 'parent_url' => $settings_link, 151 'parent_slug' => $slug, 152 'screen_function' => 'bp_settings_screen_delete_account', 153 'position' => 90, 154 'user_has_access' => ! is_super_admin( bp_displayed_user_id() ) 155 ); 156 } 157 158 parent::setup_nav( $main_nav, $sub_nav ); 159 } 160 161 /** 162 * Set up the Toolbar. 163 * 164 * @since 1.5.0 165 * 166 * @param array $wp_admin_nav Array of Admin Bar items. 167 */ 168 public function setup_admin_bar( $wp_admin_nav = array() ) { 169 170 // Menus for logged in user. 171 if ( is_user_logged_in() ) { 172 173 // Setup the logged in user variables. 174 $settings_link = trailingslashit( bp_loggedin_user_domain() . bp_get_settings_slug() ); 175 176 // Add main Settings menu. 177 $wp_admin_nav[] = array( 178 'parent' => buddypress()->my_account_menu_id, 179 'id' => 'my-account-' . $this->id, 180 'title' => __( 'Settings', 'buddypress' ), 181 'href' => $settings_link 182 ); 183 184 // General Account. 185 $wp_admin_nav[] = array( 186 'parent' => 'my-account-' . $this->id, 187 'id' => 'my-account-' . $this->id . '-general', 188 'title' => __( 'General', 'buddypress' ), 189 'href' => $settings_link 190 ); 191 192 // Notifications - only add the tab when there is something to display there. 193 if ( has_action( 'bp_notification_settings' ) ) { 194 $wp_admin_nav[] = array( 195 'parent' => 'my-account-' . $this->id, 196 'id' => 'my-account-' . $this->id . '-notifications', 197 'title' => __( 'Email', 'buddypress' ), 198 'href' => trailingslashit( $settings_link . 'notifications' ) 199 ); 200 } 201 202 // Delete Account. 203 if ( !bp_current_user_can( 'bp_moderate' ) && ! bp_core_get_root_option( 'bp-disable-account-deletion' ) ) { 204 $wp_admin_nav[] = array( 205 'parent' => 'my-account-' . $this->id, 206 'id' => 'my-account-' . $this->id . '-delete-account', 207 'title' => __( 'Delete Account', 'buddypress' ), 208 'href' => trailingslashit( $settings_link . 'delete-account' ) 209 ); 210 } 211 } 212 213 parent::setup_admin_bar( $wp_admin_nav ); 214 } 215 } 13 require dirname( __FILE__ ) . '/classes/class-bp-settings-component.php'; 216 14 217 15 /** -
trunk/src/bp-settings/classes/class-bp-settings-component.php
r10515 r10524 214 214 } 215 215 } 216 217 /**218 * Instantiates the settings component.219 *220 * @since 1.6.0221 */222 function bp_setup_settings() {223 buddypress()->settings = new BP_Settings_Component();224 }225 add_action( 'bp_setup_components', 'bp_setup_settings', 6 );
Note: See TracChangeset
for help on using the changeset viewer.