On this page
WP_Recovery_Mode::get_extension_for_error( array $error ): array|false
Gets the extension that the error occurred in.
Parameters
$errorarray Required-
Error details from
error_get_last().
Return
array|false Extension details.
slugstringThe extension slug. This is the plugin or theme's directory.typestringThe extension type. Either'plugin'or'theme'.
Source
File: wp-includes/class-wp-recovery-mode.php. View all references
protected function get_extension_for_error( $error ) {
global $wp_theme_directories;
if ( ! isset( $error['file'] ) ) {
return false;
}
if ( ! defined( 'WP_PLUGIN_DIR' ) ) {
return false;
}
$error_file = wp_normalize_path( $error['file'] );
$wp_plugin_dir = wp_normalize_path( WP_PLUGIN_DIR );
if ( 0 === strpos( $error_file, $wp_plugin_dir ) ) {
$path = str_replace( $wp_plugin_dir . '/', '', $error_file );
$parts = explode( '/', $path );
return array(
'type' => 'plugin',
'slug' => $parts[0],
);
}
if ( empty( $wp_theme_directories ) ) {
return false;
}
foreach ( $wp_theme_directories as $theme_directory ) {
$theme_directory = wp_normalize_path( $theme_directory );
if ( 0 === strpos( $error_file, $theme_directory ) ) {
$path = str_replace( $theme_directory . '/', '', $error_file );
$parts = explode( '/', $path );
return array(
'type' => 'theme',
'slug' => $parts[0],
);
}
}
return false;
}
Related
Uses
| Uses | Description |
|---|---|
| wp_normalize_path() wp-includes/functions.php | Normalizes a filesystem path. |
Used By
| Used By | Description |
|---|---|
| WP_Recovery_Mode::store_error() wp-includes/class-wp-recovery-mode.php | Stores the given error so that the extension causing it is paused. |
| WP_Recovery_Mode::handle_error() wp-includes/class-wp-recovery-mode.php | Handles a fatal error occurring. |
Changelog
| Version | Description |
|---|---|
| 5.2.0 | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/classes/wp_recovery_mode/get_extension_for_error