[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

/src/bp-core/admin/ -> bp-core-admin-settings.php (source)

   1  <?php
   2  /**
   3   * BuddyPress Admin Settings.
   4   *
   5   * @package BuddyPress
   6   * @subpackage CoreAdministration
   7   * @since 2.3.0
   8   */
   9  
  10  // Exit if accessed directly.
  11  defined( 'ABSPATH' ) || exit;
  12  
  13  /**
  14   * Main settings section description for the settings page.
  15   *
  16   * @since 1.6.0
  17   */
  18  function bp_admin_setting_callback_main_section() { }
  19  
  20  /**
  21   * Admin bar for logged out users setting field.
  22   *
  23   * @since 1.6.0
  24   *
  25   */
  26  function bp_admin_setting_callback_admin_bar() {
  27  ?>
  28  
  29      <input id="hide-loggedout-adminbar" name="hide-loggedout-adminbar" type="checkbox" value="1" <?php checked( !bp_hide_loggedout_adminbar( false ) ); ?> />
  30      <label for="hide-loggedout-adminbar"><?php _e( 'Show the Toolbar for logged out users', 'buddypress' ); ?></label>
  31  
  32  <?php
  33  }
  34  
  35  /**
  36   * Allow members to delete their accounts setting field.
  37   *
  38   * @since 1.6.0
  39   *
  40   */
  41  function bp_admin_setting_callback_account_deletion() {
  42  ?>
  43  
  44      <input id="bp-disable-account-deletion" name="bp-disable-account-deletion" type="checkbox" value="1" <?php checked( !bp_disable_account_deletion( false ) ); ?> />
  45      <label for="bp-disable-account-deletion"><?php _e( 'Allow registered members to delete their own accounts', 'buddypress' ); ?></label>
  46  
  47  <?php
  48  }
  49  
  50  /**
  51   * Form element to change the active template pack.
  52   */
  53  function bp_admin_setting_callback_theme_package_id() {
  54      $options = '';
  55  
  56      /*
  57       * Note: This should never be empty. /bp-templates/ is the
  58       * canonical backup if no other packages exist. If there's an error here,
  59       * something else is wrong.
  60       *
  61       * See BuddyPress::register_theme_packages()
  62       */
  63      foreach ( (array) buddypress()->theme_compat->packages as $id => $theme ) {
  64          $options .= sprintf(
  65              '<option value="%1$s" %2$s>%3$s</option>',
  66              esc_attr( $id ),
  67              selected( $theme->id, bp_get_theme_package_id(), false ),
  68              esc_html( $theme->name )
  69          );
  70      }
  71  
  72      if ( $options ) : ?>
  73          <select name="_bp_theme_package_id" id="_bp_theme_package_id" aria-describedby="_bp_theme_package_description"><?php echo $options; ?></select>
  74          <p id="_bp_theme_package_description" class="description"><?php esc_html_e( 'The selected Template Pack will serve all BuddyPress templates.', 'buddypress' ); ?></p>
  75  
  76      <?php else : ?>
  77          <p><?php esc_html_e( 'No template packages available.', 'buddypress' ); ?></p>
  78  
  79      <?php endif;
  80  }
  81  
  82  /** Activity *******************************************************************/
  83  
  84  /**
  85   * Groups settings section description for the settings page.
  86   *
  87   * @since 1.6.0
  88   */
  89  function bp_admin_setting_callback_activity_section() { }
  90  
  91  /**
  92   * Allow Akismet setting field.
  93   *
  94   * @since 1.6.0
  95   *
  96   */
  97  function bp_admin_setting_callback_activity_akismet() {
  98  ?>
  99  
 100      <input id="_bp_enable_akismet" name="_bp_enable_akismet" type="checkbox" value="1" <?php checked( bp_is_akismet_active( true ) ); ?> />
 101      <label for="_bp_enable_akismet"><?php _e( 'Allow Akismet to scan for activity stream spam', 'buddypress' ); ?></label>
 102  
 103  <?php
 104  }
 105  
 106  /**
 107   * Allow activity comments on posts and comments.
 108   *
 109   * @since 1.6.0
 110   */
 111  function bp_admin_setting_callback_blogforum_comments() {
 112  ?>
 113  
 114      <input id="bp-disable-blogforum-comments" name="bp-disable-blogforum-comments" type="checkbox" value="1" <?php checked( !bp_disable_blogforum_comments( false ) ); ?> />
 115      <label for="bp-disable-blogforum-comments"><?php _e( 'Allow activity stream commenting on posts and comments', 'buddypress' ); ?></label>
 116  
 117  <?php
 118  }
 119  
 120  /**
 121   * Allow Heartbeat to refresh activity stream.
 122   *
 123   * @since 2.0.0
 124   */
 125  function bp_admin_setting_callback_heartbeat() {
 126  ?>
 127  
 128      <input id="_bp_enable_heartbeat_refresh" name="_bp_enable_heartbeat_refresh" type="checkbox" value="1" <?php checked( bp_is_activity_heartbeat_active( true ) ); ?> />
 129      <label for="_bp_enable_heartbeat_refresh"><?php _e( 'Automatically check for new items while viewing the activity stream', 'buddypress' ); ?></label>
 130  
 131  <?php
 132  }
 133  
 134  /**
 135   * Sanitization for bp-disable-blogforum-comments setting.
 136   *
 137   * In the UI, a checkbox asks whether you'd like to *enable* post/comment activity comments. For
 138   * legacy reasons, the option that we store is 1 if these comments are *disabled*. So we use this
 139   * function to flip the boolean before saving the intval.
 140   *
 141   * @since 1.6.0
 142   *
 143   * @param bool $value Whether or not to sanitize.
 144   * @return bool
 145   */
 146  function bp_admin_sanitize_callback_blogforum_comments( $value = false ) {
 147      return $value ? 0 : 1;
 148  }
 149  
 150  /** Members *******************************************************************/
 151  
 152  /**
 153   * Profile settings section description for the settings page.
 154   *
 155   * @since 1.6.0
 156   */
 157  function bp_admin_setting_callback_members_section() { }
 158  
 159  /**
 160   * Allow members to upload avatars field.
 161   *
 162   * @since 1.6.0
 163   * @since 6.0.0 Setting has been moved into the Members section.
 164   */
 165  function bp_admin_setting_callback_avatar_uploads() {
 166  ?>
 167      <input id="bp-disable-avatar-uploads" name="bp-disable-avatar-uploads" type="checkbox" value="1" <?php checked( !bp_disable_avatar_uploads( false ) ); ?> />
 168      <label for="bp-disable-avatar-uploads"><?php _e( 'Allow registered members to upload avatars', 'buddypress' ); ?></label>
 169  <?php
 170  }
 171  
 172  /**
 173   * Allow members to upload cover images field.
 174   *
 175   * @since 2.4.0
 176   * @since 6.0.0 Setting has been moved into the Members section.
 177   */
 178  function bp_admin_setting_callback_cover_image_uploads() {
 179  ?>
 180      <input id="bp-disable-cover-image-uploads" name="bp-disable-cover-image-uploads" type="checkbox" value="1" <?php checked( ! bp_disable_cover_image_uploads() ); ?> />
 181      <label for="bp-disable-cover-image-uploads"><?php _e( 'Allow registered members to upload cover images', 'buddypress' ); ?></label>
 182  <?php
 183  }
 184  
 185  /**
 186   * Allow members to invite non-members to the network.
 187   *
 188   * @since 8.0.0
 189   */
 190  function bp_admin_setting_callback_members_invitations() {
 191  ?>
 192      <input id="bp-enable-members-invitations" name="bp-enable-members-invitations" type="checkbox" value="1" <?php checked( bp_get_members_invitations_allowed() ); ?> />
 193      <label for="bp-enable-members-invitations"><?php _e( 'Allow registered members to invite people to join this network', 'buddypress' ); ?></label>
 194      <?php if ( ! bp_get_signup_allowed() ) : ?>
 195          <p class="description"><?php _e( 'Public registration is currently disabled. However, invitees will still be able to register if network invitations are enabled.', 'buddypress' ); ?></p>
 196      <?php endif; ?>
 197      <?php
 198      /**
 199       * Fires after the output of the invitations settings section.
 200       *
 201       * @since 8.0.0
 202       */
 203      do_action( 'bp_admin_settings_after_members_invitations' );
 204  }
 205  
 206  /** XProfile ******************************************************************/
 207  
 208  /**
 209   * Profile settings section description for the settings page.
 210   *
 211   * @since 1.6.0
 212   */
 213  function bp_admin_setting_callback_xprofile_section() { }
 214  
 215  /**
 216   * Enable BP->WP profile syncing field.
 217   *
 218   * @since 1.6.0
 219   *
 220   */
 221  function bp_admin_setting_callback_profile_sync() {
 222  ?>
 223  
 224      <input id="bp-disable-profile-sync" name="bp-disable-profile-sync" type="checkbox" value="1" <?php checked( !bp_disable_profile_sync( false ) ); ?> />
 225      <label for="bp-disable-profile-sync"><?php _e( 'Enable BuddyPress to WordPress profile syncing', 'buddypress' ); ?></label>
 226  
 227  <?php
 228  }
 229  
 230  /** Groups Section ************************************************************/
 231  
 232  /**
 233   * Groups settings section description for the settings page.
 234   *
 235   * @since 1.6.0
 236   */
 237  function bp_admin_setting_callback_groups_section() { }
 238  
 239  /**
 240   * Allow all users to create groups field.
 241   *
 242   * @since 1.6.0
 243   *
 244   */
 245  function bp_admin_setting_callback_group_creation() {
 246  ?>
 247  
 248      <input id="bp_restrict_group_creation" name="bp_restrict_group_creation" type="checkbox" aria-describedby="bp_group_creation_description" value="1" <?php checked( !bp_restrict_group_creation( false ) ); ?> />
 249      <label for="bp_restrict_group_creation"><?php _e( 'Enable group creation for all users', 'buddypress' ); ?></label>
 250      <p class="description" id="bp_group_creation_description"><?php _e( 'Administrators can always create groups, regardless of this setting.', 'buddypress' ); ?></p>
 251  
 252  <?php
 253  }
 254  
 255  /**
 256   * 'Enable group avatars' field markup.
 257   *
 258   * @since 2.3.0
 259   */
 260  function bp_admin_setting_callback_group_avatar_uploads() {
 261  ?>
 262      <input id="bp-disable-group-avatar-uploads" name="bp-disable-group-avatar-uploads" type="checkbox" value="1" <?php checked( ! bp_disable_group_avatar_uploads() ); ?> />
 263      <label for="bp-disable-group-avatar-uploads"><?php _e( 'Allow customizable avatars for groups', 'buddypress' ); ?></label>
 264  <?php
 265  }
 266  
 267  /**
 268   * 'Enable group cover images' field markup.
 269   *
 270   * @since 2.4.0
 271   */
 272  function bp_admin_setting_callback_group_cover_image_uploads() {
 273  ?>
 274      <input id="bp-disable-group-cover-image-uploads" name="bp-disable-group-cover-image-uploads" type="checkbox" value="1" <?php checked( ! bp_disable_group_cover_image_uploads() ); ?> />
 275      <label for="bp-disable-group-cover-image-uploads"><?php _e( 'Allow customizable cover images for groups', 'buddypress' ); ?></label>
 276  <?php
 277  }
 278  
 279  /** Settings Page *************************************************************/
 280  
 281  /**
 282   * The main settings page
 283   *
 284   * @since 1.6.0
 285   *
 286   */
 287  function bp_core_admin_settings() {
 288  
 289      // We're saving our own options, until the WP Settings API is updated to work with Multisite.
 290      $form_action = add_query_arg( 'page', 'bp-settings', bp_get_admin_url( 'admin.php' ) );
 291  
 292      ?>
 293  
 294      <div class="wrap">
 295  
 296          <h1 class="wp-heading-inline"><?php esc_html_e( 'BuddyPress Settings', 'buddypress' ); ?></h1>
 297          <hr class="wp-header-end">
 298  
 299          <h2 class="nav-tab-wrapper"><?php bp_core_admin_tabs( esc_html__( 'Options', 'buddypress' ) ); ?></h2>
 300  
 301          <form action="<?php echo esc_url( $form_action ) ?>" method="post">
 302  
 303              <?php settings_fields( 'buddypress' ); ?>
 304  
 305              <?php do_settings_sections( 'buddypress' ); ?>
 306  
 307              <p class="submit">
 308                  <input type="submit" name="submit" class="button-primary" value="<?php esc_attr_e( 'Save Settings', 'buddypress' ); ?>" />
 309              </p>
 310          </form>
 311      </div>
 312  
 313  <?php
 314  }
 315  
 316  /**
 317   * Save our settings.
 318   *
 319   * @since 1.6.0
 320   */
 321  function bp_core_admin_settings_save() {
 322      global $wp_settings_fields;
 323  
 324      if ( isset( $_GET['page'] ) && 'bp-settings' == $_GET['page'] && !empty( $_POST['submit'] ) ) {
 325          check_admin_referer( 'buddypress-options' );
 326  
 327          // Because many settings are saved with checkboxes, and thus will have no values
 328          // in the $_POST array when unchecked, we loop through the registered settings.
 329          if ( isset( $wp_settings_fields['buddypress'] ) ) {
 330              foreach( (array) $wp_settings_fields['buddypress'] as $section => $settings ) {
 331                  foreach( $settings as $setting_name => $setting ) {
 332                      $value = isset( $_POST[$setting_name] ) ? $_POST[$setting_name] : '';
 333  
 334                      bp_update_option( $setting_name, $value );
 335                  }
 336              }
 337          }
 338  
 339          // Some legacy options are not registered with the Settings API, or are reversed in the UI.
 340          $legacy_options = array(
 341              'bp-disable-account-deletion',
 342              'bp-disable-avatar-uploads',
 343              'bp-disable-cover-image-uploads',
 344              'bp-disable-group-avatar-uploads',
 345              'bp-disable-group-cover-image-uploads',
 346              'bp_disable_blogforum_comments',
 347              'bp-disable-profile-sync',
 348              'bp_restrict_group_creation',
 349              'hide-loggedout-adminbar',
 350          );
 351  
 352          foreach( $legacy_options as $legacy_option ) {
 353              // Note: Each of these options is represented by its opposite in the UI
 354              // Ie, the Profile Syncing option reads "Enable Sync", so when it's checked,
 355              // the corresponding option should be unset.
 356              $value = isset( $_POST[$legacy_option] ) ? '' : 1;
 357              bp_update_option( $legacy_option, $value );
 358          }
 359  
 360          bp_core_redirect( add_query_arg( array( 'page' => 'bp-settings', 'updated' => 'true' ), bp_get_admin_url( 'admin.php' ) ) );
 361      }
 362  }
 363  add_action( 'bp_admin_init', 'bp_core_admin_settings_save', 100 );
 364  
 365  /**
 366   * Output settings API option.
 367   *
 368   * @since 1.6.0
 369   *
 370   * @param string $option  Form option to echo.
 371   * @param string $default Form option default.
 372   * @param bool   $slug    Form option slug.
 373   */
 374  function bp_form_option( $option, $default = '' , $slug = false ) {
 375      echo bp_get_form_option( $option, $default, $slug );
 376  }
 377      /**
 378       * Return settings API option
 379       *
 380       * @since 1.6.0
 381       *
 382       *
 383       * @param string $option  Form option to return.
 384       * @param string $default Form option default.
 385       * @param bool   $slug    Form option slug.
 386       * @return string
 387       */
 388  	function bp_get_form_option( $option, $default = '', $slug = false ) {
 389  
 390          // Get the option and sanitize it.
 391          $value = bp_get_option( $option, $default );
 392  
 393          // Slug?
 394          if ( true === $slug ) {
 395  
 396              /**
 397               * Filters the slug value in the form field.
 398               *
 399               * @since 1.6.0
 400               *
 401               * @param string $value Value being returned for the requested option.
 402               */
 403              $value = esc_attr( apply_filters( 'editable_slug', $value ) );
 404          } else { // Not a slug.
 405              $value = esc_attr( $value );
 406          }
 407  
 408          // Fallback to default.
 409          if ( empty( $value ) )
 410              $value = $default;
 411  
 412          /**
 413           * Filters the settings API option.
 414           *
 415           * @since 1.6.0
 416           *
 417           * @param string $value  Value being returned for the requested option.
 418           * @param string $option Option whose value is being requested.
 419           */
 420          return apply_filters( 'bp_get_form_option', $value, $option );
 421      }


Generated: Mon Jun 21 01:01:38 2021 Cross-referenced by PHPXref 0.7.1