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


Generated: Wed Jul 28 01:01:38 2021 Cross-referenced by PHPXref 0.7.1