-
Notifications
You must be signed in to change notification settings - Fork 19
Add support for registering sites with myDot and exchanging a jwt token that can be used to share site stats #1315
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 15 commits
108be2a
6cb0b73
5fec71e
2acb695
e8895ac
e798fb1
9f16a33
f6e3cf1
3efe96e
50231be
0df4710
4a4463b
cc7d926
095f889
4b4f37d
79614f1
5aa493d
b058479
c20eb30
d8a1dd5
1c77fb1
512fdec
2a2ed34
518d038
cff4290
ce98297
45af7d6
0800d3e
7ef9049
3f57bcb
543f666
fdc1452
b0e986a
cb2c23d
ab0602e
48cf076
02989fe
ffebe5c
027ddfa
15e22e4
cb1950e
0103f65
5f60721
b38b1e0
ef2e00d
8fb2f7a
bac44fb
0f52eab
5856ef4
ceb87f5
3cefde3
acdcec7
5a3b4e2
6362687
7232377
432f5be
bc9ed1d
78ebbd3
ee1c1f5
cb5b420
6b463a6
677e531
84717fa
9861bf8
acbf0d0
f9969ed
da52157
87e5998
f1f5b04
9793b90
e026b99
8cad96c
2bb0fa9
7ba2c42
553fc59
5d929d0
d48231a
29d17c5
70315b7
451a981
e6001b1
95122e6
5c60210
a9cb69e
6b06d43
52d2b2b
195a62f
ab13d4c
a1aa1a9
1567a9b
9ae7e66
b6a0562
9ade581
d4285bc
46a89da
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,353 @@ | ||||||||||||
| <?php | ||||||||||||
| /** | ||||||||||||
| * Connected Services Page and Notices for Accessibility Checker | ||||||||||||
| * | ||||||||||||
| * Handles the rendering and functionality of the license/connected services settings page | ||||||||||||
| * in the WordPress admin, including form submission, error notices, and | ||||||||||||
| * license status management. | ||||||||||||
| * | ||||||||||||
| * @package Accessibility_Checker | ||||||||||||
| * @since 1.34.0 | ||||||||||||
| */ | ||||||||||||
|
|
||||||||||||
| namespace EqualizeDigital\AccessibilityChecker\Admin\AdminPage; | ||||||||||||
|
|
||||||||||||
| use EqualizeDigital\AccessibilityChecker\MyDot\Connector; | ||||||||||||
|
|
||||||||||||
| /** | ||||||||||||
| * Class ConnectedServicesPage | ||||||||||||
| * | ||||||||||||
| * Manages connected services (license) page display and functionality within the admin settings area. | ||||||||||||
| * | ||||||||||||
| * @since 1.xx.x | ||||||||||||
|
pattonwebz marked this conversation as resolved.
|
||||||||||||
| */ | ||||||||||||
| class ConnectedServicesPage implements PageInterface { | ||||||||||||
|
|
||||||||||||
| /** | ||||||||||||
| * The capability required to access the settings page. | ||||||||||||
| * | ||||||||||||
| * @since 1.xx.x | ||||||||||||
| * | ||||||||||||
| * @var string | ||||||||||||
| */ | ||||||||||||
| private string $settings_capability; | ||||||||||||
|
|
||||||||||||
| /** | ||||||||||||
| * Constructor | ||||||||||||
| * | ||||||||||||
| * @since 1.xx.x | ||||||||||||
| * | ||||||||||||
| * @param string $settings_capability The capability required to view/edit license settings. | ||||||||||||
| */ | ||||||||||||
| public function __construct( $settings_capability ) { | ||||||||||||
| $this->settings_capability = $settings_capability; | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| /** | ||||||||||||
| * Register hooks to add the connected services page to the settings tabs | ||||||||||||
| * and handle license-related notices. | ||||||||||||
| * | ||||||||||||
| * @since 1.xx.x | ||||||||||||
| * | ||||||||||||
| * @return void | ||||||||||||
| */ | ||||||||||||
| public function add_page() { | ||||||||||||
| // Add Connected Services tab to settings page. | ||||||||||||
| add_filter( | ||||||||||||
| 'edac_filter_settings_tab_items', | ||||||||||||
| [ $this, 'add_connected_services_tab' ] | ||||||||||||
| ); | ||||||||||||
|
|
||||||||||||
| // Render Connected Services tab content when active. | ||||||||||||
| add_action( | ||||||||||||
| 'edac_settings_tab_content', | ||||||||||||
| [ $this, 'maybe_render_tab_content' ] | ||||||||||||
| ); | ||||||||||||
|
|
||||||||||||
| // Register admin notice display with higher priority than default. | ||||||||||||
| add_action( | ||||||||||||
| 'in_admin_header', | ||||||||||||
| [ $this, 'register_admin_notices' ], | ||||||||||||
| 1001 | ||||||||||||
| ); | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| /** | ||||||||||||
| * Add Connected Services tab to settings tabs array. | ||||||||||||
| * | ||||||||||||
| * @since 1.xx.x | ||||||||||||
| * | ||||||||||||
| * @param array $tabs Array of registered settings tabs. | ||||||||||||
| * | ||||||||||||
| * @return array Modified tabs array with Connected Services tab added. | ||||||||||||
| */ | ||||||||||||
| public function add_connected_services_tab( $tabs ) { | ||||||||||||
| $tabs[] = [ | ||||||||||||
| 'slug' => 'connected-services', | ||||||||||||
| 'label' => esc_html__( 'Connected Services', 'accessibility-checker' ), | ||||||||||||
| 'order' => 99, // Last tab. | ||||||||||||
| 'capability' => $this->settings_capability, | ||||||||||||
| ]; | ||||||||||||
| return $tabs; | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| /** | ||||||||||||
| * Conditionally render the tab content if the current tab is 'connected-services'. | ||||||||||||
| * | ||||||||||||
| * @since 1.xx.x | ||||||||||||
| * | ||||||||||||
| * @param string $settings_tab The current active settings tab. | ||||||||||||
| * | ||||||||||||
| * @return void | ||||||||||||
| */ | ||||||||||||
| public function maybe_render_tab_content( $settings_tab ) { | ||||||||||||
| if ( 'connected-services' === $settings_tab ) { | ||||||||||||
| $this->render_page(); | ||||||||||||
| } | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| /** | ||||||||||||
| * Register the admin notices function to display license-related messages. | ||||||||||||
| * | ||||||||||||
| * @since 1.xx.x | ||||||||||||
| * | ||||||||||||
| * @return void | ||||||||||||
| */ | ||||||||||||
| public function register_admin_notices() { | ||||||||||||
| add_action( 'admin_notices', [ $this, 'admin_notices' ] ); | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| /** | ||||||||||||
| * Render the connected services settings page content. | ||||||||||||
| * | ||||||||||||
| * @since 1.xx.x | ||||||||||||
| * | ||||||||||||
| * @return void | ||||||||||||
| */ | ||||||||||||
| public function render_page() { | ||||||||||||
| $license = get_option( 'edac_license_key' ); | ||||||||||||
| $status = get_option( 'edac_license_status' ); | ||||||||||||
| $jwt_token = get_option( 'edac_jwt_token' ); | ||||||||||||
| $is_connected = ( 'valid' === $status && ! empty( $jwt_token ) ); | ||||||||||||
| $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>'; | ||||||||||||
| $create_account_link = '<a href="' . esc_url( \edac_link_wrapper( 'https://my.equalizedigital.com/sign-up/', 'connected-services', 'signup', false ) ) . '" target="_blank" rel="noopener noreferrer">' . esc_html__( 'create a free account', 'accessibility-checker' ) . '</a>'; | ||||||||||||
| $terms_link = '<a href="' . esc_url( \edac_link_wrapper( 'https://equalizedigital.com/terms-of-service/', 'connected-services', 'terms', false ) ) . '" target="_blank" rel="noopener noreferrer">' . esc_html__( 'Terms of Service', 'accessibility-checker' ) . '</a>'; | ||||||||||||
| $privacy_link = '<a href="' . esc_url( \edac_link_wrapper( 'https://equalizedigital.com/privacy-policy/', 'connected-services', 'privacy', false ) ) . '" target="_blank" rel="noopener noreferrer">' . esc_html__( 'Privacy Policy', 'accessibility-checker' ) . '</a>'; | ||||||||||||
| ?> | ||||||||||||
| <h2><?php esc_html_e( 'Connected this site', 'accessibility-checker' ); ?></h2> | ||||||||||||
|
pattonwebz marked this conversation as resolved.
Outdated
|
||||||||||||
| <?php if ( ! defined( 'EDACP_VERSION' ) ) : ?> | ||||||||||||
| <form method="post" action="<?php echo esc_url( admin_url( 'admin-post.php' ) ); ?>"> | ||||||||||||
| <?php settings_fields( 'edac_license' ); ?> | ||||||||||||
| <table class="form-table"> | ||||||||||||
|
Comment on lines
+147
to
+149
Contributor
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. Remove or verify The form posts to 🔧 Proposed fix <form method="post" action="<?php echo esc_url( admin_url( 'admin-post.php' ) ); ?>">
- <?php settings_fields( 'edac_license' ); ?>
<table class="form-table">📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||
| <tbody> | ||||||||||||
| <tr valign="top"> | ||||||||||||
| <th scope="row" valign="top"> | ||||||||||||
| <?php esc_html_e( 'Free License Key', 'accessibility-checker' ); ?> | ||||||||||||
| </th> | ||||||||||||
| <td> | ||||||||||||
| <input | ||||||||||||
| id="edac_license_key" | ||||||||||||
| name="edac_license_key" | ||||||||||||
| type="text" | ||||||||||||
| class="regular-text" | ||||||||||||
| value="<?php echo esc_attr( $license ); ?>" | ||||||||||||
| /> | ||||||||||||
| <label class="description" for="edac_license_key"> | ||||||||||||
| <?php if ( $is_connected ) : ?> | ||||||||||||
| <span style="color:green;"> <?php esc_html_e( 'active', 'accessibility-checker' ); ?></span> | ||||||||||||
|
pattonwebz marked this conversation as resolved.
|
||||||||||||
| <?php elseif ( false !== $status && 'expired' === $status ) : ?> | ||||||||||||
| <span style="color:red;"> <?php esc_html_e( 'expired', 'accessibility-checker' ); ?></span> | ||||||||||||
| <?php else : ?> | ||||||||||||
| <?php esc_html_e( 'Enter your license key', 'accessibility-checker' ); ?> | ||||||||||||
| <?php endif; ?> | ||||||||||||
| </label> | ||||||||||||
| </td> | ||||||||||||
| </tr> | ||||||||||||
| <tr valign="top"> | ||||||||||||
| <th scope="row" valign="top"></th> | ||||||||||||
| <td> | ||||||||||||
| <input type="hidden" name="action" value="edac_license" /> | ||||||||||||
| <?php wp_nonce_field( 'edac_license_nonce', 'edac_license_nonce' ); ?> | ||||||||||||
| <?php if ( $is_connected ) : ?> | ||||||||||||
| <input | ||||||||||||
| type="submit" | ||||||||||||
| class="button-primary" | ||||||||||||
| name="edac_license_deactivate" | ||||||||||||
| value="<?php esc_attr_e( 'Disconnect Site', 'accessibility-checker' ); ?>" | ||||||||||||
| > | ||||||||||||
| <?php else : ?> | ||||||||||||
| <input | ||||||||||||
| type="submit" | ||||||||||||
| class="button-primary" | ||||||||||||
| name="edac_license_activate" | ||||||||||||
| value="<?php esc_attr_e( 'Connect Site', 'accessibility-checker' ); ?>" | ||||||||||||
| /> | ||||||||||||
| <?php endif; ?> | ||||||||||||
| </td> | ||||||||||||
| </tr> | ||||||||||||
| </tbody> | ||||||||||||
| </table> | ||||||||||||
| </form> | ||||||||||||
| <?php if ( ! $is_connected ) : ?> | ||||||||||||
| <p> | ||||||||||||
| <?php | ||||||||||||
| printf( | ||||||||||||
| /* translators: %s: link to my.equalizedigital.com dashboard */ | ||||||||||||
| esc_html__( 'If you downloaded the free plugin from Equalize Digital, you already have a free license key in your %s dashboard.', 'accessibility-checker' ), | ||||||||||||
| wp_kses_post( $dashboard_link ) | ||||||||||||
| ); | ||||||||||||
| ?> | ||||||||||||
| </p> | ||||||||||||
| <p> | ||||||||||||
| <?php | ||||||||||||
| printf( | ||||||||||||
| /* translators: %s: link to create a free account */ | ||||||||||||
| esc_html__( 'If not, %s to generate a license key and connect this site.', 'accessibility-checker' ), | ||||||||||||
| wp_kses_post( $create_account_link ) | ||||||||||||
| ); | ||||||||||||
| ?> | ||||||||||||
| </p> | ||||||||||||
| <?php endif; ?> | ||||||||||||
|
|
||||||||||||
| <?php else : ?> | ||||||||||||
| <p><?php esc_html_e( 'Get monthly accessibility email reports and access to additional services by connecting this site.', 'accessibility-checker' ); ?></p> | ||||||||||||
| <table class="form-table"> | ||||||||||||
| <tbody> | ||||||||||||
| <tr valign="top"> | ||||||||||||
| <th scope="row" valign="top"> | ||||||||||||
| <?php esc_html_e( 'Connect site', 'accessibility-checker' ); ?> | ||||||||||||
| </th> | ||||||||||||
| <td> | ||||||||||||
| <?php if ( $is_connected ) : ?> | ||||||||||||
| <form method="post" action="<?php echo esc_url( admin_url( 'admin-post.php' ) ); ?>" style="margin:0;"> | ||||||||||||
| <input type="hidden" name="action" value="edac_jwt_unregister" /> | ||||||||||||
| <?php wp_nonce_field( 'edac_jwt_unregister', 'edac_jwt_unregister_nonce' ); ?> | ||||||||||||
| <input | ||||||||||||
| type="submit" | ||||||||||||
| class="button-primary" | ||||||||||||
| name="edac_jwt_unregister" | ||||||||||||
| value="<?php esc_attr_e( 'Disconnect Site', 'accessibility-checker' ); ?>" | ||||||||||||
| > | ||||||||||||
| </form> | ||||||||||||
| <?php else : ?> | ||||||||||||
| <form method="post" action="<?php echo esc_url( admin_url( 'admin-post.php' ) ); ?>" style="margin:0;"> | ||||||||||||
| <input type="hidden" name="action" value="edac_jwt_register" /> | ||||||||||||
| <?php wp_nonce_field( 'edac_jwt_register', 'edac_jwt_register_nonce' ); ?> | ||||||||||||
| <input | ||||||||||||
| type="submit" | ||||||||||||
| class="button-primary" | ||||||||||||
| name="edac_jwt_register" | ||||||||||||
| value="<?php esc_attr_e( 'Connect Site', 'accessibility-checker' ); ?>" | ||||||||||||
| /> | ||||||||||||
| </form> | ||||||||||||
| <?php endif; ?> | ||||||||||||
| </td> | ||||||||||||
| </tr> | ||||||||||||
| </tbody> | ||||||||||||
| </table> | ||||||||||||
| <?php endif; ?> | ||||||||||||
| <p> | ||||||||||||
| <?php | ||||||||||||
| printf( | ||||||||||||
| /* translators: %1$s: link to Terms of Service, %2$s: link to Privacy Policy */ | ||||||||||||
| esc_html__( 'By connecting this site, you agree to the Equalize Digital %1$s and %2$s.', 'accessibility-checker' ), | ||||||||||||
| wp_kses_post( $terms_link ), | ||||||||||||
| wp_kses_post( $privacy_link ) | ||||||||||||
| ); | ||||||||||||
| ?> | ||||||||||||
| </p> | ||||||||||||
| <?php | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| /** | ||||||||||||
| * Display admin notices when the license added is invalid or expired. | ||||||||||||
| * | ||||||||||||
| * @since 1.xx.x | ||||||||||||
| * | ||||||||||||
| * @return void | ||||||||||||
| */ | ||||||||||||
| public function admin_notices() { | ||||||||||||
| $error = get_option( 'edac_license_error' ); | ||||||||||||
| $license_url = get_bloginfo( 'url' ) . '/wp-admin/admin.php?page=accessibility_checker_settings&tab=connected-services'; | ||||||||||||
|
coderabbitai[bot] marked this conversation as resolved.
Outdated
|
||||||||||||
| $message = null; | ||||||||||||
|
|
||||||||||||
| if ( $error ) { | ||||||||||||
| $message = $this->get_error_message( $error, $license_url ); | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| if ( isset( $message ) ) { | ||||||||||||
| printf( | ||||||||||||
| '<div class="notice notice-error"><p>%s</p></div>', | ||||||||||||
| wp_kses_post( $message ) | ||||||||||||
| ); | ||||||||||||
| } | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| /** | ||||||||||||
| * Get appropriate error message based on the license error code. | ||||||||||||
| * | ||||||||||||
| * @since 1.xx.x | ||||||||||||
| * | ||||||||||||
| * @param string $error_code The license error code. | ||||||||||||
| * @param string $license_url URL to the license settings page. | ||||||||||||
| * | ||||||||||||
| * @return string The formatted error message. | ||||||||||||
| */ | ||||||||||||
| private function get_error_message( $error_code, $license_url ) { | ||||||||||||
| switch ( $error_code ) { | ||||||||||||
| case 'expired': | ||||||||||||
| return sprintf( | ||||||||||||
| /* translators: %1$s: item name, %2$s: item name */ | ||||||||||||
| __( 'Your %1$s license has expired. <a href="https://my.equalizedigital.com/?utm_source=wpadmin" target="_blank">Please renew your license</a> to continue accessing additional features and services for %2$s.', 'accessibility-checker' ), | ||||||||||||
| Connector::PRODUCT_NAME, | ||||||||||||
| Connector::PRODUCT_NAME | ||||||||||||
| ); | ||||||||||||
|
|
||||||||||||
| case 'disabled': | ||||||||||||
| case 'revoked': | ||||||||||||
| return sprintf( | ||||||||||||
| /* translators: %s: item name */ | ||||||||||||
| __( 'Your %s license key has been disabled. Please contact our support team if you believe this is an error or would like to continue accessing additional features.', 'accessibility-checker' ), | ||||||||||||
| Connector::PRODUCT_NAME | ||||||||||||
| ); | ||||||||||||
|
|
||||||||||||
| case 'missing': | ||||||||||||
| return sprintf( | ||||||||||||
| /* translators: %1$s: item name, %2$s: license url, %3$s: item name */ | ||||||||||||
| __( 'The license key for %1$s appears to be invalid. Please <a href="%2$s">check your license key</a> to access additional accessibility features and services for %3$s.', 'accessibility-checker' ), | ||||||||||||
| Connector::PRODUCT_NAME, | ||||||||||||
| $license_url, | ||||||||||||
| Connector::PRODUCT_NAME | ||||||||||||
| ); | ||||||||||||
|
|
||||||||||||
| case 'invalid': | ||||||||||||
| case 'site_inactive': | ||||||||||||
| return sprintf( | ||||||||||||
| /* translators: %s: item name */ | ||||||||||||
| __( 'This license key for %s is not active for this site. Please activate it to access additional features on this website.', 'accessibility-checker' ), | ||||||||||||
| Connector::PRODUCT_NAME | ||||||||||||
| ); | ||||||||||||
|
|
||||||||||||
| case 'item_name_mismatch': | ||||||||||||
| return sprintf( | ||||||||||||
| /* translators: %s: the plugins item name */ | ||||||||||||
| __( 'This license key does not appear to be valid for %s. Please verify you\'ve entered the correct license key.', 'accessibility-checker' ), | ||||||||||||
| Connector::PRODUCT_NAME | ||||||||||||
| ); | ||||||||||||
|
|
||||||||||||
| case 'no_activations_left': | ||||||||||||
| return sprintf( | ||||||||||||
| /* translators: %s: the plugins item name */ | ||||||||||||
| __( 'Your %s license key has reached its site activation limit. You can upgrade your license or deactivate it on another site to use the additional features here.', 'accessibility-checker' ), | ||||||||||||
| Connector::PRODUCT_NAME | ||||||||||||
| ); | ||||||||||||
|
|
||||||||||||
| default: | ||||||||||||
| return sprintf( | ||||||||||||
| /* translators: %s: the plugins item name */ | ||||||||||||
| __( 'There was an issue validating your %s license key. Please try again or contact our support team if the problem persists.', 'accessibility-checker' ), | ||||||||||||
| Connector::PRODUCT_NAME | ||||||||||||
| ); | ||||||||||||
| } | ||||||||||||
| } | ||||||||||||
| } | ||||||||||||
Uh oh!
There was an error while loading. Please reload this page.