Skip to content

Commit b0f10c1

Browse files
authored
Merge pull request #1689 from equalizedigital/william/no-issue/make-pro-always-authoritive-for-license-checking
Make pro always authoritive for license checking
2 parents f7efcdd + a026e24 commit b0f10c1

6 files changed

Lines changed: 559 additions & 213 deletions

File tree

admin/AdminPage/AccessibilityReportsPage.php

Lines changed: 95 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ public function render_page() {
8484
$is_pro = $license_context['is_pro'];
8585
$license_key = (string) get_option( 'edacp_license_key', '' );
8686
$is_connected = $license_context['is_connected'];
87+
$is_registered = $license_context['is_registered'];
88+
$status = $license_context['status'];
8789
$next_send_date = $this->get_next_send_estimate_date();
8890
$scans_stats = new Scans_Stats();
8991
$summary = $scans_stats->summary();
@@ -137,74 +139,97 @@ public function render_page() {
137139
<section class="edac-reports-page__panel">
138140
<h2><?php esc_html_e( 'Accessibility Reports', 'accessibility-checker' ); ?></h2>
139141

140-
<?php if ( ! $is_connected ) : ?>
141-
<p class="edac-reports-page__intro">
142-
<?php
143-
if ( $is_pro ) {
144-
esc_html_e( 'Get recurring email reports with a snapshot of your site’s accessibility, including total issues, trends over time, most problematic pages, and the most severe issues to fix first.', 'accessibility-checker' );
145-
} else {
146-
esc_html_e( 'Get recurring email reports with a snapshot of your site’s accessibility, including total issues, trends over time, most problematic pages, and the most severe issues to fix first. Some details, like full-site coverage and issue breakdowns, are available in Pro.', 'accessibility-checker' );
147-
}
148-
?>
149-
</p>
150-
151-
<?php if ( $is_pro ) : ?>
152-
<div class="edac-reports-page__single-action">
142+
<?php if ( ! $is_connected && 'expired' === $status && $is_registered ) : ?>
143+
<div class="edac-reports-grid edac-reports-grid--two">
144+
<div class="edac-reports-card">
145+
<div class="edac-reports-card__header">
146+
<h3><?php esc_html_e( 'License Expired', 'accessibility-checker' ); ?></h3>
147+
</div>
148+
<p>
149+
<?php esc_html_e( 'Your license has expired. This site is still connected but reports may stop until your license is renewed.', 'accessibility-checker' ); ?>
150+
</p>
151+
<p>
152+
<a href="<?php echo esc_url( edac_link_wrapper( 'https://my.equalizedigital.com/', 'accessibility-reports', 'renew', false ) ); ?>" target="_blank" rel="noopener noreferrer">
153+
<?php esc_html_e( 'Renew your license', 'accessibility-checker' ); ?>
154+
</a>
155+
</p>
153156
<form method="post" action="<?php echo esc_url( admin_url( 'admin-post.php' ) ); ?>">
154-
<input type="hidden" name="action" value="edac_jwt_register" />
155-
<?php wp_nonce_field( 'edac_jwt_register', 'edac_jwt_register_nonce' ); ?>
156-
<button type="submit" class="button button-primary edac-reports-page__button">
157+
<input type="hidden" name="action" value="edac_jwt_unregister" />
158+
<?php wp_nonce_field( 'edac_jwt_unregister', 'edac_jwt_unregister_nonce' ); ?>
159+
<button type="submit" class="button edac-reports-page__button" name="edac_jwt_unregister">
160+
<?php esc_html_e( 'Disable Email Reports', 'accessibility-checker' ); ?>
161+
</button>
162+
</form>
163+
</div>
164+
</div>
165+
<?php elseif ( ! $is_connected ) : ?>
166+
<p class="edac-reports-page__intro">
167+
<?php
168+
if ( $is_pro ) {
169+
esc_html_e( 'Get recurring email reports with a snapshot of your site’s accessibility, including total issues, trends over time, most problematic pages, and the most severe issues to fix first.', 'accessibility-checker' );
170+
} else {
171+
esc_html_e( 'Get recurring email reports with a snapshot of your site’s accessibility, including total issues, trends over time, most problematic pages, and the most severe issues to fix first. Some details, like full-site coverage and issue breakdowns, are available in Pro.', 'accessibility-checker' );
172+
}
173+
?>
174+
</p>
175+
176+
<?php if ( $is_pro ) : ?>
177+
<div class="edac-reports-page__single-action">
178+
<form method="post" action="<?php echo esc_url( admin_url( 'admin-post.php' ) ); ?>">
179+
<input type="hidden" name="action" value="edac_jwt_register" />
180+
<?php wp_nonce_field( 'edac_jwt_register', 'edac_jwt_register_nonce' ); ?>
181+
<button type="submit" class="button button-primary edac-reports-page__button">
182+
<?php esc_html_e( 'Enable Email Reports', 'accessibility-checker' ); ?>
183+
</button>
184+
</form>
185+
</div>
186+
<?php else : ?>
187+
<div class="edac-reports-grid edac-reports-grid--two">
188+
<div class="edac-reports-card">
189+
<h3><?php esc_html_e( 'Free License Key', 'accessibility-checker' ); ?></h3>
190+
<form method="post" action="<?php echo esc_url( admin_url( 'admin-post.php' ) ); ?>">
191+
<input type="hidden" name="action" value="edac_license" />
192+
<?php wp_nonce_field( 'edac_license_nonce', 'edac_license_nonce' ); ?>
193+
<label class="screen-reader-text" for="edac-reports-license-key"><?php esc_html_e( 'Free License Key', 'accessibility-checker' ); ?></label>
194+
<input id="edac-reports-license-key" name="edacp_license_key" type="text" class="regular-text edac-reports-page__license-input" value="<?php echo esc_attr( $license_key ); ?>" />
195+
<button type="submit" class="button button-primary edac-reports-page__button" name="edac_license_activate">
157196
<?php esc_html_e( 'Enable Email Reports', 'accessibility-checker' ); ?>
158197
</button>
159198
</form>
160199
</div>
161-
<?php else : ?>
162-
<div class="edac-reports-grid edac-reports-grid--two">
163-
<div class="edac-reports-card">
164-
<h3><?php esc_html_e( 'Free License Key', 'accessibility-checker' ); ?></h3>
165-
<form method="post" action="<?php echo esc_url( admin_url( 'admin-post.php' ) ); ?>">
166-
<input type="hidden" name="action" value="edac_license" />
167-
<?php wp_nonce_field( 'edac_license_nonce', 'edac_license_nonce' ); ?>
168-
<label class="screen-reader-text" for="edac-reports-license-key"><?php esc_html_e( 'Free License Key', 'accessibility-checker' ); ?></label>
169-
<input id="edac-reports-license-key" name="edacp_license_key" type="text" class="regular-text edac-reports-page__license-input" value="<?php echo esc_attr( $license_key ); ?>" />
170-
<button type="submit" class="button button-primary edac-reports-page__button" name="edac_license_activate">
171-
<?php esc_html_e( 'Enable Email Reports', 'accessibility-checker' ); ?>
172-
</button>
173-
</form>
174-
</div>
175200

176-
<div class="edac-reports-card">
177-
<h3><?php esc_html_e( 'Get a Free License Key', 'accessibility-checker' ); ?></h3>
178-
<p>
179-
<?php
180-
printf(
181-
/* translators: %s: dashboard URL. */
182-
wp_kses_post( __( 'Got the plugin from Equalize Digital? Your key is in your <a href="%s" target="_blank" rel="noopener noreferrer">dashboard</a>.', 'accessibility-checker' ) ),
183-
esc_url( $dashboard_url )
184-
);
185-
?>
186-
</p>
187-
<p>
188-
<?php
189-
printf(
190-
/* translators: %s: signup URL. */
191-
wp_kses_post( __( 'Installed from WordPress.org? <a href="%s" target="_blank" rel="noopener noreferrer">Create a free account</a> to get one.', 'accessibility-checker' ) ),
192-
esc_url( $signup_url )
193-
);
194-
?>
195-
</p>
196-
<p>
197-
<?php
198-
printf(
199-
/* translators: %s: signup URL. */
200-
wp_kses_post( __( 'Not sure? Just <a href="%s" target="_blank" rel="noopener noreferrer">create a free account</a>. It only takes a minute.', 'accessibility-checker' ) ),
201-
esc_url( $signup_url )
202-
);
203-
?>
204-
</p>
205-
</div>
201+
<div class="edac-reports-card">
202+
<h3><?php esc_html_e( 'Get a Free License Key', 'accessibility-checker' ); ?></h3>
203+
<p>
204+
<?php
205+
printf(
206+
/* translators: %s: dashboard URL. */
207+
wp_kses_post( __( 'Got the plugin from Equalize Digital? Your key is in your <a href="%s" target="_blank" rel="noopener noreferrer">dashboard</a>.', 'accessibility-checker' ) ),
208+
esc_url( $dashboard_url )
209+
);
210+
?>
211+
</p>
212+
<p>
213+
<?php
214+
printf(
215+
/* translators: %s: signup URL. */
216+
wp_kses_post( __( 'Installed from WordPress.org? <a href="%s" target="_blank" rel="noopener noreferrer">Create a free account</a> to get one.', 'accessibility-checker' ) ),
217+
esc_url( $signup_url )
218+
);
219+
?>
220+
</p>
221+
<p>
222+
<?php
223+
printf(
224+
/* translators: %s: signup URL. */
225+
wp_kses_post( __( 'Not sure? Just <a href="%s" target="_blank" rel="noopener noreferrer">create a free account</a>. It only takes a minute.', 'accessibility-checker' ) ),
226+
esc_url( $signup_url )
227+
);
228+
?>
229+
</p>
206230
</div>
207-
<?php endif; ?>
231+
</div>
232+
<?php endif; ?>
208233
<?php else : ?>
209234
<div class="edac-reports-grid edac-reports-grid--two">
210235
<div class="edac-reports-card">
@@ -324,19 +349,23 @@ private function get_license_context(): array {
324349
* @param string $free_status Current free license status.
325350
* @param string $site_id Current connected site ID.
326351
* @param bool $fallback_active Whether a fallback from Pro to Free is currently active.
327-
* @return array{has_pro_plugin:bool,is_pro:bool,status:string,is_connected:bool,fallback_active:bool}
352+
* @return array{has_pro_plugin:bool,is_pro:bool,status:string,is_connected:bool,is_registered:bool,fallback_active:bool}
328353
*/
329354
private static function resolve_license_context( bool $has_pro_plugin, string $pro_status, string $free_status, string $site_id, bool $fallback_active = false ): array {
330-
$is_pro = $has_pro_plugin && 'valid' === $pro_status && ! $fallback_active;
331-
$status = $is_pro ? $pro_status : $free_status;
332-
$is_connected = 'valid' === $status && '' !== $site_id;
333-
355+
$is_pro = $has_pro_plugin && 'valid' === $pro_status && ! $fallback_active;
356+
$status = $is_pro ? $pro_status : $free_status;
357+
// is_connected is true when:
358+
// 1. License status is valid AND site_id exists, OR
359+
// 2. Pro exists but is expired/degraded (fallback_active), AND site_id exists (reports still flowing).
360+
$is_connected = ( 'valid' === $status && '' !== $site_id ) || ( $has_pro_plugin && $fallback_active && '' !== $site_id );
361+
$is_registered = '' !== $site_id;
334362

335363
return [
336364
'has_pro_plugin' => $has_pro_plugin,
337365
'is_pro' => $is_pro,
338366
'status' => $status,
339367
'is_connected' => $is_connected,
368+
'is_registered' => $is_registered,
340369
'fallback_active' => $fallback_active,
341370
];
342371
}

admin/AdminPage/ConnectedServicesPage.php

Lines changed: 87 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ public function render_page() {
131131
$status = $license_context['status'];
132132
$license = get_option( 'edacp_license_key' );
133133
$is_connected = $license_context['is_connected'];
134+
$is_registered = $license_context['is_registered'];
134135
$degraded_context = $this->get_degraded_notice_context( $license_context );
135136
$degraded_notice = $this->get_degraded_notice_message( $license_context );
136137
$dashboard_link = '<a href="' . esc_url( \edac_link_wrapper( 'https://my.equalizedigital.com/', 'connected-services', 'account', false ) ) . '" target="_blank" rel="noopener noreferrer">my.equalizedigital.com</a>';
@@ -174,48 +175,66 @@ class="regular-text"
174175
<tr valign="top">
175176
<th scope="row" valign="top"></th>
176177
<td>
177-
<input type="hidden" name="action" value="edac_license" />
178-
<?php wp_nonce_field( 'edac_license_nonce', 'edac_license_nonce' ); ?>
179-
<?php if ( $is_connected ) : ?>
180-
<input
181-
type="submit"
182-
class="button-primary"
183-
name="edac_license_deactivate"
184-
value="<?php esc_attr_e( 'Disconnect Site', 'accessibility-checker' ); ?>"
185-
>
186-
<?php else : ?>
187-
<input
188-
type="submit"
189-
class="button-primary"
190-
name="edac_license_activate"
191-
value="<?php esc_attr_e( 'Connect Site', 'accessibility-checker' ); ?>"
192-
/>
193-
<?php endif; ?>
178+
<input type="hidden" name="action" value="edac_license" />
179+
<?php wp_nonce_field( 'edac_license_nonce', 'edac_license_nonce' ); ?>
180+
<?php if ( $is_connected ) : ?>
181+
<input
182+
type="submit"
183+
class="button-primary"
184+
name="edac_license_deactivate"
185+
value="<?php esc_attr_e( 'Disconnect Site', 'accessibility-checker' ); ?>"
186+
>
187+
<?php elseif ( ! $is_connected && 'expired' === $status && $is_registered ) : ?>
188+
<input
189+
type="submit"
190+
class="button-primary"
191+
name="edac_license_deactivate"
192+
value="<?php esc_attr_e( 'Disconnect Site', 'accessibility-checker' ); ?>"
193+
>
194+
<?php else : ?>
195+
<input
196+
type="submit"
197+
class="button-primary"
198+
name="edac_license_activate"
199+
value="<?php esc_attr_e( 'Connect Site', 'accessibility-checker' ); ?>"
200+
/>
201+
<?php endif; ?>
194202
</td>
195203
</tr>
196204
</tbody>
197205
</table>
198206
</form>
199-
<?php if ( ! $is_connected ) : ?>
200-
<p>
201-
<?php
202-
printf(
203-
/* translators: %s: link to my.equalizedigital.com dashboard */
204-
esc_html__( 'If you downloaded the free plugin from Equalize Digital, you already have a free license key in your %s dashboard.', 'accessibility-checker' ),
205-
wp_kses_post( $dashboard_link )
206-
);
207-
?>
208-
</p>
209-
<p>
210-
<?php
211-
printf(
212-
/* translators: %s: link to create a free account */
213-
esc_html__( 'If not, %s to generate a license key and connect this site.', 'accessibility-checker' ),
214-
wp_kses_post( $create_account_link )
215-
);
216-
?>
217-
</p>
218-
<?php endif; ?>
207+
<?php if ( ! $is_connected && ! $is_registered ) : ?>
208+
<p>
209+
<?php
210+
printf(
211+
/* translators: %s: link to my.equalizedigital.com dashboard */
212+
esc_html__( 'If you downloaded the free plugin from Equalize Digital, you already have a free license key in your %s dashboard.', 'accessibility-checker' ),
213+
wp_kses_post( $dashboard_link )
214+
);
215+
?>
216+
</p>
217+
<p>
218+
<?php
219+
printf(
220+
/* translators: %s: link to create a free account */
221+
esc_html__( 'If not, %s to generate a license key and connect this site.', 'accessibility-checker' ),
222+
wp_kses_post( $create_account_link )
223+
);
224+
?>
225+
</p>
226+
<?php elseif ( ! $is_connected && 'expired' === $status && $is_registered ) : ?>
227+
<p>
228+
<?php
229+
$renew_link = '<a href="' . esc_url( \edac_link_wrapper( 'https://my.equalizedigital.com/', 'connected-services', 'renew', false ) ) . '" target="_blank" rel="noopener noreferrer">' . esc_html__( 'Renew your license', 'accessibility-checker' ) . '</a>';
230+
printf(
231+
/* translators: %s: renew license link */
232+
wp_kses_post( __( 'Your license has expired and this site is still connected. %s to restore full access, or disconnect the site above.', 'accessibility-checker' ) ),
233+
wp_kses_post( $renew_link )
234+
);
235+
?>
236+
</p>
237+
<?php endif; ?>
219238

220239
<?php endif; ?>
221240
<?php
@@ -308,22 +327,29 @@ private function get_license_context(): array {
308327
/**
309328
* Resolve effective license context from current status values.
310329
*
311-
* @param bool $has_pro_plugin Whether the Pro plugin is installed.
312-
* @param string $pro_status Current Pro license status.
313-
* @param string $free_status Current free license status.
314-
* @param string $site_id Current connected site ID.
315-
* @return array{has_pro_plugin:bool,is_pro:bool,status:string,is_connected:bool}
330+
* @param bool $has_pro_plugin Whether the Pro plugin is installed.
331+
* @param string $pro_status Current Pro license status.
332+
* @param string $free_status Current free license status.
333+
* @param string $site_id Current connected site ID.
334+
* @param bool $fallback_active Whether a fallback from Pro to Free is currently active.
335+
* @return array{has_pro_plugin:bool,is_pro:bool,status:string,is_connected:bool,is_registered:bool,fallback_active:bool}
316336
*/
317-
private static function resolve_license_context( bool $has_pro_plugin, string $pro_status, string $free_status, string $site_id ): array {
318-
$is_pro = $has_pro_plugin && 'valid' === $pro_status;
319-
$status = $is_pro ? $pro_status : $free_status;
320-
$is_connected = 'valid' === $status && '' !== $site_id;
337+
private static function resolve_license_context( bool $has_pro_plugin, string $pro_status, string $free_status, string $site_id, bool $fallback_active = false ): array {
338+
$is_pro = $has_pro_plugin && 'valid' === $pro_status && ! $fallback_active;
339+
$status = $is_pro ? $pro_status : $free_status;
340+
// is_connected is true when:
341+
// 1. License status is valid AND site_id exists, OR
342+
// 2. Pro exists but is expired/degraded (fallback_active), AND site_id exists (reports still flowing).
343+
$is_connected = ( 'valid' === $status && '' !== $site_id ) || ( $has_pro_plugin && $fallback_active && '' !== $site_id );
344+
$is_registered = '' !== $site_id;
321345

322346
return [
323-
'has_pro_plugin' => $has_pro_plugin,
324-
'is_pro' => $is_pro,
325-
'status' => $status,
326-
'is_connected' => $is_connected,
347+
'has_pro_plugin' => $has_pro_plugin,
348+
'is_pro' => $is_pro,
349+
'status' => $status,
350+
'is_connected' => $is_connected,
351+
'is_registered' => $is_registered,
352+
'fallback_active' => $fallback_active,
327353
];
328354
}
329355

@@ -359,14 +385,20 @@ private static function resolve_error_context( bool $is_pro ): array {
359385
* @param string $pro_status Current Pro status option.
360386
* @param string $effective_status Effective authority status.
361387
* @param bool $is_connected Whether UI currently considers site connected.
388+
* @param bool $fallback_active Whether Pro has degraded to fallback mode.
362389
* @return array{show:bool,mode:string}
363390
*/
364-
private static function resolve_degraded_notice_context( bool $has_pro_plugin, bool $is_pro, string $pro_status, string $effective_status, bool $is_connected ): array {
391+
private static function resolve_degraded_notice_context( bool $has_pro_plugin, bool $is_pro, string $pro_status, string $effective_status, bool $is_connected, bool $fallback_active = false ): array {
392+
// Show degraded notice when:
393+
// - Pro plugin exists AND
394+
// - Pro is not currently active as authority AND
395+
// - Pro status is set but not valid AND
396+
// - Either: Free is valid OR Pro fallback mode is active.
365397
$show = $has_pro_plugin
366398
&& ! $is_pro
367-
&& 'valid' === $effective_status
368399
&& '' !== $pro_status
369-
&& 'valid' !== $pro_status;
400+
&& 'valid' !== $pro_status
401+
&& ( 'valid' === $effective_status || $fallback_active );
370402

371403
if ( ! $show ) {
372404
return [
@@ -377,7 +409,7 @@ private static function resolve_degraded_notice_context( bool $has_pro_plugin, b
377409

378410
return [
379411
'show' => true,
380-
'mode' => ! $is_connected ? 'reconnect' : 'connected',
412+
'mode' => $is_connected ? 'connected' : 'reconnect',
381413
];
382414
}
383415

@@ -395,7 +427,7 @@ private function get_degraded_notice_message( array $license_context ): ?string
395427
}
396428

397429
if ( 'connected' === $notice_context['mode'] ) {
398-
return __( 'Your Pro license is no longer valid. This site is using a valid Free license, and email reports remain connected as Free email reports. Renew your Pro license to restore Pro-only features.', 'accessibility-checker' );
430+
return __( 'Your Pro license is no longer valid. Email reports remain connected as Free email reports. Renew your Pro license to restore Pro-only features.', 'accessibility-checker' );
399431
}
400432

401433
return __( 'Your Pro license is no longer valid. This site is using a valid Free license, but email reports are not currently connected. Connect this site from the Free License section to resume Free email reports.', 'accessibility-checker' );

0 commit comments

Comments
 (0)