Files
medicalalert-web-reloaded/wp/wp-content/themes/thbusiness/functions.php
2024-01-29 21:03:11 +00:00

2074 lines
73 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
/**
* thbusiness functions and definitions
*
* @package thbusiness
*
* medicalalert.com
*/
if ( ! function_exists( 'thbusiness_setup' ) ) :
/**
* Sets up theme defaults and registers support for various WordPress features.
*
* Note that this function is hooked into the after_setup_theme hook, which
* runs before the init hook. The init hook is too late for some features, such
* as indicating support for post thumbnails.
*/
function thbusiness_setup() {
/*
* Make theme available for translation.
* Translations can be filed in the /languages/ directory.
* If you're building a theme based on thbusiness, use a find and replace
* to change 'thbusiness' to the name of your theme in all the template files
*/
load_theme_textdomain( 'thbusiness', get_template_directory() . '/languages' );
// Add default posts and comments RSS feed links to head.
add_theme_support( 'automatic-feed-links' );
/*
* Enable support for Post Thumbnails on posts and pages.
*
* @link http://codex.wordpress.org/Function_Reference/add_theme_support#Post_Thumbnails
*/
add_theme_support( 'post-thumbnails' );
// ThBusiness Image Sizes
add_image_size( 'featured', 345, 259, true );
add_image_size( 'featured-large', 677, 400, true );
// This theme uses wp_nav_menu() in one location.
register_nav_menus( array(
'primary' => __( 'Primary Menu', 'thbusiness' ),
'mobile' => __( 'Mobile Menu' )
) );
// Enable support for Post Formats.
//add_theme_support( 'post-formats', array( 'aside', 'image', 'video', 'quote', 'link' ) );
// Setup the WordPress core custom background feature.
add_theme_support( 'custom-background', apply_filters( 'thbusiness_custom_background_args', array(
'default-color' => 'ffffff',
'default-image' => '',
) ) );
// Enable support for HTML5 markup.
add_theme_support( 'html5', array(
'comment-list',
'search-form',
'comment-form',
'gallery',
'caption',
) );
/**
* Set the content width based on the theme's design and stylesheet.
*/
global $content_width;
if ( ! isset( $content_width ) ) {
$content_width = 677; /* pixels */
}
}
endif; // thbusiness_setup
add_action( 'after_setup_theme', 'thbusiness_setup' );
/**
* Register widget area.
*
* @link http://codex.wordpress.org/Function_Reference/register_sidebar
*/
function thbusiness_widgets_init() {
register_sidebar( array(
'name' => __( 'Main Sidebar', 'thbusiness' ),
'id' => 'thbusiness-main-sidebar',
'description' => '',
'before_widget' => '<aside id="%1$s" class="widget %2$s">',
'after_widget' => '</aside>',
'before_title' => '<h1 class="widget-title">',
'after_title' => '</h1>',
) );
register_sidebar( array(
'name' => __( 'Business Template Top Area', 'thbusiness' ),
'id' => 'thbusiness-business-top-sidebar',
'description' => 'Shows the widgets on the top area of the business page.',
'before_widget' => '<aside id="%1$s" class="widget %2$s">',
'after_widget' => '</aside>',
'before_title' => '<h1 class="business-page-widget-title">',
'after_title' => '</h1>',
) );
register_sidebar( array(
'name' => __( 'Business Template Left Area', 'thbusiness' ),
'id' => 'thbusiness-business-left-sidebar',
'description' => 'Shows the widgets on the left area of the business page.',
'before_widget' => '<aside id="%1$s" class="widget %2$s">',
'after_widget' => '</aside>',
'before_title' => '<h1 class="business-page-widget-title">',
'after_title' => '</h1>',
) );
register_sidebar( array(
'name' => __( 'Business Template Right Area', 'thbusiness' ),
'id' => 'thbusiness-business-right-sidebar',
'description' => 'Shows the widgets on the right area of the business page.',
'before_widget' => '<aside id="%1$s" class="widget %2$s">',
'after_widget' => '</aside>',
'before_title' => '<h1 class="business-page-widget-title">',
'after_title' => '</h1>',
) );
register_sidebar( array(
'name' => __( 'Business Template Bottom Area', 'thbusiness' ),
'id' => 'thbusiness-business-bottom-sidebar',
'description' => 'Shows the widgets on the bottom area of the business page.',
'before_widget' => '<aside id="%1$s" class="widget %2$s">',
'after_widget' => '</aside>',
'before_title' => '<h1 class="business-page-widget-title">',
'after_title' => '</h1>',
) );
register_sidebar( array(
'name' => __( 'Footer Left Sidebar', 'thbusiness' ),
'id' => 'footer-left',
'description' => '',
'before_widget' => '<aside id="%1$s" class="widget %2$s">',
'after_widget' => '</aside>',
'before_title' => '<h1 class="footer-widget-title">',
'after_title' => '</h1>',
) );
register_sidebar( array(
'name' => __( 'Footer Mid Sidebar', 'thbusiness' ),
'id' => 'footer-mid',
'description' => '',
'before_widget' => '<aside id="%1$s" class="widget %2$s">',
'after_widget' => '</aside>',
'before_title' => '<h1 class="footer-widget-title">',
'after_title' => '</h1>',
) );
register_sidebar( array(
'name' => __( 'Footer Right Sidebar', 'thbusiness' ),
'id' => 'footer-right',
'description' => '',
'before_widget' => '<aside id="%1$s" class="widget %2$s">',
'after_widget' => '</aside>',
'before_title' => '<h1 class="footer-widget-title">',
'after_title' => '</h1>',
) );
//BLOG TEMPLATE EDITS
register_sidebar( array(
'name' => __( 'Footer Blog Sidebar', 'thbusiness' ),
'id' => 'footer-blog',
'description' => '',
'before_widget' => '<aside id="%1$s" class="widget %2$s">',
'after_widget' => '</aside>',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
) );
//BLOG TEMPLATE EDIT ENDS
}
add_action( 'widgets_init', 'thbusiness_widgets_init' );
/**
* Enqueue scripts and styles.
*/
function thbusiness_scripts() {
wp_enqueue_script( 'jquery', get_template_directory_uri() . 'js/jquery-3.5.1.min.js', array(), false, true );
wp_enqueue_script('popper', 'https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js', array('jquery'), '', true);
wp_enqueue_script( 'subid', get_template_directory_uri() . '/js/subid.js');
wp_enqueue_style( 'font-awesome', get_template_directory_uri() . '/css/font-awesome.min.css', array(), '4.1.0' );
wp_enqueue_style( 'bootstrap.css', get_template_directory_uri() . '/css/bootstrap.min.css', array(), 'all' );
wp_enqueue_style( 'thbusiness-style', get_stylesheet_uri(), array(), medical_version(), 'all' );
wp_enqueue_script( 'thbusiness-navigation', get_template_directory_uri() . '/js/navigation.js', array(), '20120206', true );
wp_enqueue_script('bootstrap-js', get_template_directory_uri() . '/js/bootstrap.min.js',array( 'jquery' ),'', true );
wp_enqueue_script( 'thbusiness-scripts', get_template_directory_uri() . '/js/scripts.js', array( 'jquery' ) );
$thbusiness_user_agent = strtolower($_SERVER['HTTP_USER_AGENT']);
if(preg_match('/(?i)msie [1-8]/',$thbusiness_user_agent)) {
wp_enqueue_script( 'html5shiv', get_template_directory_uri() . '/js/html5shiv.js', true );
}
wp_enqueue_script( 'yotpo', get_template_directory_uri() . '/js/yotpo.js' );
wp_enqueue_script( 'respond', get_template_directory_uri() . '/js/respond.min.js' );
wp_enqueue_script( 'thbusiness-skip-link-focus-fix', get_template_directory_uri() . '/js/skip-link-focus-fix.js', array(), '20130115', true );
if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
wp_enqueue_script( 'comment-reply' );
}
}
add_action( 'wp_enqueue_scripts', 'thbusiness_scripts' );
/*Owl Carousel for the blog*/
add_action( 'wp_enqueue_scripts', 'owl_carousel_script');
function owl_carousel_script(){
wp_enqueue_script('owl.carousel', get_template_directory_uri() . '/js/owl.carousel.min.js', array(), '1.0.0', true );
wp_enqueue_script('settings', get_template_directory_uri() . '/js/settings.js', array(), '1.0.0', true );
}
function owl_carousel_styles() {
wp_register_style('owl-carousel', get_template_directory_uri() .'/css/owl.carousel.css', array(), null, 'all' );
wp_enqueue_style( 'owl-carousel' );
}
add_action( 'wp_enqueue_scripts', 'owl_carousel_styles' );
/*Owl Carousel for the blog ends*/
//Enqueue Cleave.js
function enqueue_cleave(){
wp_enqueue_script('cleave', get_stylesheet_directory_uri().'/js/cleave.min.js');
}
add_action('wp_enqueue_scripts', 'enqueue_cleave');
add_action('wp_footer', 'activate_cleave');
function activate_cleave(){
?>
<script type="text/javascript">
document.addEventListener('DOMContentLoaded', () => {
if (jQuery('#phone').length) {
var phone = new Cleave('#phone', {
numericOnly: true,
blocks: [3, 3, 4],
delimiters: ['-']
});
}
});
</script>
<?php
}
/**
* This function contains all the custom styles that will be loaded in the Theme Header.
*/
function thbusiness_initialize_header() {
$style = of_get_option('thbusiness_customcss');
if ( $style != '' ) {
echo '<style type="text/css">';
echo $style;
echo '</style>';
}
}
add_action('wp_head', 'thbusiness_initialize_header');
/**
* Enqueue thbusiness options panel custom css.
*/
function thbusiness_option_panel_style() {
wp_enqueue_style( 'admin_css', get_template_directory_uri() . '/inc/admin/admin.css', false );
}
add_action( 'admin_enqueue_scripts', 'thbusiness_option_panel_style' );
/**
* Load Google Fonts
*/
function thbusiness_load_fonts() {
wp_register_style('googleWebFonts', 'https://fonts.googleapis.com/css?family=Open+Sans:400,600,300,700)');
wp_enqueue_style('googleWebFonts');
}
add_action('wp_print_styles', 'thbusiness_load_fonts');
/**
* Add flex slider.
*/
function thbusiness_flex_scripts() {
wp_enqueue_script( 'flexslider', get_template_directory_uri() . '/js/jquery.flexslider-min.js', array('jquery'), false, true );
wp_register_script( 'add-thbusiness-flex-js', get_template_directory_uri() . '/js/thbusiness.flexslider.js', array(), '', true );
wp_enqueue_script( 'add-thbusiness-flex-js' );
wp_register_style( 'add-flex-css', get_template_directory_uri() . '/css/flexslider.css','','', 'screen' );
wp_enqueue_style( 'add-flex-css' );
}
add_action( 'wp_enqueue_scripts', 'thbusiness_flex_scripts' );
/**
* Activate a favicon for the website.
*/
function thbusiness_favicon() {
if ( of_get_option( 'thbusiness_activate_favicon', '0' ) == '1' ) {
$thbusiness_favicon = of_get_option( 'thbusiness_favicon', '' );
$thbusiness_favicon_output = '';
if ( !empty( $thbusiness_favicon ) ) {
$thbusiness_favicon_output .= '<link rel="shortcut icon" href="'.esc_url( $thbusiness_favicon ).'" type="image/x-icon" />';
}
echo $thbusiness_favicon_output;
}
}
add_action( 'admin_head', 'thbusiness_favicon' );
add_action( 'wp_head', 'thbusiness_favicon' );
/**
* Implement the Custom Header feature.
*/
require get_template_directory() . '/inc/custom-header.php';
/**
* Custom template tags for this theme.
*/
require get_template_directory() . '/inc/template-tags.php';
/**
* Custom functions that act independently of the theme templates.
*/
require get_template_directory() . '/inc/extras.php';
/**
* Customizer additions.
*/
require get_template_directory() . '/inc/customizer.php';
/**
* Load Jetpack compatibility file.
*/
require get_template_directory() . '/inc/jetpack.php';
/**
* Load Custom widgets.
*/
require get_template_directory() . '/inc/widgets.php';
/**
* Load GTM Settings
*/
require_once get_template_directory() . ('/inc/gtm_settings.php');
/**
* Google Optimize page-hiding snippet
*/
//require_once get_template_directory() . ('/inc/AsyncHide.php');
/**
* Setup Theme Options Panel to THBusiness Theme.
*/
if ( !function_exists( 'optionsframework_init' ) ) {
define( 'OPTIONS_FRAMEWORK_DIRECTORY', get_template_directory_uri() . '/inc/admin/options/' );
require_once dirname( __FILE__ ) . '/inc/admin/options/options-framework.php';
}
add_action( 'template_redirect', 'medicalalert_redirects' );
function medicalalert_redirects() {
if (is_page('taking-care-of-aging-parents')) {
wp_redirect( '/mobile-app' );
exit;
}
}
/**
* Shortcode version
*/
add_shortcode('mversion', 'medical_version');
function medical_version(){
$mversion = get_option('id_version','');
return $mversion;
}
//add_action('template_redirect','remove_wpseo');
/**
* Disable Yoast on Medical Select Product page
*/
function remove_wpseo(){
if (is_page(1430)) {
global $wpseo_front;
if(defined($wpseo_front)){
remove_action('wp_head',array($wpseo_front,'head'),1);
}
else {
$wp_thing = WPSEO_Frontend::get_instance();
remove_action('wp_head',array($wp_thing,'head'),1);
}
}
}
/**
* Disable This site is optimized with the Yoast SEO
*/
add_action( 'template_redirect', function () {
if ( ! class_exists( 'WPSEO_Frontend' ) ) {
return;
}
$instance = WPSEO_Frontend::get_instance();
if ( ! method_exists( $instance, 'debug_mark') ) {
return ;
}
remove_action( 'wpseo_head', array( $instance, 'debug_mark' ), 2 );
}, 9999 );
/**
* Add excerpts for pages.
*/
add_action('init', 'thbusiness_excerpt_support');
function thbusiness_excerpt_support() {
add_post_type_support( 'page', 'excerpt' );
}
add_filter( 'wpcf7_form_elements', 'mycustom_wpcf7_form_elements' );
function mycustom_wpcf7_form_elements( $form ) {
$form = do_shortcode( $form );
return $form;
}
/**
* Shortcode for Watch Cheryls Story
*/
add_shortcode('promovideo', 'promoVideo');
function promoVideo() {
$promo_video .= '
<div class="container">
<div class="row">
<div class="col-md-12">
<h2 style="text-align: center;">Watch Cheryls Story</h2>
<div class="embed-responsive embed-responsive-16by9">
<iframe width="560" height="315" src="https://www.youtube.com/embed/iTpkzdJVRO0?rel=0" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe>
</div>
</div></div></div>
';
return $promo_video;
global $promo_video;
}
/**
* Shortcode for Trust Badge Content Block
*/
add_shortcode('trustbadge', 'trustBadge');
function trustBadge (){
$trust_badge .= '
<div class="container-fluid">
<div class="container four-widgets trust-badge">
<div class="row">
<div class="col-md-3 trustmob">
<div><img src="/wp-content/themes/thbusiness/images/Consumers-Advocate.jpg" alt="In Home Safety Guide"></div>
<div><img src="/wp-content/themes/thbusiness/images/Rating-stars.png"></div>
</div>
<div class="col-md-3 trustmob">
<img src="/wp-content/themes/thbusiness/images/In-Home-Safety-Guide.jpg" alt="Consumers Advocate">
<div><img src="/wp-content/themes/thbusiness/images/Rating-stars.png"></div>
</div>
<div class="col-md-3 trustmob">
<img src="/wp-content/themes/thbusiness/images/Medical-Alert-Buyers-Guide.jpg" alt="Best Company">
<div><img src="/wp-content/themes/thbusiness/images/Rating-stars.png"></div>
</div>
<div class="col-md-3 trustmob">
<img src="/wp-content/themes/thbusiness/images/Top10.jpg" alt="Top 10">
<div><img src="/wp-content/themes/thbusiness/images/Rating-stars.png"></div>
</div>
</div>
</div>
</div>
';
return $trust_badge;
global $trust_badge;
}
/**
* Shortcode for Feature Icons Content Block MAW-348
*/
add_shortcode('featuredicons', 'featuredIcons');
function featuredIcons (){
$featured_icons .= '
<div class="container-fluid">
<div class="container four-widgets featuredicons">
<div class="row">
<div class="col-md-3" style="text-align:center">
<p><a href="how-medical-alert-works"><img src="/wp-content/themes/thbusiness/images/icon_1_247.png" alt="24 Hours"></a></p>
<p class="feature-hdr"><strong>24/7 Response &amp;
Support Center</strong></p>
<p class="feature-copy">We&#39;re not just an emergency response system, we&#39;re a support network available at all times.</p>
</div>
<div class="col-md-3" style="text-align:center">
<p><a href="how-medical-alert-works"><img src="/wp-content/themes/thbusiness/images/icon_1_stayonline.png" alt="Reliable Support"></a></p>
<p class="feature-hdr"><strong>We Can Stay on the<br>Line Until Help Arrives</strong></p>
<p class="feature-copy">No matter where you live, a U.S. based operator can remain on the phone with you until help arrives.</p>
</div>
<!-- Add the extra clearfix for only the required viewport -->
<div class="clearfix visible-xs"></div>
<div class="col-md-3" style="text-align:center">
<p><a href="how-medical-alert-works"><img src="/wp-content/themes/thbusiness/images/icon_1_easysetup.png" alt="Easy Setup"></a></p>
<p class="feature-hdr"><strong>Easy to Use<br>Easy to Set Up</strong></p>
<p class="feature-copy">Plug in the base unit to a power outlet. Then simply push the button to call for help.</p>
</div>
<div class="col-md-3" style="text-align:center">
<p><a href="medical-select-product"><img src="/wp-content/themes/thbusiness/images/icon_1_monthlyprice.png" alt="No Hassles"></a></p>
<p class="feature-hdr"><strong>One Monthly Price<br>
No Hassles</strong></p>
<p class="feature-copy">Basic monitoring equipment at no cost, no hidden fees, no activation charges and no long-term commitment required.</p>
</div>
</div>
<div class="row">
<p style="text-align:center"><a href="medical-select-product" class="learn-more">Learn More</a></p>
</div>
</div>
</div>
';
return $featured_icons;
global $featured_icons;
}
/**
* Shortcode for How it works Content Block MAW-349
*/
add_shortcode('howitworks', 'howitWorks');
function howitWorks (){
$how_it_works .= '
<div class="container">
<h2 class="page-header-callout" style="text-align: center;font-weight: 700; margin:40px 2em; line-height:32px;">Get the Help You Need in Three Simple Steps</h2>
<div id="steps" class="row"><img class="line" src="../wp-content/themes/thbusiness/images/line.png" alt="Image Border" width="492" height="5" />
<div class="col-md-4 step-columns">
<img src="/wp-content/themes/thbusiness/images/icon_2_push.png" alt="Push Your Medical Alert Button"/>
<p class="feature-hdr"><strong>Push your button.</strong></p>
<p>Press your Medical Alert button and youll be connected immediately to one of our operators.</p>
</div>
<div class="col-md-4 step-columns">
<img src="/wp-content/themes/thbusiness/images/icon_2_talk.png" alt="Connect with the Two-Way Voice System" />
<p class="feature-hdr"><strong>Talk to us.</strong></p>
<p>Our dedicated, supportive operator determines the exact help you need.</p>
</div>
<div class="col-md-4 step-columns">
<img src="/wp-content/themes/thbusiness/images/icon-2-help.png" alt="Medical Assistance will be Dispatched" />
<p class="feature-hdr"><strong>Get help—fast.</strong></p>
Our operator will make sure you get the aid you need and even stay in communication until help arrives.
</div>
</div>
</div>
';
return $how_it_works;
global $how_it_works;
}
/**
* Shortcode for Yotpo reviews on Landing pageas
*/
add_shortcode('yl', 'yotpoReviewsLanding');
function yotpoReviewsLanding (){
$yotpolanding .= '<div class="yotpo yotpo-reviews-carousel" data-header-customisation-enabled="1" data-header-customisation-color="#56575f" data-header-customisation-font-size="18" data-header-customisation-text=""
data-header-customisation-alignment="left" data-background-color="transparent" data-mode="most_recent" data-type="site" data-count="9" data-show-bottomline="1" data-autoplay-enabled="1" ata-autoplay-speed="4500" data-show-navigation="1">&nbsp;</div>';
return $yotpolanding;
global $yotpolanding;
}
/**
* Shortcode for Yotpo reviews on Home Page widget
*/
add_shortcode('yh', 'yotpoReviewsHome');
function yotpoReviewsHome (){
$yotpohome .= '<div class="yotpo yotpo-shoppers-say">&nbsp;</div>';
return $yotpohome;
global $yotpohome;
}
/**
* Shortcode for countdown on landing pages
* Saves from editing each page to add/remove countdown id and image
*/
add_shortcode('lpc', 'Extras_Countdown');
/**
* Shortcode for images on landing pages
* Saves from editing each page to update image
*/
add_shortcode('LandingHero', 'Landing_Page_Hero_Desktop');
function Landing_Page_Hero_Desktop(){
$lphero = of_get_option('thbusiness_slider_image1','');
$lpmob = of_get_option('thbusiness_mobilehero_image1','');
$lpHero .= '<img alt="New & Exclusive Mobile Elite - Free Shipping & Free Lockbox" src="'. $lphero.'" class="site-hero" draggable="false"><img alt="Free Shipping & Free Lockbox" src="'. $lpmob.'" class="mobile-hero" draggable="false">';
return $lpHero;
global $lpHero;
}
/**
* Shortcode for button
* Saves from editing each page to update overlays
*/
add_shortcode('HeroButton', 'Landing_Page_Hero_Button');
function Landing_Page_Hero_Button(){
$lpButton = '<div class="th-slider-readmore-button"><a href="/medical-select-product" title="Mobile Medical Alert System" style="display: inline-block;margin: auto;color: #FFF;background: #4c9d08;
box-shadow: inset 0 0px 5px 0px rgba(109, 189, 49, 0.4), inset 0 0 0 3px rgba(70,146,11,.4), inset 10px 10px 0 20px rgba(25, 49, 5, 0.05), 0 3px 6px 2px rgba(60, 61, 62, 0.4), 0 0 0 0px rgba(60, 61, 62,.4), 3px 2px 0 0px rgba(60, 61, 62, 0.07) !important;padding: 3px 14px 4px 14px;-webkit-border-radius: 6px 6px 6px 6px;border-radius: 9px 9px 9px 9px;font-weight: 900;text-transform: uppercase;letter-spacing: -.5px;bottom: 19%; left: 50%;font-size: 19px;">Order Now</a></div>';
return $lpButton;
global $lpButton;
}
/**
* Shortcode for disclaimer text
* Saves from editing each page to update disclaimers
*/
add_shortcode('lpdisclaimer', 'Landing_Page_Disclaimer');
function Landing_Page_Disclaimer(){
$lpdisclaimer = '<div class="container">
<p style="font-size:10px; color: #666; margin-top:20px; padding-top:12px;" class="lp-hide">
*For new customers only. Protection plan covers a one (1) time replacement of your main system and up to two (2) buttons due to loss or damage during any 12-month period. Fall detection requires additional fees. Customers will be charged a regular monthly fee after promotional period.
<br>&dagger;Fall Detection does not detect 100% of all falls. Users should always push their button when they need help.
</p></div>';
return $lpdisclaimer;
global $lpdisclaimer;
}
/**
* Shortcode for disclaimer text
* Saves from editing each page to update disclaimers
*/
add_shortcode('homedisclaimer', 'Home_Disclaimer');
function Home_Disclaimer(){
$homedisclaimer = '<p style="font-size:10px; color: #666; margin-top:20px; padding-top:12px; border-top: 1px dotted #666;" class="lp-hide">
*Disclaimer:<br>
Promotions available for new customers only. Customers will be charged the regular monthly fee after the promotional period ends. The promotional period is defined as the first billing cycle after the initial payment. Additional fees may apply for added features. Prices may vary outside the U.S.<br>
Free month, free shipping and free lockbox offer available only on annual plans.<br>
Protection plan covers a one (1) time replacement of your main system and up to two (2) buttons due to loss or damage during any 12-month period.<br>
Fall Detection does not detect 100% of all falls. Users should always push their button when they need help.<br>
Pendant coverage is subject to device location, environment, equipment and facility conditions.
</p>';
return $homedisclaimer;
global $homedisclaimer;
}
/**
* Shortcode for countdown on widgets template
*
*/
add_shortcode('extras', 'Extras_Countdown');
$days_from_eom = $wpdb->get_var( 'SELECT `option_value` FROM `wp_xygy_options` WHERE `option_name` = "days_from_eom"' );
function Extras_Countdown(){
global $days_from_eom;
global $finaldate;
$today = date('Y-m-d');
$endday = date("Y-m-t", strtotime($today));
$finaldate = -$days_from_eom;
$startday = date( 'Y-m-d', strtotime( $endday . $finaldate . 'days' ) );
if (($today >= $startday) && ($today <= $endday)) {
$extras = '<div id="countdown"><img src="../wp-content/themes/thbusiness/images/hurry.png" alt="Hurry! Offer Ends Soon!"><div id="defaultCountdown"></div></div>';
//$lpc = '<div id="countdown"><img src="/wp-content/themes/thbusiness/images/hurry.png" alt="Hurry! Offer Ends Soon!"><div id="defaultCountdown"></div></div>';
$lpc = '';
return $lpc;
global $lpc;
return $extras;
global $extras;
} else {
$extras = '';
return $lpc;
global $lpc;
return $extras;
global $extras;
}
}
/**
* Shortcode for images on landing pages
* Saves from editing each page to update image
*/
add_shortcode('mas', 'mas_html');
function mas_html(){
$mashtml .= '
<div class="container">
<div class="row">
<div class="entry-content">
<h2 class="page-header-callout">Medical Alert Systems</h2>
<p>Order your Medical Alert system today! Keep your independence and get peace of mind knowing that youre protected at home 24/7 and on the go with our GPS-enabled mobile Medical Alert options. Have a question? Call us at <a href="tel:'.get_phone().'" id="number_link" style="color:#0B2265;"><span class="google-number">' . get_phone() . ' </span></a> and well help you choose a Medical Alert system thats perfect for you! </p>
<div id="buy-now" style="margin:10px auto 10px auto; ">
<div class="containter">
<div class="row">
<div class="col-md-6">
<div class="prod-column home-alert">
<p class="home-callout">Home System</p>
<p class="sub-callout">Our Most Affordable System</p>
<hr>
<h2 style="font-size:18px; padding-top:12px; padding-bottom:12px;"><span><img src="/wp-content/uploads/2020/09/At-Home-355x270-1.png" alt="In Home Medical Alert"> </span></h2>
<p class="prod-features">24/7/365 Continuous Monitoring</p>
<p class="prod-features">Button can be worn in shower or bath</p>
<p class="prod-features">Base Station with Two-way Speaker</p>
<p class="prod-features prod-last">Up to 36-hour Back-up Battery</p>
<a title="Home System" class="btn home-button" href="/home-system/">Select</a>
</div>
</div>
<div class="col-md-6">
<div class="prod-column anywhere">
<p class="anywhere-callout">Mobile System</p>
<p class="sub-callout">Our Most Flexible System</p>
<hr>
<h2 style="font-size:18px; padding-top:12px; padding-bottom:12px;"><span><img src="/wp-content/uploads/2020/09/On-the-Go-Extra-Button-355x270-1.png" alt="Medical Alert with GPS"></span></h2>
<p class="prod-features">24/7/365 Continuous Monitoring</p>
<p class="prod-features">Button can be worn in shower or bath</p>
<p class="prod-features">Battery Life Up to 5 Days</p>
<p class="prod-features">No Landline Phone Required</p>
<p class="prod-features">AT&amp;T Network</p>
<p class="prod-features">GPS with Location-based Services</p>
<p class="prod-features prod-last">Interchangeable Pendant & Bracelet</p>
<a title="Mobile System" class="btn anywhere-button" href="/product/mobile-system">Select</a>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
';
return $mashtml;
global $mashtml;
}
//add URLparam echo to any page
function URLParam( $atts ) {
extract( shortcode_atts( array(
'param' => 'param',
), $atts ) );
return $_GET[$param];
}
add_shortcode('URLParam', 'URLParam');
/**
* Get Query String
*/
add_action( 'wp_footer', 'getQS' );
function getQS() {
?>
<script type="text/javascript">
function getQuerystring(key, default_)
{
if (default_==null) default_="";
key = key.replace(/[\\[]/,"\\\\\\[").replace(/[\\]]/,"\\\\\\]");
var regex = new RegExp("[\\\\?&]"+key+"=([^&#]*)");
var qs = regex.exec(window.location.href);
if(qs == null)
return default_;
else
return qs[1];
}
var cid_val = getQuerystring('cid');
</script>
<?php
}
// Global JavaScript Variables
add_action ( 'wp_head', 'jsVariables' );
function jsVariables(){
global $CountdownDate;
global $days_from_eom;
global $finaldate;
?>
<script type="text/javascript">
var d = new Date();
var y = new Date(d.getFullYear());
var fdate = parseInt('<?php echo $days_from_eom ;?>')*-1;
var startdate = new Date(d.getFullYear(), d.getMonth()+1, fdate);
var enddate = new Date(d.getFullYear(), d.getMonth()+1,1);
</script>
<script>
jQuery(document).ready(function(){
jQuery(".pa-blog-module article").each(function(){
jQuery(this).children('h2,p,div').not(':first-child').wrapAll('<div class="wrap"></div>');
})
})
</script>
<?php
}
/**
* Countdown Function
*/
function countdown(){
if (is_front_page() == true) {
?>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="<?php echo esc_url( home_url( '/' ) ); ?>wp-content/themes/thbusiness/js/jquery.plugin.min.js"></script>
<script src="<?php echo esc_url( home_url( '/' ) ); ?>wp-content/themes/thbusiness/js/jquery.countdown.js"></script>
<script>
$(function () {
if(new Date() >= new Date(startdate) && new Date() <= new Date(enddate)) {
$('#defaultCountdown').countdown({until: enddate});
$('#year').text(y);
}
});
</script>
<?php
}
}
//add_action( 'wp_head', 'countdown', 2 );
//add_action( 'wp_head', 'AsyncHide', 2 );
add_action( 'wp_head', 'subid', 2);
/**
* Set cookie based on query string
*/
function setQsCookie() {
foreach($_GET as $key => $value) {
if (strpos($key,'subid') !== false || strpos($key,'cid') !== false) {
setcookie($key, $value, 0,'/');
}
}
}
add_action( 'init', 'setQsCookie');
// GTM
add_action( 'wp_head', 'gtm_output', 2 );
add_action( 'wp_footer', 'gtm_datalayer_init', 10 );
add_action( 'wp_footer', 'gtm_noscript_output', 2 );
//[op] outputs the phone number
function our_phone() {
return get_option('cta_tel',true);
}
/**
* Function get_phone
*
* Get phone number from database, campaigns and google forwarding numbers
*
*/
function get_phone() {
$thbusiness_num = get_option('cta_tel',true);
$thbusiness_ufnum = preg_replace("/[^0-9]/", "", $thbusiness_num);
$thbusiness_fnum= substr($thbusiness_ufnum,0,3)."-".substr($thbusiness_ufnum,3,3)."-".substr($thbusiness_ufnum,6);
if(isset($_COOKIE['SESSabtest']) && $_COOKIE['SESSabtest']== "1" ) {
$thbusiness_num = $_COOKIE["SESScontrolphone"];
$thbusiness_ufnum = preg_replace("/[^0-9]/", "", $thbusiness_num);
$thbusiness_fnum= substr($thbusiness_ufnum,0,3)."-".substr($thbusiness_ufnum,3,3)."-".substr($thbusiness_ufnum,6);
return $thbusiness_fnum;
global $thbusiness_fnum;
} elseif (isset($_COOKIE['SESScampaignphone'])) {
$thbusiness_num = $_COOKIE["SESScampaignphone"];
$thbusiness_ufnum = preg_replace("/[^0-9]/", "", $thbusiness_num);
$thbusiness_fnum= substr($thbusiness_ufnum,0,3)."-".substr($thbusiness_ufnum,3,3)."-".substr($thbusiness_ufnum,6);
return $thbusiness_fnum;
global $thbusiness_fnum;
} else {
return $thbusiness_fnum;
global $thbusiness_fnum;
}
}
add_shortcode('op', 'get_phone');
//adding my_campaign_id shortcode to cf7
add_action( 'wpcf7_init', 'custom_add_shortcode_campaign_id' );
function custom_add_shortcode_campaign_id() {
wpcf7_add_shortcode( 'my_campaign_id', 'custom_campaign_shortcode_handler' ); // "clock" is the type of the form-tag
}
function custom_campaign_shortcode_handler( $tag ) {
return "campaign_id:12345";
//return IperCampaignController::getCampaignID();
}
// five9 list shortcode to cf7
add_action( 'wpcf7_init', 'custom_add_shortcode_five9' );
function custom_add_shortcode_five9() {
wpcf7_add_shortcode( 'Five9Callback', 'custom_five9_shortcode_handler' );
}
function custom_five9_shortcode_handler( $tag ) {
return "campaign_five9";
//return IperCampaignController::getCampaignID();
}
add_action( 'wpcf7_before_send_mail', 'postSalesforce');
add_action( 'wpcf7_before_send_mail', 'postFiveNine');
/**
* Function postSalesforce
* Send the form data to Salesforce so that the lead is created
*/
$salesforceEnvironment = get_option('select-environment');
if ($salesforceEnvironment == 'development') {
update_option( 'default_campaign', '7011I000000dF9n');
update_option( 'sfdc_oid', '00D0n00000010Vh' );
update_option( 'webtolead_url', 'https://test.salesforce.com/servlet/servlet.WebToLead' );
$Campaign_ID = get_option('default_campaign');
$sfdc_oid = get_option('sfdc_oid');
$webtolead_url = get_option('webtolead_url');
} elseif ($salesforceEnvironment == 'staging') {
update_option( 'default_campaign', '7011I000000dF9n');
update_option( 'sfdc_oid', '00DDh0000009Umu' );
update_option( 'webtolead_url', 'https://test.salesforce.com/servlet/servlet.WebToLead' );
$Campaign_ID = get_option('default_campaign');
$sfdc_oid = get_option('sfdc_oid');
$webtolead_url = get_option('webtolead_url');
} else {
update_option( 'default_campaign', '7011I000000dDwA');
update_option( 'sfdc_oid', '00D1I000000mJ0Q' );
update_option( 'webtolead_url', 'https://webto.salesforce.com/servlet/servlet.WebToLead' );
$Campaign_ID = get_option('default_campaign');
$sfdc_oid = get_option('sfdc_oid');
$webtolead_url = get_option('webtolead_url');
}
function postSalesforce( $cf7 ) {
global $Campaign_ID;
global $sfdc_oid;
global $webtolead_url;
$member_status = "Web response";
$call_time = "00N30000009VwFg";
$comments = "00N1200000BGIy0";
$lead_source = "Web";
$wpcf7 = WPCF7_ContactForm::get_current();
$form_id = $wpcf7->id;
if ( !in_array($form_id, array('27615','27843'), false ) ) {
if(($_POST['dynamic-campaign-id']))
$Campaign_ID = ($_POST['dynamic-campaign-id']);
$cleanPOST = array(
'first_name' => ($_POST['first-name']),
'last_name' => ($_POST['last-name']),
'phone' => ($_POST['phone']),
'email' => ($_POST['your-email']),
'street' => ($_POST['street-address']),
'city' => ($_POST['city']),
'state' => ($_POST['state']),
'zip' => ($_POST['zip']),
'Referral_first_name__c' => ($_POST['first-name-ref']),
'Referral__c' => ($_POST['last-name-ref']),
'Referral_Phone_Number__c' => ($_POST['phone-ref']),
'Inquiring_for__c' => ($_POST['inquiring-for']),
'member_status' => $member_status,
'Campaign_ID' => $Campaign_ID,
'oid' => $sfdc_oid,
'lead_source' => $lead_source,
'User_Experience__c' => $control,
'GCLID__c' => ($_POST['gclid_data']),
'Custom_Field_1__c' => ($_POST['subid1']),
'Custom_Field_2__c' => ($_POST['subid2']),
'Custom_Field_3__c' => ($_POST['subid3']),
'Custom_Field_4__c' => ($_POST['subid4'])
);
foreach ($cleanPOST as $key=>$value){
$cleanPOST[stripslashes($key)] = stripslashes($value);
}
$ch = curl_init();
if (curl_error($ch) != "") {
exit( "Error: $error\n");
}
curl_setopt($ch, CURLOPT_URL, $webtolead_url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($cleanPOST));
// DEBUG use this to see the variables as it is run
//error_log(__METHOD__ . http_build_query($cleanPOST));
//error_log(__FUNCTION__ . "\n" . print_r($_POST, 1));
//ob_start();
//var_dump($_POST);
//error_log(basename(__FILE__) . "\n" . ob_get_clean());
curl_exec($ch);
curl_close($ch);
}
}
/**
* Function postFiveNine
* Send the form data to Five9 so that the call can be made
*
*/
function postFiveNine( $cf7 )
{
$Campaign_ID = '701130000026vNy';
$permalink = getenv('HTTP_REFERER');
$title = get_permalink(url_to_postid($permalink));
date_default_timezone_set('America/New_York');
$F9Date = date("Y-m-d")."-". date("H:i");
$F9domain = "connect america";
$F9list = "Web Form Submissions H";
$newphone = preg_replace('/^1|\D/', '', $_POST['phone']);
$wpcf7 = WPCF7_ContactForm::get_current();
$form_id = $wpcf7->id;
if ( !in_array($form_id, array('27615','27843'), false ) ) {
if(($_POST['dynamic-five9list']))
$F9list = ($_POST['dynamic-five9list']);
if(($_POST['dynamic-campaign-id']))
$Campaign_ID = ($_POST['dynamic-campaign-id']);
$cleanPOST = array(
'first_name' => ($_POST['first-name']),
'last_name' => ($_POST['last-name']),
'number1' => $newphone,
'F9domain' => $F9domain,
'F9list' => $F9list,
'salesforce_id' => $Campaign_ID,
'Device_6' => $title,
'WebDialer_Key' => $F9Date,
'F9key' => WebDialer_Key,
'F9CallASAP' => true
);
foreach ($cleanPOST as $key=>$value){
$cleanPOST[stripslashes($key)] = stripslashes($value);
}
$ch = curl_init();
// DEBUG - this should return a message to the user it failed
if (curl_error($ch) != "") {
echo "Error: $error\n";
}
curl_setopt($ch, CURLOPT_URL, "https://api.five9.com/web2campaign/AddToList");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($cleanPOST));
curl_exec($ch);
curl_close($ch);
}
}
/************* Campaign cron ****************/
if (!wp_next_scheduled('campaign_sync')) {
wp_schedule_event( time(), 'daily', 'campaign_sync' );
wp_schedule_event( time(), 'every_three_hours', 'campaign_sync' );
}
add_action( 'campaign_sync', 'medAlert__cron_sync' );
function medAlert__cron_sync(){
function createMessage($stato,$type,$Message){
$obj = array(
"time"=>time(),
"stato"=>$stato,
"type"=> $type,
"message"=>$Message
);
return $obj;
}
/************* chiamata request ****************/
$log = "";
$crypto = new SecuredContent();
/*$api_uri = get_option(id_api_salesforce);*/
/*$api_uri = 'https://lilsand2-connectamerica.cs23.force.com/RestServices/';*/ // this variable should be configurable
$api_rest="services/apexrest/GetProductCatalog";
/* $api_uri = get_option(id_api_salesforce);*/
$api_uri = get_option("id_api_salesforce"); // this variable should be configurable
$api_rest="GetProductCatalog";
$api_param="?brand=";
$api_brand= get_option("id_brand");
//$log_Array = array();
//array_push($log_Array,createMessage(1,"info","inizio sync"));
$is_post = false;//$_SERVER['REQUEST_METHOD'] === 'POST';
$url = $api_uri .$api_rest . $api_param . $api_brand; //$api_uri . (($is_post) ? $_POST['meta']['uri'] : $_GET['meta']['uri']);
echo $url;
$request = curl_init($url);
curl_setopt($request, CURLOPT_CUSTOMREQUEST, $is_post ? 'POST' : 'GET');
curl_setopt($request, CURLOPT_RETURNTRANSFER, true);
curl_setopt($request, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
if ($is_post) {
$data = json_encode($crypto->encode_content(json_encode($_POST['content'])));
curl_setopt($request, CURLOPT_POSTFIELDS, $data);
curl_setopt($request, CURLOPT_HTTPHEADER, array('Content-Length: ' . strlen($data)));
}
else {
$auth_header = json_encode($crypto->encode_content(urldecode($url)));
echo $auth_header;
curl_setopt($request, CURLOPT_HTTPHEADER, array('CA-Authorization: ' . $auth_header));
}
//array_push($log_Array,createMessage(1,"info","chiamata"));
global $wpdb;
$chiamta1=$wpdb->prepare("CALL IPER_MA_REQUEST_SET(%d,%s,%s,%s,%s,%d)",
0,
$url,
'',
'',
'',
-1
);
//array_push($log_Array,createMessage(1,"Chiamata",$chiamta1));
$rs=callDBStored($chiamta1,true);
array_push($log_Array,createMessage(1,"Risultato",$rs));
$result = curl_exec($request);
echo "---result--".$result."---result--";
curl_close($request);
// $result = json_decode($result);
// $result = json_decode($result);
$result = json_decode($result);
$result = (OBJECT)json_decode($crypto->decode_content($result));
$chiamta1=$wpdb->prepare("CALL IPER_MA_REQUEST_SET(%d,%s,%s,%s,%s,%d)",
$rs->identity,
$url,
'',
$result->ResponseHeader->ResponseId,
json_encode($result),
-1
);
//array_push($log_Array,createMessage(1,"Chiamata",$chiamta1));
$rs=callDBStored($chiamta1,true);
//array_push($log_Array,createMessage(1,"Risultato",$rs));
$RequestID = $rs->identity;
$ResponseId = $result->ResponseHeader->ResponseId;
$Brand = $result->ResponseBody->BrandOfferings;
if (!empty($Brand) && count($Brand)==1){
$BrandID = $result->ResponseBody->BrandOfferings[0]->BrandID;
$product = $result->ResponseBody->BrandOfferings[0]->Products;
$log = $log."INIZIO INSERIMENTO PRODOTTI".PHP_EOL;
if (!empty($product)){
//array_push($log_Array,createMessage(1,"info","Inizio Prodotti". count($product)));
$log = $log."PRODOTTI " . count($product) . PHP_EOL;
foreach ($product as $single){
/************* inserimento prodotto ****************/
$ProductName=sanitize_text_field($single->ProductName);
$ProductID=sanitize_text_field($single->ProductID);
$ProductCode=sanitize_text_field($single->ProductCode);
$IsAvailable=sanitize_text_field($single->IsAvailable)?1:0;
$log = $log."prodotto:".$ProductID .PHP_EOL;
$call=$wpdb->prepare("CALL IPER_MA_PRODUCT_SET(%d,%s,%s,%s,%s,%s,%d,%d)",
0,
$BrandID,
$ProductName,
$ProductID,
$ProductCode,
$IsAvailable,
0,
$RequestID
);
$log = $log."chiamata:".$call .PHP_EOL;
$rs=callDBStored($call,true);
$idProduct = $rs->identity;
if($rs->status == 2){
$typepost = array(
'post_title' => $ProductName,
'post_status' => 'publish', //Default status draft
'post_author' => 1,
'post_type' => 'product'
);
//creating post with arguments above and assign post id to $def_post_id
$def_post_id = wp_insert_post($typepost);
$call=$wpdb->prepare("CALL IPER_MA_PRODUCT_SET(%d,%s,%s,%s,%s,%s,%d,%d)",
$idProduct,
$BrandID,
$ProductName,
$ProductID,
$ProductCode,
$IsAvailable,
$def_post_id,
$RequestID
);
$rs=callDBStored($call,true);
$log = $log."Inserimento prodotto:".$ProductID. " id:".$idProduct.PHP_EOL;
}elseif ($rs->status == 1){
$log = $log."Modifica prodotto:".$ProductID. " id:".$idProduct.PHP_EOL;
}else{
$log = $log."Error prodotto:".$ProductID. PHP_EOL;
}
/************* inserimento RatePlans ****************/
$rateplan = $single->RatePlans;
if (!empty($rateplan)){
$log = $log."RATEPLAN " . count($rateplan) . PHP_EOL;
foreach ($rateplan as $rate) {
$Term=sanitize_text_field($rate->Term);
$RatePlanID=sanitize_text_field($rate->RatePlanID);
$Price=sanitize_text_field($rate->Price);
$OrderType=sanitize_text_field($rate->OrderType);
$MonthlyPrice = sanitize_text_field($rate->MonthlyPrice);
$log = $log."rateplan:".$RatePlanID .PHP_EOL;
$call=$wpdb->prepare("CALL IPER_MA_RATEPLAN_SET(%d,%d,%s,%s,%s,%s,%s,%d,%d)",
0,
$idProduct,
$Term,
$RatePlanID,
$Price,
$OrderType,
$MonthlyPrice,
0,
$RequestID
);
$log = $log."chiamata:".$call .PHP_EOL;
$rs=callDBStored($call,true);
$idRateplan = $rs->identity;
if($rs->status == 2){
$typepost = array(
'post_title' => $Term,
'post_status' => 'publish', //Default status draft
'post_author' => 1,
'post_type' => 'rateplan'
);
//creating post with arguments above and assign post id to $def_post_id
$def_post_id = wp_insert_post($typepost);
$call=$wpdb->prepare("CALL IPER_MA_RATEPLAN_SET(%d,%d,%s,%s,%s,%s,%s,%d,%d)",
$idRateplan,
$idProduct,
$Term,
$RatePlanID,
$Price,
$OrderType,
$MonthlyPrice,
$def_post_id,
$RequestID
);
$rs=callDBStored($call,true);
$log = $log."Inserimento rateplan:".$RatePlanID. " id:".$idRateplan.PHP_EOL;
}elseif ($rs->status == 1){
$log = $log."Modifica rateplan:".$RatePlanID. " id:".$idRateplan.PHP_EOL;
}else{
$log = $log."Error rateplan:".$RatePlanID. PHP_EOL;
}
/************* inserimento Upsell ****************/
$UpsellOptions = $rate->UpsellOptions; // da chiedere la struttura
if(!empty($UpsellOptions)) {
$log = $log."UpsellOptions " . count($UpsellOptions) . PHP_EOL;
foreach($UpsellOptions as $upsell){
$ShowBeforeAccessories = sanitize_text_field($upsell->ShowBeforeAccessories)?1:0;
$ProductName= sanitize_text_field($upsell->ProductName);
$ProductID= sanitize_text_field($upsell->ProductID);
$Price= sanitize_text_field($upsell->Price);
$log = $log."UpsellOptions:".$ProductID .PHP_EOL;
$call=$wpdb->prepare("CALL IPER_MA_UPSELL_SET(%d,%d,%s,%s,%s,%s,%d,%d)",
0,
$idRateplan,
$ProductName,
$ProductID,
$Price,
$ShowBeforeAccessories,
0,
$RequestID
);
$log = $log."chiamata:".$call .PHP_EOL;
$rs=callDBStored($call,true);
$idUpsell = $rs->identity;
if($rs->status == 2){
$typepost = array(
'post_title' => $ProductName,
'post_status' => 'publish', //Default status draft
'post_author' => 1,
'post_type' => 'upsell'
);
//creating post with arguments above and assign post id to $def_post_id
$def_post_id = wp_insert_post($typepost);
$call=$wpdb->prepare("CALL IPER_MA_UPSELL_SET(%d,%d,%s,%s,%s,%s,%d,%d)",
$idUpsell,
$idRateplan,
$ProductName,
$ProductID,
$Price,
$ShowBeforeAccessories,
$def_post_id,
$RequestID
);
$rs=callDBStored($call,true);
$log = $log."Inserimento UpsellOptions:".$idRateplan. " id:".$ProductID.PHP_EOL;
}elseif ($rs->status == 1){
$log = $log."Modifica UpsellOptions:".$idRateplan. " id:".$ProductID.PHP_EOL;
}else{
$log = $log."Error UpsellOptions:".$ProductID. PHP_EOL;
}
/********** INSERIMENTO UPSELL PROMOTION ************/
$log = $log."INSERIMENTO UPSELL PROMOTION <br>";
$UpsellPromotion = $upsell->Promotion;
$log = $log."INSERIMENTO UPSELL PROMOTION ".count($UpsellPromotion).PHP_EOL;
if(!empty($UpsellPromotion)){
$upsellPromotionID = sanitize_text_field($UpsellPromotion->PromotionID);
$upsellPrice = sanitize_text_field($UpsellPromotion->Price);
$upsellName = sanitize_text_field($UpsellPromotion->Name);
$upsellMonthlyPrice = sanitize_text_field($UpsellPromotion->MonthlyPrice);
$call = $wpdb->prepare("CALL IPER_MA_UPSELL_PROMOTION_SET(%d,%d,%s,%s,%s,%s,%d,%d)",
0,
$idUpsell,
$upsellPromotionID,
$upsellPrice,
$upsellName,
$upsellMonthlyPrice,
0,
$RequestID
);
$log = $log . "chiamata:" . $call . PHP_EOL;
$rs = callDBStored($call, true);
$idUpsellPromotions = $rs->identity;
$log = $log . "Inserimento Upsell Promotion:" . $upsellPromotionID . " id:" . $idUpsellPromotions . PHP_EOL;
}//UPSELL PROMOTION IF
}
}
/************* inserimento AccessoryGroups ****************/
$AccessoryGroups = $rate->AccessoryGroups;
if(!empty($AccessoryGroups)){
$log = $log."AccessoryGroups " . count($AccessoryGroups) . PHP_EOL;
foreach ($AccessoryGroups as $group){
$LimitRestriction=sanitize_text_field($group->LimitRestriction)?1:0;
$IncludedWithOrder=sanitize_text_field($group->IncludedWithOrder)?1:0;
$Description=sanitize_text_field($group->Description);
$AccessoryGroupID=sanitize_text_field($group->AccessoryGroupID);
$log = $log."AccessoryGroups:".$AccessoryGroupID .PHP_EOL;
$call=$wpdb->prepare("CALL IPER_MA_ACCESSORY_GROUP_SET(%d,%d,%s,%s,%s,%s,%d,%d)",
0,
$idRateplan,
$LimitRestriction,
$IncludedWithOrder,
$Description,
$AccessoryGroupID,
0,
$RequestID
);
$log = $log."chiamata:".$call .PHP_EOL;
$rs=callDBStored($call,true);
$idAccessoryGroup = $rs->identity;
$log = $log."Inserimento AccessoryGroups:".$AccessoryGroupID. " id:".$idAccessoryGroup.PHP_EOL;
/************* inserimento Accessories ****************/
$Accessory = $group->Accessories;
if(!empty($Accessory)){
$log = $log."Accessory " . count($Accessory) . PHP_EOL;
foreach ($Accessory as $single_Accessory){
$Quantity = sanitize_text_field($single_Accessory->Quantity);
$Price= sanitize_text_field($single_Accessory->Price);
$IsAvailable= sanitize_text_field($single_Accessory->IsAvailable)?1:0;
$AccessoryName= sanitize_text_field($single_Accessory->AccessoryName);
$AccessoryID= sanitize_text_field($single_Accessory->AccessoryID);
$AccessoryCode= sanitize_text_field($single_Accessory->AccessoryCode);
$log = $log."Accessories:".AccessoryID .PHP_EOL;
$call=$wpdb->prepare("CALL IPER_MA_ACCESSORY_SET(%d,%d,%s,%s,%s,%s,%s,%s,%d,%d)",
$idAccessoryGroup,
0,
$Quantity,
$Price,
$IsAvailable,
$AccessoryName,
$AccessoryID,
$AccessoryCode,
0,
$RequestID
);
$log = $log."chiamata:".$call .PHP_EOL;
$rs=callDBStored($call,true);
$idAccessory = $rs->identity;
$log = $log."Inserimento Accessories:".$AccessoryID. " id:".$idAccessory." Status".$rs->status.PHP_EOL;
if($rs->status == 2){
$typepost = array(
'post_title' => $AccessoryName,
'post_status' => 'publish', //Default status draft
'post_author' => 1,
'post_type' => 'accessory' //controllare
);
//creating post with arguments above and assign post id to $def_post_id
$def_post_id = wp_insert_post($typepost);
$call=$wpdb->prepare("CALL IPER_MA_ACCESSORY_SET(%d,%d,%s,%s,%s,%s,%s,%s,%d,%d)",
$idAccessoryGroup,
$idAccessory,
$Quantity,
$Price,
$IsAvailable,
$AccessoryName,
$AccessoryID,
$AccessoryCode,
$def_post_id,
$RequestID
);
$rs=callDBStored($call,true);
$log = $log."Inserimento Accessories:".$AccessoryID. " id:".$idAccessory.PHP_EOL;
}elseif ($rs->status == 1){
$log = $log."Modifica Accessories:".$AccessoryID. " id:".$idAccessory.PHP_EOL;
}else{
$log = $log."Error Accessories:".$ProductID. PHP_EOL;
}
}//ACCESSORY FOR
}//ACCESSORY IF
}//GROUP ACC FOR
}//GROUP ACC IF
/************* inserimento AvailablePromotions ****************/
$log = $log."INSERIMENTO PROMOTION <br>";
$AvailablePromotions = $rate->AvailablePromotions;
$log = $log."INSERIMENTO PROMOTION ".count($AvailablePromotions).PHP_EOL;
if(!empty($AvailablePromotions)){
foreach ($AvailablePromotions as $promotion) {
$PromotionID = "".sanitize_text_field($promotion->PromotionID);
$Price = "".sanitize_text_field($promotion->Price);
$Name = "".sanitize_text_field($promotion->Name);
$MonthlyPrice = "".sanitize_text_field($promotion->MonthlyPrice);
echo"idRate".$idRateplan;
print_r($promotion);
echo "CALL IPER_MA_PROMOTION_SET(%d,%d,%s,%s,%s,%s,%d,%d)";
$call = $wpdb->prepare("CALL IPER_MA_PROMOTION_SET(%d,%d,%s,%s,%s,%s,%d,%d)",
0,
$idRateplan,
$PromotionID,
$Price,
$Name,
$MonthlyPrice,
0,
$RequestID
);
$log = $log . "chiamata promotion:" . $call . PHP_EOL;
$rs = callDBStored($call, true);
$idAvailablePromotions = $rs->identity;
$log = $log . "Inserimento AvailablePromotions:" . $PromotionID . " id:" . $idAvailablePromotions . PHP_EOL;
}
}//PROMOTION IF
}//RATEPLAN FOR
}//RATEPLAN IF
$Bundles = $single->Bundles;
if(!empty($Bundles)){
$BundleProducts = $Bundles->BundleProducts;
if (!empty($BundleProducts)){
foreach ($BundleProducts as $bundle){
$Name = sanitize_text_field($bundle->Name);
$ID = sanitize_text_field($bundle->ID);
$call=$wpdb->prepare("CALL IPER_MA_BUNDLE_SET(%d,%d,%s,%s,%d,%d)",
0,
$idProduct,
$ID,
$Name,
0,
$RequestID
);
$log = $log."chiamata:".$call .PHP_EOL;
$rs=callDBStored($call,true);
$idBundleProducts = sanitize_text_field($rs->identity);
$log = $log."Inserimento BundleProducts:".$ID. " id:".$idBundleProducts.PHP_EOL;
}//BundleProducts for
}//BundleProductsif
}//bundles if
}//PRODUCT FOR
}//PRODUCT IF
/************* inserimento Shippings ****************/
$Shippings = $result->ResponseBody->BrandOfferings[0]->Shippings;
$log = $log."INIZIO INSERIMENTO SHIPPING <br>";
if(!empty($Shippings)){
$log = $log."SHIPPING " . count($Shippings) . PHP_EOL;
foreach ($Shippings as $single){
$ShippingMethod = sanitize_text_field($single->ShippingMethod);
$ShippingID = sanitize_text_field($single->ShippingID);
$ShippingCarrier = sanitize_text_field($single->ShippingCarrier);
$Price = sanitize_text_field($single->Price);
$call=$wpdb->prepare("CALL IPER_MA_SHIPPING_SET(%d,%s,%s,%s,%s,%s,%d,%d)",
0,
$BrandID,
$ShippingMethod,
$ShippingID,
$ShippingCarrier,
$Price,
0,
$RequestID
);
$log = $log."chiamata:".$call .PHP_EOL;
$rs=callDBStored($call,true);
$idShipping = sanitize_text_field($rs->identity);
if($rs->status == 2){
$typepost = array(
'post_title' => $ShippingMethod,
'post_status' => 'publish', //Default status draft
'post_author' => 1,
'post_type' => 'shipping' //controllare
);
//creating post with arguments above and assign post id to $def_post_id
$def_post_id = wp_insert_post($typepost);
$call=$wpdb->prepare("CALL IPER_MA_SHIPPING_SET(%d,%s,%s,%s,%s,%s,%d,%d)",
$idShipping,
$BrandID,
$ShippingMethod,
$ShippingID,
$ShippingCarrier,
$Price,
$def_post_id,
$RequestID
);
$log = $log."chiamata:".$call .PHP_EOL;
$rs=callDBStored($call,true);
$log = $log."Inserimento Shipping:".$ShippingID. " id:".$idShipping.PHP_EOL;
}elseif ($rs->status == 1){
$log = $log."Modifica Shipping:".$ShippingID. " id:".$idShipping.PHP_EOL;
}else{
$log = $log."Error Shipping:".$ShippingID. PHP_EOL;
}
}//Shipping for
}//shipping if
$call="CALL IPER_MA_CLEAN_WP_POST";
$rs=callDBStored($call,true);
$log = $log."Pulizia POST";
$call=$wpdb->prepare("CALL IPER_MA_REQUEST_SET_LOG(%d,%s)",
$RequestID,
$log
);
$rs=callDBStored($call,true);
$log = $log."Inserimento LOG id:".$RequestID.PHP_EOL;
}//brand
echo $log;
//CAMPAIGN SYNC
echo "\n\n***** CAMPAIGN SYNC *****\n";
$api_uri = get_option("id_api_salesforce"); // this variable should be configurable
$api_rest=IperCampaignController::kREST_ACTION;
$api_param="?Brand=";
$api_brand= get_option("id_brand");
$url = $api_uri .$api_rest . $api_param . $api_brand; //$api_uri . (($is_post) ? $_POST['meta']['uri'] : $_GET['meta']['uri']);
echo "URL: ".$url;
$request_campaign = curl_init($url);
curl_setopt($request_campaign, CURLOPT_CUSTOMREQUEST,'GET');
curl_setopt($request_campaign, CURLOPT_RETURNTRANSFER, true);
curl_setopt($request_campaign, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
curl_setopt($request_campaign, CURLOPT_COOKIE, 'debug_logs=debug_logs,domain=.force.com');
$auth_header = json_encode($crypto->encode_content(urldecode($url)));
curl_setopt($request_campaign, CURLOPT_HTTPHEADER, array('CA-Authorization: ' . $auth_header));
$result = curl_exec($request_campaign);
curl_close($request_campaign);
echo $result;
$data = stripslashes($result);
if(!empty($data)){
$data = substr($data,1);
$data = substr($data,0,-1);
$data = (OBJECT)json_decode($crypto->decode_content($data));
if(!empty($data) && !empty($data->ResponseBody)){
echo "\nTHERE ARE CAMPAIGN";
$campaignController = IperCampaignController::instance();
$campaignController->cronJob($data);
}else{
echo "\nNo data";
}
}else{
echo "\n** FAILED **\n";
}
echo "\n\n***** END CAMPAIGN SYNC *****";
}
/**
* Function A Place for MOM
*/
function postAPFM( $form, &$abort, $submission ){
if ( $abort === TRUE || $form->ID() !== 29890 ) {
return;
}
$apfm_username = 'ConnectAmerica';
$apfm_password ='APFMca_42821';
$userpwd = $apfm_username.":".$apfm_password;
$apfm_url = 'https://services.aplaceformom.com/lead';
$data = array(
'FirstName' => ($_POST['first-name']),
'LastName' => ($_POST['last-name']),
'Phone' => ($_POST['your-phone']),
'EmailAddress' => ($_POST['your-email']),
'DesiredZip' => ($_POST['your-zip'])
);
$body = json_encode($data);
$ch = curl_init($apfm_url);
curl_setopt($ch, CURLOPT_USERPWD, $userpwd);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
curl_close($ch);
return;
}
add_action('wpcf7_before_send_mail', 'postAPFM', 10, 3);
/**
* A Place for Mom Shortcode
*/
add_shortcode('apfm', 'apfm');
function apfm() {
$html_apfm = do_shortcode( '[contact-form-7 id="29890" html_id="contact-form-apfm" html_class="apfm_form]' );
$apfm .= '<div class="apfm">' .$html_apfm .'</div>';
return $apfm;
global $apfm;
}
/**
* Rewrite WordPress URLs to Include /blog/ in Post Permalink Structure
*
* @author Golden Oak Web Design <info@goldenoakwebdesign.com>
* @license https://www.gnu.org/licenses/gpl-2.0.html GPLv2+
*/
function blog_generate_rewrite_rules( $wp_rewrite ) {
$new_rules = array(
'(([^/]+/)*blog)/page/?([0-9]{1,})/?$' => 'index.php?pagename=$matches[1]&paged=$matches[3]',
'blog/([^/]+)/?$' => 'index.php?post_type=post&name=$matches[1]',
'blog/[^/]+/attachment/([^/]+)/?$' => 'index.php?post_type=post&attachment=$matches[1]',
'blog/[^/]+/attachment/([^/]+)/trackback/?$' => 'index.php?post_type=post&attachment=$matches[1]&tb=1',
'blog/[^/]+/attachment/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?post_type=post&attachment=$matches[1]&feed=$matches[2]',
'blog/[^/]+/attachment/([^/]+)/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?post_type=post&attachment=$matches[1]&feed=$matches[2]',
'blog/[^/]+/attachment/([^/]+)/comment-page-([0-9]{1,})/?$' => 'index.php?post_type=post&attachment=$matches[1]&cpage=$matches[2]',
'blog/[^/]+/attachment/([^/]+)/embed/?$' => 'index.php?post_type=post&attachment=$matches[1]&embed=true',
'blog/[^/]+/embed/([^/]+)/?$' => 'index.php?post_type=post&attachment=$matches[1]&embed=true',
'blog/([^/]+)/embed/?$' => 'index.php?post_type=post&name=$matches[1]&embed=true',
'blog/[^/]+/([^/]+)/embed/?$' => 'index.php?post_type=post&attachment=$matches[1]&embed=true',
'blog/([^/]+)/trackback/?$' => 'index.php?post_type=post&name=$matches[1]&tb=1',
'blog/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?post_type=post&name=$matches[1]&feed=$matches[2]',
'blog/([^/]+)/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?post_type=post&name=$matches[1]&feed=$matches[2]',
'blog/page/([0-9]{1,})/?$' => 'index.php?post_type=post&paged=$matches[1]',
'blog/[^/]+/page/?([0-9]{1,})/?$' => 'index.php?post_type=post&name=$matches[1]&paged=$matches[2]',
'blog/([^/]+)/page/?([0-9]{1,})/?$' => 'index.php?post_type=post&name=$matches[1]&paged=$matches[2]',
'blog/([^/]+)/comment-page-([0-9]{1,})/?$' => 'index.php?post_type=post&name=$matches[1]&cpage=$matches[2]',
'blog/([^/]+)(/[0-9]+)?/?$' => 'index.php?post_type=post&name=$matches[1]&page=$matches[2]',
'blog/[^/]+/([^/]+)/?$' => 'index.php?post_type=post&attachment=$matches[1]',
'blog/[^/]+/([^/]+)/trackback/?$' => 'index.php?post_type=post&attachment=$matches[1]&tb=1',
'blog/[^/]+/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?post_type=post&attachment=$matches[1]&feed=$matches[2]',
'blog/[^/]+/([^/]+)/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?post_type=post&attachment=$matches[1]&feed=$matches[2]',
'blog/[^/]+/([^/]+)/comment-page-([0-9]{1,})/?$' => 'index.php?post_type=post&attachment=$matches[1]&cpage=$matches[2]',
);
$wp_rewrite->rules = $new_rules + $wp_rewrite->rules;
}
add_action( 'generate_rewrite_rules', 'blog_generate_rewrite_rules' );
function update_post_link( $post_link, $id = 0 ) {
$post = get_post( $id );
if( is_object( $post ) && $post->post_type == 'post' ) {
return home_url( '/blog/' . $post->post_name . '/');
}
return $post_link;
}
add_filter( 'post_link', 'update_post_link', 1, 3 );
function skip_redirect( $skip_redirect, $post_id, $post ) {
if ( $post->post_type === 'post' ) {
$skip_redirect = true;
}
return $skip_redirect;
}
add_filter( 'wpseo_premium_post_redirect_slug_change', 'skip_redirect', 10, 3 );
add_action( 'wpcf7_before_send_mail', 'postResponsys');
// Refresh Responsys token
add_action('cron_hourly', 'getAccessCode');
if ( !wp_next_scheduled( 'cron_hourly' ) ) {
wp_schedule_event(time(), 'hourly', 'cron_hourly');
}
/**
* Get Responsys token
*/
function getAccessCode(){
$cleanPOST = array(
'auth_type' => 'password',
'user_name' => 'medicalalertapi',
'password' => '!cB4AiwCfiCZ9eX8!');
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://login2.responsys.net/rest/api/v1.3/auth/token");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($cleanPOST));
$json = json_decode(curl_exec($ch));
$authToken = $json->authToken;
$endPoint = $json->endPoint;
curl_close($curl);
update_option( 'auth_token', $authToken);
update_option( 'responsys_endpoint', $endPoint);
}
/**
* Post form data to responsys
*/
function postResponsys ( $cf7 ) {
$responsys_campaign = get_option('responsys_campaign','');
$token = get_option('auth_token');
$endpoint= get_option('responsys_endpoint');
$url = $endpoint . "/rest/api/v1.3/campaigns/".$responsys_campaign."/email";
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$header = array(
"Authorization: " . $token,
"Content-Type: application/json",
);
curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
$form_first = ($_POST['first-name']);
$form_email = ($_POST['your-email']);
$json = json_encode(
array(
"mergeTriggerRecordData" => array(
"mergeTriggerRecords" => array(
array(
"fieldValues" => array($form_email, $form_first, 'N' )
)
),
"fieldNames" => array(
"EMAIL_ADDRESS_", "FIRST_NAME", "On_Contact_File")
),
"mergeRule" => array(
"htmlValue" => "H",
"matchColumnName1" => "EMAIL_ADDRESS_",
"matchColumnName2" => null,
"optoutValue" => "O",
"insertOnNoMatch" => true,
"defaultPermissionStatus" => "OPTIN",
"rejectRecordIfChannelEmpty" => "E",
"optinValue" => "I",
"updateOnMatch" => "REPLACE_ALL",
"textValue" => "T",
"matchOperator" => "NONE"
)
)
);
curl_setopt($curl, CURLOPT_POSTFIELDS, $json);
$resp = curl_exec($curl);
curl_close($curl);
}