one-click-accessibility/modules/settings/module.php
VasylD beb8deda2e
[APP-907] Accessibility assistant (#326)
* PHPCS and remediation POC WIP

* WIP Wizard module

* Added scanner module

* [APP-929][APP-930] Add initial setup for wizard, added btn to the topbar (#230)

* [APP-929][APP-930]

* [APP-929][APP-930]

* update logic

* update init app

* [APP-0000] store plan scope after register/switch

* change return of load

* add header

* Move into shadow dom, add context, add headers components

* add UI components

* add UI components

* add UI components

* merge current develop

* merge current develop

* Add AltText Form

* Add scroll to current element

* Align with current design, add loader, added preview for svg

* Align with current design, add loader, added preview for svg

* Resolve comments

* Resolve comments

* Resolve comments

* [APP-934] add submit logic (#259)

* [APP-934] add submit logic

* [APP-934] add submit logic

* [APP-934] add submit logic

* [APP-934] add submit logic

* Added replace remediation action

* Add submit logic

* Add submit alt text logic, generate AI alt text

* Add AI generate request, add convert from SVG to png base64, added manual fix block

* Add AI generate request, add convert from SVG to png base64, added manual fix block

* Add texts, add remediation submit, fix logic to store remediation

* Add texts, add remediation submit, fix logic to store remediation

* Add texts, add remediation submit, fix logic to store remediation

* Add texts, add remediation submit, fix logic to store remediation

* Add texts, add remediation submit, fix logic to store remediation

* Add texts, add remediation submit, fix logic to store remediation

---------

Co-authored-by: Raz Ohad <admin@bainternet.info>

* Add texts, add remediation submit, fix logic to store remediation

* [APP-0000] add store request to the Service API (#268)

* [APP-0000] add store request to the Service API

* [APP-0000] add store request to the Service API

* [APP-0000] add store request to the Service API

* [APP-0000] add store request to the Service API

* [APP-0000] add request to store scanner summary

* [APP-0000] add request to store scanner summary

* [APP-0000] add request to store scanner summary

* [APP-1432] fix with AI flow (#275)

* [APP-1432] fix with AI flow

* [APP-1432] fix with AI flow

* [APP-1432] fix with AI flow

* [APP-1432] fix with AI flow

* [APP-1432] fix with AI flow

* [APP-1432] fix with AI flow

* [APP-1432] fix with AI flow

* [APP-1432] fix with AI flow

* [APP-1432] fix with AI flow

* [APP-1432] fix with AI flow

* [APP-1432] fix with AI flow

* [APP-1446] sidebar menu update (#276)

* update: simplify menu

* add: headings and scanner menu options

* [APP-945] add column for tables (#282)

* [APP-945] add column for tables

* [APP-945] add column for tables

* [APP-945] add column for tables

* [APP-945] add column for tables

* [APP-1447] Updated quota bar designs (#278)

* update: quota bar designs

* fix: the popover was partially visible

* update: AI credits name

* update: usage calculation logic

* add: quota indicators

* update: quotas tooltip text

* update: quotas notices text

* update: make toggle icon dynamic

* fix: @elementor/ui imports

* Update modules/settings/assets/js/layouts/quota-bar.js

Co-authored-by: VasylD <vasyld@elementor.red>

* update: styling of component

---------

Co-authored-by: VasylD <vasyld@elementor.red>

* [APP-1507] add UI changes (#286)

* [APP-1507] add UI changes

* [APP-1507] add UI changes

* [APP-1507] add UI changes

* [APP-1507] add UI changes

* [APP-1507] add UI changes

* [APP-1507] add UI changes

* [APP-1507] add UI changes

* [APP-1387] add mixpanel events (#288)

* [APP-1387] add mixpanel events

* [APP-1387] add mixpanel events

* New: Add the a11y assistant dashboard's UI [APP-1445] (#289)

* [APP-1513] add disconnected msg (#290)

* [APP-1513] add disconnected msg

* [APP-1513] add disconnected msg

* [APP-1513] add disconnected msg

* [APP-1547][APP-1548][APP-948] update alt text view, fix list issues (#291)

* [APP-1547][APP-1548][APP-948] update alt text view, fix list issues, add rest route for update status

* [APP-1547][APP-1548][APP-948] update alt text view, fix list issues, add rest route for update status

* fix: infotip icon padding and font style (#293)

* fix: infotip icon padding and font style

* fix: infotip icon padding and font style

* update: caniuse database

* [APP-1525] add edit mode (#294)

* [APP-1525] add edit mode

* [APP-1525] add edit mode

* [APP-1525] add edit mode

* Bug/app 1544 (#295)

* Fix: Resolve QA comments [APP-1544]

* New: Add beta tags [APP-1555]

* New: Add the "no results" state [APP-1544]

* [APP-1554] rename violations (#297)

* [APP-1512] add backend logic for remediation management (#298)

* [APP-1512] add backend logic for remediation management

* [APP-1512] add backend logic for remediation management

* Update modules/remediation/database/remediation-entry.php

Co-authored-by: gitstream-cm[bot] <111687743+gitstream-cm[bot]@users.noreply.github.com>

* Update modules/remediation/rest/items.php

Co-authored-by: gitstream-cm[bot] <111687743+gitstream-cm[bot]@users.noreply.github.com>

* [APP-1512] add backend logic for remediation management

---------

Co-authored-by: gitstream-cm[bot] <111687743+gitstream-cm[bot]@users.noreply.github.com>

* Fix: Resolve QA comments [n/a] (#299)

* [APP-1512] add FE remediation management (#300)

* [APP-1512] add backend logic for remediation management

* [APP-1512] add backend logic for remediation management

* Update modules/remediation/database/remediation-entry.php

Co-authored-by: gitstream-cm[bot] <111687743+gitstream-cm[bot]@users.noreply.github.com>

* Update modules/remediation/rest/items.php

Co-authored-by: gitstream-cm[bot] <111687743+gitstream-cm[bot]@users.noreply.github.com>

* [APP-1512] add backend logic for remediation management

* [APP-1512] add FE remediation management

* [APP-1512] add FE remediation management

* [APP-1512] add FE remediation management

* [APP-1512] add FE remediation management

* [APP-1512] add FE remediation management

* [APP-1512] add FE remediation management

* [APP-1512] add FE remediation management

* [APP-1512] add FE remediation management

---------

Co-authored-by: gitstream-cm[bot] <111687743+gitstream-cm[bot]@users.noreply.github.com>

* [APP-1609] fix tooltip

* [APP-1609] fix resolved btn click

* [APP-1401] clear cache on update (#302)

* [APP-1401] clear cache on update

* [APP-1401] clear cache on update

* [APP-1401] clear cache on update

* [APP-1401] clear cache on update

* [APP-1401] clear cache on update

* update with latest develop branch

* fix copies

* [APP-1619] add mixpanel event (#303)

* [APP-1619] add mixpanel event

* [APP-1619] add mixpanel event

* [APP-1593] Add locked variant for quota bar (#301)

* update: add locked version of quota status bar

* fix: text color for infotip

* fix: width issues

* fix: add check for 0

* [APP-1637][APP-1643] add UI fixes, add excluded rules array (#307)

* fix: make sidebar collapsible (#306)

* Merge current dev

* [APP-1603] Add dashboard menu (#309)

* [APP-1603] Add dashboard menu

* [APP-1603] Add dashboard menu

* [APP-1603] Add dashboard menu

* [APP-1603] Add dashboard menu

* Bug/app 1607 (#311)

* Fix: Update stats calculation logic [APP-1607]

* Fix: Set fixed width for the results table [APP-1650]

* Fix: Update filter rules [APP-1634]

* New: Add the no search results state [APP-1651]

* Fix: Convert indents [n/a]

* [APP-1670] add menu on Manage Fixes (#315)

* [APP-1670] add menu on Manage Fixes

* [APP-1670] update menu

* [APP-1611] fix comments

* fix: direction of snippet (#313)

* [APP-1561] New menu layout (#308)

* update: app menu and layout

* merge: latest changes from feature/remediation

* add: alert indicator to the closed sidebar

* fix: page layout for statement page

* update: menu display names

* fix: topbar menu layout

* update: sidebar menu width

* update: sidebar menu width

* fix: popup menu layout

* add: hover action to the toggle button

* update: my account menu

* fix: quota indicator for closed sidebar

* fix: icon alignments

* fix: scroll behaviour

* fix: page scroll behaviour

* fix: popup menu hover state

* update: quota bar and group layouts

* add: tooltips to the menu items

* update: make scans page fixed height and scrollable

* update: styles with theme references and added new styled components

* fix: make sidebar smoother

* update: accessibility page heading

* Merge latest develop

* [APP-1611] trigger save entry for clean cache (#314)

* [APP-1611] trigger save entry for clean cache

* [APP-1611] fix comments

* [APP-1611] fix comments

* [APP-1611] fix comments

* [APP-1611] fix comments

* [APP-0000] call trigger save async (#319)

* [APP-1611] trigger save entry for clean cache

* [APP-1611] fix comments

* [APP-1611] fix comments

* [APP-1611] fix comments

* [APP-1611] fix comments

* [APP-0000] call trigger save async

* fix: scrollbar issues (#318)

* [APP-1615] add remediation for wp image (#321)

* POC - FrontEnd remediations to handle Dynamic Data [APP-1644] (#312)

* POC - FrontEnd remediations to handle Dynamic Data

* Update modules/remediation/components/remediation-runner.php

Co-authored-by: gitstream-cm[bot] <111687743+gitstream-cm[bot]@users.noreply.github.com>

* added MutationObserver to cover elements that are added later on the page

runs until remediations are all done, and disconnect

* added $use_frontend flag instead of using "false"

* Update modules/remediation/components/remediation-runner.php

Co-authored-by: gitstream-cm[bot] <111687743+gitstream-cm[bot]@users.noreply.github.com>

* WIP on poc/fe-remediations

* [APP-0000] call trigger save async

* [APP-1644] apply FE remediation

* [APP-1644] apply FE remediation

* [APP-1644] apply FE remediation

* Add timeout (wait for FE remediation timeout)

* Add timeout (wait for FE remediation timeout)

* Add timeout (wait for FE remediation timeout)

* Add timeout (wait for FE remediation timeout)

* Add timeout (wait for FE remediation timeout)

* Small fixes

* Small fixes

* Small fixes

* Small fixes

---------

Co-authored-by: gitstream-cm[bot] <111687743+gitstream-cm[bot]@users.noreply.github.com>
Co-authored-by: vasyldinets <vasyld@elementor.red>

* [APP-1611] Fix cache issue (#324)

* [APP-1611] trigger save entry for clean cache

* [APP-1611] fix comments

* [APP-1611] fix comments

* [APP-1611] fix comments

* [APP-1611] fix comments

* [APP-0000] call trigger save async

* [APP-1611] clear cache

* [APP-1657] upgrade cta (#323)

* update: added logic to show button based on plan

* Update modules/settings/assets/js/components/quota-bar/quota-bar-group.js

Co-authored-by: gitstream-cm[bot] <111687743+gitstream-cm[bot]@users.noreply.github.com>

* fix: eslint error

---------

Co-authored-by: gitstream-cm[bot] <111687743+gitstream-cm[bot]@users.noreply.github.com>

* [APP-1658] Update accessibility admin column design (#322)

* update: wpadmin column layout

* update: move icon to assets

* Fix: Resolve remediation encoding issue [APP-1646] (#325)

---------

Co-authored-by: Ohad <ohad@elementor.com>
Co-authored-by: Raz Ohad <admin@bainternet.info>
Co-authored-by: Nirbhay Singh <121793120+nirbhayel@users.noreply.github.com>
Co-authored-by: Pavlo Kniazevych <139438463+pkniazevych@users.noreply.github.com>
Co-authored-by: gitstream-cm[bot] <111687743+gitstream-cm[bot]@users.noreply.github.com>
2025-07-07 16:25:11 +07:00

544 lines
14 KiB
PHP

<?php
namespace EA11y\Modules\Settings;
use EA11y\Classes\{Logger, Module_Base, Utils};
use EA11y\Modules\Connect\Classes\{Config, Data};
use EA11y\Modules\Connect\Classes\Utils as Connect_Utils;
use EA11y\Modules\Connect\Module as Connect;
use EA11y\Modules\Core\Components\{Notices, Svg};
use EA11y\Modules\Settings\Banners\Elementor_Birthday_Banner;
use EA11y\Modules\Settings\Classes\Settings;
use EA11y\Modules\Widget\Module as WidgetModule;
use Exception;
use Throwable;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
class Module extends Module_Base {
const SETTING_PREFIX = 'ea11y_';
const SETTING_GROUP = 'ea11y_settings';
const SETTING_BASE_SLUG = 'accessibility-settings';
const SETTING_CAPABILITY = 'manage_options';
const SETTING_PAGE_SLUG = 'toplevel_page_' . self::SETTING_BASE_SLUG;
public function get_name(): string {
return 'settings';
}
public static function component_list(): array {
return [
'Settings_Pointer',
];
}
public function render_app() {
?>
<?php Elementor_Birthday_Banner::get_banner( 'https://go.elementor.com/acc-b-day-banner' ); ?>
<!-- The hack required to wrap WP notifications -->
<div class="wrap">
<h1 style="display: none;" role="presentation"></h1>
</div>
<div id="ea11y-app"></div>
<?php
}
public function register_page() : void {
add_menu_page(
__( 'Ally - Web Accessibility', 'pojo-accessibility' ),
__( 'Ally', 'pojo-accessibility' ),
self::SETTING_CAPABILITY,
self::SETTING_BASE_SLUG,
[ $this, 'render_app' ],
$this->get_menu_icon(),
);
}
private function get_menu_icon() : string {
$svg = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 383 383">
<path fill="#a7aaad" d="M191.47,0C85.73,0,0,85.73,0,191.47s85.73,191.47,191.47,191.47,191.47-85.73,191.47-191.47S297.22,0,191.47,0ZM191.47,64.82c15.33,0,27.75,12.42,27.75,27.75s-12.42,27.75-27.75,27.75-27.75-12.42-27.75-27.75,12.42-27.75,27.75-27.75ZM296.71,150.59l-51.42,9.25c-9.25.3-16.6,7.89-16.6,17.14l5.14,126.4c0,8.16-6.6,14.76-14.76,14.76-7.72,0-14.12-5.96-14.72-13.65l-4.65-61.58c-.3-3.88-3.54-6.88-7.42-6.88s-7.12,2.99-7.42,6.88l-4.65,61.58c-.57,7.69-7,13.65-14.71,13.65-8.16,0-14.77-6.6-14.77-14.76l5.52-137.01,40.04-2.92-63.61-6.75-46.45-6.13c-10.16-1.16-15.66-7-15.66-16.12s7.57-16.42,16.67-16.12l61.85,9.72c28.07,2.77,55.77,2.84,83.1,0l63.51-9.74v.02c9.1-.3,16.64,7.02,16.64,16.15s-5.42,14.32-15.65,16.12Z"/>
</svg>';
return 'data:image/svg+xml;base64,' . base64_encode( $svg );
}
/**
* Enqueue Scripts and Styles
*/
public function enqueue_scripts( $hook ) : void {
if ( self::SETTING_PAGE_SLUG !== $hook ) {
return;
}
wp_enqueue_media();
if ( version_compare( get_bloginfo( 'version' ), '6.6', '<' ) ) {
wp_register_script(
'react-jsx-runtime',
EA11Y_ASSETS_URL . 'lib/react-jsx-runtime.js',
[ 'react' ],
'18.3.0',
true
);
}
self::refresh_plan_data();
wp_enqueue_style(
'ea11y-admin-fonts',
'https://fonts.googleapis.com/css2?family=Roboto:ital,wght@0,100;0,300;0,400;0,500;0,700;0,900;1,100;1,300;1,400;1,500;1,700;1,900&display=swap',
[],
EA11Y_VERSION
);
Utils\Assets::enqueue_app_assets( 'admin' );
wp_localize_script(
'admin',
'ea11ySettingsData',
[
'wpRestNonce' => wp_create_nonce( 'wp_rest' ),
'planData' => Settings::get( Settings::PLAN_DATA ),
'planScope' => Settings::get( Settings::PLAN_SCOPE ),
'pluginEnv' => self::get_plugin_env(),
'widgetUrl' => WidgetModule::get_widget_url(),
'adminUrl' => admin_url(),
'isUrlMismatch' => ! Connect_Utils::is_valid_home_url(),
'isDevelopment' => defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG,
'homeUrl' => home_url(),
]
);
}
/**
* Get Mixpanel project Token
* @return string
*/
public static function get_plugin_env() : string {
return apply_filters( 'ea11y_plugin_env', 'production' );
}
public static function routes_list() : array {
return [
'Get_Settings',
'Get_Media',
];
}
/**
* Get all plugin settings data
* @return array
*/
public static function get_plugin_settings(): array {
return [
'isConnected' => Connect::is_connected(),
'closePostConnectModal' => Settings::get( Settings::CLOSE_POST_CONNECT_MODAL ),
'isRTL' => is_rtl(),
'isUrlMismatch' => ! Connect_Utils::is_valid_home_url(),
'unfilteredUploads' => Svg::are_unfiltered_uploads_enabled(),
];
}
/**
* @throws Exception
*/
public function on_connect(): void {
if ( ! Connect::is_connected() ) {
return;
}
self::register_site_with_data();
}
/**
* Register the website and save the plan data.
* @return void
*/
public static function register_site_with_data() : void {
$register_response = Utils::get_api_client()->make_request(
'POST',
'site/register'
);
if ( is_wp_error( $register_response ) ) {
Logger::error( esc_html( $register_response->get_error_message() ) );
} else {
self::save_plan_data( $register_response );
if ( isset( $register_response->scopes ) ) {
Settings::set( Settings::PLAN_SCOPE, $register_response->scopes );
}
}
}
/**
* Save plan data to plan_data option
* @param $register_response
*
* @return void
*/
public static function save_plan_data( $register_response ) : void {
if ( $register_response && ! is_wp_error( $register_response ) ) {
$decoded_response = $register_response;
Data::set_subscription_id( $decoded_response->plan->subscription_id );
update_option( Settings::PLAN_DATA, $decoded_response );
update_option( Settings::IS_VALID_PLAN_DATA, true );
self::set_default_settings();
self::set_plan_data_refresh_transient();
} else {
Logger::error( esc_html( $register_response->get_error_message() ) );
update_option( Settings::IS_VALID_PLAN_DATA, false );
}
}
/**
* Refresh the plan data after 12 hours
* @return void
*/
public static function refresh_plan_data() : void {
if ( ! Connect::is_connected() ) {
return;
}
// Refresh only if refresh transient is expired
if ( self::get_plan_data_refresh_transient() ) {
return;
}
$plan_data = Settings::get( Settings::PLAN_DATA );
// Return if plan data does not have public_api_key
if ( ! $plan_data->public_api_key ) {
Logger::error( 'Cannot refresh the plan data. No public API key found.' );
self::register_site_with_data();
return;
}
$response = Utils::get_api_client()->make_request(
'GET',
'site/info',
[ 'api_key' => $plan_data->public_api_key ]
);
if ( ! is_wp_error( $response ) ) {
Settings::set( Settings::PLAN_DATA, $response );
Settings::set( Settings::IS_VALID_PLAN_DATA, true );
self::set_plan_data_refresh_transient();
} else {
Logger::error( esc_html( $response->get_error_message() ) );
Settings::set( Settings::IS_VALID_PLAN_DATA, false );
}
}
/**
* Set default values after successful registration.
* @return void
*/
private static function set_default_settings() : void {
$widget_menu_settings = [
'bigger-text' => [
'enabled' => true,
],
'bigger-line-height' => [
'enabled' => true,
],
'text-align' => [
'enabled' => true,
],
'readable-font' => [
'enabled' => true,
],
'grayscale' => [
'enabled' => true,
],
'contrast' => [
'enabled' => true,
],
'page-structure' => [
'enabled' => true,
],
'sitemap' => [
'enabled' => false,
'url' => home_url( '/wp-sitemap.xml' ),
],
'reading-mask' => [
'enabled' => true,
],
'hide-images' => [
'enabled' => true,
],
'pause-animations' => [
'enabled' => true,
],
'highlight-links' => [
'enabled' => true,
],
'focus-outline' => [
'enabled' => true,
],
];
$widget_icon_settings = [
'style' => [
'icon' => 'person',
'size' => 'medium',
'color' => '#2563eb',
],
'position' => [
'desktop' => [
'hidden' => false,
'enableExactPosition' => false,
'exactPosition' => [
'horizontal' => [
'direction' => 'right',
'value' => 10,
'unit' => 'px',
],
'vertical' => [
'direction' => 'bottom',
'value' => 10,
'unit' => 'px',
],
],
'position' => is_rtl() ? 'bottom-left' : 'bottom-right',
],
'mobile' => [
'hidden' => false,
'enableExactPosition' => false,
'exactPosition' => [
'horizontal' => [
'direction' => 'right',
'value' => 10,
'unit' => 'px',
],
'vertical' => [
'direction' => 'bottom',
'value' => 10,
'unit' => 'px',
],
],
'position' => is_rtl() ? 'bottom-left' : 'bottom-right',
],
],
];
$skip_to_content_setting = [
'enabled' => true,
'anchor' => '#content',
];
if ( ! get_option( Settings::WIDGET_MENU_SETTINGS ) ) {
update_option( Settings::WIDGET_MENU_SETTINGS, $widget_menu_settings );
}
if ( ! get_option( Settings::WIDGET_ICON_SETTINGS ) ) {
update_option( Settings::WIDGET_ICON_SETTINGS, $widget_icon_settings );
}
if ( ! get_option( Settings::SKIP_TO_CONTENT ) ) {
update_option( Settings::SKIP_TO_CONTENT, $skip_to_content_setting );
}
}
/**
* Retry registering the site if it fails during connect.
*
* @param $current_screen
* @return void
*/
public function check_plan_data( $current_screen ) : void {
if ( self::SETTING_PAGE_SLUG !== $current_screen->base ) {
return;
}
if ( Connect::is_connected() && get_option( Settings::PLAN_DATA ) === false ) {
$register_response = Utils::get_api_client()->make_request(
'POST',
'site/register'
);
self::save_plan_data( $register_response );
self::set_plan_data_refresh_transient();
}
}
public function remove_admin_footer_text( $text ) {
$screen = get_current_screen();
if ( self::SETTING_PAGE_SLUG === $screen->base ) {
remove_filter( 'update_footer', 'core_update_footer' );
return '';
}
return $text;
}
/**
* Register settings.
*
* Register settings for the plugin.
*
* @return void
* @throws Throwable
*/
public function register_settings(): void {
$settings = [
'widget_menu_settings' => [
'type' => 'object',
'show_in_rest' => [
'schema' => [
'type' => 'object',
'additionalProperties' => true,
],
],
],
'widget_icon_settings' => [
'type' => 'object',
'show_in_rest' => [
'schema' => [
'type' => 'object',
'additionalProperties' => true,
],
],
],
'skip_to_content_settings' => [
'type' => 'object',
'show_in_rest' => [
'schema' => [
'type' => 'object',
'additionalProperties' => true,
],
],
],
'plan_data' => [
'type' => 'object',
'show_in_rest' => [
'schema' => [
'type' => 'object',
'additionalProperties' => true,
],
],
],
'accessibility_statement_data' => [
'type' => 'object',
'show_in_rest' => [
'schema' => [
'type' => 'object',
'additionalProperties' => true,
],
],
],
'close_post_connect_modal' => [
'type' => 'boolean',
],
'hide_minimum_active_options_alert' => [
'type' => 'boolean',
],
'analytics_enabled' => [
'type' => 'boolean',
],
'show_accessibility_generated_page_infotip' => [
'type' => 'boolean',
],
'unfiltered_files_upload' => [
'type' => 'boolean',
],
];
foreach ( $settings as $setting => $args ) {
if ( ! isset( $args['show_in_rest'] ) ) {
$args['show_in_rest'] = true;
}
register_setting( 'options', self::SETTING_PREFIX . $setting, $args );
}
}
public static function set_plan_data_refresh_transient(): void {
set_transient( Settings::PLAN_DATA_REFRESH_TRANSIENT, true, MINUTE_IN_SECONDS * 15 );
}
public static function get_plan_data_refresh_transient(): bool {
return get_transient( Settings::PLAN_DATA_REFRESH_TRANSIENT );
}
public static function delete_plan_data_refresh_transient(): bool {
return delete_transient( Settings::PLAN_DATA_REFRESH_TRANSIENT );
}
/**
* get_upgrade_link
*
* @param $campaign
*
* @return string
*/
public static function get_upgrade_link( $campaign ) : string {
return add_query_arg([
'utm_source' => $campaign . '-upgrade',
'utm_medium' => 'wp-dash',
], 'https://go.elementor.com/' . $campaign );
}
/**
* register_notices
*
* @param Notices $notice_manager
*/
public function register_notices( Notices $notice_manager ) {
$notices = [
'Quota_80',
'Quota_100',
];
foreach ( $notices as $notice ) {
$class_name = 'EA11y\Modules\Settings\Notices\\' . $notice;
$notice_manager->register_notice( new $class_name() );
}
}
/**
* @return float
*/
public static function get_plan_usage() : float {
$plan_data = Settings::get( Settings::PLAN_DATA );
if ( ! $plan_data ) {
return 0;
}
if ( ! isset( $plan_data->visits ) ) {
return 0;
}
return round( $plan_data->visits->used / $plan_data->visits->allowed * 100, 2 );
}
/**
* @param $url
* @return string|\WP_Error
*/
public static function get_media( $url ) {
return wp_remote_get( $url );
}
/**
* Module constructor.
*/
public function __construct() {
$this->register_routes();
$this->register_components( self::component_list() );
add_filter( 'admin_footer_text', [ $this, 'remove_admin_footer_text' ] );
add_action( 'admin_menu', [ $this, 'register_page' ] );
add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_scripts' ], 9 );
add_action( 'rest_api_init', [ $this, 'register_settings' ] );
add_action( 'on_connect_' . Config::APP_PREFIX . '_connected', [ $this, 'on_connect' ] );
add_action( 'current_screen', [ $this, 'check_plan_data' ] );
// Register notices
add_action( 'ea11y_register_notices', [ $this, 'register_notices' ] );
}
}