本文整理汇总了PHP中wp_remote_post函数的典型用法代码示例。如果您正苦于以下问题:PHP wp_remote_post函数的具体用法?PHP wp_remote_post怎么用?PHP wp_remote_post使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了wp_remote_post函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: gdrive_auth_token
public static function gdrive_auth_token()
{
if (isset($_GET['code'])) {
$post_vars = array('code' => $_GET['code'], 'client_id' => UpdraftPlus_Options::get_updraft_option('updraft_googledrive_clientid'), 'client_secret' => UpdraftPlus_Options::get_updraft_option('updraft_googledrive_secret'), 'redirect_uri' => admin_url('options-general.php?page=updraftplus&action=updraftmethod-googledrive-auth'), 'grant_type' => 'authorization_code');
$result = wp_remote_post('https://accounts.google.com/o/oauth2/token', array('timeout' => 30, 'method' => 'POST', 'body' => $post_vars));
if (is_wp_error($result)) {
$add_to_url = "Bad response when contacting Google: ";
foreach ($result->get_error_messages() as $message) {
global $updraftplus;
$updraftplus->log("Google Drive authentication error: " . $message);
$add_to_url .= "{$message}. ";
}
header('Location: ' . admin_url('options-general.php?page=updraftplus&error=' . urlencode($add_to_url)));
} else {
$json_values = json_decode($result['body'], true);
if (isset($json_values['refresh_token'])) {
// Save token
UpdraftPlus_Options::update_updraft_option('updraft_googledrive_token', $json_values['refresh_token']);
if (isset($json_values['access_token'])) {
set_transient('updraftplus_tmp_googledrive_access_token', $json_values['access_token'], 3600);
// We do this to clear the GET parameters, otherwise WordPress sticks them in the _wp_referer in the form and brings them back, leading to confusion + errors
header('Location: ' . admin_url('options-general.php?page=updraftplus&action=updraftmethod-googledrive-auth&state=success'));
}
} else {
$msg = __('No refresh token was received from Google. This often means that you entered your client secret wrongly, or that you have not yet re-authenticated (below) since correcting it. Re-check it, then follow the link to authenticate again. Finally, if that does not work, then use expert mode to wipe all your settings, create a new Google client ID/secret, and start again.', 'updraftplus');
if (isset($json_values['error'])) {
$msg .= ' ' . sprintf(__('Error: %s', 'updraftplus'), $json_values['error']);
}
header('Location: ' . admin_url('options-general.php?page=updraftplus&error=' . $msg));
}
}
} else {
header('Location: ' . admin_url('options-general.php?page=updraftplus&error=' . __('Authorization failed', 'updraftplus')));
}
}
示例2: genesis_update_check
/**
* Pings http://api.genesistheme.com/ asking if a new version of this theme is
* available.
*
* If not, it returns false.
*
* If so, the external server passes serialized data back to this function,
* which gets unserialized and returned for use.
*
* @since 1.1.0
*
* @uses genesis_get_option()
* @uses PARENT_THEME_VERSION Genesis version string
*
* @global string $wp_version WordPress version string
* @return mixed Unserialized data, or false on failure
*/
function genesis_update_check()
{
global $wp_version;
/** If updates are disabled */
if (!genesis_get_option('update') || !current_theme_supports('genesis-auto-updates')) {
return false;
}
/** Get time of last update check */
$genesis_update = get_transient('genesis-update');
/** If it has expired, do an update check */
if (!$genesis_update) {
$url = 'http://api.genesistheme.com/update-themes/';
$options = apply_filters('genesis_update_remote_post_options', array('body' => array('genesis_version' => PARENT_THEME_VERSION, 'wp_version' => $wp_version, 'php_version' => phpversion(), 'uri' => home_url(), 'user-agent' => "WordPress/{$wp_version};")));
$response = wp_remote_post($url, $options);
$genesis_update = wp_remote_retrieve_body($response);
/** If an error occurred, return FALSE, store for 1 hour */
if ('error' == $genesis_update || is_wp_error($genesis_update) || !is_serialized($genesis_update)) {
set_transient('genesis-update', array('new_version' => PARENT_THEME_VERSION), 60 * 60);
return false;
}
/** Else, unserialize */
$genesis_update = maybe_unserialize($genesis_update);
/** And store in transient for 24 hours */
set_transient('genesis-update', $genesis_update, 60 * 60 * 24);
}
/** If we're already using the latest version, return false */
if (version_compare(PARENT_THEME_VERSION, $genesis_update['new_version'], '>=')) {
return false;
}
return $genesis_update;
}
示例3: check_for_update
function check_for_update($transient)
{
global $wp_filesystem, $smof_data;
if (empty($transient->checked)) {
return $transient;
}
$request_args = array('id' => $this->id, 'slug' => $this->slug, 'version' => $transient->checked[$this->id]);
$request_args['item_code'] = '2833226';
$request_args['envato_username'] = $smof_data['t4p_username'];
$request_args['api_key'] = $smof_data['t4p_api'];
$filename = trailingslashit(get_template_directory()) . 'log.txt';
$request_string = $this->prepare_request('plugin_update', $request_args);
$raw_response = wp_remote_post($this->api_url, $request_string);
$response = null;
if (!is_wp_error($raw_response) && $raw_response['response']['code'] == 200) {
$response = json_decode($raw_response['body'], true);
}
if (!empty($response)) {
// Feed the update data into WP updater
$transient->response[$this->id] = (object) $response;
}
/*$handle = fopen($filename, 'a');
fwrite($handle, json_encode($request_string));
fwrite($handle, json_encode($raw_response));*/
return $transient;
}
示例4: layerslider_verify_purchase_code
function layerslider_verify_purchase_code()
{
global $wp_version;
// Get data
$pcode = get_option('layerslider-purchase-code', '');
$validated = get_option('layerslider-validated', '0');
$channel = $_POST['channel'] === 'beta' ? 'beta' : 'stable';
// Save sent data
update_option('layerslider-release-channel', $channel);
update_option('layerslider-purchase-code', $_POST['purchase_code']);
// Release channel
if ($validated == 1) {
if ($pcode == $_POST['purchase_code']) {
die(json_encode(array('success' => true, 'message' => __('Your settings were successfully saved.', 'LayerSlider'))));
}
}
// Verify license
$response = wp_remote_post('http://activate.kreaturamedia.com/', array('user-agent' => 'WordPress/' . $wp_version . '; ' . get_bloginfo('url'), 'body' => array('plugin' => urlencode('LayerSlider WP'), 'license' => urlencode($_POST['purchase_code']))));
// Valid
if ($response['body'] == 'valid') {
update_option('layerslider-validated', '1');
die(json_encode(array('success' => true, 'message' => __('Thank you for purchasing LayerSlider WP. You successfully validated your purchase code for auto-updates.', 'LayerSlider'))));
// Invalid
} else {
update_option('layerslider-validated', '0');
die(json_encode(array('success' => false, 'message' => __("Your purchase code doesn't appear to be valid. Please make sure that you entered your purchase code correctly.", "LayerSlider"))));
}
}
示例5: mm_ux_log
function mm_ux_log($args = array())
{
$url = "https://ssl.google-analytics.com/collect";
global $title;
if (empty($_SERVER['REQUEST_URI'])) {
return;
}
$path = explode('wp-admin', $_SERVER['REQUEST_URI']);
if (empty($path) || empty($path[1])) {
$path = array("", " ");
}
$defaults = array('v' => '1', 'tid' => 'UA-39246514-3', 't' => 'pageview', 'cid' => md5(get_option('siteurl')), 'uid' => md5(get_option('siteurl') . get_current_user_id()), 'cn' => 'mojo_wp_plugin', 'cs' => 'mojo_wp_plugin', 'cm' => 'plugin_admin', 'ul' => get_locale(), 'dp' => $path[1], 'sc' => '', 'ua' => @$_SERVER['HTTP_USER_AGENT'], 'dl' => $path[1], 'dh' => get_option('siteurl'), 'dt' => $title, 'ec' => '', 'ea' => '', 'el' => '', 'ev' => '');
if (isset($_SERVER['REMOTE_ADDR'])) {
$defaults['uip'] = $_SERVER['REMOTE_ADDR'];
}
$params = wp_parse_args($args, $defaults);
$test = get_transient('mm_test', '');
if (isset($test['key']) && isset($test['name'])) {
$params['cm'] = $params['cm'] . "_" . $test['name'] . "_" . $test['key'];
}
//use test account for testing
if (defined('WP_DEBUG') && WP_DEBUG) {
$params['tid'] = 'UA-19617272-27';
}
$z = wp_rand(0, 1000000000);
$query = http_build_query(array_filter($params));
$args = array('body' => $query, 'method' => 'POST', 'blocking' => false);
$url = add_query_arg(array('z' => $z), $url);
wp_remote_post($url, $args);
}
示例6: pmxi_wp_ajax_save_import_functions
function pmxi_wp_ajax_save_import_functions()
{
if (!check_ajax_referer('wp_all_import_secure', 'security', false)) {
exit(json_encode(array('html' => __('Security check', 'wp_all_import_plugin'))));
}
if (!current_user_can('manage_options')) {
exit(json_encode(array('html' => __('Security check', 'wp_all_import_plugin'))));
}
$uploads = wp_upload_dir();
$functions = $uploads['basedir'] . DIRECTORY_SEPARATOR . WP_ALL_IMPORT_UPLOADS_BASE_DIRECTORY . DIRECTORY_SEPARATOR . 'functions.php';
$input = new PMXI_Input();
$post = $input->post('data', '');
$response = wp_remote_post('http://phpcodechecker.com/api', array('body' => array('code' => $post)));
if (is_wp_error($response)) {
$error_message = $response->get_error_message();
exit(json_encode(array('result' => false, 'msg' => $error_message)));
die;
} else {
$body = json_decode(wp_remote_retrieve_body($response), true);
if ($body['errors'] === 'TRUE') {
exit(json_encode(array('result' => false, 'msg' => $body['syntax']['message'])));
die;
} elseif ($body['errors'] === 'FALSE') {
if (strpos($post, "<?php") === false || strpos($post, "?>") === false) {
exit(json_encode(array('result' => false, 'msg' => __('PHP code must be wrapped in "<?php" and "?>"', 'wp_all_import_plugin'))));
die;
} else {
file_put_contents($functions, $post);
}
}
}
exit(json_encode(array('result' => true, 'msg' => __('File has been successfully updated.', 'wp_all_import_plugin'))));
die;
}
示例7: fetch
/**
* 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;
}
示例8: parse_gateway_notification
/**
* parse_gateway_notification method, receives data from the payment gateway
* @access private
*/
function parse_gateway_notification()
{
/// PayPal first expects the IPN variables to be returned to it within 30 seconds, so we do this first.
if ('sandbox' == get_option('paypal_certified_server_type')) {
$paypal_url = "https://www.sandbox.paypal.com/webscr";
} else {
$API_Endpoint = "https://api-3t.paypal.com/nvp";
$paypal_url = "https://www.paypal.com/cgi-bin/webscr";
}
$received_values = array();
$received_values['cmd'] = '_notify-validate';
$received_values += stripslashes_deep($_POST);
$options = array('timeout' => 20, 'body' => $received_values, 'httpversion' => '1.1', 'user-agent' => 'WP e-Commerce/' . WPSC_PRESENTABLE_VERSION);
$response = wp_remote_post($paypal_url, $options);
do_action('wpsc_paypal_express_ipn', $received_values, $this);
if ('VERIFIED' == $response['body']) {
$this->paypal_ipn_values = $received_values;
$this->session_id = $received_values['invoice'];
if (strtolower($received_values['payment_status']) == 'completed') {
$this->set_purchase_processed_by_sessionid(3);
transaction_results($this->session_id, false);
} elseif (strtolower($received_values['payment_status']) == 'denied') {
$this->set_purchase_processed_by_sessionid(6);
}
} else {
exit("IPN Request Failure");
}
}
示例9: plugins_api
/**
* Retrieve plugin installer pages from WordPress Plugins API.
*
* It is possible for a plugin to override the Plugin API result with three
* filters. Assume this is for plugins, which can extend on the Plugin Info to
* offer more choices. This is very powerful and must be used with care, when
* overridding the filters.
*
* The first filter, 'plugins_api_args', is for the args and gives the action as
* the second parameter. The hook for 'plugins_api_args' must ensure that an
* object is returned.
*
* The second filter, 'plugins_api', is the result that would be returned.
*
* @since 2.7.0
*
* @param string $action
* @param array|object $args Optional. Arguments to serialize for the Plugin Info API.
* @return mixed
*/
function plugins_api($action, $args = null)
{
if (is_array($args)) {
$args = (object) $args;
}
if (!isset($args->per_page)) {
$args->per_page = 24;
}
$args = apply_filters('plugins_api_args', $args, $action);
//NOTE: Ensure that an object is returned via this filter.
$res = apply_filters('plugins_api', false, $action, $args);
//NOTE: Allows a plugin to completely override the builtin WordPress.org API.
if (!$res) {
$request = wp_remote_post('http://api.wordpress.org/plugins/info/1.0/', array('body' => array('action' => $action, 'request' => serialize($args))));
if (is_wp_error($request)) {
$res = new WP_Error('plugins_api_failed', __('An Unexpected HTTP Error occurred during the API request.</p> <p><a href="?" onclick="document.location.reload(); return false;">Try again</a>'), $request->get_error_message());
} else {
$res = unserialize($request['body']);
if (!$res) {
$res = new WP_Error('plugins_api_failed', __('An unknown error occurred'), $request['body']);
}
}
}
return apply_filters('plugins_api_result', $res, $action, $args);
}
示例10: call_remote_api
/**
* Calls the API and, if successfull, returns the object delivered by the API.
*
* @uses get_bloginfo()
* @uses wp_remote_post()
* @uses is_wp_error()
*
* @return false||object
*/
protected function call_remote_api()
{
// only check if a transient is not set (or if it's expired)
if (get_transient($this->product->get_slug() . '-update-check-error') !== false) {
return;
}
// setup api parameters
$api_params = array('edd_action' => 'get_version', 'license' => $this->license_key, 'name' => $this->product->get_item_name(), 'slug' => $this->product->get_slug(), 'author' => $this->product->get_author());
// setup request parameters
$request_params = array('timeout' => 15, 'sslverify' => false, 'body' => $api_params);
// call remote api
$response = wp_remote_post($this->product->get_api_url(), $request_params);
// wp / http error?
if (is_wp_error($response)) {
$this->wp_error = $response;
// show error to user
add_action('admin_notices', array($this, 'show_update_error'));
// set a transient to prevent checking for updates on every page load
set_transient($this->product->get_slug() . '-update-check-error', true, 60 * 30);
// 30 mins
return false;
}
// decode response
$response = json_decode(wp_remote_retrieve_body($response));
$response->sections = maybe_unserialize($response->sections);
return $response;
}
示例11: doRequests
public function doRequests($URLs, $Blocking, $ID)
{
$requestParameters = array('plugin_version' => PLUGIN_VERSION, 'key' => $this->_apiKey, 'lossy' => $this->_compressionType, 'cmyk2rgb' => $this->_CMYKtoRGBconversion, 'resize' => $this->_resizeImages, 'resize_width' => $this->_resizeWidth, 'resize_height' => $this->_resizeHeight, 'urllist' => $URLs);
$arguments = array('method' => 'POST', 'timeout' => 45, 'redirection' => 3, 'sslverify' => false, 'httpversion' => '1.0', 'blocking' => $Blocking, 'headers' => array(), 'body' => json_encode($requestParameters), 'cookies' => array());
$response = wp_remote_post($this->_apiEndPoint, $arguments);
//only if $Blocking is true analyze the response
if ($Blocking) {
//there was an error, save this error inside file's SP optimization field
if (is_object($response) && get_class($response) == 'WP_Error') {
$errorMessage = $response->errors['http_request_failed'][0];
$errorCode = 503;
} elseif (isset($response['response']['code']) && $response['response']['code'] != 200) {
$errorMessage = $response['response']['code'] . " - " . $response['response']['message'];
$errorCode = $response['response']['code'];
}
if (isset($errorMessage)) {
//set details inside file so user can know what happened
$meta = wp_get_attachment_metadata($ID);
$meta['ShortPixelImprovement'] = 'Error: <i>' . $errorMessage . '</i>';
unset($meta['ShortPixel']['WaitingProcessing']);
wp_update_attachment_metadata($ID, $meta);
return array("response" => array("code" => $errorCode, "message" => $errorMessage));
}
return $response;
//this can be an error or a good response
}
return $response;
}
示例12: check_for_update
function check_for_update($transient)
{
global $wp_filesystem;
$avada_options = get_option('Avada_Key');
if (empty($transient->checked)) {
return $transient;
}
$request_args = array('id' => $this->theme_id, 'slug' => $this->theme_slug, 'version' => $transient->checked[$this->theme_slug]);
if ($this->api_url == 'http://updates.theme-fusion.com/avada-theme.php') {
$request_args['item_code'] = '2833226';
$request_args['envato_username'] = $avada_options['tf_username'];
$request_args['api_key'] = $avada_options['tf_api'];
}
$filename = trailingslashit(get_template_directory()) . 'log.txt';
$request_string = $this->prepare_request('theme_update', $request_args);
$raw_response = wp_remote_post($this->api_url, $request_string);
$response = null;
if (!is_wp_error($raw_response) && $raw_response['response']['code'] == 200) {
$response = json_decode($raw_response['body'], true);
}
if (!empty($response)) {
// Feed the update data into WP updater
$transient->response[$this->theme_slug] = $response;
}
/*$handle = fopen($filename, 'a');
fwrite($handle, json_encode($request_string));
fwrite($handle, json_encode($raw_response));*/
return $transient;
}
示例13: AtD_http_post
/**
* Returns array with headers in $response[0] and body in $response[1]
* Based on a function from Akismet
*/
function AtD_http_post($request, $host, $path, $port = 80)
{
$http_args = array('body' => $request, 'headers' => array('Content-Type' => 'application/x-www-form-urlencoded; charset=' . get_option('blog_charset'), 'Host' => $host, 'User-Agent' => 'AtD/0.1'), 'httpversion' => '1.0', 'timeout' => apply_filters('atd_http_post_timeout', 15));
// Handle non-standard ports being passed in.
if (80 !== $port && is_numeric($port) && intval($port) > 0) {
$host .= ':' . intval($port);
}
// Strip any / off the begining so we can add it back and protect against SSRF
$path = ltrim($path, '/');
$AtD_url = set_url_scheme("http://{$host}/{$path}");
$response = wp_remote_post($AtD_url, $http_args);
$code = (int) wp_remote_retrieve_response_code($response);
if (is_wp_error($response)) {
/**
* Fires when there is a post error to AtD.
*
* @since 1.2.3
*
* @param int|string http-error The error that AtD runs into.
*/
do_action('atd_http_post_error', 'http-error');
return array();
} elseif (200 != $code) {
/** This action is documented in modules/after-the-deadline/proxy.php */
do_action('atd_http_post_error', $code);
}
return array(wp_remote_retrieve_headers($response), wp_remote_retrieve_body($response));
}
示例14: call
public function call($operation, $params = array())
{
$url = self::URL . '/' . $operation;
$params['blog'] = $this->blog;
if ($this->ready()) {
$params['token'] = $this->token;
}
$response = wp_remote_post($url, array('body' => $params, 'timeout' => 0));
if (is_wp_error($response)) {
die($response->get_error_message());
}
$response = json_decode($response['body']);
if (property_exists($response, 'error')) {
if (is_object($response->error)) {
die($response->error->message);
} elseif ($response->code == 'invalid-session') {
throw new ClientInvalidSession();
} else {
die($response->error);
}
}
if (property_exists($response, 'token')) {
update_option(self::TOKEN, $response->token);
}
return $response;
}
示例15: validate_themes
protected function validate_themes()
{
if (empty($this->themes) || !is_array($this->themes)) {
return new WP_Error('missing_themes', __('No themes found.', 'jetpack'));
}
foreach ($this->themes as $index => $theme) {
if (self::is_installed_theme($theme)) {
return new WP_Error('theme_already_installed', __('The theme is already installed', 'jetpack'));
}
if (wp_endswith($theme, '-wpcom')) {
$file = self::download_wpcom_theme_to_file($theme);
if (is_wp_error($file)) {
return $file;
}
$this->download_links[$theme] = $file;
continue;
}
$params = (object) array('slug' => $theme);
$url = 'https://api.wordpress.org/themes/info/1.0/';
$args = array('body' => array('action' => 'theme_information', 'request' => serialize($params)));
$response = wp_remote_post($url, $args);
$theme_data = unserialize($response['body']);
if (is_wp_error($theme_data)) {
return $theme_data;
}
if (!is_object($theme_data) && !isset($theme_data->download_link)) {
return new WP_Error('theme_not_found', __('This theme does not exist', 'jetpack'), 404);
}
$this->download_links[$theme] = $theme_data->download_link;
}
return true;
}