| 1 |
<?php |
| 2 |
|
| 3 |
namespace QuadLayers\PluginFeedback; |
| 4 |
|
| 5 |
class Load |
| 6 |
{ |
| 7 |
|
| 8 |
public static $instance; |
| 9 |
public static $plugins = array(); |
| 10 |
public static $options = array(); |
| 11 |
|
| 12 |
private function __construct() |
| 13 |
{ |
| 14 |
add_action('admin_init', [self::class, 'ajax']); |
| 15 |
add_action('plugins_loaded', [self::class, 'scripts']); |
| 16 |
} |
| 17 |
|
| 18 |
public static function instance() |
| 19 |
{ |
| 20 |
if (is_null(self::$instance)) { |
| 21 |
self::$instance = new self(); |
| 22 |
} |
| 23 |
return self::$instance; |
| 24 |
} |
| 25 |
|
| 26 |
public function add(string $plugin_file, array $options = []): void |
| 27 |
{ |
| 28 |
$pluginBasename = plugin_basename($plugin_file); |
| 29 |
|
| 30 |
// Check if the plugin is already in the list |
| 31 |
if (in_array($pluginBasename, self::$plugins)) { |
| 32 |
return; |
| 33 |
} |
| 34 |
|
| 35 |
// Check if the plugin transient exists |
| 36 |
if (get_transient('ql_plugin_feedback_' . $pluginBasename)) { |
| 37 |
return; |
| 38 |
} |
| 39 |
|
| 40 |
self::$plugins[] = $pluginBasename; |
| 41 |
self::$options[$pluginBasename] = $options; |
| 42 |
} |
| 43 |
|
| 44 |
public static function scripts(): void |
| 45 |
{ |
| 46 |
// Enqueue the scripts for the deactivation survey |
| 47 |
Scripts::instance(self::$plugins, self::$options); |
| 48 |
} |
| 49 |
|
| 50 |
public static function ajax(): void |
| 51 |
{ |
| 52 |
// Register AJAX actions |
| 53 |
AjaxHandler::instance(); |
| 54 |
} |
| 55 |
} |
| 56 |
|