wpseek.com
Eine auf WordPress spezialiserte Suchmaschine für Entwickler und Theme-Autoren



_preload_old_requests_classes_and_interfaces › WordPress Function

Seit6.2.0
Veraltetn/v
_preload_old_requests_classes_and_interfaces ( $to )
Parameter:
  • (string) $to Path to old WordPress installation.
    Erforderlich: Ja
Definiert in:
Codex:

Preloads old Requests classes and interfaces.

This function preloads the old Requests code into memory before the upgrade process deletes the files. Why? Requests code is loaded into memory via an autoloader, meaning when a class or interface is needed If a request is in process, Requests could attempt to access code. If the file is not there, a fatal error could occur. If the file was replaced, the new code is not compatible with the old, resulting in a fatal error. Preloading ensures the code is in memory before the code is updated.


Quellcode

function _preload_old_requests_classes_and_interfaces( $to ) {
	global $_old_requests_files, $wp_filesystem, $wp_version;

	/*
	 * Requests was introduced in WordPress 4.6.
	 *
	 * Skip preloading if the website was previously using
	 * an earlier version of WordPress.
	 */
	if ( version_compare( $wp_version, '4.6', '<' ) ) {
		return;
	}

	if ( ! defined( 'REQUESTS_SILENCE_PSR0_DEPRECATIONS' ) ) {
		define( 'REQUESTS_SILENCE_PSR0_DEPRECATIONS', true );
	}

	foreach ( $_old_requests_files as $name => $file ) {
		// Skip files that aren't interfaces or classes.
		if ( is_int( $name ) ) {
			continue;
		}

		// Skip if it's already loaded.
		if ( class_exists( $name ) || interface_exists( $name ) ) {
			continue;
		}

		// Skip if the file is missing.
		if ( ! $wp_filesystem->is_file( $to . $file ) ) {
			continue;
		}

		require_once $to . $file;
	}
}