[ 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 esc_url( get_permalink( $existing_pages[$name] ) ); ?>" class="button-secondary" target="_bp">
 149                                      <?php _e( 'View', 'buddypress' ); ?> <span class="dashicons dashicons-external" aria-hidden="true"></span>
 150                                      <span class="screen-reader-text"><?php esc_html_e( '(opens in a new tab)', 'buddypress' ); ?></span>
 151                                  </a>
 152  
 153                              <?php endif; ?>
 154  
 155                              <?php if ( ! bp_is_root_blog() ) restore_current_blog(); ?>
 156  
 157                          </td>
 158                      </tr>
 159  
 160  
 161                  <?php endforeach ?>
 162  
 163                  <?php
 164  
 165                  /**
 166                   * Fires after the display of default directories.
 167                   *
 168                   * Allows plugins to add their own directory associations.
 169                   *
 170                   * @since 1.5.0
 171                   */
 172                  do_action( 'bp_active_external_directories' ); ?>
 173  
 174              </tbody>
 175          </table>
 176  
 177      <?php
 178  
 179      endif;
 180  
 181      /** Static Display ********************************************************/
 182  
 183      $static_pages = bp_core_admin_get_static_pages();
 184  
 185      if ( !empty( $static_pages ) ) : ?>
 186  
 187          <h3><?php _e( 'Registration', 'buddypress' ); ?></h3>
 188  
 189          <?php if ( bp_get_signup_allowed() ) : ?>
 190              <p><?php _e( 'Associate WordPress Pages with the following BuddyPress Registration pages.', 'buddypress' ); ?></p>
 191          <?php else : ?>
 192              <?php if ( is_multisite() ) : ?>
 193                  <p>
 194                      <?php
 195                      /* translators: %s: the link to the Network settings page */
 196                      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' ) );
 197                      ?>
 198                  </p>
 199              <?php else : ?>
 200                  <p>
 201                      <?php
 202                      /* translators: %s: the link to the Site settings page */
 203                      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' ) );
 204                      ?>
 205                  </p>
 206              <?php endif; ?>
 207          <?php endif; ?>
 208  
 209          <table class="form-table">
 210              <tbody>
 211  
 212                  <?php if ( bp_get_signup_allowed() ) : foreach ( $static_pages as $name => $label ) : ?>
 213  
 214                      <tr valign="top">
 215                          <th scope="row">
 216                              <label for="bp_pages[<?php echo esc_attr( $name ) ?>]"><?php echo esc_html( $label ) ?></label>
 217                          </th>
 218  
 219                          <td>
 220  
 221                              <?php if ( ! bp_is_root_blog() ) switch_to_blog( bp_get_root_blog_id() ); ?>
 222  
 223                              <?php echo wp_dropdown_pages( array(
 224                                  'name'             => 'bp_pages[' . esc_attr( $name ) . ']',
 225                                  'echo'             => false,
 226                                  'show_option_none' => __( '- None -', 'buddypress' ),
 227                                  'selected'         => !empty( $existing_pages[$name] ) ? $existing_pages[$name] : false
 228                              ) ) ?>
 229  
 230                              <?php if ( !empty( $existing_pages[$name] ) ) : ?>
 231  
 232                                  <a href="<?php echo get_permalink( $existing_pages[$name] ); ?>" class="button-secondary" target="_bp"><?php _e( 'View', 'buddypress' ); ?></a>
 233  
 234                              <?php endif; ?>
 235  
 236                              <?php if ( ! bp_is_root_blog() ) restore_current_blog(); ?>
 237  
 238                          </td>
 239                      </tr>
 240  
 241                  <?php endforeach; endif; ?>
 242  
 243                  <?php
 244  
 245                  /**
 246                   * Fires after the display of default static pages for BuddyPress setup.
 247                   *
 248                   * @since 1.5.0
 249                   */
 250                  do_action( 'bp_active_external_pages' ); ?>
 251  
 252              </tbody>
 253          </table>
 254  
 255          <?php
 256      endif;
 257  }
 258  
 259  /**
 260   * Handle saving of the BuddyPress slugs.
 261   *
 262   * @since 1.6.0
 263   * @todo Use settings API
 264   */
 265  function bp_core_admin_slugs_setup_handler() {
 266  
 267      if ( isset( $_POST['bp-admin-pages-submit'] ) ) {
 268          if ( !check_admin_referer( 'bp-admin-pages-setup' ) )
 269              return false;
 270  
 271          // Then, update the directory pages.
 272          if ( isset( $_POST['bp_pages'] ) ) {
 273              $valid_pages = array_merge( bp_core_admin_get_directory_pages(), bp_core_admin_get_static_pages() );
 274  
 275              $new_directory_pages = array();
 276              foreach ( (array) $_POST['bp_pages'] as $key => $value ) {
 277                  if ( isset( $valid_pages[ $key ] ) ) {
 278                      $new_directory_pages[ $key ] = (int) $value;
 279                  }
 280              }
 281              bp_core_update_directory_page_ids( $new_directory_pages );
 282          }
 283  
 284          $base_url = bp_get_admin_url( add_query_arg( array( 'page' => 'bp-page-settings', 'updated' => 'true' ), 'admin.php' ) );
 285  
 286          wp_redirect( $base_url );
 287      }
 288  }
 289  add_action( 'bp_admin_init', 'bp_core_admin_slugs_setup_handler' );


Generated: Wed Aug 12 01:01:32 2020 Cross-referenced by PHPXref 0.7.1