define defaults

This commit is contained in:
Tony Volpe
2024-09-17 15:52:13 +00:00
parent 8dd84d12e6
commit 2a354bae60
2 changed files with 64 additions and 114 deletions

View File

@@ -13,6 +13,9 @@ if(!class_exists('CampaignController')){
define("kPLUGIN_DIR_PATH", plugin_dir_path(__FILE__)); define("kPLUGIN_DIR_PATH", plugin_dir_path(__FILE__));
class CampaignController { class CampaignController {
const DEFAULT_PHONE_NUMBER = '800-800-2537';
const DEFAULT_CAMPAIGN_ID = '7011I000000dDwA';
const DEFAULT_FIVE9 = 'Web Form Submissions H';
const kREST_ACTION = "GetWebCampaigns"; const kREST_ACTION = "GetWebCampaigns";
const kCOOKIE_ID = "SESScampaignid"; const kCOOKIE_ID = "SESScampaignid";
@@ -24,10 +27,8 @@ if(!class_exists('CampaignController')){
protected static $instance; protected static $instance;
public function __construct() { public function __construct() {
// Start session
add_action('init', array($this, 'start_session'), 1); add_action('init', array($this, 'start_session'), 1);
// Other hooks
add_action('plugins_loaded', array($this, 'plugins_loaded')); add_action('plugins_loaded', array($this, 'plugins_loaded'));
add_action('admin_enqueue_scripts', array($this, 'load_campaign_script')); add_action('admin_enqueue_scripts', array($this, 'load_campaign_script'));
add_filter('option_cta_tel', array($this, 'check_campaign_active_tel')); add_filter('option_cta_tel', array($this, 'check_campaign_active_tel'));
@@ -36,12 +37,9 @@ if(!class_exists('CampaignController')){
add_shortcode('campaign_phone', array($this, 'check_campaign_active_tel')); add_shortcode('campaign_phone', array($this, 'check_campaign_active_tel'));
add_shortcode('campaign_id', array($this, 'getCampaignID')); add_shortcode('campaign_id', array($this, 'getCampaignID'));
add_shortcode('campaign_five9', array($this, 'getCampaignFive9')); add_shortcode('campaign_five9', array($this, 'getCampaignFive9'));
add_shortcode('campaign_special', array($this, 'getCampaignSO'));
// Hook to check UTM campaign
add_action('init', array($this, 'check_utm_campaign')); add_action('init', array($this, 'check_utm_campaign'));
// Load the custom post type
$cpt = new CptCampaign(); $cpt = new CptCampaign();
} }
@@ -52,7 +50,6 @@ if(!class_exists('CampaignController')){
return self::$instance; return self::$instance;
} }
// Start PHP session
public function start_session() { public function start_session() {
if (!session_id()) { if (!session_id()) {
session_start(); session_start();
@@ -63,7 +60,6 @@ if(!class_exists('CampaignController')){
// Reserved for future actions // Reserved for future actions
} }
// Check for UTM campaign and set cookies/sessions
public function check_utm_campaign() { public function check_utm_campaign() {
if (isset($_GET['utm_campaign'])) { if (isset($_GET['utm_campaign'])) {
$utm_campaign = sanitize_text_field($_GET['utm_campaign']); $utm_campaign = sanitize_text_field($_GET['utm_campaign']);
@@ -93,14 +89,12 @@ if(!class_exists('CampaignController')){
} }
} }
// Set session cookies
public function setCampaignCookies($id, $CampaignName, $phone) { public function setCampaignCookies($id, $CampaignName, $phone) {
setcookie(self::kCOOKIE_ID, $id, 0, '/'); setcookie(self::kCOOKIE_ID, $id, 0, '/');
setcookie(self::kCOOKIE_CAMPAIGN_NAME, $CampaignName, 0, '/'); setcookie(self::kCOOKIE_CAMPAIGN_NAME, $CampaignName, 0, '/');
setcookie(self::kCOOKIE_PHONE, $phone, 0, '/'); setcookie(self::kCOOKIE_PHONE, $phone, 0, '/');
} }
// Functions to check and retrieve active campaign phone
public function check_campaign_active_tel($phonenumber) { public function check_campaign_active_tel($phonenumber) {
if (!empty($_COOKIE[self::kCOOKIE_ID])) { if (!empty($_COOKIE[self::kCOOKIE_ID])) {
$campaign = $this->getActiveCampaignPhoneByID($_COOKIE[self::kCOOKIE_ID]); $campaign = $this->getActiveCampaignPhoneByID($_COOKIE[self::kCOOKIE_ID]);
@@ -114,7 +108,7 @@ if(!class_exists('CampaignController')){
return $campaign; return $campaign;
} }
} }
return $phonenumber; return self::DEFAULT_PHONE_NUMBER;
} }
public function check_campaign_active_ass_phone($phonenumber) { public function check_campaign_active_ass_phone($phonenumber) {
@@ -130,7 +124,7 @@ if(!class_exists('CampaignController')){
return $campaign; return $campaign;
} }
} }
return $phonenumber; return self::DEFAULT_PHONE_NUMBER;
} }
// Retrieve campaign-related information from cookies/sessions // Retrieve campaign-related information from cookies/sessions
@@ -141,7 +135,8 @@ if(!class_exists('CampaignController')){
if (!empty($_SESSION[self::kCOOKIE_ID])) { if (!empty($_SESSION[self::kCOOKIE_ID])) {
return $_SESSION[self::kCOOKIE_ID]; return $_SESSION[self::kCOOKIE_ID];
} }
return null; // Return the default campaign ID if no campaign ID is available
return self::DEFAULT_CAMPAIGN_ID;
} }
public static function getCampaignFive9() { public static function getCampaignFive9() {
@@ -151,7 +146,7 @@ if(!class_exists('CampaignController')){
if (!empty($_SESSION[self::kCOOKIE_ID_FIVE9])) { if (!empty($_SESSION[self::kCOOKIE_ID_FIVE9])) {
return $_SESSION[self::kCOOKIE_ID_FIVE9]; return $_SESSION[self::kCOOKIE_ID_FIVE9];
} }
return null; return self::DEFAULT_FIVE9;
} }
public static function getCampaignSO() { public static function getCampaignSO() {
@@ -332,7 +327,6 @@ if(!class_exists('CampaignController')){
} }
} }
// Enqueue admin scripts and styles
public function load_campaign_script($hook) { public function load_campaign_script($hook) {
if (('post.php' == $hook || 'post-new.php' == $hook) && get_post_type() == CptCampaign::POST_TYPE) { if (('post.php' == $hook || 'post-new.php' == $hook) && get_post_type() == CptCampaign::POST_TYPE) {
wp_enqueue_style('jquery-ui'); wp_enqueue_style('jquery-ui');
@@ -343,7 +337,6 @@ if(!class_exists('CampaignController')){
} }
} }
// Initialize the controller
if (class_exists('CampaignController')) { if (class_exists('CampaignController')) {
register_activation_hook(__FILE__, array('CampaignController', 'activate')); register_activation_hook(__FILE__, array('CampaignController', 'activate'));
CampaignController::instance(); CampaignController::instance();

View File

@@ -19,50 +19,6 @@ function googleapi(){
session_start(); session_start();
$utm_campaign = $_GET['promotion_id'];
if( have_rows('promotions', 'option') ) {
while( have_rows('promotions', 'option') ): the_row();
$date = date('Y-m-d');
$date = date('Y-m-d', strtotime($date));
$promo_id = get_sub_field('promotion_id');
$promotion_description = get_sub_field('promotion_description');
$promophone_number = get_sub_field('phone_number');
$promocoupon_code = get_sub_field('promocoupon_code');
$start_date = get_sub_field('start_date');
$end_date = get_sub_field('end_date');
$lldefault_descr = "Lifeline.com Default";
$lldefault_phone = "8556815351";
if ($utm_campaign === $promo_id) {
if (($date >= $start_date) && ($date <= $end_date)) :
setcookie('SESSpromoid', $promo_id, 0,'/');
setcookie('SESSpromotion_description', $promotion_description, 0,'/');
setcookie('SESSphone_number', $promophone_number, 0,'/');
setcookie('SESScoupon_code', $promocoupon_code , 0,'/');
//setcookie('SESSstart_date', $start_date , 0,'/');
//setcookie('SESSend_date', $end_date , 0,'/');
$_SESSION['SESSpromoid']=$promo_id;
$_SESSION['SESSpromotion_description']=$promotion_description;
$_SESSION['SESSphone_number']=$promophone_number;
$_SESSION['SESScoupon_code']=$promocoupon_code;
$_SESSION['SESSstart_date']=$start_date;
$_SESSION['SESSend_date']=$end_date;
endif;
}
endwhile;
}
if (!isset($_SESSION["SESSpromoid"])) {
setcookie('SESSpromoid', 'WEB_ORG_0001', 0,'/');
setcookie('SESSpromotion_description', $lldefault_descr, 0,'/');
setcookie('SESSphone_number', $lldefault_phone, 0,'/');
$_SESSION['SESSpromoid']="WEB_ORG_0001";
$_SESSION['SESSpromotion_description']=$lldefault_descr;
$_SESSION['SESSphone_number']=$lldefault_phone;
}
# Imports all Composer packages # Imports all Composer packages
require __DIR__ . '/vendor/autoload.php'; require __DIR__ . '/vendor/autoload.php';
@@ -994,6 +950,7 @@ function aarp_form_notfound()
global $aarp_member_notfound; global $aarp_member_notfound;
} }
/** /**
* Function get_phone * Function get_phone
* *
@@ -1003,8 +960,8 @@ function aarp_form_notfound()
function get_phone() function get_phone()
{ {
if (isset($_SESSION['SESSphone_number'])) { if (isset($_SESSION['SESScampaignphone'])) {
$num = $_SESSION["SESSphone_number"]; $num = $_SESSION["SESScampaignphone"];
$ufnum = preg_replace("/[^0-9]/", "", $num); $ufnum = preg_replace("/[^0-9]/", "", $num);
$fnum = substr($ufnum, 0, 3) . "-" . substr($ufnum, 3, 3) . "-" . substr($ufnum, 6); $fnum = substr($ufnum, 0, 3) . "-" . substr($ufnum, 3, 3) . "-" . substr($ufnum, 6);