Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
03/23/2023 07:35:38 PM (13 months ago)
Author:
imath
Message:

Make BP_Core_Nav generate "BP Rewrites ready" navigation links

  • Remove all components $parent_url attributes when setting sub nav items.
  • Only use the bp_core_create_nav_link() $link attribute argument & the bp_core_create_subnav_link() $parent_url attribute argument if specified to preserve backward compatibility.
  • Migrates the Community search feature so that it uses BP Rewrites.
  • Perform some bp_loggedin_user_domain() in favor of bp_loggedin_user_url().
  • Update some PHPUnit tests.

Props r-a-y, johnjamesjacoby, boonebgorges

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

File:
1 edited

Legend:

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

    r13436 r13441  
    119119 */
    120120function bp_rewrites_get_url( $args = array() ) {
    121     $bp   = buddypress();
     121    $bp  = buddypress();
    122122    $url = get_home_url( bp_get_root_blog_id() );
    123123
     
    159159            // Using pretty URLs.
    160160        } else {
    161             if ( ! isset( $component->rewrite_ids['directory'] ) || ! isset( $component->directory_permastruct ) ) {
     161            if ( isset( $component->rewrite_ids['directory'] ) && isset( $component->directory_permastruct ) ) {
     162                if ( isset( $r['member_register'] ) ) {
     163                    $url = str_replace( '%' . $component->rewrite_ids['member_register'] . '%', '', $component->register_permastruct );
     164                    unset( $r['member_register'] );
     165                } elseif ( isset( $r['member_activate'] ) ) {
     166                    $url = str_replace( '%' . $component->rewrite_ids['member_activate'] . '%', '', $component->activate_permastruct );
     167                    unset( $r['member_activate'] );
     168                } elseif ( isset( $r['create_single_item'] ) ) {
     169                    $create_slug = 'create';
     170                    if ( 'groups' === $component->id ) {
     171                        $create_slug = bp_rewrites_get_slug( 'groups', 'group_create', 'create' );
     172                    } elseif ( 'blogs' === $component->id ) {
     173                        $create_slug = bp_rewrites_get_slug( 'blogs', 'blog_create', 'create' );
     174                    }
     175
     176                    $url = str_replace( '%' . $component->rewrite_ids['directory'] . '%', $create_slug, $component->directory_permastruct );
     177                    unset( $r['create_single_item'] );
     178                } else {
     179                    $url = str_replace( '%' . $component->rewrite_ids['directory'] . '%', $r['single_item'], $component->directory_permastruct );
     180
     181                    // Remove the members directory slug when root profiles are on.
     182                    if ( bp_core_enable_root_profiles() && 'members' === $component->id && isset( $r['single_item'] ) && $r['single_item'] ) {
     183                        $url = str_replace( $bp->members->root_slug . '/', '', $url );
     184                    }
     185
     186                    unset( $r['single_item'] );
     187                }
     188
     189                $r = array_filter( $r );
     190
     191                if ( isset( $r['directory_type'] ) && $r['directory_type'] ) {
     192                    if ( 'members' === $component->id ) {
     193                        array_unshift( $r, bp_get_members_member_type_base() );
     194                    } elseif ( 'groups' === $component->id && bp_is_active( 'groups' ) ) {
     195                        array_unshift( $r, bp_get_groups_group_type_base() );
     196                    } else {
     197                        unset( $r['directory_type'] );
     198                    }
     199                }
     200
     201                if ( isset( $r['single_item_action_variables'] ) && $r['single_item_action_variables'] ) {
     202                    $r['single_item_action_variables'] = join( '/', (array) $r['single_item_action_variables'] );
     203                }
     204
     205                if ( isset( $r['create_single_item_variables'] ) && $r['create_single_item_variables'] ) {
     206                    $r['create_single_item_variables'] = join( '/', (array) $r['create_single_item_variables'] );
     207                }
     208            } elseif ( isset( $r['community_search'] ) && 1 === $r['community_search'] ) {
     209                $r   = array_filter( $r );
     210                $url = '';
     211
     212                unset( $r['community_search'] );
     213                array_unshift( $r, bp_get_search_slug() );
     214            } else {
    162215                return $url;
    163             }
    164 
    165             if ( isset( $r['member_register'] ) ) {
    166                 $url = str_replace( '%' . $component->rewrite_ids['member_register'] . '%', '', $component->register_permastruct );
    167                 unset( $r['member_register'] );
    168             } elseif ( isset( $r['member_activate'] ) ) {
    169                 $url = str_replace( '%' . $component->rewrite_ids['member_activate'] . '%', '', $component->activate_permastruct );
    170                 unset( $r['member_activate'] );
    171             } elseif ( isset( $r['create_single_item'] ) ) {
    172                 $create_slug = 'create';
    173                 if ( 'groups' === $component->id ) {
    174                     $create_slug = bp_rewrites_get_slug( 'groups', 'group_create', 'create' );
    175                 } elseif ( 'blogs' === $component->id ) {
    176                     $create_slug = bp_rewrites_get_slug( 'blogs', 'blog_create', 'create' );
    177                 }
    178 
    179                 $url = str_replace( '%' . $component->rewrite_ids['directory'] . '%', $create_slug, $component->directory_permastruct );
    180                 unset( $r['create_single_item'] );
    181             } else {
    182                 $url = str_replace( '%' . $component->rewrite_ids['directory'] . '%', $r['single_item'], $component->directory_permastruct );
    183 
    184                 // Remove the members directory slug when root profiles are on.
    185                 if ( bp_core_enable_root_profiles() && 'members' === $component->id && isset( $r['single_item'] ) && $r['single_item'] ) {
    186                     $url = str_replace( $bp->members->root_slug . '/', '', $url );
    187                 }
    188 
    189                 unset( $r['single_item'] );
    190             }
    191 
    192             $r = array_filter( $r );
    193 
    194             if ( isset( $r['directory_type'] ) && $r['directory_type'] ) {
    195                 if ( 'members' === $component->id ) {
    196                     array_unshift( $r, bp_get_members_member_type_base() );
    197                 } elseif ( 'groups' === $component->id && bp_is_active( 'groups' ) ) {
    198                     array_unshift( $r, bp_get_groups_group_type_base() );
    199                 } else {
    200                     unset( $r['directory_type'] );
    201                 }
    202             }
    203 
    204             if ( isset( $r['single_item_action_variables'] ) && $r['single_item_action_variables'] ) {
    205                 $r['single_item_action_variables'] = join( '/', (array) $r['single_item_action_variables'] );
    206             }
    207 
    208             if ( isset( $r['create_single_item_variables'] ) && $r['create_single_item_variables'] ) {
    209                 $r['create_single_item_variables'] = join( '/', (array) $r['create_single_item_variables'] );
    210216            }
    211217
Note: See TracChangeset for help on using the changeset viewer.