Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
02/24/2023 09:37:44 AM (2 years ago)
Author:
imath
Message:

Use a custom post type instead of the page post type for directories

  • The buddypress post type is now the one used for the BP component

directory page.

  • Introduce the bp_core_set_unique_directory_page_slug() function to

make sure there is no conflict with an existing WP page when setting the
BP Component directory page post_name.

  • Introduce the bp_restricted custom status. We'll be able to use it for

future visibility features.

  • Deprecate the Admin Slugs screen and corresponding functions
  • Bump raw_db_version to 13422 (the first commit about merging BP

Rewrites).

  • Add an update function to update the post type of the existing BP

component directory pages and potential WP Nav Menus including these.

Props r-a-y, johnjamesjacoby, boonebgorges

Closes https://github.com/buddypress/buddypress/pull/67
See #4954

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-core/admin/bp-core-admin-slugs.php

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