[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

/src/bp-settings/classes/ -> class-bp-settings-component.php (source)

   1  <?php
   2  /**
   3   * BuddyPress Settings Loader.
   4   *
   5   * @package BuddyPress
   6   * @subpackage SettingsLoader
   7   * @since 1.5.0
   8   */
   9  
  10  // Exit if accessed directly.
  11  defined( 'ABSPATH' ) || exit;
  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              'template',
  46              'filters',
  47              'functions',
  48          ) );
  49      }
  50  
  51      /**
  52       * Late includes method.
  53       *
  54       * Only load up certain code when on specific pages.
  55       *
  56       * @since 3.0.0
  57       */
  58  	public function late_includes() {
  59          // Bail if PHPUnit is running.
  60          if ( defined( 'BP_TESTS_DIR' ) ) {
  61              return;
  62          }
  63  
  64          // Bail if not on Settings component.
  65          if ( ! bp_is_settings_component() ) {
  66              return;
  67          }
  68  
  69          $actions = array( 'notifications', 'capabilities', 'data', 'delete-account' );
  70  
  71          // Authenticated actions.
  72          if ( is_user_logged_in() ) {
  73              if ( ! bp_current_action() || bp_is_current_action( 'general' ) ) {
  74                  require $this->path . 'bp-settings/actions/general.php';
  75  
  76              // Specific to post requests.
  77              } elseif ( bp_is_post_request() && in_array( bp_current_action(), $actions, true ) ) {
  78                  require $this->path . 'bp-settings/actions/' . bp_current_action() . '.php';
  79              }
  80          }
  81  
  82          // Screens - User profile integration.
  83          if ( bp_is_user() ) {
  84              require $this->path . 'bp-settings/screens/general.php';
  85  
  86              // Sub-nav items.
  87              if ( in_array( bp_current_action(), $actions, true ) ) {
  88                  require $this->path . 'bp-settings/screens/' . bp_current_action() . '.php';
  89              }
  90          }
  91      }
  92  
  93      /**
  94       * Setup globals.
  95       *
  96       * The BP_SETTINGS_SLUG constant is deprecated, and only used here for
  97       * backwards compatibility.
  98       *
  99       * @since 1.5.0
 100       *
 101       * @param array $args Array of arguments.
 102       */
 103  	public function setup_globals( $args = array() ) {
 104  
 105          // Define a slug, if necessary.
 106          if ( ! defined( 'BP_SETTINGS_SLUG' ) ) {
 107              define( 'BP_SETTINGS_SLUG', $this->id );
 108          }
 109  
 110          // All globals for settings component.
 111          parent::setup_globals( array(
 112              'slug'          => BP_SETTINGS_SLUG,
 113              'has_directory' => false,
 114          ) );
 115      }
 116  
 117      /**
 118       * Set up navigation.
 119       *
 120       * @since 1.5.0
 121       *
 122       * @param array $main_nav Array of main nav items.
 123       * @param array $sub_nav  Array of sub nav items.
 124       */
 125  	public function setup_nav( $main_nav = array(), $sub_nav = array() ) {
 126  
 127          // Determine user to use.
 128          if ( bp_displayed_user_domain() ) {
 129              $user_domain = bp_displayed_user_domain();
 130          } elseif ( bp_loggedin_user_domain() ) {
 131              $user_domain = bp_loggedin_user_domain();
 132          } else {
 133              return;
 134          }
 135  
 136          $access        = bp_core_can_edit_settings();
 137          $slug          = bp_get_settings_slug();
 138          $settings_link = trailingslashit( $user_domain . $slug );
 139  
 140          // Add the settings navigation item.
 141          $main_nav = array(
 142              'name'                    => __( 'Settings', 'buddypress' ),
 143              'slug'                    => $slug,
 144              'position'                => 100,
 145              'show_for_displayed_user' => $access,
 146              'screen_function'         => 'bp_settings_screen_general',
 147              'default_subnav_slug'     => 'general'
 148          );
 149  
 150          // Add General Settings nav item.
 151          $sub_nav[] = array(
 152              'name'            => __( 'General', 'buddypress' ),
 153              'slug'            => 'general',
 154              'parent_url'      => $settings_link,
 155              'parent_slug'     => $slug,
 156              'screen_function' => 'bp_settings_screen_general',
 157              'position'        => 10,
 158              'user_has_access' => $access
 159          );
 160  
 161          // Add Email nav item. Formerly called 'Notifications', we
 162          // retain the old slug and function names for backward compat.
 163          $sub_nav[] = array(
 164              'name'            => __( 'Email', 'buddypress' ),
 165              'slug'            => 'notifications',
 166              'parent_url'      => $settings_link,
 167              'parent_slug'     => $slug,
 168              'screen_function' => 'bp_settings_screen_notification',
 169              'position'        => 20,
 170              'user_has_access' => $access
 171          );
 172  
 173          // Add Spam Account nav item.
 174          if ( bp_current_user_can( 'bp_moderate' ) ) {
 175              $sub_nav[] = array(
 176                  'name'            => __( 'Capabilities', 'buddypress' ),
 177                  'slug'            => 'capabilities',
 178                  'parent_url'      => $settings_link,
 179                  'parent_slug'     => $slug,
 180                  'screen_function' => 'bp_settings_screen_capabilities',
 181                  'position'        => 80,
 182                  'user_has_access' => ! bp_is_my_profile()
 183              );
 184          }
 185  
 186          /**
 187           * Filter whether the site should show the "Settings > Data" page.
 188           *
 189           * @since 4.0.0
 190           *
 191           * @param bool $show Defaults to true.
 192           */
 193          $show_data_page = apply_filters( 'bp_settings_show_user_data_page', true );
 194  
 195          // Export Data - only available for WP 4.9.6+.
 196          if ( true === $show_data_page && version_compare( $GLOBALS['wp_version'], '4.9.6', '>=' ) ) {
 197              $sub_nav[] = array(
 198                  'name'            => __( 'Export Data', 'buddypress' ),
 199                  'slug'            => 'data',
 200                  'parent_url'      => $settings_link,
 201                  'parent_slug'     => $slug,
 202                  'screen_function' => 'bp_settings_screen_data',
 203                  'position'        => 89,
 204                  'user_has_access' => $access,
 205              );
 206          }
 207  
 208          // Add Delete Account nav item.
 209          if ( ( ! bp_disable_account_deletion() && bp_is_my_profile() ) || bp_current_user_can( 'delete_users' ) ) {
 210              $sub_nav[] = array(
 211                  'name'            => __( 'Delete Account', 'buddypress' ),
 212                  'slug'            => 'delete-account',
 213                  'parent_url'      => $settings_link,
 214                  'parent_slug'     => $slug,
 215                  'screen_function' => 'bp_settings_screen_delete_account',
 216                  'position'        => 90,
 217                  'user_has_access' => ! is_super_admin( bp_displayed_user_id() )
 218              );
 219          }
 220  
 221          parent::setup_nav( $main_nav, $sub_nav );
 222      }
 223  
 224      /**
 225       * Set up the Toolbar.
 226       *
 227       * @since 1.5.0
 228       *
 229       * @param array $wp_admin_nav Array of Admin Bar items.
 230       */
 231  	public function setup_admin_bar( $wp_admin_nav = array() ) {
 232  
 233          // Menus for logged in user.
 234          if ( is_user_logged_in() ) {
 235  
 236              // Setup the logged in user variables.
 237              $settings_link = trailingslashit( bp_loggedin_user_domain() . bp_get_settings_slug() );
 238  
 239              // Add main Settings menu.
 240              $wp_admin_nav[] = array(
 241                  'parent' => buddypress()->my_account_menu_id,
 242                  'id'     => 'my-account-' . $this->id,
 243                  'title'  => __( 'Settings', 'buddypress' ),
 244                  'href'   => $settings_link
 245              );
 246  
 247              // General Account.
 248              $wp_admin_nav[] = array(
 249                  'parent'   => 'my-account-' . $this->id,
 250                  'id'       => 'my-account-' . $this->id . '-general',
 251                  'title'    => __( 'General', 'buddypress' ),
 252                  'href'     => $settings_link,
 253                  'position' => 10
 254              );
 255  
 256              // Notifications - only add the tab when there is something to display there.
 257              if ( has_action( 'bp_notification_settings' ) ) {
 258                  $wp_admin_nav[] = array(
 259                      'parent'   => 'my-account-' . $this->id,
 260                      'id'       => 'my-account-' . $this->id . '-notifications',
 261                      'title'    => __( 'Email', 'buddypress' ),
 262                      'href'     => trailingslashit( $settings_link . 'notifications' ),
 263                      'position' => 20
 264                  );
 265              }
 266  
 267              /** This filter is documented in bp-settings/classes/class-bp-settings-component.php */
 268              $show_data_page = apply_filters( 'bp_settings_show_user_data_page', true );
 269  
 270              // Export Data.
 271              if ( true === $show_data_page && version_compare( $GLOBALS['wp_version'], '4.9.6', '>=' ) ) {
 272                  $wp_admin_nav[] = array(
 273                      'parent'   => 'my-account-' . $this->id,
 274                      'id'       => 'my-account-' . $this->id . '-data',
 275                      'title'    => __( 'Export Data', 'buddypress' ),
 276                      'href'     => trailingslashit( $settings_link . 'data' ),
 277                      'position' => 89,
 278                  );
 279              }
 280  
 281              // Delete Account
 282              if ( !bp_current_user_can( 'bp_moderate' ) && ! bp_core_get_root_option( 'bp-disable-account-deletion' ) ) {
 283                  $wp_admin_nav[] = array(
 284                      'parent'   => 'my-account-' . $this->id,
 285                      'id'       => 'my-account-' . $this->id . '-delete-account',
 286                      'title'    => __( 'Delete Account', 'buddypress' ),
 287                      'href'     => trailingslashit( $settings_link . 'delete-account' ),
 288                      'position' => 90
 289                  );
 290              }
 291          }
 292  
 293          parent::setup_admin_bar( $wp_admin_nav );
 294      }
 295  }


Generated: Wed Sep 18 01:01:38 2019 Cross-referenced by PHPXref 0.7.1