| 1 |
<?php |
| 2 |
namespace Elementor\Modules\Notifications; |
| 3 |
|
| 4 |
use Elementor\Core\Base\Module as BaseModule; |
| 5 |
|
| 6 |
if ( ! defined( 'ABSPATH' ) ) { |
| 7 |
exit; // Exit if accessed directly. |
| 8 |
} |
| 9 |
|
| 10 |
class Module extends BaseModule { |
| 11 |
|
| 12 |
public function get_name() { |
| 13 |
return 'notification-center'; |
| 14 |
} |
| 15 |
|
| 16 |
public function __construct() { |
| 17 |
parent::__construct(); |
| 18 |
|
| 19 |
add_action( 'elementor/admin_top_bar/before_enqueue_scripts', function() { |
| 20 |
if ( ! current_user_can( 'manage_options' ) ) { |
| 21 |
return; |
| 22 |
} |
| 23 |
|
| 24 |
wp_enqueue_script( |
| 25 |
'e-admin-notifications', |
| 26 |
$this->get_js_assets_url( 'admin-notifications' ), |
| 27 |
[ |
| 28 |
'elementor-v2-ui', |
| 29 |
'elementor-v2-icons', |
| 30 |
'elementor-v2-query', |
| 31 |
'wp-i18n', |
| 32 |
], |
| 33 |
ELEMENTOR_VERSION, |
| 34 |
true |
| 35 |
); |
| 36 |
|
| 37 |
wp_localize_script( |
| 38 |
'e-admin-notifications', |
| 39 |
'elementorNotifications', |
| 40 |
$this->get_app_js_config() |
| 41 |
); |
| 42 |
|
| 43 |
wp_set_script_translations( 'e-editor-notifications', 'elementor' ); |
| 44 |
}, 5 /* Before Elementor's admin enqueue scripts */ ); |
| 45 |
|
| 46 |
add_action( 'elementor/editor/v2/scripts/enqueue', [ $this, 'enqueue_editor_scripts' ] ); |
| 47 |
add_action( 'elementor/editor/after_enqueue_scripts', [ $this, 'enqueue_editor_scripts' ] ); |
| 48 |
|
| 49 |
add_action( 'elementor/ajax/register_actions', [ $this, 'register_ajax_actions' ] ); |
| 50 |
} |
| 51 |
|
| 52 |
public function enqueue_editor_scripts() { |
| 53 |
$deps = [ |
| 54 |
'elementor-editor', |
| 55 |
'elementor-v2-ui', |
| 56 |
'elementor-v2-icons', |
| 57 |
'elementor-v2-query', |
| 58 |
'elementor-v2-editor-app-bar', |
| 59 |
'wp-i18n', |
| 60 |
]; |
| 61 |
|
| 62 |
wp_enqueue_script( |
| 63 |
'e-editor-notifications', |
| 64 |
$this->get_js_assets_url( 'editor-notifications' ), |
| 65 |
$deps, |
| 66 |
ELEMENTOR_VERSION, |
| 67 |
true |
| 68 |
); |
| 69 |
|
| 70 |
wp_localize_script( |
| 71 |
'e-editor-notifications', |
| 72 |
'elementorNotifications', |
| 73 |
$this->get_app_js_config() |
| 74 |
); |
| 75 |
|
| 76 |
wp_set_script_translations( 'e-editor-notifications', 'elementor' ); |
| 77 |
} |
| 78 |
|
| 79 |
private function get_app_js_config(): array { |
| 80 |
return [ |
| 81 |
'is_unread' => Options::has_unread_notifications(), |
| 82 |
]; |
| 83 |
} |
| 84 |
|
| 85 |
public function register_ajax_actions( $ajax ) { |
| 86 |
$ajax->register_ajax_action( 'notifications_get', [ $this, 'ajax_get_notifications' ] ); |
| 87 |
} |
| 88 |
|
| 89 |
public function ajax_get_notifications() { |
| 90 |
$notifications = API::get_notifications_by_conditions( true ); |
| 91 |
|
| 92 |
Options::mark_notification_read( $notifications ); |
| 93 |
|
| 94 |
return $notifications; |
| 95 |
} |
| 96 |
} |
| 97 |
|