/** * Formats array for drop down in terms of Visual Composer. * * @since 0.3.0 * @access private * @param string * * @return array */ private function get_values($param) { $return = array(); $items = array(); $defined_options = $this->helper->get_option_group(); if ($this->client->has_valid_api_key() && $defined_options['list_id']) { if ('list' == $param) { $group = new Api\Cleverreach_Group_Adapter($this->client); $items = $this->helper->parse_list($group->get_list(), 'list_id'); } elseif ('form' == $param) { $form = new Api\Cleverreach_Form_Adapter($this->client); $items = $this->helper->parse_list($form->get_list($defined_options['list_id']), 'form_id', true); } // Prepare drop down lists in terms of Visual Composer. foreach ($items as $item) { $return[$item['name']] = $item['id']; } } return $return; }
/** * Save data and return API response as JSON. * * @since 0.2.0 * * @return array Return JSON `$result` with API response. */ public function admin_ajax_controller_interaction() { check_ajax_referer($this->plugin_name . '_admin_ajax_interaction_nonce', 'nonce'); if ($_POST['cr_admin_form'] && current_user_can('manage_options')) { // Requires $_POST from admin user. // Create or update database entry. update_option('cleverreach_extension', $this->sanitize($_POST['cr_admin_form'])); $result = array(); $client = new Api\Cleverreach(); $helper = new Core\Cre_Helper(); // Add status and list options to result. if ($client->has_valid_api_key()) { $result['status'] = 'success'; $group = new Api\Cleverreach_Group_Adapter($client); $result['list_options'] = $helper->parse_list($group->get_list(), 'list_id'); } else { $result['status'] = 'error'; } // Add form options to result. if ($client->has_valid_api_key() && $helper->has_option('list_id')) { $form = new Api\Cleverreach_Form_Adapter($client); $result['form_options'] = $helper->parse_list($form->get_list($helper->get_option('list_id')), 'form_id'); } // Add shortcode value to result. if ($client->has_valid_api_key() && $helper->has_option('form_id')) { $result['shortcode_id'] = $helper->get_option('form_id'); } // Finally return JSON result. $result = json_encode($result); echo $result; die; } }
<?php /** * Visual Composer Integration * Hooks into `cleverreach_extension` shortcode * * @since 0.2.0 * * Optimized for Visual Composer v4.6.2 * @link http://vc.wpbakery.com/ * @docs https://wpbakery.atlassian.net/wiki/display/VC/Visual+Composer+Pagebuilder+for+WordPress */ use CleverreachExtension\Core; use CleverreachExtension\Core\Api; $values = array(); $client = new Api\Cleverreach(); $helper = new Core\Cre_Helper(); if ($client->has_valid_api_key() && $helper->has_option('list_id')) { $form = new Api\Cleverreach_Form_Adapter($client); $forms = $helper->parse_list($form->get_list($helper->get_option('list_id')), 'form_id'); // Prepare dropdown list in terms of Visual Composer. foreach ($forms as $form) { $values[$form['name']] = $form['id']; } // Append `Custom` at the very end of the list. $values[esc_html__('Custom', 'cleverreachextension')] = 'custom'; } vc_map(array('name' => esc_html__('CleverReach Form', 'cleverreachextension'), 'base' => 'cleverreach_extension', 'class' => 'cleverreach_extension', 'icon' => '', 'category' => esc_html__('CleverReach', 'cleverreachextension'), 'admin_enqueue_js' => array(), 'admin_enqueue_css' => array(), 'params' => array(array('type' => 'dropdown', 'holder' => 'div', 'class' => 'cre_form_id', 'heading' => esc_html__('Form', 'cleverreachextension'), 'param_name' => 'form_id', 'value' => $values, 'std' => $helper->get_option('form_id'), 'description' => esc_html__('Check the wiki on how to customize your form.', 'cleverreachextension')))));
/** * Save data and return API response as JSON. * * @since 0.3.0 * * @wp-hook wp_ajax_cre_admin_ajax_controller_interaction * @return array Return JSON `$result` with API response. */ public function admin_ajax_controller_interaction() { check_ajax_referer($this->plugin_name . '_admin_ajax_interaction_nonce', 'nonce'); if ($_POST['cr_admin_form'] && current_user_can('manage_options')) { // Requires $_POST from admin user. // Create or update database entry. update_option('cleverreach_extension', $this->sanitize($_POST['cr_admin_form'])); // Get plugin option group. $helper = new Core\Cre_Helper(); $defined_options = $helper->get_option_group(); // Prepare API with adapters. $client = new Api\Cleverreach(); $group = new Api\Cleverreach_Group_Adapter($client); $form = new Api\Cleverreach_Form_Adapter($client); // Cleanup transients. $client->delete_transients(); // Check API key. $has_api_key = $client->has_valid_api_key(); // Build array with data and status. $result = array('api' => array('status' => $has_api_key ? true : false), 'list' => array('status' => $has_api_key && $defined_options['list_id'] ? true : false, 'options' => $has_api_key ? $helper->parse_list($group->get_list(), 'list_id') : false), 'form' => array('status' => $has_api_key && $defined_options['form_id'] ? true : false, 'options' => $has_api_key ? $helper->parse_list($form->get_list($defined_options['list_id']), 'form_id', true) : false), 'source' => array('status' => $defined_options['source'] ? true : false), 'ajax' => array('status' => $defined_options['ajax'] ? true : false)); // Return result as JSON. $result = json_encode($result); echo $result; die; } }