public function generate_content_ajax() { check_ajax_referer('easy-instagram-content-nonce', 'easy_instagram_content_security'); $error_reporting_status = error_reporting(); // Disable error reporting. Protect against AJAX call completely failing. error_reporting(0); $tag = $_GET['tag']; $user_id = $_GET['user_id']; $limit = $_GET['limit']; $data = array('status' => 'ERROR'); if (empty($tag) && empty($user_id)) { echo json_encode($data); error_reporting($error_reporting_status); exit; } $access_token = $this->get_access_token(); if (empty($access_token)) { $data['error'] = __('Invalid access token. Please check your Instagram settings', 'Easy_Instagram'); echo json_encode($data); error_reporting($error_reporting_status); exit; } $config = $this->get_instagram_config(); $instagram = new MC_Instagram_Connector($config); $instagram->setAccessToken($access_token); //Select which Instagram endpoint to use if (!empty($user_id)) { $endpoint_id = $user_id; $endpoint_type = 'user'; } else { if (!empty($tag)) { $endpoint_id = $tag; $endpoint_type = 'tag'; } } $error = ''; $instagram_elements = $this->_get_data_for_user_or_tag($instagram, $endpoint_id, $limit, $endpoint_type, $error); if (is_null($instagram_elements)) { $data['error'] = $error; } else { try { $rendered = $this->_get_render_elements($instagram_elements, $_GET); $data['status'] = 'SUCCESS'; $data['output'] = $rendered; } catch (Exception $ex) { $data['error'] = $ex->getMessage(); } } echo json_encode($data); error_reporting($error_reporting_status); exit; }