Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93
/home/sportsfe.../httpdocs/wp-conte.../plugins/string-l.../includes/Tests
File: class-loopback.php
<?php
[0] Fix | Delete
[1] Fix | Delete
namespace StringLocator\Tests;
[2] Fix | Delete
[3] Fix | Delete
class Loopback {
[4] Fix | Delete
/**
[5] Fix | Delete
* An array of HTTP status codes that will trigger the rollback feature.
[6] Fix | Delete
*
[7] Fix | Delete
* @var string[]
[8] Fix | Delete
*/
[9] Fix | Delete
private $bad_http_codes = array( '500' );
[10] Fix | Delete
[11] Fix | Delete
/**
[12] Fix | Delete
* An array holding any errors returned during testing.
[13] Fix | Delete
*
[14] Fix | Delete
* @var array
[15] Fix | Delete
*/
[16] Fix | Delete
public $errors = array();
[17] Fix | Delete
[18] Fix | Delete
/**
[19] Fix | Delete
* Loopback constructor.
[20] Fix | Delete
*/
[21] Fix | Delete
public function __construct() {
[22] Fix | Delete
add_action( 'string_locator_editor_checks', array( $this, 'print_checks_option' ) );
[23] Fix | Delete
[24] Fix | Delete
add_filter( 'string_locator_post_save', array( $this, 'maybe_perform_test' ) );
[25] Fix | Delete
add_filter( 'string_locator_post_save_fail_notice', array( $this, 'return_failure_notices' ) );
[26] Fix | Delete
}
[27] Fix | Delete
[28] Fix | Delete
public function return_failure_notices( $notices ) {
[29] Fix | Delete
if ( empty( $this->errors ) ) {
[30] Fix | Delete
return $notices;
[31] Fix | Delete
}
[32] Fix | Delete
[33] Fix | Delete
return array_merge(
[34] Fix | Delete
$notices,
[35] Fix | Delete
$this->errors
[36] Fix | Delete
);
[37] Fix | Delete
}
[38] Fix | Delete
[39] Fix | Delete
public function maybe_perform_test( $save_successful ) {
[40] Fix | Delete
// If another addon has determined the save is a failure, don't perform the test.
[41] Fix | Delete
if ( ! $save_successful ) {
[42] Fix | Delete
return $save_successful;
[43] Fix | Delete
}
[44] Fix | Delete
[45] Fix | Delete
// Do not run this check if it has been disabled.
[46] Fix | Delete
if ( ! isset( $_POST['string-locator-loopback-check'] ) ) {
[47] Fix | Delete
return $save_successful;
[48] Fix | Delete
}
[49] Fix | Delete
[50] Fix | Delete
return $this->run();
[51] Fix | Delete
}
[52] Fix | Delete
[53] Fix | Delete
public function print_checks_option() {
[54] Fix | Delete
?>
[55] Fix | Delete
[56] Fix | Delete
<div class="row">
[57] Fix | Delete
<label>
[58] Fix | Delete
<input type="checkbox" name="string-locator-loopback-check" checked="checked">
[59] Fix | Delete
<?php esc_html_e( 'Enable loopback tests after making a save.', 'string-locator' ); ?>
[60] Fix | Delete
</label>
[61] Fix | Delete
<br>
[62] Fix | Delete
<em>
[63] Fix | Delete
<?php esc_html_e( 'This feature is highly recommended, and is what WordPress does when using the plugin- or theme-editor.', 'string-locator' ); ?>
[64] Fix | Delete
</em>
[65] Fix | Delete
</div>
[66] Fix | Delete
[67] Fix | Delete
<?php
[68] Fix | Delete
}
[69] Fix | Delete
[70] Fix | Delete
/**
[71] Fix | Delete
* A helper function to return any errors.
[72] Fix | Delete
*
[73] Fix | Delete
* @return array
[74] Fix | Delete
*/
[75] Fix | Delete
public function get_errors() {
[76] Fix | Delete
return $this->errors;
[77] Fix | Delete
}
[78] Fix | Delete
[79] Fix | Delete
/**
[80] Fix | Delete
* Main test runner.
[81] Fix | Delete
*
[82] Fix | Delete
* @return bool
[83] Fix | Delete
*/
[84] Fix | Delete
public function run() {
[85] Fix | Delete
$this->bad_http_codes = apply_filters( 'string_locator_bad_http_codes', $this->bad_http_codes );
[86] Fix | Delete
[87] Fix | Delete
// Clear the error log before doing a new request.
[88] Fix | Delete
$this->errors = array();
[89] Fix | Delete
[90] Fix | Delete
$frontend = $this->test_frontend();
[91] Fix | Delete
[92] Fix | Delete
// If the frontend has a loopback error, return it immediately.
[93] Fix | Delete
if ( ! $frontend ) {
[94] Fix | Delete
return false;
[95] Fix | Delete
}
[96] Fix | Delete
[97] Fix | Delete
// If frontend tests are fine, we return the result of the backend scan.
[98] Fix | Delete
return $this->test_backend();
[99] Fix | Delete
}
[100] Fix | Delete
[101] Fix | Delete
private function test_frontend() {
[102] Fix | Delete
$header = wp_remote_head( site_url() );
[103] Fix | Delete
[104] Fix | Delete
// If we get redirected, follow the redirect.
[105] Fix | Delete
if ( ! is_wp_error( $header ) && 301 === (int) $header['response']['code'] ) {
[106] Fix | Delete
$header = wp_remote_head( $header['headers']['location'] );
[107] Fix | Delete
}
[108] Fix | Delete
[109] Fix | Delete
if ( is_wp_error( $header ) ) {
[110] Fix | Delete
if ( 'http_request_failed' === $header->get_error_code() ) {
[111] Fix | Delete
$this->errors[] = array(
[112] Fix | Delete
'type' => 'error',
[113] Fix | Delete
'message' => __( 'Your changes were not saved, as a check of your site could not be completed afterwards. This may be due to a <a href="https://wordpress.org/support/article/loopbacks/">loopback</a> error.', 'string-locator' ),
[114] Fix | Delete
);
[115] Fix | Delete
[116] Fix | Delete
return false;
[117] Fix | Delete
}
[118] Fix | Delete
[119] Fix | Delete
// Fallback error message here.
[120] Fix | Delete
$this->errors[] = array(
[121] Fix | Delete
'type' => 'error',
[122] Fix | Delete
'message' => $header->get_error_message(),
[123] Fix | Delete
);
[124] Fix | Delete
[125] Fix | Delete
return false;
[126] Fix | Delete
}
[127] Fix | Delete
[128] Fix | Delete
if ( in_array( $header['response']['code'], $this->bad_http_codes, true ) ) {
[129] Fix | Delete
$this->errors[] = array(
[130] Fix | Delete
'type' => 'error',
[131] Fix | Delete
'message' => __( 'A 500 server error was detected on your site after updating your file. We have restored the previous version of the file for you.', 'string-locator' ),
[132] Fix | Delete
);
[133] Fix | Delete
[134] Fix | Delete
return false;
[135] Fix | Delete
}
[136] Fix | Delete
[137] Fix | Delete
return true;
[138] Fix | Delete
}
[139] Fix | Delete
[140] Fix | Delete
private function test_backend() {
[141] Fix | Delete
$header = wp_remote_head( admin_url() );
[142] Fix | Delete
[143] Fix | Delete
// If we get redirected, follow the redirect.
[144] Fix | Delete
if ( ! is_wp_error( $header ) && 301 === (int) $header['response']['code'] ) {
[145] Fix | Delete
$header = wp_remote_head( $header['headers']['location'] );
[146] Fix | Delete
}
[147] Fix | Delete
[148] Fix | Delete
if ( is_wp_error( $header ) ) {
[149] Fix | Delete
if ( 'http_request_failed' === $header->get_error_code() ) {
[150] Fix | Delete
$this->errors[] = array(
[151] Fix | Delete
'type' => 'error',
[152] Fix | Delete
'message' => __( 'Your changes were not saved, as a check of your sites backend could not be completed afterwards. This may be due to a <a href="https://wordpress.org/support/article/loopbacks/">loopback</a> error.', 'string-locator' ),
[153] Fix | Delete
);
[154] Fix | Delete
[155] Fix | Delete
return false;
[156] Fix | Delete
}
[157] Fix | Delete
[158] Fix | Delete
// Fallback error message here.
[159] Fix | Delete
$this->errors[] = array(
[160] Fix | Delete
'type' => 'error',
[161] Fix | Delete
'message' => $header->get_error_message(),
[162] Fix | Delete
);
[163] Fix | Delete
[164] Fix | Delete
return false;
[165] Fix | Delete
}
[166] Fix | Delete
[167] Fix | Delete
if ( in_array( $header['response']['code'], $this->bad_http_codes, true ) ) {
[168] Fix | Delete
$this->errors[] = array(
[169] Fix | Delete
'type' => 'error',
[170] Fix | Delete
'message' => __( 'A 500 server error was detected on your sites backend after updating your file. We have restored the previous version of the file for you.', 'string-locator' ),
[171] Fix | Delete
);
[172] Fix | Delete
[173] Fix | Delete
return false;
[174] Fix | Delete
}
[175] Fix | Delete
[176] Fix | Delete
return true;
[177] Fix | Delete
}
[178] Fix | Delete
}
[179] Fix | Delete
[180] Fix | Delete
new Loopback();
[181] Fix | Delete
[182] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function