[ 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       * @see BP_Component::setup_globals() for a description of arguments.
 102       *
 103       * @param array $args See BP_Component::setup_globals() for a description.
 104       */
 105  	public function setup_globals( $args = array() ) {
 106  
 107          // Define a slug, if necessary.
 108          if ( ! defined( 'BP_SETTINGS_SLUG' ) ) {
 109              define( 'BP_SETTINGS_SLUG', $this->id );
 110          }
 111  
 112          // All globals for settings component.
 113          parent::setup_globals( array(
 114              'slug'          => BP_SETTINGS_SLUG,
 115              'has_directory' => false,
 116          ) );
 117      }
 118  
 119      /**
 120       * Set up navigation.
 121       *
 122       * @since 1.5.0
 123       *
 124       * @see BP_Component::setup_nav() for a description of arguments.
 125       *
 126       * @param array $main_nav Optional. See BP_Component::setup_nav() for
 127       *                        description.
 128       * @param array $sub_nav  Optional. See BP_Component::setup_nav() for
 129       *                        description.
 130       */
 131  	public function setup_nav( $main_nav = array(), $sub_nav = array() ) {
 132  
 133          // Determine user to use.
 134          if ( bp_displayed_user_domain() ) {
 135              $user_domain = bp_displayed_user_domain();
 136          } elseif ( bp_loggedin_user_domain() ) {
 137              $user_domain = bp_loggedin_user_domain();
 138          } else {
 139              return;
 140          }
 141  
 142          $access        = bp_core_can_edit_settings();
 143          $slug          = bp_get_settings_slug();
 144          $settings_link = trailingslashit( $user_domain . $slug );
 145  
 146          // Add the settings navigation item.
 147          $main_nav = array(
 148              'name'                    => __( 'Settings', 'buddypress' ),
 149              'slug'                    => $slug,
 150              'position'                => 100,
 151              'show_for_displayed_user' => $access,
 152              'screen_function'         => 'bp_settings_screen_general',
 153              'default_subnav_slug'     => 'general',
 154          );
 155  
 156          // Add General Settings nav item.
 157          $sub_nav[] = array(
 158              'name'            => __( 'General', 'buddypress' ),
 159              'slug'            => 'general',
 160              'parent_url'      => $settings_link,
 161              'parent_slug'     => $slug,
 162              'screen_function' => 'bp_settings_screen_general',
 163              'position'        => 10,
 164              'user_has_access' => $access,
 165          );
 166  
 167          // Add Email nav item. Formerly called 'Notifications', we
 168          // retain the old slug and function names for backward compat.
 169          $sub_nav[] = array(
 170              'name'            => __( 'Email', 'buddypress' ),
 171              'slug'            => 'notifications',
 172              'parent_url'      => $settings_link,
 173              'parent_slug'     => $slug,
 174              'screen_function' => 'bp_settings_screen_notification',
 175              'position'        => 20,
 176              'user_has_access' => $access,
 177          );
 178  
 179          // Add Spam Account nav item.
 180          if ( bp_current_user_can( 'bp_moderate' ) ) {
 181              $sub_nav[] = array(
 182                  'name'            => __( 'Capabilities', 'buddypress' ),
 183                  'slug'            => 'capabilities',
 184                  'parent_url'      => $settings_link,
 185                  'parent_slug'     => $slug,
 186                  'screen_function' => 'bp_settings_screen_capabilities',
 187                  'position'        => 80,
 188                  'user_has_access' => ! bp_is_my_profile(),
 189              );
 190          }
 191  
 192          /**
 193           * Filter whether the site should show the "Settings > Data" page.
 194           *
 195           * @since 4.0.0
 196           *
 197           * @param bool $show Defaults to true.
 198           */
 199          $show_data_page = apply_filters( 'bp_settings_show_user_data_page', true );
 200  
 201          // Export Data.
 202          if ( true === $show_data_page ) {
 203              $sub_nav[] = array(
 204                  'name'            => __( 'Export Data', 'buddypress' ),
 205                  'slug'            => 'data',
 206                  'parent_url'      => $settings_link,
 207                  'parent_slug'     => $slug,
 208                  'screen_function' => 'bp_settings_screen_data',
 209                  'position'        => 89,
 210                  'user_has_access' => $access,
 211              );
 212          }
 213  
 214          // Add Delete Account nav item.
 215          if ( ( ! bp_disable_account_deletion() && bp_is_my_profile() ) || bp_current_user_can( 'delete_users' ) ) {
 216              $sub_nav[] = array(
 217                  'name'            => __( 'Delete Account', 'buddypress' ),
 218                  'slug'            => 'delete-account',
 219                  'parent_url'      => $settings_link,
 220                  'parent_slug'     => $slug,
 221                  'screen_function' => 'bp_settings_screen_delete_account',
 222                  'position'        => 90,
 223                  'user_has_access' => ! is_super_admin( bp_displayed_user_id() )
 224              );
 225          }
 226  
 227          parent::setup_nav( $main_nav, $sub_nav );
 228      }
 229  
 230      /**
 231       * Set up the component entries in the WordPress Admin Bar.
 232       *
 233       * @since 1.5.0
 234       *
 235       * @see BP_Component::setup_nav() for a description of the $wp_admin_nav
 236       *      parameter array.
 237       *
 238       * @param array $wp_admin_nav See BP_Component::setup_admin_bar() for a
 239       *                            description.
 240       */
 241  	public function setup_admin_bar( $wp_admin_nav = array() ) {
 242  
 243          // Menus for logged in user.
 244          if ( is_user_logged_in() ) {
 245  
 246              // Setup the logged in user variables.
 247              $settings_link = trailingslashit( bp_loggedin_user_domain() . bp_get_settings_slug() );
 248  
 249              // Add main Settings menu.
 250              $wp_admin_nav[] = array(
 251                  'parent' => buddypress()->my_account_menu_id,
 252                  'id'     => 'my-account-' . $this->id,
 253                  'title'  => __( 'Settings', 'buddypress' ),
 254                  'href'   => $settings_link,
 255              );
 256  
 257              // General Account.
 258              $wp_admin_nav[] = array(
 259                  'parent'   => 'my-account-' . $this->id,
 260                  'id'       => 'my-account-' . $this->id . '-general',
 261                  'title'    => __( 'General', 'buddypress' ),
 262                  'href'     => trailingslashit( $settings_link . 'general' ),
 263                  'position' => 10,
 264              );
 265  
 266              // Notifications - only add the tab when there is something to display there.
 267              if ( has_action( 'bp_notification_settings' ) ) {
 268                  $wp_admin_nav[] = array(
 269                      'parent'   => 'my-account-' . $this->id,
 270                      'id'       => 'my-account-' . $this->id . '-notifications',
 271                      'title'    => __( 'Email', 'buddypress' ),
 272                      'href'     => trailingslashit( $settings_link . 'notifications' ),
 273                      'position' => 20,
 274                  );
 275              }
 276  
 277              /** This filter is documented in bp-settings/classes/class-bp-settings-component.php */
 278              $show_data_page = apply_filters( 'bp_settings_show_user_data_page', true );
 279  
 280              // Export Data.
 281              if ( true === $show_data_page ) {
 282                  $wp_admin_nav[] = array(
 283                      'parent'   => 'my-account-' . $this->id,
 284                      'id'       => 'my-account-' . $this->id . '-data',
 285                      'title'    => __( 'Export Data', 'buddypress' ),
 286                      'href'     => trailingslashit( $settings_link . 'data' ),
 287                      'position' => 89,
 288                  );
 289              }
 290  
 291              // Delete Account
 292              if ( !bp_current_user_can( 'bp_moderate' ) && ! bp_core_get_root_option( 'bp-disable-account-deletion' ) ) {
 293                  $wp_admin_nav[] = array(
 294                      'parent'   => 'my-account-' . $this->id,
 295                      'id'       => 'my-account-' . $this->id . '-delete-account',
 296                      'title'    => __( 'Delete Account', 'buddypress' ),
 297                      'href'     => trailingslashit( $settings_link . 'delete-account' ),
 298                      'position' => 90,
 299                  );
 300              }
 301          }
 302  
 303          parent::setup_admin_bar( $wp_admin_nav );
 304      }
 305  
 306      /**
 307       * Register the BP Settings Blocks.
 308       *
 309       * @since 9.0.0
 310       *
 311       * @param array $blocks Optional. See BP_Component::blocks_init() for the description.
 312       */
 313  	public function blocks_init( $blocks = array() ) {
 314          parent::blocks_init( array() );
 315      }
 316  }


Generated: Sun Dec 22 01:00:54 2024 Cross-referenced by PHPXref 0.7.1