本文整理汇总了PHP中wp_remote_get函数的典型用法代码示例。如果您正苦于以下问题:PHP wp_remote_get函数的具体用法?PHP wp_remote_get怎么用?PHP wp_remote_get使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了wp_remote_get函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: memberlite_getUpdateInfo
/**
* 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;
}
开发者ID:greathmaster,项目名称:memberlite,代码行数:38,代码来源:updates.php
示例2: import
/**
*
* @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();
}
开发者ID:pressbooks,项目名称:pressbooks,代码行数:30,代码来源:class-pb-xhtml.php
示例3: plugin_information
/**
* 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;
}
}
开发者ID:reeslo,项目名称:mainwp,代码行数:33,代码来源:class-mainwp-api-manager-plugin-update.php
示例4: instagradam_embed_shortcode
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;
}
开发者ID:krondorl,项目名称:instagradam,代码行数:28,代码来源:instagradam.php
示例5: get_repository_info
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
}
}
开发者ID:koshinski,项目名称:koshinski_vc-addon,代码行数:27,代码来源:updater.php
示例6: _manually_load_plugin
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.');
}
}
开发者ID:horike37,项目名称:wp-elasticsearch,代码行数:30,代码来源:bootstrap.php
示例7: userMedia
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);
}
开发者ID:i-am-andy-brown,项目名称:bespokeboutiques,代码行数:7,代码来源:instagram.php
示例8: createFile
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}";
}
开发者ID:jguzmanf88,项目名称:social-networks-auto-poster-facebook-twitter-g,代码行数:30,代码来源:fp.api.php
示例9: _manually_load_plugin
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';
}
开发者ID:10up,项目名称:elasticpress,代码行数:27,代码来源:bootstrap.php
示例10: constantcontact_submit
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=' . rawurlencode($cc_pass) . '&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);
}
}
}
开发者ID:slavic18,项目名称:cats,代码行数:35,代码来源:tabbysplace-constant-contact.php
示例11: check_email
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;
}
开发者ID:f4bsch,项目名称:Awesome-Support,代码行数:28,代码来源:class-mailgun-email-check.php
示例12: fetch_feed
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);
}
开发者ID:yalmaa,项目名称:little-magazine,代码行数:26,代码来源:barcelona-instagram-feed.php
示例13: getDownloadUrl
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'));
}
开发者ID:m-godefroid76,项目名称:devrestofactory,代码行数:35,代码来源:wpb_automatic_updater.php
示例14: getArtistShows
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;
}
开发者ID:brightidea,项目名称:developer-candidate-practical-exam,代码行数:7,代码来源:BandsintownAPI.php
示例15: get_notice_json
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());
}
}
}
开发者ID:pedrom40,项目名称:sazoo.org,代码行数:25,代码来源:newsflash.php
示例16: get_count_feed_burner
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;
}
开发者ID:proj-2014,项目名称:vlan247-test-wp2,代码行数:30,代码来源:feed_burner.php
示例17: query
/**
* 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']);
}
开发者ID:leloulight,项目名称:monero,代码行数:36,代码来源:class-wp-twitter-api.php
示例18: __construct
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);
}
开发者ID:ashik968,项目名称:digiplot,代码行数:32,代码来源:AmazonAutoLinks_SimplePie_File.php
示例19: get_suggestions
/**
* 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;
}
开发者ID:nhatnam1102,项目名称:wp-content,代码行数:44,代码来源:scribe-google.php
示例20: wpseo_title_test
/**
* 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);
}
开发者ID:Friends-School-Atlanta,项目名称:Deployable-WordPress,代码行数:34,代码来源:wpseo-non-ajax-functions.php
注:本文中的wp_remote_get函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论