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/clone/wp-inclu...
File: class-wp-recovery-mode-email-service.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* Error Protection API: WP_Recovery_Mode_Email_Link class
[2] Fix | Delete
*
[3] Fix | Delete
* @package WordPress
[4] Fix | Delete
* @since 5.2.0
[5] Fix | Delete
*/
[6] Fix | Delete
[7] Fix | Delete
/**
[8] Fix | Delete
* Core class used to send an email with a link to begin Recovery Mode.
[9] Fix | Delete
*
[10] Fix | Delete
* @since 5.2.0
[11] Fix | Delete
*/
[12] Fix | Delete
#[AllowDynamicProperties]
[13] Fix | Delete
final class WP_Recovery_Mode_Email_Service {
[14] Fix | Delete
[15] Fix | Delete
const RATE_LIMIT_OPTION = 'recovery_mode_email_last_sent';
[16] Fix | Delete
[17] Fix | Delete
/**
[18] Fix | Delete
* Service to generate recovery mode URLs.
[19] Fix | Delete
*
[20] Fix | Delete
* @since 5.2.0
[21] Fix | Delete
* @var WP_Recovery_Mode_Link_Service
[22] Fix | Delete
*/
[23] Fix | Delete
private $link_service;
[24] Fix | Delete
[25] Fix | Delete
/**
[26] Fix | Delete
* WP_Recovery_Mode_Email_Service constructor.
[27] Fix | Delete
*
[28] Fix | Delete
* @since 5.2.0
[29] Fix | Delete
*
[30] Fix | Delete
* @param WP_Recovery_Mode_Link_Service $link_service
[31] Fix | Delete
*/
[32] Fix | Delete
public function __construct( WP_Recovery_Mode_Link_Service $link_service ) {
[33] Fix | Delete
$this->link_service = $link_service;
[34] Fix | Delete
}
[35] Fix | Delete
[36] Fix | Delete
/**
[37] Fix | Delete
* Sends the recovery mode email if the rate limit has not been sent.
[38] Fix | Delete
*
[39] Fix | Delete
* @since 5.2.0
[40] Fix | Delete
*
[41] Fix | Delete
* @param int $rate_limit Number of seconds before another email can be sent.
[42] Fix | Delete
* @param array $error Error details from `error_get_last()`.
[43] Fix | Delete
* @param array $extension {
[44] Fix | Delete
* The extension that caused the error.
[45] Fix | Delete
*
[46] Fix | Delete
* @type string $slug The extension slug. The plugin or theme's directory.
[47] Fix | Delete
* @type string $type The extension type. Either 'plugin' or 'theme'.
[48] Fix | Delete
* }
[49] Fix | Delete
* @return true|WP_Error True if email sent, WP_Error otherwise.
[50] Fix | Delete
*/
[51] Fix | Delete
public function maybe_send_recovery_mode_email( $rate_limit, $error, $extension ) {
[52] Fix | Delete
[53] Fix | Delete
$last_sent = get_option( self::RATE_LIMIT_OPTION );
[54] Fix | Delete
[55] Fix | Delete
if ( ! $last_sent || time() > $last_sent + $rate_limit ) {
[56] Fix | Delete
if ( ! update_option( self::RATE_LIMIT_OPTION, time() ) ) {
[57] Fix | Delete
return new WP_Error( 'storage_error', __( 'Could not update the email last sent time.' ) );
[58] Fix | Delete
}
[59] Fix | Delete
[60] Fix | Delete
$sent = $this->send_recovery_mode_email( $rate_limit, $error, $extension );
[61] Fix | Delete
[62] Fix | Delete
if ( $sent ) {
[63] Fix | Delete
return true;
[64] Fix | Delete
}
[65] Fix | Delete
[66] Fix | Delete
return new WP_Error(
[67] Fix | Delete
'email_failed',
[68] Fix | Delete
sprintf(
[69] Fix | Delete
/* translators: %s: mail() */
[70] Fix | Delete
__( 'The email could not be sent. Possible reason: your host may have disabled the %s function.' ),
[71] Fix | Delete
'mail()'
[72] Fix | Delete
)
[73] Fix | Delete
);
[74] Fix | Delete
}
[75] Fix | Delete
[76] Fix | Delete
$err_message = sprintf(
[77] Fix | Delete
/* translators: 1: Last sent as a human time diff, 2: Wait time as a human time diff. */
[78] Fix | Delete
__( 'A recovery link was already sent %1$s ago. Please wait another %2$s before requesting a new email.' ),
[79] Fix | Delete
human_time_diff( $last_sent ),
[80] Fix | Delete
human_time_diff( $last_sent + $rate_limit )
[81] Fix | Delete
);
[82] Fix | Delete
[83] Fix | Delete
return new WP_Error( 'email_sent_already', $err_message );
[84] Fix | Delete
}
[85] Fix | Delete
[86] Fix | Delete
/**
[87] Fix | Delete
* Clears the rate limit, allowing a new recovery mode email to be sent immediately.
[88] Fix | Delete
*
[89] Fix | Delete
* @since 5.2.0
[90] Fix | Delete
*
[91] Fix | Delete
* @return bool True on success, false on failure.
[92] Fix | Delete
*/
[93] Fix | Delete
public function clear_rate_limit() {
[94] Fix | Delete
return delete_option( self::RATE_LIMIT_OPTION );
[95] Fix | Delete
}
[96] Fix | Delete
[97] Fix | Delete
/**
[98] Fix | Delete
* Sends the Recovery Mode email to the site admin email address.
[99] Fix | Delete
*
[100] Fix | Delete
* @since 5.2.0
[101] Fix | Delete
*
[102] Fix | Delete
* @param int $rate_limit Number of seconds before another email can be sent.
[103] Fix | Delete
* @param array $error Error details from `error_get_last()`.
[104] Fix | Delete
* @param array $extension {
[105] Fix | Delete
* The extension that caused the error.
[106] Fix | Delete
*
[107] Fix | Delete
* @type string $slug The extension slug. The directory of the plugin or theme.
[108] Fix | Delete
* @type string $type The extension type. Either 'plugin' or 'theme'.
[109] Fix | Delete
* }
[110] Fix | Delete
* @return bool Whether the email was sent successfully.
[111] Fix | Delete
*/
[112] Fix | Delete
private function send_recovery_mode_email( $rate_limit, $error, $extension ) {
[113] Fix | Delete
[114] Fix | Delete
$url = $this->link_service->generate_url();
[115] Fix | Delete
$blogname = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES );
[116] Fix | Delete
[117] Fix | Delete
$switched_locale = switch_to_locale( get_locale() );
[118] Fix | Delete
[119] Fix | Delete
if ( $extension ) {
[120] Fix | Delete
$cause = $this->get_cause( $extension );
[121] Fix | Delete
$details = wp_strip_all_tags( wp_get_extension_error_description( $error ) );
[122] Fix | Delete
[123] Fix | Delete
if ( $details ) {
[124] Fix | Delete
$header = __( 'Error Details' );
[125] Fix | Delete
$details = "\n\n" . $header . "\n" . str_pad( '', strlen( $header ), '=' ) . "\n" . $details;
[126] Fix | Delete
}
[127] Fix | Delete
} else {
[128] Fix | Delete
$cause = '';
[129] Fix | Delete
$details = '';
[130] Fix | Delete
}
[131] Fix | Delete
[132] Fix | Delete
/**
[133] Fix | Delete
* Filters the support message sent with the the fatal error protection email.
[134] Fix | Delete
*
[135] Fix | Delete
* @since 5.2.0
[136] Fix | Delete
*
[137] Fix | Delete
* @param string $message The Message to include in the email.
[138] Fix | Delete
*/
[139] Fix | Delete
$support = apply_filters( 'recovery_email_support_info', __( 'Please contact your host for assistance with investigating this issue further.' ) );
[140] Fix | Delete
[141] Fix | Delete
/**
[142] Fix | Delete
* Filters the debug information included in the fatal error protection email.
[143] Fix | Delete
*
[144] Fix | Delete
* @since 5.3.0
[145] Fix | Delete
*
[146] Fix | Delete
* @param array $message An associative array of debug information.
[147] Fix | Delete
*/
[148] Fix | Delete
$debug = apply_filters( 'recovery_email_debug_info', $this->get_debug( $extension ) );
[149] Fix | Delete
[150] Fix | Delete
/* translators: Do not translate LINK, EXPIRES, CAUSE, DETAILS, SITEURL, PAGEURL, SUPPORT. DEBUG: those are placeholders. */
[151] Fix | Delete
$message = __(
[152] Fix | Delete
'Howdy!
[153] Fix | Delete
[154] Fix | Delete
WordPress has a built-in feature that detects when a plugin or theme causes a fatal error on your site, and notifies you with this automated email.
[155] Fix | Delete
###CAUSE###
[156] Fix | Delete
First, visit your website (###SITEURL###) and check for any visible issues. Next, visit the page where the error was caught (###PAGEURL###) and check for any visible issues.
[157] Fix | Delete
[158] Fix | Delete
###SUPPORT###
[159] Fix | Delete
[160] Fix | Delete
If your site appears broken and you can\'t access your dashboard normally, WordPress now has a special "recovery mode". This lets you safely login to your dashboard and investigate further.
[161] Fix | Delete
[162] Fix | Delete
###LINK###
[163] Fix | Delete
[164] Fix | Delete
To keep your site safe, this link will expire in ###EXPIRES###. Don\'t worry about that, though: a new link will be emailed to you if the error occurs again after it expires.
[165] Fix | Delete
[166] Fix | Delete
When seeking help with this issue, you may be asked for some of the following information:
[167] Fix | Delete
###DEBUG###
[168] Fix | Delete
[169] Fix | Delete
###DETAILS###'
[170] Fix | Delete
);
[171] Fix | Delete
$message = str_replace(
[172] Fix | Delete
array(
[173] Fix | Delete
'###LINK###',
[174] Fix | Delete
'###EXPIRES###',
[175] Fix | Delete
'###CAUSE###',
[176] Fix | Delete
'###DETAILS###',
[177] Fix | Delete
'###SITEURL###',
[178] Fix | Delete
'###PAGEURL###',
[179] Fix | Delete
'###SUPPORT###',
[180] Fix | Delete
'###DEBUG###',
[181] Fix | Delete
),
[182] Fix | Delete
array(
[183] Fix | Delete
$url,
[184] Fix | Delete
human_time_diff( time() + $rate_limit ),
[185] Fix | Delete
$cause ? "\n{$cause}\n" : "\n",
[186] Fix | Delete
$details,
[187] Fix | Delete
home_url( '/' ),
[188] Fix | Delete
home_url( $_SERVER['REQUEST_URI'] ),
[189] Fix | Delete
$support,
[190] Fix | Delete
implode( "\r\n", $debug ),
[191] Fix | Delete
),
[192] Fix | Delete
$message
[193] Fix | Delete
);
[194] Fix | Delete
[195] Fix | Delete
$email = array(
[196] Fix | Delete
'to' => $this->get_recovery_mode_email_address(),
[197] Fix | Delete
/* translators: %s: Site title. */
[198] Fix | Delete
'subject' => __( '[%s] Your Site is Experiencing a Technical Issue' ),
[199] Fix | Delete
'message' => $message,
[200] Fix | Delete
'headers' => '',
[201] Fix | Delete
'attachments' => '',
[202] Fix | Delete
);
[203] Fix | Delete
[204] Fix | Delete
/**
[205] Fix | Delete
* Filters the contents of the Recovery Mode email.
[206] Fix | Delete
*
[207] Fix | Delete
* @since 5.2.0
[208] Fix | Delete
* @since 5.6.0 The `$email` argument includes the `attachments` key.
[209] Fix | Delete
*
[210] Fix | Delete
* @param array $email {
[211] Fix | Delete
* Used to build a call to wp_mail().
[212] Fix | Delete
*
[213] Fix | Delete
* @type string|array $to Array or comma-separated list of email addresses to send message.
[214] Fix | Delete
* @type string $subject Email subject
[215] Fix | Delete
* @type string $message Message contents
[216] Fix | Delete
* @type string|array $headers Optional. Additional headers.
[217] Fix | Delete
* @type string|array $attachments Optional. Files to attach.
[218] Fix | Delete
* }
[219] Fix | Delete
* @param string $url URL to enter recovery mode.
[220] Fix | Delete
*/
[221] Fix | Delete
$email = apply_filters( 'recovery_mode_email', $email, $url );
[222] Fix | Delete
[223] Fix | Delete
$sent = wp_mail(
[224] Fix | Delete
$email['to'],
[225] Fix | Delete
wp_specialchars_decode( sprintf( $email['subject'], $blogname ) ),
[226] Fix | Delete
$email['message'],
[227] Fix | Delete
$email['headers'],
[228] Fix | Delete
$email['attachments']
[229] Fix | Delete
);
[230] Fix | Delete
[231] Fix | Delete
if ( $switched_locale ) {
[232] Fix | Delete
restore_previous_locale();
[233] Fix | Delete
}
[234] Fix | Delete
[235] Fix | Delete
return $sent;
[236] Fix | Delete
}
[237] Fix | Delete
[238] Fix | Delete
/**
[239] Fix | Delete
* Gets the email address to send the recovery mode link to.
[240] Fix | Delete
*
[241] Fix | Delete
* @since 5.2.0
[242] Fix | Delete
*
[243] Fix | Delete
* @return string Email address to send recovery mode link to.
[244] Fix | Delete
*/
[245] Fix | Delete
private function get_recovery_mode_email_address() {
[246] Fix | Delete
if ( defined( 'RECOVERY_MODE_EMAIL' ) && is_email( RECOVERY_MODE_EMAIL ) ) {
[247] Fix | Delete
return RECOVERY_MODE_EMAIL;
[248] Fix | Delete
}
[249] Fix | Delete
[250] Fix | Delete
return get_option( 'admin_email' );
[251] Fix | Delete
}
[252] Fix | Delete
[253] Fix | Delete
/**
[254] Fix | Delete
* Gets the description indicating the possible cause for the error.
[255] Fix | Delete
*
[256] Fix | Delete
* @since 5.2.0
[257] Fix | Delete
*
[258] Fix | Delete
* @param array $extension {
[259] Fix | Delete
* The extension that caused the error.
[260] Fix | Delete
*
[261] Fix | Delete
* @type string $slug The extension slug. The directory of the plugin or theme.
[262] Fix | Delete
* @type string $type The extension type. Either 'plugin' or 'theme'.
[263] Fix | Delete
* }
[264] Fix | Delete
* @return string Message about which extension caused the error.
[265] Fix | Delete
*/
[266] Fix | Delete
private function get_cause( $extension ) {
[267] Fix | Delete
[268] Fix | Delete
if ( 'plugin' === $extension['type'] ) {
[269] Fix | Delete
$plugin = $this->get_plugin( $extension );
[270] Fix | Delete
[271] Fix | Delete
if ( false === $plugin ) {
[272] Fix | Delete
$name = $extension['slug'];
[273] Fix | Delete
} else {
[274] Fix | Delete
$name = $plugin['Name'];
[275] Fix | Delete
}
[276] Fix | Delete
[277] Fix | Delete
/* translators: %s: Plugin name. */
[278] Fix | Delete
$cause = sprintf( __( 'In this case, WordPress caught an error with one of your plugins, %s.' ), $name );
[279] Fix | Delete
} else {
[280] Fix | Delete
$theme = wp_get_theme( $extension['slug'] );
[281] Fix | Delete
$name = $theme->exists() ? $theme->display( 'Name' ) : $extension['slug'];
[282] Fix | Delete
[283] Fix | Delete
/* translators: %s: Theme name. */
[284] Fix | Delete
$cause = sprintf( __( 'In this case, WordPress caught an error with your theme, %s.' ), $name );
[285] Fix | Delete
}
[286] Fix | Delete
[287] Fix | Delete
return $cause;
[288] Fix | Delete
}
[289] Fix | Delete
[290] Fix | Delete
/**
[291] Fix | Delete
* Return the details for a single plugin based on the extension data from an error.
[292] Fix | Delete
*
[293] Fix | Delete
* @since 5.3.0
[294] Fix | Delete
*
[295] Fix | Delete
* @param array $extension {
[296] Fix | Delete
* The extension that caused the error.
[297] Fix | Delete
*
[298] Fix | Delete
* @type string $slug The extension slug. The directory of the plugin or theme.
[299] Fix | Delete
* @type string $type The extension type. Either 'plugin' or 'theme'.
[300] Fix | Delete
* }
[301] Fix | Delete
* @return array|false A plugin array {@see get_plugins()} or `false` if no plugin was found.
[302] Fix | Delete
*/
[303] Fix | Delete
private function get_plugin( $extension ) {
[304] Fix | Delete
if ( ! function_exists( 'get_plugins' ) ) {
[305] Fix | Delete
require_once ABSPATH . 'wp-admin/includes/plugin.php';
[306] Fix | Delete
}
[307] Fix | Delete
[308] Fix | Delete
$plugins = get_plugins();
[309] Fix | Delete
[310] Fix | Delete
// Assume plugin main file name first since it is a common convention.
[311] Fix | Delete
if ( isset( $plugins[ "{$extension['slug']}/{$extension['slug']}.php" ] ) ) {
[312] Fix | Delete
return $plugins[ "{$extension['slug']}/{$extension['slug']}.php" ];
[313] Fix | Delete
} else {
[314] Fix | Delete
foreach ( $plugins as $file => $plugin_data ) {
[315] Fix | Delete
if ( str_starts_with( $file, "{$extension['slug']}/" ) || $file === $extension['slug'] ) {
[316] Fix | Delete
return $plugin_data;
[317] Fix | Delete
}
[318] Fix | Delete
}
[319] Fix | Delete
}
[320] Fix | Delete
[321] Fix | Delete
return false;
[322] Fix | Delete
}
[323] Fix | Delete
[324] Fix | Delete
/**
[325] Fix | Delete
* Return debug information in an easy to manipulate format.
[326] Fix | Delete
*
[327] Fix | Delete
* @since 5.3.0
[328] Fix | Delete
*
[329] Fix | Delete
* @param array $extension {
[330] Fix | Delete
* The extension that caused the error.
[331] Fix | Delete
*
[332] Fix | Delete
* @type string $slug The extension slug. The directory of the plugin or theme.
[333] Fix | Delete
* @type string $type The extension type. Either 'plugin' or 'theme'.
[334] Fix | Delete
* }
[335] Fix | Delete
* @return array An associative array of debug information.
[336] Fix | Delete
*/
[337] Fix | Delete
private function get_debug( $extension ) {
[338] Fix | Delete
$theme = wp_get_theme();
[339] Fix | Delete
$wp_version = get_bloginfo( 'version' );
[340] Fix | Delete
[341] Fix | Delete
if ( $extension ) {
[342] Fix | Delete
$plugin = $this->get_plugin( $extension );
[343] Fix | Delete
} else {
[344] Fix | Delete
$plugin = null;
[345] Fix | Delete
}
[346] Fix | Delete
[347] Fix | Delete
$debug = array(
[348] Fix | Delete
'wp' => sprintf(
[349] Fix | Delete
/* translators: %s: Current WordPress version number. */
[350] Fix | Delete
__( 'WordPress version %s' ),
[351] Fix | Delete
$wp_version
[352] Fix | Delete
),
[353] Fix | Delete
'theme' => sprintf(
[354] Fix | Delete
/* translators: 1: Current active theme name. 2: Current active theme version. */
[355] Fix | Delete
__( 'Active theme: %1$s (version %2$s)' ),
[356] Fix | Delete
$theme->get( 'Name' ),
[357] Fix | Delete
$theme->get( 'Version' )
[358] Fix | Delete
),
[359] Fix | Delete
);
[360] Fix | Delete
[361] Fix | Delete
if ( null !== $plugin ) {
[362] Fix | Delete
$debug['plugin'] = sprintf(
[363] Fix | Delete
/* translators: 1: The failing plugins name. 2: The failing plugins version. */
[364] Fix | Delete
__( 'Current plugin: %1$s (version %2$s)' ),
[365] Fix | Delete
$plugin['Name'],
[366] Fix | Delete
$plugin['Version']
[367] Fix | Delete
);
[368] Fix | Delete
}
[369] Fix | Delete
[370] Fix | Delete
$debug['php'] = sprintf(
[371] Fix | Delete
/* translators: %s: The currently used PHP version. */
[372] Fix | Delete
__( 'PHP version %s' ),
[373] Fix | Delete
PHP_VERSION
[374] Fix | Delete
);
[375] Fix | Delete
[376] Fix | Delete
return $debug;
[377] Fix | Delete
}
[378] Fix | Delete
}
[379] Fix | Delete
[380] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function