Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
04/04/2023 01:06:03 AM (14 months ago)
Author:
imath
Message:

Use the BP Rewrites API to generate single Groups item links

  • Introduce the bp_groups_get_path_chunks() function to build BP Rewrites arguments using a regular array.
  • Improve bp_members_get_path_chunks() so that it avoids looking for a custom slug when the chunk is a numeric value.
  • Introduce the bp_get_group_manage_url() function to build Group's front-end Admin URLs using BP Rewrites.
  • Deprecate bp_group_admin_permalink() & bp_get_group_admin_permalink() in favor of bp_group_manage_url() & bp_get_group_manage_url().
  • Replace all remaining usage of bp_get_group_permalink() in favor of bp_get_group_url() or bp_get_group_manage_url().

Props r-a-y, johnjamesjacoby, boonebgorges

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

File:
1 edited

Legend:

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

    r13437 r13446  
    38363836                'position'        => 10,
    38373837                'item_css_id'     => 'home',
     3838            ),
     3839            'activity'            => array(
     3840                'rewrite_id'      => 'bp_group_read_activity',
     3841                'slug'            => 'activity',
     3842                'name'            => _x( 'Activity', 'Group read screen', 'buddypress' ),
     3843                'screen_function' => 'groups_screen_group_activity',
     3844                'position'        => 11,
     3845                'user_has_access' => false,
     3846                'no_access_url'   => '',
     3847                'item_css_id'     => 'activity',
    38383848            ),
    38393849            'request-membership' => array(
     
    39803990    return $context_screens;
    39813991}
     3992
     3993/**
     3994 * Get single group's path chunks using an array of URL slugs.
     3995 *
     3996 * @since 12.0.0
     3997 *
     3998 * @param array $chunks An array of URL slugs.
     3999 * @return array An array of BP Rewrites URL arguments.
     4000 */
     4001function bp_groups_get_path_chunks( $chunks = array(), $context = 'read' ) {
     4002    $path_chunks   = array();
     4003    $group_screens = bp_get_group_screens( $context );
     4004
     4005    if ( 'read' === $context ) {
     4006        $single_item_action = array_shift( $chunks );
     4007        if ( $single_item_action ) {
     4008            if ( isset( $group_screens[ $single_item_action ]['rewrite_id'] ) ) {
     4009                $item_action_rewrite_id            = $group_screens[ $single_item_action ]['rewrite_id'];
     4010                $path_chunks['single_item_action'] = bp_rewrites_get_slug( 'groups', $item_action_rewrite_id, $single_item_action );
     4011            } else {
     4012                $path_chunks['single_item_action'] = $single_item_action;
     4013            }
     4014        }
     4015    }
     4016
     4017    if ( $chunks ) {
     4018        foreach ( $chunks as $chunk ) {
     4019            if ( is_numeric( $chunk ) ) {
     4020                $path_chunks['single_item_action_variables'][] = $chunk;
     4021            } else {
     4022                if ( isset( $group_screens[ $chunk ]['rewrite_id'] ) ) {
     4023                    $item_action_variable_rewrite_id               = $group_screens[ $chunk ]['rewrite_id'];
     4024                    $path_chunks['single_item_action_variables'][] = bp_rewrites_get_slug( 'groups', $item_action_variable_rewrite_id, $chunk );
     4025                } else {
     4026                    $path_chunks['single_item_action_variables'][] = $chunk;
     4027                }
     4028            }
     4029        }
     4030    }
     4031
     4032    return $path_chunks;
     4033}
Note: See TracChangeset for help on using the changeset viewer.