| @@ -22,13 +22,13 @@ | ||
| 22 | 22 | /** |
| 23 | 23 | * Define Constants. |
| 24 | 24 | */ |
| 25 | 25 | private function define_constants() { |
| 26 | - $this->define( 'NOTIFIER_VERSION', '1.0.3' ); | |
| 26 | + $this->define( 'NOTIFIER_VERSION', '2.1.3' ); | |
| 27 | 27 | $this->define( 'NOTIFIER_NAME', 'notifier' ); |
| 28 | 28 | $this->define( 'NOTIFIER_PREFIX', 'notifier_' ); |
| 29 | 29 | $this->define( 'NOTIFIER_URL', trailingslashit( plugins_url( '', dirname(__FILE__) ) ) ); |
| 30 | - $this->define( 'NOTIFIER_APP_API_URL', 'https://app.wanotifier.com/api/' ); | |
| 30 | + $this->define( 'NOTIFIER_APP_API_URL', 'https://app.wanotifier.com/api/v1/' ); | |
| 31 | 31 | } |
| 32 | 32 | |
| 33 | 33 | /** |
| 34 | 34 | * Define constant if not already set. |
| @@ -57,11 +57,8 @@ | ||
| 57 | 57 | /** |
| 58 | 58 | * Include required core files used in admin and on the frontend. |
| 59 | 59 | */ |
| 60 | 60 | private function includes() { |
| 61 | - // Libraries | |
| 62 | - require_once NOTIFIER_PATH . 'libraries/action-scheduler/action-scheduler.php'; | |
| 63 | - | |
| 64 | 61 | // Functions |
| 65 | 62 | require_once NOTIFIER_PATH . 'includes/functions/functions-notifier-helpers.php'; |
| 66 | 63 | require_once NOTIFIER_PATH . 'includes/functions/functions-notifier-meta-box-fields.php'; |
| 67 | 64 | |
| @@ -70,8 +67,9 @@ | ||
| 70 | 67 | require_once NOTIFIER_PATH . 'includes/classes/class-notifier-dashboard.php'; |
| 71 | 68 | require_once NOTIFIER_PATH . 'includes/classes/class-notifier-notification-merge-tags.php'; |
| 72 | 69 | require_once NOTIFIER_PATH . 'includes/classes/class-notifier-notification-triggers.php'; |
| 73 | 70 | require_once NOTIFIER_PATH . 'includes/classes/class-notifier-settings.php'; |
| 71 | + require_once NOTIFIER_PATH . 'includes/classes/class-notifier-frontend.php'; | |
| 74 | 72 | } |
| 75 | 73 | |
| 76 | 74 | /** |
| 77 | 75 | * Hook into actions and filters. |
| @@ -78,18 +76,19 @@ | ||
| 78 | 76 | */ |
| 79 | 77 | private function init_hooks() { |
| 80 | 78 | register_activation_hook ( NOTIFIER_FILE, array( $this, 'install') ); |
| 81 | 79 | |
| 82 | - add_action( 'plugins_loaded', array( 'Notifier_Admin_Notices', 'init' ) ); | |
| 83 | - add_action( 'plugins_loaded', array( 'Notifier_Dashboard', 'init' ) ); | |
| 84 | - add_action( 'plugins_loaded', array( 'Notifier_Notification_Merge_Tags', 'init' ) ); | |
| 85 | - add_action( 'plugins_loaded', array( 'Notifier_Notification_Triggers', 'init' ) ); | |
| 86 | - add_action( 'plugins_loaded', array( 'Notifier_Settings', 'init' ) ); | |
| 87 | - | |
| 88 | - add_action( 'plugins_loaded', array( $this, 'maybe_include_woocoomerce_class' ) ); | |
| 89 | - | |
| 80 | + add_action( 'after_setup_theme', array( 'Notifier_Admin_Notices', 'init' ) ); | |
| 81 | + add_action( 'after_setup_theme', array( 'Notifier_Dashboard', 'init' ) ); | |
| 82 | + add_action( 'after_setup_theme', array( 'Notifier_Notification_Merge_Tags', 'init' ) ); | |
| 83 | + add_action( 'after_setup_theme', array( 'Notifier_Notification_Triggers', 'init' ) ); | |
| 84 | + add_action( 'after_setup_theme', array( 'Notifier_Settings', 'init' ) ); | |
| 85 | + add_action( 'after_setup_theme', array( 'Notifier_Frontend', 'init' ) ); | |
| 90 | 86 | add_action( 'admin_enqueue_scripts', array( $this , 'admin_scripts') ); |
| 87 | + add_action( 'wp_enqueue_scripts', array( $this , 'frontend_scripts') ); | |
| 91 | 88 | add_action( 'in_admin_header', array( $this , 'embed_page_header' ) ); |
| 89 | + | |
| 90 | + add_action( 'after_setup_theme', array( $this, 'maybe_include_integrations' ) ); | |
| 92 | 91 | } |
| 93 | 92 | |
| 94 | 93 | /** |
| 95 | 94 | * Setup during plugin activation |
| @@ -136,9 +135,9 @@ | ||
| 136 | 135 | true |
| 137 | 136 | ); |
| 138 | 137 | wp_localize_script( |
| 139 | 138 | NOTIFIER_NAME . '-admin-js', |
| 140 | - 'waNotifier', | |
| 139 | + 'notifierObj', | |
| 141 | 140 | apply_filters( 'notifier_js_variables', array('ajaxurl' => admin_url( 'admin-ajax.php' ) ) ) |
| 142 | 141 | ); |
| 143 | 142 | |
| 144 | 143 | // Styles |
| @@ -150,8 +149,23 @@ | ||
| 150 | 149 | ); |
| 151 | 150 | } |
| 152 | 151 | |
| 153 | 152 | /** |
| 153 | + * Add frontend scripts and styles | |
| 154 | + */ | |
| 155 | + public function frontend_scripts () { | |
| 156 | + if('yes' === get_option('notifier_ctc_enable')){ | |
| 157 | + // Styles | |
| 158 | + wp_enqueue_style( | |
| 159 | + NOTIFIER_NAME . '-frontend-css', | |
| 160 | + NOTIFIER_URL . 'assets/css/frontend.css', | |
| 161 | + null, | |
| 162 | + NOTIFIER_VERSION | |
| 163 | + ); | |
| 164 | + } | |
| 165 | + } | |
| 166 | + | |
| 167 | + /** | |
| 154 | 168 | * Set up a div for the header embed to render into. |
| 155 | 169 | * The initial contents here are meant as a place loader for when the PHP page initialy loads. |
| 156 | 170 | */ |
| 157 | 171 | public static function embed_page_header() { |
| @@ -178,9 +192,9 @@ | ||
| 178 | 192 | |
| 179 | 193 | /** |
| 180 | 194 | * For sending API requests |
| 181 | 195 | */ |
| 182 | - public static function send_api_request ( $args, $method, $headers = array() ) { | |
| 196 | + public static function send_api_request ( $endpoint, $args, $method = 'POST', $headers = array() ) { | |
| 183 | 197 | $api_key = get_option('notifier_api_key'); |
| 184 | 198 | $api_key = trim($api_key); |
| 185 | 199 | if('' == $api_key) { |
| 186 | 200 | return false; |
| @@ -185,19 +199,27 @@ | ||
| 185 | 199 | if('' == $api_key) { |
| 186 | 200 | return false; |
| 187 | 201 | } |
| 188 | 202 | |
| 189 | - $request_url = NOTIFIER_APP_API_URL . $api_key . '/'; | |
| 203 | + if(empty($headers)){ | |
| 204 | + $headers = array( | |
| 205 | + 'Content-Type' => 'application/json; charset=utf-8' | |
| 206 | + ); | |
| 207 | + } | |
| 208 | + | |
| 209 | + $request_url = NOTIFIER_APP_API_URL . $endpoint . '?key=' . $api_key; | |
| 190 | 210 | $request_args = array( |
| 191 | 211 | 'method' => $method, |
| 192 | 212 | 'headers' => $headers, |
| 193 | 213 | 'timeout' => 120, |
| 194 | - 'body' => $args, | |
| 214 | + 'body' => json_encode($args), | |
| 195 | 215 | 'sslverify' => false |
| 196 | 216 | ); |
| 197 | 217 | |
| 198 | 218 | $response = wp_remote_request( $request_url, $request_args); |
| 199 | 219 | |
| 220 | + $response_body = wp_remote_retrieve_body( $response ); | |
| 221 | + | |
| 200 | 222 | if ( is_wp_error( $response ) ) { |
| 201 | 223 | error_log( $response->get_error_message() ); |
| 202 | 224 | return false; |
| 203 | 225 | } else { |
| @@ -208,12 +230,65 @@ | ||
| 208 | 230 | |
| 209 | 231 | /** |
| 210 | 232 | * Load Woocommerce class if it's present is activated |
| 211 | 233 | */ |
| 212 | - public static function maybe_include_woocoomerce_class () { | |
| 234 | + public static function maybe_include_integrations () { | |
| 235 | + // Woocommerce | |
| 213 | 236 | if ( class_exists( 'WooCommerce' ) ) { |
| 214 | 237 | require_once NOTIFIER_PATH . 'includes/classes/class-notifier-woocommerce.php'; |
| 215 | 238 | Notifier_Woocommerce::init(); |
| 239 | + } | |
| 240 | + if ( ! class_exists( 'WC_Session' ) ) { | |
| 241 | + include_once( WP_PLUGIN_DIR . '/woocommerce/includes/abstracts/abstract-wc-session.php' ); | |
| 242 | + } | |
| 243 | + | |
| 244 | + // Gravity Forms | |
| 245 | + if ( class_exists( 'GFCommon' ) ) { | |
| 246 | + require_once NOTIFIER_PATH . 'includes/classes/class-notifier-gravityforms.php'; | |
| 247 | + Notifier_GravityForms::init(); | |
| 248 | + } | |
| 249 | + | |
| 250 | + // Contact Form 7 | |
| 251 | + if ( class_exists( 'WPCF7' ) ) { | |
| 252 | + require_once NOTIFIER_PATH . 'includes/classes/class-notifier-cf7.php'; | |
| 253 | + Notifier_ContactForm7::init(); | |
| 254 | + } | |
| 255 | + | |
| 256 | + // WPForms | |
| 257 | + if ( class_exists( 'WPForms' ) ) { | |
| 258 | + require_once NOTIFIER_PATH . 'includes/classes/class-notifier-wpforms.php'; | |
| 259 | + Notifier_WPForms::init(); | |
| 260 | + } | |
| 261 | + | |
| 262 | + // Ninja Forms | |
| 263 | + if ( class_exists( 'Ninja_Forms' ) ) { | |
| 264 | + require_once NOTIFIER_PATH . 'includes/classes/class-notifier-ninjaforms.php'; | |
| 265 | + Notifier_NinjaForms::init(); | |
| 266 | + } | |
| 267 | + | |
| 268 | + //FrmForm | |
| 269 | + if ( class_exists( 'FrmForm' ) ) { | |
| 270 | + require_once NOTIFIER_PATH . 'includes/classes/class-notifier-formidable.php'; | |
| 271 | + Notifier_Formidable::init(); | |
| 272 | + } | |
| 273 | + | |
| 274 | + //WPFluentForm | |
| 275 | + if ( function_exists( 'fluentFormApi' ) ) { | |
| 276 | + require_once NOTIFIER_PATH . 'includes/classes/class-notifier-fluentforms.php'; | |
| 277 | + Notifier_FluentForms::init(); | |
| 278 | + } | |
| 279 | + } | |
| 280 | + | |
| 281 | + /** | |
| 282 | + * Is connection to WANotifier.com active? | |
| 283 | + */ | |
| 284 | + public static function is_api_active () { | |
| 285 | + $activated = get_option(NOTIFIER_PREFIX . 'api_activated'); | |
| 286 | + if('yes' == $activated) { | |
| 287 | + return true; | |
| 288 | + } | |
| 289 | + else{ | |
| 290 | + return false; | |
| 216 | 291 | } |
| 217 | 292 | } |
| 218 | 293 | |
| 219 | 294 | } |