Skip to:
Content

BuddyPress.org

Ticket #8428: 8428.patch

File 8428.patch, 5.5 KB (added by vapvarun, 9 months ago)

initial draft

  • src/bp-core/admin/bp-core-admin-functions.php

    diff --git src/bp-core/admin/bp-core-admin-functions.php src/bp-core/admin/bp-core-admin-functions.php
    index c9a5259e9..51b2eba19 100644
    function bp_block_category( $categories = array(), $post = null ) { 
    13051305        );
    13061306}
    13071307add_filter( 'block_categories', 'bp_block_category', 1, 2 );
     1308
     1309
     1310/**
     1311 * Adds a BuddyPress Welcome email after activate user registration.
     1312 *
     1313 * @since 8.0.0
     1314 *
     1315 */
     1316function bp_add_welcome_email() {
     1317        // Do not create if it already exists and is not in the trash
     1318        $post_exists = post_exists( '[{{{site.name}}}] Welcome!' );
     1319 
     1320        if ( $post_exists != 0 && get_post_status( $post_exists ) == 'publish' )
     1321           return;
     1322 
     1323        // Create email post object
     1324        $my_post = array(
     1325          'post_title'    => __( '[{{{site.name}}}] Welcome!', 'buddypress' ),
     1326          'post_content'  => __( 'Welcome to [{{{site.name}}}]!', 'buddypress' ),  // HTML email content.
     1327          'post_excerpt'  => __( 'Welcome to [{{{site.name}}}]!', 'buddypress' ),  // Plain text email content.
     1328          'post_status'   => 'publish',
     1329          'post_type' => bp_get_email_post_type() // this is the post type for emails
     1330        );
     1331 
     1332        // Insert the email post into the database
     1333        $post_id = wp_insert_post( $my_post );
     1334 
     1335        if ( $post_id ) {
     1336                // add our email to the taxonomy term 'core-user-activation-completed'
     1337                // Email is a custom post type, therefore use wp_set_object_terms
     1338 
     1339                $tt_ids = wp_set_object_terms( $post_id, 'core-user-activation-completed', bp_get_email_tax_type() );
     1340                foreach ( $tt_ids as $tt_id ) {
     1341                        $term = get_term_by( 'term_taxonomy_id', (int) $tt_id, bp_get_email_tax_type() );
     1342                        wp_update_term( (int) $term->term_id, bp_get_email_tax_type(), array(
     1343                                'description' => 'Recipient has successfully activated an account.',
     1344                        ) );
     1345                }
     1346        }
     1347}
     1348add_action( 'bp_core_install_emails', 'bp_add_welcome_email'  );
     1349
  • src/bp-core/bp-core-functions.php

    diff --git src/bp-core/bp-core-functions.php src/bp-core/bp-core-functions.php
    index 592f5b155..25b0fd4e7 100644
    function bp_email_get_schema() { 
    36843684         * @param array $emails The array of emails schema.
    36853685         */
    36863686        return (array) apply_filters( 'bp_email_get_schema', array(
     3687                'core-user-activation-completed' => array(
     3688                        /* translators: do not remove {} brackets or translate its contents. */
     3689                        'post_title'   => __( '[{{{site.name}}}] Welcome!', 'buddypress' ),
     3690                        /* translators: do not remove {} brackets or translate its contents. */
     3691                        'post_content' => __( 'Welcome to [{{{site.name}}}]!', 'buddypress' ),
     3692                        /* translators: do not remove {} brackets or translate its contents. */
     3693                        'post_excerpt' => __( 'Welcome to [{{{site.name}}}]!', 'buddypress' ),
     3694                ),
    36873695                'activity-comment' => array(
    36883696                        /* translators: do not remove {} brackets or translate its contents. */
    36893697                        'post_title'   => __( '[{{{site.name}}}] {{poster.name}} replied to one of your updates', 'buddypress' ),
    function bp_email_get_schema() { 
    38143822                        'post_content' => __( "Your membership request for the group &quot;<a href=\"{{{group.url}}}\">{{group.name}}</a>&quot; has been rejected.", 'buddypress' ),
    38153823                        /* translators: do not remove {} brackets or translate its contents. */
    38163824                        'post_excerpt' => __( "Your membership request for the group \"{{group.name}}\" has been rejected.\n\nTo request membership again, visit: {{{group.url}}}", 'buddypress' ),
    3817                 ),
     3825                ),             
    38183826        ) );
    38193827}
    38203828
    function bp_email_get_type_schema( $field = 'description' ) { 
    39553963                        'message'       => __( 'You will no longer receive emails when your request to join a group has been accepted or denied.', 'buddypress' ),
    39563964                ),
    39573965        );
     3966       
     3967        $core_user_activation_completed = array(
     3968                'description'   => __( 'Recipient has successfully activated an account.', 'buddypress' ),             
     3969        );
    39583970
    39593971        $types = array(
    39603972                'activity-comment'                   => $activity_comment,
    function bp_email_get_type_schema( $field = 'description' ) { 
    39733985                'settings-verify-email-change'       => $settings_verify_email_change,
    39743986                'groups-membership-request-accepted' => $groups_membership_request_accepted,
    39753987                'groups-membership-request-rejected' => $groups_membership_request_rejected,
     3988                'core-user-activation-completed'         => $core_user_activation_completed,
    39763989        );
    39773990
    39783991        if ( $field !== 'all' ) {
  • src/bp-members/bp-members-functions.php

    diff --git src/bp-members/bp-members-functions.php src/bp-members/bp-members-functions.php
    index 165bc97c3..3c89efb28 100644
    function bp_members_avatar_upload_dir( $directory = 'avatars', $user_id = 0 ) { 
    33063306                'error'   => false
    33073307        ) );
    33083308}
     3309
     3310
     3311/**
     3312 * Send Core user welcome email on user activation link
     3313 *
     3314 * @since 8.0.0
     3315 *
     3316 * @param int $user_id The user ID
     3317 */
     3318
     3319function bp_send_welcome_email( $user_id ){
     3320        // add tokens to parse in email
     3321        $args = array(
     3322                'tokens' => array(
     3323                ),
     3324        );
     3325       
     3326        // add each xprofile field value of the user as an available token (e.g. {{xprofile.1}} for the field_id of "1")
     3327        $xprofile_field_ids = bp_xprofile_get_fields_by_visibility_levels( $user_id, array( 'public', 'friends', 'loggedin', 'adminsonly' ) );
     3328        foreach( $xprofile_field_ids as $field_id ) {
     3329                $token_key = 'xprofile.' . $field_id;
     3330                $args['tokens'][$token_key] = xprofile_get_field_data( $field_id, $user_id );
     3331        }
     3332                   
     3333        // send args and user ID to receive email
     3334        bp_send_email( 'core-user-activation-completed', $user_id, $args );
     3335
     3336}
     3337add_action( 'bp_core_activated_user', 'bp_send_welcome_email' );
     3338 No newline at end of file