private static function execute($controller = false, $action = false) { global $wp_query; if (!current_user_can(CRED_CAPABILITY) && !isset($_GET['ajax'])) { return; } // process pseudo-admin routes, needs care here to handle check correctly !! if (!$wp_query->query || $wp_query->is_404) { if (!$controller || !$action) { list($controller, $action) = self::processRoute(); if (!$controller || !$action) { return; } // no route to handle } $controllerObject = CRED_Loader::get("CONTROLLER/{$controller}", false); if ($controllerObject) { if (method_exists($controllerObject, $action)) { if (is_callable(array($controllerObject, $action))) { call_user_func_array(array($controllerObject, $action), array($_GET, $_POST)); $wp_query->is_404 = false; } } } } }
public function __construct() { global $wpdb; $this->wpdb = $wpdb; if (class_exists('CRED_Loader', false)) { $this->credmodel = CRED_Loader::get('MODEL/Forms'); } }
public function getFormField($get, $post) { $form_id = $post['form_id']; $field = $post['field']; $fm = CRED_Loader::get('MODEL/Forms'); $value = $fm->getFormCustomField($form_id, $field); echo json_encode($value); die; }
public function removeCustomField($get, $post) { if (isset($get['field_name']) && isset($get['post_type'])) { $field_name = $get['field_name']; $post_type = $get['post_type']; $fm = CRED_Loader::get('MODEL/Fields'); $fm->ignoreCustomFields($post_type, array($field_name), 'reset'); echo 'true'; die; } die; }
public function toggleHighlight($get, $post) { if (isset($post['cred_highlight'])) { $sm = CRED_Loader::get('MODEL/Settings'); $settings = $sm->getSettings(); if ($post['cred_highlight'] == '1') { $settings['syntax_highlight'] = 1; } else { $settings['syntax_highlight'] = 0; } $sm->updateSettings($settings); //echo $post['cred_highlight']; die(0); } }
public function removeCustomField($get, $post) { if (!current_user_can(CRED_CAPABILITY)) { wp_die(); } if (!isset($get['_wpnonce']) || !wp_verify_nonce($get['_wpnonce'], '_cred_customfield')) { echo "wpnonce error"; die; } if (isset($get['field_name']) && isset($get['post_type'])) { $field_name = sanitize_text_field($get['field_name']); $post_type = $get['post_type']; $fm = CRED_Loader::get('MODEL/Fields'); $fm->ignoreCustomFields($post_type, array($field_name), 'reset'); echo 'true'; die; } die; }
public function processAllFormsForStrings() { $fm = CRED_Loader::get('MODEL/Forms'); $forms = $fm->getAllForms(); foreach ($forms as $form) { $this->setFormData($form->ID, $form->post_title); $notification = $fm->getFormCustomField($form->ID, 'notification'); $settings = $fm->getFormCustomField($form->ID, 'form_settings'); $this->processFormForStrings($form->post_content, 'Value: '); // register form title $this->registerString('Form Title: ' . $form->post_title, $form->post_title); if ($settings && isset($settings->message)) { $this->registerString('Display Message: ' . $form->post_title, $settings->message); } // register Notification Data also if ($notification && isset($notification->notifications) && is_array($notification->notifications)) { foreach ($notification->notifications as $ii => $nott) { switch ($nott['mail_to_type']) { case 'wp_user': $this->registerString('CRED Notification ' . $ii . ' Mail To', $nott['mail_to_user']); break; case 'specific_mail': $this->registerString('CRED Notification ' . $ii . ' Mail To', $nott['mail_to_specific']); break; default: break; } $this->registerString('CRED Notification ' . $ii . ' Subject', $nott['subject']); $this->registerString('CRED Notification ' . $ii . ' Body', $nott['body']); } } $extra = $fm->getFormCustomField($form->ID, 'extra'); if ($extra && isset($extra->messages)) { // register messages also foreach ($extra->messages as $msgid => $msg) { $this->registerString('Message_' . $msgid, $msg['msg']); } } } }
public function getUserData($post_id) { if ($post_id && is_numeric($post_id)) { $fm = CRED_Loader::get('MODEL/UserFields'); $fields = $fm->getFields(array()); //$_data = get_user_by("id", $post_id); $_data = get_userdata($post_id); $_nickname = get_user_meta($post_id, 'nickname', true); if (!isset($_nickname) || empty($_nickname)) { return $this->error(__('User does not exist', 'wp-cred')); } $_data->data->nickname = $_nickname; if ($_data) { $data = (array) $_data->data; $myfields = array(); foreach ($fields['form_fields'] as $key => $value) { if ($key == 'user_pass') { continue; } if (isset($data[$key])) { $myfields[$key][] = $data[$key]; } } foreach ($fields['custom_fields'] as $key => $value) { if (!isset($value['meta_key'])) { $myfields[$key][] = ""; continue; } $user_meta = get_user_meta($post_id, $value['meta_key'], !(isset($value['data']['repetitive']) && $value['data']['repetitive'] == 1)); $myfields[$value['meta_key']][] = $user_meta; } $data = (object) $data; $data->post_type = 'user'; return (object) array('post' => $data, 'fields' => $myfields, 'taxonomies' => array(), 'extra' => array()); } return $this->error(__('User does not exist', 'wp-cred')); } return null; }
/** * getUserFields * @param type $get * @param type $post */ public function getUserFields($get, $post) { if (!current_user_can(CRED_CAPABILITY)) { wp_die(); } if (!isset($post['_wpnonce']) || !wp_verify_nonce($post['_wpnonce'], '_cred_wpnonce')) { echo "wpnonce error"; die; } $autogenerate = array('username' => isset($post['ag_uname']) ? $post['ag_uname'] : 1, 'nickname' => isset($post['ag_nname']) ? $post['ag_nname'] : 1, 'password' => isset($post['ag_pass']) ? $post['ag_pass'] : 1); $role = isset($post['role']) ? $post['role'] : ""; $fields_model = CRED_Loader::get('MODEL/UserFields'); $fields_all = $fields_model->getFields($autogenerate, $role); $settings_model = CRED_Loader::get('MODEL/Settings'); $settings = $settings_model->getSettings(); $publickey = $settings['recaptcha']['public_key']; $privatekey = $settings['recaptcha']['private_key']; $fields_all['extra_fields']['recaptcha']['public_key'] = $publickey; $fields_all['extra_fields']['recaptcha']['private_key'] = $privatekey; echo json_encode($fields_all); die; }
/** * cred_create_form * * you can create dinamically a cred form * * @param type $name * @param type $mode [new|edit] * @param type $post_type * return $post_id if created */ public static function cred_create_form($name, $mode, $post_type) { $name = sanitize_text_field($name); if (empty(self::$_created) && !in_array($name, self::$_created)) { self::$_created[] = $name; $form = get_page_by_title(html_entity_decode($name), OBJECT, CRED_FORMS_CUSTOM_POST_NAME); if (isset($form) && isset($form->ID)) { //TODO: give message? CRED form already exists return; } $model = CRED_Loader::get('MODEL/Forms'); $fields_model = CRED_Loader::get('MODEL/Fields'); $fields_all = $fields_model->getFields($post_type); $form_id = 1; $form_name = $name; $includeWPML = false; $nlcnt = 0; $groups = array(); $groups_out = ""; foreach ($fields_all['groups'] as $f => $fields) { $nlcnt++; $groups[$f] = $fields; $fields = explode(",", $fields); $groups_out .= self::groupOutput($f, $fields, $fields_all['groups_conditions'], $fields_all['custom_fields'], $form_id, $form_name, $includeWPML, PAD) . NL; } $taxs_out = ''; if (isset($fields_all['taxonomies_count']) && intval($fields_all['taxonomies_count']) > 0) { foreach ($fields_all['taxonomies'] as $f => $taxonomy) { $tax = self::array2Obj($taxonomy); if ($tax->type == 'taxonomy_hierarchical') { $tmp = array('master_taxonomy' => $tax->name, 'name' => $tax->name . '_add_new', 'add_new_taxonomy' => true); $tax->aux = self::array2Obj($tmp); } else { $tmp = array('master_taxonomy' => $tax->name, 'name' => $tax->name . '_popular', 'popular' => true); $tax->aux = self::array2Obj($tmp); } $taxs_out .= self::taxOutput($tax, $form_id, $form_name, $includeWPML, '') . NL; } } $parents_out = ''; if (isset($fields_all['parents_count']) && intval($fields_all['parents_count']) > 0) { foreach ($fields_all['parents'] as $f => $parent) { $parents_out .= self::fieldOutput($parent, $form_id, $form_name, $includeWPML, '', array('date', 'desc', 0, false, 'No Parent', '-- Select ' . $parent['data']['post_type'] . ' --', $parent['data']['post_type'] . ' must be selected')) . NL; } } // add fields $out = ''; //TODO: check _credModel.get('[form][theme]') how to reproduce in PHP if ('minimal' == 'minimal') { // bypass script and other styles added to form, minimal $out .= '[credform class="cred-form cred-keep-original"]' . NL . NL; } else { $out .= '[credform class="cred-form"]' . NL . NL; } $out .= PAD . self::shortcode($fields_all['form_fields']['form_messages']) . NL . NL; $out .= self::fieldOutput($fields_all['post_fields']['post_title'], $form_id, $form_name, $includeWPML, PAD) . NL . NL; if ($fields_all['post_fields']['post_content']['supports']) { $out .= self::fieldOutput($fields_all['post_fields']['post_content'], $form_id, $form_name, $includeWPML, PAD) . NL . NL; } if ($fields_all['post_fields']['post_excerpt']['supports']) { $out .= self::fieldOutput($fields_all['post_fields']['post_excerpt'], $form_id, $form_name, $includeWPML, PAD) . NL . NL; } if ($fields_all['extra_fields']['_featured_image']['supports']) { $out .= self::fieldOutput($fields_all['extra_fields']['_featured_image'], $form_id, $form_name, $includeWPML, PAD) . NL . NL; } /* out+= self::groupOutputContent('all', $fields_all['_post_data.singular_name+' Properties', groups_out+taxs_out+parents_out, PAD)+NL+NL; */ $out .= $groups_out; if (intval($fields_all['taxonomies_count']) > 0) { $out .= self::groupOutputContent('taxonomies', 'Taxonomies', $taxs_out, PAD) . NL . NL; } if (intval($fields_all['parents_count']) > 0) { $out .= self::groupOutputContent('parents', 'Parents', $parents_out, PAD) . NL . NL; } // if ($('#cred_include_captcha_scaffold').is(':checked')) { // if ($fields_all['extra_fields['recaptcha']['private_key'] != '' && $fields_all['extra_fields['recaptcha']['public_key'] != '') // $out .= PAD + '<div class="cred-field cred-field-recaptcha">' + self::shortcode($fields_all['extra_fields['recaptcha']) + '</div>' . NL . NL; // else { // $('#cred_include_captcha_scaffold').attr("checked", false); // alert('Captcha keys are empty !'); // } // } $out .= PAD . self::shortcode($fields_all['form_fields']['form_submit']) . NL . NL; $out .= '[/credform]' . NL; $form = new stdClass(); $form->ID = ''; $form->post_title = $name; $form->post_content = $out; $form->post_status = 'private'; $form->comment_status = 'closed'; $form->ping_status = 'closed'; $form->post_type = CRED_FORMS_CUSTOM_POST_NAME; $form->post_name = CRED_FORMS_CUSTOM_POST_NAME; //$form->guid=admin_url('admin.php').'?post_type='.CRED_FORMS_CUSTOM_POST_NAME; $fields = array(); $fields['form_settings'] = new stdClass(); $fields['form_settings']->form_type = $mode; $fields['form_settings']->form_action = 'form'; $fields['form_settings']->form_action_page = ''; $fields['form_settings']->redirect_delay = 0; $fields['form_settings']->message = ''; $fields['form_settings']->hide_comments = 1; $fields['form_settings']->include_captcha_scaffold = 0; $fields['form_settings']->include_wpml_scaffold = 0; $fields['form_settings']->has_media_button = 0; $fields['form_settings']->post_type = $post_type; $fields['form_settings']->post_status = 'publish'; $fields['form_settings']->cred_theme_css = 'minimal'; $fields['wizard'] = -1; $fields['extra'] = new stdClass(); $fields['extra']->css = ''; $fields['extra']->js = ''; $fields['extra']->messages = $model->getDefaultMessages(); return $model->saveForm($form, $fields); } }
/** * Filter the_content tag * Added support for resolving third party shortcodes in cred shortcodes */ function cred_do_shortcode($content) { $shortcodeParser = CRED_Loader::get('CLASS/Shortcode_Parser'); $content = $shortcodeParser->parse_content_shortcodes($content); return $content; }
public static function addMessagesMetaBox2($form, $args) { $extra = $args['args']['extra']; if (isset($extra->messages)) { $messages = $extra->messages; } else { $messages = false; } $model = CRED_Loader::get('MODEL/UserForms'); if (!$messages) { $messages = $model->getDefaultMessages(); } echo CRED_Loader::tpl('text-settings-meta-box', array('messages' => $messages, 'descriptions' => $model->getDefaultMessageDescriptions())); }
private function setAllowed(&$allowed_tags, &$allowed_protocols) { $__allowed_tags = wp_kses_allowed_html('post'); $__allowed_protocols = array('http', 'https', 'mailto'); $settings_model = CRED_Loader::get('MODEL/Settings'); $settings = $settings_model->getSettings(); $allowed_tags = isset($settings['allowed_tags']) ? $settings['allowed_tags'] : $__allowed_tags; foreach ($__allowed_tags as $key => $value) { if (!isset($allowed_tags[$key])) { unset($__allowed_tags[$key]); } } $allowed_tags = $__allowed_tags; $allowed_protocols = $__allowed_protocols; }
function cred_embedded_html() { if (isset($_GET['cred_id']) && is_numeric($_GET['cred_id'])) { $cred_id = (int) $_GET['cred_id']; //$cred = get_post($cred_id); $cred = get_post($cred_id, OBJECT, 'edit'); //StaticClass::_pre($cred); if (null == $cred) { wp_die('<div class="wpv-setting-container"><p class="toolset-alert toolset-alert-error">' . __('You attempted to edit a CRED that doesn’t exist. Perhaps it was deleted?', 'wpv-views') . '</p></div>'); } elseif ('cred-form' != $cred->post_type) { wp_die('<div class="wpv-setting-container"><p class="toolset-alert toolset-alert-error">' . __('You attempted to edit a CRED that doesn’t exist. Perhaps it was deleted?', 'wpv-views') . '</p></div>'); } else { CRED_Loader::loadAsset('STYLE/cred_codemirror_style_dev', 'cred_codemirror_style', false, CRED_CONCAT_ASSETS); wp_enqueue_style('cred_codemirror_style'); CRED_Loader::loadAsset('SCRIPT/cred_codemirror_dev', 'cred_codemirror_dev', false, CRED_CONCAT_ASSETS); wp_enqueue_script('cred_codemirror_dev'); $sm = CRED_Loader::get('MODEL/Settings'); $settings = $sm->getSettings(); $fm = CRED_Loader::get('MODEL/Forms'); $form_fields = $fm->getFormCustomFields($cred_id, array('form_settings', 'notification', 'extra', 'wizard')); $forms_model = CRED_Loader::get('MODEL/Forms'); $settings = $forms_model->getFormCustomField($cred_id, 'form_settings'); $fields_model = CRED_Loader::get('MODEL/Fields'); $fields_all = $fields_model->getFields($cred->post_type); if ($settings->post['post_status'] == 'trash') { wp_die('<div class="wpv-setting-container"><p class="toolset-alert toolset-alert-error">' . __("You can\\'t edit this CRED because it is in the Trash. Please restore it and try again.", 'wpv-views') . '</p></div>'); } $_button_getcred = '<a style="vertical-align: baseline; background: none repeat scroll 0 0 #f6921e; border-color: #ef6223; box-shadow: 0 1px 0 rgba(239, 239, 239, 0.5) inset, 0 1px 0 rgba(0, 0, 0, 0.15); color: #fff; text-decoration: none;" class="button button-primary-toolset" title="get cred" target="_blank" href="http://wp-types.com/home/cred/?utm_source=credplugin&utm_campaign=cred&utm_medium=embedded-cred-promotional-link&utm_term=Get CRED">Get CRED</a>'; $_header = "You are viewing the read-only version of this CRED form. To edit it, you need to get CRED plugin. {$_button_getcred}"; $_content = "CRED lets you build forms for editing any WordPress content on the site’s front-end. You can choose if the form creates or edits content and the type of content it will create or edit. The form is designed with simple HTML and shortcodes."; $settings_post_type = $settings->post['post_type']; $settings_post_status = $settings->post['post_status']; $settings_type = $settings->form['type']; $settings_action = $settings->form['action']; $has_captcha = $settings->form['include_captcha_scaffold'] == 1 ? " and includes captcha field " : ""; $notification = $form_fields['notification']; if ($notification->enable == 1 && count($notification->notifications) > 0) { $notification_txt = "<p>Enabled</p>"; foreach ($notification->notifications as $n => $notf) { if (count($notf['to']['type']) > 0) { $notification_txt .= "A notification will be sent to "; //StaticClass::_pre($notf['to']['type']); foreach ($notf['to']['type'] as $m => $t) { if ($t == 'wp_user' || $t == 'mail_field' || $t == 'user_id_field') { continue; } $notification_txt .= "<b>" . normalize_notf_txt($t) . "</b>"; } foreach ($notf['to']['wp_user'] as $a => $b) { if ($b != 'to') { $notification_txt .= " <b>" . normalize_notf_txt($b) . "</b> "; } } } if (isset($notf['event']) && !empty($notf['event'])) { $notification_event = "<p>The notification event is set to <b>" . trans_notf_event($notf['event']['type']) . "</b></p>"; $post_status_event = "<p>The notification post status event is set to <b>" . trans_notf_event($notf['event']['post_status']) . "</b></p>"; $condition_event = ""; if (!empty($notf['event']['condition']) && count($notf['event']['condition']) > 0) { $condition_event = "<p>The notification is <b>Based to conditions</b></p>"; } $notification_txt .= " {$notification_event} {$post_status_event} {$condition_event} "; } if (isset($notf['to']['author']) && $notf['to']['author'] == 'author') { $notification_txt .= "<p>A notification will be <b>Sent to the Author</b></p>"; } } } else { $notification_txt = "Disabled"; } $settings_txt = "This Form "; switch ($settings_type) { case 'new': $act = "Creates"; $settings_txt .= '<b>Creates Content</b>'; break; case 'edit': $act = "Edits"; $settings_txt .= '<b>Edits Content</b>'; break; } $settings_txt .= " and after submition "; switch ($settings_action) { case 'form': $settings_txt .= '<b>keeps displaying this form</b>'; break; case 'message': $settings_txt .= '<b>displays a custom message</b>'; break; case 'post': $settings_txt .= '<b>displays a post</b>'; break; case 'page': $settings_txt .= '<b>got to a custom page</b>'; break; } $settings_txt .= $settings->form['hide_comments'] == 1 ? "<p>Comments are hidden</p>" : ""; $settings_post_txt = "This Form {$act} <b>{$settings_post_type}</b> and the status will be <b>" . trans_txt($settings_post_status) . "</b>" . $has_captcha; $extra = $form_fields['extra']; $css = $extra->css; $css_txt = ""; $js = $extra->js; $css_txt = "Empty"; if (!empty($css)) { $css_txt = $css; } $js_txt = "Empty"; if (!empty($js)) { $js_txt = $js; } ?> <div style="clear:both;height:20px;"></div> <h2><?php echo $cred->post_title; ?> </h2> <div style="width:950px;height:auto;"> <div class="toolset-help js-info-box"> <div class="toolset-help-content"> <h2 style="color: #222; font-size: 1.1em; font-weight:bold; margin: 0.83em 0;"><?php echo $_header; ?> </h2> <p><?php echo $_content; ?> </p> </div> <div class="toolset-help-sidebar"> <div class="toolset-help-sidebar-ico"></div> </div> </div> </div> <h3>Form Settings:</h3> <?php echo $settings_txt; ?> <h3>Post Type Settings:</h3> <?php echo $settings_post_txt; ?> <h3>Form Content:</h3> <div style="width:950px;height:auto;"> <textarea id="mycontent"><?php echo $cred->post_content; ?> </textarea> </div> <script> jQuery(document).ready(function () { CodeMirror.defineMode("myshortcodes", codemirror_shortcodes_overlay); CodeMirror.fromTextArea(document.getElementById("mycontent") , { mode: 'myshortcodes', //"text/html", tabMode: "indent", lineWrapping: true, lineNumbers: true, readOnly: "nocursor" }); }); </script> <?php if (false) { ?> <div style="padding:5px;margin-left:10px;border:1px #000 solid;width:80%;height:200px;overflow-y:auto;"><?php echo $cred->post_content; ?> </div><?php } ?> <?php if (false) { ?> <h3>JS:</h3> <?php echo $js_txt; ?> <h3>CSS:</h3> <?php echo $css_txt; ?> <?php } ?> <h3>Notification:</h3> <?php echo $notification_txt; ?> <?php //StaticClass::_pre($form_fields['extra']); //StaticClass::_pre($cred); //StaticClass::_pre($settings); //StaticClass::_pre($fields_all); } } else { wp_die('<div class="wpv-setting-container"><p class="toolset-alert toolset-alert-error">' . __('You attempted to edit a View that doesn’t exist. Perhaps it was deleted?', 'wpv-views') . '</p></div>'); } ?> <?php }
if ($cred_import_file !== null && !empty($cred_import_file)) { $options = array(); if (isset($_POST["cred-overwrite-forms"])) { $options['overwrite_forms'] = 1; } if (isset($_POST["cred-overwrite-settings"])) { $options['overwrite_settings'] = 1; } if (isset($_POST["cred-overwrite-custom-fields"])) { $options['overwrite_custom_fields'] = 1; } CRED_Loader::load('CLASS/XML_Processor'); $user_results = CRED_XML_Processor::importUserFromXML($cred_import_file, $options); } } $settings_model = CRED_Loader::get('MODEL/Settings'); $settings = $settings_model->getSettings(); $url = admin_url('admin.php') . '?page=CRED_Settings'; $doaction = isset($_POST['cred_settings_action']) ? $_POST['cred_settings_action'] : false; if ($doaction) { check_admin_referer('cred-settings-action', 'cred-settings-field'); switch ($doaction) { case 'edit': $settings = isset($_POST['settings']) ? (array) $_POST['settings'] : array(); if (!isset($settings['wizard'])) { $settings['wizard'] = 0; } $settings_model->updateSettings($settings); break; } // CRED_PostExpiration
public static function add_screen_options() { $screen = get_current_screen(); // get out of here if we are not on our settings page if (!is_array(self::$screens) || !in_array($screen->id . '.php', self::$screens)) { return; } /*$value=$screen->get_option('per_page','default'); if (null===$value) $value=10;*/ $value = 10; if (isset($_REQUEST['wp_screen_options'])) { if (isset($_REQUEST['wp_screen_options']['option']) && 'cred_per_page' == $_REQUEST['wp_screen_options']['option'] && isset($_REQUEST['wp_screen_options']['value'])) { $value = intval($_REQUEST['wp_screen_options']['value']); } } elseif (isset($_REQUEST['per_page'])) { $value = intval($_REQUEST['per_page']); } $args = array('label' => __('Per Page', 'wp-cred'), 'default' => $value, 'option' => 'cred_per_page'); add_screen_option('per_page', $args); // instantiate table now to take care of column options switch ($screen->id) { case CRED_VIEWS_PATH2 . '/forms': CRED_Loader::get('TABLE/Forms'); break; case CRED_VIEWS_PATH2 . '/custom_fields': CRED_Loader::get('TABLE/Custom_Fields'); break; } }
public function deletePost($get, $post) { global $current_user; if (!array_key_exists('_wpnonce', $get) || !array_key_exists('cred_link_id', $get) || !array_key_exists('cred_action', $get) || !wp_verify_nonce($get['_wpnonce'], $get['cred_link_id'] . '_' . $get['cred_action'])) { die('Security check'); } $jsfuncs = array(); if (array_key_exists('cred_link_id', $_GET)) { $jsfuncs['parent._cred_cred_delete_post_handler'] = array('"' . $_GET['cred_link_id'] . '"'); } if (!isset($get['cred_post_id'])) { //echo json_encode(false); $jsfuncs['alert'] = array('"' . __('No post defined', 'wp-cred') . '"'); echo $this->renderJsFunction($jsfuncs); die; } $post_id = intval($get['cred_post_id']); $post = get_post($post_id); if ($post) { if (!current_user_can('delete_own_posts_with_cred') && $current_user->ID == $post->post_author) { die('<strong>' . __('Do not have permission (own)', 'wp-cred') . '</strong>'); } if (!current_user_can('delete_other_posts_with_cred') && $current_user->ID != $post->post_author) { die('<strong>' . __('Do not have permission (other)', 'wp-cred') . '</strong>'); } $fm = CRED_Loader::get('MODEL/Forms'); if ($get['cred_action'] == 'delete') { $result = $fm->deletePost($post_id, true); } elseif ($get['cred_action'] == 'trash') { $result = $fm->deletePost($post_id, false); } else { die; } //echo json_encode($result); if ($result) { $jsfuncs['alert'] = array('"' . __('Post deleted', 'wp-cred') . '"'); } else { $jsfuncs['alert'] = array('"' . __('Post delete failed', 'wp-cred') . '"'); } } echo $this->renderJsFunction($jsfuncs); die; }
public function processAllForms() { $fm = CRED_Loader::get('MODEL/Forms'); $forms = $fm->getAllForms(); foreach ($forms as $form) { $data = array('post' => $form, 'message' => '', 'messages' => array(), 'notification' => (object) array('enable' => 0, 'notifications' => array())); $fields = $fm->getFormCustomFields($form->ID, array('form_settings', 'notification', 'extra')); $settings = isset($fields['form_settings']) ? $fields['form_settings'] : false; $notification = isset($fields['notification']) ? $fields['notification'] : false; $extra = isset($fields['extra']) ? $fields['extra'] : false; // register settings if ($settings && isset($settings->form['action_message'])) { $data['message'] = $settings->form['action_message']; } // register Notification Data also if ($notification) { $data['notification'] = $notification; } // register extra fields if ($extra && isset($extra->messages)) { // register messages also $data['messages'] = $extra->messages; } $this->processForm($data); } }
public function CRED_extractUserFields($user_id, $user_role, $track = false) { global $user_ID; // reference to the form submission method global ${'_' . StaticClass::METHOD}; $method =& ${'_' . StaticClass::METHOD}; // get refs here $form =& $this->friendGet($this->_formBuilder, '&_formData'); $out_ =& $this->friendGet($this->_formBuilder, '&out_'); $form_id = $form->getForm()->ID; $zebraForm = $this->friendGet($this->_formBuilder, '_zebraForm'); $_fields = $form->getFields(); $form_type = $_fields['form_settings']->form['type']; $autogenerate_user = (bool) $_fields['form_settings']->form['autogenerate_username_scaffold'] ? true : false; $autogenerate_nick = (bool) $_fields['form_settings']->form['autogenerate_nickname_scaffold'] ? true : false; $autogenerate_pass = (bool) $_fields['form_settings']->form['autogenerate_password_scaffold'] ? true : false; $u = get_user_by('ID', $user_id); //user $post_type = $_fields['form_settings']->post['post_type']; $fields = $out_['fields']; $form_fields = $out_['form_fields']; // author // if ('new' == $form_type) // $post->post_author = $user_ID; // extract main post fields $user = array(); $user['ID'] = $user_id; $user['user_role'] = $user_role; foreach ($form_fields as $name => $field) { if (array_key_exists($name, $method)) { $user[$name] = stripslashes($method[$name]); } } //################################################################### //# AUTOGENERATION EMAIL MESSAGE //################################################################### if ($form_type == 'new' && isset($user['user_email']) && ($autogenerate_user || $autogenerate_nick || $autogenerate_pass)) { $settings_model = CRED_Loader::get('MODEL/Settings'); $settings = $settings_model->getSettings(); //by default use notification for autogeneration email $use_notification_for_autogeneration = defined('CRED_NOTIFICATION_4_AUTOGENERATION') ? CRED_NOTIFICATION_4_AUTOGENERATION : true; $subject = ""; $body = ""; if (!$use_notification_for_autogeneration) { $subject = apply_filters('cuf_autogeneration_email_subject', $settings['autogeneration_email']['subject']); $body = apply_filters('cuf_autogeneration_email_body', $settings['autogeneration_email']['body']); } if ($autogenerate_pass && !isset($_POST['user_pass'])) { $password_generated = wp_generate_password(10, false); StaticClass::$_password_generated = $password_generated; $user["user_pass"] = $password_generated; //$message[] .= "Your password is: $password_generated"; if (!$use_notification_for_autogeneration) { $body = str_replace("%cuf_password%", $password_generated, $body); } } $username_generated = StaticClass::generateUsername($user['user_email']); if ($autogenerate_nick && !isset($_POST['nickname'])) { $nick_generated = $username_generated; StaticClass::$_nickname_generated = $nick_generated; $user["nickname"] = $nick_generated; //$message[] .= "Your password is: $password_generated"; if (!$use_notification_for_autogeneration) { $body = str_replace("%cuf_nickname%", $nick_generated, $body); } } if ($autogenerate_user && !isset($_POST['user_login'])) { $username_generated = $username_generated; StaticClass::$_username_generated = $username_generated; $user["user_login"] = $username_generated; //$message[] .= "Your username is: $username_generated"; if (!$use_notification_for_autogeneration) { $body = str_replace("%cuf_username%", $username_generated, $body); } } if ($autogenerate_pass && $autogenerate_user && $autogenerate_nick) { //nothing to do } else { if ($autogenerate_pass && !$autogenerate_user && !$autogenerate_nick) { //Removing username not needed if (!$use_notification_for_autogeneration) { $body = preg_replace('#\\[username(.*)\\].*?\\[/username(.*)\\]#', '', $body); } } else { if (!$autogenerate_pass && $autogenerate_user && !$autogenerate_nick) { //Removing password not needed if (!$use_notification_for_autogeneration) { $body = preg_replace('#\\[password(.*)\\].*?\\[/password(.*)\\]#', '', $body); } } else { if (!$autogenerate_pass && !$autogenerate_user && $autogenerate_nick) { if (!$use_notification_for_autogeneration) { $body = preg_replace('#\\[nickname(.*)\\].*?\\[/nickname(.*)\\]#', '', $body); } } } } } if (!$use_notification_for_autogeneration) { $body = str_replace(array("[username]", "[/username]", "[password]", "[/password]", "[nickname]", "[/nickname]"), "", $body); $mailer = CRED_Loader::get('CLASS/Mail_Handler'); $mailer->reset(); $mailer->setHTML(true, false); $recipients = $user['user_email']; $mailer->addRecipients($recipients); $mailer->setSubject($subject); $mailer->setBody($body); $mailer->setFrom("*****@*****.**"); $_send_result = $mailer->send(); } } //################################################################### //# AUTOGENERATION EMAIL MESSAGE //################################################################### if ($track) { // track the data, eg for notifications if (isset($user['name'])) { $this->trackData(array('name' => $user['name'])); } } // return them return $user; }
/** * method gets data to be display inside the table sets pagination data and sets items fields of the parent class * */ function prepare_items() { global $wpdb, $_wp_column_headers; $screen = get_current_screen(); // sorting $orderby = !empty($_GET['orderby']) ? $_GET['orderby'] : 'post_title'; $order = !empty($_GET['order']) ? $_GET['order'] : 'asc'; //How many to display per page? $perpage = 10; if (isset($_REQUEST['wp_screen_options'])) { if (isset($_REQUEST['wp_screen_options']['option']) && 'cred_per_page' == $_REQUEST['wp_screen_options']['option'] && isset($_REQUEST['wp_screen_options']['value'])) { $perpage = intval($_REQUEST['wp_screen_options']['value']); } } elseif (isset($_REQUEST['per_page'])) { $perpage = intval($_REQUEST['per_page']); } //Which page is this? $paged = !empty($_GET["paged"]) ? mysql_real_escape_string($_GET["paged"]) : ''; //Page Number if (empty($paged) || !is_numeric($paged) || $paged <= 0) { $paged = 1; } $totalitems = 0; $this->items = array(); $fm = CRED_Loader::get('MODEL/Forms'); /* -- Fetch the items -- */ $totalitems = $fm->getFormsCount(); //count($this->items); if (($paged - 1) * $perpage > $totalitems) { $paged = 1; } $this->items = $fm->getFormsForTable($paged, $perpage, $orderby, $order); /* -- Register the pagination -- */ //How many pages do we have in total? $totalpages = ceil($totalitems / $perpage); $this->set_pagination_args(array("total_items" => $totalitems, "total_pages" => $totalpages, "per_page" => $perpage, "paged" => $paged)); //The pagination links are automatically built according to those parameters /* — Register the Columns — */ $columns = $this->get_columns(); $hidden = array(); $sortable = $this->get_sortable_columns(); $this->_column_headers = array($columns, $hidden, $sortable); }
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); }
public function loadForm($formID, $post_type, $preview = false) { global $post, $current_user; // reference to the form submission method global ${'_' . StaticClass::METHOD}; $method =& ${'_' . StaticClass::METHOD}; // load form data $fm = $post_type == CRED_USER_FORMS_CUSTOM_POST_NAME ? CRED_Loader::get('MODEL/UserForms') : CRED_Loader::get('MODEL/Forms'); $form = $fm->getForm($formID); if (!$form) { return $this->error(__('Form does not exist!', 'wp-cred')); } // preview when form is saved only partially if (!isset($form->fields) || !is_array($form->fields) || empty($form->fields)) { $form->fields = array(); if ($preview) { unset($form); return $this->error(__('Form preview does not exist. Try saving your form first', 'wp-cred')); } } $form->fields = array_merge(array('form_settings' => (object) array('form' => array(), 'post' => array()), 'extra' => (object) array('css' => '', 'js' => ''), 'notification' => (object) array('enable' => 0, 'notifications' => array())), $form->fields); if (!isset($form->fields['extra']->css)) { $form->fields['extra']->css = ''; } if (!isset($form->fields['extra']->js)) { $form->fields['extra']->js = ''; } $redirect_delay = isset($form->fields['form_settings']->form['redirect_delay']) ? intval($form->fields['form_settings']->form['redirect_delay']) : self::DELAY; $hide_comments = isset($form->fields['form_settings']->form['hide_comments']) && $form->fields['form_settings']->form['hide_comments'] ? true : false; $form->fields['form_settings']->form['redirect_delay'] = $redirect_delay; $form->fields['form_settings']->form['hide_comments'] = $hide_comments; if ($preview) { if (array_key_exists(StaticClass::PREFIX . 'form_preview_post_type', $method)) { $form->fields['form_settings']->post['post_type'] = stripslashes($method[StaticClass::PREFIX . 'form_preview_post_type']); } else { unset($form); return $this->error(__('Preview post type not provided', 'wp-cred')); } if (array_key_exists(StaticClass::PREFIX . 'form_preview_form_type', $method)) { $form->fields['form_settings']->form['type'] = stripslashes($method[StaticClass::PREFIX . 'form_preview_form_type']); } else { unset($form); $this->error = __('Preview form type not provided', 'wp-cred'); } if (array_key_exists(StaticClass::PREFIX . 'form_preview_content', $method)) { $form->form->post_content = stripslashes($method[StaticClass::PREFIX . 'form_preview_content']); } else { unset($form); return $this->error(__('No preview form content provided', 'wp-cred')); } if (array_key_exists(StaticClass::PREFIX . 'extra_css_to_use', $method)) { $form->fields['extra']->css = trim(stripslashes($method[StaticClass::PREFIX . 'extra_css_to_use'])); } if (array_key_exists(StaticClass::PREFIX . 'extra_js_to_use', $method)) { $form->fields['extra']->js = trim(stripslashes($method[StaticClass::PREFIX . 'extra_js_to_use'])); } } else { if ($post_type == CRED_USER_FORMS_CUSTOM_POST_NAME) { $form->fields['form_settings']->post['post_type'] = "user"; } } if (!isset($form->fields['extra']->messages)) { $form->fields['extra']->messages = $fm->getDefaultMessages(); } //return it return $form; }
function glue_get_original_field_list() { //original fields $orig_fields = "post_title,post_content,post_excerpt"; $taxonomies = get_taxonomies(); $exclude = array('nav_menu', 'link_category', 'post_format'); $taxonomies = array_diff($taxonomies, $exclude); sort($taxonomies, SORT_STRING); foreach ($taxonomies as $taxonomy) { $orig_fields .= ',' . $taxonomy; } $fm = CRED_Loader::get('MODEL/Fields'); $custom_fields = $fm->getPostTypeCustomFields('post', array(), false, 1); foreach ($custom_fields as $custom_field) { $orig_fields .= ',' . $custom_field; } return $orig_fields; }
function init() { /* CRED must be activated */ if (!class_exists('CRED_Loader', false)) { return; } // init same internal vars for localization foreach ($this->_action_post_status as $value => $text) { $this->_action_post_status[$value] = __($text, $this->_localization_context); } foreach ($this->_extra_notification_codes as $code => $text) { $this->_extra_notification_codes[$code] = __($text, $this->_localization_context); } /* get the settings option for auto expire date feature */ $settings_model = CRED_Loader::get('MODEL/Settings'); $settings = $settings_model->getSettings(); $this->_post_expiration_enabled = isset($settings['enable_post_expiration']) ? $settings['enable_post_expiration'] : false; $this->cred_pe_setup_schedule(); /* get the CRED Form model */ $this->_credmodel = CRED_Loader::get('MODEL/Forms'); /* register our script. */ wp_register_script('script-cred-post-expiration', CRED_PE_SCRIPT_URL . 'cred_post_expiration.js', array('jquery-ui-datepicker'), '1.0.0', true); }
/** * method forms the data output style * */ function display_rows() { $path = admin_url('admin.php') . '?page=CRED_Fields'; $setfieldpath = cred_route('/Generic_Fields/getCustomField'); $editfieldpath = cred_route('/Generic_Fields/getCustomField'); $removefieldpath = cred_route('/Generic_Fields/removeCustomField'); //Get the records registered in the prepare_items method $records = $this->items; $cred_fields = CRED_Loader::get('MODEL/Fields')->getCustomFields($this->_post_type); $default_types = CRED_Loader::get('MODEL/Fields')->getTypesDefaultFields(true); //Get the columns registered in the get_columns and get_sortable_columns methods list($columns, $hidden) = $this->get_column_info(); //Loop for each record if (empty($records)) { return false; } foreach ($records as $rec) { //Open the line $field_id = $rec; $ignore = false; $credfieldtype = __('Not Set', 'wp-cred'); $credfieldname = __('Not Set', 'wp-cred'); if (isset($cred_fields[$rec])) { $credfieldtype = $cred_fields[$rec]['type']; $credfieldname = isset($default_types[$cred_fields[$rec]['type']]) ? $default_types[$cred_fields[$rec]['type']]['title'] : $credfieldname; if (isset($cred_fields[$rec]['_cred_ignore'])) { $ignore = true; } } //if ($ignore) // echo '<tr id="'.$field_id.'" class="cred-ignore-field">'; //else echo '<tr id="' . $field_id . '">'; //$checkbox_id = "checkbox_" . $field_id; //$checkbox = "<input type='checkbox' name='checked[]' value='" . $field_id . "' id='" . $checkbox_id . "' /><label class='screen-reader-text' for='" . $checkbox_id . "' >" . __('Select') . " " . $rec . "</label>"; /*$ignorecheckbox_id = "ignorecheckbox_" . $field_id; $unignorecheckbox_id = "unignorecheckbox_" . $ignorecheckbox_id; if ($ignore) $ignorecheckbox = "<input checked='checked' type='checkbox' name='ignorechecked[]' value='" . $field_id . "' id='" . $ignorecheckbox_id . "' /><label style='margin-left:10px;' for='" . $ignorecheckbox_id . "' >" . __('Not include in Scaffold','wp-cred') . "</label>"; else $ignorecheckbox = "<input type='checkbox' name='ignorechecked[]' value='" . $field_id . "' id='" . $ignorecheckbox_id . "' /><label style='margin-left:10px;' for='" . $ignorecheckbox_id . "' >" . __('Not include in Scaffold','wp-cred') . "</label>"; $unignorecheckbox = "<input style='display:none;' type='checkbox' name='unignorechecked[]' value='" . $field_id . "' id='" . $unignorecheckbox_id . "' />"; $resetcheckbox_id = "resetcheckbox_" . $field_id; $resetcheckbox = "<input type='checkbox' name='resetchecked[]' value='" . $field_id . "' id='" . $resetcheckbox_id . "' /><label style='margin-left:10px;' for='" . $resetcheckbox_id . "' >" . __('Reset CRED settings','wp-cred') . "</label>"; */ foreach ($columns as $column_name => $column_display_name) { //Style attributes for each col $class = "class='{$column_name} column-{$column_name}'"; $style = ""; if (in_array($column_name, $hidden)) { $style = ' style="display:none;"'; } $attributes = $class . $style; //Display the cell switch ($column_name) { /*case "cb": echo "<th scope='row' class='check-column'>$checkbox</th>"; break;*/ case "col_field_name": //$actions = array(); //$actions['edit'] = '<a class="submitedit thickbox" href="'.$editfieldpath.'&post_type='.$this->_post_type.'&field_name='.$rec.'&TB_iframe=true&width=600&height=450" title="'.__('Edit','wp-cred').'">'.__('Edit','wp-cred').'</a>'; echo '<td ' . $attributes . '><strong><a class="thickbox" href="' . $editfieldpath . '?post_type=' . $this->_post_type . '&field_name=' . $rec . '&TB_iframe=true&width=600&height=450" title="" title="' . __('Edit', 'wp-cred') . '">' . stripslashes($rec) . '</a>'; //echo $this->row_actions( $actions ); echo '</td>'; break; /*case "col_post_type": echo '<td '.$attributes.'>'.$this->_post_type.'</td>'; break;*/ /*case "col_post_type": echo '<td '.$attributes.'>'.$this->_post_type.'</td>'; break;*/ case "col_cred_type": echo '<td ' . $attributes . '><span class="cred-field-type" style="margin-right:15px">' . $credfieldname . '</span></td>'; break; case "col_actions": $actions = array('<a style="margin-right:10px" class="cred-field-actions _cred-field-set thickbox" href="' . $setfieldpath . '?post_type=' . $this->_post_type . '&field_name=' . $rec . '&TB_iframe=true&width=600&height=450" title="' . __('Set field type', 'wp-cred') . '">' . __('Add', 'wp-cred') . '</a>', '<a style="margin-right:10px" class="cred-field-actions _cred-field-edit thickbox" href="' . $editfieldpath . '?post_type=' . $this->_post_type . '&field_name=' . $rec . '&TB_iframe=true&width=600&height=450" title="' . __('Edit field settings', 'wp-cred') . '">' . __('Edit', 'wp-cred') . '</a>', '<a style="margin-right:10px" class="cred-field-actions _cred-field-remove" href="' . $removefieldpath . '?post_type=' . $this->_post_type . '&field_name=' . $rec . '" title="' . __('Remove this field as a CRED field type', 'wp-cred') . '">' . __('Remove', 'wp-cred') . '</a>'); $act_out = implode('', $actions); //.'<br />'.$unignorecheckbox.$ignorecheckbox.'<br />'.$resetcheckbox; echo '<td ' . $attributes . '>' . $act_out . '</td>'; break; } } echo '</tr>'; } }
public function cred_field_shortcodes($atts) { extract(shortcode_atts(array('post' => '', 'field' => '', 'value' => null, 'placeholder' => null, 'escape' => 'false', 'readonly' => 'false', 'taxonomy' => null, 'single_select' => null, 'type' => null, 'display' => null, 'max_width' => null, 'max_height' => null, 'max_results' => null, 'order' => null, 'ordering' => null, 'required' => 'false', 'no_parent_text' => __('No Parent', 'wp-cred'), 'select_text' => __('-- Please Select --', 'wp-cred'), 'validate_text' => $this->getLocalisedMessage('field_required')), $atts)); // make boolean $escape = false; //(bool)(strtoupper($escape)==='TRUE'); // make boolean $readonly = (bool) (strtoupper($readonly) === 'TRUE'); if (!$taxonomy) { if (in_array($field, array_keys($this->_fields['post_fields']))) { if ($post != $this->_post_type) { return ''; } $field = $this->_fields['post_fields'][$field]; $name = $name_orig = $field['slug']; if (isset($field['plugin_type_prefix'])) { $name = $field['plugin_type_prefix'] . $name; } if ($field['type'] == 'image' || $field['type'] == 'file') { $ids = $this->translate_field($name, $field, array('preset_value' => $value, 'is_tax' => false, 'max_width' => $max_width, 'max_height' => $max_height)); } else { $ids = $this->translate_field($name, $field, array('preset_value' => $value, 'value_escape' => $escape, 'make_readonly' => $readonly, 'placeholder' => $placeholder)); } // check which fields are actually used in form $this->_form_fields[$name_orig] = $ids; $this->_form_fields_qualia[$name_orig] = array('type' => $field['type'], 'repetitive' => isset($field['data']['repetitive']) && $field['data']['repetitive'], 'plugin_type' => isset($field['plugin_type']) ? $field['plugin_type'] : '', 'name' => $name); $out = ''; foreach ($ids as $id) { $out .= "[render-cred-field post='{$post}' field='{$id}']"; } return $out; } elseif (in_array($field, array_keys($this->_fields['parents']))) { $name = $name_orig = $field; $field = $this->_fields['parents'][$field]; $potential_parents = CRED_Loader::get('MODEL/Fields')->getPotentialParents($field['data']['post_type'], $this->_post_id, $max_results, $order, $ordering); $field['data']['options'] = array(); $default_option = ''; // enable setting parent form url param if (array_key_exists('parent_' . $field['data']['post_type'] . '_id', $_GET)) { $default_option = $_GET['parent_' . $field['data']['post_type'] . '_id']; } $required = (bool) (strtoupper($required) === 'TRUE'); if (!$required) { $field['data']['options']['-1'] = array('title' => $no_parent_text, 'value' => '-1', 'display_value' => '-1'); } else { $field['data']['options']['-1'] = array('title' => $select_text, 'value' => '', 'display_value' => '', 'dummy' => true); $field['data']['validate'] = array('required' => array('message' => $validate_text, 'active' => 1)); } foreach ($potential_parents as $ii => $option) { $option_id = (string) $option->ID; $field['data']['options'][$option_id] = array('title' => $option->post_title, 'value' => $option_id, 'display_value' => $option_id); } $field['data']['options']['default'] = $default_option; //print_r($field['data']); $ids = $this->translate_field($name, $field, array('preset_value' => $value)); // check which fields are actually used in form $this->_form_fields[$name_orig] = $ids; $this->_form_fields_qualia[$name_orig] = array('type' => $field['type'], 'repetitive' => isset($field['data']['repetitive']) && $field['data']['repetitive'], 'plugin_type' => isset($field['plugin_type']) ? $field['plugin_type'] : '', 'name' => $name); $out = ''; foreach ($ids as $id) { $out .= "[render-cred-field field='{$id}']"; } return $out; } elseif (in_array($field, array_keys($this->_fields['form_fields']))) { $name = $name_orig = $field; $field = $this->_fields['form_fields'][$field]; $ids = $this->translate_field($name, $field, array('preset_value' => $value)); // check which fields are actually used in form $this->_form_fields[$name_orig] = $ids; $this->_form_fields_qualia[$name_orig] = array('type' => $field['type'], 'repetitive' => isset($field['data']['repetitive']) && $field['data']['repetitive'], 'plugin_type' => isset($field['plugin_type']) ? $field['plugin_type'] : '', 'name' => $name); $out = ''; foreach ($ids as $id) { $out .= "[render-cred-field field='{$id}']"; } return $out; } elseif (in_array($field, array_keys($this->_fields['extra_fields']))) { $field = $this->_fields['extra_fields'][$field]; $name = $name_orig = $field['slug']; $ids = $this->translate_field($name, $field, array('preset_value' => $value)); // check which fields are actually used in form $this->_form_fields[$name_orig] = $ids; $this->_form_fields_qualia[$name_orig] = array('type' => $field['type'], 'repetitive' => isset($field['data']['repetitive']) && $field['data']['repetitive'], 'plugin_type' => isset($field['plugin_type']) ? $field['plugin_type'] : '', 'name' => $name); $out = ''; foreach ($ids as $id) { $out .= "[render-cred-field field='{$id}']"; } return $out; } elseif (in_array($field, array_keys($this->_fields['taxonomies']))) { $field = $this->_fields['taxonomies'][$field]; $name = $name_orig = $field['name']; $single_select = $single_select === 'true'; $ids = $this->translate_field($name, $field, array('preset_value' => $display, 'is_tax' => true, 'single_select' => $single_select)); // check which fields are actually used in form $this->_form_fields[$name_orig] = $ids; $this->_form_fields_qualia[$name_orig] = array('type' => $field['type'], 'repetitive' => isset($field['data']['repetitive']) && $field['data']['repetitive'], 'plugin_type' => isset($field['plugin_type']) ? $field['plugin_type'] : '', 'name' => $name); $out = ''; foreach ($ids as $id) { $out .= "[render-cred-field field='{$id}']"; } return $out; } } else { if (in_array($taxonomy, array_keys($this->_fields['taxonomies'])) && in_array($type, array('show_popular', 'add_new'))) { if ($type == 'show_popular' && !$this->_fields['taxonomies'][$taxonomy]['hierarchical'] || $type == 'add_new' && $this->_fields['taxonomies'][$taxonomy]['hierarchical']) { $field = array('taxonomy' => $this->_fields['taxonomies'][$taxonomy], 'type' => $type, 'master_taxonomy' => $taxonomy); $name = $name_orig = $taxonomy . '_' . $type; $ids = $this->translate_field($name, $field, array('preset_value' => $value, 'is_tax' => true)); // check which fields are actually used in form //$this->_form_fields[$name_orig]=$ids; $out = ''; foreach ($ids as $id) { $out .= "[render-cred-field field='{$id}']"; } return $out; } } } return ''; }
public function getFields($autogenerate = array('username' => true, 'nickname' => true, 'password' => true), $role = "", $add_default = true, $localized_message_callback = null) { // ALL FIELDS $fields_all = array(); // fetch custom fields for post type even if not created by types or default $groups = array(); $groups_conditions = array(); $fields = $this->getCustomFields($role); //######################################################################################### $user_fields = array(); if ($add_default) { if ($localized_message_callback) { $message = call_user_func($localized_message_callback, 'field_required'); } else { $message = __('This field is required', 'wp-cred'); } $expression_user = isset($autogenerate['username']) && ((bool) $autogenerate['username'] !== true || $autogenerate['username'] === 'false'); $expression_nick = isset($autogenerate['nickname']) && ((bool) $autogenerate['nickname'] !== true || $autogenerate['nickname'] === 'false'); $expression_pawwsd = isset($autogenerate['password']) && ((bool) $autogenerate['password'] !== true || $autogenerate['password'] === 'false'); if ($expression_user === true) { $user_fields['user_login'] = array('post_type' => 'user', 'post_labels' => __('Username', 'wp-cred'), 'id' => 'user_login', 'wp_default' => true, 'slug' => 'user_login', 'type' => 'textfield', 'name' => __('Username', 'wp-cred'), 'description' => 'Username', 'data' => array('repetitive' => 0, 'validate' => array('required' => array('active' => 1, 'value' => true, 'message' => $message)), 'conditional_display' => array(), 'disabled_by_type' => 0)); } if ($expression_nick === true) { $user_fields['nickname'] = array('post_type' => 'user', 'post_labels' => __('Nickname', 'wp-cred'), 'id' => 'nickname', 'wp_default' => true, 'slug' => 'nickname', 'type' => 'textfield', 'name' => __('Nickname', 'wp-cred'), 'description' => 'Nickname', 'data' => array('repetitive' => 0, 'validate' => array('required' => array('active' => 1, 'value' => true, 'message' => __('This field is required', 'wp-cred'))), 'conditional_display' => array(), 'disabled_by_type' => 0)); } if ($expression_pawwsd === true) { $user_fields['user_pass'] = array('post_type' => 'user', 'post_labels' => __('Password', 'wp-cred'), 'id' => 'user_pass', 'wp_default' => true, 'slug' => 'user_pass', 'type' => 'password', 'name' => __('Password', 'wp-cred'), 'description' => 'Password', 'data' => array('repetitive' => 0, 'validate' => array('required' => array('active' => 1, 'value' => true, 'message' => $message)), 'conditional_display' => array(), 'disabled_by_type' => 0)); $user_fields['user_pass2'] = array('post_type' => 'user', 'post_labels' => __('Repeat Password', 'wp-cred'), 'id' => 'user_pass2', 'wp_default' => true, 'slug' => 'user_pass2', 'type' => 'password', 'name' => __('Repeat Password', 'wp-cred'), 'description' => 'Repeat Password', 'data' => array('repetitive' => 0, 'validate' => array('required' => array('active' => 1, 'value' => true, 'message' => $message)), 'conditional_display' => array(), 'disabled_by_type' => 0)); } $user_fields['user_email'] = array('post_type' => 'user', 'post_labels' => __('Email', 'wp-cred'), 'id' => 'user_email', 'wp_default' => true, 'slug' => 'user_email', 'type' => 'email', 'name' => __('Email', 'wp-cred'), 'description' => 'Email', 'data' => array('repetitive' => 0, 'validate' => array('email' => array('active' => 1, 'message' => __('Please enter a valid email address', 'wp-cred')), 'required' => array('active' => 1, 'value' => true, 'message' => __('This field is required', 'wp-cred'))), 'conditional_display' => array(), 'disabled_by_type' => 0)); $user_fields['user_url'] = array('post_type' => 'user', 'post_labels' => __('Website', 'wp-cred'), 'id' => 'user_url', 'wp_default' => true, 'slug' => 'user_url', 'type' => 'textfield', 'name' => __('Website', 'wp-cred'), 'description' => 'Url', 'data' => array()); } $parents = array(); // EXTRA FIELDS $extra_fields = array(); $extra_fields['recaptcha'] = array('id' => 're_captcha', 'slug' => 'recaptcha', 'name' => esc_js(__('reCaptcha', 'wp-cred')), 'type' => 'recaptcha', 'cred_builtin' => true, 'description' => esc_js(__('Adds Image Captcha to your forms to prevent automatic submision by bots', 'wp-cred'))); $setts = CRED_Loader::get('MODEL/Settings')->getSettings(); if (!isset($setts['recaptcha']['public_key']) || !isset($setts['recaptcha']['private_key']) || empty($setts['recaptcha']['public_key']) || empty($setts['recaptcha']['private_key'])) { // no keys set for API $extra_fields['recaptcha']['disabled'] = true; $extra_fields['recaptcha']['disabled_reason'] = sprintf('<a href="%s" target="_blank">%s</a> %s', CRED_CRED::$settingsPage, __('Get and Enter your API keys', 'wp-cred'), esc_js(__('to use the Captcha field.', 'wp-cred'))); } /* else $extra_fields['recaptcha']['disabled']=false; */ // featured image field $extra_fields['_featured_image'] = array('id' => '_featured_image', 'slug' => '_featured_image', 'name' => esc_js(__('Featured Image', 'wp-cred')), 'type' => 'image', 'cred_builtin' => true, 'description' => 'Featured Image'); $extra_fields['_featured_image']['supports'] = false; // BASIC FORM FIELDS $form_fields = array(); $form_fields['form'] = array('id' => 'creduserform', 'name' => esc_js(__('User Form Container', 'wp-cred')), 'slug' => 'creduserform', 'type' => 'creduserform', 'cred_builtin' => true, 'description' => esc_js(__('User Form (required)', 'wp-cred', 'wp-cred'))); //$form_fields['form_end']=array('id'=>'form_end','name'=>'Form End','slug'=>'form_end','type'=>'form_end','cred_builtin'=>true,'description'=>__('End of Form')); $form_fields['form_submit'] = array('value' => __('Submit', 'wp-cred'), 'id' => 'form_submit', 'name' => esc_js(__('Form Submit', 'wp-cred')), 'slug' => 'form_submit', 'type' => 'form_submit', 'cred_builtin' => true, 'description' => esc_js(__('Form Submit Button', 'wp-cred'))); $form_fields['form_messages'] = array('value' => '', 'id' => 'form_messages', 'name' => esc_js(__('Form Messages', 'wp-cred')), 'slug' => 'form_messages', 'type' => 'form_messages', 'cred_builtin' => true, 'description' => esc_js(__('Form Messages Container', 'wp-cred'))); $form_fields['user_login'] = array('post_type' => 'user', 'post_labels' => __('Username', 'wp-cred'), 'id' => 'user_login', 'wp_default' => true, 'slug' => 'user_login', 'type' => 'textfield', 'name' => __('Username', 'wp-cred'), 'description' => 'Username', 'data' => array('repetitive' => 0, 'validate' => array('required' => array('active' => 1, 'value' => true, 'message' => $message)), 'conditional_display' => array(), 'disabled_by_type' => 0)); //nickname is required $form_fields['nickname'] = array('post_type' => 'user', 'post_labels' => __('Nickname', 'wp-cred'), 'id' => 'nickname', 'wp_default' => true, 'slug' => 'nickname', 'type' => 'textfield', 'name' => __('Nickname', 'wp-cred'), 'description' => 'Nickname', 'data' => array()); $form_fields['user_pass'] = array('post_type' => 'user', 'post_labels' => __('Password', 'wp-cred'), 'id' => 'user_pass', 'wp_default' => true, 'slug' => 'user_pass', 'type' => 'password', 'name' => __('Password', 'wp-cred'), 'description' => 'Password', 'data' => array('repetitive' => 0, 'validate' => array('required' => array('active' => 1, 'value' => true, 'message' => $message)), 'conditional_display' => array(), 'disabled_by_type' => 0)); $form_fields['user_pass2'] = array('post_type' => 'user', 'post_labels' => __('Repeat Password', 'wp-cred'), 'id' => 'user_pass2', 'wp_default' => true, 'slug' => 'user_pass2', 'type' => 'password', 'name' => __('Repeat Password', 'wp-cred'), 'description' => 'Repeat Password', 'data' => array('repetitive' => 0, 'validate' => array('required' => array('active' => 1, 'value' => true, 'message' => $message)), 'conditional_display' => array(), 'disabled_by_type' => 0)); // TAXONOMIES FIELDS $taxonomies = array(); $form_fields = array_merge($user_fields, $form_fields); $fields_all['groups'] = $groups; $fields_all['groups_conditions'] = $groups_conditions; $fields_all['form_fields'] = $form_fields; $fields_all['user_fields'] = $user_fields; $fields_all['custom_fields'] = $fields; $fields_all['taxonomies'] = $taxonomies; $fields_all['parents'] = $parents; $fields_all['extra_fields'] = $extra_fields; $fields_all['form_fields_count'] = count($form_fields); $fields_all['user_fields_count'] = count($user_fields); $fields_all['custom_fields_count'] = count($fields); $fields_all['taxonomies_count'] = count($taxonomies); $fields_all['parents_count'] = count($parents); $fields_all['extra_fields_count'] = count($extra_fields); return $fields_all; }
if (!current_user_can(CRED_CAPABILITY)) { die('Access Denied'); } // include needed files $wp_list_table = CRED_Loader::get('TABLE/UserForms'); $doaction = $wp_list_table->current_action(); $url = CRED_CRED::getNewUserFormLink(); $form_id = ''; $form_name = ''; $form_type = ''; $post_type = ''; $form_content = ''; $fields = ''; // Handle Table Action if ($doaction) { $forms_model = CRED_Loader::get('MODEL/UserForms'); switch ($doaction) { case 'delete-selected': if (isset($_REQUEST['checked']) && is_array($_REQUEST['checked'])) { if (check_admin_referer('cred-bulk-selected-action', 'cred-bulk-selected-field')) { foreach ($_REQUEST['checked'] as $form_id) { $forms_model->deleteForm((int) $form_id); } } } break; case 'clone-selected': if (isset($_REQUEST['checked']) && is_array($_REQUEST['checked'])) { if (check_admin_referer('cred-bulk-selected-action', 'cred-bulk-selected-field')) { foreach ($_REQUEST['checked'] as $form_id) { $forms_model->cloneForm((int) $form_id);
public function deletePost($get, $post) { global $current_user; /* $return_codes=array( '101'=>'Success', '202'=>'Failure', '404'=>'No post' '505'=>'No permision', ); */ if (!array_key_exists('_wpnonce', $get) || !array_key_exists('_cred_link_id', $get) || !array_key_exists('cred_action', $get) || !wp_verify_nonce($get['_wpnonce'], $get['_cred_link_id'] . '_' . $get['cred_action'])) { die('Security check'); } $jsfuncs = array(); $redirect_url = false; if (!isset($get['cred_post_id'])) { //echo json_encode(false); //$jsfuncs['alert']=array("'".esc_js(__('No post defined','wp-cred'))."'"); $jsfuncs['parent._cred_cred_delete_post_handler'] = array('false', '""', '""', '404'); echo $this->renderJsFunction($jsfuncs); die; } $post_id = intval($get['cred_post_id']); $post = get_post($post_id); if ($post) { if (!current_user_can('delete_own_posts_with_cred') && $current_user->ID == $post->post_author) { $jsfuncs['parent._cred_cred_delete_post_handler'] = array('false', '""', '""', '505'); echo $this->renderJsFunction($jsfuncs); die; //die('<strong>'.__('Do not have permission (own)','wp-cred').'</strong>'); } if (!current_user_can('delete_other_posts_with_cred') && $current_user->ID != $post->post_author) { $jsfuncs['parent._cred_cred_delete_post_handler'] = array('false', '""', '""', '505'); echo $this->renderJsFunction($jsfuncs); die; //die('<strong>'.__('Do not have permission (other)','wp-cred').'</strong>'); } $action = apply_filters('cred_delete_action', $get['cred_action'], $post_id); $result = false; $redirect_url = false; if ($action && in_array($action, array('delete', 'trash'))) { if (array_key_exists('_cred_url', $get) && !empty($get['_cred_url'])) { $redirect_url = urldecode($get['_cred_url']); } if ($redirect_url) { $redirect_url = apply_filters('cred_redirect_after_delete_action', $redirect_url, $post_id); } if ($redirect_url) { $redirect_url = '"' . $redirect_url . '"'; } else { $redirect_url = 'false'; } $fm = CRED_Loader::get('MODEL/Forms'); if ($get['cred_action'] == 'delete') { $result = $fm->deletePost($post_id, true); } elseif ($get['cred_action'] == 'trash') { $result = $fm->deletePost($post_id, false); } else { $jsfuncs['parent._cred_cred_delete_post_handler'] = array('false', '""', '""', '505'); echo $this->renderJsFunction($jsfuncs); die; } } //echo json_encode($result); // //Added redirect to page_id //https://icanlocalize.basecamphq.com/projects/11629195-toolset-peripheral-work/todo_items/195364093/comments#307203773 if (isset($get['redirect']) && $get['redirect'] != 0 && is_numeric($get['redirect'])) { $p = get_post($get['redirect']); if ($p) { $redirect_url = '"' . get_permalink($p->ID) . '"'; } } //############################################### if ($result) { if (array_key_exists('_cred_link_id', $get)) { $jsfuncs['parent._cred_cred_delete_post_handler'] = array('false', '"' . urldecode($get['_cred_link_id']) . '"', $redirect_url, '101'); } else { $jsfuncs['parent._cred_cred_delete_post_handler'] = array('false', '""', $redirect_url, '101'); } //$jsfuncs['alert']=array("'".esc_js(__('Post deleted','wp-cred'))."'"); } else { if (array_key_exists('_cred_link_id', $get)) { $jsfuncs['parent._cred_cred_delete_post_handler'] = array('false', '"' . urldecode($get['_cred_link_id']) . '"', $redirect_url, '202'); } else { $jsfuncs['parent._cred_cred_delete_post_handler'] = array('false', '""', $redirect_url, '202'); } //$jsfuncs['alert']=array("'".esc_js(__('Post delete failed','wp-cred'))."'"); } } echo $this->renderJsFunction($jsfuncs); die; }
private function CRED_user_save($user_role, $user_id = null) { // reference to the form submission method global ${'_' . StaticClass::METHOD}; $method =& ${'_' . StaticClass::METHOD}; $formHelper = $this->_formHelper; $zebraForm = $this->_zebraForm; $form =& $this->_formData; $form_id = $form->getForm()->ID; $_fields = $form->getFields(); $form_type = $_fields['form_settings']->form['type']; $out_ =& $this->out_; $post_type = $this->_postType; $thisform = array('id' => $form_id, 'post_type' => $post_type, 'form_type' => $form_type, 'container_id' => StaticClass::$_cred_container_id); // do custom actions before post save do_action('cred_before_save_data_' . $form_id, $thisform); do_action('cred_before_save_data', $thisform); // track form data for notification mail $trackNotification = false; if (isset($_fields['notification']->enable) && $_fields['notification']->enable && !empty($_fields['notification']->notifications)) { $trackNotification = true; } // save result (on success this is post ID) $new_user_id = false; // Check if we are posting nothing, in which case we are dealing with uploads greater than the size limit if (empty($method) && isset($_GET['_tt'])) { return $new_user_id; } // default post fields $user = $formHelper->CRED_extractUserFields($user_id, $user_role, $trackNotification); $all_ok = false; if ($user) { $all_ok = true; } // custom fields, taxonomies and file uploads; also, catch error_files for sizes lower than the server maximum but higher than the form/site maximum list($fields, $fieldsInfo, $files, $removed_fields, $error_files) = $formHelper->CRED_extractCustomUserFields($user_id, $trackNotification); // upload attachments $extra_files = array(); if (count($error_files) > 0) { $all_ok = false; } else { $all_ok = $formHelper->CRED_uploadAttachments($user->ID, $fields, $files, $extra_files, $trackNotification); } if ($all_ok) { add_filter('terms_clauses', array(&$this, 'terms_clauses')); add_filter('wpml_save_post_lang', array(&$this, 'wpml_save_post_lang')); //add_filter('wpml_save_post_trid_value',array(&$this,'wpml_save_post_trid_value'),10,2); //https://onthegosystems.myjetbrains.com/youtrack/issue/cred-131# $fields = StaticClass::cf_sanitize_values_on_save($fields); // save everything $model = CRED_Loader::get('MODEL/UserForms'); if ($form_type == 'edit' && isset($user_id)) { $new_user_id = $model->updateUser($user, $fields, $fieldsInfo, $removed_fields); } else { $new_user_id = $model->addUser($user, $fields, $fieldsInfo, $removed_fields); } //cred_log(array('fields'=>$fields, 'info'=>$fieldsInfo, 'removed'=>$removed_fields)); if (is_int($new_user_id) && $new_user_id > 0) { $formHelper->attachUploads($new_user_id, $fields, $files, $extra_files); // save notification data (pre-formatted) if ($trackNotification) { $out_['notification_data'] = $formHelper->trackData(null, true); } // for WooCommerce products only (update prices in products) if (class_exists('Woocommerce') && 'product' == get_post_type($new_user_id)) { if (isset($fields['_regular_price']) && !isset($fields['_price'])) { $regular_price = $fields['_regular_price']; update_post_meta($new_user_id, '_price', $regular_price); $sale_price = get_post_meta($new_user_id, '_sale_price', true); // Update price if on sale if ($sale_price != '') { $sale_price_dates_from = get_post_meta($new_user_id, '_sale_price_dates_from', true); $sale_price_dates_to = get_post_meta($new_user_id, '_sale_price_dates_to', true); if ($sale_price_dates_to == '' && $sale_price_dates_to == '') { update_post_meta($new_user_id, '_price', $sale_price); } else { if ($sale_price_dates_from && strtotime($sale_price_dates_from) < strtotime('NOW', current_time('timestamp'))) { update_post_meta($new_user_id, '_price', $sale_price); } } if ($sale_price_dates_to && strtotime($sale_price_dates_to) < strtotime('NOW', current_time('timestamp'))) { update_post_meta($new_user_id, '_price', $regular_price); } } } else { if (isset($fields['_price']) && !isset($fields['_regular_price'])) { update_post_meta($new_user_id, '_regular_price', $fields['_price']); } } } // do custom actions on successful post save /* EMERSON: https://icanlocalize.basecamphq.com/projects/7393061-toolset/todo_items/185624661/comments /*Add cred_save_data_form_ hook on CRED 1.3 */ $form_slug = $form->getForm()->post_name; do_action('cred_save_data_form_' . $form_slug, $new_user_id, $thisform); do_action('cred_save_data_' . $form_id, $new_user_id, $thisform); do_action('cred_save_data', $new_user_id, $thisform); } } else { $WP_Error = new WP_Error(); $WP_Error->add('upload', 'Error some required upload field failed.'); $new_post_id = $WP_Error; } // return saved post_id as result return $new_user_id; }