; break; } } /** * Retrieve the name of the importer. * * @access private * * @param string $importer Either a string reported by the importer, the class name of the importer, or 'unknown'. * @return string Name of the importer, or "Unknown Importer" if importer is unknown. */ private function get_importer_name( $importer ) { $importers = get_importers(); return isset( $importers[ $importer ] ) ? $importers[ $importer ][0] : 'Unknown Importer'; } /** * Determine the class that extends `WP_Importer` which is responsible for * the current action. Designed to be used within an action handler. * * @access private * @static * * @return string The name of the calling class, or 'unknown'. */ private static function get_calling_importer_class() { // If WP_Importer doesn't exist, neither will any importer that extends it. if ( ! class_exists( 'WP_Importer', false ) ) { return 'unknown'; } $action = current_filter(); $backtrace = debug_backtrace( false ); //phpcs:ignore PHPCompatibility.FunctionUse.NewFunctionParameters.debug_backtrace_optionsFound,WordPress.PHP.DevelopmentFunctions.error_log_debug_backtrace $do_action_pos = -1; $backtrace_len = count( $backtrace ); for ( $i = 0; $i < $backtrace_len; $i++ ) { // Find the location in the stack of the calling action. if ( 'do_action' === $backtrace[ $i ]['function'] && $action === $backtrace[ $i ]['args'][0] ) { $do_action_pos = $i; break; } } // If the action wasn't called, the calling class is unknown. if ( -1 === $do_action_pos ) { return 'unknown'; } // Continue iterating the stack looking for a caller that extends WP_Importer. for ( $i = $do_action_pos + 1; $i < $backtrace_len; $i++ ) { // If there is no class on the trace, continue. if ( ! isset( $backtrace[ $i ]['class'] ) ) { continue; } $class_name = $backtrace[ $i ]['class']; // Check if the class extends WP_Importer. if ( class_exists( $class_name, false ) ) { $parents = class_parents( $class_name, false ); if ( $parents && in_array( 'WP_Importer', $parents, true ) ) { return $class_name; } } } // If we've exhausted the stack without a match, the calling class is unknown. return 'unknown'; } }