| 1 |
<?php |
| 2 |
namespace UninstallerForm; |
| 3 |
|
| 4 |
use ReflectionMethod; |
| 5 |
use UninstallerForm\Api\FeedbackController; |
| 6 |
use UninstallerForm\Support\Localizer; |
| 7 |
|
| 8 |
/** |
| 9 |
* HookRegistrar class for the uninstaller form. |
| 10 |
* |
| 11 |
* @since 1.0.0 |
| 12 |
* |
| 13 |
* @package UNINSTALLER_FORM |
| 14 |
*/ |
| 15 |
class HookRegistrar { |
| 16 |
protected $plugin_name, $plugin_slug, $plugin_file, $plugin_text_domain, $script_handler,$webhook; |
| 17 |
|
| 18 |
/** |
| 19 |
* HookRegistrar Constructor. |
| 20 |
* |
| 21 |
* @param string $plugin_name The name of the plugin. |
| 22 |
* @param string $plugin_slug The slug of the plugin. |
| 23 |
* @param string $plugin_file The path to the plugin file. |
| 24 |
* @param string $plugin_text_domain The text domain of the plugin. |
| 25 |
* @param string $script_handler The handle of the script to enqueue. |
| 26 |
* |
| 27 |
* @since 1.0.0 |
| 28 |
*/ |
| 29 |
public function __construct($plugin_name, $plugin_slug, $plugin_file, $plugin_text_domain, $script_handler,$webhook='') { |
| 30 |
$this->plugin_name = $plugin_name; |
| 31 |
$this->plugin_slug = $plugin_slug; |
| 32 |
$this->plugin_file = $plugin_file; |
| 33 |
$this->plugin_text_domain = $plugin_text_domain; |
| 34 |
$this->script_handler = $script_handler; |
| 35 |
$this->webhook = $webhook; |
| 36 |
} |
| 37 |
|
| 38 |
/** |
| 39 |
* Register hooks for the uninstaller form. |
| 40 |
* |
| 41 |
* @since 1.0.0 |
| 42 |
* |
| 43 |
* @return void |
| 44 |
*/ |
| 45 |
public function register() { |
| 46 |
add_action('rest_api_init', function () { |
| 47 |
$reflection = new ReflectionMethod(FeedbackController::class, '__construct'); |
| 48 |
$totalParams = $reflection->getNumberOfParameters(); |
| 49 |
if( $totalParams === 5){ |
| 50 |
new FeedbackController($this->plugin_file,$this->plugin_text_domain, $this->plugin_name, $this->plugin_slug,$this->webhook); |
| 51 |
} |
| 52 |
}); |
| 53 |
|
| 54 |
add_action('admin_enqueue_scripts', function () { |
| 55 |
$localizer = new Localizer($this->plugin_name, $this->plugin_text_domain, $this->plugin_file, $this->script_handler); |
| 56 |
$localizer->handle(); |
| 57 |
}); |
| 58 |
} |
| 59 |
} |