Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
12/10/2021 04:14:37 PM (3 years ago)
Author:
dcavins
Message:

Add membership request-related emails and notifications.

Add 'members-membership-request' email and
'membership_request_submitted' notification
which is sent to site admins when a new request
is submitted. Also add
'members-membership-request-rejected' email
which is sent to the requester when denied.

See #8582.

t

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-members/bp-members-notifications.php

    r13105 r13168  
    6060                    $text = sprintf( __( '%s is now a member of the site', 'buddypress' ),  bp_core_get_user_displayname( $item_id ) );
    6161                }
     62            }
     63            break;
     64
     65        case 'membership_request_submitted':
     66            // $item_id is the id of the signup, not the user ID.
     67            $signup = new BP_Signup( $item_id );
     68
     69            // Set up the string and the filter.
     70            if ( (int) $total_items > 1 ) {
     71                $link   = bp_get_notifications_permalink();
     72                $amount = 'multiple';
     73
     74                $text = sprintf( __( '%d people have requested site membership.', 'buddypress' ), (int) $total_items );
     75            } else {
     76                $link   = add_query_arg( array(
     77                    'mod_req'   => 1,
     78                    'page'      => 'bp-signups',
     79                    'signup_id' => $item_id,
     80                    'action'    => 'resend',
     81                ), bp_get_admin_url( 'users.php' ) );
     82                $amount = 'single';
     83
     84                /* translators: %s: new user name */
     85                $text = sprintf( __( '%s has requested site membership.', 'buddypress' ),  esc_html( $signup->user_login ) );
    6286            }
    6387            break;
     
    168192        ),
    169193        array(
    170             'user_id' => bp_loggedin_user_id(),
    171             'item_id' => bp_displayed_user_id(),
     194            'user_id'          => bp_loggedin_user_id(),
     195            'item_id'          => bp_displayed_user_id(),
     196            'component_action' => 'accepted_invitation',
    172197        )
    173198    );
     
    176201
    177202/**
     203 * Mark new membership request notifications as read when user visits Manage BP Signups screen.
     204 *
     205 * @since 10.0.0
     206 */
     207function bp_members_mark_read_submitted_membership_request_notification() {
     208
     209    $signup_screens = array( 'users_page_bp-signups', 'users_page_bp-signups-network' );
     210    if ( ! wp_doing_ajax() && in_array( get_current_screen()->base, $signup_screens, true ) && ! empty( $_GET['mod_req'] ) && ! empty( $_GET['signup_id'] ) ) {
     211        // Mark all notifications about this request as read.
     212        BP_Notifications_Notification::update(
     213            array(
     214                'is_new' => false,
     215            ),
     216            array(
     217                'item_id'          => $_GET['signup_id'],
     218                'component_action' => 'membership_request_submitted',
     219            )
     220        );
     221    }
     222}
     223add_action( 'admin_footer', 'bp_members_mark_read_submitted_membership_request_notification' );
     224
     225/**
    178226 * Add Members-related settings to the Settings > Notifications page.
    179227 *
     
    182230function members_screen_notification_settings() {
    183231
    184     // Bail early if invitations are not allowed--they are the only members notification so far.
    185     if ( ! bp_get_members_invitations_allowed () ) {
     232    // Bail early if invitations and requests are not allowed--they are the only members notification so far.
     233    if ( ! bp_get_members_invitations_allowed() && ( ! bp_get_membership_requests_required() || ! user_can( bp_displayed_user_id(), 'bp_moderate' ) ) ) {
    186234        return;
    187     }
    188 
    189     if ( ! $allow_acceptance_emails = bp_get_user_meta( bp_displayed_user_id(), 'notification_members_invitation_accepted', true ) ) {
    190         $allow_acceptance_emails = 'yes';
    191235    }
    192236    ?>
     
    203247
    204248        <tbody>
    205             <tr id="members-notification-settings-invitation_accepted">
    206                 <td></td>
    207                 <td><?php _ex( 'Someone accepts your membership invitation', 'Member settings on notification settings page', 'buddypress' ) ?></td>
    208                 <td class="yes"><input type="radio" name="notifications[notification_members_invitation_accepted]" id="notification-members-invitation-accepted-yes" value="yes" <?php checked( $allow_acceptance_emails, 'yes', true ) ?>/><label for="notification-members-invitation-accepted-yes" class="bp-screen-reader-text"><?php
    209                     /* translators: accessibility text */
    210                     _e( 'Yes, send email', 'buddypress' );
    211                 ?></label></td>
    212                 <td class="no"><input type="radio" name="notifications[notification_members_invitation_accepted]" id="notification-members-invitation-accepted-no" value="no" <?php checked( $allow_acceptance_emails, 'no', true ) ?>/><label for="notification-members-invitation-accepted-no" class="bp-screen-reader-text"><?php
    213                     /* translators: accessibility text */
    214                     _e( 'No, do not send email', 'buddypress' );
    215                 ?></label></td>
    216             </tr>
    217249
    218250            <?php
     251            if ( bp_get_members_invitations_allowed() ) :
     252                if ( ! $allow_acceptance_emails = bp_get_user_meta( bp_displayed_user_id(), 'notification_members_invitation_accepted', true ) ) {
     253                    $allow_acceptance_emails = 'yes';
     254                }
     255                ?>
     256                <tr id="members-notification-settings-invitation_accepted">
     257                    <td></td>
     258                    <td><?php echo esc_html_x( 'Someone accepts your membership invitation', 'Member settings on notification settings page', 'buddypress' ); ?></td>
     259                    <td class="yes"><input type="radio" name="notifications[notification_members_invitation_accepted]" id="notification-members-invitation-accepted-yes" value="yes" <?php checked( $allow_acceptance_emails, 'yes', true ) ?>/><label for="notification-members-invitation-accepted-yes" class="bp-screen-reader-text">
     260                        <?php
     261                        /* translators: accessibility text */
     262                        esc_html_e( 'Yes, send email', 'buddypress' );
     263                        ?>
     264                    </label></td>
     265                    <td class="no"><input type="radio" name="notifications[notification_members_invitation_accepted]" id="notification-members-invitation-accepted-no" value="no" <?php checked( $allow_acceptance_emails, 'no', true ) ?>/><label for="notification-members-invitation-accepted-no" class="bp-screen-reader-text">
     266                        <?php
     267                        /* translators: accessibility text */
     268                        esc_html_e( 'No, do not send email', 'buddypress' );
     269                        ?>
     270                    </label></td>
     271                </tr>
     272                <?php
     273            endif;
     274
     275            if ( bp_get_membership_requests_required() && user_can( bp_displayed_user_id(), 'bp_moderate' ) ) :
     276                if ( ! $allow_request_emails = bp_get_user_meta( bp_displayed_user_id(), 'notification_members_membership_request', true ) ) {
     277                    $allow_request_emails = 'yes';
     278                }
     279                ?>
     280                <tr id="members-notification-settings-submitted_membership_request">
     281                    <td></td>
     282                    <td><?php echo esc_html_x( 'Someone has requested site membership', 'Member settings on notification settings page', 'buddypress' ) ?></td>
     283                    <td class="yes"><input type="radio" name="notifications[notification_members_membership_request]" id="notification-members-submitted_membership_request-yes" value="yes" <?php checked( $allow_request_emails, 'yes', true ) ?>/><label for="notification-members-submitted_membership_request-yes" class="bp-screen-reader-text">
     284                        <?php
     285                        /* translators: accessibility text */
     286                        esc_html_e( 'Yes, send email', 'buddypress' );
     287                        ?>
     288                    </label></td>
     289                    <td class="no"><input type="radio" name="notifications[notification_members_membership_request]" id="notification-members-submitted_membership_request-no" value="no" <?php checked( $allow_request_emails, 'no', true ) ?>/><label for="notification-members-submitted_membership_request-no" class="bp-screen-reader-text">
     290                        <?php
     291                        /* translators: accessibility text */
     292                        esc_html_e( 'No, do not send email', 'buddypress' );
     293                        ?>
     294                    </label></td>
     295                </tr>
     296                <?php
     297            endif;
    219298
    220299            /**
Note: See TracChangeset for help on using the changeset viewer.