Skip to:
Content

BuddyPress.org

Changeset 13431


Ignore:
Timestamp:
02/24/2023 09:37:44 AM (12 months 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

Location:
trunk
Files:
1 added
17 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-blogs/bp-blogs-functions.php

    r13405 r13431  
    117117
    118118        // Truncate user blogs table.
    119         $truncate = $wpdb->query( "TRUNCATE {$bp->blogs->table_name}" );
     119        if ( $bp->is_phpunit_running ) {
     120            $query_part = 'DELETE FROM';
     121        } else {
     122            $query_part = 'TRUNCATE';
     123        }
     124
     125        $truncate = $wpdb->query( "{$query_part} {$bp->blogs->table_name}" );
    120126        if ( is_wp_error( $truncate ) ) {
    121127            return false;
     
    123129
    124130        // Truncate user blogmeta table.
    125         $truncate = $wpdb->query( "TRUNCATE {$bp->blogs->table_name_blogmeta}" );
     131        $truncate = $wpdb->query( "{$query_part} {$bp->blogs->table_name_blogmeta}" );
    126132        if ( is_wp_error( $truncate ) ) {
    127133            return false;
  • trunk/src/bp-core/admin/bp-core-admin-functions.php

    r13395 r13431  
    310310
    311311    if ( ! empty( $orphaned_components ) ) {
    312         $admin_url = bp_get_admin_url( add_query_arg( array( 'page' => 'bp-page-settings' ), 'admin.php' ) );
    313         $notice    = sprintf(
    314             '%1$s <a href="%2$s">%3$s</a>',
    315             sprintf(
    316                 // Translators: %s is the comma separated list of components needing a directory page.
    317                 __( 'The following active BuddyPress Components do not have associated WordPress Pages: %s.', 'buddypress' ),
    318                 '<strong>' . implode( '</strong>, <strong>', array_map( 'esc_html', $orphaned_components ) ) . '</strong>'
    319             ),
    320             esc_url( $admin_url ),
    321             __( 'Repair', 'buddypress' )
     312        $notice = sprintf(
     313            // Translators: %s is the comma separated list of components needing a directory page.
     314            __( 'The following active BuddyPress Components do not have associated BuddyPress Pages: %s.', 'buddypress' ),
     315            '<strong>' . implode( '</strong>, <strong>', array_map( 'esc_html', $orphaned_components ) ) . '</strong>'
    322316        );
    323317
     
    341335    // If there are duplicates, post a message about them.
    342336    if ( ! empty( $dupe_names ) ) {
    343         $admin_url = bp_get_admin_url( add_query_arg( array( 'page' => 'bp-page-settings' ), 'admin.php' ) );
    344         $notice    = sprintf(
    345             '%1$s <a href="%2$s">%3$s</a>',
    346             sprintf(
    347                 // Translators: %s is the list of directory pages associated to more than one component.
    348                 __( 'Each BuddyPress Component needs its own WordPress page. The following WordPress Pages have more than one component associated with them: %s.', 'buddypress' ),
    349                 '<strong>' . implode( '</strong>, <strong>', array_map( 'esc_html', $dupe_names ) ) . '</strong>'
    350             ),
    351             esc_url( $admin_url ),
    352             __( 'Repair', 'buddypress' )
     337        $notice = ssprintf(
     338            // Translators: %s is the list of directory pages associated to more than one component.
     339            __( 'Each BuddyPress Component needs its own BuddyPress page. The following BuddyPress Pages have more than one component associated with them: %s.', 'buddypress' ),
     340            '<strong>' . implode( '</strong>, <strong>', array_map( 'esc_html', $dupe_names ) ) . '</strong>'
    353341        );
    354342
     
    506494            'href' => bp_get_admin_url( add_query_arg( array( 'page' => 'bp-settings' ), 'admin.php' ) ),
    507495            'name' => __( 'Options', 'buddypress' ),
    508         ),
    509         '1' => array(
    510             'id'   => 'bp-page-settings',
    511             'href' => bp_get_admin_url( add_query_arg( array( 'page' => 'bp-page-settings' ), 'admin.php' ) ),
    512             'name' => __( 'Pages', 'buddypress' ),
    513496        ),
    514497        '3' => array(
  • 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' ) );
  • trunk/src/bp-core/bp-core-actions.php

    r13306 r13431  
    7070 */
    7171add_action( 'bp_init', 'bp_register_post_types',     2  );
     72add_action( 'bp_init', 'bp_register_post_statuses',  2  );
    7273add_action( 'bp_init', 'bp_register_taxonomies',     2  );
    7374add_action( 'bp_init', 'bp_core_set_uri_globals',    2  );
  • trunk/src/bp-core/bp-core-dependency.php

    r13418 r13431  
    124124     */
    125125    do_action( 'bp_register_post_types' );
     126}
     127
     128/**
     129 * Fire the 'bp_register_post_statuses' action, where plugins should register post statuses.
     130 *
     131 * @since 12.0.0
     132 */
     133function bp_register_post_statuses() {
     134
     135    /**
     136     * Fires inside the 'bp_register_post_statuses' function, where plugins should register post statuses.
     137     *
     138     * @since 12.0.0
     139     */
     140    do_action( 'bp_register_post_statuses' );
    126141}
    127142
  • trunk/src/bp-core/bp-core-functions.php

    r13377 r13431  
    698698
    699699/**
     700 * Get the directory pages post type.
     701 *
     702 * @since 12.0.0
     703 *
     704 * @return string The post type to use for directory pages.
     705 */
     706function bp_core_get_directory_post_type() {
     707    $post_type = 'buddypress';
     708
     709    /**
     710     * Filter here to edit the post type to use for directory pages.
     711     *
     712     * @since 12.0.0
     713     *
     714     * @param string $post_type The post type to use for directory pages.
     715     */
     716    return apply_filters( 'bp_core_get_directory_post_type', $post_type );
     717}
     718
     719/**
    700720 * Get names and slugs for BuddyPress component directory pages.
    701721 *
     
    834854    // Create the pages.
    835855    foreach ( $pages_to_create as $component_name => $page_name ) {
    836         $exists = get_page_by_path( $component_name );
     856        $existing_id = bp_core_get_directory_page_id( $component_name );
    837857
    838858        // If page already exists, use it.
    839         if ( ! empty( $exists ) ) {
    840             $pages[ $component_name ] = $exists->ID;
     859        if ( ! empty( $existing_id ) ) {
     860            $pages[ $component_name ] = (int) $existing_id;
    841861        } else {
    842862            $pages[ $component_name ] = wp_insert_post( array(
     
    845865                'post_status'    => 'publish',
    846866                'post_title'     => $page_name,
    847                 'post_type'      => 'page',
     867                'post_type'      => bp_core_get_directory_post_type(),
    848868            ) );
    849869        }
     
    887907
    888908/**
     909 * Make sure Components directory page `post_name` are unique.
     910 *
     911 * Goal is to avoid a slug conflict between a Page and a Component's directory page `post_name`.
     912 *
     913 * @since 12.0.0
     914 *
     915 * @param string $slug          The post slug.
     916 * @param int    $post_ID       Post ID.
     917 * @param string $post_status   The post status.
     918 * @param string $post_type     Post type.
     919 * @param int    $post_parent   Post parent ID.
     920 * @param string $original_slug The original post slug.
     921 */
     922function bp_core_set_unique_directory_page_slug( $slug = '', $post_ID = 0, $post_status = '', $post_type = '', $post_parent = 0, $original_slug = '' ) {
     923    if ( ( 'buddypress' === $post_type || 'page' === $post_type ) && $slug === $original_slug ) {
     924        $pages = get_posts(
     925            array(
     926                'post__not_in' => array( $post_ID ),
     927                'post_status'  => array( 'publish', 'bp_restricted' ),
     928                'post_type'    => array( 'buddypress', 'page' ),
     929            )
     930        );
     931
     932        $illegal_names = wp_list_pluck( $pages, 'post_name' );
     933        if ( is_multisite() && ! is_subdomain_install() ) {
     934            $current_site = get_current_site();
     935            $site         = get_site_by_path( $current_site->domain, trailingslashit( $current_site->path ) . $slug );
     936
     937            if ( isset( $site->blog_id ) && 1 !== $site->blog_id ) {
     938                $illegal_names[] = $slug;
     939            }
     940        }
     941
     942        if ( in_array( $slug, $illegal_names, true ) ) {
     943            $suffix = 2;
     944            do {
     945                $alt_post_name   = _truncate_post_slug( $slug, 200 - ( strlen( $suffix ) + 1 ) ) . "-$suffix";
     946                $post_name_check = in_array( $alt_post_name, $illegal_names, true );
     947                $suffix++;
     948            } while ( $post_name_check );
     949            $slug = $alt_post_name;
     950        }
     951    }
     952
     953    return $slug;
     954}
     955add_filter( 'wp_unique_post_slug', 'bp_core_set_unique_directory_page_slug', 10, 6 );
     956
     957/**
    889958 * Remove the entry from bp_pages when the corresponding WP page is deleted.
    890959 *
     
    914983}
    915984add_action( 'delete_post', 'bp_core_on_directory_page_delete' );
    916 
    917 /**
    918  * Create a default component slug from a WP page root_slug.
    919  *
    920  * Since 1.5, BP components get their root_slug (the slug used immediately
    921  * following the root domain) from the slug of a corresponding WP page.
    922  *
    923  * E.g. if your BP installation at example.com has its members page at
    924  * example.com/community/people, $bp->members->root_slug will be
    925  * 'community/people'.
    926  *
    927  * By default, this function creates a shorter version of the root_slug for
    928  * use elsewhere in the URL, by returning the content after the final '/'
    929  * in the root_slug ('people' in the example above).
    930  *
    931  * Filter on 'bp_core_component_slug_from_root_slug' to override this method
    932  * in general, or define a specific component slug constant (e.g.
    933  * BP_MEMBERS_SLUG) to override specific component slugs.
    934  *
    935  * @since 1.5.0
    936  *
    937  * @param string $root_slug The root slug, which comes from $bp->pages->[component]->slug.
    938  * @return string The short slug for use in the middle of URLs.
    939  */
    940 function bp_core_component_slug_from_root_slug( $root_slug ) {
    941     $slug_chunks = explode( '/', $root_slug );
    942     $slug        = array_pop( $slug_chunks );
    943 
    944     /**
    945      * Filters the default component slug from a WP page root_slug.
    946      *
    947      * @since 1.5.0
    948      *
    949      * @param string $slug      Short slug for use in the middle of URLs.
    950      * @param string $root_slug The root slug which comes from $bp->pages-[component]->slug.
    951      */
    952     return apply_filters( 'bp_core_component_slug_from_root_slug', $slug, $root_slug );
    953 }
    954 
    955 /**
    956  * Add support for a top-level ("root") component.
    957  *
    958  * This function originally (pre-1.5) let plugins add support for pages in the
    959  * root of the install. These root level pages are now handled by actual
    960  * WordPress pages and this function is now a convenience for compatibility
    961  * with the new method.
    962  *
    963  * @since 1.0.0
    964  *
    965  * @param string $slug The slug of the component being added to the root list.
    966  */
    967 function bp_core_add_root_component( $slug ) {
    968     $bp = buddypress();
    969 
    970     if ( empty( $bp->pages ) ) {
    971         $bp->pages = bp_core_get_directory_pages();
    972     }
    973 
    974     $match = false;
    975 
    976     // Check if the slug is registered in the $bp->pages global.
    977     foreach ( (array) $bp->pages as $key => $page ) {
    978         if ( $key == $slug || $page->slug == $slug ) {
    979             $match = true;
    980         }
    981     }
    982 
    983     // Maybe create the add_root array.
    984     if ( empty( $bp->add_root ) ) {
    985         $bp->add_root = array();
    986     }
    987 
    988     // If there was no match, add a page for this root component.
    989     if ( empty( $match ) ) {
    990         $add_root_items   = $bp->add_root;
    991         $add_root_items[] = $slug;
    992         $bp->add_root     = $add_root_items;
    993     }
    994 
    995     // Make sure that this component is registered as requiring a top-level directory.
    996     if ( isset( $bp->{$slug} ) ) {
    997         $bp->loaded_components[$bp->{$slug}->slug] = $bp->{$slug}->id;
    998         $bp->{$slug}->has_directory = true;
    999     }
    1000 }
    1001 
    1002 /**
    1003  * Create WordPress pages to be used as BP component directories.
    1004  *
    1005  * @since 1.5.0
    1006  */
    1007 function bp_core_create_root_component_page() {
    1008 
    1009     // Get BuddyPress.
    1010     $bp = buddypress();
    1011 
    1012     $new_page_ids = array();
    1013 
    1014     foreach ( (array) $bp->add_root as $slug ) {
    1015         $new_page_ids[ $slug ] = wp_insert_post( array(
    1016             'comment_status' => 'closed',
    1017             'ping_status'    => 'closed',
    1018             'post_title'     => ucwords( $slug ),
    1019             'post_status'    => 'publish',
    1020             'post_type'      => 'page'
    1021         ) );
    1022     }
    1023 
    1024     $page_ids = array_merge( $new_page_ids, bp_core_get_directory_page_ids( 'all' ) );
    1025     bp_core_update_directory_page_ids( $page_ids );
    1026 }
    1027985
    1028986/**
     
    48204778        '10.0',
    48214779        '11.0',
     4780        '12.0',
    48224781    );
    48234782
     
    48924851    return $latest_deprecated_functions_versions;
    48934852}
     4853
     4854/**
     4855 * Get the BuddyPress Post Type site ID.
     4856 *
     4857 * @since 12.0.0
     4858 *
     4859 * @return int The site ID the BuddyPress Post Type should be registered on.
     4860 */
     4861function bp_get_post_type_site_id() {
     4862    $site_id = bp_get_root_blog_id();
     4863
     4864    /**
     4865     * Filter here to edit the site ID.
     4866     *
     4867     * @todo This will need to be improved to take in account
     4868     * specific configurations like multiblog.
     4869     *
     4870     * @since 12.0.0
     4871     *
     4872     * @param integer $site_id The site ID to register the post type on.
     4873     */
     4874    return (int) apply_filters( 'bp_get_post_type_site_id', $site_id );
     4875}
  • trunk/src/bp-core/bp-core-update.php

    r13395 r13431  
    292292        }
    293293
     294        // Version 12.0.0.
     295        if ( $raw_db_version < 13422 ){
     296            bp_update_to_12_0();
     297        }
    294298    }
    295299
     
    792796
    793797    return $new_emails;
     798}
     799
     800/**
     801 * 12.0.0 update routine.
     802 *
     803 * - Swith directory page post type from "page" to "buddypress".
     804 *
     805 * @since 12.0.0
     806 */
     807function bp_update_to_12_0() {
     808    $post_type = bp_core_get_directory_post_type();
     809
     810    if ( 'page' !== $post_type ) {
     811        $directory_pages   = bp_core_get_directory_pages();
     812        $nav_menu_item_ids = array();
     813
     814        // Do not check post slugs nor post types.
     815        remove_filter( 'wp_unique_post_slug', 'bp_core_set_unique_directory_page_slug', 10 );
     816
     817        // Update Directory pages post types.
     818        foreach ( $directory_pages as $directory_page ) {
     819            $nav_menu_item_ids[] = $directory_page->id;
     820
     821            // Switch the post type.
     822            wp_update_post(
     823                array(
     824                    'ID'          => $directory_page->id,
     825                    'post_type'   => $post_type,
     826                    'post_status' => 'publish',
     827                )
     828            );
     829        }
     830
     831        // Update nav menu items!
     832        $nav_menus = wp_get_nav_menus( array( 'hide_empty' => true ) );
     833        foreach ( $nav_menus as $nav_menu ) {
     834            $items = wp_get_nav_menu_items( $nav_menu->term_id );
     835            foreach ( $items as $item ) {
     836                if ( 'page' !== $item->object || ! in_array( $item->object_id, $nav_menu_item_ids, true ) ) {
     837                    continue;
     838                }
     839
     840                wp_update_nav_menu_item(
     841                    $nav_menu->term_id,
     842                    $item->ID,
     843                    array(
     844                        'menu-item-db-id'       => $item->db_id,
     845                        'menu-item-object-id'   => $item->object_id,
     846                        'menu-item-object'      => $post_type,
     847                        'menu-item-parent-id'   => $item->menu_item_parent,
     848                        'menu-item-position'    => $item->menu_order,
     849                        'menu-item-type'        => 'post_type',
     850                        'menu-item-title'       => $item->title,
     851                        'menu-item-url'         => $item->url,
     852                        'menu-item-description' => $item->description,
     853                        'menu-item-attr-title'  => $item->attr_title,
     854                        'menu-item-target'      => $item->target,
     855                        'menu-item-classes'     => implode( ' ', (array) $item->classes ),
     856                        'menu-item-xfn'         => $item->xfn,
     857                        'menu-item-status'      => 'publish',
     858                    )
     859                );
     860            }
     861        }
     862
     863        // Finally make sure to rebuilt permalinks at next page load.
     864        delete_option( 'rewrite_rules' );
     865    }
    794866}
    795867
  • trunk/src/bp-core/classes/class-bp-admin.php

    r13414 r13431  
    147147        require( $this->admin_dir . 'bp-core-admin-functions.php'  );
    148148        require( $this->admin_dir . 'bp-core-admin-components.php' );
    149         require( $this->admin_dir . 'bp-core-admin-slugs.php'      );
    150149        require( $this->admin_dir . 'bp-core-admin-tools.php'      );
    151150        require( $this->admin_dir . 'bp-core-admin-optouts.php'    );
     
    275274        $this->submenu_pages['settings']['bp-components'] = $bp_components_page;
    276275        $hooks[]                                          = $bp_components_page;
    277 
    278         $bp_page_settings_page = add_submenu_page(
    279             $this->settings_page,
    280             __( 'BuddyPress Pages', 'buddypress' ),
    281             __( 'BuddyPress Pages', 'buddypress' ),
    282             $this->capability,
    283             'bp-page-settings',
    284             'bp_core_admin_slugs_settings'
    285         );
    286 
    287         $this->submenu_pages['settings']['bp-page-settings'] = $bp_page_settings_page;
    288         $hooks[]                                             = $bp_page_settings_page;
    289276
    290277        $bp_settings_page = add_submenu_page(
     
    627614
    628615        // Settings pages.
    629         remove_submenu_page( $this->settings_page, 'bp-page-settings' );
    630616        remove_submenu_page( $this->settings_page, 'bp-settings'      );
    631617        remove_submenu_page( $this->settings_page, 'bp-credits'       );
  • trunk/src/bp-core/classes/class-bp-component.php

    r13422 r13431  
    543543        add_action( 'bp_register_post_types',    array( $this, 'register_post_types'    ), 10 );
    544544
     545        // Register post statuses.
     546        add_action( 'bp_register_post_statuses', array( $this, 'register_post_statuses' ), 10 );
     547
    545548        // Register taxonomies.
    546549        add_action( 'bp_register_taxonomies',    array( $this, 'register_taxonomies'    ), 10 );
     
    856859         */
    857860        do_action( 'bp_' . $this->id . '_register_post_types' );
     861    }
     862
     863    /**
     864     * Set up the component post statuses.
     865     *
     866     * @since 12.0.0
     867     */
     868    public function register_post_statuses() {
     869
     870        /**
     871         * Fires in the `register_post_statuses` method inside BP_Component.
     872         *
     873         * This is a dynamic hook that is based on the component string ID.
     874         *
     875         * @since 12.0.0
     876         */
     877        do_action( 'bp_' . $this->id . '_register_post_statuses' );
    858878    }
    859879
  • trunk/src/bp-core/classes/class-bp-core.php

    r13414 r13431  
    324324     * Set up post types.
    325325     *
    326      * @since BuddyPress (2.4.0)
     326     * @since 2.4.0
     327     * @since 12.0.0 Registers the 'buddypress' post type for component directories.
    327328     */
    328329    public function register_post_types() {
    329 
    330         // Emails
     330        // Component directories.
     331        if ( (int) get_current_blog_id() === bp_get_post_type_site_id() ) {
     332            register_post_type(
     333                'buddypress',
     334                array(
     335                    'label'               => _x( 'BuddyPress Directories', 'Post Type label', 'buddypress' ),
     336                    'labels'              => array(
     337                        'singular_name' => _x( 'BuddyPress Directory', 'Post Type singular name', 'buddypress' ),
     338                    ),
     339                    'description'         => __( 'The BuddyPress Post Type used for component directories.', 'buddypress' ),
     340                    'public'              => false,
     341                    'hierarchical'        => true,
     342                    'exclude_from_search' => true,
     343                    'publicly_queryable'  => false,
     344                    'show_ui'             => false,
     345                    'show_in_nav_menus'   => true,
     346                    'show_in_rest'        => false,
     347                    'supports'            => array( 'title' ),
     348                    'has_archive'         => false,
     349                    'rewrite'             => false,
     350                    'query_var'           => false,
     351                    'delete_with_user'    => false,
     352                )
     353            );
     354        }
     355
     356        // Emails.
    331357        if ( bp_is_root_blog() && ! is_network_admin() ) {
    332358            register_post_type(
     
    357383
    358384        parent::register_post_types();
     385    }
     386
     387    /**
     388     * Set up the component post statuses.
     389     *
     390     * @since 12.0.0
     391     */
     392    public function register_post_statuses() {
     393        register_post_status(
     394            'bp_restricted',
     395            array(
     396                'label'    => _x( 'Restricted to members', '`buddypress` post type post status', 'buddypress' ),
     397                'public'   => false,
     398                'internal' => true,
     399            )
     400        );
     401
     402        parent::register_post_statuses();
    359403    }
    360404
  • trunk/src/class-buddypress.php

    r13422 r13431  
    442442
    443443        $this->version    = '12.0.0-alpha';
    444         $this->db_version = 13271;
     444        $this->db_version = 13422;
    445445
    446446        /** Loading */
  • trunk/tests/phpunit/testcases/core/functions.php

    r13417 r13431  
    566566        restore_current_blog();
    567567
    568         $this->assertFalse( wp_cache_get( 'directory_pages', 'bp' ) );
     568        $this->assertFalse( wp_cache_get( 'directory_pages', 'bp_pages' ) );
    569569    }
    570570
     
    631631
    632632    /**
    633      * @group bp_core_add_root_component
    634      */
    635     public function test_add_root_component_not_in_bp_pages() {
    636         buddypress()->foo = new stdClass;
    637         buddypress()->foo->id = 'foo';
    638         buddypress()->foo->slug = 'foo';
    639 
    640         bp_core_add_root_component( 'foo' );
    641 
    642         $this->assertTrue( in_array( 'foo', buddypress()->add_root ) );
    643         $this->assertTrue( buddypress()->foo->has_directory );
    644         $this->assertNotEmpty( buddypress()->loaded_components['foo'] );
    645     }
    646 
    647     /**
    648633     * @group bp_core_time_since
    649634     * @group bp_core_current_time
     
    841826    /**
    842827     * @group bp_core_add_page_mappings
    843      * @ticket 8187
     828     * @ticket BP8187
    844829     */
    845830    public function test_bp_core_add_page_mappings_in_multisite_subdirectory() {
  • trunk/tests/phpunit/testcases/core/functions/bpCoreGetDirectoryPageIds.php

    r13159 r13431  
    250250        bp_update_option( 'bp-pages', 'foo' );
    251251
    252         $this->assertFalse( wp_cache_get( 'directory_pages', 'bp' ) );
     252        $this->assertFalse( wp_cache_get( 'directory_pages', 'bp_pages' ) );
    253253
    254254        bp_update_option( 'bp-pages', $v );
  • trunk/tests/phpunit/testcases/members/functions.php

    r13414 r13431  
    124124        $pages = bp_core_get_directory_pages();
    125125        $members_page = get_post( $pages->members->id );
    126         $members_page->post_name = 'new-members-slug';
    127         wp_update_post( $members_page );
     126        $new_members_slug = 'new-members-slug';
     127        $members_page->post_name = $new_members_slug;
     128        $p = wp_update_post( $members_page );
     129
     130        // Weird!
     131        if ( is_multisite() ) {
     132            $new_members_slug = get_post_field( 'post_name', $p );
     133        }
    128134
    129135        // Go back to members directory page and recheck user domain
    130         $this->go_to( trailingslashit( home_url( 'new-members-slug' ) ) );
     136        $this->go_to( trailingslashit( home_url( $new_members_slug ) ) );
    131137        $user = new WP_User( $user_id );
    132138
    133         $this->assertSame( home_url( 'new-members-slug' ) . '/' . $user->user_nicename . '/', bp_core_get_user_domain( $user_id ) );
     139        $this->assertSame( home_url( $new_members_slug ) . '/' . $user->user_nicename . '/', bp_core_get_user_domain( $user_id ) );
    134140    }
    135141
  • trunk/tests/phpunit/testcases/routing/activity.php

    r13314 r13431  
    2121    function test_activity_directory() {
    2222        $this->go_to( bp_get_activity_directory_permalink() );
    23         $this->assertEquals( bp_get_activity_root_slug(), bp_current_component() );
     23
     24        $pages        = bp_core_get_directory_pages();
     25        $component_id = bp_current_component();
     26
     27        $this->assertEquals( bp_get_activity_root_slug(), $pages->{$component_id}->slug );
    2428    }
    2529
  • trunk/tests/phpunit/testcases/routing/members.php

    r13314 r13431  
    2222    function test_members_directory() {
    2323        $this->go_to( bp_get_members_directory_permalink() );
    24         $this->assertEquals( bp_get_members_root_slug(), bp_current_component() );
     24
     25        $pages        = bp_core_get_directory_pages();
     26        $component_id = bp_current_component();
     27
     28        $this->assertEquals( bp_get_members_root_slug(), $pages->{$component_id}->slug );
    2529    }
    2630
     
    2832        $this->go_to( bp_core_get_user_domain( bp_loggedin_user_id() ) );
    2933        $this->assertTrue( bp_is_my_profile() );
    30     }
    31 
    32     /**
    33      * @ticket BP6475
    34      */
    35     public function test_member_directory_when_nested_under_wp_page() {
    36         $p = self::factory()->post->create( array(
    37             'post_type' => 'page',
    38             'post_name' => 'foo',
    39         ) );
    40 
    41         $members_page = get_page_by_path( 'members' );
    42 
    43         wp_update_post( array(
    44             'ID' => $members_page->ID,
    45             'post_parent' => $p,
    46         ) );
    47 
    48         $members_page_permalink = bp_get_root_domain() . '/foo/members/';
    49         $this->go_to( $members_page_permalink );
    50 
    51         $this->assertTrue( bp_is_members_component() );
    52         $this->assertEquals( '', bp_current_action() );
    5334    }
    5435
  • trunk/tests/phpunit/testcases/routing/root-profiles.php

    r13314 r13431  
    3131    public function test_members_directory() {
    3232        $this->go_to( home_url( bp_get_members_root_slug() ) );
    33         $this->assertEquals( bp_get_members_root_slug(), bp_current_component() );
     33
     34        $pages        = bp_core_get_directory_pages();
     35        $component_id = bp_current_component();
     36
     37        $this->assertEquals( bp_get_members_root_slug(), $pages->{$component_id}->slug );
    3438    }
    3539
     
    5256        ) );
    5357
    54         $members_page = get_page_by_path( 'members' );
     58        $members_page_id = bp_core_get_directory_page_id( 'members' );
    5559        wp_update_post( array(
    56             'ID' => $members_page->ID,
     60            'ID'          => $members_page_id,
    5761            'post_parent' => $p,
    5862        ) );
Note: See TracChangeset for help on using the changeset viewer.