| @@ -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.13' ); | |
| 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,50 +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( | |
| 185 | - 'ajaxurl' => admin_url( 'admin-ajax.php' ), | |
| 186 | - 'nonces' => array( | |
| 187 | - 'preview_btn_style' => wp_create_nonce( 'notifier_preview_btn_style' ), | |
| 188 | - 'fetch_activity_logs' => wp_create_nonce( 'notifier_fetch_activity_logs' ), | |
| 189 | - 'change_trigger_status' => wp_create_nonce( 'notifier_change_trigger_status' ), | |
| 190 | - 'fetch_trigger_fields' => wp_create_nonce( 'notifier_fetch_trigger_fields' ) | |
| 191 | - ) | |
| 192 | - ) ) | |
| 193 | - ); | |
| 194 | - | |
| 195 | - // Styles | |
| 196 | - wp_enqueue_style( | |
| 197 | - NOTIFIER_NAME . '-admin-css', | |
| 198 | - NOTIFIER_URL . 'assets/css/admin.css', | |
| 199 | - null, | |
| 200 | - NOTIFIER_VERSION | |
| 201 | - ); | |
| 200 | + wp_enqueue_style( | |
| 201 | + NOTIFIER_NAME . '-admin-css', | |
| 202 | + NOTIFIER_URL . 'assets/css/admin.css', | |
| 203 | + null, | |
| 204 | + NOTIFIER_VERSION | |
| 205 | + ); | |
| 202 | 206 | } |
| 203 | 207 | |
| 204 | 208 | /** |
| 205 | 209 | * Add frontend scripts and styles |
| @@ -214,9 +218,9 @@ | ||
| 214 | 218 | NOTIFIER_VERSION |
| 215 | 219 | ); |
| 216 | 220 | } |
| 217 | 221 | |
| 218 | - 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() ) { | |
| 219 | 223 | wp_enqueue_script( |
| 220 | 224 | NOTIFIER_NAME . '-js', |
| 221 | 225 | NOTIFIER_URL . 'assets/js/script.js', |
| 222 | 226 | array('jquery'), |
| @@ -236,23 +240,36 @@ | ||
| 236 | 240 | } |
| 237 | 241 | |
| 238 | 242 | /** |
| 239 | 243 | * Set up a div for the header embed to render into. |
| 240 | - * 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. | |
| 241 | 246 | */ |
| 242 | 247 | public static function embed_page_header() { |
| 243 | 248 | if (!self::is_notifier_page()) { |
| 244 | 249 | return; |
| 245 | 250 | } |
| 246 | - $current_screen = get_current_screen(); | |
| 247 | - $cpt = ( '' !== $current_screen->post_type) ? $current_screen->post_type : ''; | |
| 248 | - $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 : ''; | |
| 249 | 266 | ?> |
| 250 | 267 | <div id="notifier-admin-header" data-post-type="<?php echo esc_attr($cpt); ?>"> |
| 251 | 268 | <div class="notifier-admin-header-content"> |
| 252 | 269 | <div class="header-page-title w-30 d-flex align-content-center"> |
| 253 | - <a class="header-logo" href="admin.php?page=notifier"><img src="<?php echo NOTIFIER_URL; ?>assets/images/favicon.svg"></a> | |
| 254 | - <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> | |
| 255 | 272 | </div> |
| 256 | 273 | <div class="header-action-links w-30 d-flex justify-content-end"> |
| 257 | 274 | <span class="review-us-link">Review us: <a href="https://wordpress.org/support/plugin/notifier/reviews/#new-post" target="_blank">⭐⭐⭐⭐⭐</a></span> |
| 258 | 275 | <span class="header-version">Version: <?php echo esc_html(NOTIFIER_VERSION); ?></span> |
| @@ -278,15 +295,15 @@ | ||
| 278 | 295 | 'Content-Type' => 'application/json; charset=utf-8' |
| 279 | 296 | ); |
| 280 | 297 | } |
| 281 | 298 | |
| 282 | - $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); | |
| 283 | 300 | $request_args = array( |
| 284 | 301 | 'method' => $method, |
| 285 | 302 | 'headers' => $headers, |
| 286 | 303 | 'timeout' => 120, |
| 287 | 304 | 'body' => json_encode($args), |
| 288 | - 'sslverify' => false | |
| 305 | + 'sslverify' => true | |
| 289 | 306 | ); |
| 290 | 307 | |
| 291 | 308 | $response = wp_remote_request( $request_url, $request_args ); |
| 292 | 309 | |
| @@ -301,22 +318,60 @@ | ||
| 301 | 318 | } |
| 302 | 319 | } |
| 303 | 320 | |
| 304 | 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 | + /** | |
| 305 | 358 | * Load Woocommerce class if it's present is activated |
| 306 | 359 | */ |
| 307 | 360 | public static function maybe_include_integrations () { |
| 308 | - // Woocommerce | |
| 309 | - 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' ) ) { | |
| 310 | 365 | require_once NOTIFIER_PATH . 'includes/classes/integrations/class-notifier-woocommerce.php'; |
| 311 | 366 | Notifier_Woocommerce::init(); |
| 312 | 367 | } |
| 313 | - if ( ! class_exists( 'WC_Session' ) ) { | |
| 368 | + if ( ! $woo_handled && ! class_exists( 'WC_Session' ) && class_exists( 'WooCommerce' ) ) { | |
| 314 | 369 | include_once( WP_PLUGIN_DIR . '/woocommerce/includes/abstracts/abstract-wc-session.php' ); |
| 315 | 370 | } |
| 316 | 371 | |
| 317 | - // WooCommerce Cart Abandonment Recovery by CartFlows | |
| 318 | - 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', '>=')) { | |
| 319 | 374 | require_once NOTIFIER_PATH . 'includes/classes/integrations/class-notifier-wcar.php'; |
| 320 | 375 | Notifier_WCAR::init(); |
| 321 | 376 | } |
| 322 | 377 | |
| @@ -354,8 +409,26 @@ | ||
| 354 | 409 | if ( function_exists( 'fluentFormApi' ) ) { |
| 355 | 410 | require_once NOTIFIER_PATH . 'includes/classes/integrations/class-notifier-fluentforms.php'; |
| 356 | 411 | Notifier_FluentForms::init(); |
| 357 | 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 | + } | |
| 358 | 431 | } |
| 359 | 432 | |
| 360 | 433 | /** |
| 361 | 434 | * Is connection to WANotifier.com active? |
| @@ -411,10 +484,14 @@ | ||
| 411 | 484 | /** |
| 412 | 485 | * Create New db table-- notifier_cart_abandonment |
| 413 | 486 | */ |
| 414 | 487 | public static function create_cart_abandonment_table() { |
| 488 | + if ( self::is_woo_handled_by_standalone_plugin() ) { | |
| 489 | + return; | |
| 490 | + } | |
| 491 | + | |
| 415 | 492 | $notifier_plugin_data = get_option('notifier_meta', array()); |
| 416 | - 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' ) { | |
| 417 | 494 | global $wpdb; |
| 418 | 495 | $table_name = $wpdb->prefix . NOTIFIER_CART_ABANDONMENT_TABLE; |
| 419 | 496 | $charset_collate = $wpdb->get_charset_collate(); |
| 420 | 497 | |