/** * 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.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; } }