/** * Create CF View interface. * * @since 0.0.1 * * @param int $form_id ID of form to view * @param array $fields Optional. An array of fields to show. If empty, the default, all fields of form are shown. * @param null|int $editor_id Optional. ID of a page with the form on it, used for editing. If null, the default, no edit links are shown. * * @return string|void */ function cf_view_three($form_id, $fields = array(), $editor_id = null) { if (!is_array(Caldera_Forms::get_form($form_id))) { return; } require_once CFCORE_PATH . 'classes/admin.php'; $data = Caldera_Forms_Admin::get_entries($form_id); if (is_array($data) && isset($data['entries']) && !empty($data)) { $entries = $data['entries']; if (empty($fields)) { $fields = $data['fields']; } $_fields = $fields; $fields = array(); $form = Caldera_Forms::get_form($form_id); $index = array_merge(wp_list_pluck($form['fields'], 'ID'), wp_list_pluck($form['fields'], 'slug')); //Josh - this array flip seems silly, but doing the array_merge the other way didn't work, trust me -Josh $index = array_flip($index); foreach ($_fields as $slug => $label) { if (isset($index[$slug])) { $id = $index[$slug]; $fields[] = array('label' => $label, 'slug' => $slug, 'ID' => $id); } } include_once dirname(__FILE__) . '/classes/table_three.php'; wp_enqueue_script('jquery'); wp_enqueue_script('footable-core-3'); wp_enqueue_style('footable-core-3'); $foos = cf_view_componets(); foreach ($foos as $foo) { wp_enqueue_script('footable-' . $foo); wp_enqueue_style('footable-' . $foo); } wp_enqueue_script('cf-view'); $class = new \calderawp\view\table_three($fields, $entries, $form_id, $editor_id); $js = $class->get_js_config(); wp_localize_script('cf-view', 'CF_VIEW_FOO_TABLE_OPTIONS', $js); return $class->get_html(); } }
/** * Add an error notice in admin. * * @since 1.3 * * @param string $notice The message. */ protected function add_notice($notice) { if (class_exists('Caldera_Forms_Admin')) { Caldera_Forms_Admin::add_admin_notice($notice); } $this->notices[] = $notice; }
/** * Return an instance of this class. * * * @return object A single instance of this class. */ public static function get_instance() { // If the single instance hasn't been set, set it now. if (null == self::$instance) { self::$instance = new self(); } return self::$instance; }
/** * Create a new form * * @since 1.3.4 * * @param array $newform Data for new form * * @return array|mixed|void */ public static function create_form($newform) { require_once CFCORE_PATH . 'classes/admin.php'; // get form templates (PROBABLY NEED TO MOVE METHOD INTO THIS CLASS) $form_templates = Caldera_Forms_Admin::internal_form_templates(); if (!empty($newform['clone'])) { $clone = $newform['clone']; } // load template if any if (!empty($newform['template'])) { if (isset($form_templates[$newform['template']]) && !empty($form_templates[$newform['template']]['template'])) { $form_template = $form_templates[$newform['template']]['template']; } } $id = uniqid('CF'); $newform = array("ID" => $id, "name" => $newform['name'], "description" => $newform['description'], "success" => __('Form has been successfully submitted. Thank you.', 'caldera-forms'), "form_ajax" => 1, "hide_form" => 1, "check_honey" => 1, "db_support" => 1, 'mailer' => array('on_insert' => 1)); // is template? if (!empty($form_template) && is_array($form_template)) { $newform = array_merge($form_template, $newform); } /** * Filter newly created form before saving * * @since unknown * * @param array $newform New form config */ $newform = apply_filters('caldera_forms_create_form', $newform); self::update_registry($id); if (!empty($clone)) { $clone_form = self::get_form($clone); if (!empty($clone_form['ID']) && $clone == $clone_form['ID']) { $newform = array_merge($clone_form, $newform); } } // add form to db $added = add_option($id, $newform, false); if (!$added) { return false; } /** * Runs after form is created * * @since unkown * * @param array $newform New form config */ do_action('caldera_forms_create_form', $newform); return $newform; }