Make WordPress Core

Ticket #46898: 46898.6.alt.diff

File 46898.6.alt.diff, 6.6 KB (added by SergeyBiryukov, 6 years ago)
  • src/wp-includes/class-wp-recovery-mode-email-service.php

     
    9393         *
    9494         * @param int   $rate_limit Number of seconds before another email can be sent.
    9595         * @param array $error      Error details from {@see error_get_last()}
    96          * @param array $extension  Extension that caused the error.
    97          *
     96         * @param array $extension  The extension that caused the error. {
     97         *      @type string $slug The extension slug. The plugin or theme's directory.
     98         *      @type string $type The extension type. Either 'plugin' or 'theme'.
     99         * }
    98100         * @return bool Whether the email was sent successfully.
    99101         */
    100102        private function send_recovery_mode_email( $rate_limit, $error, $extension ) {
     
    110112                }
    111113
    112114                if ( $extension ) {
    113                         $cause   = $this->get_cause( $extension );
    114                         $details = wp_strip_all_tags( wp_get_extension_error_description( $error ) );
     115                        $extension_name = $this->get_extension_name( $extension );
     116                        $details        = wp_strip_all_tags( wp_get_extension_error_description( $error ) );
    115117
    116118                        if ( $details ) {
    117119                                $header  = __( 'Error Details' );
    118120                                $details = "\n\n" . $header . "\n" . str_pad( '', strlen( $header ), '=' ) . "\n" . $details;
    119121                        }
     122
     123                        if ( 'plugin' === $extension['type'] ) {
     124                                /* translators: %s: plugin name */
     125                                $cause   = sprintf( __( 'In this case, WordPress caught an error with one of your plugins: %s.' ), $extension_name );
     126                                $support = sprintf(
     127                                        /* translators: 1: plugin name, 2: plugin slug */
     128                                        __(
     129                                                'If nothing looks broken, the author of %1$s would greatly appreciate if you could post more information about this error in the support forums. You can find the error details at the end of this email.
     130
     131https://wordpress.org/support/plugin/%2$s/
     132
     133If your site appears broken and you can\'t access your dashboard normally, WordPress now has a special "recovery mode". This lets you safely log in to your dashboard and disable the %1$s plugin.'
     134                                        ),
     135                                        $extension_name,
     136                                        $extension['slug']
     137                                );
     138                        } else {
     139                                /* translators: %s: theme name */
     140                                $cause   = sprintf( __( 'In this case, WordPress caught an error with your active theme: %s.' ), $extension_name );
     141                                $support = sprintf(
     142                                        /* translators: 1: theme name, 2: theme slug */
     143                                        __(
     144                                                'If nothing looks broken, the author of %1$s would greatly appreciate if you could post more information about this error in the support forums. You can find the error details at the end of this email.
     145
     146https://wordpress.org/support/theme/%2$s/
     147
     148If your site appears broken and you can\'t access your dashboard normally, WordPress now has a special "recovery mode". This lets you safely log in to your dashboard and switch to another theme.'
     149                                        ),
     150                                        $extension_name,
     151                                        $extension['slug']
     152                                );
     153                        }
    120154                } else {
    121155                        $cause   = '';
     156                        $support = __( 'If your site appears broken and you can\'t access your dashboard normally, WordPress now has a special "recovery mode". This lets you safely log in to your dashboard.' );
    122157                        $details = '';
    123158                }
    124159
     160                /* translators: Do not translate CAUSE, SITEURL, ERROR_PAGE, SUPPORT, RECOVERY_LINK, EXPIRES, DETAILS: those are placeholders. */
    125161                $message = __(
    126                         'Howdy,
     162                        'Howdy!
    127163
    128 Your site recently crashed and may not be working as expected.
     164Since WordPress 5.2 there is a built-in feature that detects when a plugin or theme causes a fatal error on your site, and sends you this automated email.
    129165###CAUSE###
    130 Please click the link below to initiate recovery mode and fix the problem.
     166First, visit your website (###SITEURL###) and check for any visible issues. Next, visit the page where the error was caught (###ERROR_PAGE###) and check for any visible issues.
    131167
    132 This link expires in ###EXPIRES###.
     168###SUPPORT###
    133169
    134 ###LINK### ###DETAILS###
     170###RECOVERY_LINK###
    135171
     172To 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 you click on it after it expires.
     173###DETAILS###
     174
    136175--The WordPress Team
    137176https://wordpress.org/
    138177'
     
    139178                );
    140179                $message = str_replace(
    141180                        array(
    142                                 '###LINK###',
     181                                '###CAUSE###',
     182                                '###SITEURL###',
     183                                '###ERROR_PAGE###',
     184                                '###SUPPORT###',
     185                                '###RECOVERY_LINK###',
    143186                                '###EXPIRES###',
    144                                 '###CAUSE###',
    145187                                '###DETAILS###',
    146188                        ),
    147189                        array(
     190                                $cause ? "\n{$cause}\n" : "\n",
     191                                home_url(),
     192                                home_url( $_SERVER['REQUEST_URI'] ),
     193                                $support,
    148194                                $url,
    149195                                human_time_diff( time() + $rate_limit ),
    150                                 $cause ? "\n{$cause}\n" : "\n",
    151196                                $details,
    152197                        ),
    153198                        $message
     
    201246        }
    202247
    203248        /**
    204          * Gets the description indicating the possible cause for the error.
     249         * Gets the name of the extension that caused the error.
    205250         *
    206251         * @since 5.2.0
    207252         *
    208          * @param array $extension The extension that caused the error.
    209          * @return string Message about which extension caused the error.
     253         * @param array $extension The extension that caused the error. {
     254         *      @type string $slug The extension slug. The plugin or theme's directory.
     255         *      @type string $type The extension type. Either 'plugin' or 'theme'.
     256         * }
     257         * @return string Name of extension that caused the error.
    210258         */
    211         private function get_cause( $extension ) {
     259        private function get_extension_name( $extension ) {
    212260
    213261                if ( 'plugin' === $extension['type'] ) {
    214262                        if ( ! function_exists( 'get_plugins' ) ) {
     
    222270                        // Assume plugin main file name first since it is a common convention.
    223271                        if ( isset( $plugins[ "{$extension['slug']}/{$extension['slug']}.php" ] ) ) {
    224272                                $name = $plugins[ "{$extension['slug']}/{$extension['slug']}.php" ]['Name'];
     273                        } elseif ( isset( $plugins[ $extension['slug'] ] ) ) {
     274                                // Plugin does not have a parent directory.
     275                                $name = $plugins[ $extension['slug'] ]['Name'];
    225276                        } else {
    226277                                foreach ( $plugins as $file => $plugin_data ) {
    227278                                        if ( 0 === strpos( $file, "{$extension['slug']}/" ) ) {
     
    234285                        if ( empty( $name ) ) {
    235286                                $name = $extension['slug'];
    236287                        }
    237 
    238                         /* translators: %s: plugin name */
    239                         $cause = sprintf( __( 'This was caused by the following plugin: %s.' ), $name );
    240288                } else {
    241                         $theme = wp_get_theme( $extension['slug'] );
    242                         $name  = $theme->exists() ? $theme->display( 'Name' ) : $extension['slug'];
    243 
    244                         /* translators: %s: theme name */
    245                         $cause = sprintf( __( 'This was caused by the following theme: %s.' ), $name );
     289                        $name = $theme->exists() ? $theme->display( 'Name' ) : $extension['slug'];
    246290                }
    247291
    248                 return $cause;
     292                return $name;
    249293        }
    250294}