From 97c3e83c08077b3a0384ede985cbdd5cc3c177f7 Mon Sep 17 00:00:00 2001 From: Tanner Record Date: Wed, 11 Sep 2024 12:04:08 -0400 Subject: [PATCH 01/17] Hide authorize link when no valid license present --- src/assets/js/key-admin.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/assets/js/key-admin.js b/src/assets/js/key-admin.js index cef4a7ba..6393792c 100644 --- a/src/assets/js/key-admin.js +++ b/src/assets/js/key-admin.js @@ -3,9 +3,11 @@ $( '.stellarwp-uplink-license-key-field' ).each( function() { var $el = $( this ); var $field = $el.find( 'input[type="text"]' ); + var $oauth = $el.parent().next( '.uplink-authorize-container' ); if ( '' === $field.val().trim() ) { $el.find( '.license-test-results' ).hide(); + $oauth.hide(); } obj.validateKey( $el ); @@ -21,9 +23,11 @@ const field = $el.find( 'input[type="text"]' ) const action = $el.data( 'action' ); const slug = $el.data( 'plugin-slug' ); + const $oauth = $el.find( 'a.uplink-authorize'); let $validityMessage = $el.find( '.key-validity' ); if ( '' === field.val().trim() ) { + $oauth.hide(); return; } @@ -53,9 +57,11 @@ switch (response.status) { case 1: $validityMessage.addClass('valid-key').removeClass('invalid-key'); + $oauth.show(); break; case 2: $validityMessage.addClass('valid-key service-msg'); + $oauth.show(); break; default: $validityMessage.addClass('invalid-key').removeClass('valid-key'); From cc7da69bda8e18d7e2fa3fa5dfcddf24c0057046 Mon Sep 17 00:00:00 2001 From: Tanner Record Date: Wed, 11 Sep 2024 14:06:41 -0400 Subject: [PATCH 02/17] Fix dom traversing to get authorize link --- src/assets/js/key-admin.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/assets/js/key-admin.js b/src/assets/js/key-admin.js index 6393792c..090efd8b 100644 --- a/src/assets/js/key-admin.js +++ b/src/assets/js/key-admin.js @@ -23,7 +23,7 @@ const field = $el.find( 'input[type="text"]' ) const action = $el.data( 'action' ); const slug = $el.data( 'plugin-slug' ); - const $oauth = $el.find( 'a.uplink-authorize'); + const $oauth = $el.parent().next( '.uplink-authorize-container' ).find( 'a.uplink-authorize'); let $validityMessage = $el.find( '.key-validity' ); if ( '' === field.val().trim() ) { From 33e957fb0d09eea36025d4f4de51772bf526f2cc Mon Sep 17 00:00:00 2001 From: Tanner Record Date: Wed, 11 Sep 2024 16:34:00 -0400 Subject: [PATCH 03/17] Render auth button within license field container --- src/Uplink/Admin/Fields/Field.php | 15 ++------------- src/views/admin/fields/field.php | 5 +++++ 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/src/Uplink/Admin/Fields/Field.php b/src/Uplink/Admin/Fields/Field.php index 56fe77eb..ede06230 100644 --- a/src/Uplink/Admin/Fields/Field.php +++ b/src/Uplink/Admin/Fields/Field.php @@ -237,22 +237,11 @@ public function get_render_html(): string { $args = [ 'field' => $this, + 'resource' => $this->resource, 'group' => $this->group->get_name( $this->get_slug() ), ]; - if ( $this->resource->is_using_oauth() ) { - ob_start(); - - if ( $this->resource->oauth_requires_license_key() ) { - echo $this->view->render( self::VIEW, $args ); - } - - UplinkNamespace\render_authorize_button( $this->get_slug() ); - - $html = (string) ob_get_clean(); - } else { - $html = $this->view->render( self::VIEW, $args ); - } + $html = $this->view->render( self::VIEW, $args ); /** * Filters the field HTML. diff --git a/src/views/admin/fields/field.php b/src/views/admin/fields/field.php index ef5134f9..d51b2e26 100644 --- a/src/views/admin/fields/field.php +++ b/src/views/admin/fields/field.php @@ -1,11 +1,13 @@ get_nonce_field(); ?> + is_using_oauth() ) : ?> + slug, $resource->get_home_url(), $resource->license_key); ?> + should_show_label() ) : ?> From 6f0761039596558eee56499a4f23e662fb7b56f3 Mon Sep 17 00:00:00 2001 From: Tanner Record Date: Wed, 11 Sep 2024 16:46:16 -0400 Subject: [PATCH 04/17] Fix issues with strauss missing function namespace --- src/views/admin/fields/field.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/views/admin/fields/field.php b/src/views/admin/fields/field.php index d51b2e26..195e2d68 100644 --- a/src/views/admin/fields/field.php +++ b/src/views/admin/fields/field.php @@ -8,6 +8,7 @@ use StellarWP\Uplink\Config; use StellarWP\Uplink\Admin\Fields\Field; use StellarWP\Uplink\Resources\Resource; +use function StellarWP\Uplink\render_authorize_button; ?> get_nonce_field(); ?> is_using_oauth() ) : ?> - slug, $resource->get_home_url(), $resource->license_key); ?> + slug, get_site_url(), $resource->license_key ?? '' ); ?> should_show_label() ) : ?> From e20bf39b3bc08437acec32dd34f22b7187a80657 Mon Sep 17 00:00:00 2001 From: Tanner Record Date: Thu, 12 Sep 2024 12:42:37 -0400 Subject: [PATCH 05/17] Add slug attribute to easily identify authorize button --- src/Uplink/Components/Admin/Authorize_Button_Controller.php | 1 + src/views/admin/authorize-button.php | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Uplink/Components/Admin/Authorize_Button_Controller.php b/src/Uplink/Components/Admin/Authorize_Button_Controller.php index 7390e520..27191f5d 100644 --- a/src/Uplink/Components/Admin/Authorize_Button_Controller.php +++ b/src/Uplink/Components/Admin/Authorize_Button_Controller.php @@ -212,6 +212,7 @@ public function render( array $args = [] ): void { 'target' => $target, 'tag' => $tag, 'classes' => $this->classes( $classes ), + 'slug' => $slug, ] ); } diff --git a/src/views/admin/authorize-button.php b/src/views/admin/authorize-button.php index 0f5983c1..6b3422ca 100644 --- a/src/views/admin/authorize-button.php +++ b/src/views/admin/authorize-button.php @@ -10,12 +10,13 @@ * @var string $target The link target. * @var string $tag The HTML tag to use for the wrapper. * @var string $classes The CSS classes for the hyperlink. + * @var string $slug The slug of the product the authorize button is for. */ defined( 'ABSPATH' ) || exit; ?> -< class="uplink-authorize-container"> +< class="uplink-authorize-container" data-slug=""> From 81df54862c5897225f20f640eab154aac870f38a Mon Sep 17 00:00:00 2001 From: Tanner Record Date: Thu, 12 Sep 2024 13:22:54 -0400 Subject: [PATCH 06/17] Remove function use statement for Strauss compatibility --- src/views/admin/fields/field.php | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/views/admin/fields/field.php b/src/views/admin/fields/field.php index 195e2d68..2b407539 100644 --- a/src/views/admin/fields/field.php +++ b/src/views/admin/fields/field.php @@ -8,7 +8,7 @@ use StellarWP\Uplink\Config; use StellarWP\Uplink\Admin\Fields\Field; use StellarWP\Uplink\Resources\Resource; -use function StellarWP\Uplink\render_authorize_button; +use StellarWP\Uplink\Components\Admin\Authorize_Button_Controller; ?> get_nonce_field(); ?> is_using_oauth() ) : ?> - slug, get_site_url(), $resource->license_key ?? '' ); ?> + get( Authorize_Button_Controller::class )->render( [ + 'slug' => $field->get_slug(), + 'domain' => get_site_url(), + 'license' => $resource->license_key, + ] ); + } catch ( Throwable $e ) { + if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) { + error_log( "Unable to render authorize button: {$e->getMessage()} {$e->getFile()}:{$e->getLine()} {$e->getTraceAsString()}" ); + } + } + ?> should_show_label() ) : ?> From fe3647b0f8bbd8ce557dd083f78aaed78e053b23 Mon Sep 17 00:00:00 2001 From: Tanner Record Date: Thu, 12 Sep 2024 13:27:35 -0400 Subject: [PATCH 07/17] Use matching plugin slug data attribute --- src/views/admin/authorize-button.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/views/admin/authorize-button.php b/src/views/admin/authorize-button.php index 6b3422ca..8e67b6ba 100644 --- a/src/views/admin/authorize-button.php +++ b/src/views/admin/authorize-button.php @@ -16,7 +16,7 @@ defined( 'ABSPATH' ) || exit; ?> -< class="uplink-authorize-container" data-slug=""> +< class="uplink-authorize-container" data-plugin-slug=""> From c5433cb0957c7ed9aaca4ae73570d5d99786bb09 Mon Sep 17 00:00:00 2001 From: Tanner Record Date: Thu, 12 Sep 2024 13:27:51 -0400 Subject: [PATCH 08/17] Move authorize button within license key field container --- src/views/admin/fields/field.php | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/views/admin/fields/field.php b/src/views/admin/fields/field.php index 2b407539..804806fd 100644 --- a/src/views/admin/fields/field.php +++ b/src/views/admin/fields/field.php @@ -62,22 +62,22 @@ class="regular-text stellarwp-uplink__settings-field" get_key_status_html(); ?> get_nonce_field(); ?> - - is_using_oauth() ) : ?> - get( Authorize_Button_Controller::class )->render( [ - 'slug' => $field->get_slug(), - 'domain' => get_site_url(), - 'license' => $resource->license_key, - ] ); - } catch ( Throwable $e ) { - if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) { - error_log( "Unable to render authorize button: {$e->getMessage()} {$e->getFile()}:{$e->getLine()} {$e->getTraceAsString()}" ); + is_using_oauth() ) : ?> + get( Authorize_Button_Controller::class )->render( [ + 'slug' => $field->get_slug(), + 'domain' => get_site_url(), + 'license' => $resource->license_key, + ] ); + } catch ( Throwable $e ) { + if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) { + error_log( "Unable to render authorize button: {$e->getMessage()} {$e->getFile()}:{$e->getLine()} {$e->getTraceAsString()}" ); + } } - } - ?> - + ?> + + should_show_label() ) : ?> From ec0416c634aed60ad4f22211c82589c55549d8b5 Mon Sep 17 00:00:00 2001 From: Tanner Record Date: Thu, 12 Sep 2024 13:59:05 -0400 Subject: [PATCH 09/17] Fix warning when license key isn't set --- src/views/admin/fields/field.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/views/admin/fields/field.php b/src/views/admin/fields/field.php index 804806fd..da1c0383 100644 --- a/src/views/admin/fields/field.php +++ b/src/views/admin/fields/field.php @@ -68,7 +68,7 @@ class="regular-text stellarwp-uplink__settings-field" Config::get_container()->get( Authorize_Button_Controller::class )->render( [ 'slug' => $field->get_slug(), 'domain' => get_site_url(), - 'license' => $resource->license_key, + 'license' => $resource->license_key ?? '', ] ); } catch ( Throwable $e ) { if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) { From 650a24049de2cda9a07d3214946a6e93a382599b Mon Sep 17 00:00:00 2001 From: Tanner Record Date: Thu, 12 Sep 2024 14:12:40 -0400 Subject: [PATCH 10/17] Move plugin slug to actual button element --- src/views/admin/authorize-button.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/views/admin/authorize-button.php b/src/views/admin/authorize-button.php index 8e67b6ba..3eccd3af 100644 --- a/src/views/admin/authorize-button.php +++ b/src/views/admin/authorize-button.php @@ -16,10 +16,11 @@ defined( 'ABSPATH' ) || exit; ?> -< class="uplink-authorize-container" data-plugin-slug=""> +< class="uplink-authorize-container"> + data-plugin-slug="" > From 281b2110b985898a3c4c094e036baef265a37754 Mon Sep 17 00:00:00 2001 From: Tanner Record Date: Thu, 12 Sep 2024 16:14:17 -0400 Subject: [PATCH 11/17] Finish auth button adjustments --- src/Uplink/Admin/Ajax.php | 13 ++++ src/Uplink/functions.php | 6 +- src/assets/css/main.css | 17 +++-- src/assets/js/key-admin.js | 33 ++++++++-- src/views/admin/fields/field.php | 110 +++++++++++++++---------------- 5 files changed, 111 insertions(+), 68 deletions(-) diff --git a/src/Uplink/Admin/Ajax.php b/src/Uplink/Admin/Ajax.php index f4e263b7..9a9ac45a 100644 --- a/src/Uplink/Admin/Ajax.php +++ b/src/Uplink/Admin/Ajax.php @@ -3,6 +3,7 @@ namespace StellarWP\Uplink\Admin; use StellarWP\ContainerContract\ContainerInterface; +use StellarWP\Uplink\Auth\Auth_Url_Builder; use StellarWP\Uplink\Config; use StellarWP\Uplink\Resources\Collection; use StellarWP\Uplink\Utils; @@ -57,10 +58,22 @@ public function validate_license(): void { $results = $plugin->validate_license( $submission['key'] ); $message = is_plugin_active_for_network( $plugin->get_path() ) ? $results->get_network_message()->get() : $results->get_message()->get(); + try { + $auth_url = Config::get_container()->get( Auth_Url_Builder::class ) + ->set_license( $submission['key'] ) + ->build( $submission['slug'], get_site_url() ); + } catch ( Throwable $e ) { + if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) { + error_log( "Error building auth URL: {$e->getMessage()} {$e->getFile()}:{$e->getLine()} {$e->getTraceAsString()}" ); + } + + $auth_url = ''; + } wp_send_json( [ 'status' => absint( $results->is_valid() ), 'message' => $message, + 'auth_url' => $auth_url, ] ); } diff --git a/src/Uplink/functions.php b/src/Uplink/functions.php index 37f2e56c..f3e91482 100644 --- a/src/Uplink/functions.php +++ b/src/Uplink/functions.php @@ -113,13 +113,15 @@ function is_user_authorized(): bool { * * @param string $slug The Product slug to render the button for. * @param string $domain An optional domain associated with a license key to pass along. + * @param string $license An optional license key to pass along. * * @return string */ -function build_auth_url( string $slug, string $domain = '' ): string { +function build_auth_url( string $slug, string $domain = '', string $license = ''): string { try { return Config::get_container()->get( Auth_Url_Builder::class ) - ->build( $slug, $domain ); + ->set_license( $license ) + ->build( $slug, $domain, $license ); } catch ( Throwable $e ) { if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) { error_log( "Error building auth URL: {$e->getMessage()} {$e->getFile()}:{$e->getLine()} {$e->getTraceAsString()}" ); diff --git a/src/assets/css/main.css b/src/assets/css/main.css index 9344e611..4fbb148a 100644 --- a/src/assets/css/main.css +++ b/src/assets/css/main.css @@ -1,24 +1,31 @@ .license-test-results { - margin-top: 10px; + margin-top: 10px; } .key-validity { - display: inline-block; + display: inline-block; } .valid-key { - color: green; + color: green; } .invalid-key { - color: red; + color: red; +} + +.uplink-authorize-container { + display: inline-block; } .uplink-authorize { - margin-bottom: 16px !important; transition: border-color 300ms ease-in-out; } +.uplink-authorize.button { + vertical-align: initial; +} + .uplink-authorize.not-authorized { background: #b8e6bf; border-color: #00a32a; diff --git a/src/assets/js/key-admin.js b/src/assets/js/key-admin.js index 090efd8b..272b990c 100644 --- a/src/assets/js/key-admin.js +++ b/src/assets/js/key-admin.js @@ -1,13 +1,21 @@ ( function( $, obj ) { obj.init = function() { + + $('a.uplink-authorize').on( 'click', function (e) { + if ( $( this ).attr('disabled') === 'disabled' ) { + e.preventDefault(); + } + } ); + $( '.stellarwp-uplink-license-key-field' ).each( function() { var $el = $( this ); + var slug = $el.data( 'plugin-slug' ); var $field = $el.find( 'input[type="text"]' ); - var $oauth = $el.parent().next( '.uplink-authorize-container' ); + var $oauth = $el.find( `a[data-plugin-slug="${slug}"]`); if ( '' === $field.val().trim() ) { $el.find( '.license-test-results' ).hide(); - $oauth.hide(); + obj.disableAuthorizeButton( $oauth ); } obj.validateKey( $el ); @@ -19,15 +27,25 @@ } ); }; + obj.disableAuthorizeButton = function( $button ) { + $button.attr( 'aria-disabled', 'true' ); + $button.attr( 'disabled', 'disabled' ); + } + + obj.enableAuthorizeButton = function( $button ) { + $button.removeAttr( 'aria-disabled' ); + $button.removeAttr( 'disabled' ); + } + obj.validateKey = function( $el ) { const field = $el.find( 'input[type="text"]' ) const action = $el.data( 'action' ); const slug = $el.data( 'plugin-slug' ); - const $oauth = $el.parent().next( '.uplink-authorize-container' ).find( 'a.uplink-authorize'); + const $oauth = $el.find( `a[data-plugin-slug="${slug}"]`); let $validityMessage = $el.find( '.key-validity' ); if ( '' === field.val().trim() ) { - $oauth.hide(); + obj.disableAuthorizeButton( $oauth ); return; } @@ -53,23 +71,26 @@ $.post(ajaxurl, data, function (response) { $validityMessage.show(); $validityMessage.html(response.message); + $oauth.attr( 'href', response.auth_url ); switch (response.status) { case 1: $validityMessage.addClass('valid-key').removeClass('invalid-key'); - $oauth.show(); + obj.enableAuthorizeButton( $oauth ); break; case 2: $validityMessage.addClass('valid-key service-msg'); - $oauth.show(); + obj.enableAuthorizeButton( $oauth ); break; default: $validityMessage.addClass('invalid-key').removeClass('valid-key'); + obj.disableAuthorizeButton( $oauth ); break; } }).fail(function(error) { $validityMessage.show(); $validityMessage.html(error.message); + obj.disableAuthorizeButton( $oauth ); }).always(function() { $($el).find('.ajax-loading-license').hide(); }); diff --git a/src/views/admin/fields/field.php b/src/views/admin/fields/field.php index da1c0383..4eda4190 100644 --- a/src/views/admin/fields/field.php +++ b/src/views/admin/fields/field.php @@ -23,65 +23,65 @@ ?> should_show_label() ) : ?> - - - + + - + + Date: Fri, 13 Sep 2024 07:26:34 -0400 Subject: [PATCH 12/17] Fix bug causing URL to be overwritten at all times This prevented all disconnect functionality --- src/assets/js/key-admin.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/assets/js/key-admin.js b/src/assets/js/key-admin.js index 272b990c..3470bcbb 100644 --- a/src/assets/js/key-admin.js +++ b/src/assets/js/key-admin.js @@ -71,16 +71,21 @@ $.post(ajaxurl, data, function (response) { $validityMessage.show(); $validityMessage.html(response.message); - $oauth.attr( 'href', response.auth_url ); switch (response.status) { case 1: $validityMessage.addClass('valid-key').removeClass('invalid-key'); obj.enableAuthorizeButton( $oauth ); + if ( $oauth.hasClass( 'not-authorized' ) ) { + $oauth.attr( 'href', response.auth_url ); + } break; case 2: $validityMessage.addClass('valid-key service-msg'); obj.enableAuthorizeButton( $oauth ); + if ( $oauth.hasClass( 'not-authorized' ) ) { + $oauth.attr( 'href', response.auth_url ); + } break; default: $validityMessage.addClass('invalid-key').removeClass('valid-key'); From 85ec045b96e182a68a98448aea6fb48270f1c3b0 Mon Sep 17 00:00:00 2001 From: Tanner Record Date: Fri, 13 Sep 2024 07:43:10 -0400 Subject: [PATCH 13/17] Fix calling build method within ajax request --- src/Uplink/Auth/Auth_Url_Builder.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Uplink/Auth/Auth_Url_Builder.php b/src/Uplink/Auth/Auth_Url_Builder.php index 7e48ed37..1e59c267 100644 --- a/src/Uplink/Auth/Auth_Url_Builder.php +++ b/src/Uplink/Auth/Auth_Url_Builder.php @@ -50,6 +50,13 @@ public function build( string $slug, string $domain = '' ): string { return ''; } + $callback_url = $pagenow; + + // If building the URL in an ajax context, use the referring URL. + if ( wp_parse_url( $pagenow, PHP_URL_PATH ) === 'admin-ajax.php' ) { + $callback_url = wp_get_referer(); + } + $auth_url = $this->auth_url_manager->get( $slug ); if ( ! $auth_url ) { @@ -69,7 +76,7 @@ public function build( string $slug, string $domain = '' ): string { $url = add_query_arg( array_filter( array_merge( $_GET, $args ) ), - admin_url( $pagenow ) + admin_url( $callback_url ) ); return sprintf( '%s?%s', From 662feecbdb75c07e90262c1344fcd1f96eec98dd Mon Sep 17 00:00:00 2001 From: Tanner Record Date: Fri, 13 Sep 2024 07:49:44 -0400 Subject: [PATCH 14/17] Pass full built URL instead of $pagenow --- src/Uplink/Auth/Auth_Url_Builder.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Uplink/Auth/Auth_Url_Builder.php b/src/Uplink/Auth/Auth_Url_Builder.php index 1e59c267..7064cf50 100644 --- a/src/Uplink/Auth/Auth_Url_Builder.php +++ b/src/Uplink/Auth/Auth_Url_Builder.php @@ -50,7 +50,7 @@ public function build( string $slug, string $domain = '' ): string { return ''; } - $callback_url = $pagenow; + $callback_url = admin_url( $pagenow ); // If building the URL in an ajax context, use the referring URL. if ( wp_parse_url( $pagenow, PHP_URL_PATH ) === 'admin-ajax.php' ) { @@ -76,7 +76,7 @@ public function build( string $slug, string $domain = '' ): string { $url = add_query_arg( array_filter( array_merge( $_GET, $args ) ), - admin_url( $callback_url ) + $callback_url ); return sprintf( '%s?%s', From 2f5d4d3c7a95cd930d5760c00e3daf8037e5dad9 Mon Sep 17 00:00:00 2001 From: Tanner Record Date: Fri, 13 Sep 2024 09:54:24 -0400 Subject: [PATCH 15/17] Fix static analysis issues --- src/Uplink/Admin/Ajax.php | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/src/Uplink/Admin/Ajax.php b/src/Uplink/Admin/Ajax.php index 9a9ac45a..25e34ab9 100644 --- a/src/Uplink/Admin/Ajax.php +++ b/src/Uplink/Admin/Ajax.php @@ -56,19 +56,11 @@ public function validate_license(): void { ] ); } - $results = $plugin->validate_license( $submission['key'] ); - $message = is_plugin_active_for_network( $plugin->get_path() ) ? $results->get_network_message()->get() : $results->get_message()->get(); - try { - $auth_url = Config::get_container()->get( Auth_Url_Builder::class ) - ->set_license( $submission['key'] ) - ->build( $submission['slug'], get_site_url() ); - } catch ( Throwable $e ) { - if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) { - error_log( "Error building auth URL: {$e->getMessage()} {$e->getFile()}:{$e->getLine()} {$e->getTraceAsString()}" ); - } - - $auth_url = ''; - } + $results = $plugin->validate_license( $submission['key'] ); + $message = is_plugin_active_for_network( $plugin->get_path() ) ? $results->get_network_message()->get() : $results->get_message()->get(); + $auth_url = Config::get_container()->get( Auth_Url_Builder::class ) + ->set_license( $submission['key'] ) + ->build( $submission['slug'], get_site_url() ); wp_send_json( [ 'status' => absint( $results->is_valid() ), From 4f13cbdcdb31c08fd6819e4c2f19443624f70631 Mon Sep 17 00:00:00 2001 From: Tanner Record Date: Fri, 13 Sep 2024 10:22:08 -0400 Subject: [PATCH 16/17] Fix snapshot test for oauth with license key --- tests/wpunit/Admin/Fields/FieldTest.php | 2 +- ...resource_with_license_key__0.snapshot.html | 63 ++++++++++--------- 2 files changed, 33 insertions(+), 32 deletions(-) diff --git a/tests/wpunit/Admin/Fields/FieldTest.php b/tests/wpunit/Admin/Fields/FieldTest.php index 7ba22f07..28569fe4 100644 --- a/tests/wpunit/Admin/Fields/FieldTest.php +++ b/tests/wpunit/Admin/Fields/FieldTest.php @@ -266,7 +266,7 @@ public function it_should_render_correct_html_for_oauth_resource_with_license_ke update_option( 'test_storage', [ 'stellarwp_auth_url_service_oauth_with_license_key_field_1' => [ 'expiration' => 0, - 'value' => 'https://licensing.stellarwp.com/account-auth?uplink_domain=&uplink_slug=service-oauth-with-license-key-field-1&_uplink_nonce=535281edcd', + 'value' => 'https://licensing.stellarwp.com/account-auth', ] ] ); $collection = $this->container->get( Collection::class ); diff --git a/tests/wpunit/Admin/Fields/__snapshots__/FieldTest__it_should_render_correct_html_for_oauth_resource_with_license_key__0.snapshot.html b/tests/wpunit/Admin/Fields/__snapshots__/FieldTest__it_should_render_correct_html_for_oauth_resource_with_license_key__0.snapshot.html index df61d908..5b395d63 100644 --- a/tests/wpunit/Admin/Fields/__snapshots__/FieldTest__it_should_render_correct_html_for_oauth_resource_with_license_key__0.snapshot.html +++ b/tests/wpunit/Admin/Fields/__snapshots__/FieldTest__it_should_render_correct_html_for_oauth_resource_with_license_key__0.snapshot.html @@ -1,37 +1,38 @@ - - + From da8644673b21e1818e085b119b02ac893be1f1af Mon Sep 17 00:00:00 2001 From: Matthew Batchelder Date: Fri, 13 Sep 2024 13:39:50 -0400 Subject: [PATCH 17/17] chore: Fix spacing --- src/Uplink/Admin/Ajax.php | 7 ++++--- src/Uplink/functions.php | 4 ++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/Uplink/Admin/Ajax.php b/src/Uplink/Admin/Ajax.php index 25e34ab9..14687c41 100644 --- a/src/Uplink/Admin/Ajax.php +++ b/src/Uplink/Admin/Ajax.php @@ -58,9 +58,10 @@ public function validate_license(): void { $results = $plugin->validate_license( $submission['key'] ); $message = is_plugin_active_for_network( $plugin->get_path() ) ? $results->get_network_message()->get() : $results->get_message()->get(); - $auth_url = Config::get_container()->get( Auth_Url_Builder::class ) - ->set_license( $submission['key'] ) - ->build( $submission['slug'], get_site_url() ); + $auth_url = Config::get_container() + ->get( Auth_Url_Builder::class ) + ->set_license( $submission['key'] ) + ->build( $submission['slug'], get_site_url() ); wp_send_json( [ 'status' => absint( $results->is_valid() ), diff --git a/src/Uplink/functions.php b/src/Uplink/functions.php index f3e91482..bc74f581 100644 --- a/src/Uplink/functions.php +++ b/src/Uplink/functions.php @@ -120,8 +120,8 @@ function is_user_authorized(): bool { function build_auth_url( string $slug, string $domain = '', string $license = ''): string { try { return Config::get_container()->get( Auth_Url_Builder::class ) - ->set_license( $license ) - ->build( $slug, $domain, $license ); + ->set_license( $license ) + ->build( $slug, $domain, $license ); } catch ( Throwable $e ) { if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) { error_log( "Error building auth URL: {$e->getMessage()} {$e->getFile()}:{$e->getLine()} {$e->getTraceAsString()}" );