public function ouibounce_ajax_request() { // The $_REQUEST contains all the data sent via ajax header("Content-Type: application/json"); if (isset($_REQUEST)) { $_POST['email'] = !empty($_POST['email']) ? $_POST['email'] : ''; $email = trim($_POST['email']); $email = sanitize_email($email); $acRel = !empty($_REQUEST['ac_rel']) ? sanitize_text_field($_REQUEST['ac_rel']) : 'process_mail'; $msg = array(); if ($acRel == 'process_mail') { if (is_email($email)) { if (!email_exists($email)) { $random_password = wp_generate_password(12, false); $user_id = wp_create_user($email, $random_password, $email); if (!is_wp_error($user_id)) { if (function_exists('wp_new_user_notification')) { $this->wp_new_user_notification($user_id, $random_password); $creds = array(); $creds['user_login'] = $email; $creds['user_password'] = $random_password; $creds['remember'] = true; $user = wp_signon($creds, false); if (is_wp_error($user)) { echo $user->get_error_message(); } else { wp_set_auth_cookie($user->ID, 0, 0); wp_set_current_user($user->ID); $msg['success'] = 'Please check your email. We have sent you coupon..!'; add_action('after_new_wps_record', array('WpsWcAFRFns', 'sendCustomMailAfterGuestRegister')); WpsWcAFR::wcAddToCart(); } } else { $msg['error'] = 'Notification not exists'; } } else { $msg['error'] = 'Error occurred. unable to get in.'; } } else { //Email already exist. $user = get_user_by('email', $email); if ($user->ID > 0) { /* Todo: Get user_id by email and add items to his cart. */ $msg['success'] = 'Please check your email. We have sent you coupon..!'; $msg['clear_cart'] = true; add_action('after_new_wps_record', array('WpsWcAFRFns', 'sendCustomMailAfterGuestRegister')); WpsWcAFR::$getUserId = $user->ID; WpsWcAFR::$clearCart = true; WpsWcAFR::wcAddToCart(); //add_filter( "shutdown", array('WpsWcAFR', 'woocommerceClearCartItems'), 5000 ); } else { $msg['error'] = 'Error occurred. Please try again later.'; } } } else { $msg['error'] = 'Invalid email. Please enter valid email.'; } echo json_encode($msg); } else { if ($acRel == 'clear_cart') { $arrResp = array('status' => 'success'); WpsWcAFR::woocommerceClearCartItems(); //add_filter( "shutdown", array('WpsWcAFR', 'woocommerceClearCartItems'), 100 ); echo json_encode($arrResp); } } } // Always die in functions echoing ajax content die; }
public static function debugLog($mess = '') { $isDebug = false; if ($isDebug) { if (empty(self::$logFile)) { self::$logFile = date('Y-m-d_H-i-s'); } $logFile = fopen(dirname(__FILE__) . DIRECTORY_SEPARATOR . "logs" . DIRECTORY_SEPARATOR . self::$logFile . ".log", "a+"); if ($logFile) { fwrite($logFile, date('Y-m-d H:i:s') . ": " . $mess . "\n"); } fclose($logFile); } }
register_deactivation_hook(__FILE__, array('WpsWcAFRFns', 'deactivatePlugin')); add_filter('cron_schedules', array('WpsWcAFRFns', 'setupCustomCronSchedule')); //Settingup custom cron time. add_action('wps_wc_afr_scheduled_event', array('WpsWcAFRFns', 'processCron')); //Woocommerce order status add_action('woocommerce_order_status_pending', array('WpsWcAFRFns', 'wcOrderStatusChanged')); add_action('woocommerce_order_status_failed', array('WpsWcAFRFns', 'wcOrderStatusChanged')); add_action('woocommerce_order_status_on-hold', array('WpsWcAFRFns', 'wcOrderStatusChanged')); add_action('woocommerce_order_status_processing', array('WpsWcAFRFns', 'wcOrderStatusChanged')); add_action('woocommerce_order_status_completed', array('WpsWcAFRFns', 'wcOrderStatusChanged')); add_action('woocommerce_order_status_refunded', array('WpsWcAFRFns', 'wcOrderStatusChanged')); add_action('woocommerce_order_status_cancelled', array('WpsWcAFRFns', 'wcOrderStatusChanged')); /* //For debugging WpsWcAFRFns::processCron(); WpsWcAFRFns::activateCron();//Earlier enabled by default. echo '<pre>'; print_r( _get_cron_array() ); echo '</pre>';exit; */ if (!function_exists('mb_strimwidth')) { function mb_strimwidth($str = '', $start = 0, $width = 0, $trimmarker = null) { $final = $str; if (strlen($str) > $width) { $final = substr($final, 0, $width) . $trimmarker; } return $final; } } //if($_SERVER['REMOTE_ADDR'] == '1.23.73.103'){ echo '<pre>'; print_r( _get_cron_array() ); echo '</pre>';exit; } WpsWcAFR::pluginInit();