| @@ -22,14 +22,14 @@ | ||
| 22 | 22 | /** |
| 23 | 23 | * Define Constants. |
| 24 | 24 | */ |
| 25 | 25 | private function define_constants() { |
| 26 | - $this->define( 'NOTIFIER_VERSION', '0.1.0' ); | |
| 26 | + $this->define( 'NOTIFIER_VERSION', '2.6.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_WA_API_VERSION', 'v14.0' ); | |
| 31 | - $this->define( 'NOTIFIER_WA_API_URL', 'https://graph.facebook.com/' . NOTIFIER_WA_API_VERSION . '/' ); | |
| 30 | + $this->define( 'NOTIFIER_APP_API_URL', 'https://app.wanotifier.com/api/v1/' ); | |
| 31 | + $this->define( 'NOTIFIER_ACTIVITY_TABLE_NAME', 'notifier_activity_log' ); | |
| 32 | 32 | } |
| 33 | 33 | |
| 34 | 34 | /** |
| 35 | 35 | * Define constant if not already set. |
| @@ -58,23 +58,21 @@ | ||
| 58 | 58 | /** |
| 59 | 59 | * Include required core files used in admin and on the frontend. |
| 60 | 60 | */ |
| 61 | 61 | private function includes() { |
| 62 | - // Libraries | |
| 63 | - require_once NOTIFIER_PATH . 'libraries/action-scheduler/action-scheduler.php'; | |
| 64 | - | |
| 65 | 62 | // Functions |
| 66 | 63 | require_once NOTIFIER_PATH . 'includes/functions/functions-notifier-helpers.php'; |
| 67 | 64 | require_once NOTIFIER_PATH . 'includes/functions/functions-notifier-meta-box-fields.php'; |
| 65 | + require_once NOTIFIER_PATH . 'libraries/action-scheduler/action-scheduler.php'; | |
| 68 | 66 | |
| 69 | 67 | // Classes |
| 70 | 68 | require_once NOTIFIER_PATH . 'includes/classes/class-notifier-admin-notices.php'; |
| 71 | 69 | require_once NOTIFIER_PATH . 'includes/classes/class-notifier-dashboard.php'; |
| 72 | - require_once NOTIFIER_PATH . 'includes/classes/class-notifier-message-templates.php'; | |
| 73 | - require_once NOTIFIER_PATH . 'includes/classes/class-notifier-contacts.php'; | |
| 74 | - require_once NOTIFIER_PATH . 'includes/classes/class-notifier-notifications.php'; | |
| 70 | + require_once NOTIFIER_PATH . 'includes/classes/class-notifier-notification-merge-tags.php'; | |
| 75 | 71 | require_once NOTIFIER_PATH . 'includes/classes/class-notifier-notification-triggers.php'; |
| 76 | 72 | require_once NOTIFIER_PATH . 'includes/classes/class-notifier-settings.php'; |
| 73 | + require_once NOTIFIER_PATH . 'includes/classes/class-notifier-frontend.php'; | |
| 74 | + require_once NOTIFIER_PATH . 'includes/classes/class-notifier-tools.php'; | |
| 77 | 75 | } |
| 78 | 76 | |
| 79 | 77 | /** |
| 80 | 78 | * Hook into actions and filters. |
| @@ -79,41 +77,68 @@ | ||
| 79 | 77 | /** |
| 80 | 78 | * Hook into actions and filters. |
| 81 | 79 | */ |
| 82 | 80 | private function init_hooks() { |
| 83 | - register_activation_hook ( NOTIFIER_FILE, array( $this, 'install') ); | |
| 81 | + register_activation_hook ( NOTIFIER_FILE, array( $this, 'activate') ); | |
| 82 | + register_deactivation_hook ( NOTIFIER_FILE, array( $this, 'deactivate') ); | |
| 84 | 83 | |
| 85 | - add_action( 'plugins_loaded', array( 'Notifier_Dashboard', 'init' ) ); | |
| 86 | - add_action( 'plugins_loaded', array( 'Notifier_Message_Templates', 'init' ) ); | |
| 87 | - add_action( 'plugins_loaded', array( 'Notifier_Contacts', 'init' ) ); | |
| 88 | - add_action( 'plugins_loaded', array( 'Notifier_Notifications', 'init' ) ); | |
| 89 | - add_action( 'plugins_loaded', array( 'Notifier_Notification_Triggers', 'init' ) ); | |
| 90 | - add_action( 'plugins_loaded', array( 'Notifier_Settings', 'init' ) ); | |
| 91 | - add_action( 'plugins_loaded', array( $this, 'maybe_include_woocoomerce_class' ) ); | |
| 92 | - | |
| 93 | - add_filter( 'init', array( $this , 'handle_webhook_requests') ); | |
| 94 | - | |
| 84 | + add_action( 'after_setup_theme', array( 'Notifier_Admin_Notices', 'init' ) ); | |
| 85 | + add_action( 'after_setup_theme', array( 'Notifier_Dashboard', 'init' ) ); | |
| 86 | + add_action( 'after_setup_theme', array( 'Notifier_Notification_Merge_Tags', 'init' ) ); | |
| 87 | + add_action( 'after_setup_theme', array( 'Notifier_Notification_Triggers', 'init' ) ); | |
| 88 | + add_action( 'after_setup_theme', array( 'Notifier_Settings', 'init' ) ); | |
| 89 | + add_action( 'after_setup_theme', array( 'Notifier_Frontend', 'init' ) ); | |
| 95 | 90 | add_action( 'admin_enqueue_scripts', array( $this , 'admin_scripts') ); |
| 91 | + add_action( 'wp_enqueue_scripts', array( $this , 'frontend_scripts') ); | |
| 96 | 92 | add_action( 'in_admin_header', array( $this , 'embed_page_header' ) ); |
| 97 | 93 | |
| 98 | - add_action( 'removable_query_args', array( $this , 'remove_admin_query_args') ); | |
| 94 | + add_action( 'after_setup_theme', array( $this, 'maybe_include_integrations' ) ); | |
| 95 | + add_action( 'after_setup_theme', array( 'Notifier_Tools', 'init' ) ); | |
| 99 | 96 | |
| 100 | - add_action( 'admin_footer', array($this, 'add_admin_html_templates') ); | |
| 97 | + add_action( 'wp_loaded', array( $this, 'setup_activity_log' ) ); | |
| 98 | + add_action( 'notifier_clean_old_logs', array( $this, 'notifier_delete_old_activity_logs' ) ); | |
| 101 | 99 | } |
| 102 | 100 | |
| 103 | 101 | /** |
| 104 | 102 | * Setup during plugin activation |
| 105 | 103 | */ |
| 106 | - public function install() { | |
| 107 | - $verify_token = get_option(NOTIFIER_PREFIX . 'verify_token'); | |
| 108 | - if (!$verify_token) { | |
| 109 | - $bytes = random_bytes(20); | |
| 110 | - $verify_token = NOTIFIER_NAME . '-' . substr(bin2hex($bytes), 0, 10); | |
| 111 | - update_option(NOTIFIER_PREFIX . 'verify_token', $verify_token); | |
| 104 | + public function activate() { | |
| 105 | + $notifier_plugin_data = get_option('notifier_meta', array()); | |
| 106 | + if (isset($notifier_plugin_data['as_clear_log']) && $notifier_plugin_data['as_clear_log'] === 'yes') { | |
| 107 | + unset($notifier_plugin_data['as_clear_log']); | |
| 108 | + update_option('notifier_meta', $notifier_plugin_data); | |
| 112 | 109 | } |
| 113 | 110 | } |
| 114 | 111 | |
| 115 | 112 | /** |
| 113 | + * Setup during plugin deactivation | |
| 114 | + */ | |
| 115 | + public function deactivate() { | |
| 116 | + as_unschedule_action('notifier_clean_old_logs'); | |
| 117 | + $notifier_plugin_data = get_option('notifier_meta', array()); | |
| 118 | + $notifier_plugin_data['as_clear_log'] = 'yes'; | |
| 119 | + update_option('notifier_meta', $notifier_plugin_data); | |
| 120 | + } | |
| 121 | + | |
| 122 | + /** | |
| 123 | + * Check if the plugin was updated and run the upgrade routine if necessary. | |
| 124 | + */ | |
| 125 | + public function setup_activity_log() { | |
| 126 | + $notifier_plugin_data = get_option('notifier_meta', array()); | |
| 127 | + if (!isset($notifier_plugin_data['activity_log_table']) && $notifier_plugin_data['activity_log_table'] !== 'yes') { | |
| 128 | + self::create_notifier_activity_log_table(); | |
| 129 | + } | |
| 130 | + | |
| 131 | + $args = array(); | |
| 132 | + $as_clear_log = isset($notifier_plugin_data['as_clear_log']) ? $notifier_plugin_data['as_clear_log'] : 'no'; | |
| 133 | + if ($as_clear_log !== 'yes') { | |
| 134 | + if (false === as_next_scheduled_action('notifier_clean_old_logs')) { | |
| 135 | + as_schedule_recurring_action(time(), DAY_IN_SECONDS, 'notifier_clean_old_logs', $args); | |
| 136 | + } | |
| 137 | + } | |
| 138 | + } | |
| 139 | + | |
| 140 | + /** | |
| 116 | 141 | * Check if plugin's page |
| 117 | 142 | */ |
| 118 | 143 | public static function is_notifier_page() { |
| 119 | 144 | $current_screen = get_current_screen(); |
| @@ -120,13 +145,8 @@ | ||
| 120 | 145 | if ( strpos($current_screen->id, NOTIFIER_NAME) !== false) { |
| 121 | 146 | return true; |
| 122 | 147 | } |
| 123 | 148 | |
| 124 | - $plugin_ctps = array( 'wa_message_template', 'wa_contact', 'wa_notification' ); | |
| 125 | - if ( '' !== $current_screen->post_type && in_array( $current_screen->post_type, $plugin_ctps ) ) { | |
| 126 | - return true; | |
| 127 | - } | |
| 128 | - | |
| 129 | 149 | return false; |
| 130 | 150 | } |
| 131 | 151 | |
| 132 | 152 | /** |
| @@ -145,18 +165,8 @@ | ||
| 145 | 165 | NOTIFIER_VERSION, |
| 146 | 166 | true |
| 147 | 167 | ); |
| 148 | 168 | |
| 149 | - // Date / time picker | |
| 150 | - wp_enqueue_script( 'jquery-ui-datepicker' ); | |
| 151 | - wp_enqueue_script( | |
| 152 | - NOTIFIER_NAME . '-timepicker-addon', | |
| 153 | - NOTIFIER_URL . 'assets/js/jquery-ui-timepicker-addon.min.js', | |
| 154 | - array( 'jquery-ui-datepicker' ), | |
| 155 | - NOTIFIER_VERSION, | |
| 156 | - true | |
| 157 | - ); | |
| 158 | - | |
| 159 | 169 | // Admin JS file |
| 160 | 170 | wp_enqueue_script( |
| 161 | 171 | NOTIFIER_NAME . '-admin-js', |
| 162 | 172 | NOTIFIER_URL . 'assets/js/admin.js', |
| @@ -165,15 +175,12 @@ | ||
| 165 | 175 | true |
| 166 | 176 | ); |
| 167 | 177 | wp_localize_script( |
| 168 | 178 | NOTIFIER_NAME . '-admin-js', |
| 169 | - 'waNotifier', | |
| 179 | + 'notifierObj', | |
| 170 | 180 | apply_filters( 'notifier_js_variables', array('ajaxurl' => admin_url( 'admin-ajax.php' ) ) ) |
| 171 | 181 | ); |
| 172 | 182 | |
| 173 | - // Media upload library | |
| 174 | - wp_enqueue_media(); | |
| 175 | - | |
| 176 | 183 | // Styles |
| 177 | 184 | wp_enqueue_style( |
| 178 | 185 | NOTIFIER_NAME . '-admin-css', |
| 179 | 186 | NOTIFIER_URL . 'assets/css/admin.css', |
| @@ -182,8 +189,23 @@ | ||
| 182 | 189 | ); |
| 183 | 190 | } |
| 184 | 191 | |
| 185 | 192 | /** |
| 193 | + * Add frontend scripts and styles | |
| 194 | + */ | |
| 195 | + public function frontend_scripts () { | |
| 196 | + if('yes' === get_option('notifier_ctc_enable')){ | |
| 197 | + // Styles | |
| 198 | + wp_enqueue_style( | |
| 199 | + NOTIFIER_NAME . '-frontend-css', | |
| 200 | + NOTIFIER_URL . 'assets/css/frontend.css', | |
| 201 | + null, | |
| 202 | + NOTIFIER_VERSION | |
| 203 | + ); | |
| 204 | + } | |
| 205 | + } | |
| 206 | + | |
| 207 | + /** | |
| 186 | 208 | * Set up a div for the header embed to render into. |
| 187 | 209 | * The initial contents here are meant as a place loader for when the PHP page initialy loads. |
| 188 | 210 | */ |
| 189 | 211 | public static function embed_page_header() { |
| @@ -195,34 +217,16 @@ | ||
| 195 | 217 | $tax = ( '' !== $current_screen->taxonomy) ? $current_screen->taxonomy : ''; |
| 196 | 218 | ?> |
| 197 | 219 | <div id="notifier-admin-header" data-post-type="<?php echo esc_attr($cpt); ?>"> |
| 198 | 220 | <div class="notifier-admin-header-content"> |
| 199 | - <div class="header-page-title w-30"> | |
| 221 | + <div class="header-page-title w-30 d-flex align-content-center"> | |
| 222 | + <a class="header-logo" href="admin.php?page=notifier"><img src="<?php echo NOTIFIER_URL; ?>assets/images/favicon.svg"></a> | |
| 200 | 223 | <h2><?php echo esc_attr(get_admin_page_title()); ?></h2> |
| 201 | 224 | </div> |
| 202 | - <div class="header-menu-items w-40 d-flex justify-content-center"> | |
| 203 | - <?php | |
| 204 | - if ( 'wa_contact' == $cpt ) { | |
| 205 | - ?> | |
| 206 | - <ul> | |
| 207 | - <li> | |
| 208 | - <a class="<?php echo ('wa_contact_list' !== $tax && 'wa_contact_tag' !== $tax) ? 'active' : ''; ?>" href="<?php echo esc_url( admin_url('edit.php?post_type=wa_contact') ); ?>" class="">Contacts</a> | |
| 209 | - </li> | |
| 210 | - <li> | |
| 211 | - <a class="<?php echo ('wa_contact_list' == $tax) ? 'active' : ''; ?>" href="<?php echo esc_url( admin_url('edit-tags.php?taxonomy=wa_contact_list&post_type=wa_contact') ); ?>">Lists</a> | |
| 212 | - </li> | |
| 213 | - <li> | |
| 214 | - <a class="<?php echo ('wa_contact_tag' == $tax) ? 'active' : ''; ?>" href="<?php echo esc_url( admin_url('edit-tags.php?taxonomy=wa_contact_tag&post_type=wa_contact') ); ?>">Tags</a> | |
| 215 | - </li> | |
| 216 | - </ul> | |
| 217 | - <?php | |
| 218 | - } | |
| 219 | - ?> | |
| 220 | - </div> | |
| 221 | 225 | <div class="header-action-links w-30 d-flex justify-content-end"> |
| 222 | - <span class="header-version">Version: <?php echo esc_html(NOTIFIER_VERSION); ?> (beta)</span> | |
| 223 | - <a href="mailto:ram@fantastech.co?subject=%5BWA%20Notifier%5D%20Help%20Needed%20on<?php echo esc_url(get_site_url()); ?>">Help</a> | |
| 224 | - <a href="admin.php?page=notifier&show=disclaimer">Disclaimer</a> | |
| 226 | + <span class="review-us-link">Review us: <a href="https://wordpress.org/support/plugin/notifier/reviews/#new-post" target="_blank">⭐⭐⭐⭐⭐</a></span> | |
| 227 | + <span class="header-version">Version: <?php echo esc_html(NOTIFIER_VERSION); ?></span> | |
| 228 | + <a href="https://wanotifier.com/support/" target="_blank">Help</a> | |
| 225 | 229 | </div> |
| 226 | 230 | </div> |
| 227 | 231 | </div> |
| 228 | 232 | <?php |
| @@ -228,80 +232,39 @@ | ||
| 228 | 232 | <?php |
| 229 | 233 | } |
| 230 | 234 | |
| 231 | 235 | /** |
| 232 | - * Handle response from Whatsapp | |
| 236 | + * For sending API requests | |
| 233 | 237 | */ |
| 234 | - public static function handle_webhook_requests () { | |
| 235 | - if ( ! isset($_GET['notifier']) ) { | |
| 236 | - return; | |
| 238 | + public static function send_api_request ( $endpoint, $args, $method = 'POST', $headers = array() ) { | |
| 239 | + $api_key = get_option('notifier_api_key'); | |
| 240 | + $api_key = trim($api_key); | |
| 241 | + if('' == $api_key) { | |
| 242 | + return false; | |
| 237 | 243 | } |
| 238 | 244 | |
| 239 | - if ( ! isset($_POST) ) { | |
| 240 | - return; | |
| 245 | + if(empty($headers)){ | |
| 246 | + $headers = array( | |
| 247 | + 'Content-Type' => 'application/json; charset=utf-8' | |
| 248 | + ); | |
| 241 | 249 | } |
| 242 | 250 | |
| 243 | - $hub_mode = isset($_GET['hub_mode']) ? sanitize_text_field( wp_unslash( $_GET['hub_mode'] ) ) : ''; | |
| 244 | - $hub_verify_token = isset($_GET['hub_verify_token']) ? sanitize_text_field( wp_unslash( $_GET['hub_verify_token'] ) ) : ''; | |
| 245 | - $hub_challenge = isset($_GET['hub_challenge']) ? sanitize_text_field( wp_unslash( $_GET['hub_challenge'] ) ) : ''; | |
| 246 | - | |
| 247 | - /* Validate WhastApp API webbook */ | |
| 248 | - if ( 'subscribe' === $hub_mode ) { | |
| 249 | - $verify_token = get_option(NOTIFIER_PREFIX . 'verify_token'); | |
| 250 | - if ($hub_verify_token == $verify_token) { | |
| 251 | - echo esc_html($hub_challenge); | |
| 252 | - } | |
| 253 | - } | |
| 254 | - | |
| 255 | - exit; | |
| 256 | - } | |
| 257 | - | |
| 258 | - /** | |
| 259 | - * For sending requests to Cloud API | |
| 260 | - */ | |
| 261 | - public static function wa_cloud_api_request ( $endpoint, $args = array(), $method = 'POST', $headers = array() ) { | |
| 262 | - $phone_number_id = get_option('notifier_phone_number_id'); | |
| 263 | - $request_url = NOTIFIER_WA_API_URL . $phone_number_id . '/' . untrailingslashit($endpoint); | |
| 264 | - return self::send_api_request($request_url, $args, $method, $headers); | |
| 265 | - } | |
| 266 | - | |
| 267 | - /** | |
| 268 | - * For sending requests to WA Business API | |
| 269 | - */ | |
| 270 | - public static function wa_business_api_request ( $endpoint, $args = array(), $method = 'POST', $headers = array() ) { | |
| 271 | - $business_account_id = get_option('notifier_business_account_id'); | |
| 272 | - $request_url = NOTIFIER_WA_API_URL . $business_account_id . '/' . untrailingslashit($endpoint); | |
| 273 | - return self::send_api_request($request_url, $args, $method, $headers); | |
| 274 | - } | |
| 275 | - | |
| 276 | - /** | |
| 277 | - * For sending graph api requests | |
| 278 | - */ | |
| 279 | - public static function wa_graph_api_request ( $endpoint, $args = array(), $method = 'POST', $headers = array() ) { | |
| 280 | - $request_url = NOTIFIER_WA_API_URL . untrailingslashit($endpoint); | |
| 281 | - return self::send_api_request($request_url, $args, $method, $headers); | |
| 282 | - } | |
| 283 | - | |
| 284 | - /** | |
| 285 | - * For sending API requests | |
| 286 | - */ | |
| 287 | - private static function send_api_request ( $request_url, $args, $method, $headers ) { | |
| 288 | - $permanent_access_token = get_option('notifier_permanent_access_token'); | |
| 289 | - $headers = wp_parse_args($headers, array( | |
| 290 | - 'Authorization' => 'Bearer ' . $permanent_access_token | |
| 291 | - )); | |
| 251 | + $request_url = NOTIFIER_APP_API_URL . $endpoint . '?key=' . esc_attr($api_key); | |
| 292 | 252 | $request_args = array( |
| 293 | 253 | 'method' => $method, |
| 294 | 254 | 'headers' => $headers, |
| 295 | - 'body' => $args | |
| 255 | + 'timeout' => 120, | |
| 256 | + 'body' => json_encode($args), | |
| 257 | + 'sslverify' => false | |
| 296 | 258 | ); |
| 297 | - $response = wp_remote_request( $request_url, $request_args); | |
| 259 | + | |
| 260 | + $response = wp_remote_request( $request_url, $request_args ); | |
| 261 | + | |
| 262 | + $response_body = wp_remote_retrieve_body( $response ); | |
| 263 | + | |
| 298 | 264 | if ( is_wp_error( $response ) ) { |
| 299 | 265 | error_log( $response->get_error_message() ); |
| 300 | 266 | return false; |
| 301 | - } elseif (isset($response->error)) { | |
| 302 | - error_log($response->error_user_title . ' - ' . $response->eerror_user_msg); | |
| 303 | - return json_decode($response_body); | |
| 304 | 267 | } else { |
| 305 | 268 | $response_body = wp_remote_retrieve_body( $response ); |
| 306 | 269 | return json_decode($response_body); |
| 307 | 270 | } |
| @@ -307,98 +270,110 @@ | ||
| 307 | 270 | } |
| 308 | 271 | } |
| 309 | 272 | |
| 310 | 273 | /** |
| 311 | - * For uploading profile pic to app | |
| 274 | + * Load Woocommerce class if it's present is activated | |
| 312 | 275 | */ |
| 313 | - public static function wa_cloud_api_upload_profile_pic($attachment_id) { | |
| 314 | - $file_path = get_attached_file($attachment_id); | |
| 315 | - $file_size = filesize($file_path); | |
| 276 | + public static function maybe_include_integrations () { | |
| 277 | + // Woocommerce | |
| 278 | + if ( class_exists( 'WooCommerce' ) ) { | |
| 279 | + require_once NOTIFIER_PATH . 'includes/classes/integrations/class-notifier-woocommerce.php'; | |
| 280 | + Notifier_Woocommerce::init(); | |
| 281 | + } | |
| 282 | + if ( ! class_exists( 'WC_Session' ) ) { | |
| 283 | + include_once( WP_PLUGIN_DIR . '/woocommerce/includes/abstracts/abstract-wc-session.php' ); | |
| 284 | + } | |
| 316 | 285 | |
| 317 | - if (!$file_path) { | |
| 318 | - return; | |
| 286 | + // WooCommerce Cart Abandonment Recovery by CartFlows | |
| 287 | + if ( class_exists( 'CARTFLOWS_CA_Loader' ) && defined('CARTFLOWS_CA_VER') && version_compare(CARTFLOWS_CA_VER, '1.2.25', '>=')) { | |
| 288 | + require_once NOTIFIER_PATH . 'includes/classes/integrations/class-notifier-wcar.php'; | |
| 289 | + Notifier_WCAR::init(); | |
| 319 | 290 | } |
| 320 | 291 | |
| 321 | - $file_args = array ( | |
| 322 | - 'file_length' => $file_size, | |
| 323 | - 'file_type' => get_post_mime_type($attachment_id) | |
| 324 | - ); | |
| 292 | + // Gravity Forms | |
| 293 | + if ( class_exists( 'GFCommon' ) ) { | |
| 294 | + require_once NOTIFIER_PATH . 'includes/classes/integrations/class-notifier-gravityforms.php'; | |
| 295 | + Notifier_GravityForms::init(); | |
| 296 | + } | |
| 325 | 297 | |
| 326 | - // $phone_number_id = get_option('notifier_phone_number_id'); | |
| 327 | - // $request_url = NOTIFIER_WA_API_URL . $phone_number_id . '/media'; | |
| 328 | - $permanent_access_token = get_option('notifier_permanent_access_token'); | |
| 298 | + // Contact Form 7 | |
| 299 | + if ( class_exists( 'WPCF7' ) ) { | |
| 300 | + require_once NOTIFIER_PATH . 'includes/classes/integrations/class-notifier-cf7.php'; | |
| 301 | + Notifier_ContactForm7::init(); | |
| 302 | + } | |
| 329 | 303 | |
| 330 | - // Create session ID for upload | |
| 331 | - $upload_session = self::wa_graph_api_request('app/uploads', $file_args); | |
| 332 | - if (!isset($upload_session->id)) { | |
| 333 | - error_log('Error creating WhatsApp image upload session: ' . $upload_session); | |
| 334 | - return false; | |
| 304 | + // WPForms | |
| 305 | + if ( class_exists( 'WPForms' ) ) { | |
| 306 | + require_once NOTIFIER_PATH . 'includes/classes/integrations/class-notifier-wpforms.php'; | |
| 307 | + Notifier_WPForms::init(); | |
| 335 | 308 | } |
| 336 | 309 | |
| 337 | - // Upload the file | |
| 338 | - $file = @fopen( $file_path, 'r' ); | |
| 339 | - $file_data = fread( $file, $file_size ); | |
| 310 | + // Ninja Forms | |
| 311 | + if ( class_exists( 'Ninja_Forms' ) ) { | |
| 312 | + require_once NOTIFIER_PATH . 'includes/classes/integrations/class-notifier-ninjaforms.php'; | |
| 313 | + Notifier_NinjaForms::init(); | |
| 314 | + } | |
| 340 | 315 | |
| 341 | - $upload_headers = array( | |
| 342 | - 'Authorization' => 'OAuth ' . $permanent_access_token, | |
| 343 | - 'file_offset' => 0, | |
| 344 | - 'Connection' => 'Close', | |
| 345 | - 'Host' => 'graph.facebook.com', | |
| 346 | - 'Content-Type' => 'multipart/form-data' | |
| 347 | - ); | |
| 316 | + //FrmForm | |
| 317 | + if ( class_exists( 'FrmForm' ) ) { | |
| 318 | + require_once NOTIFIER_PATH . 'includes/classes/integrations/class-notifier-formidable.php'; | |
| 319 | + Notifier_Formidable::init(); | |
| 320 | + } | |
| 348 | 321 | |
| 349 | - $upload_handle = self::wa_graph_api_request( $upload_session->id, $file_data, null, $upload_headers ); | |
| 350 | - | |
| 351 | - if (!isset($upload_handle->h)) { | |
| 352 | - error_log('Error while uploading profile image: ' . $upload_handle); | |
| 353 | - return false; | |
| 322 | + //WPFluentForm | |
| 323 | + if ( function_exists( 'fluentFormApi' ) ) { | |
| 324 | + require_once NOTIFIER_PATH . 'includes/classes/integrations/class-notifier-fluentforms.php'; | |
| 325 | + Notifier_FluentForms::init(); | |
| 354 | 326 | } |
| 355 | - | |
| 356 | - return $upload_handle->h; | |
| 357 | 327 | } |
| 358 | 328 | |
| 359 | 329 | /** |
| 360 | - * Remove query args from WP backend | |
| 330 | + * Is connection to WANotifier.com active? | |
| 361 | 331 | */ |
| 362 | - public static function remove_admin_query_args ($args) { | |
| 363 | - $remove_args = array('wa_import_count', 'wa_import_skipped', 'wa_contacts_import', 'import_contacts_from_users', 'refresh_status'); | |
| 364 | - return array_merge($args, $remove_args); | |
| 332 | + public static function is_api_active () { | |
| 333 | + $activated = get_option(NOTIFIER_PREFIX . 'api_activated'); | |
| 334 | + if('yes' == $activated) { | |
| 335 | + return true; | |
| 336 | + } | |
| 337 | + else{ | |
| 338 | + return false; | |
| 339 | + } | |
| 365 | 340 | } |
| 366 | 341 | |
| 367 | 342 | /** |
| 368 | - * Load Woocommerce class if it's present is activated | |
| 369 | - */ | |
| 370 | - public static function maybe_include_woocoomerce_class () { | |
| 371 | - if ( class_exists( 'WooCommerce' ) ) { | |
| 372 | - require_once NOTIFIER_PATH . 'includes/classes/class-notifier-woocommerce.php'; | |
| 373 | - Notifier_Woocommerce::init(); | |
| 374 | - } | |
| 343 | + * Create New db table-- wanotifier_activity_log | |
| 344 | + */ | |
| 345 | + public static function create_notifier_activity_log_table() { | |
| 346 | + global $wpdb; | |
| 347 | + $table_name = $wpdb->prefix . NOTIFIER_ACTIVITY_TABLE_NAME; | |
| 348 | + | |
| 349 | + $charset_collate = $wpdb->get_charset_collate(); | |
| 350 | + | |
| 351 | + // Include IF NOT EXISTS clause in the CREATE TABLE query | |
| 352 | + $sql = "CREATE TABLE IF NOT EXISTS $table_name ( | |
| 353 | + log_id bigint(20) unsigned NOT NULL AUTO_INCREMENT, | |
| 354 | + timestamp timestamp NOT NULL, | |
| 355 | + message text NOT NULL, | |
| 356 | + type varchar(16) NOT NULL, | |
| 357 | + PRIMARY KEY (log_id), | |
| 358 | + INDEX idx_timestamp (timestamp) | |
| 359 | + ) $charset_collate;"; | |
| 360 | + | |
| 361 | + require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); | |
| 362 | + dbDelta( $sql ); | |
| 363 | + | |
| 364 | + $notifier_plugin_data = get_option('notifier_meta', array()); | |
| 365 | + $notifier_plugin_data['activity_log_table'] = 'yes'; | |
| 366 | + update_option('notifier_meta', $notifier_plugin_data); | |
| 375 | 367 | } |
| 376 | 368 | |
| 377 | 369 | /** |
| 378 | - * Add admin html templates to footer | |
| 379 | - */ | |
| 380 | - public static function add_admin_html_templates () { | |
| 381 | - if (!self::is_notifier_page()) { | |
| 382 | - return; | |
| 383 | - } | |
| 384 | - | |
| 385 | - $templates = apply_filters('notifier_admin_html_templates', array()); | |
| 386 | - | |
| 387 | - if (count($templates) == 0) { | |
| 388 | - return; | |
| 389 | - } | |
| 390 | - | |
| 391 | - echo '<div class="notifier-templates">'; | |
| 392 | - foreach ($templates as $template) { | |
| 393 | - $file_path = NOTIFIER_PATH . '/views/templates/admin-' . $template . '.php'; | |
| 394 | - if ( ! file_exists($file_path) ) { | |
| 395 | - continue; | |
| 396 | - } | |
| 397 | - echo '<template id="notifier-template-' . esc_attr($template) . '">'; | |
| 398 | - require_once $file_path; | |
| 399 | - echo '</template>'; | |
| 400 | - } | |
| 401 | - echo '</div>'; | |
| 370 | + * Delete old log from activity table according to interval | |
| 371 | + */ | |
| 372 | + public function notifier_delete_old_activity_logs() { | |
| 373 | + global $wpdb; | |
| 374 | + $table_name = $wpdb->prefix . NOTIFIER_ACTIVITY_TABLE_NAME; | |
| 375 | + $retention_time = apply_filters( 'notifier_logs_retention_time', 7 ); | |
| 376 | + $retention_time = intval($retention_time); | |
| 377 | + $wpdb->query( $wpdb->prepare( "DELETE FROM `$table_name` WHERE timestamp <= DATE_SUB(NOW(), INTERVAL %d DAY)", $retention_time ) ); | |
| 402 | 378 | } |
| 403 | - | |
| 404 | 379 | } |