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


Generated: Fri Jul 19 01:01:43 2019 Cross-referenced by PHPXref 0.7.1