PluginProbe
WANotifier for Forms and Actions / 3.1.1
WANotifier for Forms and Actions v3.1.1
3.1.1 3.1.0 3.0.4 2.7.10 2.7.11 2.7.12 2.7.13 2.7.2 2.7.3 2.7.4 2.7.5 2.7.6 2.7.7 2.7.8 2.7.9 3.0.0 3.0.1 3.0.2 3.0.3 trunk 0.1.0 0.1.1 1.0.0 1.0.1 1.0.2 All 67 releases
← All changes | includes/class-notifier.php +140 -55 2.7.113.1.1 View file →
@@ -1,5 +1,9 @@
1 1 <?php
2 +if ( ! defined( 'ABSPATH' ) ) {
3 + exit;
4 +}
5 +
2 6 /**
3 7 * The core plugin class.
4 8 *
5 9 * @package Notifier
@@ -22,13 +26,14 @@
22 26 /**
23 27 * Define Constants.
24 28 */
25 29 private function define_constants() {
26 - $this->define( 'NOTIFIER_VERSION', '2.7.11' );
30 + $this->define( 'NOTIFIER_VERSION', '3.1.1' );
27 31 $this->define( 'NOTIFIER_NAME', 'notifier' );
28 32 $this->define( 'NOTIFIER_PREFIX', 'notifier_' );
29 33 $this->define( 'NOTIFIER_URL', trailingslashit( plugins_url( '', dirname(__FILE__) ) ) );
30 - $this->define( 'NOTIFIER_APP_API_URL', 'https://app.wanotifier.com/api/v1/' );
34 + $this->define( 'NOTIFIER_APP_BASE_URL', 'https://app.wanotifier.com' );
35 + $this->define( 'NOTIFIER_APP_API_PATH', 'api/v1' );
31 36 $this->define( 'NOTIFIER_ACTIVITY_TABLE_NAME', 'notifier_activity_log' );
32 37 $this->define( 'NOTIFIER_CART_ABANDONMENT_TABLE', 'notifier_cart_abandonment' );
33 38 }
34 39
@@ -61,19 +66,18 @@
61 66 */
62 67 private function includes() {
63 68 // Functions
64 69 require_once NOTIFIER_PATH . 'includes/functions/functions-notifier-helpers.php';
65 - require_once NOTIFIER_PATH . 'includes/functions/functions-notifier-meta-box-fields.php';
66 70 require_once NOTIFIER_PATH . 'libraries/action-scheduler/action-scheduler.php';
67 71
68 72 // Classes
69 73 require_once NOTIFIER_PATH . 'includes/classes/class-notifier-admin-notices.php';
70 - require_once NOTIFIER_PATH . 'includes/classes/class-notifier-dashboard.php';
74 + require_once NOTIFIER_PATH . 'includes/classes/class-notifier-connection.php';
75 + require_once NOTIFIER_PATH . 'includes/classes/class-notifier-migration.php';
76 + require_once NOTIFIER_PATH . 'includes/classes/class-notifier-backend.php';
71 77 require_once NOTIFIER_PATH . 'includes/classes/class-notifier-notification-merge-tags.php';
72 78 require_once NOTIFIER_PATH . 'includes/classes/class-notifier-notification-triggers.php';
73 - require_once NOTIFIER_PATH . 'includes/classes/class-notifier-settings.php';
74 79 require_once NOTIFIER_PATH . 'includes/classes/class-notifier-frontend.php';
75 - require_once NOTIFIER_PATH . 'includes/classes/class-notifier-tools.php';
76 80 }
77 81
78 82 /**
79 83 * Hook into actions and filters.
@@ -82,12 +86,13 @@
82 86 register_activation_hook ( NOTIFIER_FILE, array( $this, 'activate') );
83 87 register_deactivation_hook ( NOTIFIER_FILE, array( $this, 'deactivate') );
84 88
85 89 add_action( 'after_setup_theme', array( 'Notifier_Admin_Notices', 'init' ) );
86 - add_action( 'after_setup_theme', array( 'Notifier_Dashboard', 'init' ) );
90 + add_action( 'after_setup_theme', array( 'Notifier_Connection', 'init' ) );
91 + add_action( 'after_setup_theme', array( 'Notifier_Migration', 'init' ) );
92 + add_action( 'after_setup_theme', array( 'Notifier_Backend', 'init' ) );
87 93 add_action( 'after_setup_theme', array( 'Notifier_Notification_Merge_Tags', 'init' ) );
88 94 add_action( 'after_setup_theme', array( 'Notifier_Notification_Triggers', 'init' ) );
89 - add_action( 'after_setup_theme', array( 'Notifier_Settings', 'init' ) );
90 95 add_action( 'after_setup_theme', array( 'Notifier_Frontend', 'init' ) );
91 96 add_action( 'admin_enqueue_scripts', array( $this , 'admin_scripts') );
92 97 add_action( 'wp_enqueue_scripts', array( $this , 'frontend_scripts') );
93 98 add_action( 'in_admin_header', array( $this , 'embed_page_header' ) );
@@ -92,10 +97,10 @@
92 97 add_action( 'wp_enqueue_scripts', array( $this , 'frontend_scripts') );
93 98 add_action( 'in_admin_header', array( $this , 'embed_page_header' ) );
94 99
95 100 add_action( 'after_setup_theme', array( $this, 'maybe_include_integrations' ) );
96 - add_action( 'after_setup_theme', array( 'Notifier_Tools', 'init' ) );
97 101
102 + add_action( 'init', array( $this, 'load_textdomain' ) );
98 103 add_action( 'wp_loaded', array( $this, 'setup_activity_log' ) );
99 104 add_action( 'notifier_clean_old_logs', array( $this, 'notifier_delete_old_activity_logs' ) );
100 105
101 106 add_action( 'wp_loaded', array( $this, 'create_cart_abandonment_table' ) );
@@ -101,8 +106,15 @@
101 106 add_action( 'wp_loaded', array( $this, 'create_cart_abandonment_table' ) );
102 107 }
103 108
104 109 /**
110 + * Load plugin text domain for translations.
111 + */
112 + public function load_textdomain() {
113 + load_plugin_textdomain( 'notifier', false, dirname( plugin_basename( NOTIFIER_FILE ) ) . '/languages' );
114 + }
115 +
116 + /**
105 117 * Setup during plugin activation
106 118 */
107 119 public function activate() {
108 120 $notifier_plugin_data = get_option('notifier_meta', array());
@@ -127,9 +139,9 @@
127 139 * Check if the plugin was updated and run the upgrade routine if necessary.
128 140 */
129 141 public function setup_activity_log() {
130 142 $notifier_plugin_data = get_option('notifier_meta', array());
131 - if (!isset($notifier_plugin_data['activity_log_table']) && $notifier_plugin_data['activity_log_table'] !== 'yes') {
143 + if ( ! isset( $notifier_plugin_data['activity_log_table'] ) || $notifier_plugin_data['activity_log_table'] !== 'yes' ) {
132 144 self::create_notifier_activity_log_table();
133 145 }
134 146
135 147 $args = array();
@@ -145,9 +157,11 @@
145 157 * Check if plugin's page
146 158 */
147 159 public static function is_notifier_page() {
148 160 $current_screen = get_current_screen();
149 - if ( strpos($current_screen->id, NOTIFIER_NAME) !== false) {
161 + if ( strpos( $current_screen->id, NOTIFIER_NAME ) !== false
162 + && strpos( $current_screen->id, 'order-notifications-for-woocommerce' ) === false
163 + ) {
150 164 return true;
151 165 }
152 166
153 167 return false;
@@ -156,42 +170,40 @@
156 170 /**
157 171 * Add admin scripts and styles
158 172 */
159 173 public function admin_scripts () {
174 + if ( ! Notifier_Migration::is_migration_complete() && 'dismissed' !== get_option( 'notifier_migration_notice_dismissed' ) ) {
175 + wp_enqueue_script(
176 + 'notifier-admin',
177 + NOTIFIER_URL . 'assets/js/admin.js',
178 + array( 'jquery' ),
179 + NOTIFIER_VERSION,
180 + true
181 + );
182 + wp_localize_script( 'notifier-admin', 'notifier_migration', array(
183 + 'ajax_url' => admin_url( 'admin-ajax.php' ),
184 + 'nonce' => wp_create_nonce( 'notifier_dismiss_migration' ),
185 + ) );
186 + }
187 +
160 188 if (!self::is_notifier_page()) {
161 189 return;
162 190 }
163 191
164 - // Select2
165 - wp_enqueue_script(
166 - NOTIFIER_NAME . '-select2-js',
167 - NOTIFIER_URL . 'assets/js/select2.min.js',
168 - array('jquery'),
169 - NOTIFIER_VERSION,
170 - true
171 - );
192 + wp_enqueue_script(
193 + NOTIFIER_NAME . '-admin-react',
194 + NOTIFIER_URL . 'assets/js/admin-react.js',
195 + array(),
196 + NOTIFIER_VERSION,
197 + true
198 + );
172 199
173 - // Admin JS file
174 - wp_enqueue_script(
175 - NOTIFIER_NAME . '-admin-js',
176 - NOTIFIER_URL . 'assets/js/admin.js',
177 - array('jquery'),
178 - NOTIFIER_VERSION,
179 - true
180 - );
181 - wp_localize_script(
182 - NOTIFIER_NAME . '-admin-js',
183 - 'notifierObj',
184 - apply_filters( 'notifier_js_variables', array('ajaxurl' => admin_url( 'admin-ajax.php' ) ) )
185 - );
186 -
187 - // Styles
188 - wp_enqueue_style(
189 - NOTIFIER_NAME . '-admin-css',
190 - NOTIFIER_URL . 'assets/css/admin.css',
191 - null,
192 - NOTIFIER_VERSION
193 - );
200 + wp_enqueue_style(
201 + NOTIFIER_NAME . '-admin-css',
202 + NOTIFIER_URL . 'assets/css/admin.css',
203 + null,
204 + NOTIFIER_VERSION
205 + );
194 206 }
195 207
196 208 /**
197 209 * Add frontend scripts and styles
@@ -206,9 +218,9 @@
206 218 NOTIFIER_VERSION
207 219 );
208 220 }
209 221
210 - if ('yes' === get_option('notifier_enable_abandonment_cart_tracking', 'no') && class_exists('WooCommerce') && is_checkout() ) {
222 + if ( ! self::is_woo_handled_by_standalone_plugin() && 'yes' === get_option('notifier_enable_abandonment_cart_tracking', 'no') && class_exists('WooCommerce') && is_checkout() ) {
211 223 wp_enqueue_script(
212 224 NOTIFIER_NAME . '-js',
213 225 NOTIFIER_URL . 'assets/js/script.js',
214 226 array('jquery'),
@@ -228,23 +240,36 @@
228 240 }
229 241
230 242 /**
231 243 * Set up a div for the header embed to render into.
232 - * The initial contents here are meant as a place loader for when the PHP page initialy loads.
244 + * Only renders for legacy (non-SPA) pages like the trigger CPT editor.
245 + * SPA pages render the header via the React app.
233 246 */
234 247 public static function embed_page_header() {
235 248 if (!self::is_notifier_page()) {
236 249 return;
237 250 }
238 - $current_screen = get_current_screen();
239 - $cpt = ( '' !== $current_screen->post_type) ? $current_screen->post_type : '';
240 - $tax = ( '' !== $current_screen->taxonomy) ? $current_screen->taxonomy : '';
251 +
252 + $screen = get_current_screen();
253 + $spa_pages = array(
254 + 'toplevel_page_notifier',
255 + 'wanotifier_page_notifier-chat-button',
256 + 'wanotifier_page_notifier-settings',
257 + 'wanotifier_page_notifier-logs',
258 + 'wanotifier_page_notifier-migration',
259 + );
260 +
261 + if ( in_array( $screen->id, $spa_pages, true ) ) {
262 + return;
263 + }
264 +
265 + $cpt = ( '' !== $screen->post_type ) ? $screen->post_type : '';
241 266 ?>
242 267 <div id="notifier-admin-header" data-post-type="<?php echo esc_attr($cpt); ?>">
243 268 <div class="notifier-admin-header-content">
244 269 <div class="header-page-title w-30 d-flex align-content-center">
245 - <a class="header-logo" href="admin.php?page=notifier"><img src="<?php echo NOTIFIER_URL; ?>assets/images/favicon.svg"></a>
246 - <h2><?php echo esc_attr(get_admin_page_title()); ?></h2>
270 + <a class="header-logo" href="admin.php?page=notifier"><img src="<?php echo esc_url( NOTIFIER_URL . 'assets/images/favicon.svg' ); ?>"></a>
271 + <h2>WANotifier</h2>
247 272 </div>
248 273 <div class="header-action-links w-30 d-flex justify-content-end">
249 274 <span class="review-us-link">Review us: <a href="https://wordpress.org/support/plugin/notifier/reviews/#new-post" target="_blank">⭐⭐⭐⭐⭐</a></span>
250 275 <span class="header-version">Version: <?php echo esc_html(NOTIFIER_VERSION); ?></span>
@@ -270,15 +295,15 @@
270 295 'Content-Type' => 'application/json; charset=utf-8'
271 296 );
272 297 }
273 298
274 - $request_url = NOTIFIER_APP_API_URL . $endpoint . '?key=' . esc_attr($api_key);
299 + $request_url = NOTIFIER_APP_BASE_URL . '/' . NOTIFIER_APP_API_PATH . '/' . $endpoint . '?key=' . esc_attr($api_key);
275 300 $request_args = array(
276 301 'method' => $method,
277 302 'headers' => $headers,
278 303 'timeout' => 120,
279 304 'body' => json_encode($args),
280 - 'sslverify' => false
305 + 'sslverify' => true
281 306 );
282 307
283 308 $response = wp_remote_request( $request_url, $request_args );
284 309
@@ -293,22 +318,60 @@
293 318 }
294 319 }
295 320
296 321 /**
322 + * Whether the standalone WANotifier for WooCommerce plugin is active and
323 + * has completed its connection/migration, meaning this plugin should defer
324 + * all Woo/WCAR functionality to it.
325 + *
326 + * @return bool
327 + */
328 + public static function is_woo_handled_by_standalone_plugin() {
329 + static $result = null;
330 + if ( null !== $result ) {
331 + return $result;
332 + }
333 +
334 + if ( ! function_exists( 'is_plugin_active' ) ) {
335 + require_once ABSPATH . 'wp-admin/includes/plugin.php';
336 + }
337 +
338 + if ( ! is_plugin_active( 'order-notifications-for-woocommerce/order-notifications-for-woocommerce.php' ) ) {
339 + $result = false;
340 + return false;
341 + }
342 +
343 + if ( 'complete' === get_option( 'wanowc_migration_status' ) ) {
344 + $result = true;
345 + return true;
346 + }
347 +
348 + if ( get_option( 'wanowc_conn_woocommerce_auth_key' ) || get_option( 'wanowc_conn_wcar_auth_key' ) ) {
349 + $result = true;
350 + return true;
351 + }
352 +
353 + $result = false;
354 + return false;
355 + }
356 +
357 + /**
297 358 * Load Woocommerce class if it's present is activated
298 359 */
299 360 public static function maybe_include_integrations () {
300 - // Woocommerce
301 - if ( class_exists( 'WooCommerce' ) ) {
361 + $woo_handled = self::is_woo_handled_by_standalone_plugin();
362 +
363 + // Woocommerce — skip when the standalone plugin handles it
364 + if ( ! $woo_handled && class_exists( 'WooCommerce' ) ) {
302 365 require_once NOTIFIER_PATH . 'includes/classes/integrations/class-notifier-woocommerce.php';
303 366 Notifier_Woocommerce::init();
304 367 }
305 - if ( ! class_exists( 'WC_Session' ) ) {
368 + if ( ! $woo_handled && ! class_exists( 'WC_Session' ) && class_exists( 'WooCommerce' ) ) {
306 369 include_once( WP_PLUGIN_DIR . '/woocommerce/includes/abstracts/abstract-wc-session.php' );
307 370 }
308 371
309 - // WooCommerce Cart Abandonment Recovery by CartFlows
310 - if ( class_exists( 'CARTFLOWS_CA_Loader' ) && defined('CARTFLOWS_CA_VER') && version_compare(CARTFLOWS_CA_VER, '1.2.25', '>=')) {
372 + // WooCommerce Cart Abandonment Recovery — skip when the standalone plugin handles it
373 + if ( ! $woo_handled && class_exists( 'CARTFLOWS_CA_Loader' ) && defined('CARTFLOWS_CA_VER') && version_compare(CARTFLOWS_CA_VER, '1.2.25', '>=')) {
311 374 require_once NOTIFIER_PATH . 'includes/classes/integrations/class-notifier-wcar.php';
312 375 Notifier_WCAR::init();
313 376 }
314 377
@@ -346,8 +409,26 @@
346 409 if ( function_exists( 'fluentFormApi' ) ) {
347 410 require_once NOTIFIER_PATH . 'includes/classes/integrations/class-notifier-fluentforms.php';
348 411 Notifier_FluentForms::init();
349 412 }
413 +
414 + //Forminator
415 + if ( class_exists( 'Forminator' ) ) {
416 + require_once NOTIFIER_PATH . 'includes/classes/integrations/class-notifier-forminator.php';
417 + Notifier_Forminator::init();
418 + }
419 +
420 + //SureForms
421 + if ( class_exists( 'SRFM\Plugin_Loader' ) ) {
422 + require_once NOTIFIER_PATH . 'includes/classes/integrations/class-notifier-sureforms.php';
423 + Notifier_SureForms::init();
424 + }
425 +
426 + //WS Form
427 + if ( class_exists( 'WS_Form' ) ) {
428 + require_once NOTIFIER_PATH . 'includes/classes/integrations/class-notifier-wsform.php';
429 + Notifier_WSForm::init();
430 + }
350 431 }
351 432
352 433 /**
353 434 * Is connection to WANotifier.com active?
@@ -403,10 +484,14 @@
403 484 /**
404 485 * Create New db table-- notifier_cart_abandonment
405 486 */
406 487 public static function create_cart_abandonment_table() {
488 + if ( self::is_woo_handled_by_standalone_plugin() ) {
489 + return;
490 + }
491 +
407 492 $notifier_plugin_data = get_option('notifier_meta', array());
408 - if (!isset($notifier_plugin_data['cart_abandonment_table']) && $notifier_plugin_data['cart_abandonment_table'] !== 'yes') {
493 + if ( ! isset( $notifier_plugin_data['cart_abandonment_table'] ) || $notifier_plugin_data['cart_abandonment_table'] !== 'yes' ) {
409 494 global $wpdb;
410 495 $table_name = $wpdb->prefix . NOTIFIER_CART_ABANDONMENT_TABLE;
411 496 $charset_collate = $wpdb->get_charset_collate();
412 497