WordPress at a glance
function is not described

WP_Recovery_Mode::get_extension_for_error() protected WP 5.2.0

Gets the extension that the error occurred in.

{} It's a method of the class: WP_Recovery_Mode{}

No Hooks.

Return

Array/false. Extension details.

  • slug(string)
    The extension slug. This is the plugin or theme's directory.

  • type(string)
    The extension type. Either 'plugin' or 'theme'.

Usage

// protected - for code of main (parent) or child class
$result = $this->get_extension_for_error( $error );
$error(array) (required)
Error that was triggered.

Notes

  • Global. Array. $wp_theme_directories

Changelog

Since 5.2.0 Introduced.

Code of WP_Recovery_Mode::get_extension_for_error() WP 5.5.1

<?php
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;
}