View difference between Paste ID: twiKyDxQ and abx9m2i7
SHOW: | | - or go back to the newest paste.
1
function my_acf_save__posts( $post_id ) {
2
    if (get_post_type($post_id) == "prace_konkursowe") {
3
    // get the user name field
4
    $first_name = get_field('twoje_imie', $post_id);
5
    
6
   	$email = get_field('twoj_email', $post_id); 
7
8
   	$pass = wp_generate_password();
9
    
10
    // create the user
11
    $create = wp_create_user( $email, $pass, $email );
12
13
14
15
    if ((is_wp_error($create) || isset($_COOKIE['konkurs'])) && !current_user_can('manage_options')) {
16
    	wp_delete_post($post_id);
17
    	echo "Już dodałeś prace";
18
    	exit;
19
    }
20
21
    $user = get_user_by_email($email);
22
    wp_update_user(['ID'=>$user->ID, 'first_name' => $first_name]);
23
    update_user_meta($user->ID, 'post_created', 1);
24
25
    wp_new_user_notification($user->ID);
26
    // delete the unused post
27
28
    
29
30
    $arg = array(
31
    'ID' => $post_id,
32
    'post_author' => $user->ID,
33
);
34
	wp_update_post( $arg );
35
36
37
   
38
    }
39
}