Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
03/18/2023 09:42:31 AM (13 months ago)
Author:
imath
Message:

BP Rewrites: start the migration process for the Groups component

  • Add rewrite tags & rules for the Groups directory type and the create URLs.
  • Introduce bp_get_group_url()/bp_group_url() & to retrieve/output a Groups single item URL using BP Rewrites.
  • Introduce bp_get_group_restricted_screens(), bp_get_group_extension_screens() & bp_get_group_screens() to get information about the Groups screens (in particular each screen rewrite ID). These functions will ease slug customizations from the BuddyPress URL settings tab.
  • Improve the Group creation process making sure it's using BP Rewrites to build URLs.
  • Perform easiest replacements for bp_get_group_permalink()/bp_group_permalink() & bp_get_groups_directory_permalink()/bp_groups_directory_permalink() in favor of bp_get_group_url()/bp_group_url() & bp_get_groups_directory_url()/bp_groups_directory_url()`.
  • Improve code formatting & properly escape single group URLs into templates.
  • Update impacted Unit Tests.

Props r-a-y, johnjamesjacoby, boonebgorges

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-groups/classes/class-bp-groups-component.php

    r13432 r13437  
    375375
    376376        // Set default Group creation steps.
    377         $group_creation_steps = array(
    378             'group-details'  => array(
    379                 'name'       => _x( 'Details', 'Group screen nav', 'buddypress' ),
    380                 'position'   => 0
    381             ),
    382             'group-settings' => array(
    383                 'name'       => _x( 'Settings', 'Group screen nav', 'buddypress' ),
    384                 'position'   => 10
    385             )
    386         );
    387 
    388         // If avatar uploads are not disabled, add avatar option.
     377        $group_creation_steps = bp_get_group_screens( 'create' );
     378
     379        // If avatar uploads are disabled, remove avatar view.
    389380        $disabled_avatar_uploads = (int) bp_disable_group_avatar_uploads();
    390         if ( ! $disabled_avatar_uploads && $bp->avatar->show_avatars ) {
    391             $group_creation_steps['group-avatar'] = array(
    392                 'name'     => _x( 'Photo', 'Group screen nav', 'buddypress' ),
    393                 'position' => 20
    394             );
    395         }
    396 
    397         if ( bp_group_use_cover_image_header() ) {
    398             $group_creation_steps['group-cover-image'] = array(
    399                 'name'     => _x( 'Cover Image', 'Group screen nav', 'buddypress' ),
    400                 'position' => 25
    401             );
    402         }
    403 
    404         // If invitations are enabled, add invitations.
    405         if ( bp_is_active( 'groups', 'invitations' ) ) {
    406             $group_creation_steps['group-invites'] = array(
    407                 'name'     => _x( 'Invites',  'Group screen nav', 'buddypress' ),
    408                 'position' => 30
    409             );
     381        if ( $disabled_avatar_uploads || empty( $bp->avatar->show_avatars ) ) {
     382            unset( $group_creation_steps['group-avatar'] );
     383        }
     384
     385        // If cover images are disabled, remove its view.
     386        if ( ! bp_group_use_cover_image_header() ) {
     387            unset( $group_creation_steps['group-cover-image'] );
     388        }
     389
     390        // If the invitations feature is not active, remove the corresponding view.
     391        if ( ! bp_is_active( 'groups', 'invitations' ) ) {
     392            unset( $group_creation_steps['group-invites'] );
    410393        }
    411394
     
    415398         * @since 1.1.0
    416399         *
    417          * @param array $value Array of preconfigured group creation steps.
     400         * @param array $group_creation_steps Array of preconfigured group creation steps.
    418401         */
    419402        $this->group_creation_steps = apply_filters( 'groups_create_group_steps', $group_creation_steps );
     
    542525
    543526        // Prepare for a redirect to the canonical URL.
    544         $bp->canonical_stack['base_url'] = bp_get_group_permalink( $this->current_group );
     527        $bp->canonical_stack['base_url'] = bp_get_group_url( $this->current_group );
    545528
    546529        if ( bp_current_action() ) {
     
    670653            ), 'groups' );
    671654
    672             $group_link = bp_get_group_permalink( $this->current_group );
     655            $group_link = bp_get_group_url( $this->current_group );
    673656
    674657            // Add the "Home" subnav item, as this will always be present.
     
    919902                    'id'       => 'my-account-' . $this->id . '-create',
    920903                    'title'    => _x( 'Create a Group', 'My Account Groups sub nav', 'buddypress' ),
    921                     'href'     => trailingslashit( bp_get_groups_directory_permalink() . 'create' ),
     904                    'href'     => bp_get_groups_directory_url(
     905                        array(
     906                            'create_single_item' => 1,
     907                        )
     908                    ),
    922909                    'position' => 90
    923910                );
     
    1009996        // Just let BP Component fire 'bp_groups_register_taxonomies'.
    1010997        return parent::register_taxonomies();
     998    }
     999
     1000    /**
     1001     * Adds the Groups directory type & Group create rewrite tags.
     1002     *
     1003     * @since 12.0.0
     1004     *
     1005     * @param array $rewrite_tags Optional. See BP_Component::add_rewrite_tags() for
     1006     *                            description.
     1007     */
     1008    public function add_rewrite_tags( $rewrite_tags = array() ) {
     1009        $rewrite_tags = array(
     1010            'directory_type'               => '([^/]+)',
     1011            'create_single_item'           => '([1]{1,})',
     1012            'create_single_item_variables' => '(.+?)',
     1013        );
     1014
     1015        parent::add_rewrite_tags( $rewrite_tags );
     1016    }
     1017
     1018    /**
     1019     * Adds the Groups directory type & Group create rewrite rules.
     1020     *
     1021     * @since 12.0.0
     1022     *
     1023     * @param array $rewrite_rules Optional. See BP_Component::add_rewrite_rules() for
     1024     *                             description.
     1025     */
     1026    public function add_rewrite_rules( $rewrite_rules = array() ) {
     1027        $create_slug = bp_rewrites_get_slug( 'groups', 'group_create', 'create' );
     1028
     1029        $rewrite_rules = array(
     1030            'directory_type'      => array(
     1031                'regex' => $this->root_slug . '/' . bp_get_groups_group_type_base() . '/([^/]+)/?$',
     1032                'order' => 50,
     1033                'query' => 'index.php?' . $this->rewrite_ids['directory'] . '=1&' . $this->rewrite_ids['directory_type'] . '=$matches[1]',
     1034            ),
     1035            'create_single_item' => array(
     1036                'regex' => $this->root_slug . '/' . $create_slug . '/?$',
     1037                'order' => 40,
     1038                'query' => 'index.php?' . $this->rewrite_ids['directory'] . '=1&' . $this->rewrite_ids['create_single_item'] . '=1',
     1039            ),
     1040            'create_single_item_variables' => array(
     1041                'regex' => $this->root_slug . '/' . $create_slug . '/(.+?)/?$',
     1042                'order' =>30,
     1043                'query' => 'index.php?' . $this->rewrite_ids['directory'] . '=1&' . $this->rewrite_ids['create_single_item'] . '=1&' . $this->rewrite_ids['create_single_item_variables'] . '=$matches[1]',
     1044            ),
     1045        );
     1046
     1047        parent::add_rewrite_rules( $rewrite_rules );
    10111048    }
    10121049
Note: See TracChangeset for help on using the changeset viewer.