-
Notifications
You must be signed in to change notification settings - Fork 31
Legacy license field improvements #2960
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
960edff
fa916c2
859574d
ae61456
b18e87d
3d08cb4
07c8007
c401e02
aab9e63
0b03b38
a8f9d74
e2231e8
ddce579
f6e1239
085650f
bdabde4
98e3f64
90489d5
52d1051
6298ee3
c7b54fd
c53de37
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| Significance: minor | ||
| Type: fix | ||
|
|
||
| Warn users when they attempt to enter a Unified license key into the standalone license key field |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -29,12 +29,21 @@ | |
| * @package TEC\Common\Libraries\Harbor | ||
| */ | ||
| class Harbor extends Controller_Contract { | ||
| /** | ||
| * Prefix for Liquid Web unified license keys. | ||
| * | ||
| * @since TBD | ||
| * | ||
| * @var string | ||
| */ | ||
| private const UNIFIED_LICENSE_KEY_PREFIX = 'LWSW-'; | ||
|
|
||
| /** | ||
| * The TEC product slug to Harbor product slug map. | ||
| * | ||
| * @since 6.11.0 | ||
| * | ||
| * @var array | ||
| * @var array<string, string> | ||
| */ | ||
| private const TEC_PRODUCT_SLUG_TO_HARBOR_PRODUCT_SLUG_MAP = [ | ||
| 'the-events-calendar' => 'the-events-calendar', | ||
|
|
@@ -81,6 +90,9 @@ public function do_register(): void { | |
|
|
||
| add_filter( 'lw-harbor/legacy_licenses', [ $this,'register_legacy_licenses' ] ); | ||
| add_filter( 'lw_harbor/premium_plugin_exists', [ $this, 'register_premium_plugin_exists' ] ); | ||
| // Runs even when Harbor does not fully load (no premium plugin), so unified keys | ||
| // pasted into free-plugin PUE fields still get a clear guidance message. | ||
| add_filter( 'tec_common_pue_pre_validate_key', [ $this, 'filter_tec_common_pue_pre_validate_key' ], 10, 3 ); | ||
|
|
||
| Harbor_Provider::init(); | ||
|
|
||
|
|
@@ -105,6 +117,7 @@ public function do_register(): void { | |
| public function unregister(): void { | ||
| remove_filter( 'lw-harbor/legacy_licenses', [ $this,'register_legacy_licenses' ] ); | ||
| remove_filter( 'lw_harbor/premium_plugin_exists', [ $this, 'register_premium_plugin_exists' ] ); | ||
| remove_filter( 'tec_common_pue_pre_validate_key', [ $this, 'filter_tec_common_pue_pre_validate_key' ] ); | ||
| remove_action( 'init', [ $this, 'decorate_uplinks_auth_url' ] ); | ||
| } | ||
|
|
||
|
|
@@ -119,6 +132,48 @@ public function decorate_uplinks_auth_url(): void { | |
| $this->container->bind( Auth_Url::class, Auth_URL_Decorator::class ); | ||
| } | ||
|
|
||
| /** | ||
| * Reject unified license keys when Harbor is not loaded. | ||
| * | ||
| * Without a premium plugin, Harbor never fires `lw_harbor/loaded` and the PUE | ||
| * Harbor integration is not registered — so this callback is the only guard that | ||
| * stops a unified key from being sent through legacy PUE validation. | ||
| * | ||
| * @since TBD | ||
| * | ||
| * @param array|null $response Early response, or null to continue. | ||
| * @param string $key The license key being validated. | ||
| * @param \Tribe__PUE__Checker|null $checker The PUE checker instance. | ||
| * | ||
| * @return array|null | ||
| */ | ||
| public function filter_tec_common_pue_pre_validate_key( ?array $response, string $key, $checker ): ?array { | ||
| if ( null !== $response ) { | ||
| return $response; | ||
| } | ||
|
|
||
| // Bail out if harbor is loaded. | ||
| if ( did_action( 'lw_harbor/loaded' ) ) { | ||
|
dpanta94 marked this conversation as resolved.
|
||
| return $response; | ||
| } | ||
|
|
||
| if ( ! $this->is_unified_license_key( $key ) ) { | ||
| return $response; | ||
| } | ||
|
|
||
| return [ | ||
| 'status' => 0, | ||
| 'message' => sprintf( | ||
| /* translators: %s: My account page link. */ | ||
| __( | ||
| 'This is a unified license key. To activate it, install The Events Calendar Pro or Event Tickets Pro, then add your license in the Unified License Manager. You can download the plugin from <a href="%s" target="_blank">your account</a>.', | ||
| 'tribe-common' | ||
| ), | ||
| esc_url( $this->get_portal_url() ) | ||
| ), | ||
| ]; | ||
| } | ||
|
|
||
| /** | ||
| * Get the premium plugin existence callbacks. | ||
| * | ||
|
|
@@ -232,7 +287,7 @@ public function register_legacy_licenses( array $licenses ): array { | |
| return array_values( | ||
| array_filter( | ||
| $licenses, | ||
| static fn( array $license ): bool => ! empty( $license['key'] ) && ! str_starts_with( $license['key'], 'LWSW-' ) | ||
| fn( array $license ): bool => ! empty( $license['key'] ) && ! $this->is_unified_license_key( $license['key'] ) | ||
| ) | ||
| ); | ||
| } | ||
|
|
@@ -265,6 +320,62 @@ public function is_product_licensed( string $product ): bool { | |
| return lw_harbor_is_feature_available( $product ); | ||
| } | ||
|
|
||
| /** | ||
| * Whether a license key uses the unified Liquid Web format. | ||
| * | ||
| * @since TBD | ||
| * | ||
| * @param string $key The license key. | ||
| * | ||
| * @return bool | ||
| */ | ||
| public function is_unified_license_key( string $key ): bool { | ||
| return str_starts_with( trim( $key ), self::UNIFIED_LICENSE_KEY_PREFIX ); | ||
| } | ||
|
|
||
| /** | ||
| * Whether a TEC product license field is managed by Harbor. | ||
| * | ||
| * When true, the unified license key should be shown read-only and should not | ||
| * be validated through legacy PUE per-product fields. | ||
| * | ||
| * Checks that the product's license is actually active/valid for this site, not | ||
| * merely that the customer's tier entitles them to it — a customer can be entitled | ||
| * to a product without having activated it here, in which case a legacy per-product | ||
| * key should still be accepted. | ||
|
pramodjodhani marked this conversation as resolved.
|
||
| * | ||
| * @since TBD | ||
| * | ||
| * @param string $tec_product_slug The TEC product slug. | ||
| * | ||
| * @return bool | ||
| */ | ||
| public function is_license_field_managed_by_harbor( string $tec_product_slug ): bool { | ||
| if ( ! lw_harbor_has_unified_license_key() ) { | ||
| return false; | ||
| } | ||
|
|
||
| return lw_harbor_is_feature_enabled( | ||
| $this->get_harbor_product_slug( $tec_product_slug ) | ||
| ); | ||
|
Comment on lines
+353
to
+360
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🗄️ Data Integrity & Integration | 🟠 Major | 🏗️ Heavy lift Use the active-capability check for all legacy PUE paths. Line 313 correctly checks whether the capability is active on this site. However, If a customer is entitled to a capability but has not activated it on this site, the field remains editable but PUE still reads and uses the unified key. A saved legacy key cannot become effective. Use the active-capability predicate for these legacy PUE paths. Add coverage with an entitled capability that is not activated on the current site. 🤖 Prompt for AI Agents
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @dpanta94 I think this comment makes sense and should be implemented. But I want to confirm this with you, as its possible I might have not full context of why
|
||
| } | ||
|
|
||
| /** | ||
| * Error message shown when a unified license key is entered in a per-product field. | ||
| * | ||
| * @since TBD | ||
| * | ||
| * @return string | ||
| */ | ||
| public function get_unified_license_key_entry_error_message(): string { | ||
| return sprintf( | ||
| /* translators: %1$s: opening anchor tag, %2$s: closing anchor tag. */ | ||
| __( 'This is a unified license key. Please %1$sclick here%2$s to enter it in the Unified License Manager.', 'tribe-common' ), | ||
| '<a href="' . esc_url( lw_harbor_get_license_page_url() ) . '" target=_blank>', | ||
| '</a>' | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * Get the unified license key if the feature is enabled. | ||
| * | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.