PluginProbe
NotificationX – FOMO, Live Sales Notification, WooCommerce Sales Popup, GDPR, Social Proof, Announcement Banner & Floating Notification Bar / 1.0.0
NotificationX – FOMO, Live Sales Notification, WooCommerce Sales Popup, GDPR, Social Proof, Announcement Banner & Floating Notification Bar v1.0.0
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.0, at includes/class-nx.php

300 lines 9.2 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 * NotificationX Messages
103 */
104 require_once NOTIFICATIONX_ROOT_DIR_PATH . 'includes/class-nx-message.php';
105 /**
106 * NotificationX Cron
107 */
108 require_once NOTIFICATIONX_ROOT_DIR_PATH . 'includes/class-nx-cron.php';
109 /**
110 * The class responsible for orchestrating the actions and filters of the
111 * core plugin.
112 *
113 * TODO: do something with loader
114 */
115 // require_once NOTIFICATIONX_ROOT_DIR_PATH . 'includes/class-nx-loader.php';
116
117 /**
118 * The class responsible for defining internationalization functionality
119 * of the plugin.
120 */
121 require_once NOTIFICATIONX_ROOT_DIR_PATH . 'includes/class-nx-i18n.php';
122 require_once NOTIFICATIONX_ROOT_DIR_PATH . 'includes/class-plugin-usage-tracker.php';
123
124 require_once NOTIFICATIONX_ROOT_DIR_PATH . 'public/includes/class-nx-template.php';
125 require_once NOTIFICATIONX_ROOT_DIR_PATH . 'includes/class-nx-locations.php';
126 /**
127 * The class responsible for defining all actions that occur in the admin area.
128 */
129 require_once NOTIFICATIONX_ADMIN_DIR_PATH . 'includes/class-nx-metabox.php';
130 require_once NOTIFICATIONX_ADMIN_DIR_PATH . 'includes/class-nx-settings.php';
131 require_once NOTIFICATIONX_ADMIN_DIR_PATH . 'class-nx-admin.php';
132
133 /**
134 * The class responsible for defining extensions functionality
135 * of the plugin.
136 */
137 require_once NOTIFICATIONX_ROOT_DIR_PATH . 'includes/class-nx-extension-factory.php';
138 require_once NOTIFICATIONX_ROOT_DIR_PATH . 'includes/class-nx-extension.php';
139 require_once NOTIFICATIONX_EXT_DIR_PATH . 'press-bar/class-press-bar.php';
140 require_once NOTIFICATIONX_EXT_DIR_PATH . 'wp-comments/class-wp-comments.php';
141 require_once NOTIFICATIONX_EXT_DIR_PATH . 'woocommerce/class-woocommerce.php';
142 require_once NOTIFICATIONX_EXT_DIR_PATH . 'edd/class-edd.php';
143 /**
144 * The class responsible for defining all actions that occur in the public-facing
145 * side of the site.
146 */
147 require_once NOTIFICATIONX_ROOT_DIR_PATH . 'public/class-nx-public.php';
148 do_action('notificationx_load_depedencies');
149 }
150 /**
151 * Optional usage tracker
152 *
153 * @since v1.0.0
154 */
155 public function start_plugin_tracking() {
156 new NotificationX_Plugin_Usage_Tracker(
157 NOTIFICATIONX_FILE,
158 'http://app.wpdeveloper.net',
159 array(),
160 true,
161 true,
162 1
163 );
164 }
165
166 /**
167 * This function is responsible for load all extensions
168 *
169 * @return void
170 */
171 public function load_extensions(){
172 global $nx_extension_factory;
173
174 $extensions = [
175 'NotificationX_EDD_Extension',
176 'NotificationX_PressBar_Extension',
177 'NotificationX_WP_Comments_Extension',
178 'NotificationX_WooCommerce_Extension',
179 ];
180
181 foreach( $extensions as $extension ) {
182 /**
183 * Register the extension
184 */
185 nx_register_extension( $extension );
186 }
187 /**
188 * Init all extensions here.
189 */
190 do_action( 'nx_extensions_init' );
191 /**
192 * Load all extension.
193 */
194 $nx_extension_factory->load();
195 }
196 /**
197 * Define the locale for this plugin for internationalization.
198 *
199 * Uses the NotificationX_i18n class in order to set the domain and to register the hook
200 * with WordPress.
201 *
202 * @since 1.0.0
203 * @access private
204 */
205 private function set_locale() {
206 $plugin_i18n = new NotificationX_i18n();
207 add_action( 'plugins_loaded', array( $plugin_i18n, 'load_plugin_textdomain' ) );
208 }
209 /**
210 * Register all of the hooks related to the admin area functionality
211 * of the plugin.
212 *
213 * @since 1.0.0
214 * @access private
215 */
216 public function define_admin_hooks() {
217
218 $plugin_admin = new NotificationX_Admin( $this->get_plugin_name(), $this->get_version() );
219 $plugin_admin->metabox = new NotificationX_MetaBox;
220
221 add_action( 'init', array( $plugin_admin, 'register') );
222 add_action( 'init', array( $plugin_admin, 'get_active_items') );
223 add_action( 'add_meta_boxes', array( $plugin_admin->metabox, 'add_meta_boxes') );
224 add_action( 'nx_builder_before_tab', array( $plugin_admin->metabox, 'finalize_builder'), 10, 2 );
225 add_action( 'admin_menu', array( $plugin_admin, 'menu_page') );
226 add_action( 'admin_footer', array( $plugin_admin, 'notification_preview') );
227 add_filter( 'manage_notificationx_posts_columns', array( $plugin_admin, 'custom_columns') );
228 add_action( 'manage_notificationx_posts_custom_column', array( $plugin_admin, 'manage_custom_columns' ), 10, 2 );
229 add_action( 'wp_ajax_notifications_toggle_status', array( $plugin_admin, 'notification_status') );
230
231 add_action( 'admin_enqueue_scripts', array( $plugin_admin, 'enqueue_styles') );
232 add_action( 'admin_enqueue_scripts', array( $plugin_admin, 'enqueue_scripts') );
233
234 add_action( 'save_post', array( $plugin_admin->metabox, 'save_metabox') );
235
236 /**
237 * Initializing NotificationX_Settings
238 */
239 NotificationX_Settings::init();
240
241 do_action( 'nx_admin_action' );
242 }
243 /**
244 * Register all of the hooks related to the public-facing functionality
245 * of the plugin.
246 *
247 * @since 1.0.0
248 * @access private
249 */
250 public function define_public_hooks() {
251
252 $plugin_public = new NotificationX_Public( $this->get_plugin_name(), $this->get_version() );
253
254 do_action( 'nx_public_action' );
255
256 add_action( 'wp_enqueue_scripts', array( $plugin_public, 'enqueue_styles') );
257 add_action( 'wp_enqueue_scripts', array( $plugin_public, 'enqueue_scripts') );
258 add_action( 'wp', array( $plugin_public, 'get_active_items') );
259 add_action( 'wp_footer', array( $plugin_public, 'generate_active_notificationx') );
260 add_action( 'wp_ajax_nx_get_conversions', array( $plugin_public, 'generate_conversions') );
261 add_action( 'wp_ajax_nopriv_nx_get_conversions', array( $plugin_public, 'generate_conversions') );
262 }
263 /**
264 * Run the loader to execute all of the hooks with WordPress.
265 *
266 * @since 1.0.0
267 */
268 public function run() {
269 return $this;
270 }
271 /**
272 * The name of the plugin used to uniquely identify it within the context of
273 * WordPress and to define internationalization functionality.
274 *
275 * @since 1.0.0
276 * @return string The name of the plugin.
277 */
278 public function get_plugin_name() {
279 return $this->plugin_name;
280 }
281 /**
282 * The reference to the class that orchestrates the hooks with the plugin.
283 *
284 * @since 1.0.0
285 * @return NotificationX_Loader Orchestrates the hooks of the plugin.
286 * TODO: remove this or do others
287 */
288 public function get_loader() {
289 return $this->loader;
290 }
291 /**
292 * Retrieve the version number of the plugin.
293 *
294 * @since 1.0.0
295 * @return string The version number of the plugin.
296 */
297 public function get_version() {
298 return $this->version;
299 }
300 }