public static function saveFormCustomFields($post_id, $post) { if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) { return; } if (wp_is_post_revision($post_id)) { return; } if (CRED_FORMS_CUSTOM_POST_NAME != $post->post_type && CRED_USER_FORMS_CUSTOM_POST_NAME != $post->post_type) { return; } if (!current_user_can('edit_post', $post_id)) { return; } // hook not called from admin edit page, return if (empty($_POST) || !isset($_POST['cred-admin-post-page-field']) || !wp_verify_nonce($_POST['cred-admin-post-page-field'], 'cred-admin-post-page-action')) { return; } if (isset($_POST['_cred']) && is_array($_POST['_cred']) && !empty($_POST['_cred'])) { // new format if (CRED_FORMS_CUSTOM_POST_NAME == $post->post_type) { $model = CRED_Loader::get('MODEL/Forms'); $add_merge = array('hide_comments' => 0, 'has_media_button' => 0, 'action_message' => ''); } if (CRED_USER_FORMS_CUSTOM_POST_NAME == $post->post_type) { $model = CRED_Loader::get('MODEL/UserForms'); if (isset($_POST['_cred']['form']['user_role'])) { $_POST['_cred']['form']['user_role'] = json_encode($_POST['_cred']['form']['user_role']); } $add_merge = array('hide_comments' => 0, 'has_media_button' => 0, 'action_message' => '', 'autogenerate_username_scaffold' => isset($_POST['_cred']['form']['autogenerate_username_scaffold']) ? 1 : 0, 'autogenerate_nickname_scaffold' => isset($_POST['_cred']['form']['autogenerate_nickname_scaffold']) ? 1 : 0, 'autogenerate_password_scaffold' => isset($_POST['_cred']['form']['autogenerate_password_scaffold']) ? 1 : 0); } // settings (form, post, actions, messages, css etc..) $settings = new stdClass(); $settings->form = isset($_POST['_cred']['form']) ? $_POST['_cred']['form'] : array(); $settings->post = isset($_POST['_cred']['post']) ? $_POST['_cred']['post'] : array(); $settings->form = CRED_Helper::mergeArrays($add_merge, $settings->form); // notifications $notification = new stdClass(); $notification->notifications = array(); // normalize order of notifications using array_values $notification->notifications = isset($_POST['_cred']['notification']['notifications']) ? array_values($_POST['_cred']['notification']['notifications']) : array(); //we have notifications allways enabled //$notification->enable=isset($_POST['_cred']['notification']['enable'])?1:0; $notification->enable = 1; foreach ($notification->notifications as $ii => $nott) { if (isset($nott['event']['condition']) && is_array($nott['event']['condition'])) { // normalize order $notification->notifications[$ii]['event']['condition'] = array_values($notification->notifications[$ii]['event']['condition']); $notification->notifications[$ii]['event']['condition'] = CRED_Helper::applyDefaults($notification->notifications[$ii]['event']['condition'], array('field' => '', 'op' => '', 'value' => '', 'only_if_changed' => 0)); } else { $notification->notifications[$ii]['event']['condition'] = array(); } } // extra $__allowed_tags = wp_kses_allowed_html('post'); $__allowed_protocols = array('http', 'https', 'mailto'); $allowed_tags = $__allowed_tags; $allowed_protocols = $__allowed_protocols; $extra_js = isset($_POST['_cred']['extra']['js']) ? $_POST['_cred']['extra']['js'] : ''; $extra_css = isset($_POST['_cred']['extra']['css']) ? $_POST['_cred']['extra']['css'] : ''; if (!empty($extra_js)) { $extra_js = wp_kses($extra_js, $allowed_tags, $allowed_protocols); } if (!empty($extra_css)) { $extra_css = wp_kses($extra_css, $allowed_tags, $allowed_protocols); } $messages = $model->getDefaultMessages(); $extra = new stdClass(); $extra->css = $extra_css; $extra->js = $extra_js; $extra->messages = isset($_POST['_cred']['extra']['messages']) ? $_POST['_cred']['extra']['messages'] : $model->getDefaultMessages(); // update $model->updateFormCustomFields($post_id, array('form_settings' => $settings, 'notification' => $notification, 'extra' => $extra)); // wizard if (isset($_POST['_cred']['wizard'])) { $model->updateFormCustomField($post_id, 'wizard', intval($_POST['_cred']['wizard'])); } // validation if (isset($_POST['_cred']['validation'])) { $model->updateFormCustomField($post_id, 'validation', $_POST['_cred']['validation']); } else { $model->updateFormCustomField($post_id, 'validation', array('success' => 1)); } // allow 3rd-party to do its own stuff on CRED form save do_action('cred_admin_save_form', $post_id, $post); // localize form with WPML //THIS code make notification on cred to be lost /* $data=CRED_Helper::localizeFormOnSave(array( 'post'=>$post, 'notification'=>$notification, 'message'=>$settings->form['action_message'], 'messages'=>$extra->messages )); $model->updateFormCustomField($post_id, 'notification', $data['notification']); */ CRED_Helper::localizeFormOnSave(array('post' => $post, 'notification' => $notification, 'message' => $settings->form['action_message'], 'messages' => $extra->messages)); } }