| Server IP : 151.101.66.159 / Your IP : 216.73.216.66 Web Server : Flywheel/5.1.0 System : Linux wordpress 6.12.113+ #1 SMP Thu Oct 22 02:38:20 UTC 2026 x86_64 User : root ( ) PHP Version : 7.4.33.18 Disable Function : disk_free_space,diskfreespace,dl,exec,fpassthru,getmypid,getmyuid,highlight_file,link,opcache_compile_file,opcache_get_configuration,opcache_is_script_cached,passthru,pcntl_alarm,pcntl_exec,pcntl_fork,pcntl_get_last_error,pcntl_getpriority,pcntl_setpriority,pcntl_signal,pcntl_signal_dispatch,pcntl_sigprocmask,pcntl_sigtimedwait,pcntl_sigwaitinfo,pcntl_strerror,pcntl_wait,pcntl_waitpid,pcntl_wexitstatus,pcntl_wifcontinued,pcntl_wifexited,pcntl_wifsignaled,pcntl_wifstopped,pcntl_wstopsig,pcntl_wtermsig,phpinfo,popen,posix_ctermid,posix_getcwd,posix_getegid,posix_geteuid,posix_getgid,posix_getgrgid,posix_getgrnam,posix_getgroups,posix_getlogin,posix_getpgid,posix_getpgrp,posix_getpid,posix_getppid,posix_getpwnam,posix_getpwuid,posix_getrlimit,posix_getsid,posix_getuid,posix_isatty,posix_kill,posix_mkfifo,posix_setegid,posix_seteuid,posix_setgid,posix_setpgid,posix_setsid,posix_setuid,posix_times,posix_ttyname,posix_uname,proc_close,proc_get_status,proc_nice,proc_open,proc_terminate,shell_exec,show_source,socket_listen,source,system,virtual MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /www/wp-content/plugins/filester/vendor-prefixed/src/Registry/ |
Upload File : |
<?php
namespace FilesterScoped\YayCommerce\AdminShell\Registry;
/**
* Reads the legacy yaycommerce_licensing_plugins filter at priority 999
* (after all legacy plugins register at priority 100) and converts each
* legacy registration into a PluginLicenseInfo stub with is_legacy=true.
*
* This enables the unified Licenses page to display un-migrated plugins
* alongside migrated ones during incremental rollout.
* @internal
*/
class LegacyBridge
{
private LicenseRegistry $registry;
public function __construct(LicenseRegistry $registry)
{
$this->registry = $registry;
}
/**
* Hook into plugins_loaded at priority 9999 so the registry is populated
* before admin_menu fires. This guarantees the Licenses submenu renders
* even when only un-migrated (legacy) plugins are active.
*
* Priority 9999 runs AFTER VersionedLoader::elect() at 999 (which calls
* AdminShell::boot() and fires yaycommerce_admin_shell_booted) AND after
* all legacy plugins register via yaycommerce_licensing_plugins at 100.
*
* INVARIANT: if VersionedLoader priority changes, update this priority too.
*/
public function init() : void
{
add_action('plugins_loaded', [$this, 'load_legacy_plugins'], 9999);
}
/**
* Read legacy filter and convert entries to PluginLicenseInfo stubs.
*
* Legacy format (each entry):
* [ 'slug', 'basename', 'file', 'url', 'item_id', 'dir_path', 'name' ]
*/
public function load_legacy_plugins() : void
{
$legacy_plugins = \apply_filters('yaycommerce_licensing_plugins', []);
foreach ($legacy_plugins as $plugin) {
$slug = $plugin['slug'] ?? '';
if (empty($slug)) {
continue;
}
// Skip if already registered by migrated code.
if ($this->registry->has($slug)) {
continue;
}
$info = $this->build_legacy_info($plugin);
$this->registry->register($info);
}
}
/**
* Build a PluginLicenseInfo from a legacy filter entry.
* Reads {slug}_license_info from wp_options to get current status.
*/
private function build_legacy_info(array $plugin) : PluginLicenseInfo
{
$slug = $plugin['slug'] ?? '';
$raw_info = get_option($slug . '_license_info', []);
if (\is_string($raw_info)) {
$raw_info = \json_decode($raw_info, \true) ?: [];
}
$license_key = (string) get_option($slug . '_license_key', '');
$expires_raw = $raw_info['expires'] ?? null;
$status = $this->derive_status($license_key, $raw_info);
$info = new PluginLicenseInfo();
$info->slug = $slug;
$info->name = $plugin['name'] ?? $slug;
$info->version = '';
// legacy plugins don't expose version here
$info->basename = $plugin['basename'] ?? '';
$info->item_id = (int) ($plugin['item_id'] ?? 0);
$info->store_link = $plugin['url'] ?? '';
$info->license_key = $license_key;
$info->status = $status;
$info->expires_at = $expires_raw && 'Not updated' !== $expires_raw ? $expires_raw : null;
$info->activations_used = (int) ($raw_info['site_count'] ?? 0);
$info->activations_limit = (int) ($raw_info['license_limit'] ?? 0);
$info->is_legacy = \true;
$info->raw_info = $raw_info;
return $info;
}
/**
* Derive a normalized status string from legacy option data.
*/
private function derive_status(string $license_key, array $raw_info) : string
{
if (empty($license_key)) {
return 'inactive';
}
$expires = $raw_info['expires'] ?? null;
if ($expires && 'lifetime' !== $expires && 'Not updated' !== $expires) {
if (\strtotime($expires) < \time()) {
return 'expired';
}
}
return 'valid';
}
}