Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
04/08/2023 06:31:46 AM (20 months ago)
Author:
imath
Message:

Make sure all Groups component URLs are built using BP rewrites API

  • Introduce the bp_groups_get_create_url() to ease Groups create URLs generation.
  • Improve bp_groups_get_path_chunks() to deal with front-end group admin URLs and the Groups create URLs.
  • Deprecate bp_get_groups_directory_permalink() in favor of bp_get_groups_directory_url().
  • Replace all remaining deprecated functions usage.
  • Start putting deprecated functions behind a function_exists( 'bp_classic' ) check, corresponding functions were added inside the BP Classic backcompat plugin.
  • Adjust some Groups routing unit tests.

Props r-a-y, johnjamesjacoby, boonebgorges

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

File:
1 edited

Legend:

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

    r13446 r13449  
    146146
    147147/**
    148  * Output group directory permalink.
    149  *
    150  * @since 1.5.0
    151  * @deprecated 12.0.0
    152  */
    153 function bp_groups_directory_permalink() {
    154     _deprecated_function( __FUNCTION__, '12.0.0', 'bp_groups_directory_url()' );
    155     bp_groups_directory_url();
    156 }
    157     /**
    158      * Return group directory permalink.
    159      *
    160      * @since 1.5.0
    161      * @deprecated 12.0.0
    162      *
    163      * @return string
    164      */
    165     function bp_get_groups_directory_permalink() {
    166         /*
    167          * This function is used at many places and we need to review all this
    168          * places during the 12.0 development cycle. Using BP Rewrites means we
    169          * cannot concatenate URL chunks to build our URL anymore. We now need
    170          * to use `bp_get_groups_directory_url( $array )` and make sure to use
    171          * the right arguments inside this `$array`. Morevover as this function
    172          * is also used to build a single group URL, we need to create a new
    173          * function to create single group URLs using BP Rewrites.
    174          *
    175          * @todo Once every link reviewed, we'll be able to remove this check
    176          *       and let PHPUnit tell us the one we forgot, eventually!
    177          */
    178         if ( ! buddypress()->is_phpunit_running ) {
    179             _deprecated_function( __FUNCTION__, '12.0.0', 'bp_get_groups_directory_url()' );
    180         }
    181 
    182         $url = bp_get_groups_directory_url();
    183 
    184         /**
    185          * Filters the group directory permalink.
    186          *
    187          * @since 1.5.0
    188          * @deprecated 12.0.0
    189          *
    190          * @param string $url Permalink for the group directory.
    191          */
    192         return apply_filters_deprecated( 'bp_get_groups_directory_permalink', array( $url ), '12.0.0', 'bp_get_groups_directory_url' );
    193     }
     148 * Returns a group create URL accoding to requested path chunks.
     149 *
     150 * @since 12.0.0
     151 *
     152 * @param array $chunks array A list of create action variables.
     153 * @return string The group create URL.
     154 */
     155function bp_groups_get_create_url( $action_variables = array() ) {
     156    $path_chunks = array();
     157
     158    if ( is_array( $action_variables ) && $action_variables ) {
     159        $path_chunks = bp_groups_get_path_chunks( $action_variables, 'create' );
     160    } else {
     161        $path_chunks = array(
     162            'create_single_item' => 1,
     163        );
     164    }
     165
     166    return bp_get_groups_directory_url( $path_chunks );
     167}
    194168
    195169/**
     
    227201        }
    228202
     203        $url = bp_get_groups_directory_url(
     204            array(
     205                'directory_type' => $type->directory_slug,
     206            )
     207        );
     208
    229209        /**
    230210         * Filters the group type directory permalink.
     
    232212         * @since 2.7.0
    233213         *
    234          * @param string $value       Group type directory permalink.
     214         * @param string $url         Group type directory permalink.
    235215         * @param object $type        Group type object.
    236216         * @param string $member_type Group type name, as passed to the function.
    237217         */
    238         return apply_filters( 'bp_get_group_type_directory_permalink', trailingslashit( bp_get_groups_directory_permalink() . bp_get_groups_group_type_base() . '/' . $type->directory_slug ), $type, $group_type );
     218        return apply_filters( 'bp_get_group_type_directory_permalink', $url, $type, $group_type );
    239219    }
    240220
     
    12741254    $slug = groups_get_slug( $group );
    12751255
    1276     if ( $group instanceof BP_Groups_Group ) {
     1256    if ( $group instanceof BP_Groups_Group || ( is_object( $group ) && isset( $group->id, $group->name, $group->slug ) ) ) {
    12771257        $group_id = (int) $group->id;
    12781258    } else {
     
    39743954            'link_text'  => __( 'Create a Group', 'buddypress' ),
    39753955            'link_class' => 'group-create no-ajax',
    3976             'link_href'  => bp_get_groups_directory_url(
    3977                 array(
    3978                     'create_single_item' => 1,
    3979                 )
    3980             ),
     3956            'link_href'  => bp_groups_get_create_url(),
    39813957            'wrapper'    => false,
    39823958            'block_self' => false,
     
    50695045
    50705046        if ( $is_enabled && isset( $create_steps[ $create_step ]['rewrite_id'], $create_steps[ $create_step ]['default_slug'] ) ) {
    5071             $create_step_slug = bp_rewrites_get_slug( 'groups', 'bp_group_create_step', 'step' );
    5072             $step_slug        = bp_rewrites_get_slug( 'groups', $create_steps[ $create_step ]['rewrite_id'], $create_steps[ $create_step ]['default_slug'] );
    5073             $url              = bp_get_groups_directory_url(
    5074                 array(
    5075                     'create_single_item'           => 1,
    5076                     'create_single_item_variables' => array( $create_step_slug, $step_slug ),
    5077                 )
    5078             );
     5047            $url = bp_groups_get_create_url( array( $create_steps[ $create_step ]['default_slug'] ) );
    50795048
    50805049            $step_name = sprintf( '<a href="%1$s">%2$s. %3$s</a>', esc_url( $url ), absint( $counter ), esc_html( $step_name ) );
     
    51375106        $create_step  = bp_action_variable( 1 );
    51385107        if ( $create_step && isset( $create_steps[ $create_step ]['rewrite_id'], $create_steps[ $create_step ]['default_slug'] ) ) {
    5139             $create_step_slug = bp_rewrites_get_slug( 'groups', 'bp_group_create_step', 'step' );
    5140             $step_slug        = bp_rewrites_get_slug( 'groups', $create_steps[ $create_step ]['rewrite_id'], $create_steps[ $create_step ]['default_slug'] );
    5141 
    5142             $url = bp_get_groups_directory_url(
    5143                 array(
    5144                     'create_single_item'           => 1,
    5145                     'create_single_item_variables' => array( $create_step_slug, $step_slug ),
    5146                 )
    5147             );
     5108            $url = bp_groups_get_create_url( array( $create_steps[ $create_step ]['default_slug'] ) );
    51485109        }
    51495110
     
    55055466
    55065467        if ( isset( $create_steps[ $previous_step ]['rewrite_id'], $create_steps[ $previous_step ]['default_slug'] ) ) {
    5507             $create_step_slug = bp_rewrites_get_slug( 'groups', 'bp_group_create_step', 'step' );
    5508             $previous_step    = bp_rewrites_get_slug( 'groups', $create_steps[ $previous_step ]['rewrite_id'], $create_steps[ $previous_step ]['default_slug'] );
    5509 
    5510             $url = bp_get_groups_directory_url(
    5511                 array(
    5512                     'create_single_item'           => 1,
    5513                     'create_single_item_variables' => array( $create_step_slug, $previous_step ),
    5514                 )
    5515             );
     5468            $url = bp_groups_get_create_url( array( $create_steps[ $previous_step ]['default_slug'] ) );
    55165469        }
    55175470
     
    64886441
    64896442        if ( bp_is_current_action( 'create' ) ) {
    6490             $uninvite_url = bp_get_groups_directory_permalink() . 'create/step/group-invites/?user_id=' . $user_id;
     6443            $uninvite_url = add_query_arg(
     6444                'user_id',
     6445                $user_id,
     6446                bp_get_groups_directory_url( bp_groups_get_path_chunks( array( 'group-invites' ), 'create' ) )
     6447            );
    64916448        } else {
    64926449            $uninvite_url = bp_get_group_url(
Note: See TracChangeset for help on using the changeset viewer.