PluginProbe
NotificationX – FOMO, Live Sales Notification, WooCommerce Sales Popup, GDPR, Social Proof, Announcement Banner & Floating Notification Bar / 1.0.2
NotificationX – FOMO, Live Sales Notification, WooCommerce Sales Popup, GDPR, Social Proof, Announcement Banner & Floating Notification Bar v1.0.2
3.3.1 3.3.0 3.2.14 3.2.13 3.2.12 3.2.11 3.2.10 3.2.9 3.2.8 3.2.7 trunk 0.2.5.5 0.2.5.6 0.2.5.7 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.2.0 1.2.1 All 156 releases
notificationx / includes / class-nx.php

class-nx.php in NotificationX – FOMO, Live Sales Notification, WooCommerce Sales Popup, GDPR, Social Proof, Announcement Banner & Floating Notification Bar 1.0.2, at includes/class-nx.php

302 lines 9.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * The core plugin class.
4 *
5 * This is used to define internationalization, admin-specific hooks, and
6 * public-facing site hooks.
7 *
8 * Also maintains the unique identifier of this plugin as well as the current
9 * version of the plugin.
10 *
11 * @since 1.0.0
12 * @package NotificationX
13 * @subpackage NotificationX/includes
14 * @author WPDeveloper <support@wpdeveloper.net>
15 */
16 final class NotificationX {
17 /**
18 * The unique identifier of this plugin.
19 *
20 * @since 1.0.0
21 * @access protected
22 * @var string $plugin_name The string used to uniquely identify this plugin.
23 */
24 protected $plugin_name;
25
26 /**
27 * The current version of the plugin.
28 *
29 * @since 1.0.0
30 * @access protected
31 * @var string $version The current version of the plugin.
32 */
33 protected $version;
34
35 /**
36 * Define the core functionality of the plugin.
37 *
38 * Set the plugin name and the plugin version that can be used throughout the plugin.
39 * Load the dependencies, define the locale, and set the hooks for the admin area and
40 * the public-facing side of the site.
41 *
42 * @since 1.0.0
43 */
44 public function __construct() {
45 if ( defined( 'NOTIFICATIONX_VERSION' ) ) {
46 $this->version = NOTIFICATIONX_VERSION;
47 } else {
48 $this->version = '1.0.0';
49 }
50 $this->plugin_name = 'notificationx';
51
52 $this->load_dependencies();
53 $this->set_locale();
54 $this->start_plugin_tracking();
55 add_action( 'plugins_loaded', array( $this, 'load_extensions' ) );
56 add_action( 'plugins_loaded', array( $this, 'define_admin_hooks' ) );
57 add_action( 'plugins_loaded', array( $this, 'define_public_hooks' ) );
58 add_action( 'admin_init', array( $this, 'redirect' ) );
59 }
60
61 public function redirect() {
62 // Bail if no activation transient is set.
63 if ( ! get_transient( '_nx_meta_activation_notice' ) ) {
64 return;
65 }
66 // Delete the activation transient.
67 delete_transient( '_nx_meta_activation_notice' );
68
69 if ( ! is_multisite() ) {
70 // Redirect to the welcome page.
71 wp_safe_redirect( add_query_arg( array(
72 'page' => 'nx-builder'
73 ), admin_url( 'admin.php' ) ) );
74 }
75 }
76 /**
77 * Load the required dependencies for this plugin.
78 *
79 * Include the following files that make up the plugin:
80 *
81 * - NotificationX_Loader. Orchestrates the hooks of the plugin.
82 * - NotificationX_i18n. Defines internationalization functionality.
83 * - NotificationX_Admin. Defines all hooks for the admin area.
84 * - NotificationX_Public. Defines all hooks for the public side of the site.
85 *
86 * Create an instance of the loader which will be used to register the hooks
87 * with WordPress.
88 *
89 * @since 1.0.0
90 * @access private
91 */
92 private function load_dependencies() {
93 /**
94 * NotificationX DB
95 */
96 require_once NOTIFICATIONX_ROOT_DIR_PATH . 'includes/class-nx-db.php';
97 /**
98 * NotificationX Helper
99 */
100 require_once NOTIFICATIONX_ROOT_DIR_PATH . 'includes/class-nx-helper.php';
101
102 /**
103 * NotificationX Messages
104 */
105 require_once NOTIFICATIONX_ROOT_DIR_PATH . 'includes/class-nx-message.php';
106 /**
107 * NotificationX Cron
108 */
109 require_once NOTIFICATIONX_ROOT_DIR_PATH . 'includes/class-nx-cron.php';
110 /**
111 * The class responsible for orchestrating the actions and filters of the
112 * core plugin.
113 *
114 * TODO: do something with loader
115 */
116 // require_once NOTIFICATIONX_ROOT_DIR_PATH . 'includes/class-nx-loader.php';
117
118 /**
119 * The class responsible for defining internationalization functionality
120 * of the plugin.
121 */
122 require_once NOTIFICATIONX_ROOT_DIR_PATH . 'includes/class-nx-i18n.php';
123 require_once NOTIFICATIONX_ROOT_DIR_PATH . 'includes/class-plugin-usage-tracker.php';
124
125 require_once NOTIFICATIONX_ROOT_DIR_PATH . 'public/includes/class-nx-template.php';
126 require_once NOTIFICATIONX_ROOT_DIR_PATH . 'includes/class-nx-locations.php';
127 /**
128 * The class responsible for defining all actions that occur in the admin area.
129 */
130 require_once NOTIFICATIONX_ADMIN_DIR_PATH . 'includes/class-nx-metabox.php';
131 require_once NOTIFICATIONX_ADMIN_DIR_PATH . 'includes/class-nx-settings.php';
132 require_once NOTIFICATIONX_ADMIN_DIR_PATH . 'class-nx-admin.php';
133
134 /**
135 * The class responsible for defining extensions functionality
136 * of the plugin.
137 */
138 require_once NOTIFICATIONX_ROOT_DIR_PATH . 'includes/class-nx-array.php';
139 require_once NOTIFICATIONX_ROOT_DIR_PATH . 'includes/class-nx-extension-factory.php';
140 require_once NOTIFICATIONX_ROOT_DIR_PATH . 'includes/class-nx-extension.php';
141 require_once NOTIFICATIONX_EXT_DIR_PATH . 'press-bar/class-press-bar.php';
142 require_once NOTIFICATIONX_EXT_DIR_PATH . 'wp-comments/class-wp-comments.php';
143 require_once NOTIFICATIONX_EXT_DIR_PATH . 'woocommerce/class-woocommerce.php';
144 require_once NOTIFICATIONX_EXT_DIR_PATH . 'edd/class-edd.php';
145 /**
146 * The class responsible for defining all actions that occur in the public-facing
147 * side of the site.
148 */
149 require_once NOTIFICATIONX_ROOT_DIR_PATH . 'public/class-nx-public.php';
150 do_action('notificationx_load_depedencies');
151 }
152 /**
153 * Optional usage tracker
154 *
155 * @since v1.0.0
156 */
157 public function start_plugin_tracking() {
158 new NotificationX_Plugin_Usage_Tracker(
159 NOTIFICATIONX_FILE,
160 'http://app.wpdeveloper.net',
161 array(),
162 true,
163 true,
164 1
165 );
166 }
167
168 /**
169 * This function is responsible for load all extensions
170 *
171 * @return void
172 */
173 public function load_extensions(){
174 global $nx_extension_factory;
175
176 $extensions = [
177 'NotificationX_EDD_Extension',
178 'NotificationX_PressBar_Extension',
179 'NotificationX_WP_Comments_Extension',
180 'NotificationX_WooCommerce_Extension',
181 ];
182
183 foreach( $extensions as $extension ) {
184 /**
185 * Register the extension
186 */
187 nx_register_extension( $extension );
188 }
189 /**
190 * Init all extensions here.
191 */
192 do_action( 'nx_extensions_init' );
193 /**
194 * Load all extension.
195 */
196 $nx_extension_factory->load();
197 }
198 /**
199 * Define the locale for this plugin for internationalization.
200 *
201 * Uses the NotificationX_i18n class in order to set the domain and to register the hook
202 * with WordPress.
203 *
204 * @since 1.0.0
205 * @access private
206 */
207 private function set_locale() {
208 $plugin_i18n = new NotificationX_i18n();
209 add_action( 'plugins_loaded', array( $plugin_i18n, 'load_plugin_textdomain' ) );
210 }
211 /**
212 * Register all of the hooks related to the admin area functionality
213 * of the plugin.
214 *
215 * @since 1.0.0
216 * @access private
217 */
218 public function define_admin_hooks() {
219
220 $plugin_admin = new NotificationX_Admin( $this->get_plugin_name(), $this->get_version() );
221 $plugin_admin->metabox = new NotificationX_MetaBox;
222
223 add_action( 'init', array( $plugin_admin, 'register') );
224 add_action( 'init', array( $plugin_admin, 'get_active_items') );
225 add_action( 'add_meta_boxes', array( $plugin_admin->metabox, 'add_meta_boxes') );
226 add_action( 'nx_builder_before_tab', array( $plugin_admin->metabox, 'finalize_builder'), 10, 2 );
227 add_action( 'admin_menu', array( $plugin_admin, 'menu_page') );
228 add_action( 'admin_footer', array( $plugin_admin, 'notification_preview') );
229 add_filter( 'manage_notificationx_posts_columns', array( $plugin_admin, 'custom_columns') );
230 add_action( 'manage_notificationx_posts_custom_column', array( $plugin_admin, 'manage_custom_columns' ), 10, 2 );
231 add_action( 'wp_ajax_notifications_toggle_status', array( $plugin_admin, 'notification_status') );
232
233 add_action( 'admin_enqueue_scripts', array( $plugin_admin, 'enqueue_styles') );
234 add_action( 'admin_enqueue_scripts', array( $plugin_admin, 'enqueue_scripts') );
235
236 add_action( 'save_post', array( $plugin_admin->metabox, 'save_metabox') );
237
238 /**
239 * Initializing NotificationX_Settings
240 */
241 NotificationX_Settings::init();
242
243 do_action( 'nx_admin_action' );
244 }
245 /**
246 * Register all of the hooks related to the public-facing functionality
247 * of the plugin.
248 *
249 * @since 1.0.0
250 * @access private
251 */
252 public function define_public_hooks() {
253
254 $plugin_public = new NotificationX_Public( $this->get_plugin_name(), $this->get_version() );
255
256 do_action( 'nx_public_action' );
257
258 add_action( 'wp_enqueue_scripts', array( $plugin_public, 'enqueue_styles') );
259 add_action( 'wp_enqueue_scripts', array( $plugin_public, 'enqueue_scripts') );
260 add_action( 'wp', array( $plugin_public, 'get_active_items') );
261 add_action( 'wp_footer', array( $plugin_public, 'generate_active_notificationx') );
262 add_action( 'wp_ajax_nx_get_conversions', array( $plugin_public, 'generate_conversions') );
263 add_action( 'wp_ajax_nopriv_nx_get_conversions', array( $plugin_public, 'generate_conversions') );
264 }
265 /**
266 * Run the loader to execute all of the hooks with WordPress.
267 *
268 * @since 1.0.0
269 */
270 public function run() {
271 return $this;
272 }
273 /**
274 * The name of the plugin used to uniquely identify it within the context of
275 * WordPress and to define internationalization functionality.
276 *
277 * @since 1.0.0
278 * @return string The name of the plugin.
279 */
280 public function get_plugin_name() {
281 return $this->plugin_name;
282 }
283 /**
284 * The reference to the class that orchestrates the hooks with the plugin.
285 *
286 * @since 1.0.0
287 * @return NotificationX_Loader Orchestrates the hooks of the plugin.
288 * TODO: remove this or do others
289 */
290 public function get_loader() {
291 return $this->loader;
292 }
293 /**
294 * Retrieve the version number of the plugin.
295 *
296 * @since 1.0.0
297 * @return string The version number of the plugin.
298 */
299 public function get_version() {
300 return $this->version;
301 }
302 }