Support

Account

Home Forums ACF PRO Check for previously entered data

Unread

Check for previously entered data

  • I’ve got a post type called “Artist Alias”. Each Artist Alias has members and additional writers. Each of these is a repeater field containing a radio button that has “existing” selected by default and shows a user field. If a member or writer does not yet have an account, one would select “Invite New” from the radio field, revealing an email field.

    Then, on save / update, each invitee receives an email asking them to create a user account. I have all of this working per the function below, but what i need now is a way to make sure that each time an “Artist Alias” is updated (via a front-end form), it doesn’t send all of the existing invites again to the people already invited. Is there any way to check for that so that anyone that has already received an invite won’t get it again and if a person adds another invite, only that new person gets emailed the invite? Any help is greatly appreciated!

    function bpl_invite_new_writer( $post_id ) {
    	// bail early if editing in admin
    	if( is_admin() )
    		return;		
    
    	// Get data from the 2 repeater fields
    	$artist_members	= get_field('artist_members', $post_id);
    	$add_writers	= get_field('additional_writers', $post_id);
    
    	// Create arrays storing only invited users, if there are any
    	$artist_emails = array();
    	foreach ($artist_members as $member) {
    		$artist_emails[] = $member['invite_new_user'];
    	}
    	$writer_emails = array();
    	foreach ($add_writers as $writer) {
    		$writer_emails[] = $writer['invite_new_user'];
    	}
    
    	// Send if there are any new users to be invited
    	if (is_array($artist_emails)) {
    		foreach ($artist_emails as $email) {
    			// define to, subject, body and headers 
    			...
    			// send email
    			wp_mail($to, $subject, $body, $headers );
    		}
    	}
    	if (is_array($writer_emails)) {
    		foreach ($writer_emails as $email) {
    			// define to, subject, body and headers 
    			...
    			// send email
    			wp_mail($to, $subject, $body, $headers );
    		}
    	}
    
    }
    add_action('acf/save_post', 'bpl_invite_new_writer', 20);
Viewing 1 post (of 1 total)

The topic ‘Check for previously entered data’ is closed to new replies.