| 1 |
<?php |
| 2 |
|
| 3 |
namespace gVectors\License; |
| 4 |
|
| 5 |
// Exit if accessed directly |
| 6 |
if( ! defined( 'ABSPATH' ) ) exit; |
| 7 |
|
| 8 |
/** |
| 9 |
* Admin UI: enqueues admin CSS/JS and renders the addon store page. |
| 10 |
*/ |
| 11 |
class AdminPage { |
| 12 |
private $config; |
| 13 |
|
| 14 |
public function __construct( Config $config ) { |
| 15 |
$this->config = $config; |
| 16 |
$this->init_hooks(); |
| 17 |
} |
| 18 |
|
| 19 |
private function init_hooks() { |
| 20 |
add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_assets' ] ); |
| 21 |
add_action( $this->config->get_dashboard_menu_hook(), function( $parent_slug ) { |
| 22 |
add_submenu_page( |
| 23 |
$parent_slug, |
| 24 |
__( 'Addons', 'gvectors' ), |
| 25 |
__( 'Addons', 'gvectors' ), |
| 26 |
'activate_plugins', |
| 27 |
$this->config->get_dashboard_addons_page_slug(), |
| 28 |
function() { |
| 29 |
$this->render_store_page(); |
| 30 |
} |
| 31 |
); |
| 32 |
} ); |
| 33 |
} |
| 34 |
|
| 35 |
/** |
| 36 |
* Render the addon store page (called from admin/pages/addons.php replacement or new page) |
| 37 |
*/ |
| 38 |
private function render_store_page(): void { |
| 39 |
if( ! current_user_can( 'activate_plugins' ) ) return; |
| 40 |
$slug = $this->config->get_core_plugin_slug(); |
| 41 |
require __DIR__ . '/../admin/store-page.php'; |
| 42 |
} |
| 43 |
|
| 44 |
/** |
| 45 |
* Enqueue admin assets only on gVectors admin pages |
| 46 |
*/ |
| 47 |
public function enqueue_assets( $hook ): void { |
| 48 |
if( strpos( $hook, $this->config->get_core_plugin_slug() ) === false ) return; |
| 49 |
|
| 50 |
$slug = $this->config->get_core_plugin_slug(); |
| 51 |
$module_url = $this->config->get_license_module_url() . '/admin/assets'; |
| 52 |
$module_dir = __DIR__ . '/../admin/assets'; |
| 53 |
|
| 54 |
// Module CSS (handle prefixed per plugin to avoid dedup conflicts) |
| 55 |
wp_enqueue_style( |
| 56 |
$slug . '-gvlicense-admin', |
| 57 |
$module_url . '/css/admin.css', |
| 58 |
[], |
| 59 |
filemtime( $module_dir . '/css/admin.css' ) |
| 60 |
); |
| 61 |
|
| 62 |
// Module JS (handle prefixed per plugin to avoid dedup conflicts) |
| 63 |
wp_enqueue_script( |
| 64 |
$slug . '-gvlicense-admin', |
| 65 |
$module_url . '/js/admin.js', |
| 66 |
[ 'jquery', 'wp-util' ], |
| 67 |
filemtime( $module_dir . '/js/admin.js' ), |
| 68 |
true |
| 69 |
); |
| 70 |
|
| 71 |
// Pass config to JS (global name prefixed per plugin: e.g. wpforoLicense, wpdiscuzLicense) |
| 72 |
wp_localize_script( $slug . '-gvlicense-admin', $slug . 'License', [ |
| 73 |
'ajaxUrl' => admin_url( 'admin-ajax.php' ), |
| 74 |
'nonce' => wp_create_nonce( $slug . '_gvectors_nonce' ), |
| 75 |
'ajaxPrefix' => $slug . '_gvectors_', |
| 76 |
'proxy_server_url' => $this->config->get_proxy_server_url(), |
| 77 |
'checkout_loading_url' => $this->config->get_proxy_checkout_loading_url(), |
| 78 |
'checkout_url' => $this->config->get_proxy_checkout_base_url(), |
| 79 |
'siteDomain' => LicenseModule::get_site_domain(), |
| 80 |
'i18n' => [ |
| 81 |
'loading' => __( 'Loading...', 'gvectors' ), |
| 82 |
'buy' => __( 'Buy Now', 'gvectors' ), |
| 83 |
'startTrial' => __( 'Start Free Trial', 'gvectors' ), |
| 84 |
'activateLicense' => __( 'Activate License', 'gvectors' ), |
| 85 |
'deactivateLicense' => __( 'Deactivate', 'gvectors' ), |
| 86 |
'install' => __( 'Install', 'gvectors' ), |
| 87 |
'activate' => __( 'Activate', 'gvectors' ), |
| 88 |
'installed' => __( 'Installed', 'gvectors' ), |
| 89 |
'active' => __( 'Active', 'gvectors' ), |
| 90 |
'expired' => __( 'Expired', 'gvectors' ), |
| 91 |
'trial' => __( 'Trial', 'gvectors' ), |
| 92 |
'cancelled' => __( 'Cancelled', 'gvectors' ), |
| 93 |
'enterLicenseKey' => __( 'Enter license key', 'gvectors' ), |
| 94 |
'enterKeyOrId' => __( 'Enter license key or transaction ID', 'gvectors' ), |
| 95 |
'activatingByDomain' => __( 'Searching for licenses registered to this domain...', 'gvectors' ), |
| 96 |
'noLicensesFound' => __( 'No licenses found for this domain', 'gvectors' ), |
| 97 |
'confirmCancel' => __( 'Are you sure you want to cancel this subscription?', 'gvectors' ), |
| 98 |
'processing' => __( 'Processing...', 'gvectors' ), |
| 99 |
'success' => __( 'Success!', 'gvectors' ), |
| 100 |
'error' => __( 'Error', 'gvectors' ), |
| 101 |
'perMonth' => __( '/month', 'gvectors' ), |
| 102 |
'perYear' => __( '/year', 'gvectors' ), |
| 103 |
'oneTime' => __( 'one-time', 'gvectors' ), |
| 104 |
'manageSubscription' => __( 'Manage Subscription', 'gvectors' ), |
| 105 |
'updatePayment' => __( 'Update Payment Method', 'gvectors' ), |
| 106 |
'cancelSubscription' => __( 'Cancel Subscription', 'gvectors' ), |
| 107 |
'pauseSubscription' => __( 'Pause Subscription', 'gvectors' ), |
| 108 |
'resumeSubscription' => __( 'Resume Subscription', 'gvectors' ), |
| 109 |
'refreshProducts' => __( 'Refresh', 'gvectors' ), |
| 110 |
'noProducts' => __( 'No products available at this time.', 'gvectors' ), |
| 111 |
'checkoutError' => __( 'Checkout could not be opened. Please try again.', 'gvectors' ), |
| 112 |
], |
| 113 |
] ); |
| 114 |
} |
| 115 |
} |
| 116 |
|