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

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