Skip to:
Content

BuddyPress.org

Ticket #8139: 8139.07-just-new-parts.patch

File 8139.07-just-new-parts.patch, 20.7 KB (added by dcavins, 3 years ago)

This is just the code that is new in .07 and not in .06.

  • src/bp-core/bp-core-filters.php

    diff --git src/bp-core/bp-core-filters.php src/bp-core/bp-core-filters.php
    index 1b285555c..85a8978d2 100644
    function bp_email_set_default_headers( $headers, $property, $transform, $email ) 
    10741074                        'user_id'           => $user_id,
    10751075                        'notification_type' => $email->get( 'type' ),
    10761076                );
    1077                 // If this email is not to a current member, include the nonmember's email address.
     1077
     1078                // If this email is not to a current member, include the nonmember's email address and the Inviter ID.
    10781079                if ( ! $user_id ) {
    10791080                        $args['email_address'] = $tokens['recipient.email'];
     1081                        $args['member_id']     = bp_loggedin_user_id();
    10801082                }
    10811083
    10821084                $link = bp_email_get_unsubscribe_link( $args );
  • src/bp-core/bp-core-functions.php

    diff --git src/bp-core/bp-core-functions.php src/bp-core/bp-core-functions.php
    index 98b46f5ce..9464d61ad 100644
    function bp_email_get_type_schema( $field = 'description' ) { 
    40274027                'description'   => __( 'A site member has sent a site invitation to the recipient.', 'buddypress' ),
    40284028                'unsubscribe'   => array(
    40294029                        'meta_key'      => 'notification_bp_members_invite',
    4030                         'message'       => __( 'You will no longer receive emails when you are invited to join a site.', 'buddypress' ),
     4030                        'message'       => __( 'You will no longer receive emails when you are invited to join this site.', 'buddypress' ),
    40314031                ),
    40324032        );
    40334033
    function bp_email_unsubscribe_handler() { 
    40714071        $raw_user_id    = ! empty( $_GET['uid'] ) ? absint( $_GET['uid'] ) : 0;
    40724072        $raw_user_email = ! empty( $_GET['uem'] ) ? $_GET['uem'] : '';
    40734073        $raw_member_id  = ! empty( $_GET['mid'] ) ? absint( $_GET['mid'] ) : 0;
     4074        $redirect_to    = '';
    40744075
    40754076        $new_hash = '';
    40764077        if ( ! empty( $raw_user_id ) ) {
    function bp_email_unsubscribe_handler() { 
    41094110        // This is an unsubscribe request from a nonmember.
    41104111        } else if ( $raw_user_email ) {
    41114112                // Unsubscribe.
    4112                 error_log( 'caught unsubscribe request {$raw_user_email}' );
    4113                 $optout_args = array(
    4114                         'email_address' => $raw_user_email,
    4115                         'user_id'       => $raw_member_id,
    4116                         'email_type'    => $raw_email_type,
    4117                         'date_modified' => bp_core_current_time(),
    4118                 );
    4119                 $result      = bp_add_optout( $optout_args );
    4120                 $redirect_to = home_url();
    4121                 $result_msg  = $emails[ $raw_email_type ]['unsubscribe']['message'];
    4122                 $unsub_msg   = __( 'You have been unsubscribed.', 'buddypress' );
     4113                if ( bp_user_has_opted_out() ) {
     4114                        $result_msg = $emails[ $raw_email_type ]['unsubscribe']['message'];
     4115                        $unsub_msg  = __( 'You have already unsubscribed from all communication from this site.', 'buddypress' );
     4116                } else {
     4117                        $optout_args = array(
     4118                                'email_address' => $raw_user_email,
     4119                                'user_id'       => $raw_member_id,
     4120                                'email_type'    => $raw_email_type,
     4121                                'date_modified' => bp_core_current_time(),
     4122                        );
     4123                        bp_add_optout( $optout_args );
     4124                        $result_msg = $emails[ $raw_email_type ]['unsubscribe']['message'];
     4125                        $unsub_msg  = __( 'You have been unsubscribed.', 'buddypress' );
     4126                }
    41234127
    41244128        // This is an unsubscribe request from a current member.
    41254129        } else {
    function bp_email_unsubscribe_handler() { 
    41414145                $unsub_msg  = __( 'You can change this or any other email notification preferences in your email settings.', 'buddypress' );
    41424146        }
    41434147
    4144         $message = sprintf(
    4145                 '%1$s <a href="%2$s">%3$s</a>',
    4146                 $result_msg,
    4147                 esc_url( $redirect_to ),
    4148                 esc_html( $unsub_msg )
    4149         );
     4148        if ( $raw_user_id && $redirect_to ) {
     4149                $message = sprintf(
     4150                        '%1$s <a href="%2$s">%3$s</a>',
     4151                        $result_msg,
     4152                        esc_url( $redirect_to ),
     4153                        esc_html( $unsub_msg )
     4154                );
    41504155
    4151         bp_core_add_message( $message );
     4156                // Template notices are only displayed on BP pages.
     4157                bp_core_add_message( $message );
     4158                bp_core_redirect( bp_core_get_user_domain( $raw_user_id ) );
    41524159
    4153         $page_redirect = '';
    4154         if ( $raw_user_id  ) {
    4155                 $page_redirect = bp_core_get_user_domain( $raw_user_id );
     4160                exit;
     4161        } else {
     4162                wp_die(
     4163                        sprintf( '%1$s %2$s', esc_html( $unsub_msg ), esc_html( $result_msg ) ),
     4164                        esc_html( $unsub_msg ),
     4165                        array(
     4166                                'link_url'  => home_url(),
     4167                                'link_text' => __( 'Go to website\'s home page.', 'buddypress' ),
     4168                        )
     4169                );
    41564170        }
    4157 
    4158         bp_core_redirect( $page_redirect );
    4159 
    4160         exit;
    41614171}
    41624172
    41634173/**
  • src/bp-core/classes/class-bp-email.php

    diff --git src/bp-core/classes/class-bp-email.php src/bp-core/classes/class-bp-email.php
    index 78188fe4e..7c64102df 100644
    class BP_Email { 
    999999                        $retval = new WP_Error( 'missing_parameter', __CLASS__, $this );
    10001000                }
    10011001
     1002                // Has the user opted out of receiving any email from this site?
     1003                $recipient_address = array_shift( $this->get_to() )->get_address();
     1004                if ( bp_user_has_opted_out( $recipient_address ) ) {
     1005                        $retval = new WP_Error( 'user_has_opted_out', 'The email recipient has opted out from receiving communication from this site.', $this );
     1006                }
     1007
    10021008                /**
    10031009                 * Filters whether the email passes basic validation checks.
    10041010                 *
  • src/bp-core/classes/class-bp-invitation.php

    diff --git src/bp-core/classes/class-bp-invitation.php src/bp-core/classes/class-bp-invitation.php
    index 2f5504df2..c1e941de2 100644
    class BP_Invitation { 
    660660         *     Associative array of arguments. All arguments but $page and
    661661         *     $per_page can be treated as filter values for get_where_sql()
    662662         *     and get_query_clauses(). All items are optional.
    663          *     @type int|array    $id                ID of invitation being updated.
     663         *     @type int|array    $id                ID of invitation being fetched.
    664664         *                                           Can be an array of IDs.
    665665         *     @type int|array    $user_id           ID of user being queried. Can be an
    666666         *                                           Can be an array of IDs.
  • src/bp-members/bp-members-filters.php

    diff --git src/bp-members/bp-members-filters.php src/bp-members/bp-members-filters.php
    index fcdcf4fa3..4c6eacead 100644
    function bp_members_invitations_get_registration_welcome_message() { 
    209209                return $message;
    210210        }
    211211        $invite = bp_get_members_invitation_from_request();
    212         if ( ! $invite->id ) {
     212        if ( ! $invite->id || ! $invite->invitee_email ) {
    213213                return $message;
    214214        }
    215215
    216         // Fetch the display names of all inviters to personalize the welcome message.
    217         $all_invites = bp_members_invitations_get_invites(
    218                 array(
     216        // Check if the user is already a site member.
     217        $maybe_user = get_user_by( 'email', $invite->invitee_email );
     218
     219        // This user is already a member
     220        if ( $maybe_user ) {
     221                $message = sprintf( __( 'Welcome! You are already a member of this site. Please <a href="%1s">log in</a> to continue. If you have forgotten your password, you can <a href="%2s">reset it</a>.', 'buddypress' ), wp_login_url( bp_get_root_domain() ), wp_lostpassword_url(  bp_get_root_domain() ) );
     222        // This user can register!
     223        } else {
     224
     225                // Fetch the display names of all inviters to personalize the welcome message.
     226                $args = array(
    219227                        'invitee_email' => $invite->invitee_email,
    220228                        'invite_sent'   => 'sent',
    221                 )
    222         );
    223         $inviters = array();
    224         foreach ( $all_invites as $inv ) {
    225                 $inviters[] = bp_core_get_user_displayname( $inv->inviter_id );
    226         }
     229                );
     230                $all_invites = bp_members_invitations_get_invites( $all_args );
     231                $inviters = array();
     232                foreach ( $all_invites as $inv ) {
     233                        $inviters[] = bp_core_get_user_displayname( $inv->inviter_id );
     234                }
    227235
    228         if ( ! empty( $inviters ) ) {
    229                 $message = sprintf( _n( 'Welcome! You&#8217;ve been invited to join the site by the following user: %s. ', 'Welcome! You&#8217;ve been invited to join the site by the following users: %s. ', count( $inviters ), 'buddypress' ), implode( ', ', $inviters ) );
    230         } else {
    231                 $message = __( 'Welcome! You&#8217;ve been invited to join the site. ', 'buddypress' );
     236                if ( ! empty( $inviters ) ) {
     237                        $message = sprintf( _n( 'Welcome! You&#8217;ve been invited to join the site by the following user: %s. ', 'Welcome! You&#8217;ve been invited to join the site by the following users: %s. ', count( $inviters ), 'buddypress' ), implode( ', ', $inviters ) );
     238                } else {
     239                        $message = __( 'Welcome! You&#8217;ve been invited to join the site. ', 'buddypress' );
     240                }
    232241        }
     242
    233243        return $message;
    234244}
    235245
    function bp_members_invitations_get_registration_welcome_message() { 
    246256function bp_members_invitations_get_modified_registration_disabled_message() {
    247257        $message = '';
    248258        if ( bp_get_members_invitations_allowed() ) {
    249                 $message = __( 'Member registration is allowed by invitation only.', 'buddypress' );
    250                 // Is the user trying to accept an invitation but something is wrong?
    251                 if ( ! empty( $_GET['inv'] ) ) {
    252                         $message .= __( ' It looks like there is a problem with your invitation. Please try again.', 'buddypress' );
     259
     260                $invite = bp_get_members_invitation_from_request();
     261                if ( ! $invite->id || ! $invite->invitee_email ) {
     262                        return $message;
     263                }
     264
     265                // Check if the user is already a site member.
     266                $maybe_user = get_user_by( 'email', $invite->invitee_email );
     267
     268                if ( ! $maybe_user ) {
     269                        $message = __( 'Member registration is allowed by invitation only.', 'buddypress' );
     270                        // Is the user trying to accept an invitation but something is wrong?
     271                        if ( ! empty( $_GET['inv'] ) ) {
     272                                $message .= __( ' It looks like there is a problem with your invitation. Please try again.', 'buddypress' );
     273                        }
     274                } else if ( 'nouveau' === bp_get_theme_package_id() ) {
     275                        $message = sprintf( __( 'Welcome! You are already a member of this site. Please <a href="%1s">log in</a> to continue. If you have forgotten your password, you can <a href="%2s">reset it</a>.', 'buddypress' ), wp_login_url( bp_get_root_domain() ), wp_lostpassword_url(  bp_get_root_domain() ) );
    253276                }
    254277        }
    255278        return $message;
  • src/bp-members/bp-members-functions.php

    diff --git src/bp-members/bp-members-functions.php src/bp-members/bp-members-functions.php
    index b6940ebb1..b6fdc0122 100644
    function bp_members_invitations_delete_by_id( $id = 0 ) { 
    35383538 */
    35393539function bp_members_invitations_delete_invites( $args ) {
    35403540        $r = bp_parse_args( $args, array(
    3541                 'id'            => 0,
     3541                'id'            => false,
    35423542                'invitee_email' => '',
    35433543                'network_id'    => get_current_network_id(),
    35443544                'inviter_id'    => null,
    35453545                'accepted'      => null,
    35463546                'invite_sent'   => null
    3547         ), 'community_invitation_delete_invites' );
     3547        ), 'members_invitations_delete_invites' );
    35483548
    35493549        $inv_args = array(
    35503550                'id'            => $r['id'],
    35513551                'invitee_email' => $r['invitee_email'],
    35523552                'item_id'       => $r['network_id'],
    35533553                'inviter_id'    => $r['inviter_id'],
     3554                'accepted'      => $r['accepted'],
     3555                'invite_sent'   => $r['invite_sent']
    35543556        );
    35553557
    35563558        // Find the invitation(s).
  • src/bp-members/bp-members-invitations.php

    diff --git src/bp-members/bp-members-invitations.php src/bp-members/bp-members-invitations.php
    index 2e1b5458e..2a04c3dbd 100644
    function bp_members_invitations_complete_signup( $user_id, $user_login, $user_pa 
    139139}
    140140add_action( 'bp_core_signup_user', 'bp_members_invitations_complete_signup', 10, 4 );
    141141
     142/**
     143 * Delete site membership invitations when an opt-out request is saved.
     144 *
     145 * @since 8.0.0
     146 *
     147 * @param BP_Optout $optout Characteristics of the opt-out just saved.
     148 */
     149function bp_members_invitations_delete_optedout_invites( $optout ) {
     150
     151        $args = array(
     152                'invitee_email' => $optout->email_address,
     153        );
     154        bp_members_invitations_delete_invites( $args );
     155}
     156add_action( 'bp_optout_after_save', 'bp_members_invitations_delete_optedout_invites' );
  • src/bp-members/bp-members-notifications.php

    diff --git src/bp-members/bp-members-notifications.php src/bp-members/bp-members-notifications.php
    index 23ee17a77..6571eb1e5 100644
    defined( 'ABSPATH' ) || exit; 
    2121 * @param string $action            The kind of notification being rendered.
    2222 * @param int    $item_id           The primary item ID.
    2323 * @param int    $secondary_item_id The secondary item ID.
    24  * @param int    $total_items       The total number of messaging-related notifications
     24 * @param int    $total_items       The total number of members-related notifications
    2525 *                                  waiting for the user.
    2626 * @param string $format            'string' for BuddyBar-compatible notifications;
    2727 *                                  'array' for WP Toolbar. Default: 'string'.
    function members_format_notifications( $action, $item_id, $secondary_item_id, $t 
    3434
    3535                        // Set up the string and the filter.
    3636                        if ( (int) $total_items > 1 ) {
    37                                 $link = bp_get_members_directory_permalink();
    38                                 /* translators: %d: the number of new users */
    39                                 $text = sprintf( __( '%d members accepted your membership invitations', 'buddypress' ), (int) $total_items );
     37                                $link   = bp_get_notifications_permalink();
    4038                                $amount = 'multiple';
     39
     40                                // This is the inviter whose invitation was accepted.
     41                                if ( 0 !== (int) $secondary_item_id )  {
     42                                        /* translators: %d: the number of new users */
     43                                        $text = sprintf( __( '%d members accepted your membership invitations', 'buddypress' ), (int) $total_items );
     44                                // This is someone who also invited that user to join.
     45                                } else {
     46                                        /* translators: %d: the number of new users */
     47                                        $text = sprintf( __( '%d members are now members of the site', 'buddypress' ), (int) $total_items );
     48                                }
    4149                        } else {
    42                                 $link = bp_core_get_user_domain( $item_id );
    43                                 /* translators: %s: new user name */
    44                                 $text = sprintf( __( '%s accepted your membership invitation', 'buddypress' ),  bp_core_get_user_displayname( $item_id ) );
     50                                $link   = add_query_arg( 'welcome', 1, bp_core_get_user_domain( $item_id ) );
    4551                                $amount = 'single';
    46                         }
    4752
     53                                // This is the inviter whose invitation was accepted.
     54                                if ( 0 !== (int) $secondary_item_id )  {
     55                                        /* translators: %s: new user name */
     56                                        $text = sprintf( __( '%s accepted your membership invitation', 'buddypress' ),  bp_core_get_user_displayname( $item_id ) );                             // This is someone who also invited that user to join.
     57                                } else {
     58                                        /* translators: %s: new user name */
     59                                        $text = sprintf( __( '%s is now a member of the site', 'buddypress' ),  bp_core_get_user_displayname( $item_id ) );
     60                                }
     61                        }
    4862                        break;
    4963        }
    5064
    function members_format_notifications( $action, $item_id, $secondary_item_id, $t 
    103117 */
    104118function bp_members_invitations_accepted_invitation_notification( $invite, $new_user, $inviter_id ) {
    105119
    106         $res = bp_notifications_add_notification( array(
    107                 'user_id'           => $inviter_id,
    108                 'item_id'           => $new_user->ID,
    109                 'secondary_item_id' => $invite->id,
    110                 'component_name'    => buddypress()->members->id,
    111                 'component_action'  => 'accepted_invitation',
    112                 'date_notified'     => bp_core_current_time(),
    113                 'is_new'            => 1,
    114         ) );
     120        // Add "user is a member of the site" notification for other inviters.
     121        $args = array(
     122                'invitee_email' => $new_user->user_email,
     123                'accepted'      => 'all',
     124        );
     125        $invites = bp_members_invitations_get_invites( $args );
     126
     127        if ( ! $invites ) {
     128                return;
     129        }
     130        foreach ( $invites as $invite) {
     131                // Include the id of the "accepted" invitation.
     132                if ( $invite->inviter_id === $inviter_id ) {
     133                        $secondary_item_id = $invite->id;
     134                } else {
     135                        // Else don't store the invite id, so we know this is not the primary.
     136                        $secondary_item_id = 0;
     137                }
     138                $res = bp_notifications_add_notification( array(
     139                        'user_id'           => $invite->inviter_id,
     140                        'item_id'           => $new_user->ID,
     141                        'secondary_item_id' => $secondary_item_id,
     142                        'component_name'    => buddypress()->members->id,
     143                        'component_action'  => 'accepted_invitation',
     144                        'date_notified'     => bp_core_current_time(),
     145                        'is_new'            => 1,
     146                ) );
     147        }
    115148}
    116149add_action( 'community_membership_invite_accepted', 'bp_members_invitations_accepted_invitation_notification', 10, 3 );
    117150
     151/**
     152 * Mark accepted invitation notifications as read when user visits new user profile.
     153 *
     154 *
     155 * @since 8.0.0
     156 */
     157function bp_members_mark_read_accepted_invitation_notification() {
     158        if ( false === is_singular() || false === is_user_logged_in() || ! bp_is_user() || empty( $_GET['welcome'] ) ) {
     159                return;
     160        }
     161
     162        // Mark notification as read.
     163        BP_Notifications_Notification::update(
     164                array(
     165                        'is_new'  => false
     166                ),
     167                array(
     168                        'user_id' => bp_loggedin_user_id(),
     169                        'item_id' => bp_displayed_user_id(),
     170                )
     171        );
     172}
     173add_action( 'bp_screens', 'bp_members_mark_read_accepted_invitation_notification' );
     174
    118175/**
    119176 * Add Friends-related settings to the Settings > Notifications page.
    120177 *
    function members_screen_notification_settings() { 
    127184                return;
    128185        }
    129186
    130         if ( ! $allow_acceptance_emails = bp_get_user_meta( bp_displayed_user_id(), 'notification_members_invitation_accepted', true ) )
     187        if ( ! $allow_acceptance_emails = bp_get_user_meta( bp_displayed_user_id(), 'notification_members_invitation_accepted', true ) ) {
    131188                $allow_acceptance_emails = 'yes';
     189        }
    132190        ?>
    133191
    134192        <table class="notification-settings" id="members-notification-settings">
  • src/bp-members/classes/class-bp-members-invitation-manager.php

    diff --git src/bp-members/classes/class-bp-members-invitation-manager.php src/bp-members/classes/class-bp-members-invitation-manager.php
    index 061c5bade..a708ee17b 100644
    class BP_Members_Invitation_Manager extends BP_Invitation_Manager { 
    112112                                bp_update_user_meta( $new_user->ID, 'accepted_members_invitation', $invite->id );
    113113
    114114                                // We will mark all invitations to this user as "accepted."
    115                                 $args  = array(
    116                                         'invitee_email' => $invite->invitee_email,
    117                                         'item_id'       => get_current_network_id(),
    118                                         'type'          => 'all'
    119                                 );
    120                                 $this->mark_accepted( $args );
     115                                if ( ! empty( $invite->invitee_email )  ) {
     116                                        $args  = array(
     117                                                'invitee_email' => $invite->invitee_email,
     118                                                'item_id'       => get_current_network_id(),
     119                                                'type'          => 'all'
     120                                        );
     121                                        $this->mark_accepted( $args );
     122                                }
    121123
    122124                                /**
    123125                                 * Fires after a user has accepted a site membership invite.
    124126                                 *
    125127                                 * @since 8.0.0
    126128                                 *
    127                                  * @param BP_Invitation $invite    Invitation that was accepted.
     129                                 * @param BP_Invitation $invite     Invitation that was accepted.
    128130                                 * @param WP_user       $new_user   ID of the user who accepted the membership invite.
    129131                                 * @param int           $inviter_id ID of the user who invited this user to the site.
    130132                                 */
  • src/bp-members/screens/register.php

    diff --git src/bp-members/screens/register.php src/bp-members/screens/register.php
    index b08f6ece8..77929c442 100644
    function bp_core_screen_signup() { 
    4747        if ( bp_get_members_invitations_allowed() ) {
    4848                // Check to see if there's a valid invitation.
    4949                $maybe_invite = bp_get_members_invitation_from_request();
    50                 if ( $maybe_invite->id ) {
    51                         $active_invite = true;
     50                if ( $maybe_invite->id && $maybe_invite->invitee_email ) {
     51                        // Check if this user is already a member.
     52                        $args = array(
     53                                'invitee_email' => $maybe_invite->invitee_email,
     54                                'accepted'      => 'accepted',
     55                                'fields'        => 'ids',
     56                        );
     57                        $accepted_invites = bp_members_invitations_get_invites( $args );
     58                        if ( ! $accepted_invites ) {
     59                                $active_invite = true;
     60                        }
    5261                }
    5362        }
    5463
  • src/bp-members/screens/send-invites.php

    diff --git src/bp-members/screens/send-invites.php src/bp-members/screens/send-invites.php
    index 6471ebf1d..f2af326e2 100644
    function bp_network_invitations_catch_send_action() { 
    6767        if ( bp_verify_nonce_request( 'bp_members_invitation_send_' . bp_displayed_user_id() ) && bp_members_invitations_invite_user( $invite_args ) ) {
    6868                bp_core_add_message( __( 'Invitation successfully sent!', 'buddypress' )          );
    6969        } else {
    70                 bp_core_add_message( __( 'There was a problem sending that invitation.', 'buddypress' ), 'error' );
     70                bp_core_add_message( __( 'There was a problem sending that invitation. The user could already be a member of the site or have chosen not to receive invitations from this site.', 'buddypress' ), 'error' );
    7171        }
    7272
    7373        // Redirect.
  • src/bp-templates/bp-legacy/buddypress-functions.php

    diff --git src/bp-templates/bp-legacy/buddypress-functions.php src/bp-templates/bp-legacy/buddypress-functions.php
    index 03c09ac00..4da3d1ae9 100644
    function bp_legacy_theme_group_manage_members_add_search() { 
    20262026function bp_members_invitations_add_legacy_welcome_message() {
    20272027        $message = bp_members_invitations_get_registration_welcome_message();
    20282028        if ( $message ) {
    2029                 echo '<p>' . esc_html( $message ) . '</p>';
     2029                echo '<p>' . $message . '</p>';
    20302030        }
    20312031}
    20322032add_action( 'bp_before_register_page', 'bp_members_invitations_add_legacy_welcome_message' );