Edit File by line
/home/zeestwma/ajeebong.../wp-inclu...
File: https-detection.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* HTTPS detection functions.
[2] Fix | Delete
*
[3] Fix | Delete
* @package WordPress
[4] Fix | Delete
* @since 5.7.0
[5] Fix | Delete
*/
[6] Fix | Delete
[7] Fix | Delete
/**
[8] Fix | Delete
* Checks whether the website is using HTTPS.
[9] Fix | Delete
*
[10] Fix | Delete
* This is based on whether both the home and site URL are using HTTPS.
[11] Fix | Delete
*
[12] Fix | Delete
* @since 5.7.0
[13] Fix | Delete
* @see wp_is_home_url_using_https()
[14] Fix | Delete
* @see wp_is_site_url_using_https()
[15] Fix | Delete
*
[16] Fix | Delete
* @return bool True if using HTTPS, false otherwise.
[17] Fix | Delete
*/
[18] Fix | Delete
function wp_is_using_https() {
[19] Fix | Delete
if ( ! wp_is_home_url_using_https() ) {
[20] Fix | Delete
return false;
[21] Fix | Delete
}
[22] Fix | Delete
[23] Fix | Delete
return wp_is_site_url_using_https();
[24] Fix | Delete
}
[25] Fix | Delete
[26] Fix | Delete
/**
[27] Fix | Delete
* Checks whether the current site URL is using HTTPS.
[28] Fix | Delete
*
[29] Fix | Delete
* @since 5.7.0
[30] Fix | Delete
* @see home_url()
[31] Fix | Delete
*
[32] Fix | Delete
* @return bool True if using HTTPS, false otherwise.
[33] Fix | Delete
*/
[34] Fix | Delete
function wp_is_home_url_using_https() {
[35] Fix | Delete
return 'https' === wp_parse_url( home_url(), PHP_URL_SCHEME );
[36] Fix | Delete
}
[37] Fix | Delete
[38] Fix | Delete
/**
[39] Fix | Delete
* Checks whether the current site's URL where WordPress is stored is using HTTPS.
[40] Fix | Delete
*
[41] Fix | Delete
* This checks the URL where WordPress application files (e.g. wp-blog-header.php or the wp-admin/ folder)
[42] Fix | Delete
* are accessible.
[43] Fix | Delete
*
[44] Fix | Delete
* @since 5.7.0
[45] Fix | Delete
* @see site_url()
[46] Fix | Delete
*
[47] Fix | Delete
* @return bool True if using HTTPS, false otherwise.
[48] Fix | Delete
*/
[49] Fix | Delete
function wp_is_site_url_using_https() {
[50] Fix | Delete
/*
[51] Fix | Delete
* Use direct option access for 'siteurl' and manually run the 'site_url'
[52] Fix | Delete
* filter because `site_url()` will adjust the scheme based on what the
[53] Fix | Delete
* current request is using.
[54] Fix | Delete
*/
[55] Fix | Delete
/** This filter is documented in wp-includes/link-template.php */
[56] Fix | Delete
$site_url = apply_filters( 'site_url', get_option( 'siteurl' ), '', null, null );
[57] Fix | Delete
[58] Fix | Delete
return 'https' === wp_parse_url( $site_url, PHP_URL_SCHEME );
[59] Fix | Delete
}
[60] Fix | Delete
[61] Fix | Delete
/**
[62] Fix | Delete
* Checks whether HTTPS is supported for the server and domain.
[63] Fix | Delete
*
[64] Fix | Delete
* This function makes an HTTP request through `wp_get_https_detection_errors()`
[65] Fix | Delete
* to check for HTTPS support. As this process can be resource-intensive,
[66] Fix | Delete
* it should be used cautiously, especially in performance-sensitive environments,
[67] Fix | Delete
* to avoid potential latency issues.
[68] Fix | Delete
*
[69] Fix | Delete
* @since 5.7.0
[70] Fix | Delete
*
[71] Fix | Delete
* @return bool True if HTTPS is supported, false otherwise.
[72] Fix | Delete
*/
[73] Fix | Delete
function wp_is_https_supported() {
[74] Fix | Delete
$https_detection_errors = wp_get_https_detection_errors();
[75] Fix | Delete
[76] Fix | Delete
// If there are errors, HTTPS is not supported.
[77] Fix | Delete
return empty( $https_detection_errors );
[78] Fix | Delete
}
[79] Fix | Delete
[80] Fix | Delete
/**
[81] Fix | Delete
* Runs a remote HTTPS request to detect whether HTTPS supported, and stores potential errors.
[82] Fix | Delete
*
[83] Fix | Delete
* This function checks for HTTPS support by making an HTTP request. As this process can be resource-intensive,
[84] Fix | Delete
* it should be used cautiously, especially in performance-sensitive environments.
[85] Fix | Delete
* It is called when HTTPS support needs to be validated.
[86] Fix | Delete
*
[87] Fix | Delete
* @since 6.4.0
[88] Fix | Delete
* @access private
[89] Fix | Delete
*
[90] Fix | Delete
* @return array An array containing potential detection errors related to HTTPS, or an empty array if no errors are found.
[91] Fix | Delete
*/
[92] Fix | Delete
function wp_get_https_detection_errors() {
[93] Fix | Delete
/**
[94] Fix | Delete
* Short-circuits the process of detecting errors related to HTTPS support.
[95] Fix | Delete
*
[96] Fix | Delete
* Returning a `WP_Error` from the filter will effectively short-circuit the default logic of trying a remote
[97] Fix | Delete
* request to the site over HTTPS, storing the errors array from the returned `WP_Error` instead.
[98] Fix | Delete
*
[99] Fix | Delete
* @since 6.4.0
[100] Fix | Delete
*
[101] Fix | Delete
* @param null|WP_Error $pre Error object to short-circuit detection,
[102] Fix | Delete
* or null to continue with the default behavior.
[103] Fix | Delete
*/
[104] Fix | Delete
$support_errors = apply_filters( 'pre_wp_get_https_detection_errors', null );
[105] Fix | Delete
if ( is_wp_error( $support_errors ) ) {
[106] Fix | Delete
return $support_errors->errors;
[107] Fix | Delete
}
[108] Fix | Delete
[109] Fix | Delete
$support_errors = new WP_Error();
[110] Fix | Delete
[111] Fix | Delete
$response = wp_remote_request(
[112] Fix | Delete
home_url( '/', 'https' ),
[113] Fix | Delete
array(
[114] Fix | Delete
'headers' => array(
[115] Fix | Delete
'Cache-Control' => 'no-cache',
[116] Fix | Delete
),
[117] Fix | Delete
'sslverify' => true,
[118] Fix | Delete
)
[119] Fix | Delete
);
[120] Fix | Delete
[121] Fix | Delete
if ( is_wp_error( $response ) ) {
[122] Fix | Delete
$unverified_response = wp_remote_request(
[123] Fix | Delete
home_url( '/', 'https' ),
[124] Fix | Delete
array(
[125] Fix | Delete
'headers' => array(
[126] Fix | Delete
'Cache-Control' => 'no-cache',
[127] Fix | Delete
),
[128] Fix | Delete
'sslverify' => false,
[129] Fix | Delete
)
[130] Fix | Delete
);
[131] Fix | Delete
[132] Fix | Delete
if ( is_wp_error( $unverified_response ) ) {
[133] Fix | Delete
$support_errors->add(
[134] Fix | Delete
'https_request_failed',
[135] Fix | Delete
__( 'HTTPS request failed.' )
[136] Fix | Delete
);
[137] Fix | Delete
} else {
[138] Fix | Delete
$support_errors->add(
[139] Fix | Delete
'ssl_verification_failed',
[140] Fix | Delete
__( 'SSL verification failed.' )
[141] Fix | Delete
);
[142] Fix | Delete
}
[143] Fix | Delete
[144] Fix | Delete
$response = $unverified_response;
[145] Fix | Delete
}
[146] Fix | Delete
[147] Fix | Delete
if ( ! is_wp_error( $response ) ) {
[148] Fix | Delete
if ( 200 !== wp_remote_retrieve_response_code( $response ) ) {
[149] Fix | Delete
$support_errors->add( 'bad_response_code', wp_remote_retrieve_response_message( $response ) );
[150] Fix | Delete
} elseif ( false === wp_is_local_html_output( wp_remote_retrieve_body( $response ) ) ) {
[151] Fix | Delete
$support_errors->add( 'bad_response_source', __( 'It looks like the response did not come from this site.' ) );
[152] Fix | Delete
}
[153] Fix | Delete
}
[154] Fix | Delete
[155] Fix | Delete
return $support_errors->errors;
[156] Fix | Delete
}
[157] Fix | Delete
[158] Fix | Delete
/**
[159] Fix | Delete
* Checks whether a given HTML string is likely an output from this WordPress site.
[160] Fix | Delete
*
[161] Fix | Delete
* This function attempts to check for various common WordPress patterns whether they are included in the HTML string.
[162] Fix | Delete
* Since any of these actions may be disabled through third-party code, this function may also return null to indicate
[163] Fix | Delete
* that it was not possible to determine ownership.
[164] Fix | Delete
*
[165] Fix | Delete
* @since 5.7.0
[166] Fix | Delete
* @access private
[167] Fix | Delete
*
[168] Fix | Delete
* @param string $html Full HTML output string, e.g. from a HTTP response.
[169] Fix | Delete
* @return bool|null True/false for whether HTML was generated by this site, null if unable to determine.
[170] Fix | Delete
*/
[171] Fix | Delete
function wp_is_local_html_output( $html ) {
[172] Fix | Delete
// 1. Check if HTML includes the site's Really Simple Discovery link.
[173] Fix | Delete
if ( has_action( 'wp_head', 'rsd_link' ) ) {
[174] Fix | Delete
$pattern = preg_replace( '#^https?:(?=//)#', '', esc_url( site_url( 'xmlrpc.php?rsd', 'rpc' ) ) ); // See rsd_link().
[175] Fix | Delete
return str_contains( $html, $pattern );
[176] Fix | Delete
}
[177] Fix | Delete
[178] Fix | Delete
// 2. Check if HTML includes the site's REST API link.
[179] Fix | Delete
if ( has_action( 'wp_head', 'rest_output_link_wp_head' ) ) {
[180] Fix | Delete
// Try both HTTPS and HTTP since the URL depends on context.
[181] Fix | Delete
$pattern = preg_replace( '#^https?:(?=//)#', '', esc_url( get_rest_url() ) ); // See rest_output_link_wp_head().
[182] Fix | Delete
return str_contains( $html, $pattern );
[183] Fix | Delete
}
[184] Fix | Delete
[185] Fix | Delete
// Otherwise the result cannot be determined.
[186] Fix | Delete
return null;
[187] Fix | Delete
}
[188] Fix | Delete
[189] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function