'' ), $atts); $uid = get_current_user_id(); if ($register || (!empty($a['field_group']) && !empty($uid))) { $options = array( 'post_id' => 'user_' . $uid, 'field_groups' => array(intval($a['field_group'])), 'updated_message' => $register ? "Profile Registered" : "Profile Updated", //'submit_value' => $register ? "Register" :"Update", /*Choices of 'top' (Above fields) or 'left' (Beside fields) */ 'label_placement' => 'left', 'html_submit_button' => '
', //'', /* (boolean) Whether or not to create a form element. Useful when a adding to an existing form. Defaults to true */ 'form' => $showForm, 'return' => add_query_arg('updated', 'true', get_permalink()) ); ob_start(); acf_form($options); $form = ob_get_contents(); ob_end_clean(); } return $form; } function my_acf_user_form_showProfile($atts) { return my_acf_user_form_func($atts, false, false); } function my_acf_user_form_editProfile($atts) { return my_acf_user_form_func($atts, true, false); } function my_acf_user_form_register($atts) { return my_acf_user_form_func($atts, true, true); } add_shortcode('my_acf_user_form', 'my_acf_user_form_editProfile'); add_shortcode('my_acf_user_show_form', 'my_acf_user_form_showProfile'); add_shortcode('my_acf_user_register_form', 'my_acf_user_form_register'); //adding AFC form head function add_acf_form_head() { global $post; if (!empty($post) && (has_shortcode($post->post_content, 'my_acf_user_form') || has_shortcode($post->post_content, 'my_acf_user_show_form') || has_shortcode($post->post_content, 'my_acf_user_register_form'))) { acf_form_head(); } /*if ( !empty($post) && ( has_shortcode( $post->post_content, 'my_acf_user_register_form' )) ) { //create user first //prepare basic user info $password = wp_generate_password( 10, true, false ); $username = $_POST['fields']['field_5dbca1ef8994b']; $email = $_POST['fields']['field_5dbca1ef8994b']; //register user $user_id = wp_create_user( $username, $password, $email ); wp_update_user( array( 'ID' => $user_id, 'first_name' => $_POST['fields']['field_5dbc8a9f6d904'], 'last_name' => $_POST['fields']['field_5dbc8ad36d905'], 'display_name' => $_POST['fields']['field_5dbc8a9f6d904'] . ' ' . $_POST['fields']['field_5dbc8ad36d905'] ) ); acf_form_head(); }*/ } add_action('wp_head', 'add_acf_form_head', 7); // set ACF pre-save stuff add_filter('acf/pre_save_post', 'acf_create_new_user'); function acf_create_new_user($post_id) { global $post; if (!empty($post) && (has_shortcode($post->post_content, 'my_acf_user_register_form'))) { error_log('post id: ' . $post_id); // // exit if user already logged in, front-end form sent his ID // if ( $post_id != 'new' ) { // error_log( 'post not new: ' . $post_id); // // wp_redirect( home_url() ); // return $post_id; // } $field_group = acf_get_fields_by_id('4067'); //prepare basic user info foreach ($field_group as $key => $value) { // "