Skip to content

Commit

Permalink
merge: develop
Browse files Browse the repository at this point in the history
  • Loading branch information
nirbhayel committed Dec 30, 2024
2 parents 008de11 + 08ced7e commit b87ad0d
Show file tree
Hide file tree
Showing 22 changed files with 545 additions and 335 deletions.
1 change: 1 addition & 0 deletions includes/manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public static function get_module_list(): array {
'Connect',
'Settings',
'Widget',
'Core',
];
}

Expand Down
49 changes: 49 additions & 0 deletions modules/core/components/pointers.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

namespace EA11y\Modules\Core\Components;

if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}

class Pointers {
const DISMISSED_POINTERS_META_KEY = 'ea11y_dismissed_pointers';

public function dismiss_pointers() {
if ( empty( $_POST['nonce'] ) || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['nonce'] ) ), 'ea11y-pointer-dismissed' ) ) {
wp_send_json_error( [ 'message' => 'Invalid nonce' ] );
}

$pointer = sanitize_text_field( $_POST['data']['pointer'] ) ?? null;

if ( empty( $pointer ) ) {
wp_send_json_error( [ 'message' => 'The pointer id must be provided' ] );
}

$pointer = explode( ',', $pointer );

$user_dismissed_meta = get_user_meta( get_current_user_id(), self::DISMISSED_POINTERS_META_KEY, true );

if ( ! $user_dismissed_meta ) {
$user_dismissed_meta = [];
}

foreach ( $pointer as $item ) {
$user_dismissed_meta[ $item ] = true;
}

update_user_meta( get_current_user_id(), self::DISMISSED_POINTERS_META_KEY, $user_dismissed_meta );

wp_send_json_success( [] );
}

public static function is_dismissed( string $slug ): bool {
$meta = (array) get_user_meta( get_current_user_id(), self::DISMISSED_POINTERS_META_KEY, true );

return key_exists( $slug, $meta );
}

public function __construct() {
add_action( 'wp_ajax_ea11y_pointer_dismissed', [ $this, 'dismiss_pointers' ] );
}
}
61 changes: 61 additions & 0 deletions modules/core/module.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php
namespace EA11y\Modules\Core;

use EA11y\Classes\Module_Base;
use EA11y\Modules\Connect\Module as Connect;
use EA11y\Modules\Settings\Module as Settings;

if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}

class Module extends Module_Base {
public function get_name(): string {
return 'core';
}

public static function component_list() : array {
return [
'Pointers',
];
}

public function add_plugin_links( $links, $plugin_file_name ): array {
if ( ! str_ends_with( $plugin_file_name, '/pojo-accessibility.php' ) ) {
return (array) $links;
}

$custom_links = [
'dashboard' => sprintf(
'<a href="%s">%s</a>',
admin_url( 'admin.php?page=' . Settings::SETTING_BASE_SLUG ),
esc_html__( 'Dashboard', 'pojo-accessibility' )
),
];

if ( Connect::is_connected() ) {
$custom_links['upgrade'] = sprintf(
'<a href="%s" style="color: #524CFF; font-weight: 700;" target="_blank" rel="noopener noreferrer">%s</a>',
'https://go.elementor.com/sm-panel-wp-dash-upgrade-plugins/',
esc_html__( 'Upgrade', 'pojo-accessibility' )
);
} else {
$custom_links['connect'] = sprintf(
'<a href="%s" style="color: #524CFF; font-weight: 700;">%s</a>',
admin_url( 'admin.php?page=' . Settings::SETTING_BASE_SLUG ),
esc_html__( 'Connect', 'pojo-accessibility' )
);
}

return array_merge( $custom_links, $links );
}

/**
* Module constructor.
*/
public function __construct() {
$this->register_components();

add_filter( 'plugin_action_links', [ $this, 'add_plugin_links' ], 10, 2 );
}
}
5 changes: 4 additions & 1 deletion modules/settings/assets/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
Notifications,
MenuItems,
AdminTopBar,
PostConnectModal,
} from '@ea11y/components';
import {
useNotificationSettings,
Expand All @@ -19,7 +20,8 @@ import { usePluginSettingsContext } from './contexts/plugin-settings';

const App = () => {
useSavedSettings();
const { isConnected, isRTL } = usePluginSettingsContext();
const { isConnected, isRTL, closePostConnectModal } =
usePluginSettingsContext();
const { notificationMessage, notificationType } = useNotificationSettings();
const { selectedMenu } = useSettings();

Expand All @@ -32,6 +34,7 @@ const App = () => {
<DirectionProvider rtl={isRTL}>
<ThemeProvider colorScheme="light">
{!isConnected && <ConnectModal />}
{isConnected && !closePostConnectModal && <PostConnectModal />}
<Grid display="flex" flexDirection="row" height="100%">
<Sidebar />
<Box
Expand Down
Loading

0 comments on commit b87ad0d

Please sign in to comment.