<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[BuddyPress][13168] trunk/src: Add membership request-related emails and notifications.</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { white-space: pre-line; overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta" style="font-size: 105%">
<dt style="float: left; width: 6em; font-weight: bold">Revision</dt> <dd><a style="font-weight: bold" href="http://buddypress.trac.wordpress.org/changeset/13168">13168</a><script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","description":"Review this Commit","action":{"@type":"ViewAction","url":"http://buddypress.trac.wordpress.org/changeset/13168","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>dcavins</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2021-12-10 16:14:37 +0000 (Fri, 10 Dec 2021)</dd>
</dl>

<pre style='padding-left: 1em; margin: 2em 0; border-left: 2px solid #ccc; line-height: 1.25; font-size: 105%; font-family: sans-serif'>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 <a href="http://buddypress.trac.wordpress.org/ticket/8582">#8582</a>.

t</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcbpcorebpcorefunctionsphp">trunk/src/bp-core/bp-core-functions.php</a></li>
<li><a href="#trunksrcbpcorebpcoreupdatephp">trunk/src/bp-core/bp-core-update.php</a></li>
<li><a href="#trunksrcbpmembersbpmembersmembershiprequestsphp">trunk/src/bp-members/bp-members-membership-requests.php</a></li>
<li><a href="#trunksrcbpmembersbpmembersnotificationsphp">trunk/src/bp-members/bp-members-notifications.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcbpcorebpcorefunctionsphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/bp-core/bp-core-functions.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/bp-core/bp-core-functions.php   2021-12-10 16:14:25 UTC (rev 13167)
+++ trunk/src/bp-core/bp-core-functions.php     2021-12-10 16:14:37 UTC (rev 13168)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -3812,6 +3812,8 @@
</span><span class="cx" style="display: block; padding: 0 10px">  * Get a list of emails for populating the email post type.
</span><span class="cx" style="display: block; padding: 0 10px">  *
</span><span class="cx" style="display: block; padding: 0 10px">  * @since 2.5.1
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @since 10.0.0 Added members-membership-request and
+ *               members-membership-request-rejected email types.
</ins><span class="cx" style="display: block; padding: 0 10px">  *
</span><span class="cx" style="display: block; padding: 0 10px">  * @return array
</span><span class="cx" style="display: block; padding: 0 10px">  */
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -3972,6 +3974,22 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        /* translators: do not remove {} brackets or translate its contents. */
</span><span class="cx" style="display: block; padding: 0 10px">                        'post_excerpt' => __( "{{inviter.name}} has invited you to join the site \"{{site.name}}\".\n\n{{usermessage}}\n\nTo accept your invitation, visit: {{{invite.accept_url}}}\n\nTo learn more about the site, visit: {{{site.url}}}.\nTo view {{inviter.name}}'s profile, visit: {{{inviter.url}}}", 'buddypress' ),
</span><span class="cx" style="display: block; padding: 0 10px">                ),
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                'members-membership-request' => array(
+                       /* translators: do not remove {} brackets or translate its contents. */
+                       'post_title'   => __( '{{requesting-user.user_login}} would like to join {{site.name}}', 'buddypress' ),
+                       /* translators: do not remove {} brackets or translate its contents. */
+                       'post_content' => __( "{{requesting-user.user_login}} would like to join the site: &quot;{{site.name}}&quot;.\n\n<a href=\"{{{manage.url}}}\">Manage the request</a>.", 'buddypress' ),
+                       /* translators: do not remove {} brackets or translate its contents. */
+                       'post_excerpt' => __( "{{requesting-user.user_login}} would like to join the site \"{{site.name}}\".\n\nTo manage the request, visit: {{{manage.url}}}.", 'buddypress' ),
+               ),
+               'members-membership-request-rejected' => array(
+                       /* translators: do not remove {} brackets or translate its contents. */
+                       'post_title'   => __( 'Your request to join {{site.name}} has been declined', 'buddypress' ),
+                       /* translators: do not remove {} brackets or translate its contents. */
+                       'post_content' => __( "Sorry, your request to join the site &quot;{{site.name}}&quot; has been declined.", 'buddypress' ),
+                       /* translators: do not remove {} brackets or translate its contents. */
+                       'post_excerpt' => __( "Sorry, your request to join the site \"{{site.name}}\" has been declined.", 'buddypress' ),
+               ),
</ins><span class="cx" style="display: block; padding: 0 10px">         ) );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -4144,25 +4162,42 @@
</span><span class="cx" style="display: block; padding: 0 10px">                ),
</span><span class="cx" style="display: block; padding: 0 10px">        );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+        $members_membership_request = array(
+               'description'      => __( 'Someone has requested membership on this site.', 'buddypress' ),
+               'named_salutation' => true,
+               'unsubscribe'      => array(
+                       'meta_key' => 'notification_members_membership_request',
+                       'message'  => __( 'You will no longer receive emails when people submit requests to join this site.', 'buddypress' ),
+               ),
+       );
+
+       $members_membership_request_rejected = array(
+               'description'      => __( 'A site membership request has been rejected.', 'buddypress' ),
+               'named_salutation' => false,
+               'unsubscribe'      => false,
+       );
+
</ins><span class="cx" style="display: block; padding: 0 10px">         $types = array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                'activity-comment'                   => $activity_comment,
-               'activity-comment-author'            => $activity_comment_author,
-               'activity-at-message'                => $activity_at_message,
-               'groups-at-message'                  => $groups_at_message,
-               'core-user-registration'             => $core_user_registration,
-               'core-user-registration-with-blog'   => $core_user_registration_with_blog,
-               'friends-request'                    => $friends_request,
-               'friends-request-accepted'           => $friends_request_accepted,
-               'groups-details-updated'             => $groups_details_updated,
-               'groups-invitation'                  => $groups_invitation,
-               'groups-member-promoted'             => $groups_member_promoted,
-               'groups-membership-request'          => $groups_membership_request,
-               'messages-unread'                    => $messages_unread,
-               'settings-verify-email-change'       => $settings_verify_email_change,
-               'groups-membership-request-accepted' => $groups_membership_request_accepted,
-               'groups-membership-request-rejected' => $groups_membership_request_rejected,
-               'core-user-activation'               => $core_user_activation,
-               'bp-members-invitation'              => $members_invitation,
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         'activity-comment'                    => $activity_comment,
+               'activity-comment-author'             => $activity_comment_author,
+               'activity-at-message'                 => $activity_at_message,
+               'groups-at-message'                   => $groups_at_message,
+               'core-user-registration'              => $core_user_registration,
+               'core-user-registration-with-blog'    => $core_user_registration_with_blog,
+               'friends-request'                     => $friends_request,
+               'friends-request-accepted'            => $friends_request_accepted,
+               'groups-details-updated'              => $groups_details_updated,
+               'groups-invitation'                   => $groups_invitation,
+               'groups-member-promoted'              => $groups_member_promoted,
+               'groups-membership-request'           => $groups_membership_request,
+               'messages-unread'                     => $messages_unread,
+               'settings-verify-email-change'        => $settings_verify_email_change,
+               'groups-membership-request-accepted'  => $groups_membership_request_accepted,
+               'groups-membership-request-rejected'  => $groups_membership_request_rejected,
+               'core-user-activation'                => $core_user_activation,
+               'bp-members-invitation'               => $members_invitation,
+               'members-membership-request'          => $members_membership_request,
+               'members-membership-request-rejected' => $members_membership_request_rejected,
</ins><span class="cx" style="display: block; padding: 0 10px">         );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        if ( $field !== 'all' ) {
</span></span></pre></div>
<a id="trunksrcbpcorebpcoreupdatephp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/bp-core/bp-core-update.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/bp-core/bp-core-update.php      2021-12-10 16:14:25 UTC (rev 13167)
+++ trunk/src/bp-core/bp-core-update.php        2021-12-10 16:14:37 UTC (rev 13168)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -278,6 +278,12 @@
</span><span class="cx" style="display: block; padding: 0 10px">                if ( $raw_db_version < 12850 ) {
</span><span class="cx" style="display: block; padding: 0 10px">                        bp_update_to_8_0();
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+               // Version 10.0.0.
+               if ( $raw_db_version < 13165 ) {
+                       bp_update_to_10_0();
+               }
+
</ins><span class="cx" style="display: block; padding: 0 10px">         }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        /* All done! *************************************************************/
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -705,6 +711,44 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * 10.0.0 update routine.
+ *
+ * - Install new BP Emails for membership requests.
+ *
+ * @since 10.0.0
+ */
+function bp_update_to_10_0() {
+
+       // Install membership request emails.
+       add_filter( 'bp_email_get_schema', 'bp_core_get_10_0_upgrade_email_schema' );
+
+       bp_core_install_emails();
+
+       remove_filter( 'bp_email_get_schema', 'bp_core_get_10_0_upgrade_email_schema' );
+}
+
+/**
+ * Select only the emails that need to be installed with version 10.0.
+ *
+ * @since 10.0.0
+ *
+ * @param array $emails The array of emails schema.
+ */
+function bp_core_get_10_0_upgrade_email_schema( $emails ) {
+       $new_emails = array();
+
+       if ( isset( $emails['members-membership-request'] ) ) {
+               $new_emails['members-membership-request'] = $emails['members-membership-request'];
+       }
+
+       if ( isset( $emails['members-membership-request-rejected'] ) ) {
+               $new_emails['members-membership-request-rejected'] = $emails['members-membership-request-rejected'];
+       }
+
+       return $new_emails;
+}
+
+/**
</ins><span class="cx" style="display: block; padding: 0 10px">  * Updates the component field for new_members type.
</span><span class="cx" style="display: block; padding: 0 10px">  *
</span><span class="cx" style="display: block; padding: 0 10px">  * @since 2.2.0
</span></span></pre></div>
<a id="trunksrcbpmembersbpmembersmembershiprequestsphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/bp-members/bp-members-membership-requests.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/bp-members/bp-members-membership-requests.php   2021-12-10 16:14:25 UTC (rev 13167)
+++ trunk/src/bp-members/bp-members-membership-requests.php     2021-12-10 16:14:37 UTC (rev 13168)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -135,3 +135,126 @@
</span><span class="cx" style="display: block; padding: 0 10px"> add_filter( 'bp_core_signup_send_activation_key_multisite', 'bp_members_membership_requests_cancel_activation_email_multisite', 10, 5 );
</span><span class="cx" style="display: block; padding: 0 10px"> add_filter( 'bp_core_signup_send_activation_key_multisite_blog', 'bp_members_membership_requests_cancel_activation_email_multisite', 10, 5 );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+/**
+ * Notifications
+ *********************************************************************/
+
+/**
+ * Notify site admins about a new membership request.
+ *
+ * @since 10.0.0
+ *
+ * @param BP_Signup $signup The signup object that has been created.
+ */
+function bp_members_membership_requests_notify_site_admins( $signup ) {
+
+       if ( ! isset( $signup->signup_id ) ) {
+               return;
+       }
+
+       // Notify all site admins so the request can be handled.
+       $admin_ids = get_users(
+               array(
+                       'fields' => 'ids',
+                       'role'   => 'administrator',
+               )
+       );
+
+       foreach ( $admin_ids as $admin_id ) {
+               // Trigger a BuddyPress Notification.
+               if ( bp_is_active( 'notifications' ) ) {
+                       bp_notifications_add_notification(
+                               array(
+                                       'user_id'          => $admin_id,
+                                       'item_id'          => $signup->signup_id,
+                                       'component_name'   => buddypress()->members->id,
+                                       'component_action' => 'membership_request_submitted',
+                                       'date_notified'    => bp_core_current_time(),
+                                       'is_new'           => 1,
+                               )
+                       );
+               }
+
+               // Bail if member opted out of receiving this email.
+               if ( 'no' === bp_get_user_meta( $admin_id, 'notification_members_membership_request', true ) ) {
+                       return;
+               }
+
+               $unsubscribe_args = array(
+                       'user_id'           => $admin_id,
+                       'notification_type' => 'members-membership-request',
+               );
+
+               $manage_url = add_query_arg(
+                       array(
+                               'mod_req'   => 1,
+                               'page'      => 'bp-signups',
+                               'signup_id' => $signup->signup_id,
+                               'action'    => 'resend',
+                       ),
+                       bp_get_admin_url( 'users.php' )
+               );
+
+               $args  = array(
+                       'tokens' => array(
+                               'admin.id'                   => $admin_id,
+                               'manage.url'                 => esc_url_raw( $manage_url ),
+                               'requesting-user.user_login' => esc_html( $signup->user_login ),
+                               'unsubscribe'                => esc_url( bp_email_get_unsubscribe_link( $unsubscribe_args ) ),
+                       ),
+               );
+
+               bp_send_email( 'members-membership-request', (int) $admin_id, $args );
+       }
+}
+add_action( 'bp_members_membership_request_submitted', 'bp_members_membership_requests_notify_site_admins' );
+
+/**
+ * Send a message to the requesting user when his or her
+ * site membership request has been rejected.
+ *
+ * @since 10.0.0
+ *
+ * @param array $signup_ids Array of pending IDs to delete.
+ */
+function bp_members_membership_requests_send_rejection_mail( $signup_ids ) {
+       $signups = BP_Signup::get(
+               array(
+                       'include' => $signup_ids,
+               )
+       );
+
+       if ( empty( $signups['signups'] ) ) {
+               return;
+       }
+
+       foreach ( $signups['signups'] as $signup ) {
+               if ( ! empty( $signup->user_email ) ) {
+                       bp_send_email( 'members-membership-request-rejected', $signup->user_email );
+               }
+       }
+}
+add_action( 'bp_core_signup_before_delete', 'bp_members_membership_requests_send_rejection_mail' );
+
+/**
+ * When a request is approved, activated or deleted,
+ * delete the associated notifications.
+ *
+ * @since 10.0.0
+ *
+ * @param array $signup_ids Array of changing signup IDs.
+ */
+function bp_members_membership_requests_delete_notifications_on_change( $signup_ids ) {
+       foreach ( $signup_ids as $signup_id ) {
+               BP_Notifications_Notification::delete(
+                       array(
+                               'item_id'          => $signup_id,
+                               'component_action' => 'membership_request_submitted',
+                       )
+               );
+       }
+}
+add_action( 'bp_core_signup_after_resend',   'bp_members_membership_requests_delete_notifications_on_change' );
+add_action( 'bp_core_signup_after_activate', 'bp_members_membership_requests_delete_notifications_on_change' );
+add_action( 'bp_core_signup_after_delete',   'bp_members_membership_requests_delete_notifications_on_change' );
+
</ins></span></pre></div>
<a id="trunksrcbpmembersbpmembersnotificationsphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/bp-members/bp-members-notifications.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/bp-members/bp-members-notifications.php 2021-12-10 16:14:25 UTC (rev 13167)
+++ trunk/src/bp-members/bp-members-notifications.php   2021-12-10 16:14:37 UTC (rev 13168)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -61,6 +61,30 @@
</span><span class="cx" style="display: block; padding: 0 10px">                                }
</span><span class="cx" style="display: block; padding: 0 10px">                        }
</span><span class="cx" style="display: block; padding: 0 10px">                        break;
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+               case 'membership_request_submitted':
+                       // $item_id is the id of the signup, not the user ID.
+                       $signup = new BP_Signup( $item_id );
+
+                       // Set up the string and the filter.
+                       if ( (int) $total_items > 1 ) {
+                               $link   = bp_get_notifications_permalink();
+                               $amount = 'multiple';
+
+                               $text = sprintf( __( '%d people have requested site membership.', 'buddypress' ), (int) $total_items );
+                       } else {
+                               $link   = add_query_arg( array(
+                                       'mod_req'   => 1,
+                                       'page'      => 'bp-signups',
+                                       'signup_id' => $item_id,
+                                       'action'    => 'resend',
+                               ), bp_get_admin_url( 'users.php' ) );
+                               $amount = 'single';
+
+                               /* translators: %s: new user name */
+                               $text = sprintf( __( '%s has requested site membership.', 'buddypress' ),  esc_html( $signup->user_login ) );
+                       }
+                       break;
</ins><span class="cx" style="display: block; padding: 0 10px">         }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        // Return either an HTML link or an array, depending on the requested format.
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -167,8 +191,9 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        'is_new' => false,
</span><span class="cx" style="display: block; padding: 0 10px">                ),
</span><span class="cx" style="display: block; padding: 0 10px">                array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        'user_id' => bp_loggedin_user_id(),
-                       'item_id' => bp_displayed_user_id(),
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 'user_id'          => bp_loggedin_user_id(),
+                       'item_id'          => bp_displayed_user_id(),
+                       'component_action' => 'accepted_invitation',
</ins><span class="cx" style="display: block; padding: 0 10px">                 )
</span><span class="cx" style="display: block; padding: 0 10px">        );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -175,6 +200,29 @@
</span><span class="cx" style="display: block; padding: 0 10px"> add_action( 'bp_screens', 'bp_members_mark_read_accepted_invitation_notification' );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Mark new membership request notifications as read when user visits Manage BP Signups screen.
+ *
+ * @since 10.0.0
+ */
+function bp_members_mark_read_submitted_membership_request_notification() {
+
+       $signup_screens = array( 'users_page_bp-signups', 'users_page_bp-signups-network' );
+       if ( ! wp_doing_ajax() && in_array( get_current_screen()->base, $signup_screens, true ) && ! empty( $_GET['mod_req'] ) && ! empty( $_GET['signup_id'] ) ) {
+               // Mark all notifications about this request as read.
+               BP_Notifications_Notification::update(
+                       array(
+                               'is_new' => false,
+                       ),
+                       array(
+                               'item_id'          => $_GET['signup_id'],
+                               'component_action' => 'membership_request_submitted',
+                       )
+               );
+       }
+}
+add_action( 'admin_footer', 'bp_members_mark_read_submitted_membership_request_notification' );
+
+/**
</ins><span class="cx" style="display: block; padding: 0 10px">  * Add Members-related settings to the Settings > Notifications page.
</span><span class="cx" style="display: block; padding: 0 10px">  *
</span><span class="cx" style="display: block; padding: 0 10px">  * @since 8.0.0
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -181,14 +229,10 @@
</span><span class="cx" style="display: block; padding: 0 10px">  */
</span><span class="cx" style="display: block; padding: 0 10px"> function members_screen_notification_settings() {
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-        // Bail early if invitations are not allowed--they are the only members notification so far.
-       if ( ! bp_get_members_invitations_allowed () ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // Bail early if invitations and requests are not allowed--they are the only members notification so far.
+       if ( ! bp_get_members_invitations_allowed() && ( ! bp_get_membership_requests_required() || ! user_can( bp_displayed_user_id(), 'bp_moderate' ) ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px">                 return;
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-
-       if ( ! $allow_acceptance_emails = bp_get_user_meta( bp_displayed_user_id(), 'notification_members_invitation_accepted', true ) ) {
-               $allow_acceptance_emails = 'yes';
-       }
</del><span class="cx" style="display: block; padding: 0 10px">         ?>
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        <table class="notification-settings" id="members-notification-settings">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -202,21 +246,56 @@
</span><span class="cx" style="display: block; padding: 0 10px">                </thead>
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                <tbody>
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        <tr id="members-notification-settings-invitation_accepted">
-                               <td></td>
-                               <td><?php _ex( 'Someone accepts your membership invitation', 'Member settings on notification settings page', 'buddypress' ) ?></td>
-                               <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
-                                       /* translators: accessibility text */
-                                       _e( 'Yes, send email', 'buddypress' );
-                               ?></label></td>
-                               <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
-                                       /* translators: accessibility text */
-                                       _e( 'No, do not send email', 'buddypress' );
-                               ?></label></td>
-                       </tr>
</del><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                        <?php
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                        if ( bp_get_members_invitations_allowed() ) :
+                               if ( ! $allow_acceptance_emails = bp_get_user_meta( bp_displayed_user_id(), 'notification_members_invitation_accepted', true ) ) {
+                                       $allow_acceptance_emails = 'yes';
+                               }
+                               ?>
+                               <tr id="members-notification-settings-invitation_accepted">
+                                       <td></td>
+                                       <td><?php echo esc_html_x( 'Someone accepts your membership invitation', 'Member settings on notification settings page', 'buddypress' ); ?></td>
+                                       <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
+                                               /* translators: accessibility text */
+                                               esc_html_e( 'Yes, send email', 'buddypress' );
+                                               ?>
+                                       </label></td>
+                                       <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
+                                               /* translators: accessibility text */
+                                               esc_html_e( 'No, do not send email', 'buddypress' );
+                                               ?>
+                                       </label></td>
+                               </tr>
+                               <?php
+                       endif;
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                        if ( bp_get_membership_requests_required() && user_can( bp_displayed_user_id(), 'bp_moderate' ) ) :
+                               if ( ! $allow_request_emails = bp_get_user_meta( bp_displayed_user_id(), 'notification_members_membership_request', true ) ) {
+                                       $allow_request_emails = 'yes';
+                               }
+                               ?>
+                               <tr id="members-notification-settings-submitted_membership_request">
+                                       <td></td>
+                                       <td><?php echo esc_html_x( 'Someone has requested site membership', 'Member settings on notification settings page', 'buddypress' ) ?></td>
+                                       <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">
+                                               <?php
+                                               /* translators: accessibility text */
+                                               esc_html_e( 'Yes, send email', 'buddypress' );
+                                               ?>
+                                       </label></td>
+                                       <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">
+                                               <?php
+                                               /* translators: accessibility text */
+                                               esc_html_e( 'No, do not send email', 'buddypress' );
+                                               ?>
+                                       </label></td>
+                               </tr>
+                               <?php
+                       endif;
+
</ins><span class="cx" style="display: block; padding: 0 10px">                         /**
</span><span class="cx" style="display: block; padding: 0 10px">                         * Fires after the last table row on the members notification screen.
</span><span class="cx" style="display: block; padding: 0 10px">                         *
</span></span></pre>
</div>
</div>

</body>
</html>