adapter->get_*() methods. * The hardcoded yaycommerce_licensing_plugins filter registration at priority 100 * is preserved for backwards compat — new code uses LicenseRegistry instead. * * NOTE: The original LicenseHandler used CorePlugin::get() for item_id/slug/etc. * Here those values come from the injected LicenseConfigAdapter. Port is faithful; * any oddities from source preserved with // TODO: investigate comments. */ class LicenseHandler { protected LicenseConfigAdapter $adapter; protected License $license; public function __construct(LicenseConfigAdapter $adapter) { $this->adapter = $adapter; $this->license = new License($adapter); new RestAPI($adapter); if (is_admin()) { $this->do_hooks(); $this->do_cron_job(); $this->do_post_requests(); $this->show_plugin_page_notification(); } } public function do_hooks(): void { add_action('admin_notices', [$this, 'not_activate_license_notice']); add_action('admin_enqueue_scripts', [$this, 'enqueue_license_scripts']); add_action('yaycommerce_licenses_page', [$this, 'render_license_settings'], 100); // Legacy filter — new code uses LicenseRegistry, but this keeps // backward compat so old Licenses page views still work during transition. add_filter('yaycommerce_licensing_plugins', [$this, 'register_licensing_plugins'], 100); /** Expired license admin notice */ add_action('admin_notices', [$this, 'license_expired_admin_notice']); // License-specific action link: "Enter license key" when inactive if (!$this->license->is_active() || $this->license->is_expired()) { add_filter('plugin_action_links_' . $this->adapter->get_plugin_basename(), [$this, 'add_license_action_link']); } add_action('admin_init', [$this, 'auto_update']); add_filter('auto_update_plugin', [$this, 'add_disabled_auto_update_text'], 100, 2); add_filter('plugins_list', [$this, 'support_auto_update'], 100); } /** * Handle POST-based license form submissions (legacy AJAX path). * REST API (RestAPI.php) is the primary path — this is a no-op * placeholder for backward compatibility with any direct form posts. */ public function do_post_requests(): void { // REST API handles all license actions. No legacy POST handling needed. } public function do_cron_job(): void { add_filter('cron_schedules', [$this, 'custom_schedules']); add_action('check_license_cron_' . $this->adapter->get_plugin_slug(), [$this, 'check_license_cron_run']); $cron_hook = 'check_license_cron_' . $this->adapter->get_plugin_slug(); if (!wp_next_scheduled($cron_hook)) { wp_schedule_event(time(), 'daily', $cron_hook); } } public function custom_schedules(array $schedules): array { $schedules['3hours'] = ['interval' => 60 * 60 * 3, 'display' => 'Three Hours']; return $schedules; } public function check_license_cron_run(): void { $this->license->update(); } public function enqueue_license_scripts(): void { if (!isset($_GET['page']) || 'yaycommerce-licenses' !== $_GET['page']) { // phpcs:ignore WordPress.Security.NonceVerification return; } $slug = $this->adapter->get_plugin_slug(); $assets_url = plugin_dir_url(__FILE__) . '../../assets/'; wp_enqueue_script('yaycommerce-license', $assets_url . 'js/license.js', ['jquery'], $this->adapter->get_plugin_version(), \true); wp_localize_script('yaycommerce-license', Slug::to_var_name($slug) . 'LicenseData', ['slug' => $slug, 'apiSettings' => ['restNonce' => wp_create_nonce('wp_rest'), 'restUrl' => esc_url_raw(rest_url(Slug::to_var_name($slug) . '/v1')), 'adminUrl' => admin_url()]]); } public function render_license_settings(): void { $license = $this->license; $_plugin = ['slug' => $this->adapter->get_plugin_slug(), 'name' => $this->adapter->get_plugin_name()]; if ($license->is_active()) { include __DIR__ . '/../../views/license-card.php'; } else { include __DIR__ . '/../../views/license-activate-card.php'; } } public function register_licensing_plugins(array $plugins = []): array { $plugin_data = ['name' => $this->adapter->get_plugin_name(), 'slug' => $this->adapter->get_plugin_slug(), 'basename' => $this->adapter->get_plugin_basename(), 'file' => $this->adapter->get_plugin_file(), 'url' => $this->adapter->get_store_link(), 'item_id' => $this->adapter->get_item_id()]; return array_merge($plugins, [$plugin_data]); } public function not_activate_license_notice(): void { $current_screen = get_current_screen(); if (!$current_screen || $current_screen->id !== 'plugins') { return; } if ($this->license->is_active()) { return; } $slug = $this->adapter->get_plugin_slug(); $name = $this->adapter->get_plugin_name(); ?>
', ''); ?>
', '' ); ?>