diff --git a/src/wp-includes/class-simplepie.php b/src/wp-includes/class-simplepie.php index 958ba463e9..6110413767 100644 --- a/src/wp-includes/class-simplepie.php +++ b/src/wp-includes/class-simplepie.php @@ -29,35 +29,10 @@ function wp_simplepie_autoload( $class ) { include( $file ); } -if ( function_exists( 'spl_autoload_register' ) ) { - /** - * We autoload classes we may not need. - * - * If SPL is disabled, we load all of SimplePie manually. - * - * Core.php is not loaded manually, because SimplePie_Core (a deprecated class) - * was never included in WordPress core. - */ - spl_autoload_register( 'wp_simplepie_autoload' ); -} else { - require ABSPATH . WPINC . '/SimplePie/Cache/Base.php'; - require ABSPATH . WPINC . '/SimplePie/Cache/DB.php'; - require ABSPATH . WPINC . '/SimplePie/Cache/File.php'; - require ABSPATH . WPINC . '/SimplePie/Cache/Memcache.php'; - require ABSPATH . WPINC . '/SimplePie/Cache/MySQL.php'; - require ABSPATH . WPINC . '/SimplePie/Caption.php'; - require ABSPATH . WPINC . '/SimplePie/Category.php'; - require ABSPATH . WPINC . '/SimplePie/Copyright.php'; - require ABSPATH . WPINC . '/SimplePie/Credit.php'; - require ABSPATH . WPINC . '/SimplePie/Decode/HTML/Entities.php'; - require ABSPATH . WPINC . '/SimplePie/Enclosure.php'; - require ABSPATH . WPINC . '/SimplePie/gzdecode.php'; - require ABSPATH . WPINC . '/SimplePie/HTTP/Parser.php'; - require ABSPATH . WPINC . '/SimplePie/Net/IPv6.php'; - require ABSPATH . WPINC . '/SimplePie/Rating.php'; - require ABSPATH . WPINC . '/SimplePie/Restriction.php'; - require ABSPATH . WPINC . '/SimplePie/Source.php'; -} +/** + * We autoload classes we may not need. + */ +spl_autoload_register( 'wp_simplepie_autoload' ); /** * SimplePie diff --git a/src/wp-includes/compat.php b/src/wp-includes/compat.php index cfb0f70aa8..64f4ba5170 100644 --- a/src/wp-includes/compat.php +++ b/src/wp-includes/compat.php @@ -434,3 +434,84 @@ if ( ! interface_exists( 'JsonSerializable' ) ) { if ( ! function_exists( 'random_int' ) ) { require ABSPATH . WPINC . '/random_compat/random.php'; } + +// SPL can be disabled on PHP 5.2 +if ( ! function_exists( 'spl_autoload_register' ) ): + $_wp_spl_autoloaders = array(); + + /** + * Autoloader compatibility callback. + * + * @param string $classname Class to attempt autoloading. + */ + function __autoload( $classname ) { + global $_wp_spl_autoloaders; + foreach ( $_wp_spl_autoloaders as $autoloader ) { + if ( ! is_callable( $autoloader ) ) { + // Avoid the extra warning if the autoloader isn't callable. + continue; + } + + call_user_func( $autoloader, $classname ); + + // If it has been autoloaded, stop processing. + if ( class_exists( $classname, false ) ) { + return; + } + } + } + + /** + * Register a function to be autoloaded. + * + * @param callable $autoload_function The function to register. + * @param boolean $throw Should the function throw an exception if the function isn't callable? + * @param boolean $prepend Should we prepend the function to the stack? + */ + function spl_autoload_register( $autoload_function, $throw = true, $prepend = false ) { + if ( $throw && ! is_callable( $autoload_function ) ) { + // String not translated to match PHP core. + throw new Exception( 'Function not callable' ); + } + + global $_wp_spl_autoloaders; + + // Don't allow multiple registration. + if ( in_array( $autoload_function, $_wp_spl_autoloaders ) ) { + return; + } + + if ( $prepend ) { + array_unshift( $_wp_spl_autoloaders, $autoload_function ); + } else { + $_wp_spl_autoloaders[] = $autoload_function; + } + } + + /** + * Unregister an autoloader function. + * + * @param callable $function The function to unregister. + * @return boolean True if the function was unregistered, false if it could not be. + */ + function spl_autoload_unregister( $function ) { + global $_wp_spl_autoloaders; + foreach ( $_wp_spl_autoloaders as &$autoloader ) { + if ( $autoloader === $function ) { + unset( $autoloader ); + return true; + } + } + + return false; + } + + /** + * Get the registered autoloader functions. + * + * @return array List of autoloader functions. + */ + function spl_autoload_functions() { + return $GLOBALS['_wp_spl_autoloaders']; + } +endif;