本文整理汇总了PHP中WP_CLI::error_log方法的典型用法代码示例。如果您正苦于以下问题:PHP WP_CLI::error_log方法的具体用法?PHP WP_CLI::error_log怎么用?PHP WP_CLI::error_log使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WP_CLI
的用法示例。
在下文中一共展示了WP_CLI::error_log方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: http_request
/**
* Make a HTTP request to a remote URL.
*
* Wraps the Requests HTTP library to ensure every request includes a cert.
*
* ```
* # `wp core download` verifies the hash for a downloaded WordPress archive
*
* $md5_response = Utils\http_request( 'GET', $download_url . '.md5' );
* if ( 20 != substr( $md5_response->status_code, 0, 2 ) ) {
* WP_CLI::error( "Couldn't access md5 hash for release (HTTP code {$response->status_code})" );
* }
* ```
*
* @access public
*
* @param string $method HTTP method (GET, POST, DELETE, etc.)
* @param string $url URL to make the HTTP request to.
* @param array $headers Add specific headers to the request.
* @param array $options
* @return object
*/
function http_request($method, $url, $data = null, $headers = array(), $options = array())
{
$cert_path = '/rmccue/requests/library/Requests/Transport/cacert.pem';
if (inside_phar()) {
// cURL can't read Phar archives
$options['verify'] = extract_from_phar(WP_CLI_ROOT . '/vendor' . $cert_path);
} else {
foreach (get_vendor_paths() as $vendor_path) {
if (file_exists($vendor_path . $cert_path)) {
$options['verify'] = $vendor_path . $cert_path;
break;
}
}
if (empty($options['verify'])) {
WP_CLI::error_log("Cannot find SSL certificate.");
}
}
try {
$request = \Requests::request($url, $headers, $data, $method, $options);
return $request;
} catch (\Requests_Exception $ex) {
// Handle SSL certificate issues gracefully
\WP_CLI::warning($ex->getMessage());
$options['verify'] = false;
try {
return \Requests::request($url, $headers, $data, $method, $options);
} catch (\Requests_Exception $ex) {
\WP_CLI::error($ex->getMessage());
}
}
}