<?php list($instagram_client_id, $instagram_client_secret, $instagram_redirect_uri) = $this->get_instagram_settings(); $logout_requested = false; if (isset($_POST['instagram-logout']) && check_admin_referer('ei_user_logout_nonce', 'ei_user_logout_nonce')) { $this->set_access_token(''); update_option('ei_access_token', ''); $logout_requested = true; } $config = $this->get_instagram_config(); $cache_dir = $this->get_cache_directory(); $instagram = new MC_Instagram_Connector($config); $access_token = $this->get_access_token(); $instagram_exception = null; if (!$logout_requested && empty($access_token)) { if (isset($_GET['code'])) { try { $access_token = $instagram->getAccessToken(); if (!empty($access_token)) { $this->set_access_token($access_token); } $instagram_user = $instagram->getCurrentUser(); if (!empty($instagram_user)) { $this->set_instagram_user_data($instagram_user->username, $instagram_user->id); } } catch (Exception $ex) { $instagram_exception = $ex; } } } ?>
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; }