Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
04/08/2023 06:31:46 AM (4 years 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/actions/create.php

    r13437 r13449  
    3131        }
    3232
    33         $bp = buddypress();
     33        $bp           = buddypress();
     34        $redirect_url = bp_groups_get_create_url();
    3435
    3536        // Make sure creation steps are in the right order.
    … …  
    4546                setcookie( 'bp_completed_create_steps', false, time() - 1000, COOKIEPATH, COOKIE_DOMAIN, is_ssl() );
    4647
    47                 $reset_steps = true;
    48                 $keys        = array_keys( $bp->groups->group_creation_steps );
    49                 bp_core_redirect( trailingslashit( bp_get_groups_directory_permalink() . 'create/step/' . array_shift( $keys ) ) );
     48                $reset_steps     = true;
     49                $keys            = array_keys( $bp->groups->group_creation_steps );
     50                $action_variable = array_shift( $keys );
     51                bp_core_redirect( bp_groups_get_create_url( array( $action_variable ) ) );
    5052        }
    5153
    … …  
    5355        if ( bp_get_groups_current_create_step() && empty( $bp->groups->group_creation_steps[bp_get_groups_current_create_step()] ) ) {
    5456                bp_core_add_message( __('There was an error saving group details. Please try again.', 'buddypress'), 'error' );
    55                 bp_core_redirect( trailingslashit( bp_get_groups_directory_permalink() . 'create' ) );
     57                bp_core_redirect( $redirect_url );
    5658        }
    5759
    … …  
    6769                if ( ! bp_is_group_creator( $bp->groups->current_group, bp_loggedin_user_id() ) ) {
    6870                        bp_core_add_message( __( 'Only the group creator may continue editing this group.', 'buddypress' ), 'error' );
    69                         bp_core_redirect( trailingslashit( bp_get_groups_directory_permalink() . 'create' ) );
     71                        bp_core_redirect( $redirect_url );
    7072                }
    7173        }
    … …  
    8082                        if ( empty( $_POST['group-name'] ) || empty( $_POST['group-desc'] ) || !strlen( trim( $_POST['group-name'] ) ) || !strlen( trim( $_POST['group-desc'] ) ) ) {
    8183                                bp_core_add_message( __( 'Please fill in all of the required fields', 'buddypress' ), 'error' );
    82                                 bp_core_redirect( trailingslashit( bp_get_groups_directory_permalink() . 'create/step/' . bp_get_groups_current_create_step() ) );
     84                                bp_core_redirect( bp_groups_get_create_url( array( bp_get_groups_current_create_step() ) ) );
    8385                        }
    8486
    8587                        $new_group_id = isset( $bp->groups->new_group_id ) ? $bp->groups->new_group_id : 0;
    8688
    87                         if ( !$bp->groups->new_group_id = groups_create_group( array( 'group_id' => $new_group_id, 'name' => $_POST['group-name'], 'description' => $_POST['group-desc'], 'slug' => groups_check_slug( sanitize_title( esc_attr( $_POST['group-name'] ) ) ), 'date_created' => bp_core_current_time(), 'status' => 'public' ) ) ) {
     89                        if ( ! $bp->groups->new_group_id = groups_create_group( array( 'group_id' => $new_group_id, 'name' => $_POST['group-name'], 'description' => $_POST['group-desc'], 'slug' => groups_check_slug( sanitize_title( esc_attr( $_POST['group-name'] ) ) ), 'date_created' => bp_core_current_time(), 'status' => 'public' ) ) ) {
    8890                                bp_core_add_message( __( 'There was an error saving group details. Please try again.', 'buddypress' ), 'error' );
    89                                 bp_core_redirect( trailingslashit( bp_get_groups_directory_permalink() . 'create/step/' . bp_get_groups_current_create_step() ) );
     91                                bp_core_redirect( bp_groups_get_create_url( array( bp_get_groups_current_create_step() ) ) );
    9092                        }
    9193                }
    … …  
    104106                                $group_status = 'hidden';
    105107
    106                         if ( !$bp->groups->new_group_id = groups_create_group( array( 'group_id' => $bp->groups->new_group_id, 'status' => $group_status, 'enable_forum' => $group_enable_forum ) ) ) {
     108                        if ( ! $bp->groups->new_group_id = groups_create_group( array( 'group_id' => $bp->groups->new_group_id, 'status' => $group_status, 'enable_forum' => $group_enable_forum ) ) ) {
    107109                                bp_core_add_message( __( 'There was an error saving group details. Please try again.', 'buddypress' ), 'error' );
    108                                 bp_core_redirect( trailingslashit( bp_get_groups_directory_permalink() . 'create/step/' . bp_get_groups_current_create_step() ) );
     110                                bp_core_redirect( bp_groups_get_create_url( array( bp_get_groups_current_create_step() ) ) );
    109111                        }
    110112
    … …  
    219221                        }
    220222
    221                         bp_core_redirect( trailingslashit( bp_get_groups_directory_permalink() . 'create/step/' . $next_step ) );
     223                        $redirect_url = bp_get_groups_directory_url( bp_groups_get_path_chunks( array( $next_step ), 'create' ) );
     224                        bp_core_redirect( $redirect_url );
    222225                }
    223226        }
    … …  
    238241
    239242                bp_core_add_message( $message, $error );
    240                 bp_core_redirect( trailingslashit( bp_get_groups_directory_permalink() . 'create/step/group-invites' ) );
     243                bp_core_redirect( bp_groups_get_create_url( array( 'group-invites' ) ) );
    241244        }
    242245
Note: See TracChangeset for help on using the changeset viewer.