public static function addMenuItems() { $menu_label = CRED_NAME; //__( 'CRED','wp-cred' ); $url = CRED_CRED::getNewFormLink(false); //'post-new.php?post_type='.CRED_FORMS_CUSTOM_POST_NAME; $cf_url = CRED_CRED::getNewUserFormLink(false); //'post-new.php?post_type='.CRED_FORMS_CUSTOM_POST_NAME; $cred_index = 'CRED_Forms'; //CRED_VIEWS_PATH2.'/forms.php'; add_menu_page($menu_label, $menu_label, CRED_CAPABILITY, $cred_index, array(__CLASS__, 'FormsMenuPage'), 'none'); // allow 3rd-party menu items to be included do_action('cred_admin_menu_top', $cred_index); add_submenu_page($cred_index, __('Post Forms', 'wp-cred'), __('Post Forms', 'wp-cred'), CRED_CAPABILITY, 'CRED_Forms', array(__CLASS__, 'FormsMenuPage')); add_submenu_page($cred_index, __('New Post Form', 'wp-cred'), __('New Post Form', 'wp-cred'), CRED_CAPABILITY, $url); // CredUserForms add_submenu_page($cred_index, __('User Forms', 'wp-cred'), __('User Forms', 'wp-cred'), CRED_CAPABILITY, 'CRED_User_Forms', array(__CLASS__, 'UserFormsMenuPage')); add_submenu_page($cred_index, __('New User Form', 'wp-cred'), __('New User Form', 'wp-cred'), CRED_CAPABILITY, $cf_url); // allow 3rd-party menu items to be included do_action('cred_admin_menu_after_forms', $cred_index); add_submenu_page($cred_index, __('Custom Fields', 'wp-cred'), __('Custom Fields', 'wp-cred'), CRED_CAPABILITY, 'CRED_Fields', array(__CLASS__, 'FieldsMenuPage')); // allow 3rd-party menu items to be included do_action('cred_admin_menu_after_fields', $cred_index); add_submenu_page($cred_index, __('Settings/Import', 'wp-cred'), __('Settings/Import', 'wp-cred'), CRED_CAPABILITY, 'CRED_Settings', array(__CLASS__, 'SettingsMenuPage')); // allow 3rd-party menu items to be included do_action('cred_admin_menu_after_settings', $cred_index); $hook = add_submenu_page($cred_index, __('Help', 'wp-cred'), __('Help', 'wp-cred'), CRED_CAPABILITY, 'CRED_Help', array(__CLASS__, 'HelpMenuPage')); add_submenu_page($hook, __('Debug information', 'wp-cred'), __('Debug information', 'wp-cred'), CRED_CAPABILITY, 'cred-debug-information', array(__CLASS__, 'DebugMenuPage')); // allow 3rd-party menu items to be included do_action('cred_admin_menu_bottom', $cred_index); CRED_Helper::$screens = array('toplevel_page_CRED_Forms', 'toplevel_page_CRED_User_Forms', 'cred_page_CRED_Forms', 'cred_page_CRED_User_Forms', 'cred_page_CRED_Fields'); foreach (CRED_Helper::$screens as $screen) { add_action("load-" . $screen, array(__CLASS__, 'addScreenOptions')); } }
function cred_form($form, $post_id = false, $return = false) { $output = CRED_Helper::cred_form($form, $post_id); if ($return) { return $output; } echo $output; }
public function processForm($data) { if (!isset($data['post'])) { return; } $form = $data['post']; $message = $data['message']; $notification = $data['notification']; $messages = $data['messages']; $this->setFormData($form->ID, $form->post_title); // register field values $this->processFormForStrings($form->post_content, 'Value: '); // register form title $this->registerString('Form Title: ' . $form->post_title, $form->post_title); $this->registerString('Display Message: ' . $form->post_title, $message); // register Notification Data also if ($notification && isset($notification->notifications) && is_array($notification->notifications)) { foreach ($notification->notifications as $ii => $nott) { // new format // these are not relevant in new format for localization /*switch($nott['to']['type']) { case 'wp_user': $this->registerString('CRED Notification '.$ii.' Mail To', $nott['to']['user']); break; case 'specific_mail': $this->registerString('CRED Notification '.$ii.' Mail To', $nott['to']['address']); if (isset($nott['to']['name'])) $this->registerString('CRED Notification '.$ii.' Mail To Name', $nott['to']['name']); if (isset($nott['to']['lastname'])) $this->registerString('CRED Notification '.$ii.' Mail To LastName', $nott['to']['lastname']); break; default: break; }*/ $hashSubject = CRED_Helper::strHash($nott['mail']['subject']); $hashBody = CRED_Helper::strHash($nott['mail']['body']); $this->registerString('CRED Notification Subject ' . $hashSubject, $nott['mail']['subject']); $this->registerString('CRED Notification Body ' . $hashBody, $nott['mail']['body']); } } // register messages also foreach ($messages as $msgid => $msg) { $this->registerString('Message_' . $msgid, $msg); } // register options from select and checkboxes/radio fields, force form build CRED_Loader::load('CLASS/Form_Builder'); CRED_Form_Builder::init(); CRED_Form_Builder::getForm($form->ID, null, false); // allow 3rd-party to add extra localization do_action('cred_localize_form', $data); }
<?php _e('Redirect delay (in seconds)', 'wp-cred'); ?> <input type='text' size='3' id='cred_form_redirect_delay' name='_cred[form][redirect_delay]' value='<?php echo esc_attr($settings['redirect_delay']); ?> ' /> </span> <div data-cred-bind="{ action: 'fadeSlide', condition: '_cred[form][action]=message' }"> <p class='cred-explain-text'><?php _e('Enter the message to display instead of the form. You can use HTML and shortcodes.', 'wp-cred'); ?> </p> <?php echo CRED_Helper::getRichEditor('credformactionmessage', '_cred[form][action_message]', $settings['action_message'], array('wpautop' => true, 'teeny' => true, 'editor_height' => 200, 'editor_class' => 'wpcf-wysiwyg')); ?> <!--<textarea id='cred_form_action_message' name='_cred[form][action_message]' style="position:relative; width:95%;"><?php //echo esc_textarea($settings['action_message']); ?> </textarea>--> <!-- correct initial value --> <script type='text/javascript'> /* <![CDATA[ */ (function (window, $, undefined) { $(function () { try { $('#credformactionmessage').val($('#credformactionmessage').text()); } catch (e) { } });
public static function sendNotifications($post_id, $form_id, $notificationsToSent) { // custom action hooks here, for 3rd-party integration //do_action('cred_before_send_notifications_'.$form_id, $post_id, $form_id, $notificationsToSent); //do_action('cred_before_send_notifications', $post_id, $form_id, $notificationsToSent); // get Mailer $mailer = CRED_Loader::get('CLASS/Mail_Handler'); // get current user $user = self::getCurrentUserData(); $is_user_form = self::get_form_type($form_id) == CRED_USER_FORMS_CUSTOM_POST_NAME; // get Model $model = $is_user_form ? CRED_Loader::get('MODEL/UserForms') : CRED_Loader::get('MODEL/Forms'); //user created/updated $the_user = $is_user_form ? get_userdata($post_id)->data : null; // get some data for placeholders $form_post = get_post($form_id); $form_title = $form_post ? $form_post->post_title : ''; $link = get_permalink($post_id); $title = get_the_title($post_id); $admin_edit_link = CRED_CRED::getPostAdminEditLink($post_id); //get_edit_post_link( $post_id ); //$date=date('d/m/Y H:i:s'); $date = date('Y-m-d H:i:s', current_time('timestamp')); // placeholder codes, allow to add custom $data_subject = apply_filters('cred_subject_notification_codes', array('%%USER_USERID%%' => isset($the_user) && isset($the_user->ID) ? $the_user->ID : '', '%%USER_EMAIL%%' => isset($the_user) && isset($the_user->user_email) ? $the_user->user_email : '', '%%USER_USERNAME%%' => isset(StaticClass::$_username_generated) ? StaticClass::$_username_generated : '', '%%USER_PASSWORD%%' => isset(StaticClass::$_password_generated) ? StaticClass::$_password_generated : '', '%%USER_NICKNAME%%' => isset(StaticClass::$_nickname_generated) ? StaticClass::$_nickname_generated : '', '%%USER_LOGIN_NAME%%' => $user->login, '%%USER_DISPLAY_NAME%%' => $user->display_name, '%%POST_ID%%' => $post_id, '%%POST_TITLE%%' => $title, '%%FORM_NAME%%' => $form_title, '%%DATE_TIME%%' => $date), $form_id, $post_id); // placeholder codes, allow to add custom $data_body = apply_filters('cred_body_notification_codes', array('%%USER_USERID%%' => isset($the_user) && isset($the_user->ID) ? $the_user->ID : '', '%%USER_EMAIL%%' => isset($the_user) && isset($the_user->user_email) ? $the_user->user_email : '', '%%USER_USERNAME%%' => isset(StaticClass::$_username_generated) ? StaticClass::$_username_generated : '', '%%USER_PASSWORD%%' => isset(StaticClass::$_password_generated) ? StaticClass::$_password_generated : '', '%%USER_NICKNAME%%' => isset(StaticClass::$_nickname_generated) ? StaticClass::$_nickname_generated : '', '%%USER_LOGIN_NAME%%' => $user->login, '%%USER_DISPLAY_NAME%%' => $user->display_name, '%%POST_ID%%' => $post_id, '%%POST_TITLE%%' => $title, '%%POST_LINK%%' => $link, '%%POST_ADMIN_LINK%%' => $admin_edit_link, '%%FORM_NAME%%' => $form_title, '%%DATE_TIME%%' => $date), $form_id, $post_id); //cred_log(array($post_id, $form_id, $data_subject, $data_body, $notificationsToSent)); foreach ($notificationsToSent as $notification) { // bypass if nothing if (!$notification || empty($notification) || !(isset($notification['to']['type']) || isset($notification['to']['author']))) { continue; } // reset mail handler $mailer->reset(); $mailer->setHTML(true, false); $recipients = array(); if (isset($notification['to']['author']) && 'author' == $notification['to']['author']) { $author_post_id = isset($_POST['form_' . $form_id . '_referrer_post_id']) ? $_POST['form_' . $form_id . '_referrer_post_id'] : 0; if (0 == $author_post_id && $post_id) { $mypost = get_post($post_id); $author_id = $mypost->post_author; } else { $mypost = get_post($author_post_id); $author_id = $user->ID; if (!isset($author_id)) { $author_id = $mypost->post_author; } } if ($author_id) { $_to_type = 'to'; $user_info = get_userdata($author_id); $_addr_name = isset($user_info) && isset($user_info->user_firstname) && !empty($user_info->user_firstname) ? $user_info->user_firstname : false; $_addr_lastname = isset($user_info) && isset($user_info->user_lasttname) && !empty($user_info->user_lasttname) ? $user_info->user_lastname : false; $_addr = $user_info->user_email; if (isset($_addr)) { $recipients[] = array('to' => $_to_type, 'address' => $_addr, 'name' => $_addr_name, 'lastname' => $_addr_lastname); } } } // parse Notification Fields if (!isset($notification['to']['type'])) { $notification['to']['type'] = array(); } if (!is_array($notification['to']['type'])) { $notification['to']['type'] = (array) $notification['to']['type']; } // notification to a mail field (which is saved as post meta) if (in_array('mail_field', $notification['to']['type']) && isset($notification['to']['mail_field']['address_field']) && !empty($notification['to']['mail_field']['address_field'])) { $_to_type = 'to'; $_addr = false; $_addr_name = false; $_addr_lastname = false; if ($is_user_form) { $_addr = $the_user->user_email; } else { $_addr = $model->getPostMeta($post_id, $notification['to']['mail_field']['address_field']); } if (isset($notification['to']['mail_field']['to_type']) && in_array($notification['to']['mail_field']['to_type'], array('to', 'cc', 'bcc'))) { $_to_type = $notification['to']['mail_field']['to_type']; } if (isset($notification['to']['mail_field']['name_field']) && !empty($notification['to']['mail_field']['name_field']) && '###none###' != $notification['to']['mail_field']['name_field']) { $_addr_name = $is_user_form ? $model->getUserMeta($post_id, $notification['to']['mail_field']['name_field']) : $model->getPostMeta($post_id, $notification['to']['mail_field']['name_field']); } if (isset($notification['to']['mail_field']['lastname_field']) && !empty($notification['to']['mail_field']['lastname_field']) && '###none###' != $notification['to']['mail_field']['lastname_field']) { $_addr_lastname = $is_user_form ? $model->getUserMeta($post_id, $notification['to']['mail_field']['lastname_field']) : $model->getPostMeta($post_id, $notification['to']['mail_field']['lastname_field']); } // add to recipients $recipients[] = array('to' => $_to_type, 'address' => $_addr, 'name' => $_addr_name, 'lastname' => $_addr_lastname); } // notification to an exisiting wp user if (in_array('wp_user', $notification['to']['type'])) { $_to_type = 'to'; $_addr = false; $_addr_name = false; $_addr_lastname = false; if (isset($notification['to']['wp_user']['to_type']) && in_array($notification['to']['wp_user']['to_type'], array('to', 'cc', 'bcc'))) { $_to_type = $notification['to']['wp_user']['to_type']; } $_addr = $notification['to']['wp_user']['user']; $user_id = email_exists($_addr); if ($user_id) { $user_info = get_userdata($user_id); $_addr_name = isset($user_info->user_firstname) && !empty($user_info->user_firstname) ? $user_info->user_firstname : false; $_addr_lastname = isset($user_info->user_lasttname) && !empty($user_info->user_lasttname) ? $user_info->user_lastname : false; // add to recipients $recipients[] = array('to' => $_to_type, 'address' => $_addr, 'name' => $_addr_name, 'lastname' => $_addr_lastname); } } // notification to an exisiting wp user if (in_array('user_id_field', $notification['to']['type'])) { $_to_type = 'to'; $_addr = false; $_addr_name = false; $_addr_lastname = false; if (isset($notification['to']['user_id_field']['to_type']) && in_array($notification['to']['user_id_field']['to_type'], array('to', 'cc', 'bcc'))) { $_to_type = $notification['to']['user_id_field']['to_type']; } //$user_id = $is_user_form ? @trim($model->getUserMeta($post_id, $notification['to']['user_id_field']['field_name'])) : @trim($model->getPostMeta($post_id, $notification['to']['user_id_field']['field_name'])); $user_id = $is_user_form ? $post_id : @trim($model->getPostMeta($post_id, $notification['to']['user_id_field']['field_name'])); if ($user_id) { $user_info = get_userdata($user_id); if ($user_info) { $_addr = isset($user_info->user_email) && !empty($user_info->user_email) ? $user_info->user_email : false; $_addr_name = isset($user_info->user_firstname) && !empty($user_info->user_firstname) ? $user_info->user_firstname : false; $_addr_lastname = isset($user_info->user_lasttname) && !empty($user_info->user_lasttname) ? $user_info->user_lastname : false; // add to recipients $recipients[] = array('to' => $_to_type, 'address' => $_addr, 'name' => $_addr_name, 'lastname' => $_addr_lastname); } } } // notification to specific recipients if (in_array('specific_mail', $notification['to']['type']) && isset($notification['to']['specific_mail']['address'])) { $tmp = explode(',', $notification['to']['specific_mail']['address']); foreach ($tmp as $aa) { $recipients[] = array('address' => $aa, 'to' => false, 'name' => false, 'lastname' => false); } unset($tmp); } // add custom recipients by 3rd-party //cred_log(array('cred_notification_recipients', $recipients, $notification, $form_id, $post_id)); //$recipients=apply_filters('cred_notification_recipients', $recipients, array('form_id'=>$form_id, 'post_id'=>$post_id, 'notification'=>$notification)); $recipients = apply_filters('cred_notification_recipients', $recipients, $notification, $form_id, $post_id); if (!$recipients || empty($recipients)) { continue; } // build recipients foreach ($recipients as $ii => $recipient) { // nowhere to send, bypass if (!isset($recipient['address']) || !$recipient['address']) { unset($recipients[$ii]); continue; } if (false === $recipient['to']) { // this is already formatted $recipients[$ii] = $recipient['address']; continue; } $tmp = ''; $tmp .= $recipient['to'] . ': '; $tmp2 = array(); if ($recipient['name']) { $tmp2[] = $recipient['name']; } if ($recipient['lastname']) { $tmp2[] = $recipient['lastname']; } if (!empty($tmp2)) { $tmp .= implode(' ', $tmp2) . ' <' . $recipient['address'] . '>'; } else { $tmp .= $recipient['address']; } $recipients[$ii] = $tmp; } //cred_log($recipients); $mailer->addRecipients($recipients); if (isset($_POST[StaticClass::PREFIX . 'cred_container_id'])) { $notification['mail']['body'] = str_replace("[cred-container-id]", StaticClass::$_cred_container_id, $notification['mail']['body']); } global $current_user_id; $current_user_id = $user_id; if (!$user_id && $is_user_form) { $current_user_id = $post_id; } // build SUBJECT $_subj = ''; if (isset($notification['mail']['subject'])) { $_subj = $notification['mail']['subject']; } // build BODY $_bod = ''; if (isset($notification['mail']['body'])) { $_bod = $notification['mail']['body']; } // replace placeholders $_subj = self::replacePlaceholders($_subj, $data_subject); // replace placeholders $_bod = self::replacePlaceholders($_bod, $data_body); //fixing https://icanlocalize.basecamphq.com/projects/7393061-toolset/todo_items/188538611/comments if (defined('WPCF_EMBEDDED_ABSPATH') && WPCF_EMBEDDED_ABSPATH) { require_once WPCF_EMBEDDED_ABSPATH . '/frontend.php'; } // provide WPML localisation if (isset($notification['_cred_icl_string_id']['subject'])) { $notification_subject_string_translation_name = self::getNotification_translation_name($notification['_cred_icl_string_id']['subject']); if ($notification_subject_string_translation_name) { $_subj = cred_translate($notification_subject_string_translation_name, $_subj, 'cred-form-' . $form_title . '-' . $form_id); } } // provide WPML localisation if (isset($notification['_cred_icl_string_id']['body'])) { $notification_body_string_translation_name = self::getNotification_translation_name($notification['_cred_icl_string_id']['body']); if ($notification_body_string_translation_name) { $_bod = cred_translate($notification_body_string_translation_name, $_bod, 'cred-form-' . $form_title . '-' . $form_id); } } // parse shortcodes if necessary relative to $post_id $_subj = CRED_Helper::renderWithPost(stripslashes($_subj), $post_id, false); $mailer->setSubject($_subj); // parse shortcodes/rich text if necessary relative to $post_id $_bod = CRED_Helper::renderWithPost($_bod, $post_id); //https://icanlocalize.basecamphq.com/projects/11629195-toolset-peripheral-work/todo_items/195775787/comments#310779109 $_bod = stripslashes($_bod); $mailer->setBody($_bod); // build FROM address / name, independantly $_from = array(); if (isset($notification['from']['address']) && !empty($notification['from']['address'])) { $_from['address'] = $notification['from']['address']; } if (isset($notification['from']['name']) && !empty($notification['from']['name'])) { $_from['name'] = $notification['from']['name']; } if (!empty($_from)) { $mailer->setFrom($_from); } // send it $_send_result = $mailer->send(); if ($_send_result !== true) { update_option('_' . $form_id . '_last_mail_error', $_send_result); } } // custom action hooks here, for 3rd-party integration //do_action('cred_after_send_notifications_'.$form_id, $post_id); //do_action('cred_after_send_notifications', $post_id); }
/** * * $HeadURL: https://www.onthegosystems.com/misc_svn/crud/trunk_new/embedded/views/templates/notification-condition.tpl.php $ * $LastChangedDate: 2014-07-21 16:02:20 +0200 (lun, 21 lug 2014) $ * $LastChangedRevision: 25151 $ * $LastChangedBy: marcin $ * */ if (!defined('ABSPATH')) { die('Security check'); } if (!is_array($condition)) { $condition = array(); } $condition = CRED_Helper::mergeArrays(array('field' => '', 'op' => '=', 'value' => '', 'only_if_changed' => 1), $condition); ?> <p id="cred_notification_field_condition-<?php echo $ii; ?> -<?php echo $jj; ?> "> <i title="<?php echo esc_attr(__('Please select a field', 'wp-cred')); ?> " id="notification_field_required-<?php echo $ii; ?> -<?php
public function displayMessage($form) { $_fields = $form->getFields(); // apply some rich filters return CRED_Helper::renderWithBasicFilters(cred_translate('Display Message: ' . $form->getForm()->post_title, $_fields['form_settings']->form['action_message'], 'cred-form-' . $form->getForm()->post_title . '-' . $form->getForm()->ID)); /* return do_shortcode( cred_translate( 'Display Message: '.$form->form->post_title, $form->fields['form_settings']->form['action_message'], 'cred-form-'.$form->form->post_title.'-'.$form->form->ID ) ); */ }
<fieldset class="cred-fieldset"> <h4><?php _e('Body of emails', 'wp-cred'); ?> </h4> <div id="cred_mail_body_placeholders-<?php echo $ii; ?> " class="cred-label-holder wpcf-wysiwyg"> <label><?php _e('Notification mail body:', 'wp-cred'); ?> </label> <?php echo CRED_Helper::getRichEditor("credmailbody{$ii}", "_cred[notification][notifications][{$ii}][mail][body]", $notification['mail']['body'], array('wpautop' => false, 'teeny' => true, 'editor_height' => 200, 'editor_class' => 'wpcf-wysiwyg'), array('custom_media_buttons' => true, 'extra' => CRED_Loader::tpl('notification-body-codes', array('area_id' => "credmailbody{$ii}", 'form' => $form, 'ii' => $ii, 'notification' => $notification)))); ?> </div> </fieldset> <?php do_action('cred_admin_notification_fields_after', $form, $ii, $notification); ?> <?php if ($enableTestMail) { ?> <p> <a class='button' href='javascript:;' data-cred-bind="{ event: 'click',
public static function setupCustomUserCaps() { global $wp_roles; if (function_exists('wpcf_access_register_caps')) { // integrate with Types Access //cred_log('Access Active', 'access.log'); add_filter('types-access-area', array(__CLASS__, 'register_access_cred_user_area')); add_filter('types-access-group', array(__CLASS__, 'register_access_cred_user_group'), 10, 2); add_filter('types-access-cap', array(__CLASS__, 'register_access_cred_user_caps'), 10, 3); // do any necessary changes when access imports / exports custom capabilities add_filter('access_import_custom_capabilities_' . '__CRED_CRED_USER', array(__CLASS__, 'import_access_cred_user_caps'), 1, 2); add_filter('access_export_custom_capabilities_' . '__CRED_CRED_USER', array(__CLASS__, 'export_access_cred_user_caps'), 1, 2); } elseif (function_exists('ure_not_edit_admin') || class_exists('Members_Load')) { // export custom cred caps to admin role for other plugins to manipulate them (eg User Role Editor or Members) if (!isset($wp_roles) && class_exists('WP_Roles')) { $wp_roles = new WP_Roles(); } $wp_roles->use_db = true; if ($wp_roles->is_role('administrator')) { $administrator = $wp_roles->get_role('administrator'); } else { $administrator = false; trigger_error(__('Administrator Role not found! CRED Users capabilities will not work', 'wp-cred'), E_USER_NOTICE); return; } if ($administrator) { self::addCredUserCapsToRoleUser($administrator); } } else { self::$caps = array_merge(self::$caps, self::buildCredUserCaps()); add_filter('user_has_cap', array('CRED_Helper', 'defaultCredCapsFilter'), 5, 3); } }
<?php if (!defined('ABSPATH')) { die('Security check'); } $settings = CRED_Helper::mergeArrays(array('post' => array('post_type' => 'post', 'post_status' => 'draft'), 'form' => array('type' => 'new', 'action' => 'form', 'action_page' => '', 'action_message' => '', 'redirect_delay' => 0, 'hide_comments' => 0, 'theme' => 'minimal', 'has_media_button' => 0, 'include_wpml_scaffold' => 0, 'include_captcha_scaffold' => 0)), (array) $settings); ?> <p class='cred-label-holder'> <label for="cred_post_type"><?php _e('Choose the type of content this form will create or modify:', 'wp-cred'); ?> </label> </p> <select id="cred_post_type" name="_cred[post][post_type]" class='cred_ajax_change'> <?php foreach ($post_types as $pt) { if (!has_filter('cred_wpml_glue_is_translated_and_unique_post_type') || apply_filters('cred_wpml_glue_is_translated_and_unique_post_type', $pt['type'])) { if ($settings['post']['post_type'] == $pt['type'] || isset($_GET['glue_post_type']) && $pt['type'] == $_GET['glue_post_type']) { echo '<option value="' . $pt['type'] . '" selected="selected">' . $pt['name'] . '</option>'; } else { echo '<option value="' . $pt['type'] . '">' . $pt['name'] . '</option>'; } } } ?> </select> <p class="cred-label-holder"> <label for="cred_post_status"><?php _e('Select the status of content created by this form:', 'wp-cred'); ?> </label>
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)); } }
public static function initAdmin() { global $wp_version, $post; // add plugin menus // setup js, css assets CRED_Helper::setupAdmin(); add_action('admin_menu', array(__CLASS__, 'admin_menu'), 20); // add media buttons for cred forms at editor // if (version_compare($wp_version, '3.1.4', '>')) { // add_action('media_buttons', array(__CLASS__, 'addFormsButton'), 20, 2); // } else { // add_action('media_buttons_context', array(__CLASS__, 'addFormsButton'), 20, 2); // } // integrate with Views add_filter('wpv_meta_html_add_form_button', array(__CLASS__, 'addCREDButton'), 20, 2); //WATCHOUT: remove custom meta boxes from cred forms (to avoid any problems) // add custom meta boxes for cred forms //add_action('add_meta_boxes_' . CRED_FORMS_CUSTOM_POST_NAME, array(__CLASS__, 'addMetaBoxes'), 20, 1); // save custom fields of cred forms //add_action('save_post', array(__CLASS__, 'saveFormCustomFields'), 10, 2); // IMPORTANT: drafts should now be left with post_status=draft, maybe show up because of previous versions //add_filter('wp_insert_post_data', array(__CLASS__, 'forcePrivateforForms')); }