| @@ 11-45 (lines=35) @@ | ||
| 8 | /** |
|
| 9 | * THIS CODE WOULD NEED TO BE DUPLICATED IN EACH PLUGIN... |
|
| 10 | */ |
|
| 11 | if ( ! function_exists( 'jetpack_enqueue_library' ) ) { |
|
| 12 | function jetpack_enqueue_library( $class_name, $version, $path ) { |
|
| 13 | global $jetpack_libraries; |
|
| 14 | if ( ! is_array( $jetpack_libraries ) ) { |
|
| 15 | $jetpack_libraries = array(); |
|
| 16 | } |
|
| 17 | if ( ! isset( $jetpack_libraries[ $class_name ] ) ) { |
|
| 18 | $jetpack_libraries[ $class_name ] = array(); |
|
| 19 | } |
|
| 20 | $jetpack_libraries[ $class_name ][] = array( 'version' => $version, 'path' => $path ); |
|
| 21 | } |
|
| 22 | ||
| 23 | // add the autoloader |
|
| 24 | spl_autoload_register( function ($class_name) { |
|
| 25 | global $jetpack_libraries; |
|
| 26 | if ( ! isset( $jetpack_libraries[ $class_name ] ) ) { |
|
| 27 | // the library is not registered try a different autoloader |
|
| 28 | return; |
|
| 29 | } |
|
| 30 | ||
| 31 | if ( ! did_action( 'plugin_loaded' ) ) { |
|
| 32 | _doing_it_wrong( $class_name , 'Not all plugins have loaded yet!' ); |
|
| 33 | } |
|
| 34 | ||
| 35 | $initial = array_shift($jetpack_libraries[ $class_name ] ); |
|
| 36 | $max_version_info = array_reduce( $jetpack_libraries[ $class_name ], function( $carry_class_info, $class_info ) { |
|
| 37 | if ( version_compare( $class_info['version'], $carry_class_info['version'], '>' ) ) { |
|
| 38 | return $class_info; |
|
| 39 | } |
|
| 40 | return $carry_class_info; |
|
| 41 | }, $initial ); |
|
| 42 | ||
| 43 | require_once $max_version_info['path']; |
|
| 44 | } ); |
|
| 45 | } |
|
| 46 | /** |
|
| 47 | * END OF DUPLICATE CODE |
|
| 48 | */ |
|
| @@ 62-96 (lines=35) @@ | ||
| 59 | /** |
|
| 60 | * THIS CODE WOULD NEED TO BE DUPLICATED IN EACH PLUGIN... |
|
| 61 | */ |
|
| 62 | if ( ! function_exists( 'jetpack_enqueue_library' ) ) { |
|
| 63 | function jetpack_enqueue_library( $class_name, $version, $path ) { |
|
| 64 | global $jetpack_libraries; |
|
| 65 | if ( ! is_array( $jetpack_libraries ) ) { |
|
| 66 | $jetpack_libraries = array(); |
|
| 67 | } |
|
| 68 | if ( ! isset( $jetpack_libraries[ $class_name ] ) ) { |
|
| 69 | $jetpack_libraries[ $class_name ] = array(); |
|
| 70 | } |
|
| 71 | $jetpack_libraries[ $class_name ][] = array( 'version' => $version, 'path' => $path ); |
|
| 72 | } |
|
| 73 | ||
| 74 | // add the autoloader |
|
| 75 | spl_autoload_register( function ($class_name) { |
|
| 76 | global $jetpack_libraries; |
|
| 77 | if ( ! isset( $jetpack_libraries[ $class_name ] ) ) { |
|
| 78 | // the library is not registered try a different autoloader |
|
| 79 | return; |
|
| 80 | } |
|
| 81 | ||
| 82 | if ( ! did_action( 'plugin_loaded' ) ) { |
|
| 83 | _doing_it_wrong( $class_name , 'Not all plugins have loaded yet!' ); |
|
| 84 | } |
|
| 85 | ||
| 86 | $initial = array_shift($jetpack_libraries[ $class_name ] ); |
|
| 87 | $max_version_info = array_reduce( $jetpack_libraries[ $class_name ], function( $carry_class_info, $class_info ) { |
|
| 88 | if ( version_compare( $class_info['version'], $carry_class_info['version'], '>' ) ) { |
|
| 89 | return $class_info; |
|
| 90 | } |
|
| 91 | return $carry_class_info; |
|
| 92 | }, $initial ); |
|
| 93 | ||
| 94 | require_once $max_version_info['path']; |
|
| 95 | } ); |
|
| 96 | } |
|
| 97 | /** |
|
| 98 | * END OF DUPLICATE CODE |
|
| 99 | */ |
|