/** * Get theme update information from the PMPro server. * * @since 2.0 */ function memberlite_getUpdateInfo() { //check if forcing a pull from the server $update_info = get_option("memberlite_update_info", false); $update_info_timestamp = get_option("memberlite_update_info_timestamp", 0); //if no update_infos locally, we need to hit the server if (empty($update_info) || !empty($_REQUEST['force-check']) || current_time('timestamp') > $update_info_timestamp + 86400) { /** * Filter to change the timeout for this wp_remote_get() request. * * @since 2.0.1 * * @param int $timeout The number of seconds before the request times out */ $timeout = apply_filters("memberlite_get_update_info_timeout", 5); //get em $remote_info = wp_remote_get(PMPRO_LICENSE_SERVER . "/themes/memberlite", $timeout); //test response if (is_wp_error($remote_info) || empty($remote_info['response']) || $remote_info['response']['code'] != '200') { //error pmpro_setMessage("Could not connect to the PMPro License Server to get update information. Try again later.", "error"); } else { //update update_infos in cache $update_info = json_decode(wp_remote_retrieve_body($remote_info), true); delete_option('memberlite_update_info'); add_option("memberlite_update_info", $update_info, NULL, 'no'); } //save timestamp of last update delete_option('memberlite_update_info_timestamp'); add_option("memberlite_update_info_timestamp", current_time('timestamp'), NULL, 'no'); } return $update_info; }
public static function fetch_url($url) { $use_file_get_contents = get_option('ecwid_fetch_url_use_file_get_contents', false); if ($use_file_get_contents == 'Y') { $result = @file_get_contents($url); } else { if (get_option('ecwid_http_use_stream', false)) { self::$http_use_streams = true; } $result = wp_remote_get($url, array('timeout' => get_option('ecwid_remote_get_timeout', 5))); if (get_option('ecwid_http_use_stream', false)) { self::$http_use_streams = false; } if (!is_array($result)) { $result = @file_get_contents($url); if (!empty($result)) { update_option('ecwid_fetch_url_use_file_get_contents', true); } } } $return = array('code' => '', 'data' => '', 'message' => ''); if (is_array($result)) { $return = array('code' => $result['response']['code'], 'data' => $result['body']); } elseif (is_object($result)) { $return = array('code' => $result->get_error_code(), 'data' => $result->get_error_data(), 'message' => $result->get_error_message()); $get_contents = file_get_contents($url); if ($get_contents !== false) { $return = array('code' => 200, 'data' => $get_contents, 'is_file_get_contents' => true); } } return $return; }
/** * * @param array $current_import * @return bool */ function import(array $current_import) { // fetch the remote content $html = wp_remote_get($current_import['file']); // Something failed if (is_wp_error($html)) { $redirect_url = get_admin_url(get_current_blog_id(), '/tools.php?page=pb_import'); error_log('\\PressBooks\\Import\\Html import error, wp_remote_get() ' . $html->get_error_message()); $_SESSION['pb_errors'][] = $html->get_error_message(); $this->revokeCurrentImport(); \Pressbooks\Redirect\location($redirect_url); } $url = parse_url($current_import['file']); // get parent directory (with forward slash e.g. /parent) $path = dirname($url['path']); $domain = $url['scheme'] . '://' . $url['host'] . $path; // get id (there will be only one) $id = array_keys($current_import['chapters']); // front-matter, chapter, or back-matter $post_type = $this->determinePostType($id[0]); $chapter_parent = $this->getChapterParent(); $body = $this->kneadandInsert($html['body'], $post_type, $chapter_parent, $domain); // Done return $this->revokeCurrentImport(); }
/** * Sends and receives data to and from the server API * * @access public * @since 1.0.0 * @return object $response */ public function plugin_information($args) { $target_url = $this->create_upgrade_api_url($args); $apisslverify = get_option('mainwp_api_sslVerifyCertificate') === false || get_option('mainwp_api_sslVerifyCertificate') == 1 ? 1 : 0; $request = wp_remote_get($target_url, array('timeout' => 50, 'sslverify' => $apisslverify)); // $request = wp_remote_post( MainWP_Api_Manager::instance()->getUpgradeUrl() . 'wc-api/upgrade-api/', array('body' => $args) ); if (is_wp_error($request) || wp_remote_retrieve_response_code($request) != 200) { return false; } $response = unserialize(wp_remote_retrieve_body($request)); /** * For debugging errors from the API * For errors like: unserialize(): Error at offset 0 of 170 bytes * Comment out $response above first */ // $response = wp_remote_retrieve_body( $request ); // print_r($response); exit; if (is_object($response)) { if (isset($response->package)) { $response->package = apply_filters('mainwp_api_manager_upgrade_url', $response->package); } return $response; } else { return false; } }
function constantcontact_submit() { $form_email = $_REQUEST['constantcontact_email']; if ($form_email) { $cc_user = get_field('constant_contact_username', 'option'); $cc_pass = get_field('constant_contact_password', 'option'); $cc_group = get_field('constant_contact_group_name', 'option'); if (empty($cc_user) || empty($cc_pass) || empty($cc_group)) { $message = 'Plugin Settings incomplete'; } else { if (empty($form_email)) { $message = 'Email address is required.'; } else { $cc_url = 'https://api.constantcontact.com/0.1/API_AddSiteVisitor.jsp?' . 'loginName=' . rawurlencode($cc_user) . '&loginPassword='******'&ea=' . rawurlencode($form_email) . '&ic=' . rawurlencode($cc_group); $response = wp_remote_get($cc_url); if (is_wp_error($response)) { $message = 'Could not connect to Constant Contact'; } else { $rsp = explode("\n", $response['body']); if (intval($rsp[0])) { $message = !empty($rsp[1]) ? $rsp[1] : (intval($rsp[0]) == 400 ? __('Constant Contact username/password not accepted') : __('Constant Contact error')); } else { $message = get_field('constant_contact_success_message', 'option'); $message = $message ? $message : "Thank you, you've been added to the list!"; $message_type = 'success'; } } } } if ($message) { $tabby_cc_param = array('message' => $message, 'message_type' => $message_type ? $message_type : 'error'); wp_localize_script('jquery', 'tabby_cc_param', $tabby_cc_param); } } }
function instagradam_embed_shortcode($atts, $content = null) { // define main output $str = ""; // get remote data $result = wp_remote_get("https://api.instagram.com/v1/media/popular?client_id=3f72f6859f3240c68b362b80c70e3121"); if (is_wp_error($result)) { // error handling $error_message = $result->get_error_message(); $str = "Something went wrong: {$error_message}"; } else { // processing further $result = json_decode($result['body']); $main_data = array(); $n = 0; // get username and actual thumbnail foreach ($result->data as $d) { $main_data[$n]['user'] = $d->user->username; $main_data[$n]['thumbnail'] = $d->images->thumbnail->url; $n++; } // create main string, pictures embedded in links foreach ($main_data as $data) { $str .= '<a target="_blank" href="http://instagram.com/' . $data['user'] . '"><img src="' . $data['thumbnail'] . '" alt="' . $data['user'] . ' pictures"></a> '; } } return $str; }
private function get_repository_info() { if (is_null($this->github_response)) { // Do we have a response? $request_uri = sprintf('https://api.github.com/repos/%s/%s/releases', $this->username, $this->repository); // Build URI if ($this->authorize_token) { // Is there an access token? $request_uri = add_query_arg('access_token', $this->authorize_token, $request_uri); // Append it } $response = json_decode(wp_remote_retrieve_body(wp_remote_get($request_uri)), true); // Get JSON and parse it if (is_array($response)) { // If it is an array $response = current($response); // Get the first item } if ($this->authorize_token) { // Is there an access token? $response['zipball_url'] = add_query_arg('access_token', $this->authorize_token, $response['zipball_url']); // Update our zip url with token } $this->github_response = $response; // Set it to our property } }
function _manually_load_plugin() { $host = getenv('ES_HOST'); $host = preg_replace('/(^https:\\/\\/|^http:\\/\\/)/is', '', $host); $port = getenv('ES_PORT'); if (empty($host)) { $host = 'localhost'; } if (empty($port)) { $port = 9200; } define('ES_HOST', $host); define('ES_PORT', $port); require dirname(dirname(__FILE__)) . '/wp-elasticsearch.php'; $tries = 5; $sleep = 3; do { $response = wp_remote_get(esc_url(ES_HOST) . ':' . ES_PORT); if (200 == wp_remote_retrieve_response_code($response)) { // Looks good! break; } else { printf("\nInvalid response from ES, sleeping %d seconds and trying again...\n", intval($sleep)); sleep($sleep); } } while (--$tries); if (200 != wp_remote_retrieve_response_code($response)) { exit('Could not connect to Elasticsearch server.'); } }
function get_count_feed_burner($uri) { $whaturl = "https://feedburner.google.com/api/awareness/1.0/GetFeedData?uri={$uri}"; /* //Initialize the Curl session $ch = curl_init(); //Set curl to return the data instead of printing it to the browser. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //Set the URL curl_setopt($ch, CURLOPT_URL, $whaturl); //Execute the fetch $feed_data = curl_exec($ch); //Close the connection curl_close($ch); */ $fb = ''; $args = array('method' => 'GET', 'timeout' => 5, 'redirection' => 5, 'httpversion' => '1.0', 'blocking' => true, 'headers' => array(), 'body' => null, 'cookies' => array()); $feed_data = wp_remote_get($whaturl, $args); if (!is_wp_error($feed_data)) { $feed_data = $feed_data['body']; $xml = new SimpleXMLElement($feed_data); $fb = $xml->feed->entry['circulation']; //end get cool feedburner count } //echo the subscriber count return $fb; }
/** * Test whether force rewrite should be enabled or not. */ function wpseo_title_test() { $options = get_option('wpseo_titles'); $options['forcerewritetitle'] = false; $options['title_test'] = 1; update_option('wpseo_titles', $options); // Setting title_test to > 0 forces the plugin to output the title below through a filter in class-frontend.php. $expected_title = 'This is a Yoast Test Title'; WPSEO_Utils::clear_cache(); $args = array('user-agent' => sprintf('WordPress/%1$s; %2$s - Yoast', $GLOBALS['wp_version'], get_site_url())); $resp = wp_remote_get(get_bloginfo('url'), $args); if ($resp && !is_wp_error($resp) && (200 == $resp['response']['code'] && isset($resp['body']))) { $res = preg_match('`<title>([^<]+)</title>`im', $resp['body'], $matches); if ($res && strcmp($matches[1], $expected_title) !== 0) { $options['forcerewritetitle'] = true; $resp = wp_remote_get(get_bloginfo('url'), $args); $res = false; if ($resp && !is_wp_error($resp) && (200 == $resp['response']['code'] && isset($resp['body']))) { $res = preg_match('`/<title>([^>]+)</title>`im', $resp['body'], $matches); } } if (!$res || $matches[1] != $expected_title) { $options['forcerewritetitle'] = false; } } else { // If that dies, let's make sure the titles are correct and force the output. $options['forcerewritetitle'] = true; } $options['title_test'] = 0; update_option('wpseo_titles', $options); }
public function __construct($sURL, $iTimeout = 10, $iRedirects = 5, $aHeaders = null, $sUserAgent = null, $bForceFsockOpen = false) { $this->timeout = $iTimeout; $this->redirects = $iRedirects; $this->headers = $sUserAgent; $this->useragent = $sUserAgent; $this->url = $sURL; // If the scheme is not http or https. if (!preg_match('/^http(s)?:\\/\\//i', $sURL)) { $this->error = ''; $this->success = false; return; } // Arguments $aArgs = array('timeout' => $this->timeout, 'redirection' => $this->redirects, true, 'sslverify' => false); if (!empty($this->headers)) { $aArgs['headers'] = $this->headers; } if (SIMPLEPIE_USERAGENT != $this->useragent) { $aArgs['user-agent'] = $this->useragent; } // Request $res = function_exists('wp_safe_remote_request') ? wp_safe_remote_request($sURL, $aArgs) : wp_remote_get($sURL, $aArgs); if (is_wp_error($res)) { $this->error = 'WP HTTP Error: ' . $res->get_error_message(); $this->success = false; return; } $this->headers = wp_remote_retrieve_headers($res); $this->body = wp_remote_retrieve_body($res); $this->status_code = wp_remote_retrieve_response_code($res); }
function createFile($imgURL) { $remImgURL = urldecode($imgURL); $urlParced = pathinfo($remImgURL); $remImgURLFilename = $urlParced['basename']; $imgData = wp_remote_get($remImgURL); if (is_wp_error($imgData)) { $badOut['Error'] = print_r($imgData, true) . " - ERROR"; return $badOut; } $imgData = $imgData['body']; $tmp = array_search('uri', @array_flip(stream_get_meta_data($GLOBALS[mt_rand()] = tmpfile()))); if (!is_writable($tmp)) { return "Your temporary folder or file (file - " . $tmp . ") is not witable. Can't upload images to Flickr"; } rename($tmp, $tmp .= '.png'); register_shutdown_function(create_function('', "unlink('{$tmp}');")); file_put_contents($tmp, $imgData); if (!$tmp) { return 'You must specify a path to a file'; } if (!file_exists($tmp)) { return 'File path specified does not exist'; } if (!is_readable($tmp)) { return 'File path specified is not readable'; } // $data['name'] = basename($tmp); return "@{$tmp}"; }
public function check_email($data = '') { if (empty($this->public_key)) { return new WP_Error('no_api_key', __('No API key was provided', 'awesome-support')); } if (empty($data)) { if (isset($_POST)) { $data = $_POST; } else { return new WP_Error('no_data', __('No data to check', 'awesome-support')); } } if (!isset($data['email'])) { return new WP_Error('no_email', __('No e-mail to check', 'awesome-support')); } global $wp_version; $args = array('timeout' => 5, 'redirection' => 5, 'httpversion' => '1.0', 'user-agent' => 'WordPress/' . $wp_version . '; ' . get_bloginfo('url'), 'blocking' => true, 'headers' => array('Authorization' => 'Basic ' . base64_encode('api:' . $this->public_key)), 'cookies' => array(), 'body' => array('address' => $data['email']), 'compress' => false, 'decompress' => true, 'sslverify' => true, 'stream' => false, 'filename' => null); $response = wp_remote_get(esc_url($this->endpoint), $args); $response_code = wp_remote_retrieve_response_code($response); if (is_wp_error($response)) { return $response; } if (200 != $response_code) { return new WP_Error($response_code, wp_remote_retrieve_response_message($response)); } $body = wp_remote_retrieve_body($response); return $body; }
protected function getDownloadUrl() { global $wp_filesystem; $this->skin->feedback('download_envato'); $package_filename = 'js_composer.zip'; $res = $this->fs_connect(array(WP_CONTENT_DIR)); if (!$res) { return new WP_Error('no_credentials', __("Error! Can't connect to filesystem", 'js_composer')); } $username = WPBakeryVisualComposerSettings::get('envato_username'); $api_key = WPBakeryVisualComposerSettings::get('envato_api_key'); $purchase_code = WPBakeryVisualComposerSettings::get('js_composer_purchase_code'); if (empty($username) || empty($api_key) || empty($purchase_code)) { return new WP_Error('no_credentials', __('Error! Envato username, api key and your purchase code are required for downloading updates from Envato marketplace for the Visual Composer. Visit <a href="' . admin_url('options-general.php?page=wpb_vc_settings&tab=updater') . '' . '">Settings</a> to fix.', 'js_composer')); } $json = wp_remote_get($this->envatoDownloadPurchaseUrl($username, $api_key, $purchase_code)); $result = json_decode($json['body'], true); if (!isset($result['download-purchase']['download_url'])) { return new WP_Error('no_credentials', __('Error! Envato API error' . (isset($result['error']) ? ': ' . $result['error'] : '.'), 'js_composer')); } $result['download-purchase']['download_url']; $download_file = download_url($result['download-purchase']['download_url']); if (is_wp_error($download_file)) { return $download_file; } $upgrade_folder = $wp_filesystem->wp_content_dir() . 'upgrade_tmp/js_composer_envato_package'; if (is_dir($upgrade_folder)) { $wp_filesystem->delete($upgrade_folder); } $result = unzip_file($download_file, $upgrade_folder); if ($result && is_file($upgrade_folder . '/' . $package_filename)) { return $upgrade_folder . '/' . $package_filename; } return new WP_Error('no_credentials', __('Error on unzipping package', 'js_composer')); }
function fetch_feed($username, $slice = 8) { $barcelona_remote_url = esc_url('http://instagram.com/' . trim(strtolower($username))); $barcelona_transient_key = 'barcelona_instagram_feed_' . sanitize_title_with_dashes($username); $slice = absint($slice); if (false === ($barcelona_result_data = get_transient($barcelona_transient_key))) { $barcelona_remote = wp_remote_get($barcelona_remote_url); if (is_wp_error($barcelona_remote) || 200 != wp_remote_retrieve_response_code($barcelona_remote)) { return new WP_Error('not-connected', esc_html__('Unable to communicate with Instagram.', 'barcelona')); } preg_match('#window\\.\\_sharedData\\s\\=\\s(.*?)\\;\\<\\/script\\>#', $barcelona_remote['body'], $barcelona_match); if (!empty($barcelona_match)) { $barcelona_data = json_decode(end($barcelona_match), true); if (is_array($barcelona_data) && isset($barcelona_data['entry_data']['ProfilePage'][0]['user']['media']['nodes'])) { $barcelona_result_data = $barcelona_data['entry_data']['ProfilePage'][0]['user']['media']['nodes']; } } if (is_array($barcelona_result_data)) { set_transient($barcelona_transient_key, $barcelona_result_data, 60 * 60 * 2); } } if (empty($barcelona_result_data)) { return new WP_Error('no-images', esc_html__('Instagram did not return any images.', 'barcelona')); } return array_slice($barcelona_result_data, 0, $slice); }
public function getArtistShows($artist) { $json = wp_remote_get($this->apiUrl . 'artists/' . $artist . '/events.json?api_version=2.0&app_id=developer-candidate-practical-exam'); $array = json_decode($json['body']); $shows = $array; return $shows; }
private function get_notice_json() { // get notice data from server $data = @wp_remote_get($this->server_file, array('sslverify' => false)); if (isset($data) && !empty($data) && !is_wp_error($data) && $data['response']['code'] == 200) { $data = $data['body']; // if some data exists if ($data != '' || !empty($data)) { if (!empty($this->notice_data)) { if (strcmp($data, $this->notice_data) == 0) { // set new cookie for interval value AvadaRedux_Functions::setCookie($this->cookie_id, time(), time() + 86400 * $this->interval, '/'); // bail out return; } } update_option('r_notice_data', $data); $this->notice_data = $data; // set cookie for three day expiry setcookie($this->cookie_id, time(), time() + 86400 * $this->interval, '/'); // set unique key for dismiss meta key update_option($this->cookie_id, time()); } } }
/** * Query twitter's API * * @uses $this->get_bearer_token() to retrieve token if not working * * @param string $query Insert the query in the format "count=1&include_entities=true&include_rts=true&screen_name=micc1983! * @param array $query_args Array of arguments: Resource type (string) and cache duration (int) * @param bool $stop Stop the query to avoid infinite loop * * @return bool|object Return an object containing the result */ public function query($query, $query_args = array(), $stop = false) { if ($this->has_error) { return false; } if (is_array($query_args) && !empty($query_args)) { $this->query_args = array_merge($this->query_args, $query_args); } $transient_name = 'wta_' . md5($query); if (false !== ($data = get_transient($transient_name))) { return json_decode($data); } $args = array('method' => 'GET', 'timeout' => 5, 'redirection' => 5, 'httpversion' => '1.0', 'blocking' => true, 'headers' => array('Authorization' => 'Bearer ' . $this->bearer_token, 'Accept-Encoding' => 'gzip'), 'body' => null, 'cookies' => array()); $response = wp_remote_get('https://api.twitter.com/1.1/' . $this->query_args['type'] . '.json?' . $query, $args); if (is_wp_error($response) || 200 != $response['response']['code']) { if (!$stop) { $this->bearer_token = $this->get_bearer_token(); return $this->query($query, $this->query_args, true); } else { return $this->bail(__('Bearer Token is good, check your query', 'wp_twitter_api'), $response); } } set_transient($transient_name, $response['body'], $this->query_args['cache']); return json_decode($response['body']); }
/** * Returns an array of search suggestions from the unofficial completion API located * at the endpoint specified in this class. &q=query * * Parses the output into an array of associative arrays with keys of term, volume and * current. "current" is a boolean that determines whether the result in question is the searched * for term. * * @return array|WP_Error WP_Error if something goes wrong. Otherwise, an array as described above. */ public static function get_suggestions($search_term) { $search_term = trim($search_term); if (empty($search_term)) { return new WP_Error('empty_term', __('Please provide a search term.', 'scribeseo')); } $response = wp_remote_get(add_query_arg(array('q' => urlencode($search_term)), self::ENDPOINT)); if (is_wp_error($response)) { return $response; } $result = array(); // turn on user error handing $user_errors = libxml_use_internal_errors(true); $complete_suggestions = simplexml_load_string(wp_remote_retrieve_body($response)); // get any errors $xml_errors = libxml_get_errors(); // restore error handling setting libxml_use_internal_errors($user_errors); if (!empty($xml_errors)) { return new WP_Error('xml_error', __('The XML from the Google Completion API could not be loaded appropriately.', 'scribeseo')); } $complete_suggestions_po = json_decode(json_encode($complete_suggestions)); if (!is_object($complete_suggestions_po) || !isset($complete_suggestions_po->CompleteSuggestion)) { return new WP_Error('xml_error', __('The XML from the Google Completion API could not be loaded appropriately.', 'scribeseo')); } foreach ($complete_suggestions_po->CompleteSuggestion as $suggestion) { $term = $suggestion->suggestion->{'@attributes'}->data; $volume = intval($suggestion->num_queries->{'@attributes'}->int); $volume_nice = number_format_i18n($volume); $current = $term == $search_term; $result[] = compact('term', 'volume', 'volume_nice', 'current'); } return $result; }
/** * Execute an API call * @param string $method The HTTP method * @param string $url The API endpoint * @param string $call The API method to call * @param array $additional Additional parameters * @return array */ public function fetch($method, $url, $call, array $additional = array()) { // Get the signed request URL $request = $this->getSignedRequest($method, $url, $call, $additional); if ($method == 'GET') { $args = array(); $response = wp_remote_get($request['url'], $args); $this->outFile = null; } elseif ($method == 'POST') { $args = array('body' => $request['postfields']); $response = wp_remote_post($request['url'], $args); } elseif ($method == 'PUT' && $this->inFile) { return new WP_Error('unsupported', "WordPress does not have a native HTTP PUT function"); } // If the response body is not a JSON encoded string // we'll return the entire response body // Important to do this first, as the next section relies on the decoding having taken place if (!($body = json_decode($response['body']))) { $body = $response['body']; } // Check if an error occurred and throw an Exception. This is part of the authentication process - don't modify. if (!empty($body->error)) { $message = $body->error . ' (Status Code: ' . $response['code'] . ')'; throw new Dropbox_Exception($message); } if (is_wp_error($response)) { $message = $response->get_error_message(); throw new Dropbox_Exception($message); } $results = array('body' => $body, 'code' => $response['response']['code'], 'headers' => $response['headers']); return $results; }
private function get_notice_json() { // filesystem object $filesystem = $this->parent->filesystem; // get notice data from server //$data = $filesystem->execute('get_contents', $this->server_file);// 'http://www.reduxframework.com/' . 'wp-content/uploads/redux/redux_notice.json'); $data = wp_remote_get($this->server_file, array('sslverify' => false)); $data = $data['body']; // if some data exists if ($data != '' || !empty($data)) { // if local notice file exists if (file_exists($this->notice_json)) { // get cached data $cache_data = $filesystem->execute('get_contents', $this->notice_json); // if local and server data are same, then return if (strcmp($data, $cache_data) == 0) { // set new cookie for interval value Redux_Functions::setCookie($this->cookie_id, time(), time() + 86400 * $this->interval, '/'); // bail out return; } } // set server data $params = array('content' => $data); // write local notice file with new data $filesystem->execute('put_contents', $this->notice_json, $params); // set cookie for three day expiry setcookie($this->cookie_id, time(), time() + 86400 * $this->interval, '/'); // set unique key for dismiss meta key update_option($this->cookie_id, time()); } }
/** * Get uploads from the production site and store them * in the local filesystem if they don't already exist. * * @return void */ function uploads_proxy() { global $wp_filesystem; WP_Filesystem(); // The relative request path $requestPath = $_SERVER['REQUEST_URI']; // The relative uploads path $uploadsPath = str_replace(get_bloginfo('url'), '', wp_upload_dir()['baseurl']); // Check if a upload was requested if (strpos($requestPath, $uploadsPath) === 0) { // The absolute remote path to the upload $remotePath = UP_SITEURL . $requestPath; // Get the remote upload file $response = wp_remote_get($remotePath); // Check the response code if ($response['response']['code'] === 200) { // The file path relative to the uploads path to store the upload file to $relativeUploadFile = str_replace($uploadsPath, '', $_SERVER['REQUEST_URI']); // The absolute file path to store the upload file to $absoluteUploadFile = wp_upload_dir()['basedir'] . $relativeUploadFile; // Make sure the upload directory exists wp_mkdir_p(pathinfo($absoluteUploadFile)['dirname']); if ($wp_filesystem->put_contents(urldecode($absoluteUploadFile), $response['body'], FS_CHMOD_FILE)) { // Redirect to the stored upload wp_redirect($requestPath); } } } }
public static function login_existing_facebook_user_ajax() { check_ajax_referer('displet_check_user_nonce'); if (isset($_POST['action']) && $_POST['action'] == 'displet_user_check_request' && !empty($_POST['email']) && !empty($_POST['token'])) { $user_id = DispletRetsIdxUsersModel::get_user_id_by_email($_POST['email']); if (!empty($user_id)) { $json_array = wp_remote_post('https://graph.facebook.com/oauth/access_token?client_id=' . self::$_options['facebook_app_id'] . '&client_secret=' . self::$_options['facebook_app_secret'] . '&grant_type=client_credentials'); if (!empty($json_array['body'])) { $response = wp_remote_get('https://graph.facebook.com/debug_token?input_token=' . $_POST['token'] . '&' . $json_array['body']); if (!empty($response['body'])) { $result = json_decode($response['body']); if (!empty($result->data) && !empty($result->data->is_valid) && !empty($result->data->app_id) && $result->data->app_id === self::$_options['facebook_app_id']) { wp_set_auth_cookie($user_id, true); echo 'User Exists and Logged In'; } } } } else { echo 'There is no email account associated with this user.'; } die; } echo 'We\'re sorry, there was an error processing your request. Please try again.'; die; }
function userMedia() { $url = 'https://api.instagram.com/v1/users/' . $this->userID() . '/media/recent/?access_token=' . $this->access_token; $content = wp_remote_get($url); $response = wp_remote_retrieve_body($content); return $json = json_decode($response, true); }
/** * Show Theme changes. Code adapted from W3 Total Cache. * * @return void */ function wplms_update_message($args) { $transient_name = 'wplms_upgrade_notice_' . $args['Version']; if (false === ($upgrade_notice = get_transient($transient_name))) { $response = wp_remote_get('https://s3.amazonaws.com/WPLMS/readme.txt'); if (!is_wp_error($response) && !empty($response['body'])) { // Output Upgrade Notice $matches = null; $regexp = '~==\\s*Upgrade Notice\\s*==\\s*=\\s*(.*)\\s*=(.*)(=\\s*' . preg_quote(WC_VERSION) . '\\s*=|$)~Uis'; $upgrade_notice = ''; if (preg_match($regexp, $response['body'], $matches)) { $version = trim($matches[1]); $notices = (array) preg_split('~[\\r\\n]+~', trim($matches[2])); if (version_compare(WC_VERSION, $version, '<')) { $upgrade_notice .= '<div class="wplms_plugin_upgrade_notice">'; foreach ($notices as $index => $line) { $upgrade_notice .= wp_kses_post(preg_replace('~\\[([^\\]]*)\\]\\(([^\\)]*)\\)~', '<a href="${2}">${1}</a>', $line)); } $upgrade_notice .= '</div> '; } } set_transient($transient_name, $upgrade_notice, DAY_IN_SECONDS); } } echo wp_kses_post($upgrade_notice); }
function _manually_load_plugin() { $host = getenv('EP_HOST'); if (empty($host)) { $host = 'http://localhost:9200'; } define('EP_HOST', $host); require dirname(__FILE__) . '/../vendor/woocommerce/woocommerce.php'; require dirname(__FILE__) . '/../elasticpress.php'; add_filter('ep_config_mapping', 'ep_test_shard_number'); $tries = 5; $sleep = 3; do { $response = wp_remote_get(EP_HOST); if (200 == wp_remote_retrieve_response_code($response)) { // Looks good! break; } else { printf("\nInvalid response from ES, sleeping %d seconds and trying again...\n", intval($sleep)); sleep($sleep); } } while (--$tries); if (200 != wp_remote_retrieve_response_code($response)) { exit('Could not connect to ElasticPress server.'); } require_once dirname(__FILE__) . '/includes/functions.php'; }
function ping_search_system() { global $site_link; $url = ''; $last_ping = get_option('last_ping_search_system') != false ? get_option('last_ping_search_system') : 0; $limit_time = time() - $last_ping > 3600; //limit time 3600 sm - 1 hour; if (count($_POST) > 1 && $limit_time) { foreach ($_POST as $key) { switch ($key) { case 'google_ping': $url = '//google.com/webmasters/sitemaps/ping?sitemap='; break; case 'yandex_ping': $url = '//webmaster.yandex.ru/wmconsole/sitemap_list.xml?host='; break; case 'yahoo_ping': $url = '//search.yahooapis.com/SiteExplorerService/V1/ping?sitemap='; break; case 'bing_ping': $url = '//www.bing.com/webmaster/ping.aspx?siteMap='; break; case 'ask_ping': $url = '//submissions.ask.com/ping?sitemap='; break; } if (@get_headers($url)) { wp_remote_get($url . $site_link . "sitemap.xml"); } } update_option('last_ping_search_system', time()); } }
public static function get_user($domain, $jwt, $user_id) { $endpoint = "https://{$domain}/api/v2/users/" . urlencode($user_id); $headers = self::get_info_headers(); $headers['Authorization'] = "Bearer {$jwt}"; return wp_remote_get($endpoint, array('headers' => $headers)); }
/** * The API call */ function wpl_instagram_response($userid = null, $count = 6, $columns = 3) { if (intval($userid) === 0) { return '<p>No user ID specified.</p>'; } $transient_var = 'biw_' . $userid . '_' . $count; if (false === ($items = get_transient($transient_var))) { $response = wp_remote_get('https://api.instagram.com/v1/users/' . $userid . '/media/recent/?client_id=' . BIW_CLIENT_ID . '&count=' . esc_attr($count)); $response_body = json_decode($response['body']); //echo '<pre>'; print_r( $response_body ); echo '</pre>'; if ($response_body->meta->code !== 200) { return '<p>Incorrect user ID specified.</p>'; } $items_as_objects = $response_body->data; $items = array(); foreach ($items_as_objects as $item_object) { $item['link'] = $item_object->link; $item['src'] = $item_object->images->low_resolution->url; $items[] = $item; } set_transient($transient_var, $items, 60 * 60); } $output = '<ul class="photo-tiles large-block-grid-3 medium-block-grid-6 small-block-grid-3">'; foreach ($items as $item) { $link = $item['link']; $image = $item['src']; $output .= '<li class="photo-tile"><a href="' . esc_url($link) . '"><img src="' . esc_url($image) . '" /></a></li>'; } $output .= '</ul>'; return $output; }
private static function apiRequest($act, $post_data = null, $use_ssl = true) { global $wp_version; $site = rawurlencode(base64_encode(get_option('siteurl'))); $url = "http" . ($use_ssl ? "s://ssl-account.com" : ":/") . "/interface.fabi.me/wpfilebase-pro/{$act}.php"; $get_args = array('version' => WPFB_VERSION, 'pl_slug' => 'wp-filebase', 'pl_ver' => WPFB_VERSION, 'wp_ver' => $wp_version, 'site' => $site); // try to get from cache $cache_key = 'wpfb_apireq_' . md5($act . '||' . serialize($get_args) . '||' . serialize($post_data) . '||' . __FILE__); if (isset($_REQUEST['no_api_cache'])) { delete_transient($cache_key); } $res = get_transient($cache_key); if ($res !== false) { return $res; } //trigger_error ( "WP-Filebase apiRequest (ssl=$use_ssl): $act ".json_encode($post_data), E_USER_NOTICE ); if (empty($post_data)) { $res = wp_remote_get($url, $get_args); } else { $res = wp_remote_post(add_query_arg($get_args, $url), array('body' => $post_data)); } if (is_wp_error($res)) { if ($use_ssl) { // retry without ssl return self::apiRequest($act, $post_data, false); } echo "<b>WP-Filebase API request error:</b>"; print_r($res); return false; } $res = empty($res['body']) ? false : json_decode($res['body']); set_transient($cache_key, $res, 0 + 6 * HOUR_IN_SECONDS); return $res; }