Skip to:
Content

BuddyPress.org

Changeset 13468


Ignore:
Timestamp:
05/03/2023 06:18:23 AM (14 months ago)
Author:
imath
Message:

Stop using BP Legacy URL parser in favor of the new BP Rewrites API

  • Deprecate bp_core_set_uri_globals(). This function is moved inside the BP Classic compatibility plugin.
  • Introduce the new bp_register_nav action to hook to when globalizing Members single item navigations from the BP_Component class.
  • Improve bp_get_component_navigations() so that Avatar/Cover images navigation items are moved inside the Profile sub nav if the Extended profile component is active.
  • Register Avatar/Cover images Ajax actions so that these actions trigger our new URL Parser inside Ajax context.
  • Improve the BP_Core_Nav::add_nav() method so that any BP action variable slugs can be customized.
  • Improve Members & Groups component canonical redirections.
  • Handle slugs customization persistency using directory pages post metas.
  • Introduce a new repair tool to reset all slugs to BuddyPress default one.
  • Adapt some PHPUnit tests to better handle our new URL parser.

Props Props r-a-y, johnjamesjacoby, boonebgorges

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

Location:
trunk
Files:
27 edited

Legend:

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

    r13464 r13468  
    477477            'name' => __( 'Components', 'buddypress' ),
    478478        ),
    479         '1' => array(
    480             'id'   => 'bp-rewrites',
    481             'href' => bp_get_admin_url( add_query_arg( array( 'page' => 'bp-rewrites' ), 'admin.php' ) ),
    482             'name' => __( 'URLs', 'buddypress' ),
    483         ),
    484479        '2' => array(
    485480            'id'   => 'bp-settings',
     
    493488        ),
    494489    );
     490
     491    if ( 'rewrites' === bp_core_get_query_parser() ) {
     492        $settings_tabs['1'] = array(
     493            'id'   => 'bp-rewrites',
     494            'href' => bp_get_admin_url( add_query_arg( array( 'page' => 'bp-rewrites' ), 'admin.php' ) ),
     495            'name' => __( 'URLs', 'buddypress' ),
     496        );
     497    }
    495498
    496499    if ( ! $apply_filters ) {
  • trunk/src/bp-core/admin/bp-core-admin-rewrites.php

    r13451 r13468  
    3030
    3131    wp_enqueue_script( 'bp-rewrites-ui' );
     32
     33    // Handle slugs customization.
     34    if ( isset( $_POST['bp-admin-rewrites-submit'] ) ) {
     35        check_admin_referer( 'bp-admin-rewrites-setup' );
     36
     37        $base_url = bp_get_admin_url( add_query_arg( 'page', 'bp-rewrites', 'admin.php' ) );
     38
     39        if ( ! isset( $_POST['components'] ) ) {
     40            wp_safe_redirect( add_query_arg( 'error', 'true', $base_url ) );
     41        }
     42
     43        $directory_pages     = (array) bp_core_get_directory_pages();
     44        $current_page_slugs  = wp_list_pluck( $directory_pages, 'slug', 'id' );
     45        $current_page_titles = wp_list_pluck( $directory_pages, 'title', 'id' );
     46        $reset_rewrites      = false;
     47
     48        // Data is sanitized inside the foreach loop.
     49        $components = wp_unslash( $_POST['components'] ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput
     50
     51        foreach ( $components as $page_id => $posted_data ) {
     52            $postarr = array();
     53
     54            if ( ! isset( $current_page_slugs[ $page_id ] ) ) {
     55                continue;
     56            }
     57
     58            $postarr['ID'] = $page_id;
     59
     60            if ( isset( $posted_data['post_title'] ) ) {
     61                $post_title = sanitize_text_field( $posted_data['post_title'] );
     62
     63                if ( $current_page_titles[ $page_id ] !== $post_title ) {
     64                    $postarr['post_title'] = $post_title;
     65                }
     66            }
     67
     68            if ( isset( $posted_data['post_name'] ) ) {
     69                $post_name = sanitize_text_field( $posted_data['post_name'] );
     70
     71                if ( $current_page_slugs[ $page_id ] !== $post_name ) {
     72                    $reset_rewrites       = true;
     73                    $postarr['post_name'] = $post_name;
     74                }
     75            }
     76
     77            if ( isset( $posted_data['_bp_component_slugs'] ) && is_array( $posted_data['_bp_component_slugs'] ) ) {
     78                $postarr['meta_input']['_bp_component_slugs'] = array_map( 'sanitize_title', $posted_data['_bp_component_slugs'] );
     79            }
     80
     81            if ( isset( $posted_data['_bp_component_slugs']['bp_group_create'] ) ) {
     82                $new_current_group_create_slug    = sanitize_text_field( $posted_data['_bp_component_slugs']['bp_group_create'] );
     83                $current_group_create_custom_slug = '';
     84
     85                if ( isset( $directory_pages->groups->custom_slugs['bp_group_create'] ) ) {
     86                    $current_group_create_custom_slug = $directory_pages->groups->custom_slugs['bp_group_create'];
     87                }
     88
     89                if ( $new_current_group_create_slug !== $current_group_create_custom_slug ) {
     90                    $reset_rewrites = true;
     91                }
     92            }
     93
     94            wp_update_post( $postarr );
     95        }
     96
     97        // Make sure the WP rewrites will be regenarated at next page load.
     98        if ( $reset_rewrites ) {
     99            bp_delete_rewrite_rules();
     100        }
     101
     102        wp_safe_redirect( add_query_arg( 'updated', 'true', $base_url ) );
     103    }
    32104}
    33105
     
    133205
    134206                                            if ( isset( $navs['sub_nav'] ) ) {
     207                                                if ( 'profile' === $navs['main_nav']['slug'] ) {
     208                                                    $edit_subnav = wp_list_filter( $navs['sub_nav'], array( 'slug' => 'edit' ) );
     209                                                    $position    = key( $edit_subnav );
     210
     211                                                    if ( $edit_subnav ) {
     212                                                        $edit_subnav = reset( $edit_subnav );
     213                                                        array_splice(
     214                                                            $navs['sub_nav'],
     215                                                            $position + 1,
     216                                                            0,
     217                                                            array(
     218                                                                array(
     219                                                                    'name'       => __( 'Field Group', 'buddypress' ),
     220                                                                    'slug'       => 'group',
     221                                                                    'rewrite_id' => $edit_subnav['rewrite_id'] . '_group',
     222                                                                )
     223                                                            )
     224                                                        );
     225                                                    }
     226                                                }
     227
    135228                                                $members_sub_navigation[ $navs['main_nav']['slug'] ] = array(
    136229                                                    'name'    => $navs['main_nav']['name'],
     
    146239                                                        /* translators: %s is the member primary screen name */
    147240                                                        esc_html_x( '"%s" slug', 'member primary screen name URL admin label', 'buddypress' ),
    148                                                         esc_html( _bp_strip_spans_from_title( $navs['main_nav']['name'] ) )
     241                                                        esc_html( $navs['main_nav']['name'] )
    149242                                                    );
    150243                                                    ?>
     
    184277                                                                    /* translators: %s is the member secondary view name */
    185278                                                                    esc_html_x( '"%s" slug', 'member secondary screen name URL admin label', 'buddypress' ),
    186                                                                     esc_html( _bp_strip_spans_from_title( $secondary_nav_item['name'] ) )
     279                                                                    esc_html( $secondary_nav_item['name'] )
    187280                                                                );
    188281                                                                ?>
     
    253346                                                                /* translators: %s is group view name */
    254347                                                                esc_html_x( '"%s" slug', 'group view name URL admin label', 'buddypress' ),
    255                                                                 esc_html( _bp_strip_spans_from_title( $group_screen['name'] ) )
     348                                                                esc_html( str_replace( ' %s', '', $group_screen['name'] ) )
    256349                                                            );
    257350                                                            ?>
     
    270363                    </div>
    271364                <?php endforeach; ?>
     365
     366                <p class="submit clear">
     367                    <input class="button-primary" type="submit" name="bp-admin-rewrites-submit" id="bp-admin-rewrites-submit" value="<?php esc_attr_e( 'Save Settings', 'buddypress' ); ?>"/>
     368                </p>
     369
     370                <?php wp_nonce_field( 'bp-admin-rewrites-setup' ); ?>
     371
    272372            </form>
    273373        </div>
  • trunk/src/bp-core/admin/bp-core-admin-tools.php

    r13137 r13468  
    9696 */
    9797function bp_admin_repair_list() {
    98     $repair_list = array();
     98    $repair_list = array(
     99        -1 => array(
     100            'bp-reset-slugs',
     101            __( 'Reset all BuddyPress slugs to default ones', 'buddypress' ),
     102            'bp_admin_reset_slugs',
     103        ),
     104    );
    99105
    100106    // Members:
     
    177183     */
    178184    return (array) apply_filters( 'bp_repair_list', $repair_list );
     185}
     186
     187/**
     188 * Reset all BuddyPress slug to default ones.
     189 *
     190 * @since 12.0.0
     191 */
     192function bp_admin_reset_slugs() {
     193    /* translators: %s: the result of the action performed by the repair tool */
     194    $statement = __( 'Removing all custom slugs and resetting default ones&hellip; %s', 'buddypress' );
     195
     196    $bp_pages = bp_core_get_directory_page_ids( 'all' );
     197    foreach ( $bp_pages as $page_id ) {
     198        delete_post_meta( $page_id, '_bp_component_slugs' );
     199    }
     200
     201    // Delete BP Pages cache and rewrite rules.
     202    wp_cache_delete( 'directory_pages', 'bp_pages' );
     203    bp_delete_rewrite_rules();
     204
     205    return array( 0, sprintf( $statement, __( 'Complete!', 'buddypress' ) ) );
    179206}
    180207
  • trunk/src/bp-core/bp-core-actions.php

    r13461 r13468  
    7373add_action( 'bp_init', 'bp_register_taxonomies',     2  );
    7474add_action( 'bp_init', 'bp_setup_globals',           4  );
     75add_action( 'bp_init', 'bp_register_nav',            5  );
    7576add_action( 'bp_init', 'bp_blocks_init',             10 );
    7677add_action( 'bp_init', 'bp_core_load_admin_bar_css', 12 );
     
    110111        $key_actions['_bp_maybe_remove_redirect_canonical'] = 10;
    111112        $key_actions['bp_remove_adjacent_posts_rel_link']   = 10;
    112 
    113         /**
    114          *
    115          * @todo This code should be moved to BP Classic.
    116          *
    117          */
    118         add_action( $hook, 'bp_core_set_uri_globals', 2 );
    119113    }
    120114
     
    127121
    128122        add_action( $hook, $action, $priority, $arguments );
     123    }
     124
     125    // Fire a deprecation notice for following deprecated hooks, if needed.
     126    if ( ! function_exists( 'bp_classic' ) ) {
     127        apply_filters_deprecated( 'bp_uri', array( '' ), '12.0.0' );
     128        do_action_deprecated( 'is_not_buddypress', array(), '12.0.0' );
    129129    }
    130130}
  • trunk/src/bp-core/bp-core-attachments.php

    r13417 r13468  
    16481648
    16491649/**
     1650 * Register Cover Image ajax actions.
     1651 *
     1652 * @since 12.0.0
     1653 */
     1654function bp_attachments_cover_register_ajax_actions() {
     1655    bp_ajax_register_action( 'bp_cover_image_upload' );
     1656    bp_ajax_register_action( 'bp_cover_image_delete' );
     1657}
     1658add_action( 'bp_init', 'bp_attachments_cover_register_ajax_actions' );
     1659
     1660/**
    16501661 * Returns a file's mime type.
    16511662 *
  • trunk/src/bp-core/bp-core-avatars.php

    r13436 r13468  
    26012601}
    26022602add_action( 'wp_ajax_bp_avatar_delete_previous', 'bp_avatar_ajax_delete_previous_avatar' );
     2603
     2604
     2605/**
     2606 * Register Avatar ajax actions.
     2607 *
     2608 * @since 12.0.0
     2609 */
     2610function bp_avatar_register_ajax_actions() {
     2611    $ajax_actions = array( 'bp_avatar_upload', 'bp_avatar_set', 'bp_avatar_delete', 'bp_avatar_recycle_previous', 'bp_avatar_delete_previous' );
     2612
     2613    foreach ( $ajax_actions as $ajax_action ) {
     2614        bp_ajax_register_action( $ajax_action );
     2615    }
     2616}
     2617add_action( 'bp_init', 'bp_avatar_register_ajax_actions' );
  • trunk/src/bp-core/bp-core-catchuri.php

    r13461 r13468  
    1313// Exit if accessed directly.
    1414defined( 'ABSPATH' ) || exit;
    15 
    16 /**
    17  * Analyze the URI and break it down into BuddyPress-usable chunks.
    18  *
    19  * BuddyPress can use complete custom friendly URIs without the user having to
    20  * add new rewrite rules. Custom components are able to use their own custom
    21  * URI structures with very little work.
    22  *
    23  * The URIs are broken down as follows:
    24  *   - http:// example.com / members / andy / [current_component] / [current_action] / [action_variables] / [action_variables] / ...
    25  *   - OUTSIDE ROOT: http:// example.com / sites / buddypress / members / andy / [current_component] / [current_action] / [action_variables] / [action_variables] / ...
    26  *
    27  * Example:
    28  *    - http://example.com/members/andy/profile/edit/group/5/
    29  *    - $bp->current_component: string 'xprofile'
    30  *    - $bp->current_action: string 'edit'
    31  *    - $bp->action_variables: array ['group', 5]
    32  *
    33  * @since 1.0.0
    34  */
    35 function bp_core_set_uri_globals() {
    36     global $current_blog, $wp_rewrite;
    37 
    38     // Don't catch URIs on non-root blogs unless multiblog mode is on.
    39     if ( !bp_is_root_blog() && !bp_is_multiblog_mode() )
    40         return false;
    41 
    42     $bp = buddypress();
    43 
    44     // Define local variables.
    45     $root_profile = $match   = false;
    46     $key_slugs    = $matches = $uri_chunks = array();
    47 
    48     // Fetch all the WP page names for each component.
    49     if ( empty( $bp->pages ) )
    50         $bp->pages = bp_core_get_directory_pages();
    51 
    52     // Ajax or not?
    53     if ( defined( 'DOING_AJAX' ) && DOING_AJAX || strpos( $_SERVER['REQUEST_URI'], 'wp-load.php' ) )
    54         $path = bp_get_referer_path();
    55     else
    56         $path = esc_url( $_SERVER['REQUEST_URI'] );
    57 
    58     /**
    59      * Filters the BuddyPress global URI path.
    60      *
    61      * @since 1.0.0
    62      *
    63      * @param string $path Path to set.
    64      */
    65     $path = apply_filters( 'bp_uri', $path );
    66 
    67     // Take GET variables off the URL to avoid problems.
    68     $path = strtok( $path, '?' );
    69 
    70     // Fetch current URI and explode each part separated by '/' into an array.
    71     $bp_uri = explode( '/', $path );
    72 
    73     // Loop and remove empties.
    74     foreach ( (array) $bp_uri as $key => $uri_chunk ) {
    75         if ( empty( $bp_uri[$key] ) ) {
    76             unset( $bp_uri[$key] );
    77         }
    78     }
    79 
    80     /*
    81      * If running off blog other than root, any subdirectory names must be
    82      * removed from $bp_uri. This includes two cases:
    83      *
    84      * 1. when WP is installed in a subdirectory,
    85      * 2. when BP is running on secondary blog of a subdirectory
    86      * multisite installation. Phew!
    87      */
    88     if ( is_multisite() && !is_subdomain_install() && ( bp_is_multiblog_mode() || 1 != bp_get_root_blog_id() ) ) {
    89 
    90         // Blow chunks.
    91         $chunks = explode( '/', $current_blog->path );
    92 
    93         // If chunks exist...
    94         if ( !empty( $chunks ) ) {
    95 
    96             // ...loop through them...
    97             foreach( $chunks as $key => $chunk ) {
    98                 $bkey = array_search( $chunk, $bp_uri );
    99 
    100                 // ...and unset offending keys.
    101                 if ( false !== $bkey ) {
    102                     unset( $bp_uri[$bkey] );
    103                 }
    104 
    105                 $bp_uri = array_values( $bp_uri );
    106             }
    107         }
    108     }
    109 
    110     // Get site path items.
    111     $paths = explode( '/', bp_core_get_site_path() );
    112 
    113     // Take empties off the end of path.
    114     if ( empty( $paths[count( $paths ) - 1] ) )
    115         array_pop( $paths );
    116 
    117     // Take empties off the start of path.
    118     if ( empty( $paths[0] ) )
    119         array_shift( $paths );
    120 
    121     // Reset indexes.
    122     $bp_uri = array_values( $bp_uri );
    123     $paths  = array_values( $paths );
    124 
    125     // Unset URI indices if they intersect with the paths.
    126     foreach ( (array) $bp_uri as $key => $uri_chunk ) {
    127         if ( isset( $paths[$key] ) && $uri_chunk == $paths[$key] ) {
    128             unset( $bp_uri[$key] );
    129         }
    130     }
    131 
    132     // Reset the keys by merging with an empty array.
    133     $bp_uri = array_merge( array(), $bp_uri );
    134 
    135     /*
    136      * If a component is set to the front page, force its name into $bp_uri
    137      * so that $current_component is populated (unless a specific WP post is being requested
    138      * via a URL parameter, usually signifying Preview mode).
    139      */
    140     if ( 'page' == get_option( 'show_on_front' ) && get_option( 'page_on_front' ) && empty( $bp_uri ) && empty( $_GET['p'] ) && empty( $_GET['page_id'] ) ) {
    141         $post = get_post( get_option( 'page_on_front' ) );
    142         if ( !empty( $post ) ) {
    143             $bp_uri[0] = $post->post_name;
    144         }
    145     }
    146 
    147     // Keep the unfiltered URI safe.
    148     $bp->unfiltered_uri = $bp_uri;
    149 
    150     // Don't use $bp_unfiltered_uri, this is only for backpat with old plugins. Use $bp->unfiltered_uri.
    151     $GLOBALS['bp_unfiltered_uri'] = &$bp->unfiltered_uri;
    152 
    153     // Get slugs of pages into array.
    154     foreach ( (array) $bp->pages as $page_key => $bp_page )
    155         $key_slugs[$page_key] = trailingslashit( '/' . $bp_page->slug );
    156 
    157     // Bail if keyslugs are empty, as BP is not setup correct.
    158     if ( empty( $key_slugs ) )
    159         return;
    160 
    161     // Loop through page slugs and look for exact match to path.
    162     foreach ( $key_slugs as $key => $slug ) {
    163         if ( $slug == $path ) {
    164             $match      = $bp->pages->{$key};
    165             $match->key = $key;
    166             $matches[]  = 1;
    167             break;
    168         }
    169     }
    170 
    171     // No exact match, so look for partials.
    172     if ( empty( $match ) ) {
    173 
    174         // Loop through each page in the $bp->pages global.
    175         foreach ( (array) $bp->pages as $page_key => $bp_page ) {
    176 
    177             // Look for a match (check members first).
    178             if ( in_array( $bp_page->name, (array) $bp_uri ) ) {
    179 
    180                 // Match found, now match the slug to make sure.
    181                 $uri_chunks = explode( '/', $bp_page->slug );
    182 
    183                 // Loop through uri_chunks.
    184                 foreach ( (array) $uri_chunks as $key => $uri_chunk ) {
    185 
    186                     // Make sure chunk is in the correct position.
    187                     if ( !empty( $bp_uri[$key] ) && ( $bp_uri[$key] == $uri_chunk ) ) {
    188                         $matches[] = 1;
    189 
    190                     // No match.
    191                     } else {
    192                         $matches[] = 0;
    193                     }
    194                 }
    195 
    196                 // Have a match.
    197                 if ( !in_array( 0, (array) $matches ) ) {
    198                     $match      = $bp_page;
    199                     $match->key = $page_key;
    200                     break;
    201                 };
    202 
    203                 // Unset matches.
    204                 unset( $matches );
    205             }
    206 
    207             // Unset uri chunks.
    208             unset( $uri_chunks );
    209         }
    210     }
    211 
    212     // URLs with BP_ENABLE_ROOT_PROFILES enabled won't be caught above.
    213     if ( empty( $matches ) && bp_core_enable_root_profiles() && ! empty( $bp_uri[0] ) ) {
    214 
    215         // Switch field based on compat.
    216         $field = bp_is_username_compatibility_mode() ? 'login' : 'slug';
    217 
    218         /**
    219          * Filter the portion of the URI that is the displayed user's slug.
    220          *
    221          * Eg. example.com/ADMIN (when root profiles is enabled)
    222          *     example.com/members/ADMIN (when root profiles isn't enabled)
    223          *
    224          * ADMIN would be the displayed user's slug.
    225          *
    226          * @since 2.6.0
    227          *
    228          * @param string $member_slug
    229          */
    230         $member_slug = apply_filters( 'bp_core_set_uri_globals_member_slug', $bp_uri[0] );
    231 
    232         // Make sure there's a user corresponding to $bp_uri[0].
    233         if ( ! empty( $bp->pages->members ) && $root_profile = get_user_by( $field, $member_slug ) ) {
    234 
    235             // Force BP to recognize that this is a members page.
    236             $matches[]  = 1;
    237             $match      = $bp->pages->members;
    238             $match->key = 'members';
    239         }
    240     }
    241 
    242     // Search doesn't have an associated page, so we check for it separately.
    243     if ( isset( $_POST['search-terms'] ) && !empty( $bp_uri[0] ) && ( bp_get_search_slug() == $bp_uri[0] ) ) {
    244         $matches[]   = 1;
    245         $match       = new stdClass;
    246         $match->key  = 'search';
    247         $match->slug = bp_get_search_slug();
    248     }
    249 
    250     // This is not a BuddyPress page, so just return.
    251     if ( empty( $matches ) ) {
    252         /**
    253          * Fires when the the current page is not a BuddyPress one.
    254          *
    255          * @since 10.0.0
    256          */
    257         do_action( 'is_not_buddypress' );
    258         return false;
    259     }
    260 
    261     $wp_rewrite->use_verbose_page_rules = false;
    262 
    263     // Find the offset. With $root_profile set, we fudge the offset down so later parsing works.
    264     $slug       = !empty ( $match ) ? explode( '/', $match->slug ) : '';
    265     $uri_offset = empty( $root_profile ) ? 0 : -1;
    266 
    267     // Rejig the offset.
    268     if ( !empty( $slug ) && ( 1 < count( $slug ) ) ) {
    269         // Only offset if not on a root profile. Fixes issue when Members page is nested.
    270         if ( false === $root_profile ) {
    271             array_pop( $slug );
    272             $uri_offset = count( $slug );
    273         }
    274     }
    275 
    276     // Global the unfiltered offset to use in bp_core_load_template().
    277     // To avoid PHP warnings in bp_core_load_template(), it must always be >= 0.
    278     $bp->unfiltered_uri_offset = $uri_offset >= 0 ? $uri_offset : 0;
    279 
    280     // We have an exact match.
    281     if ( isset( $match->key ) ) {
    282 
    283         // Set current component to matched key.
    284         $bp->current_component = $match->key;
    285 
    286         // If members component, do more work to find the actual component.
    287         if ( 'members' == $match->key ) {
    288 
    289             $after_member_slug = false;
    290             if ( ! empty( $bp_uri[ $uri_offset + 1 ] ) ) {
    291                 $after_member_slug = $bp_uri[ $uri_offset + 1 ];
    292             }
    293 
    294             // Are we viewing a specific user?
    295             if ( $after_member_slug ) {
    296 
    297                 /** This filter is documented in bp-core/bp-core-catchuri.php */
    298                 $after_member_slug = apply_filters( 'bp_core_set_uri_globals_member_slug', $after_member_slug );
    299 
    300                 // If root profile, we've already queried for the user.
    301                 if ( $root_profile instanceof WP_User ) {
    302                     $bp->displayed_user->id = $root_profile->ID;
    303 
    304                 // Switch the displayed_user based on compatibility mode.
    305                 } elseif ( bp_is_username_compatibility_mode() ) {
    306                     $bp->displayed_user->id = (int) bp_core_get_userid( urldecode( $after_member_slug ) );
    307 
    308                 } else {
    309                     $bp->displayed_user->id = (int) bp_core_get_userid_from_nicename( $after_member_slug );
    310                 }
    311             }
    312 
    313             // Is this a member type directory?
    314             if ( ! bp_displayed_user_id() && $after_member_slug === bp_get_members_member_type_base() && ! empty( $bp_uri[ $uri_offset + 2 ] ) ) {
    315                 $matched_types = bp_get_member_types( array(
    316                     'has_directory'  => true,
    317                     'directory_slug' => $bp_uri[ $uri_offset + 2 ],
    318                 ) );
    319 
    320                 if ( ! empty( $matched_types ) ) {
    321                     $bp->current_member_type = reset( $matched_types );
    322                     unset( $bp_uri[ $uri_offset + 1 ] );
    323                 }
    324             }
    325 
    326             // If the slug matches neither a member type nor a specific member, 404.
    327             if ( ! bp_displayed_user_id() && ! bp_get_current_member_type() && $after_member_slug ) {
    328                 // Prevent components from loading their templates.
    329                 $bp->current_component = '';
    330                 bp_do_404();
    331                 return;
    332             }
    333 
    334             // If the displayed user is marked as a spammer, 404 (unless logged-in user is a super admin).
    335             if ( bp_displayed_user_id() && bp_is_user_spammer( bp_displayed_user_id() ) ) {
    336                 if ( bp_current_user_can( 'bp_moderate' ) ) {
    337                     bp_core_add_message( __( 'This user has been marked as a spammer. Only site admins can view this profile.', 'buddypress' ), 'warning' );
    338                 } else {
    339                     bp_do_404();
    340                     return;
    341                 }
    342             }
    343 
    344             // Bump the offset.
    345             if ( bp_displayed_user_id() ) {
    346                 if ( isset( $bp_uri[$uri_offset + 2] ) ) {
    347                     $bp_uri                = array_merge( array(), array_slice( $bp_uri, $uri_offset + 2 ) );
    348                     $bp->current_component = $bp_uri[0];
    349 
    350                 // No component, so default will be picked later.
    351                 } else {
    352                     $bp_uri                = array_merge( array(), array_slice( $bp_uri, $uri_offset + 2 ) );
    353                     $bp->current_component = '';
    354                 }
    355 
    356                 // Reset the offset.
    357                 $uri_offset = 0;
    358             }
    359         }
    360     }
    361 
    362     // Determine the current action.
    363     $current_action = isset( $bp_uri[ $uri_offset + 1 ] ) ? $bp_uri[ $uri_offset + 1 ] : '';
    364 
    365     /*
    366      * If a BuddyPress directory is set to the WP front page, URLs like example.com/members/?s=foo
    367      * shouldn't interfere with blog searches.
    368      */
    369     if ( empty( $current_action) && ! empty( $_GET['s'] ) && 'page' == get_option( 'show_on_front' ) && ! empty( $match->id ) ) {
    370         $page_on_front = (int) get_option( 'page_on_front' );
    371         if ( (int) $match->id === $page_on_front ) {
    372             $bp->current_component = '';
    373             return false;
    374         }
    375     }
    376 
    377     $bp->current_action = $current_action;
    378 
    379     // Slice the rest of the $bp_uri array and reset offset.
    380     $bp_uri      = array_slice( $bp_uri, $uri_offset + 2 );
    381     $uri_offset  = 0;
    382 
    383     // Set the entire URI as the action variables, we will unset the current_component and action in a second.
    384     $bp->action_variables = $bp_uri;
    385 
    386     // Reset the keys by merging with an empty array.
    387     $bp->action_variables = array_merge( array(), $bp->action_variables );
    388 }
    38915
    39016/**
  • trunk/src/bp-core/bp-core-dependency.php

    r13431 r13468  
    157157
    158158/**
    159  * Fire the 'bp_setup_nav' action, where plugins should register their navigation items.
     159 * Fire the 'bp_register_nav' action, where plugins should register their navigation items.
    160160 *
    161161 * @since 1.2.0
    162162 */
     163function bp_register_nav() {
     164    /**
     165     * Fires inside the 'bp_register_nav' function, where plugins should register their navigation items.
     166     *
     167     * @since 12.0.0
     168     */
     169    do_action( 'bp_register_nav' );
     170}
     171
     172/**
     173 * Fire the 'bp_setup_nav' action, where navigation items are generated.
     174 *
     175 * @since 1.2.0
     176 */
    163177function bp_setup_nav() {
    164178
    165179    /**
    166      * Fires inside the 'bp_setup_nav' function, where plugins should register their navigation items.
     180     * Fires inside the 'bp_setup_nav' function, where navigation items are generated.
    167181     *
    168182     * @since 1.2.0
  • trunk/src/bp-core/bp-core-functions.php

    r13461 r13468  
    160160     *                       Possible values are `rewrites` or `legacy`.
    161161     */
    162     return apply_filters( 'bp_core_get_query_parser', bp_has_pretty_urls() ? 'legacy' : 'rewrites' );
     162    return apply_filters( 'bp_core_get_query_parser', 'rewrites' );
    163163}
    164164
     
    958958            $site         = get_site_by_path( $current_site->domain, trailingslashit( $current_site->path ) . $slug );
    959959
    960             if ( isset( $site->blog_id ) && 1 !== $site->blog_id ) {
     960            if ( isset( $site->blog_id ) && 1 !== (int) $site->blog_id ) {
    961961                $illegal_names[] = $slug;
    962962            }
     
    49574957
    49584958        if ( isset( $component->sub_nav ) && is_array( $component->sub_nav ) && $component->sub_nav ) {
     4959            // We possibly need to move some members nav items.
     4960            if ( 'members' === $key_component && isset( $navigations['profile']['sub_nav'] ) ) {
     4961                $profile_subnav_slugs = wp_list_pluck( $navigations['profile']['sub_nav'], 'slug' );
     4962                foreach ( $component->sub_nav as $members_subnav ) {
     4963                    if ( 'profile' === $members_subnav['parent_slug'] && ! in_array( $members_subnav['slug'], $profile_subnav_slugs, true ) ) {
     4964                        $navigations['profile']['sub_nav'][] = $members_subnav;
     4965                    }
     4966                }
     4967            }
     4968
    49594969            $navigations[ $key_component ]['sub_nav'] = $component->sub_nav;
    49604970        }
  • trunk/src/bp-core/bp-core-template-loader.php

    r13461 r13468  
    566566    }
    567567
     568    // Set some needed URI globals.
     569    $bp                        = buddypress();
     570    $bp->unfiltered_uri        = explode( '/', $GLOBALS['wp']->request );
     571    $bp->unfiltered_uri_offset = 0;
     572
    568573    /**
    569574     * Fires at the end of the bp_parse_query function.
  • trunk/src/bp-core/classes/class-bp-admin.php

    r13450 r13468  
    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-rewrites.php';
    150149        require $this->admin_dir . 'bp-core-admin-tools.php';
    151150        require $this->admin_dir . 'bp-core-admin-optouts.php';
     151
     152        if ( 'rewrites' === bp_core_get_query_parser() ) {
     153            require $this->admin_dir . 'bp-core-admin-rewrites.php';
     154        }
    152155    }
    153156
     
    276279        $hooks[]                                          = $bp_components_page;
    277280
    278         $bp_rewrite_settings_page = add_submenu_page(
    279             $this->settings_page,
    280             __( 'BuddyPress URLs', 'buddypress' ),
    281             __( 'BuddyPress URLs', 'buddypress' ),
    282             $this->capability,
    283             'bp-rewrites',
    284             'bp_core_admin_rewrites_settings'
    285         );
    286 
    287         $this->submenu_pages['settings']['bp-rewrites'] = $bp_rewrite_settings_page;
    288         $hooks[]                                        = $bp_rewrite_settings_page;
     281        if ( 'rewrites' === bp_core_get_query_parser() ) {
     282            $bp_rewrites_settings_page = add_submenu_page(
     283                $this->settings_page,
     284                __( 'BuddyPress URLs', 'buddypress' ),
     285                __( 'BuddyPress URLs', 'buddypress' ),
     286                $this->capability,
     287                'bp-rewrites',
     288                'bp_core_admin_rewrites_settings'
     289            );
     290
     291            $this->submenu_pages['settings']['bp-rewrites'] = $bp_rewrites_settings_page;
     292            $hooks[]                                        = $bp_rewrites_settings_page;
     293        }
    289294
    290295        $bp_settings_page = add_submenu_page(
  • trunk/src/bp-core/classes/class-bp-component.php

    r13461 r13468  
    539539        // compatibility; henceforth, plugins should register themselves by
    540540        // extending this base class.
    541         add_action( 'bp_include',                array( $this, 'includes'               ), 8 );
     541        add_action( 'bp_include',                array( $this, 'includes'               ),  8 );
    542542
    543543        // Load files conditionally, based on certain pages.
    544         add_action( 'bp_late_include',           array( $this, 'late_includes'          ) );
     544        add_action( 'bp_late_include',           array( $this, 'late_includes'          ), 10 );
    545545
    546546        // Generate navigation.
    547         add_action( 'bp_setup_nav',              array( $this, 'register_nav'           ),  7 );
     547        add_action( 'bp_register_nav',           array( $this, 'register_nav'           ),  9 );
    548548
    549549        // Setup navigation.
  • trunk/src/bp-core/classes/class-bp-core-nav.php

    r13441 r13468  
    201201                $args['link'] = bp_rewrites_get_url( $path_chunks );
    202202            } else {
    203                 $path_chunks['single_item_component'] = bp_rewrites_get_slug( 'members', 'member_' . $path_chunks['single_item_component'], $path_chunks['single_item_component'] );
    204 
    205                 if ( isset( $path_chunks['single_item_action'] ) && ! is_numeric( $path_chunks['single_item_action'] ) ) {
    206                     $path_chunks['single_item_action'] = bp_rewrites_get_slug(
    207                         'members',
    208                         'member_' . $path_chunks['single_item_component'] . '_' . $path_chunks['single_item_action'],
    209                         $path_chunks['single_item_action']
    210                     );
     203                if ( isset( $path_chunks['single_item_component'] ) ) {
     204                    // First try to get custom item action slugs.
     205                    if ( isset( $path_chunks['single_item_action'] ) && ! is_numeric( $path_chunks['single_item_action'] ) ) {
     206                        $path_chunks['single_item_action'] = bp_rewrites_get_slug(
     207                            'members',
     208                            'member_' . $path_chunks['single_item_component'] . '_' . str_replace( '-', '_', $path_chunks['single_item_action'] ),
     209                            $path_chunks['single_item_action']
     210                        );
     211                    }
     212
     213                    // Then only try to get custom item component slug.
     214                    $path_chunks['single_item_component'] = bp_rewrites_get_slug( 'members', 'member_' . str_replace( '-', '_', $path_chunks['single_item_component'] ), $path_chunks['single_item_component'] );
    211215                }
    212216
  • trunk/src/bp-core/deprecated/12.0.php

    r13449 r13468  
    1414// These functions has been moved to the BP Classic plugin.
    1515if ( ! function_exists( 'bp_classic' ) ) {
     16    /**
     17     * Analyze the URI and break it down into BuddyPress-usable chunks.
     18     *
     19     * BuddyPress can use complete custom friendly URIs without the user having to
     20     * add new rewrite rules. Custom components are able to use their own custom
     21     * URI structures with very little work.
     22     *
     23     * The URIs are broken down as follows:
     24     *   - http:// example.com / members / andy / [current_component] / [current_action] / [action_variables] / [action_variables] / ...
     25     *   - OUTSIDE ROOT: http:// example.com / sites / buddypress / members / andy / [current_component] / [current_action] / [action_variables] / [action_variables] / ...
     26     *
     27     * Example:
     28     *    - http://example.com/members/andy/profile/edit/group/5/
     29     *    - $bp->current_component: string 'xprofile'
     30     *    - $bp->current_action: string 'edit'
     31     *    - $bp->action_variables: array ['group', 5]
     32     *
     33     * @since 1.0.0
     34     * @deprecated 12.0.0
     35     */
     36    function bp_core_set_uri_globals() {
     37        _deprecated_function( __FUNCTION__, '12.0.0' );
     38    }
     39
    1640    /**
    1741     * Add support for a top-level ("root") component.
  • trunk/src/bp-groups/bp-groups-functions.php

    r13451 r13468  
    40544054
    40554055    if ( $chunks ) {
     4056        // If action variables were added as an array, reset chunks to it.
     4057        if ( isset( $chunks[0] ) && is_array( $chunks[0] ) ) {
     4058            $chunks = reset( $chunks );
     4059        }
     4060
    40564061        foreach ( $chunks as $chunk ) {
    40574062            if ( is_numeric( $chunk ) ) {
  • trunk/src/bp-groups/classes/class-bp-groups-component.php

    r13464 r13468  
    179179                in_array( bp_current_action(), array( 'create', 'join', 'leave-group' ), true )
    180180            ) {
    181                 require $this->path . 'bp-groups/actions/' . bp_current_action() . '.php';
     181                require_once $this->path . 'bp-groups/actions/' . bp_current_action() . '.php';
    182182            }
    183183
    184184            // Actions - RSS feed handler.
    185185            if ( bp_is_active( 'activity' ) && bp_is_current_action( 'feed' ) ) {
    186                 require $this->path . 'bp-groups/actions/feed.php';
     186                require_once $this->path . 'bp-groups/actions/feed.php';
    187187            }
    188188
    189189            // Actions - Random group handler.
    190190            if ( isset( $_GET['random-group'] ) ) {
    191                 require $this->path . 'bp-groups/actions/random.php';
     191                require_once $this->path . 'bp-groups/actions/random.php';
    192192            }
    193193
    194194            // Screens - Directory.
    195195            if ( bp_is_groups_directory() ) {
    196                 require $this->path . 'bp-groups/screens/directory.php';
     196                require_once $this->path . 'bp-groups/screens/directory.php';
    197197            }
    198198
    199199            // Screens - User profile integration.
    200200            if ( bp_is_user() ) {
    201                 require $this->path . 'bp-groups/screens/user/my-groups.php';
     201                require_once $this->path . 'bp-groups/screens/user/my-groups.php';
    202202
    203203                if ( bp_is_current_action( 'invites' ) ) {
    204                     require $this->path . 'bp-groups/screens/user/invites.php';
     204                    require_once $this->path . 'bp-groups/screens/user/invites.php';
    205205                }
    206206            }
     
    209209            if ( bp_is_group() ) {
    210210                // Actions - Access protection.
    211                 require $this->path . 'bp-groups/actions/access.php';
     211                require_once $this->path . 'bp-groups/actions/access.php';
    212212
    213213                // Public nav items.
    214214                if ( in_array( bp_current_action(), array( 'home', 'request-membership', 'activity', 'members', 'send-invites' ), true ) ) {
    215                     require $this->path . 'bp-groups/screens/single/' . bp_current_action() . '.php';
     215                    require_once $this->path . 'bp-groups/screens/single/' . bp_current_action() . '.php';
    216216                }
    217217
    218218                // Admin nav items.
    219219                if ( bp_is_item_admin() && is_user_logged_in() ) {
    220                     require $this->path . 'bp-groups/screens/single/admin.php';
     220                    require_once $this->path . 'bp-groups/screens/single/admin.php';
    221221
    222222                    if ( in_array( bp_get_group_current_admin_tab(), array( 'edit-details', 'group-settings', 'group-avatar', 'group-cover-image', 'manage-members', 'membership-requests', 'delete-group' ), true ) ) {
    223                         require $this->path . 'bp-groups/screens/single/admin/' . bp_get_group_current_admin_tab() . '.php';
     223                        require_once $this->path . 'bp-groups/screens/single/admin/' . bp_get_group_current_admin_tab() . '.php';
    224224                    }
    225225                }
     
    554554        // Prepare for a redirect to the canonical URL.
    555555        $bp->canonical_stack['base_url'] = bp_get_group_url( $this->current_group );
    556 
    557         if ( bp_current_action() ) {
    558             $bp->canonical_stack['action'] = bp_current_action();
    559         }
     556        $current_action                  = bp_current_action();
    560557
    561558        /**
     
    567564         */
    568565        if ( ! $this->current_group->front_template && ( bp_is_current_action( 'activity' ) || ( ! bp_is_active( 'activity' ) && bp_is_current_action( 'members' ) ) ) ) {
    569             $bp->canonical_stack['action'] = 'home';
    570         }
    571 
    572         if ( ! empty( $bp->action_variables ) ) {
    573             $bp->canonical_stack['action_variables'] = bp_action_variables();
    574         }
    575 
    576         // When viewing the default extension, the canonical URL should not have
    577         // that extension's slug, unless more has been tacked onto the URL via
    578         // action variables.
     566            $current_action = 'home';
     567        }
     568
     569        if ( $current_action ) {
     570            $context                       = 'read';
     571            $path_chunks                   = bp_groups_get_path_chunks( array( $current_action ), $context );
     572            $bp->canonical_stack['action'] = $current_action;
     573
     574            if ( isset( $path_chunks['single_item_action'] ) ) {
     575                $bp->canonical_stack['action'] = $path_chunks['single_item_action'];
     576            }
     577
     578            if ( ! empty( $bp->action_variables ) ) {
     579                $key_action_variables = 'single_item_action_variables';
     580
     581                if ( bp_is_group_admin_page() ) {
     582                    $context = 'manage';
     583                } elseif ( bp_is_group_create() ) {
     584                    $context              = 'create';
     585                    $key_action_variables = 'create_single_item_variables';;
     586                }
     587
     588                $path_chunks                             = bp_groups_get_path_chunks( $bp->action_variables, $context );
     589                $bp->canonical_stack['action_variables'] = bp_action_variables();
     590
     591                if ( isset( $path_chunks[ $key_action_variables ] ) ) {
     592                    $bp->canonical_stack['action_variables'] = $path_chunks[ $key_action_variables ];
     593                }
     594            }
     595        }
     596
     597        /*
     598         * When viewing the default extension, the canonical URL should not have
     599         * that extension's slug, unless more has been tacked onto the URL via
     600         * action variables.
     601         */
    579602        if ( bp_is_current_action( $this->default_extension ) && empty( $bp->action_variables ) )  {
    580603            unset( $bp->canonical_stack['action'] );
     
    11251148                    $bp->action_variables         = array( $group_type_slug );
    11261149                } else {
    1127                     $bp->current_component = false;
     1150                    $bp->current_component        = false;
     1151                    $this->current_directory_type = '';
    11281152                    bp_do_404();
    11291153                    return;
  • trunk/src/bp-members/bp-members-functions.php

    r13454 r13468  
    162162        $item_action_rewrite_id_suffix     = str_replace( '-', '_', $single_item_action );
    163163        $path_chunks['single_item_action'] = bp_rewrites_get_slug( 'members', 'member_' . $item_component_rewrite_id_suffix . '_' . $item_action_rewrite_id_suffix, $single_item_action );
     164    }
     165
     166    // If action variables were added as an array, reset chunks to it.
     167    if ( isset( $chunks[0] ) && is_array( $chunks[0] ) ) {
     168        $chunks = reset( $chunks );
    164169    }
    165170
  • trunk/src/bp-members/classes/class-bp-members-component.php

    r13464 r13468  
    389389        if ( bp_displayed_user_id() ) {
    390390            $bp->canonical_stack['base_url'] = bp_displayed_user_url();
    391 
    392             if ( bp_current_component() ) {
    393                 $bp->canonical_stack['component'] = bp_current_component();
    394             }
    395 
    396             if ( bp_current_action() ) {
    397                 $bp->canonical_stack['action'] = bp_current_action();
    398             }
    399 
    400             if ( ! empty( $bp->action_variables ) ) {
    401                 $bp->canonical_stack['action_variables'] = bp_action_variables();
    402             }
    403 
    404             // Looking at the single member root/home, so assume the default.
    405             if ( ! bp_current_component() ) {
     391            $action_variables                = (array) bp_action_variables();
     392            $path_chunks                     = bp_members_get_path_chunks(
     393                array_merge(
     394                    array( bp_current_component(), bp_current_action() ),
     395                    array_filter( $action_variables )
     396                )
     397            );
     398
     399            if ( isset( $path_chunks['single_item_component'] ) ) {
     400                $bp->canonical_stack['component'] = $path_chunks['single_item_component'];
     401
     402                // The canonical URL will not contain the default component.
     403                if ( bp_is_current_component( $bp->default_component ) && ! bp_current_action() ) {
     404                    unset( $bp->canonical_stack['component'] );
     405                } elseif ( isset( $path_chunks['single_item_action'] ) ) {
     406                    $bp->canonical_stack['action'] = $path_chunks['single_item_action'];
     407
     408                    if ( isset( $path_chunks['single_item_action_variables'] ) ) {
     409                        $bp->canonical_stack['action_variables'] = $path_chunks['single_item_action_variables'];
     410                    }
     411                }
     412
     413                // Looking at the single member root/home, so assume the default.
     414            } else {
    406415                $bp->current_component = $bp->default_component;
    407 
    408             // The canonical URL will not contain the default component.
    409             } elseif ( bp_is_current_component( $bp->default_component ) && ! bp_current_action() ) {
    410                 unset( $bp->canonical_stack['component'] );
    411             }
    412 
    413             // If we're on a spammer's profile page, only users with the 'bp_moderate' cap
    414             // can view subpages on the spammer's profile.
    415             //
    416             // users without the cap trying to access a spammer's subnav page will get
    417             // redirected to the root of the spammer's profile page.  this occurs by
    418             // by removing the component in the canonical stack.
     416            }
     417
     418            /*
     419             * If we're on a spammer's profile page, only users with the 'bp_moderate' cap
     420             * can view subpages on the spammer's profile.
     421             *
     422             * users without the cap trying to access a spammer's subnav page will get
     423             * redirected to the root of the spammer's profile page.  this occurs by
     424             * by removing the component in the canonical stack.
     425             */
    419426            if ( bp_is_user_spammer( bp_displayed_user_id() ) && ! bp_current_user_can( 'bp_moderate' ) ) {
    420427                unset( $bp->canonical_stack['component'] );
     
    896903                $action_variables = $query->get( $this->rewrite_ids['single_item_action_variables'] );
    897904                if ( $action_variables ) {
     905                    $context = sprintf( 'bp_member_%1$s_%2$s_', $bp->current_component, $bp->current_action );
     906
    898907                    if ( ! is_array( $action_variables ) ) {
    899                         $bp->action_variables = explode( '/', ltrim( $action_variables, '/' ) );
    900                     } else {
    901                         $bp->action_variables = $action_variables;
     908                        $action_variables = explode( '/', ltrim( $action_variables, '/' ) );
    902909                    }
     910
     911                    foreach ( $action_variables as $key_variable => $action_variable ) {
     912                        $item_component_action_variable_rewrite_id = bp_rewrites_get_custom_slug_rewrite_id( 'members', $action_variable, $context );
     913
     914                        if ( $item_component_action_variable_rewrite_id ) {
     915                            $action_variables[ $key_variable ] = str_replace( $context, '', $item_component_action_variable_rewrite_id );
     916                        }
     917                    }
     918
     919                    $bp->action_variables = $action_variables;
    903920                }
    904921
  • trunk/src/bp-templates/bp-nouveau/buddypress-functions.php

    r13461 r13468  
    207207        }
    208208
    209         // Set the BP Uri for the Ajax customizer preview.
    210         add_filter( 'bp_uri', array( $this, 'customizer_set_uri' ), 10, 1 );
    211 
    212209        // Modify "registration disabled" and welcome message if invitations are enabled.
    213210        add_action( 'bp_nouveau_feedback_messages', array( $this, 'filter_registration_messages' ), 99 );
     
    662659     *
    663660     * @since 3.0.0
     661     * @todo deprecate The `bp_uri` filter is not available anymore. Is this function still needed using BP Rewrites?
    664662     *
    665663     * @param  string $path The BP Uri.
  • trunk/src/bp-xprofile/screens/edit.php

    r13443 r13468  
    2323    $profile_slug = bp_get_profile_slug();
    2424    $path_chunks  = array(
    25         'single_item_component'        => bp_rewrites_get_slug( 'members', 'member_' . $profile_slug, $profile_slug ),
    26         'single_item_action'           => bp_rewrites_get_slug( 'members', 'member_' . $profile_slug . '_edit', 'edit' ),
     25        'single_item_component' => bp_rewrites_get_slug( 'members', 'member_' . $profile_slug, $profile_slug ),
     26        'single_item_action'    => bp_rewrites_get_slug( 'members', 'member_' . $profile_slug . '_edit', 'edit' ),
    2727    );
    2828
  • trunk/src/class-buddypress.php

    r13461 r13468  
    5656     * The unfiltered URI broken down into chunks.
    5757     *
    58      * @see bp_core_set_uri_globals()
    5958     * @var array
    6059     */
     
    486485        /**
    487486         * @var int The current offset of the URI.
    488          * @see bp_core_set_uri_globals()
    489487         */
    490488        $this->unfiltered_uri_offset = 0;
  • trunk/tests/phpunit/includes/testcase.php

    r13464 r13468  
    135135        buddypress()->loggedin_user         = new stdClass();
    136136        buddypress()->pages                 = array();
     137        buddypress()->groups->types         = array();
    137138
    138139        parent::clean_up_global_scope();
     
    205206        }
    206207
     208        do_action( 'bp_init' );
     209
    207210        parent::go_to( $url );
    208211
    209         do_action( 'bp_init' );
    210212        do_action( 'bp_template_redirect' );
    211213    }
  • trunk/tests/phpunit/testcases/activity/notifications.php

    r13436 r13468  
    4646     */
    4747    public function test_bp_activity_remove_screen_notifications_on_single_activity_permalink() {
    48         $this->create_notifications();
    49         $this->set_permalink_structure( '/%postname%/' );
    50 
    51         $notifications = BP_Notifications_Notification::get( array(
    52             'user_id' => $this->u1,
    53         ) );
    54 
    55         // Double check it's there
    56         $this->assertEquals( array( $this->a1 ), wp_list_pluck( $notifications, 'item_id' ) );
     48        $this->set_permalink_structure( '/%postname%/' );
     49        $this->create_notifications();
     50
     51        $notifications = BP_Notifications_Notification::get( array(
     52            'user_id' => $this->u1,
     53        ) );
     54
     55        // Double check it's there
     56        $this->assertEquals( array( $this->a1 ), wp_list_pluck( $notifications, 'item_id' ) );
     57        $url = bp_members_get_user_url(
     58            $this->u1,
     59            array(
     60                'single_item_component' => bp_rewrites_get_slug( 'members', 'member_activity', bp_get_activity_slug() ),
     61                'single_item_action'    => $this->a1,
     62            )
     63        );
     64
     65        // Go to the activity permalink page
     66        $this->go_to( $url );
     67
     68        $notifications = BP_Notifications_Notification::get( array(
     69            'user_id' => $this->u1,
     70        ) );
     71
     72        // Should be empty
     73        $this->assertEquals( array(), $notifications );
     74    }
     75
     76    /**
     77     * @group bp_activity_remove_screen_notifications
     78     * @group mentions
     79     */
     80    public function test_bp_activity_remove_screen_notifications_on_single_activity_permalink_logged_out() {
     81        $this->create_notifications();
     82        $this->set_permalink_structure( '/%postname%/' );
     83
     84        $notifications = BP_Notifications_Notification::get( array(
     85            'user_id' => $this->u1,
     86        ) );
     87
     88        // Double check it's there
     89        $this->assertEquals( array( $this->a1 ), wp_list_pluck( $notifications, 'item_id' ) );
     90
     91        // Log out
     92        $this->set_current_user( 0 );
    5793
    5894        // Go to the activity permalink page
     
    71107        ) );
    72108
    73         // Should be empty
    74         $this->assertEquals( array(), $notifications );
    75     }
    76 
    77     /**
    78      * @group bp_activity_remove_screen_notifications
    79      * @group mentions
    80      */
    81     public function test_bp_activity_remove_screen_notifications_on_single_activity_permalink_logged_out() {
    82         $this->create_notifications();
    83         $this->set_permalink_structure( '/%postname%/' );
    84 
    85         $notifications = BP_Notifications_Notification::get( array(
    86             'user_id' => $this->u1,
    87         ) );
    88 
    89         // Double check it's there
    90         $this->assertEquals( array( $this->a1 ), wp_list_pluck( $notifications, 'item_id' ) );
    91 
    92         // Log out
    93         $this->set_current_user( 0 );
     109        // Should be untouched
     110        $this->assertEquals( array( $this->a1 ), wp_list_pluck( $notifications, 'item_id' ) );
     111
     112        $this->set_current_user( $this->u1 );
     113    }
     114
     115    /**
     116     * @group bp_activity_remove_screen_notifications
     117     * @group mentions
     118     */
     119    public function test_bp_activity_remove_screen_notifications_on_single_activity_permalink_wrong_user() {
     120        $this->create_notifications();
     121        $this->set_permalink_structure( '/%postname%/' );
     122
     123        $notifications = BP_Notifications_Notification::get( array(
     124            'user_id' => $this->u1,
     125        ) );
     126
     127        // Double check it's there
     128        $this->assertEquals( array( $this->a1 ), wp_list_pluck( $notifications, 'item_id' ) );
     129
     130        // Switch user
     131        $this->set_current_user( $this->u2 );
    94132
    95133        // Go to the activity permalink page
     
    118156     * @group mentions
    119157     */
    120     public function test_bp_activity_remove_screen_notifications_on_single_activity_permalink_wrong_user() {
    121         $this->create_notifications();
    122         $this->set_permalink_structure( '/%postname%/' );
    123 
    124         $notifications = BP_Notifications_Notification::get( array(
    125             'user_id' => $this->u1,
    126         ) );
    127 
    128         // Double check it's there
    129         $this->assertEquals( array( $this->a1 ), wp_list_pluck( $notifications, 'item_id' ) );
    130 
    131         // Switch user
    132         $this->set_current_user( $this->u2 );
    133 
    134         // Go to the activity permalink page
    135         $this->go_to(
    136             bp_members_get_user_url(
    137                 $this->u1,
    138                 array(
    139                     'single_item_component' => bp_rewrites_get_slug( 'members', 'member_activity', bp_get_activity_slug() ),
    140                     'single_item_action'    => $this->a1,
    141                 )
    142             )
    143         );
    144 
    145         $notifications = BP_Notifications_Notification::get( array(
    146             'user_id' => $this->u1,
    147         ) );
    148 
    149         // Should be untouched
    150         $this->assertEquals( array( $this->a1 ), wp_list_pluck( $notifications, 'item_id' ) );
    151 
    152         $this->set_current_user( $this->u1 );
    153     }
    154 
    155     /**
    156      * @group bp_activity_remove_screen_notifications
    157      * @group mentions
    158      */
    159158    public function test_bp_activity_remove_screen_notifications_on_mentions() {
    160159        $this->create_notifications();
  • trunk/tests/phpunit/testcases/core/nav/bpCoreNewSubnavItem.php

    r13449 r13468  
    349349    }
    350350
     351    public function screen_callback() {
     352        bp_core_load_template( 'members/single/plugins' );
     353    }
     354
     355    public function new_nav_hook() {
     356        bp_core_new_subnav_item(
     357            array(
     358                'name'            => 'Testing',
     359                'slug'            => 'testing',
     360                'parent_slug'     => bp_get_profile_slug(),
     361                'screen_function' => array( $this, 'screen_callback' ),
     362                'position'        => 20
     363            )
     364        );
     365    }
     366
    351367    /**
    352368     * @ticket BP7931
    353369     */
    354370    public function test_subnav_should_not_404_on_early_bp_setup_nav_priority() {
     371        // Register a subnav on 'bp_setup_nav' hook early (at priority zero).
     372        add_action( 'bp_setup_nav', array( $this, 'screen_callback' ), 0 );
     373
    355374        $u = self::factory()->user->create();
    356375        $old_current_user = get_current_user_id();
    357376        $this->set_current_user( $u );
    358377
    359         $user_domain = bp_members_get_user_url( $u );
    360 
    361         // Register a subnav on 'bp_setup_nav' hook early (at priority zero).
    362         add_action( 'bp_setup_nav', function() use ( $user_domain ) {
    363             /*
    364              * Emulate a subnav screen.
    365              *
    366              * The bp_core_load_template() call is imperative for our 404 check to work!
    367              */
    368             $screen = function() {
    369                 bp_core_load_template ('members/single/plugins');
    370             };
    371 
    372             // Register the subnav.
    373             bp_core_new_subnav_item( array (
    374                 'name'            => 'Testing',
    375                 'slug'            => 'testing',
    376                 'parent_url'      => $user_domain . bp_get_profile_slug (). '/',
    377                 'parent_slug'     => bp_get_profile_slug (),
    378                 'screen_function' => $screen,
    379                 'position'        => 20
    380             ) );
    381         }, 0 );
     378        $url = bp_members_get_user_url(
     379            $u,
     380            array(
     381                'single_item_component' => bp_get_profile_slug(),
     382                'single_item_action'    => 'testing',
     383            )
     384        );
    382385
    383386        // Emulate visit to our new subnav page.
    384         $this->go_to( $user_domain . bp_get_profile_slug () . '/testing/' );
     387        $this->go_to( $url );
    385388
    386389        // Assert that subnav page does not 404.
    387390        $this->assertFalse( is_404() );
    388391
     392        remove_action( 'bp_setup_nav', array( $this, 'screen_callback' ), 0 );
     393
    389394        $this->set_current_user( $old_current_user );
    390395    }
  • trunk/tests/phpunit/testcases/routing/groups.php

    r13449 r13468  
    5555    public function test_group_directory_with_type() {
    5656        $this->set_permalink_structure( '/%postname%/' );
    57         bp_groups_register_group_type( 'foo' );
     57        bp_groups_register_group_type(
     58            'foo',
     59            array(
     60                'has_directory' => true,
     61            )
     62        );
     63
     64        $url = bp_get_groups_directory_url(
     65            array(
     66                'directory_type' => 'foo',
     67            )
     68        );
     69
     70        $this->go_to( $url );
     71
     72        $this->assertTrue( bp_is_groups_component() && ! bp_is_group() && bp_is_current_action( bp_get_groups_group_type_base() ) && bp_is_action_variable( 'foo', 0 ) );
     73    }
     74
     75    /**
     76     * @group group_types
     77     */
     78    public function test_group_directory_with_type_that_has_custom_directory_slug() {
     79        $this->set_permalink_structure( '/%postname%/' );
     80        bp_groups_register_group_type( 'bar', array( 'has_directory' => 'bars' ) );
     81
     82        $url = bp_get_groups_directory_url(
     83            array(
     84                'directory_type' => 'bars',
     85            )
     86        );
     87
     88        $this->go_to( $url );
     89
     90        $this->assertTrue( bp_is_groups_component() && ! bp_is_group() && bp_is_current_action( bp_get_groups_group_type_base() ) && bp_is_action_variable( 'bars', 0 ) );
     91    }
     92
     93    /**
     94     * @group group_types
     95     */
     96    public function test_group_directory_should_404_for_group_types_that_have_no_directory() {
     97        $this->set_permalink_structure( '/%postname%/' );
     98        bp_groups_register_group_type( 'taz', array( 'has_directory' => false ) );
     99
    58100        $this->go_to(
    59101            bp_get_groups_directory_url(
    60102                array(
    61                     'directory_type' => 'foo',
    62                 )
    63             )
    64         );
    65         $this->assertTrue( bp_is_groups_component() && ! bp_is_group() && bp_is_current_action( bp_get_groups_group_type_base() ) && bp_is_action_variable( 'foo', 0 ) );
    66     }
    67 
    68     /**
    69      * @group group_types
    70      */
    71     public function test_group_directory_with_type_that_has_custom_directory_slug() {
    72         $this->set_permalink_structure( '/%postname%/' );
    73         bp_groups_register_group_type( 'foo', array( 'has_directory' => 'foos' ) );
    74         $this->go_to(
    75             bp_get_groups_directory_url(
    76                 array(
    77                     'directory_type' => 'foos',
    78                 )
    79             )
    80         );
    81         $this->assertTrue( bp_is_groups_component() && ! bp_is_group() && bp_is_current_action( bp_get_groups_group_type_base() ) && bp_is_action_variable( 'foos', 0 ) );
    82     }
    83 
    84     /**
    85      * @group group_types
    86      */
    87     public function test_group_directory_should_404_for_group_types_that_have_no_directory() {
    88         $this->set_permalink_structure( '/%postname%/' );
    89         bp_groups_register_group_type( 'taz', array( 'has_directory' => false ) );
    90         $this->go_to(
    91             bp_get_groups_directory_url(
    92                 array(
    93103                    'directory_type' => 'taz',
    94104                )
    95105            )
    96106        );
     107
    97108        $this->assertEmpty( bp_get_current_group_directory_type() );
    98109    }
     
    167178    /**
    168179     * @group group_previous_slug
    169      * @group imath
    170180     */
    171181    public function test_group_previous_slug_most_recent_takes_precedence() {
  • trunk/tests/phpunit/testcases/routing/members.php

    r13433 r13468  
    4646        $this->set_permalink_structure( '/%postname%/' );
    4747        bp_register_member_type( 'foo' );
    48         $this->go_to( bp_get_members_directory_permalink() . 'type/foo/' );
     48        $url = bp_get_member_type_directory_permalink( 'foo' );
     49        $this->go_to( $url );
    4950        $this->assertTrue( bp_is_members_component() );
    5051    }
     
    5960
    6061        add_filter( 'bp_members_member_type_base', array( $this, 'filter_member_type_base' ) );
    61         $this->go_to( bp_get_members_directory_permalink() . 'buddypress-member-type/foo/' );
     62
     63        $url = bp_get_member_type_directory_permalink( 'foo' );
     64
    6265        remove_filter( 'bp_members_member_type_base', array( $this, 'filter_member_type_base' ) );
    63         $this->assertTrue( bp_is_members_component() );
     66
     67        $this->assertSame( $url, 'http://example.org/members/bp-member-type/foo/' );
    6468    }
    6569
    6670    public function filter_member_type_base( $base ) {
    67         return 'buddypress-member-type';
     71        return 'bp-member-type';
    6872    }
    6973
  • trunk/tests/phpunit/testcases/routing/root-profiles.php

    r13461 r13468  
    5656     */
    5757    public function test_member_permalink_when_members_page_is_nested_under_wp_page() {
     58        $this->markTestSkipped();
     59
     60        /**
     61         * This is no more supported in BuddyPress.
     62         */
     63
    5864        $this->set_permalink_structure( '/%postname%/' );
    5965        $p = self::factory()->post->create( array(
    60             'post_type' => 'page',
     66            'post_type' => 'post',
    6167            'post_name' => 'foo',
    6268        ) );
     
    6874        ) );
    6975
    70         $domain = home_url( $this->u->user_nicename );
    71         $this->go_to( $domain );
     76        $url = bp_members_get_user_url( $this->u->ID );
     77        $this->go_to( $url );
    7278
    7379        $this->assertTrue( bp_is_user() );
Note: See TracChangeset for help on using the changeset viewer.