PluginProbe ʕ •ᴥ•ʔ
Backup Migration / 2.1.7
Backup Migration v2.1.7
2.1.7 2.1.6 2.1.5.2 trunk 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.3.9 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.6.1 1.4.7 1.4.8 1.4.9 1.4.9.1 2.0.0 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.1.5.1
backup-backup / analyst / sdk_resolver.php
backup-backup / analyst Last commit date
assets 2 weeks ago src 2 weeks ago templates 2 weeks ago autoload.php 2 weeks ago index.php 2 weeks ago main.php 2 weeks ago sdk_resolver.php 2 weeks ago version.php 2 weeks ago
sdk_resolver.php
82 lines
1 <?php
2
3 if ( ! defined( 'ABSPATH' ) ) exit;
4
5 if (!function_exists('analyst_resolve_sdk')) {
6
7 /**
8 * Resolve supported sdk versions and load latest supported one
9 * also bootstrap sdk with autoloader
10 *
11 * @since 1.1.3
12 *
13 * @param null $thisPluginPath
14 * @return void
15 * @throws Exception
16 */
17 function analyst_resolve_sdk($thisPluginPath = null) {
18 static $loaded = false;
19
20 // Exit if we already resolved SDK
21 if ($loaded) return;
22
23 $plugins = get_option('active_plugins');
24
25 if ($thisPluginPath) {
26 array_push($plugins, plugin_basename($thisPluginPath));
27 }
28
29 $pluginsFolder = WP_PLUGIN_DIR;
30
31 $possibleSDKs = array_map(function ($path) use ($pluginsFolder) {
32 $sdkFolder = sprintf('%s/%s/analyst/', $pluginsFolder, dirname($path));
33
34 $sdkFolder = str_replace('\\', '/', $sdkFolder);
35
36 $versionPath = $sdkFolder . 'version.php';
37
38 if (file_exists($versionPath)) {
39 return require $versionPath;
40 }
41
42 return false;
43 }, $plugins);
44
45 global $wp_version;
46
47 // Filter out plugins which has no SDK
48 $SDKs = array_filter($possibleSDKs, function ($s) {return is_array($s);});
49
50 // Filter SDKs which is supported by PHP and WP
51 $supported = array_values(array_filter($SDKs, function ($sdk) use($wp_version) {
52 $phpSupported = version_compare(PHP_VERSION, $sdk['php']) >= 0;
53 $wpSupported = version_compare($wp_version, $sdk['wp']) >= 0;
54
55 return $phpSupported && $wpSupported;
56 }));
57
58 // Sort SDK by version in descending order
59 uasort($supported, function ($x, $y) {
60 return version_compare($y['sdk'], $x['sdk']);
61 });
62
63 // Reset sorted values keys
64 $supported = array_values($supported);
65
66 if (!isset($supported[0])) {
67 throw new Exception('There is no SDK which is support current PHP version and WP version');
68 }
69
70 // Autoload files for supported SDK
71 $autoloaderPath = str_replace(
72 '\\',
73 '/',
74 sprintf('%s/autoload.php', $supported[0]['path'])
75 );
76
77 require_once $autoloaderPath;
78
79 $loaded = true;
80 }
81 }
82