[ 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  /** XProfile ******************************************************************/
 186  
 187  /**
 188   * Profile settings section description for the settings page.
 189   *
 190   * @since 1.6.0
 191   */
 192  function bp_admin_setting_callback_xprofile_section() { }
 193  
 194  /**
 195   * Enable BP->WP profile syncing field.
 196   *
 197   * @since 1.6.0
 198   *
 199   */
 200  function bp_admin_setting_callback_profile_sync() {
 201  ?>
 202  
 203      <input id="bp-disable-profile-sync" name="bp-disable-profile-sync" type="checkbox" value="1" <?php checked( !bp_disable_profile_sync( false ) ); ?> />
 204      <label for="bp-disable-profile-sync"><?php _e( 'Enable BuddyPress to WordPress profile syncing', 'buddypress' ); ?></label>
 205  
 206  <?php
 207  }
 208  
 209  /** Groups Section ************************************************************/
 210  
 211  /**
 212   * Groups settings section description for the settings page.
 213   *
 214   * @since 1.6.0
 215   */
 216  function bp_admin_setting_callback_groups_section() { }
 217  
 218  /**
 219   * Allow all users to create groups field.
 220   *
 221   * @since 1.6.0
 222   *
 223   */
 224  function bp_admin_setting_callback_group_creation() {
 225  ?>
 226  
 227      <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 ) ); ?> />
 228      <label for="bp_restrict_group_creation"><?php _e( 'Enable group creation for all users', 'buddypress' ); ?></label>
 229      <p class="description" id="bp_group_creation_description"><?php _e( 'Administrators can always create groups, regardless of this setting.', 'buddypress' ); ?></p>
 230  
 231  <?php
 232  }
 233  
 234  /**
 235   * 'Enable group avatars' field markup.
 236   *
 237   * @since 2.3.0
 238   */
 239  function bp_admin_setting_callback_group_avatar_uploads() {
 240  ?>
 241      <input id="bp-disable-group-avatar-uploads" name="bp-disable-group-avatar-uploads" type="checkbox" value="1" <?php checked( ! bp_disable_group_avatar_uploads() ); ?> />
 242      <label for="bp-disable-group-avatar-uploads"><?php _e( 'Allow customizable avatars for groups', 'buddypress' ); ?></label>
 243  <?php
 244  }
 245  
 246  /**
 247   * 'Enable group cover images' field markup.
 248   *
 249   * @since 2.4.0
 250   */
 251  function bp_admin_setting_callback_group_cover_image_uploads() {
 252  ?>
 253      <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() ); ?> />
 254      <label for="bp-disable-group-cover-image-uploads"><?php _e( 'Allow customizable cover images for groups', 'buddypress' ); ?></label>
 255  <?php
 256  }
 257  
 258  /** Settings Page *************************************************************/
 259  
 260  /**
 261   * The main settings page
 262   *
 263   * @since 1.6.0
 264   *
 265   */
 266  function bp_core_admin_settings() {
 267  
 268      // We're saving our own options, until the WP Settings API is updated to work with Multisite.
 269      $form_action = add_query_arg( 'page', 'bp-settings', bp_get_admin_url( 'admin.php' ) );
 270  
 271      ?>
 272  
 273      <div class="wrap">
 274  
 275          <h1 class="wp-heading-inline"><?php esc_html_e( 'BuddyPress Settings', 'buddypress' ); ?></h1>
 276          <hr class="wp-header-end">
 277  
 278          <h2 class="nav-tab-wrapper"><?php bp_core_admin_tabs( esc_html__( 'Options', 'buddypress' ) ); ?></h2>
 279  
 280          <form action="<?php echo esc_url( $form_action ) ?>" method="post">
 281  
 282              <?php settings_fields( 'buddypress' ); ?>
 283  
 284              <?php do_settings_sections( 'buddypress' ); ?>
 285  
 286              <p class="submit">
 287                  <input type="submit" name="submit" class="button-primary" value="<?php esc_attr_e( 'Save Settings', 'buddypress' ); ?>" />
 288              </p>
 289          </form>
 290      </div>
 291  
 292  <?php
 293  }
 294  
 295  /**
 296   * Save our settings.
 297   *
 298   * @since 1.6.0
 299   */
 300  function bp_core_admin_settings_save() {
 301      global $wp_settings_fields;
 302  
 303      if ( isset( $_GET['page'] ) && 'bp-settings' == $_GET['page'] && !empty( $_POST['submit'] ) ) {
 304          check_admin_referer( 'buddypress-options' );
 305  
 306          // Because many settings are saved with checkboxes, and thus will have no values
 307          // in the $_POST array when unchecked, we loop through the registered settings.
 308          if ( isset( $wp_settings_fields['buddypress'] ) ) {
 309              foreach( (array) $wp_settings_fields['buddypress'] as $section => $settings ) {
 310                  foreach( $settings as $setting_name => $setting ) {
 311                      $value = isset( $_POST[$setting_name] ) ? $_POST[$setting_name] : '';
 312  
 313                      bp_update_option( $setting_name, $value );
 314                  }
 315              }
 316          }
 317  
 318          // Some legacy options are not registered with the Settings API, or are reversed in the UI.
 319          $legacy_options = array(
 320              'bp-disable-account-deletion',
 321              'bp-disable-avatar-uploads',
 322              'bp-disable-cover-image-uploads',
 323              'bp-disable-group-avatar-uploads',
 324              'bp-disable-group-cover-image-uploads',
 325              'bp_disable_blogforum_comments',
 326              'bp-disable-profile-sync',
 327              'bp_restrict_group_creation',
 328              'hide-loggedout-adminbar',
 329          );
 330  
 331          foreach( $legacy_options as $legacy_option ) {
 332              // Note: Each of these options is represented by its opposite in the UI
 333              // Ie, the Profile Syncing option reads "Enable Sync", so when it's checked,
 334              // the corresponding option should be unset.
 335              $value = isset( $_POST[$legacy_option] ) ? '' : 1;
 336              bp_update_option( $legacy_option, $value );
 337          }
 338  
 339          bp_core_redirect( add_query_arg( array( 'page' => 'bp-settings', 'updated' => 'true' ), bp_get_admin_url( 'admin.php' ) ) );
 340      }
 341  }
 342  add_action( 'bp_admin_init', 'bp_core_admin_settings_save', 100 );
 343  
 344  /**
 345   * Output settings API option.
 346   *
 347   * @since 1.6.0
 348   *
 349   * @param string $option  Form option to echo.
 350   * @param string $default Form option default.
 351   * @param bool   $slug    Form option slug.
 352   */
 353  function bp_form_option( $option, $default = '' , $slug = false ) {
 354      echo bp_get_form_option( $option, $default, $slug );
 355  }
 356      /**
 357       * Return settings API option
 358       *
 359       * @since 1.6.0
 360       *
 361       *
 362       * @param string $option  Form option to return.
 363       * @param string $default Form option default.
 364       * @param bool   $slug    Form option slug.
 365       * @return string
 366       */
 367  	function bp_get_form_option( $option, $default = '', $slug = false ) {
 368  
 369          // Get the option and sanitize it.
 370          $value = bp_get_option( $option, $default );
 371  
 372          // Slug?
 373          if ( true === $slug ) {
 374  
 375              /**
 376               * Filters the slug value in the form field.
 377               *
 378               * @since 1.6.0
 379               *
 380               * @param string $value Value being returned for the requested option.
 381               */
 382              $value = esc_attr( apply_filters( 'editable_slug', $value ) );
 383          } else { // Not a slug.
 384              $value = esc_attr( $value );
 385          }
 386  
 387          // Fallback to default.
 388          if ( empty( $value ) )
 389              $value = $default;
 390  
 391          /**
 392           * Filters the settings API option.
 393           *
 394           * @since 1.6.0
 395           *
 396           * @param string $value  Value being returned for the requested option.
 397           * @param string $option Option whose value is being requested.
 398           */
 399          return apply_filters( 'bp_get_form_option', $value, $option );
 400      }


Generated: Fri Nov 27 01:01:40 2020 Cross-referenced by PHPXref 0.7.1