Make WordPress Core

Ticket #48090: 48090.2.patch

File 48090.2.patch, 5.0 KB (added by Clorith, 5 years ago)
  • src/wp-includes/class-wp-recovery-mode-email-service.php

     
    138138                 */
    139139                $support = apply_filters( 'recovery_email_support_info', __( 'Please contact your host for assistance with investigating this issue further.' ) );
    140140
    141                 /* translators: Do not translate LINK, EXPIRES, CAUSE, DETAILS, SITEURL, PAGEURL, SUPPORT: those are placeholders. */
     141                /**
     142                 * Filters the debug information included in the fatal error protection email.
     143                 *
     144                 * @since 5.3.0
     145                 *
     146                 * @param $message array An associated array of debug information.
     147                 */
     148                $debug = apply_filters( 'recovery_email_debug_info', $this->get_debug( $extension ) );
     149
     150                /* translators: Do not translate LINK, EXPIRES, CAUSE, DETAILS, SITEURL, PAGEURL, SUPPORT. DEBUG: those are placeholders. */
    142151                $message = __(
    143152                        'Howdy!
    144153
     
    154163
    155164To 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.
    156165
     166When seeking help with this issue, you may be asked for some of the following information:
     167###DEBUG###
     168
    157169###DETAILS###'
    158170                );
    159171                $message = str_replace(
     
    165177                                '###SITEURL###',
    166178                                '###PAGEURL###',
    167179                                '###SUPPORT###',
     180                                '###DEBUG###',
    168181                        ),
    169182                        array(
    170183                                $url,
     
    174187                                home_url( '/' ),
    175188                                home_url( $_SERVER['REQUEST_URI'] ),
    176189                                $support,
     190                                implode( "\r\n", $debug ),
    177191                        ),
    178192                        $message
    179193                );
     
    207221                        restore_previous_locale();
    208222                }
    209223
     224                echo '<pre>';
     225                print_r( $message );
     226                echo '</pre>';
     227
    210228                return $sent;
    211229        }
    212230
     
    236254        private function get_cause( $extension ) {
    237255
    238256                if ( 'plugin' === $extension['type'] ) {
    239                         if ( ! function_exists( 'get_plugins' ) ) {
    240                                 require_once ABSPATH . 'wp-admin/includes/plugin.php';
    241                         }
    242 
    243                         $plugins = get_plugins();
     257                        $plugin = $this->get_plugin( $extension );
    244258
    245                         $name = '';
    246 
    247                         // Assume plugin main file name first since it is a common convention.
    248                         if ( isset( $plugins[ "{$extension['slug']}/{$extension['slug']}.php" ] ) ) {
    249                                 $name = $plugins[ "{$extension['slug']}/{$extension['slug']}.php" ]['Name'];
     259                        if ( false === $plugin ) {
     260                                $name = $extension['slug'];
    250261                        } else {
    251                                 foreach ( $plugins as $file => $plugin_data ) {
    252                                         if ( 0 === strpos( $file, "{$extension['slug']}/" ) || $file === $extension['slug'] ) {
    253                                                 $name = $plugin_data['Name'];
    254                                                 break;
    255                                         }
    256                                 }
    257                         }
    258 
    259                         if ( empty( $name ) ) {
    260                                 $name = $extension['slug'];
     262                                $name = $plugin['Name'];
    261263                        }
    262264
    263265                        /* translators: %s: Plugin name. */
     
    272274
    273275                return $cause;
    274276        }
     277
     278        /**
     279         * Return the details for a single plugin based on the extension data from an error.
     280         *
     281         * @param array $extension The extension that caused the error.
     282         *
     283         * @return bool|array A plugin array {@see get_plugins()} or `false` if no plugin was found.
     284         */
     285        private function get_plugin( $extension ) {
     286                if ( ! function_exists( 'get_plugins' ) ) {
     287                        require_once ABSPATH . 'wp-admin/includes/plugin.php';
     288                }
     289
     290                $plugins = get_plugins();
     291
     292                // Assume plugin main file name first since it is a common convention.
     293                if ( isset( $plugins[ "{$extension['slug']}/{$extension['slug']}.php" ] ) ) {
     294                        return $plugins[ "{$extension['slug']}/{$extension['slug']}.php" ];
     295                } else {
     296                        foreach ( $plugins as $file => $plugin_data ) {
     297                                if ( 0 === strpos( $file, "{$extension['slug']}/" ) || $file === $extension['slug'] ) {
     298                                        return $plugin_data;
     299                                }
     300                        }
     301                }
     302
     303                return false;
     304        }
     305
     306        /**
     307         * Return debug information in an easy to manipulate format.
     308         *
     309         * @param array $extension The extension that caused the error.
     310         *
     311         * @return array An associated array of debug information.
     312         */
     313        private function get_debug( $extension ) {
     314                $theme = wp_get_theme();
     315                $wp_version = get_bloginfo( 'version' );
     316
     317                if ( $extension ) {
     318                        $plugin = $this->get_plugin( $extension );
     319                } else {
     320                        $plugin = null;
     321                }
     322
     323                $debug = array(
     324                        // translators: %s: Current WordPress version number.
     325                        'wp'    => sprintf(
     326                                __( 'WordPress version %s' ),
     327                                $wp_version
     328                        ),
     329                        'theme' => sprintf(
     330                                // translators: 1: Current active theme name. 2: Current active theme version.
     331                                __( 'Current theme: %1$s (version %2$s)' ),
     332                                $theme->get( 'Name' ),
     333                                $theme->get( 'Version' )
     334                        ),
     335                );
     336
     337                if ( null !== $plugin ) {
     338                        $debug['plugin'] = sprintf(
     339                                // translators: 1: The failing plugins name. 2: The failing plugins version.
     340                                __( 'Current plugin: %1$s (version %2$s)' ),
     341                                $plugin['Name'],
     342                                $plugin['Version']
     343                        );
     344                }
     345
     346                $debug['php'] = sprintf(
     347                        // translators: %s: The currently used PHP version.
     348                        __( 'PHP version %s' ),
     349                        PHP_VERSION
     350                );
     351
     352                return $debug;
     353        }
    275354}