Skip to:
Content
Pages
Categories
Search
Top
Bottom

Sending notifications for multiple field groups


  • zeichnicht
    Participant

    @zeichnicht

    My client has asked that notifications get sent everytime a user updates his profile. I have two profiles that require notifications – the base group, and a group called: ‘Personal Details’ – the code I am using is sending emails for both forms no matter which form is selected, I have tried using if statements but the do not send.

    The current code:

    function rc_buddypress_profile_update( $user_id ) {
    
        $admin_email = "barbara@lsdev.biz";
        $message = sprintf( __( 'Dear Admin, "Base Profile" details have been updated for the following member: %1$s', 'buddypress' ), bp_core_get_user_displayname( $user_id ) ) . "\r\n\r\n";
        $message .= sprintf( __( 'Name: %s' ), bp_get_profile_field_data('field=Name') ). "\r\n";
        $message .= sprintf( __( 'Surname: %s' ), bp_get_profile_field_data('field=Surname') ). "\r\n";
        $message .= sprintf( __( 'Company Name: %s' ), bp_get_profile_field_data('field=Company Name') ). "\r\n";
        $message .= sprintf( __( 'Company Website: %s' ), bp_get_profile_field_data('field=Company Website') ). "\r\n";
        wp_mail( $admin_email, sprintf( __( 'FISA Member Base Profile Update' ), FISA ), $message );
    }
    
    $personalDetails = xprofile_get_field_id_from_name( 'Personal Details' );
    
    function rc_buddypress_personal_details_update( $personalDetails ) {
        $admin_email = "barbara@lsdev.biz";
        $message = sprintf( __( 'Dear Admin, "Personal Details" have been updated for the following member: %1$s', 'buddypress' ), bp_core_get_user_displayname( $personalDetails ) ) . "\r\n\r\n";
        $message .= sprintf( __( 'Mobile Phone: %s' ), bp_get_profile_field_data('field=Mobile Phone') ). "\r\n";
        $message .= sprintf( __( 'Work Phone: %s' ), bp_get_profile_field_data('field=Work Phone') ). "\r\n\r\n";
        $message .= sprintf( __( 'Address Line 1: %s' ), bp_get_profile_field_data('field=Address Line 1') ). "\r\n";
        $message .= sprintf( __( 'Address Line 2: %s' ), bp_get_profile_field_data('field=Address Line 2') ). "\r\n";
        $message .= sprintf( __( 'Address Line 3: %s' ), bp_get_profile_field_data('field=Address Line 3') ). "\r\n\r\n";
        $message .= sprintf( __( 'City: %s' ), bp_get_profile_field_data('field=City') ). "\r\n";
        $message .= sprintf( __( 'Postal Code: %s' ), bp_get_profile_field_data('field=Postal Code') ). "\r\n";
        $message .= sprintf( __( 'Region: %s' ), bp_get_profile_field_data('field=Region') ). "\r\n\r\n";
        wp_mail( $admin_email, sprintf( __( 'FISA Member Personal Details Update' ), get_option('blogname') ), $message );
    
    }
    
        add_action( 'xprofile_updated_profile', 'rc_buddypress_personal_details_update', 10, 5 );
        add_action( 'xprofile_updated_profile', 'rc_buddypress_profile_update', 10, 5 );
    

    What I tried to use to separate them:

    function rc_buddypress_profile_update( $user_id ) {
        if ( xprofile_get_field_data( "User Type") == "Personal Details" ) {
                $admin_email = "martin@lsdev.biz";
    
                $message = sprintf( __( 'Dear Admin, "Personal Details" have been updated for the following member: %1$s', 'buddypress' ), bp_core_get_user_displayname( $user_id ) ) . "\r\n\r\n";
                $message .= sprintf( __( 'Mobile Phone: %s' ), bp_get_profile_field_data('field=Mobile Phone') ). "\r\n";
                $message .= sprintf( __( 'Work Phone: %s' ), bp_get_profile_field_data('field=Work Phone') ). "\r\n\r\n";
                $message .= sprintf( __( 'Address Line 1: %s' ), bp_get_profile_field_data('field=Address Line 1') ). "\r\n";
                $message .= sprintf( __( 'Address Line 2: %s' ), bp_get_profile_field_data('field=Address Line 2') ). "\r\n";
                $message .= sprintf( __( 'Address Line 3: %s' ), bp_get_profile_field_data('field=Address Line 3') ). "\r\n\r\n";
                $message .= sprintf( __( 'City: %s' ), bp_get_profile_field_data('field=City') ). "\r\n";
                $message .= sprintf( __( 'Postal Code: %s' ), bp_get_profile_field_data('field=Postal Code') ). "\r\n";
                $message .= sprintf( __( 'Region: %s' ), bp_get_profile_field_data('field=Region') ). "\r\n\r\n";
                wp_mail( $admin_email, sprintf( __( 'FISA Member Personal Details Update' ), get_option('blogname') ), $message );
    
            } else  {
            $admin_email = "martin@lsdev.biz";
    
            $message = sprintf( __( 'Dear Admin, "Base Profile" details have been updated for the following member: %1$s', 'buddypress' ), bp_core_get_user_displayname( $user_id ) ) . "\r\n\r\n";
                $message .= sprintf( __( 'Name: %s' ), bp_get_profile_field_data('field=Name') ). "\r\n";
                $message .= sprintf( __( 'Surname: %s' ), bp_get_profile_field_data('field=Surname') ). "\r\n";
                $message .= sprintf( __( 'Company Name: %s' ), bp_get_profile_field_data('field=Company Name') ). "\r\n";
                $message .= sprintf( __( 'Company Website: %s' ), bp_get_profile_field_data('field=Company Website') ). "\r\n";
                wp_mail( $admin_email, sprintf( __( 'FISA Member Base Profile Update' ), FISA ), $message );
            }
    
        add_action( 'xprofile_updated_profile', 'rc_buddypress_profile_update', 10, 5 );

    Would appreciate some help on this.

Viewing 1 replies (of 1 total)

  • shanebp
    Moderator

    @shanebp

    Look thru this BP function: xprofile_screen_edit_profile()

    There are 2 hooks you could use:

    do_action( 'xprofile_profile_field_data_updated', $field_id, $value );

    do_action( 'xprofile_updated_profile', bp_displayed_user_id(), $posted_field_ids, $errors, $old_values, $new_values );

    The first is probably easier because you just have to check for the $field_id that you want.

Viewing 1 replies (of 1 total)
  • You must be logged in to reply to this topic.
Skip to toolbar