assets
11 months ago
src
11 months ago
templates
11 months ago
autoload.php
11 months ago
index.php
11 months ago
main.php
11 months ago
sdk_resolver.php
11 months ago
version.php
11 months ago
main.php
71 lines
| 1 | <?php |
| 2 | |
| 3 | require_once 'sdk_resolver.php'; |
| 4 | |
| 5 | /** |
| 6 | * Initialize analyst "private" |
| 7 | * |
| 8 | * @param array $options |
| 9 | */ |
| 10 | if (!function_exists('___analyst_init')) { |
| 11 | function ___analyst_init($options) { |
| 12 | $capabilities = [ |
| 13 | 'activate_plugins', |
| 14 | 'edit_plugins', |
| 15 | 'install_plugins', |
| 16 | 'update_plugins', |
| 17 | 'delete_plugins', |
| 18 | 'manage_network_plugins', |
| 19 | 'upload_plugins' |
| 20 | ]; |
| 21 | |
| 22 | // Allow if has any of above permissions |
| 23 | $hasPerms = false; |
| 24 | foreach ($capabilities as $i => $cap) { |
| 25 | if (current_user_can($cap)) { |
| 26 | $hasPerms = true; |
| 27 | break; |
| 28 | } |
| 29 | } |
| 30 | |
| 31 | if ($hasPerms == false) { |
| 32 | return; |
| 33 | } |
| 34 | |
| 35 | // Try resolve latest supported SDK |
| 36 | // In case resolving is failed exit the execution |
| 37 | try { |
| 38 | analyst_resolve_sdk($options['base-dir']); |
| 39 | } catch (Exception $exception) { |
| 40 | // error_log('[ANALYST] Cannot resolve any supported SDK'); |
| 41 | return; |
| 42 | } |
| 43 | |
| 44 | try { |
| 45 | global /** @var Analyst\Analyst $analyst */ |
| 46 | $analyst; |
| 47 | |
| 48 | // Set global instance of analyst |
| 49 | if (!$analyst) { |
| 50 | $analyst = Analyst\Analyst::getInstance(); |
| 51 | } |
| 52 | |
| 53 | $analyst->registerAccount(new Account\Account($options['client-id'], $options['client-secret'], $options['base-dir'])); |
| 54 | } catch (Exception $e) { |
| 55 | // error_log('Analyst SDK receive an error: [' . $e->getMessage() . '] Please contact our support at support@analyst.com'); |
| 56 | } |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | |
| 61 | if (!function_exists('analyst_init')) { |
| 62 | function analyst_init($__options) { |
| 63 | if (did_action('init') > 0 && function_exists('current_user_can')) ___analyst_init($__options); |
| 64 | else { |
| 65 | add_action('wp_loaded', function () use ($__options) { |
| 66 | ___analyst_init($__options); |
| 67 | }, -1000); |
| 68 | } |
| 69 | } |
| 70 | } |
| 71 |