BP_Settings_Component

Creates our Settings component.

Defined (1)

The class is defined in the following location(s).

/bp-settings/classes/class-bp-settings-component.php  
  1. class BP_Settings_Component extends BP_Component { 
  2.  
  3. /** 
  4. * Start the settings component creation process. 
  5. * @since 1.5.0 
  6. */ 
  7. public function __construct() { 
  8. parent::start( 
  9. 'settings',  
  10. __( 'Settings', 'buddypress' ),  
  11. buddypress()->plugin_dir,  
  12. array( 
  13. 'adminbar_myaccount_order' => 100 
  14. ); 
  15.  
  16. /** 
  17. * Include files. 
  18. * @since 1.5.0 
  19. * @param array $includes Array of values to include. Not used. 
  20. */ 
  21. public function includes( $includes = array() ) { 
  22. parent::includes( array( 
  23. 'actions',  
  24. 'screens',  
  25. 'template',  
  26. 'functions',  
  27. ) ); 
  28.  
  29. /** 
  30. * Setup globals. 
  31. * The BP_SETTINGS_SLUG constant is deprecated, and only used here for 
  32. * backwards compatibility. 
  33. * @since 1.5.0 
  34. * @param array $args Array of arguments. 
  35. */ 
  36. public function setup_globals( $args = array() ) { 
  37.  
  38. // Define a slug, if necessary. 
  39. if ( ! defined( 'BP_SETTINGS_SLUG' ) ) { 
  40. define( 'BP_SETTINGS_SLUG', $this->id ); 
  41.  
  42. // All globals for settings component. 
  43. parent::setup_globals( array( 
  44. 'slug' => BP_SETTINGS_SLUG,  
  45. 'has_directory' => false,  
  46. ) ); 
  47.  
  48. /** 
  49. * Set up navigation. 
  50. * @since 1.5.0 
  51. * @param array $main_nav Array of main nav items. 
  52. * @param array $sub_nav Array of sub nav items. 
  53. */ 
  54. public function setup_nav( $main_nav = array(), $sub_nav = array() ) { 
  55.  
  56. // Determine user to use. 
  57. if ( bp_displayed_user_domain() ) { 
  58. $user_domain = bp_displayed_user_domain(); 
  59. } elseif ( bp_loggedin_user_domain() ) { 
  60. $user_domain = bp_loggedin_user_domain(); 
  61. } else { 
  62. return; 
  63.  
  64. $access = bp_core_can_edit_settings(); 
  65. $slug = bp_get_settings_slug(); 
  66. $settings_link = trailingslashit( $user_domain . $slug ); 
  67.  
  68. // Add the settings navigation item. 
  69. $main_nav = array( 
  70. 'name' => __( 'Settings', 'buddypress' ),  
  71. 'slug' => $slug,  
  72. 'position' => 100,  
  73. 'show_for_displayed_user' => $access,  
  74. 'screen_function' => 'bp_settings_screen_general',  
  75. 'default_subnav_slug' => 'general' 
  76. ); 
  77.  
  78. // Add General Settings nav item. 
  79. $sub_nav[] = array( 
  80. 'name' => __( 'General', 'buddypress' ),  
  81. 'slug' => 'general',  
  82. 'parent_url' => $settings_link,  
  83. 'parent_slug' => $slug,  
  84. 'screen_function' => 'bp_settings_screen_general',  
  85. 'position' => 10,  
  86. 'user_has_access' => $access 
  87. ); 
  88.  
  89. // Add Email nav item. Formerly called 'Notifications', we 
  90. // retain the old slug and function names for backward compat. 
  91. $sub_nav[] = array( 
  92. 'name' => __( 'Email', 'buddypress' ),  
  93. 'slug' => 'notifications',  
  94. 'parent_url' => $settings_link,  
  95. 'parent_slug' => $slug,  
  96. 'screen_function' => 'bp_settings_screen_notification',  
  97. 'position' => 20,  
  98. 'user_has_access' => $access 
  99. ); 
  100.  
  101. // Add Spam Account nav item. 
  102. if ( bp_current_user_can( 'bp_moderate' ) ) { 
  103. $sub_nav[] = array( 
  104. 'name' => __( 'Capabilities', 'buddypress' ),  
  105. 'slug' => 'capabilities',  
  106. 'parent_url' => $settings_link,  
  107. 'parent_slug' => $slug,  
  108. 'screen_function' => 'bp_settings_screen_capabilities',  
  109. 'position' => 80,  
  110. 'user_has_access' => ! bp_is_my_profile() 
  111. ); 
  112.  
  113. // Add Delete Account nav item. 
  114. if ( ( ! bp_disable_account_deletion() && bp_is_my_profile() ) || bp_current_user_can( 'delete_users' ) ) { 
  115. $sub_nav[] = array( 
  116. 'name' => __( 'Delete Account', 'buddypress' ),  
  117. 'slug' => 'delete-account',  
  118. 'parent_url' => $settings_link,  
  119. 'parent_slug' => $slug,  
  120. 'screen_function' => 'bp_settings_screen_delete_account',  
  121. 'position' => 90,  
  122. 'user_has_access' => ! is_super_admin( bp_displayed_user_id() ) 
  123. ); 
  124.  
  125. parent::setup_nav( $main_nav, $sub_nav ); 
  126.  
  127. /** 
  128. * Set up the Toolbar. 
  129. * @since 1.5.0 
  130. * @param array $wp_admin_nav Array of Admin Bar items. 
  131. */ 
  132. public function setup_admin_bar( $wp_admin_nav = array() ) { 
  133.  
  134. // Menus for logged in user. 
  135. if ( is_user_logged_in() ) { 
  136.  
  137. // Setup the logged in user variables. 
  138. $settings_link = trailingslashit( bp_loggedin_user_domain() . bp_get_settings_slug() ); 
  139.  
  140. // Add main Settings menu. 
  141. $wp_admin_nav[] = array( 
  142. 'parent' => buddypress()->my_account_menu_id,  
  143. 'id' => 'my-account-' . $this->id,  
  144. 'title' => __( 'Settings', 'buddypress' ),  
  145. 'href' => $settings_link 
  146. ); 
  147.  
  148. // General Account. 
  149. $wp_admin_nav[] = array( 
  150. 'parent' => 'my-account-' . $this->id,  
  151. 'id' => 'my-account-' . $this->id . '-general',  
  152. 'title' => __( 'General', 'buddypress' ),  
  153. 'href' => $settings_link,  
  154. 'position' => 10 
  155. ); 
  156.  
  157. // Notifications - only add the tab when there is something to display there. 
  158. if ( has_action( 'bp_notification_settings' ) ) { 
  159. $wp_admin_nav[] = array( 
  160. 'parent' => 'my-account-' . $this->id,  
  161. 'id' => 'my-account-' . $this->id . '-notifications',  
  162. 'title' => __( 'Email', 'buddypress' ),  
  163. 'href' => trailingslashit( $settings_link . 'notifications' ),  
  164. 'position' => 20 
  165. ); 
  166.  
  167. // Delete Account 
  168. if ( !bp_current_user_can( 'bp_moderate' ) && ! bp_core_get_root_option( 'bp-disable-account-deletion' ) ) { 
  169. $wp_admin_nav[] = array( 
  170. 'parent' => 'my-account-' . $this->id,  
  171. 'id' => 'my-account-' . $this->id . '-delete-account',  
  172. 'title' => __( 'Delete Account', 'buddypress' ),  
  173. 'href' => trailingslashit( $settings_link . 'delete-account' ),  
  174. 'position' => 90 
  175. ); 
  176.  
  177. parent::setup_admin_bar( $wp_admin_nav );