Skip to:
Content

BuddyPress.org

Changeset 13156


Ignore:
Timestamp:
11/25/2021 12:30:33 AM (2 months ago)
Author:
dcavins
Message:

Declare invitations as feature of groups component.

Centralize the logic which determines whether
group invitations are active by declaring
invitations as a feature of the groups
component. This also makes it easy for
developers to filter that value using the
bp_is_groups_invitations_active filter hook.

Props imath.

Fixes #8550.

Location:
trunk/src
Files:
7 edited

Legend:

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

    r13144 r13156  
    111111     */
    112112    public function __construct() {
     113        $features = array();
     114        if ( bp_is_active( 'friends' ) ) {
     115            $features[] = 'invitations';
     116        }
     117
    113118        parent::start(
    114119            'groups',
     
    117122            array(
    118123                'adminbar_myaccount_order' => 70,
    119                 'search_query_arg' => 'groups_search',
     124                'search_query_arg'         => 'groups_search',
     125                'features'                 => $features,
    120126            )
    121127        );
     
    393399        }
    394400
    395         // If friends component is active, add invitations.
    396         if ( bp_is_active( 'friends' ) ) {
     401        // If invitations are enabled, add invitations.
     402        if ( bp_is_active( 'groups', 'invitations' ) ) {
    397403            $this->group_creation_steps['group-invites'] = array(
    398404                'name'     => _x( 'Invites',  'Group screen nav', 'buddypress' ),
     
    608614            );
    609615
    610             // Add the Group Invites nav item.
    611             $sub_nav[] = array(
    612                 'name'            => __( 'Invitations', 'buddypress' ),
    613                 'slug'            => 'invites',
    614                 'parent_url'      => $groups_link,
    615                 'parent_slug'     => $slug,
    616                 'screen_function' => 'groups_screen_group_invites',
    617                 'user_has_access' => $access,
    618                 'position'        => 30
    619             );
     616            if ( bp_is_active( 'groups', 'invitations' ) ) {
     617                // Add the Group Invites nav item.
     618                $sub_nav[] = array(
     619                    'name'            => __( 'Invitations', 'buddypress' ),
     620                    'slug'            => 'invites',
     621                    'parent_url'      => $groups_link,
     622                    'parent_slug'     => $slug,
     623                    'screen_function' => 'groups_screen_group_invites',
     624                    'user_has_access' => $access,
     625                    'position'        => 30
     626                );
     627            }
    620628
    621629            parent::setup_nav( $main_nav, $sub_nav );
     
    706714            }
    707715
    708             if ( bp_is_active( 'friends' ) && bp_groups_user_can_send_invites() ) {
     716            if ( bp_is_active( 'groups', 'invitations' ) ) {
    709717                $sub_nav[] = array(
    710718                    'name'            => _x( 'Send Invites', 'My Group screen nav', 'buddypress' ),
     
    834842            $groups_link = trailingslashit( bp_loggedin_user_domain() . bp_get_groups_slug() );
    835843
    836             // Pending group invites.
    837             $count   = groups_get_invite_count_for_user();
    838844            $title   = _x( 'Groups', 'My Account Groups', 'buddypress' );
    839845            $pending = _x( 'No Pending Invites', 'My Account Groups sub nav', 'buddypress' );
    840846
    841             if ( $count ) {
    842                 $title = sprintf(
    843                     /* translators: %s: Group invitation count for the current user */
    844                     _x( 'Groups %s', 'My Account Groups nav', 'buddypress' ),
    845                     '<span class="count">' . bp_core_number_format( $count ) . '</span>'
    846                 );
    847 
    848                 $pending = sprintf(
    849                     /* translators: %s: Group invitation count for the current user */
    850                     _x( 'Pending Invites %s', 'My Account Groups sub nav', 'buddypress' ),
    851                     '<span class="count">' . bp_core_number_format( $count ) . '</span>'
    852                 );
     847            if ( bp_is_active( 'groups', 'invitations' ) ) {
     848                // Pending group invites.
     849                $count   = groups_get_invite_count_for_user();
     850                if ( $count ) {
     851                    $title = sprintf(
     852                        /* translators: %s: Group invitation count for the current user */
     853                        _x( 'Groups %s', 'My Account Groups nav', 'buddypress' ),
     854                        '<span class="count">' . bp_core_number_format( $count ) . '</span>'
     855                    );
     856
     857                    $pending = sprintf(
     858                        /* translators: %s: Group invitation count for the current user */
     859                        _x( 'Pending Invites %s', 'My Account Groups sub nav', 'buddypress' ),
     860                        '<span class="count">' . bp_core_number_format( $count ) . '</span>'
     861                    );
     862                }
    853863            }
    854864
     
    871881
    872882            // Invitations.
    873             $wp_admin_nav[] = array(
    874                 'parent'   => 'my-account-' . $this->id,
    875                 'id'       => 'my-account-' . $this->id . '-invites',
    876                 'title'    => $pending,
    877                 'href'     => trailingslashit( $groups_link . 'invites' ),
    878                 'position' => 30
    879             );
     883            if ( bp_is_active( 'groups', 'invitations' ) ) {
     884                $wp_admin_nav[] = array(
     885                    'parent'   => 'my-account-' . $this->id,
     886                    'id'       => 'my-account-' . $this->id . '-invites',
     887                    'title'    => $pending,
     888                    'href'     => trailingslashit( $groups_link . 'invites' ),
     889                    'position' => 30
     890                );
     891            }
    880892
    881893            // Create a Group.
  • trunk/src/bp-templates/bp-legacy/buddypress/groups/create.php

    r12375 r13156  
    173173                <?php endif; ?>
    174174
    175                 <fieldset class="group-create-invitations">
    176 
    177                     <legend><?php _e( 'Group Invitations', 'buddypress' ); ?></legend>
    178 
    179                     <p><?php _e( 'Which members of this group are allowed to invite others?', 'buddypress' ); ?></p>
    180 
    181                     <div class="radio">
    182 
    183                         <label for="group-invite-status-members"><input type="radio" name="group-invite-status" id="group-invite-status-members" value="members"<?php bp_group_show_invite_status_setting( 'members' ); ?> /> <?php _e( 'All group members', 'buddypress' ); ?></label>
    184 
    185                         <label for="group-invite-status-mods"><input type="radio" name="group-invite-status" id="group-invite-status-mods" value="mods"<?php bp_group_show_invite_status_setting( 'mods' ); ?> /> <?php _e( 'Group admins and mods only', 'buddypress' ); ?></label>
    186 
    187                         <label for="group-invite-status-admins"><input type="radio" name="group-invite-status" id="group-invite-status-admins" value="admins"<?php bp_group_show_invite_status_setting( 'admins' ); ?> /> <?php _e( 'Group admins only', 'buddypress' ); ?></label>
    188 
    189                     </div>
    190 
    191                 </fieldset>
     175                <?php if ( bp_is_active( 'groups', 'invitations' ) ): ?>
     176
     177                    <fieldset class="group-create-invitations">
     178
     179                        <legend><?php _e( 'Group Invitations', 'buddypress' ); ?></legend>
     180
     181                        <p><?php _e( 'Which members of this group are allowed to invite others?', 'buddypress' ); ?></p>
     182
     183                        <div class="radio">
     184
     185                            <label for="group-invite-status-members"><input type="radio" name="group-invite-status" id="group-invite-status-members" value="members"<?php bp_group_show_invite_status_setting( 'members' ); ?> /> <?php _e( 'All group members', 'buddypress' ); ?></label>
     186
     187                            <label for="group-invite-status-mods"><input type="radio" name="group-invite-status" id="group-invite-status-mods" value="mods"<?php bp_group_show_invite_status_setting( 'mods' ); ?> /> <?php _e( 'Group admins and mods only', 'buddypress' ); ?></label>
     188
     189                            <label for="group-invite-status-admins"><input type="radio" name="group-invite-status" id="group-invite-status-admins" value="admins"<?php bp_group_show_invite_status_setting( 'admins' ); ?> /> <?php _e( 'Group admins only', 'buddypress' ); ?></label>
     190
     191                        </div>
     192
     193                    </fieldset>
     194
     195                <?php endif; ?>
    192196
    193197                <?php
  • trunk/src/bp-templates/bp-legacy/buddypress/groups/single/admin/group-settings.php

    r12082 r13156  
    8181<?php endif; ?>
    8282
    83 <fieldset class="group-create-invitations">
    8483
    85     <legend><?php _e( 'Group Invitations', 'buddypress' ); ?></legend>
     84<?php if ( bp_is_active( 'groups', 'invitations' ) ): ?>
    8685
    87     <p><?php _e( 'Which members of this group are allowed to invite others?', 'buddypress' ); ?></p>
     86    <fieldset class="group-create-invitations">
    8887
    89     <div class="radio">
     88        <legend><?php _e( 'Group Invitations', 'buddypress' ); ?></legend>
    9089
    91         <label for="group-invite-status-members"><input type="radio" name="group-invite-status" id="group-invite-status-members" value="members"<?php bp_group_show_invite_status_setting( 'members' ); ?> /> <?php _e( 'All group members', 'buddypress' ); ?></label>
     90        <p><?php _e( 'Which members of this group are allowed to invite others?', 'buddypress' ); ?></p>
    9291
    93         <label for="group-invite-status-mods"><input type="radio" name="group-invite-status" id="group-invite-status-mods" value="mods"<?php bp_group_show_invite_status_setting( 'mods' ); ?> /> <?php _e( 'Group admins and mods only', 'buddypress' ); ?></label>
     92        <div class="radio">
    9493
    95         <label for="group-invite-status-admins"><input type="radio" name="group-invite-status" id="group-invite-status-admins" value="admins"<?php bp_group_show_invite_status_setting( 'admins' ); ?> /> <?php _e( 'Group admins only', 'buddypress' ); ?></label>
     94            <label for="group-invite-status-members"><input type="radio" name="group-invite-status" id="group-invite-status-members" value="members"<?php bp_group_show_invite_status_setting( 'members' ); ?> /> <?php _e( 'All group members', 'buddypress' ); ?></label>
    9695
    97     </div>
     96            <label for="group-invite-status-mods"><input type="radio" name="group-invite-status" id="group-invite-status-mods" value="mods"<?php bp_group_show_invite_status_setting( 'mods' ); ?> /> <?php _e( 'Group admins and mods only', 'buddypress' ); ?></label>
    9897
    99 </fieldset>
     98            <label for="group-invite-status-admins"><input type="radio" name="group-invite-status" id="group-invite-status-admins" value="admins"<?php bp_group_show_invite_status_setting( 'admins' ); ?> /> <?php _e( 'Group admins only', 'buddypress' ); ?></label>
     99
     100        </div>
     101
     102    </fieldset>
     103
     104<?php endif; ?>
    100105
    101106<?php
  • trunk/src/bp-templates/bp-legacy/buddypress/groups/single/send-invites.php

    r12082 r13156  
    1515do_action( 'bp_before_group_send_invites_content' ); ?>
    1616
     17<?php if ( ! bp_is_active( 'friends' ) ) : ?>
     18    <div id="message" class="info">
     19        <p class="notice"><?php esc_html_e( 'Group invitations can only be extended to friends.', 'buddypress' ); ?></p>
     20    </div>
    1721<?php
    1822/* Does the user have friends that could be invited to the group? */
    19 if ( bp_get_new_group_invite_friend_list() ) : ?>
     23elseif ( bp_get_new_group_invite_friend_list() ) : ?>
    2024
    2125    <h2 class="bp-screen-reader-text"><?php _e( 'Send invites', 'buddypress' ); ?></h2>
  • trunk/src/bp-templates/bp-nouveau/buddypress/groups/single/admin/group-settings.php

    r12231 r13156  
    8787<?php endif; ?>
    8888
     89<?php if ( bp_is_active( 'groups', 'invitations' ) ): ?>
     90
    8991    <fieldset class="radio group-invitations">
    9092        <legend><?php esc_html_e( 'Group Invitations', 'buddypress' ); ?></legend>
     
    109111    </fieldset>
    110112
     113<?php endif; ?>
     114
    111115</div><!-- // .group-settings-selections -->
  • trunk/src/bp-templates/bp-nouveau/includes/groups/classes.php

    r13094 r13156  
    260260                'position'    => 10,
    261261            ),
    262             'invites' => array(
    263                 'name'        => _x( 'Invite', 'My Group screen nav', 'buddypress' ),
    264                 'slug'        => 'send-invites',
    265                 'parent_slug' => $this->group->slug,
    266                 'position'    => 70,
    267             ),
    268262            'manage'  => array(
    269263                'name'        => _x( 'Manage', 'My Group screen nav', 'buddypress' ),
     
    273267            ),
    274268        );
     269
     270        if ( bp_is_active( 'groups', 'invitations' ) ) {
     271            $nav_items['invites'] = array(
     272                'name'        => _x( 'Invite', 'My Group screen nav', 'buddypress' ),
     273                'slug'        => 'send-invites',
     274                'parent_slug' => $this->group->slug,
     275                'position'    => 70,
     276            );
     277        }
    275278
    276279        // Make sure only global front.php will be checked.
  • trunk/src/bp-templates/bp-nouveau/includes/groups/functions.php

    r13108 r13156  
    102102    return apply_filters( 'bp_nouveau_groups_disallow_all_members_invites', $default );
    103103}
     104
     105/**
     106 * Activate the Groups invitations feature if any member can be invited.
     107 *
     108 * @since 10.0.0
     109 *
     110 * @param bool True if any member can be invited. False otherwise.
     111 */
     112function bp_nouveau_is_groups_invitations_active() {
     113    return ! bp_nouveau_groups_disallow_all_members_invites();
     114}
     115add_filter( 'bp_is_groups_invitations_active', 'bp_nouveau_is_groups_invitations_active' );
    104116
    105117/**
     
    311323
    312324/**
    313  * @since 3.0.0
     325 * Rename the Group invite step.
     326 *
     327 * @since 3.0.0
     328 * @since 10.0.0 The function is no more creating a Group invite step.
     329 *
     330 * @param array $steps The Group create steps.
     331 * @return array       The Group create steps.
    314332 */
    315333function bp_nouveau_group_invites_create_steps( $steps = array() ) {
    316     if ( bp_is_active( 'friends' ) && isset( $steps['group-invites'] ) ) {
    317         // Simply change the name
     334    if ( isset( $steps['group-invites'] ) ) {
    318335        $steps['group-invites']['name'] = _x( 'Invite', 'Group invitations menu title', 'buddypress' );
    319         return $steps;
    320     }
    321 
    322     // Add the create step if friends component is not active
    323     $steps['group-invites'] = array(
    324         'name'     => _x( 'Invite', 'Group invitations menu title', 'buddypress' ),
    325         'position' => 30,
    326     );
     336    }
    327337
    328338    return $steps;
     
    330340
    331341/**
    332  * @since 3.0.0
     342 * Rename the Group Invites nav.
     343 *
     344 * @since 3.0.0
     345 * @since 10.0.0 The function is no longer creating a Group invite nav.
    333346 */
    334347function bp_nouveau_group_setup_nav() {
     
    337350    }
    338351
    339     // Simply change the name
    340     if ( bp_is_active( 'friends' ) ) {
     352    if ( bp_is_active( 'groups', 'invitations' ) ) {
    341353        $bp = buddypress();
    342354
     
    346358            bp_get_current_group_slug()
    347359        );
    348 
    349     // Create the Subnav item for the group
    350     } else {
    351         $current_group = groups_get_current_group();
    352         $group_link    = bp_get_group_permalink( $current_group );
    353 
    354         bp_core_new_subnav_item( array(
    355             'name'            => _x( 'Invite', 'Group invitations menu title', 'buddypress' ),
    356             'slug'            => 'send-invites',
    357             'parent_url'      => $group_link,
    358             'parent_slug'     => $current_group->slug,
    359             'screen_function' => 'groups_screen_group_invite',
    360             'item_css_id'     => 'invite',
    361             'position'        => 70,
    362             'user_has_access' => $current_group->user_has_access,
    363             'no_access_url'   => $group_link,
    364         ) );
    365360    }
    366361}
Note: See TracChangeset for help on using the changeset viewer.