[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

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

   1  <?php
   2  /**
   3   * BuddyPress Admin Slug Functions.
   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   * Renders the page mapping admin panel.
  15   *
  16   * @since 1.6.0
  17   * @todo Use settings API
  18   */
  19  function bp_core_admin_slugs_settings() {
  20  ?>
  21  
  22      <div class="wrap">
  23  
  24          <h1><?php _e( 'BuddyPress Settings', 'buddypress' ); ?> </h1>
  25  
  26          <h2 class="nav-tab-wrapper"><?php bp_core_admin_tabs( __( 'Pages', 'buddypress' ) ); ?></h2>
  27          <form action="" method="post" id="bp-admin-page-form">
  28  
  29              <?php bp_core_admin_slugs_options(); ?>
  30  
  31              <p class="submit clear">
  32                  <input class="button-primary" type="submit" name="bp-admin-pages-submit" id="bp-admin-pages-submit" value="<?php esc_attr_e( 'Save Settings', 'buddypress' ) ?>"/>
  33              </p>
  34  
  35              <?php wp_nonce_field( 'bp-admin-pages-setup' ); ?>
  36  
  37          </form>
  38      </div>
  39  
  40  <?php
  41  }
  42  
  43  /**
  44   * Generate a list of directory pages, for use when building Components panel markup.
  45   *
  46   * @since 2.4.1
  47   *
  48   * @return array
  49   */
  50  function bp_core_admin_get_directory_pages() {
  51      $bp = buddypress();
  52      $directory_pages = array();
  53  
  54      // Loop through loaded components and collect directories.
  55      if ( is_array( $bp->loaded_components ) ) {
  56          foreach( $bp->loaded_components as $component_slug => $component_id ) {
  57  
  58              // Only components that need directories should be listed here.
  59              if ( isset( $bp->{$component_id} ) && !empty( $bp->{$component_id}->has_directory ) ) {
  60  
  61                  // The component->name property was introduced in BP 1.5, so we must provide a fallback.
  62                  $directory_pages[$component_id] = !empty( $bp->{$component_id}->name ) ? $bp->{$component_id}->name : ucwords( $component_id );
  63              }
  64          }
  65      }
  66  
  67      /** Directory Display *****************************************************/
  68  
  69      /**
  70       * Filters the loaded components needing directory page association to a WordPress page.
  71       *
  72       * @since 1.5.0
  73       *
  74       * @param array $directory_pages Array of available components to set associations for.
  75       */
  76      return apply_filters( 'bp_directory_pages', $directory_pages );
  77  }
  78  
  79  /**
  80   * Generate a list of static pages, for use when building Components panel markup.
  81   *
  82   * By default, this list contains 'register' and 'activate'.
  83   *
  84   * @since 2.4.1
  85   *
  86   * @return array
  87   */
  88  function bp_core_admin_get_static_pages() {
  89      $static_pages = array(
  90          'register' => __( 'Register', 'buddypress' ),
  91          'activate' => __( 'Activate', 'buddypress' ),
  92      );
  93  
  94      /**
  95       * Filters the default static pages for BuddyPress setup.
  96       *
  97       * @since 1.6.0
  98       *
  99       * @param array $static_pages Array of static default static pages.
 100       */
 101      return apply_filters( 'bp_static_pages', $static_pages );
 102  }
 103  
 104  /**
 105   * Creates reusable markup for page setup on the Components and Pages dashboard panel.
 106   *
 107   * @package BuddyPress
 108   * @since 1.6.0
 109   * @todo Use settings API
 110   */
 111  function bp_core_admin_slugs_options() {
 112  
 113      // Get the existing WP pages
 114      $existing_pages = bp_core_get_directory_page_ids();
 115  
 116      // Set up an array of components (along with component names) that have directory pages.
 117      $directory_pages = bp_core_admin_get_directory_pages();
 118  
 119      if ( !empty( $directory_pages ) ) : ?>
 120  
 121          <h3><?php _e( 'Directories', 'buddypress' ); ?></h3>
 122  
 123          <p><?php _e( 'Associate a WordPress Page with each BuddyPress component directory.', 'buddypress' ); ?></p>
 124  
 125          <table class="form-table">
 126              <tbody>
 127  
 128                  <?php foreach ( $directory_pages as $name => $label ) : ?>
 129  
 130                      <tr valign="top">
 131                          <th scope="row">
 132                              <label for="bp_pages[<?php echo esc_attr( $name ) ?>]"><?php echo esc_html( $label ) ?></label>
 133                          </th>
 134  
 135                          <td>
 136  
 137                              <?php if ( ! bp_is_root_blog() ) switch_to_blog( bp_get_root_blog_id() ); ?>
 138  
 139                              <?php echo wp_dropdown_pages( array(
 140                                  'name'             => 'bp_pages[' . esc_attr( $name ) . ']',
 141                                  'echo'             => false,
 142                                  'show_option_none' => __( '- None -', 'buddypress' ),
 143                                  'selected'         => !empty( $existing_pages[$name] ) ? $existing_pages[$name] : false
 144                              ) ); ?>
 145  
 146                              <?php if ( !empty( $existing_pages[$name] ) ) : ?>
 147  
 148                                  <a href="<?php echo get_permalink( $existing_pages[$name] ); ?>" class="button-secondary" target="_bp"><?php _e( 'View', 'buddypress' ); ?></a>
 149  
 150                              <?php endif; ?>
 151  
 152                              <?php if ( ! bp_is_root_blog() ) restore_current_blog(); ?>
 153  
 154                          </td>
 155                      </tr>
 156  
 157  
 158                  <?php endforeach ?>
 159  
 160                  <?php
 161  
 162                  /**
 163                   * Fires after the display of default directories.
 164                   *
 165                   * Allows plugins to add their own directory associations.
 166                   *
 167                   * @since 1.5.0
 168                   */
 169                  do_action( 'bp_active_external_directories' ); ?>
 170  
 171              </tbody>
 172          </table>
 173  
 174      <?php
 175  
 176      endif;
 177  
 178      /** Static Display ********************************************************/
 179  
 180      $static_pages = bp_core_admin_get_static_pages();
 181  
 182      if ( !empty( $static_pages ) ) : ?>
 183  
 184          <h3><?php _e( 'Registration', 'buddypress' ); ?></h3>
 185  
 186          <?php if ( bp_get_signup_allowed() ) : ?>
 187              <p><?php _e( 'Associate WordPress Pages with the following BuddyPress Registration pages.', 'buddypress' ); ?></p>
 188          <?php else : ?>
 189              <?php if ( is_multisite() ) : ?>
 190                  <p><?php printf( __( 'Registration is currently disabled.  Before associating a page is allowed, please enable registration by selecting either the "User accounts may be registered" or "Both sites and user accounts can be registered" option on <a href="%s">this page</a>.', 'buddypress' ), network_admin_url( 'settings.php' ) ); ?></p>
 191              <?php else : ?>
 192                  <p><?php printf( __( 'Registration is currently disabled.  Before associating a page is allowed, please enable registration by clicking on the "Anyone can register" checkbox on <a href="%s">this page</a>.', 'buddypress' ), admin_url( 'options-general.php' ) ); ?></p>
 193              <?php endif; ?>
 194          <?php endif; ?>
 195  
 196          <table class="form-table">
 197              <tbody>
 198  
 199                  <?php if ( bp_get_signup_allowed() ) : foreach ( $static_pages as $name => $label ) : ?>
 200  
 201                      <tr valign="top">
 202                          <th scope="row">
 203                              <label for="bp_pages[<?php echo esc_attr( $name ) ?>]"><?php echo esc_html( $label ) ?></label>
 204                          </th>
 205  
 206                          <td>
 207  
 208                              <?php if ( ! bp_is_root_blog() ) switch_to_blog( bp_get_root_blog_id() ); ?>
 209  
 210                              <?php echo wp_dropdown_pages( array(
 211                                  'name'             => 'bp_pages[' . esc_attr( $name ) . ']',
 212                                  'echo'             => false,
 213                                  'show_option_none' => __( '- None -', 'buddypress' ),
 214                                  'selected'         => !empty( $existing_pages[$name] ) ? $existing_pages[$name] : false
 215                              ) ) ?>
 216  
 217                              <?php if ( !empty( $existing_pages[$name] ) ) : ?>
 218  
 219                                  <a href="<?php echo get_permalink( $existing_pages[$name] ); ?>" class="button-secondary" target="_bp"><?php _e( 'View', 'buddypress' ); ?></a>
 220  
 221                              <?php endif; ?>
 222  
 223                              <?php if ( ! bp_is_root_blog() ) restore_current_blog(); ?>
 224  
 225                          </td>
 226                      </tr>
 227  
 228                  <?php endforeach; endif; ?>
 229  
 230                  <?php
 231  
 232                  /**
 233                   * Fires after the display of default static pages for BuddyPress setup.
 234                   *
 235                   * @since 1.5.0
 236                   */
 237                  do_action( 'bp_active_external_pages' ); ?>
 238  
 239              </tbody>
 240          </table>
 241  
 242          <?php
 243      endif;
 244  }
 245  
 246  /**
 247   * Handle saving of the BuddyPress slugs.
 248   *
 249   * @since 1.6.0
 250   * @todo Use settings API
 251   */
 252  function bp_core_admin_slugs_setup_handler() {
 253  
 254      if ( isset( $_POST['bp-admin-pages-submit'] ) ) {
 255          if ( !check_admin_referer( 'bp-admin-pages-setup' ) )
 256              return false;
 257  
 258          // Then, update the directory pages.
 259          if ( isset( $_POST['bp_pages'] ) ) {
 260              $valid_pages = array_merge( bp_core_admin_get_directory_pages(), bp_core_admin_get_static_pages() );
 261  
 262              $new_directory_pages = array();
 263              foreach ( (array) $_POST['bp_pages'] as $key => $value ) {
 264                  if ( isset( $valid_pages[ $key ] ) ) {
 265                      $new_directory_pages[ $key ] = (int) $value;
 266                  }
 267              }
 268              bp_core_update_directory_page_ids( $new_directory_pages );
 269          }
 270  
 271          $base_url = bp_get_admin_url( add_query_arg( array( 'page' => 'bp-page-settings', 'updated' => 'true' ), 'admin.php' ) );
 272  
 273          wp_redirect( $base_url );
 274      }
 275  }
 276  add_action( 'bp_admin_init', 'bp_core_admin_slugs_setup_handler' );


Generated: Wed Jul 24 01:01:43 2019 Cross-referenced by PHPXref 0.7.1