Skip to:
Content

BuddyPress.org

Changeset 12932


Ignore:
Timestamp:
04/29/2021 01:28:50 PM (4 years ago)
Author:
imath
Message:

BP Email: introduce "unnamed" salutation

The member invites feature's goal is to invite external users to join a community. The BP Email feature uses a named salutation by default. As a result, the salutation of invitation emails was "Hi email@…,". The user's name is not yet known and using this kind of salutation is odd. The member invites feature's need is to simply use an "unnamed" salutation eg: "Hi,". To satisfy it we are updating the BP Email type schema with a new property $named_salutation which defaults to true. If this property is false, then the sent email will from now on use an unnamed salutation.

NB: to prevent potential back compatibiliy issues, each kind of salutation has their own filters

  • Use bp_email_get_unnamed_salutation to edit the unnamed one.
  • Use bp_email_get_salutation to edit the default one (named).

Props dcavins for coloring outside the lines a bit 😉

See #8139

Location:
trunk/src/bp-core
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-core/bp-core-functions.php

    r12931 r12932  
    39783978function bp_email_get_type_schema( $field = 'description' ) {
    39793979    $activity_comment = array(
    3980         'description'   => __( 'A member has replied to an activity update that the recipient posted.', 'buddypress' ),
    3981         'unsubscribe'   => array(
    3982             'meta_key'  => 'notification_activity_new_reply',
    3983             'message'   => __( 'You will no longer receive emails when someone replies to an update or comment you posted.', 'buddypress' ),
     3980        'description'      => __( 'A member has replied to an activity update that the recipient posted.', 'buddypress' ),
     3981        'named_salutation' => true,
     3982        'unsubscribe'      => array(
     3983            'meta_key' => 'notification_activity_new_reply',
     3984            'message'  => __( 'You will no longer receive emails when someone replies to an update or comment you posted.', 'buddypress' ),
    39843985        ),
    39853986    );
    39863987
    39873988    $activity_comment_author = array(
    3988         'description'   => __( 'A member has replied to a comment on an activity update that the recipient posted.', 'buddypress' ),
    3989         'unsubscribe'   => array(
    3990             'meta_key'  => 'notification_activity_new_reply',
    3991             'message'   => __( 'You will no longer receive emails when someone replies to an update or comment you posted.', 'buddypress' ),
     3989        'description'      => __( 'A member has replied to a comment on an activity update that the recipient posted.', 'buddypress' ),
     3990        'named_salutation' => true,
     3991        'unsubscribe'      => array(
     3992            'meta_key' => 'notification_activity_new_reply',
     3993            'message'  => __( 'You will no longer receive emails when someone replies to an update or comment you posted.', 'buddypress' ),
    39923994        ),
    39933995    );
    39943996
    39953997    $activity_at_message = array(
    3996         'description'   => __( 'Recipient was mentioned in an activity update.', 'buddypress' ),
    3997         'unsubscribe'   => array(
    3998             'meta_key'  => 'notification_activity_new_mention',
    3999             'message'   => __( 'You will no longer receive emails when someone mentions you in an update.', 'buddypress' ),
     3998        'description'      => __( 'Recipient was mentioned in an activity update.', 'buddypress' ),
     3999        'named_salutation' => true,
     4000        'unsubscribe'      => array(
     4001            'meta_key' => 'notification_activity_new_mention',
     4002            'message'  => __( 'You will no longer receive emails when someone mentions you in an update.', 'buddypress' ),
    40004003        ),
    40014004    );
    40024005
    40034006    $groups_at_message = array(
    4004         'description'   => __( 'Recipient was mentioned in a group activity update.', 'buddypress' ),
    4005         'unsubscribe'   => array(
    4006             'meta_key'  => 'notification_activity_new_mention',
    4007             'message'   => __( 'You will no longer receive emails when someone mentions you in an update.', 'buddypress' ),
     4007        'description'      => __( 'Recipient was mentioned in a group activity update.', 'buddypress' ),
     4008        'named_salutation' => true,
     4009        'unsubscribe'      => array(
     4010            'meta_key' => 'notification_activity_new_mention',
     4011            'message'  => __( 'You will no longer receive emails when someone mentions you in an update.', 'buddypress' ),
    40084012        ),
    40094013    );
    40104014
    40114015    $core_user_registration = array(
    4012         'description'   => __( 'Recipient has registered for an account.', 'buddypress' ),
    4013         'unsubscribe'   => false,
     4016        'description'      => __( 'Recipient has registered for an account.', 'buddypress' ),
     4017        'named_salutation' => true,
     4018        'unsubscribe'      => false,
    40144019    );
    40154020
    40164021    $core_user_registration_with_blog = array(
    4017         'description'   => __( 'Recipient has registered for an account and site.', 'buddypress' ),
    4018         'unsubscribe'   => false,
     4022        'description'      => __( 'Recipient has registered for an account and site.', 'buddypress' ),
     4023        'named_salutation' => true,
     4024        'unsubscribe'      => false,
    40194025    );
    40204026
    40214027    $friends_request = array(
    4022         'description'   => __( 'A member has sent a friend request to the recipient.', 'buddypress' ),
    4023         'unsubscribe'   => array(
    4024             'meta_key'  => 'notification_friends_friendship_request',
    4025             'message'   => __( 'You will no longer receive emails when someone sends you a friend request.', 'buddypress' ),
     4028        'description'      => __( 'A member has sent a friend request to the recipient.', 'buddypress' ),
     4029        'named_salutation' => true,
     4030        'unsubscribe'      => array(
     4031            'meta_key' => 'notification_friends_friendship_request',
     4032            'message'  => __( 'You will no longer receive emails when someone sends you a friend request.', 'buddypress' ),
    40264033        ),
    40274034    );
    40284035
    40294036    $friends_request_accepted = array(
    4030         'description'   => __( 'Recipient has had a friend request accepted by a member.', 'buddypress' ),
    4031         'unsubscribe'   => array(
    4032             'meta_key'  => 'notification_friends_friendship_accepted',
    4033             'message'   => __( 'You will no longer receive emails when someone accepts your friendship request.', 'buddypress' ),
     4037        'description'      => __( 'Recipient has had a friend request accepted by a member.', 'buddypress' ),
     4038        'named_salutation' => true,
     4039        'unsubscribe'      => array(
     4040            'meta_key' => 'notification_friends_friendship_accepted',
     4041            'message'  => __( 'You will no longer receive emails when someone accepts your friendship request.', 'buddypress' ),
    40344042        ),
    40354043    );
    40364044
    40374045    $groups_details_updated = array(
    4038         'description'   => __( "A group's details were updated.", 'buddypress' ),
    4039         'unsubscribe'   => array(
    4040             'meta_key'  => 'notification_groups_group_updated',
    4041             'message'   => __( 'You will no longer receive emails when one of your groups is updated.', 'buddypress' ),
     4046        'description'      => __( "A group's details were updated.", 'buddypress' ),
     4047        'named_salutation' => true,
     4048        'unsubscribe'      => array(
     4049            'meta_key' => 'notification_groups_group_updated',
     4050            'message'  => __( 'You will no longer receive emails when one of your groups is updated.', 'buddypress' ),
    40424051        ),
    40434052    );
    40444053
    40454054    $groups_invitation = array(
    4046         'description'   => __( 'A member has sent a group invitation to the recipient.', 'buddypress' ),
    4047         'unsubscribe'   => array(
    4048             'meta_key'  => 'notification_groups_invite',
    4049             'message'   => __( 'You will no longer receive emails when you are invited to join a group.', 'buddypress' ),
     4055        'description'      => __( 'A member has sent a group invitation to the recipient.', 'buddypress' ),
     4056        'named_salutation' => true,
     4057        'unsubscribe'      => array(
     4058            'meta_key' => 'notification_groups_invite',
     4059            'message'  => __( 'You will no longer receive emails when you are invited to join a group.', 'buddypress' ),
    40504060        ),
    40514061    );
    40524062
    40534063    $groups_member_promoted = array(
    4054         'description'   => __( "Recipient's status within a group has changed.", 'buddypress' ),
    4055         'unsubscribe'   => array(
    4056             'meta_key'  => 'notification_groups_admin_promotion',
    4057             'message'   => __( 'You will no longer receive emails when you have been promoted in a group.', 'buddypress' ),
     4064        'description'      => __( "Recipient's status within a group has changed.", 'buddypress' ),
     4065        'named_salutation' => true,
     4066        'unsubscribe' => array(
     4067            'meta_key' => 'notification_groups_admin_promotion',
     4068            'message'  => __( 'You will no longer receive emails when you have been promoted in a group.', 'buddypress' ),
    40584069        ),
    40594070    );
    40604071
    40614072    $groups_membership_request = array(
    4062         'description'   => __( 'A member has requested permission to join a group.', 'buddypress' ),
    4063         'unsubscribe'   => array(
    4064             'meta_key'  => 'notification_groups_membership_request',
    4065             'message'   => __( 'You will no longer receive emails when someone requests to be a member of your group.', 'buddypress' ),
     4073        'description'      => __( 'A member has requested permission to join a group.', 'buddypress' ),
     4074        'named_salutation' => true,
     4075        'unsubscribe'      => array(
     4076            'meta_key' => 'notification_groups_membership_request',
     4077            'message'  => __( 'You will no longer receive emails when someone requests to be a member of your group.', 'buddypress' ),
    40664078        ),
    40674079    );
    40684080
    40694081    $messages_unread = array(
    4070         'description'   => __( 'Recipient has received a private message.', 'buddypress' ),
    4071         'unsubscribe'   => array(
    4072             'meta_key'  => 'notification_messages_new_message',
    4073             'message'   => __( 'You will no longer receive emails when someone sends you a message.', 'buddypress' ),
     4082        'description'      => __( 'Recipient has received a private message.', 'buddypress' ),
     4083        'named_salutation' => true,
     4084        'unsubscribe'      => array(
     4085            'meta_key' => 'notification_messages_new_message',
     4086            'message'  => __( 'You will no longer receive emails when someone sends you a message.', 'buddypress' ),
    40744087        ),
    40754088    );
    40764089
    40774090    $settings_verify_email_change = array(
    4078         'description'   => __( 'Recipient has changed their email address.', 'buddypress' ),
    4079         'unsubscribe'   => false,
     4091        'description'      => __( 'Recipient has changed their email address.', 'buddypress' ),
     4092        'named_salutation' => true,
     4093        'unsubscribe'      => false,
    40804094    );
    40814095
    40824096    $groups_membership_request_accepted = array(
    4083         'description'   => __( 'Recipient had requested to join a group, which was accepted.', 'buddypress' ),
    4084         'unsubscribe'   => array(
    4085             'meta_key'  => 'notification_membership_request_completed',
    4086             'message'   => __( 'You will no longer receive emails when your request to join a group has been accepted or denied.', 'buddypress' ),
     4097        'description'      => __( 'Recipient had requested to join a group, which was accepted.', 'buddypress' ),
     4098        'named_salutation' => true,
     4099        'unsubscribe'      => array(
     4100            'meta_key' => 'notification_membership_request_completed',
     4101            'message'  => __( 'You will no longer receive emails when your request to join a group has been accepted or denied.', 'buddypress' ),
    40874102        ),
    40884103    );
    40894104
    40904105    $groups_membership_request_rejected = array(
    4091         'description'   => __( 'Recipient had requested to join a group, which was rejected.', 'buddypress' ),
    4092         'unsubscribe'   => array(
    4093             'meta_key'  => 'notification_membership_request_completed',
    4094             'message'   => __( 'You will no longer receive emails when your request to join a group has been accepted or denied.', 'buddypress' ),
     4106        'description'      => __( 'Recipient had requested to join a group, which was rejected.', 'buddypress' ),
     4107        'named_salutation' => true,
     4108        'unsubscribe'      => array(
     4109            'meta_key' => 'notification_membership_request_completed',
     4110            'message'  => __( 'You will no longer receive emails when your request to join a group has been accepted or denied.', 'buddypress' ),
    40954111        ),
    40964112    );
    40974113
    40984114    $core_user_activation = array(
    4099         'description'   => __( 'Recipient has successfully activated an account.', 'buddypress' ),
     4115        'description'      => __( 'Recipient has successfully activated an account.', 'buddypress' ),
     4116        'named_salutation' => true,
     4117        'unsubscribe'      => false,
    41004118    );
    41014119
    41024120    $members_invitation = array(
    4103         'description'   => __( 'A site member has sent a site invitation to the recipient.', 'buddypress' ),
    4104         'unsubscribe'   => array(
    4105             'meta_key'  => 'notification_bp_members_invite',
    4106             'message'   => __( 'You will no longer receive emails when you are invited to join this site.', 'buddypress' ),
     4121        'description'      => __( 'A site member has sent a site invitation to the recipient.', 'buddypress' ),
     4122        'named_salutation' => false,
     4123        'unsubscribe'      => array(
     4124            'meta_key' => 'notification_bp_members_invite',
     4125            'message'  => __( 'You will no longer receive emails when you are invited to join this site.', 'buddypress' ),
    41074126        ),
    41084127    );
     
    43514370
    43524371/**
     4372 * Gets the BP Email type of a BP Email ID or object.
     4373 *
     4374 * @since 8.0.0
     4375 *
     4376 * @param int|WP_Post $email Optional. BP Email ID or BP Email object. Defaults to global $post.
     4377 * @return string The type of the BP Email object.
     4378 */
     4379function bp_email_get_type( $email = null ) {
     4380    $email = get_post( $email );
     4381
     4382    if ( ! $email ) {
     4383        return '';
     4384    }
     4385
     4386    $types = bp_get_object_terms( $email->ID, bp_get_email_tax_type(), array( 'fields' => 'slugs' ) );
     4387    $type  = reset( $types );
     4388
     4389    return $type;
     4390}
     4391
     4392/**
    43534393 * Get BuddyPress content allowed tags.
    43544394 *
  • trunk/src/bp-core/bp-core-template.php

    r12919 r12932  
    38013801     *
    38023802     * @since 2.5.0
     3803     * @since 8.0.0 Checks current BP Email type schema to eventually use the unnamed salutation.
    38033804     *
    38043805     * @param array $settings Email Settings.
     
    38063807     */
    38073808    function bp_email_get_salutation( $settings = array() ) {
    3808         $token = '{{recipient.name}}';
    3809 
    3810         /**
    3811          * Filters The Recipient Salutation inside the Email Template.
    3812          *
    3813          * @since 2.5.0
    3814          *
    3815          * @param string $value    The Recipient Salutation.
    3816          * @param array  $settings Email Settings.
    3817          * @param string $token    The Recipient token.
    3818          */
    3819         return apply_filters(
    3820             'bp_email_get_salutation',
    3821             sprintf(
    3822                 /* translators: %s: the email token for the recipient name */
    3823                 _x( 'Hi %s,', 'recipient salutation', 'buddypress' ),
     3809        $email_type = bp_email_get_type();
     3810        $saluation  = '';
     3811
     3812        if ( $email_type ) {
     3813            $types_schema = bp_email_get_type_schema( 'named_salutation' );
     3814
     3815            if ( isset( $types_schema[ $email_type ] ) && false === $types_schema[ $email_type ] ) {
     3816                /**
     3817                 * Filters The Recipient Unnamed Salutation inside the Email Template.
     3818                 *
     3819                 * @since 8.0.0
     3820                 *
     3821                 * @param string $value    The Recipient Salutation.
     3822                 * @param array  $settings Email Settings.
     3823                 */
     3824                $saluation = apply_filters(
     3825                    'bp_email_get_unnamed_salutation',
     3826                    _x( 'Hi,', 'Unnamed recipient salutation', 'buddypress' ),
     3827                    $settings
     3828                );
     3829            }
     3830        }
     3831
     3832        // Named salutations are default.
     3833        if ( ! $saluation ) {
     3834            $token = '{{recipient.name}}';
     3835
     3836            /**
     3837             * Filters The Recipient Named Salutation inside the Email Template.
     3838             *
     3839             * @since 2.5.0
     3840             *
     3841             * @param string $value    The Recipient Salutation.
     3842             * @param array  $settings Email Settings.
     3843             * @param string $token    The Recipient token.
     3844             */
     3845            $saluation = apply_filters(
     3846                'bp_email_get_salutation',
     3847                sprintf(
     3848                    /* translators: %s: the email token for the recipient name */
     3849                    _x( 'Hi %s,', 'Named recipient salutation', 'buddypress' ),
     3850                    $token
     3851                ),
     3852                $settings,
    38243853                $token
    3825             ),
    3826             $settings,
    3827             $token
    3828         );
    3829     }
     3854            );
     3855        }
     3856
     3857        return $saluation;
     3858    }
  • trunk/src/bp-core/classes/class-bp-email.php

    r12913 r12932  
    791791            add_filter( 'bp_locate_template_and_load', '__return_true' );
    792792
     793            // Set up the `$post` global.
     794            global $post;
     795            $reset_post = $post;
     796            $post       = $this->post_object;
     797
    793798            bp_locate_template( bp_email_get_template( $this->post_object ), true, false );
     799
     800            // Reset the `$post` global.
     801            $post = $reset_post;
    794802
    795803            remove_filter( 'bp_locate_template_and_load', '__return_true' );
Note: See TracChangeset for help on using the changeset viewer.