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

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