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/bp-groups-notifications.php

    r13436 r13437  
    5252                /* translators: 1: the old group permalink. 2: the new group permalink. */
    5353                _x( '* Permalink changed from "%1$s" to "%2$s".', 'Group update email text', 'buddypress' ),
    54                 esc_url( bp_get_group_permalink( $old_group ) ),
    55                 esc_url( bp_get_group_permalink( $group ) )
     54                esc_url( bp_get_group_url( $old_group ) ),
     55                esc_url( bp_get_group_url( $group ) )
    5656            );
    5757        }
     
    9090                'group'        => $group,
    9191                'group.id'     => $group_id,
    92                 'group.url'    => esc_url( bp_get_group_permalink( $group ) ),
     92                'group.url'    => esc_url( bp_get_group_url( $group ) ),
    9393                'group.name'   => $group->name,
    9494                'unsubscribe'  => esc_url( bp_email_get_unsubscribe_link( $unsubscribe_args ) ),
     
    216216            'group.id'           => $group_id,
    217217            'group.name'         => $group->name,
    218             'group.url'          => esc_url( bp_get_group_permalink( $group ) ),
     218            'group.url'          => esc_url( bp_get_group_url( $group ) ),
    219219            'requesting-user.id' => $requesting_user_id,
    220220        ),
     
    291291            'group'       => $group,
    292292            'group.id'    => $group_id,
    293             'group.url'   => esc_url( bp_get_group_permalink( $group ) ),
     293            'group.url'   => esc_url( bp_get_group_url( $group ) ),
    294294            'group.name'  => $group->name,
    295295            'promoted_to' => $promoted_to,
     
    363363        'tokens' => array(
    364364            'group'          => $group,
    365             'group.url'      => bp_get_group_permalink( $group ),
     365            'group.url'      => esc_url( bp_get_group_url( $group ) ),
    366366            'group.name'     => $group->name,
    367367            'inviter.name'   => bp_core_get_userlink( $inviter_user_id, true, false ),
     
    397397    switch ( $action ) {
    398398        case 'new_membership_request':
    399             $group_id = $item_id;
     399            $group_id           = $item_id;
    400400            $requesting_user_id = $secondary_item_id;
    401401
    402             $group = groups_get_group( $group_id );
    403             $group_link = bp_get_group_permalink( $group );
    404             $amount = 'single';
    405 
    406             // Set up the string and the filter
    407             // because different values are passed to the filters,
    408             // we'll return values inline.
     402            $group      = groups_get_group( $group_id );
     403            $group_link = bp_get_group_url( $group );
     404            $amount     = 'single';
     405
     406            /*
     407             * Set up the string and the filter
     408             * because different values are passed to the filters,
     409             * we'll return values inline.
     410             */
    409411            if ( (int) $total_items > 1 ) {
    410412                /* translators: 1: number of group membership requests. 2: group name. */
    411                 $text = sprintf( __( '%1$d new membership requests for the group "%2$s"', 'buddypress' ), (int) $total_items, $group->name );
    412                 $amount = 'multiple';
    413                 $notification_link = $group_link . 'admin/membership-requests/?n=1';
     413                $text              = sprintf( __( '%1$d new membership requests for the group "%2$s"', 'buddypress' ), (int) $total_items, $group->name );
     414                $amount            = 'multiple';
     415                $notification_link = add_query_arg(
     416                    array(
     417                        'n' => 1,
     418                    ),
     419                    bp_get_group_url(
     420                        $group,
     421                        array(
     422                            'single_item_action'           => bp_rewrites_get_slug( 'groups', 'bp_group_read_admin', 'admin' ),
     423                            'single_item_action_variables' => array( bp_rewrites_get_slug( 'groups', 'bp_group_manage_membership_requests', 'membership-requests' ) ),
     424                        )
     425                    )
     426                );
    414427
    415428                if ( 'string' == $format ) {
     
    430443                     * @param string $notification_link The permalink for notification.
    431444                     */
    432                     return apply_filters( 'bp_groups_' . $amount . '_' . $action . 's_notification', '<a href="' . $notification_link . '">' . $text . '</a>', $group_link, $total_items, $group->name, $text, $notification_link );
     445                    return apply_filters( 'bp_groups_' . $amount . '_' . $action . 's_notification', '<a href="' . esc_url( $notification_link ) . '">' . esc_html( $text ) . '</a>', $group_link, $total_items, $group->name, $text, $notification_link );
    433446                } else {
    434447
     
    455468            } else {
    456469                $user_fullname = bp_core_get_user_displayname( $requesting_user_id );
     470
    457471                /* translators: %s: member name */
    458                 $text = sprintf( __( '%s requests group membership', 'buddypress' ), $user_fullname );
    459                 $notification_link = $group_link . 'admin/membership-requests/?n=1';
     472                $text              = sprintf( __( '%s requests group membership', 'buddypress' ), $user_fullname );
     473                $notification_link = $notification_link = add_query_arg(
     474                    array(
     475                        'n' => 1,
     476                    ),
     477                    bp_get_group_url(
     478                        $group,
     479                        array(
     480                            'single_item_action'           => bp_rewrites_get_slug( 'groups', 'bp_group_read_admin', 'admin' ),
     481                            'single_item_action_variables' => array( bp_rewrites_get_slug( 'groups', 'bp_group_manage_membership_requests', 'membership-requests' ) ),
     482                        )
     483                    )
     484                );
    460485
    461486                if ( 'string' == $format ) {
     
    476501                     * @param string $notification_link The permalink for notification.
    477502                     */
    478                     return apply_filters( 'bp_groups_' . $amount . '_' . $action . '_notification', '<a href="' . $notification_link . '">' . $text . '</a>', $group_link, $user_fullname, $group->name, $text, $notification_link );
     503                    return apply_filters( 'bp_groups_' . $amount . '_' . $action . '_notification', '<a href="' . esc_url( $notification_link ) . '">' . esc_html( $text ) . '</a>', $group_link, $user_fullname, $group->name, $text, $notification_link );
    479504                } else {
    480505
     
    506531            $group_id = $item_id;
    507532
    508             $group = groups_get_group( $group_id );
    509             $group_link = bp_get_group_permalink( $group );
    510             $amount = 'single';
     533            $group      = groups_get_group( $group_id );
     534            $group_link = bp_get_group_url( $group );
     535            $amount     = 'single';
    511536
    512537            if ( (int) $total_items > 1 ) {
    513538                /* translators: 1: number of accepted group membership requests. 2: group name. */
    514                 $text = sprintf( __( '%1$d accepted group membership requests for the group "%2$s"', 'buddypress' ), (int) $total_items, $group->name );
    515                 $amount = 'multiple';
     539                $text              = sprintf( __( '%1$d accepted group membership requests for the group "%2$s"', 'buddypress' ), (int) $total_items, $group->name );
     540                $amount            = 'multiple';
    516541                $notification_link = trailingslashit( bp_loggedin_user_domain() . bp_get_groups_slug() ) . '?n=1';
    517542
     
    530555                     * @param string $notification_link The permalink for notification.
    531556                     */
    532                     return apply_filters( 'bp_groups_' . $amount . '_' . $action . '_notification', '<a href="' . $notification_link . '">' . $text . '</a>', $total_items, $group->name, $text, $notification_link );
     557                    return apply_filters( 'bp_groups_' . $amount . '_' . $action . '_notification', '<a href="' . esc_url( $notification_link ) . '">' . esc_html( $text ) . '</a>', $total_items, $group->name, $text, $notification_link );
    533558                } else {
    534559
     
    552577            } else {
    553578                /* translators: %s: group name. */
    554                 $text = sprintf( __( 'Membership for group "%s" accepted', 'buddypress' ), $group->name );
    555                 $filter = 'bp_groups_single_membership_request_accepted_notification';
    556                 $notification_link = $group_link . '?n=1';
     579                $text              = sprintf( __( 'Membership for group "%s" accepted', 'buddypress' ), $group->name );
     580                $filter            = 'bp_groups_single_membership_request_accepted_notification';
     581                $notification_link = add_query_arg( 'n', 1, $group_link );
    557582
    558583                if ( 'string' == $format ) {
     
    570595                     * @param string $notification_link The permalink for notification.
    571596                     */
    572                     return apply_filters( 'bp_groups_' . $amount . '_' . $action . '_notification', '<a href="' . $notification_link . '">' . $text . '</a>', $group_link, $group->name, $text, $notification_link );
     597                    return apply_filters( 'bp_groups_' . $amount . '_' . $action . '_notification', '<a href="' . esc_url( $notification_link ) . '">' . esc_html( $text ) . '</a>', $group_link, $group->name, $text, $notification_link );
    573598                } else {
    574599
     
    597622            $group_id = $item_id;
    598623
    599             $group = groups_get_group( $group_id );
    600             $group_link = bp_get_group_permalink( $group );
    601             $amount = 'single';
     624            $group      = groups_get_group( $group_id );
     625            $group_link = bp_get_group_url( $group );
     626            $amount     = 'single';
    602627
    603628            if ( (int) $total_items > 1 ) {
    604629                /* translators: 1: number of accepted group membership requests. 2: group name. */
    605                 $text = sprintf( __( '%1$d rejected group membership requests for the group "%2$s"', 'buddypress' ), (int) $total_items, $group->name );
    606                 $amount = 'multiple';
     630                $text              = sprintf( __( '%1$d rejected group membership requests for the group "%2$s"', 'buddypress' ), (int) $total_items, $group->name );
     631                $amount            = 'multiple';
    607632                $notification_link = trailingslashit( bp_loggedin_user_domain() . bp_get_groups_slug() ) . '?n=1';
    608633
     
    621646                     * @param string $notification_link The permalink for notification.
    622647                     */
    623                     return apply_filters( 'bp_groups_' . $amount . '_' . $action . '_notification', '<a href="' . $notification_link . '">' . $text . '</a>', $total_items, $group->name, $text, $notification_link );
     648                    return apply_filters( 'bp_groups_' . $amount . '_' . $action . '_notification', '<a href="' . esc_url( $notification_link ) . '">' . esc_html( $text ) . '</a>', $total_items, $group->name, $text, $notification_link );
    624649                } else {
    625650
     
    643668            } else {
    644669                /* translators: %s: group name. */
    645                 $text = sprintf( __( 'Membership for group "%s" rejected', 'buddypress' ), $group->name );
    646                 $notification_link = $group_link . '?n=1';
     670                $text              = sprintf( __( 'Membership for group "%s" rejected', 'buddypress' ), $group->name );
     671                $notification_link = add_query_arg( 'n', 1, $group_link );
    647672
    648673                if ( 'string' == $format ) {
     
    660685                     * @param string $notification_link The permalink for notification.
    661686                     */
    662                     return apply_filters( 'bp_groups_' . $amount . '_' . $action . '_notification', '<a href="' . $notification_link . '">' . $text . '</a>', $group_link, $group->name, $text, $notification_link );
     687                    return apply_filters( 'bp_groups_' . $amount . '_' . $action . '_notification', '<a href="' . esc_url( $notification_link ) . '">' . esc_html( $text ) . '</a>', $group_link, $group->name, $text, $notification_link );
    663688                } else {
    664689
     
    687712            $group_id = $item_id;
    688713
    689             $group = groups_get_group( $group_id );
    690             $group_link = bp_get_group_permalink( $group );
    691             $amount = 'single';
     714            $group      = groups_get_group( $group_id );
     715            $group_link = bp_get_group_url( $group );
     716            $amount     = 'single';
    692717
    693718            if ( (int) $total_items > 1 ) {
    694719                /* translators: %d: number of groups the user has been promoted admin for */
    695                 $text = sprintf( __( 'You were promoted to an admin in %d groups', 'buddypress' ), (int) $total_items );
    696                 $amount = 'multiple';
     720                $text              = sprintf( __( 'You were promoted to an admin in %d groups', 'buddypress' ), (int) $total_items );
     721                $amount            = 'multiple';
    697722                $notification_link = trailingslashit( bp_loggedin_user_domain() . bp_get_groups_slug() ) . '?n=1';
    698723
     
    709734                     * @param string $notification_link The permalink for notification.
    710735                     */
    711                     return apply_filters( 'bp_groups_' . $amount . '_' . $action . '_notification', '<a href="' . $notification_link . '">' . $text . '</a>', $total_items, $text, $notification_link );
     736                    return apply_filters( 'bp_groups_' . $amount . '_' . $action . '_notification', '<a href="' . esc_url( $notification_link ) . '">' . esc_html( $text ) . '</a>', $total_items, $text, $notification_link );
    712737                } else {
    713738                    /**
     
    729754            } else {
    730755                /* translators: %s: group name. */
    731                 $text = sprintf( __( 'You were promoted to an admin in the group "%s"', 'buddypress' ), $group->name );
    732                 $notification_link = $group_link . '?n=1';
     756                $text              = sprintf( __( 'You were promoted to an admin in the group "%s"', 'buddypress' ), $group->name );
     757                $notification_link = add_query_arg( 'n', 1, $group_link );
    733758
    734759                if ( 'string' == $format ) {
     
    745770                     * @param string $notification_link The permalink for notification.
    746771                     */
    747                     return apply_filters( 'bp_groups_' . $amount . '_' . $action . '_notification', '<a href="' . $notification_link . '">' . $text . '</a>', $group_link, $group->name, $text, $notification_link );
     772                    return apply_filters( 'bp_groups_' . $amount . '_' . $action . '_notification', '<a href="' . esc_url( $notification_link ) . '">' . esc_html( $text ) . '</a>', $group_link, $group->name, $text, $notification_link );
    748773                } else {
    749774                    /**
     
    771796            $group_id = $item_id;
    772797
    773             $group = groups_get_group( $group_id );
    774             $group_link = bp_get_group_permalink( $group );
    775             $amount = 'single';
     798            $group      = groups_get_group( $group_id );
     799            $group_link = bp_get_group_url( $group );
     800            $amount     = 'single';
    776801
    777802            if ( (int) $total_items > 1 ) {
    778803                /* translators: %d: number of groups the user has been promoted mod for */
    779                 $text = sprintf( __( 'You were promoted to a mod in %d groups', 'buddypress' ), (int) $total_items );
    780                 $amount = 'multiple';
     804                $text              = sprintf( __( 'You were promoted to a mod in %d groups', 'buddypress' ), (int) $total_items );
     805                $amount            = 'multiple';
    781806                $notification_link = trailingslashit( bp_loggedin_user_domain() . bp_get_groups_slug() ) . '?n=1';
    782807
     
    793818                     * @param string $notification_link The permalink for notification.
    794819                     */
    795                     return apply_filters( 'bp_groups_' . $amount . '_' . $action . '_notification', '<a href="' . $notification_link . '">' . $text . '</a>', $total_items, $text, $notification_link );
     820                    return apply_filters( 'bp_groups_' . $amount . '_' . $action . '_notification', '<a href="' . esc_url( $notification_link ) . '">' . esc_html( $text ) . '</a>', $total_items, $text, $notification_link );
    796821                } else {
    797822                    /**
     
    813838            } else {
    814839                /* translators: %s: group name. */
    815                 $text = sprintf( __( 'You were promoted to a mod in the group "%s"', 'buddypress' ), $group->name );
    816                 $notification_link = $group_link . '?n=1';
     840                $text              = sprintf( __( 'You were promoted to a mod in the group "%s"', 'buddypress' ), $group->name );
     841                $notification_link = add_query_arg( 'n', 1, $group_link );
    817842
    818843                if ( 'string' == $format ) {
     
    829854                     * @param string $notification_link The permalink for notification.
    830855                     */
    831                     return apply_filters( 'bp_groups_' . $amount . '_' . $action . '_notification', '<a href="' . $notification_link . '">' . $text . '</a>', $group_link, $group->name, $text, $notification_link );
     856                    return apply_filters( 'bp_groups_' . $amount . '_' . $action . '_notification', '<a href="' . esc_url( $notification_link ) . '">' . esc_html( $text ) . '</a>', $group_link, $group->name, $text, $notification_link );
    832857                } else {
    833858                    /**
     
    853878
    854879        case 'group_invite':
    855             $group_id = $item_id;
    856             $group = groups_get_group( $group_id );
    857             $group_link = bp_get_group_permalink( $group );
    858             $amount = 'single';
     880            $group_id   = $item_id;
     881            $group      = groups_get_group( $group_id );
     882            $group_link = bp_get_group_url( $group );
     883            $amount     = 'single';
    859884
    860885            $notification_link = bp_loggedin_user_domain() . bp_get_groups_slug() . '/invites/?n=1';
     
    897922            } else {
    898923                /* translators: %s: group name. */
    899                 $text = sprintf( __( 'You have an invitation to the group: %s', 'buddypress' ), $group->name );
     924                $text   = sprintf( __( 'You have an invitation to the group: %s', 'buddypress' ), $group->name );
    900925                $filter = 'bp_groups_single_group_invite_notification';
    901926
     
    913938                     * @param string $notification_link The permalink for notification.
    914939                     */
    915                     return apply_filters( 'bp_groups_' . $amount . '_' . $action . '_notification', '<a href="' . $notification_link . '">' . $text . '</a>', $group_link, $group->name, $text, $notification_link );
     940                    return apply_filters( 'bp_groups_' . $amount . '_' . $action . '_notification', '<a href="' . esc_url( $notification_link ) . '">' . esc_html( $text ) . '</a>', $group_link, $group->name, $text, $notification_link );
    916941                } else {
    917942                    /**
     
    12571282            'group.id'        => $group_id,
    12581283            'group.name'      => $group->name,
    1259             'group.url'       => esc_url( bp_get_group_permalink( $group ) ),
     1284            'group.url'       => esc_url( bp_get_group_url( $group ) ),
    12601285            'leave-group.url' => esc_url(
    12611286                bp_members_get_user_url(
Note: See TracChangeset for help on using the changeset viewer.