| 1 |
<?php |
| 2 |
/** |
| 3 |
* NotificationX Elementor Manager |
| 4 |
* |
| 5 |
* Registers the "NotificationX" widget category, all NX Elementor widgets, |
| 6 |
* and the JS/CSS assets that power them (both on the public frontend and |
| 7 |
* inside the Elementor editor preview iframe). |
| 8 |
* |
| 9 |
* @package NotificationX\Extensions\Elementor |
| 10 |
*/ |
| 11 |
|
| 12 |
namespace NotificationX\Extensions\Elementor; |
| 13 |
|
| 14 |
use NotificationX\GetInstance; |
| 15 |
|
| 16 |
if ( ! defined( 'ABSPATH' ) ) { |
| 17 |
exit; |
| 18 |
} |
| 19 |
|
| 20 |
/** |
| 21 |
* @method static ElementorManager get_instance($args = null) |
| 22 |
*/ |
| 23 |
class ElementorManager { |
| 24 |
|
| 25 |
use GetInstance; |
| 26 |
|
| 27 |
public function __construct() { |
| 28 |
add_action( 'elementor/elements/categories_registered', [ $this, 'register_category' ] ); |
| 29 |
add_action( 'elementor/widgets/register', [ $this, 'register_widgets' ] ); |
| 30 |
|
| 31 |
// Register scripts/styles so Elementor can enqueue them via |
| 32 |
// Widget_Base::get_script_depends() / get_style_depends(). |
| 33 |
// `elementor/frontend/after_register_scripts` fires in both the |
| 34 |
// editor preview iframe and on the public frontend. |
| 35 |
add_action( 'elementor/frontend/after_register_scripts', [ $this, 'register_scripts' ] ); |
| 36 |
add_action( 'elementor/frontend/after_register_styles', [ $this, 'register_styles' ] ); |
| 37 |
} |
| 38 |
|
| 39 |
/** |
| 40 |
* Register a dedicated "NotificationX" widget category. |
| 41 |
* |
| 42 |
* @param \Elementor\Elements_Manager $elements_manager |
| 43 |
*/ |
| 44 |
public function register_category( $elements_manager ) { |
| 45 |
$elements_manager->add_category( |
| 46 |
'notificationx', |
| 47 |
[ |
| 48 |
'title' => esc_html__( 'NotificationX', 'notificationx' ), |
| 49 |
'icon' => 'fa fa-bell', |
| 50 |
] |
| 51 |
); |
| 52 |
} |
| 53 |
|
| 54 |
/** |
| 55 |
* Register NX widgets with Elementor. |
| 56 |
* |
| 57 |
* @param \Elementor\Widgets_Manager $widgets_manager |
| 58 |
*/ |
| 59 |
public function register_widgets( $widgets_manager ) { |
| 60 |
$widgets_manager->register( new CountdownWidget() ); |
| 61 |
$widgets_manager->register( new FormWidget() ); |
| 62 |
} |
| 63 |
|
| 64 |
/** |
| 65 |
* Register JS assets. |
| 66 |
* Called on `elementor/frontend/after_register_scripts` — runs in |
| 67 |
* both editor preview and public frontend. |
| 68 |
*/ |
| 69 |
public function register_scripts() { |
| 70 |
wp_register_script( |
| 71 |
'nx-countdown', |
| 72 |
NOTIFICATIONX_PUBLIC_URL . 'js/nx-countdown.js', |
| 73 |
[ 'jquery' ], |
| 74 |
NOTIFICATIONX_VERSION, |
| 75 |
true // in footer |
| 76 |
); |
| 77 |
|
| 78 |
wp_register_script( |
| 79 |
'nx-elementor-form', |
| 80 |
NOTIFICATIONX_PUBLIC_URL . 'js/nx-elementor-form.js', |
| 81 |
[], |
| 82 |
NOTIFICATIONX_VERSION, |
| 83 |
true |
| 84 |
); |
| 85 |
} |
| 86 |
|
| 87 |
/** |
| 88 |
* Register CSS assets. |
| 89 |
* Called on `elementor/frontend/after_register_styles`. |
| 90 |
*/ |
| 91 |
public function register_styles() { |
| 92 |
wp_register_style( |
| 93 |
'nx-countdown', |
| 94 |
NOTIFICATIONX_PUBLIC_URL . 'css/nx-countdown.css', |
| 95 |
[], |
| 96 |
NOTIFICATIONX_VERSION |
| 97 |
); |
| 98 |
|
| 99 |
wp_register_style( |
| 100 |
'nx-elementor-form', |
| 101 |
NOTIFICATIONX_PUBLIC_URL . 'css/nx-elementor-form.css', |
| 102 |
[], |
| 103 |
NOTIFICATIONX_VERSION |
| 104 |
); |
| 105 |
} |
| 106 |
} |
| 107 |
|