當前位置: 首頁>>代碼示例>>PHP>>正文


PHP WP_CLI::error_log方法代碼示例

本文整理匯總了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());
        }
    }
}
開發者ID:voldemortensen,項目名稱:wp-cli,代碼行數:53,代碼來源:utils.php


注:本文中的WP_CLI::error_log方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。