__( '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' => '', 'before_title' => '

', 'after_title' => '

', ) ); 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' => '', 'before_title' => '

', 'after_title' => '

', ) ); 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' => '', 'before_title' => '

', 'after_title' => '

', ) ); 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' => '', 'before_title' => '

', 'after_title' => '

', ) ); 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' => '', 'before_title' => '

', 'after_title' => '

', ) ); register_sidebar( array( 'name' => __( 'Footer Left Sidebar', 'thbusiness' ), 'id' => 'footer-left', 'description' => '', 'before_widget' => '', 'before_title' => '

', 'after_title' => '

', ) ); register_sidebar( array( 'name' => __( 'Footer Mid Sidebar', 'thbusiness' ), 'id' => 'footer-mid', 'description' => '', 'before_widget' => '', 'before_title' => '

', 'after_title' => '

', ) ); register_sidebar( array( 'name' => __( 'Footer Right Sidebar', 'thbusiness' ), 'id' => 'footer-right', 'description' => '', 'before_widget' => '', 'before_title' => '

', 'after_title' => '

', ) ); //BLOG TEMPLATE EDITS register_sidebar( array( 'name' => __( 'Footer Blog Sidebar', 'thbusiness' ), 'id' => 'footer-blog', 'description' => '', 'before_widget' => '', 'before_title' => '

', 'after_title' => '

', ) ); //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(){ ?> '; echo $style; echo ''; } } 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 .= ''; } 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 Cheryl’s Story */ add_shortcode('promovideo', 'promoVideo'); function promoVideo() { $promo_video .= '

Watch Cheryl’s Story

'; return $promo_video; global $promo_video; } /** * Shortcode for Trust Badge Content Block */ add_shortcode('trustbadge', 'trustBadge'); function trustBadge (){ $trust_badge .= '
In Home Safety Guide
Consumers Advocate
Best Company
Top 10
'; return $trust_badge; global $trust_badge; } /** * Shortcode for Feature Icons Content Block MAW-348 */ add_shortcode('featuredicons', 'featuredIcons'); function featuredIcons (){ $featured_icons .= '

24 Hours

24/7 Response & Support Center

We're not just an emergency response system, we're a support network available at all times.

Reliable Support

We Can Stay on the
Line Until Help Arrives

No matter where you live, a U.S. based operator can remain on the phone with you until help arrives.

Easy Setup

Easy to Use
Easy to Set Up

Plug in the base unit to a power outlet. Then simply push the button to call for help.

No Hassles

One Monthly Price
No Hassles

Basic monitoring equipment at no cost, no hidden fees, no activation charges and no long-term commitment required.

'; return $featured_icons; global $featured_icons; } /** * Shortcode for How it works Content Block MAW-349 */ add_shortcode('howitworks', 'howitWorks'); function howitWorks (){ $how_it_works .= '

Get the Help You Need in Three Simple Steps

Image Border
Push Your Medical Alert Button

Push your button.

Press your Medical Alert button and you’ll be connected immediately to one of our operators.

Connect with the Two-Way Voice System

Talk to us.

Our dedicated, supportive operator determines the exact help you need.

Medical Assistance will be Dispatched

Get help—fast.

Our operator will make sure you get the aid you need and even stay in communication until help arrives.
'; return $how_it_works; global $how_it_works; } /** * Shortcode for Yotpo reviews on Landing pageas */ add_shortcode('yl', 'yotpoReviewsLanding'); function yotpoReviewsLanding (){ $yotpolanding .= ''; return $yotpolanding; global $yotpolanding; } /** * Shortcode for Yotpo reviews on Home Page widget */ add_shortcode('yh', 'yotpoReviewsHome'); function yotpoReviewsHome (){ $yotpohome .= '
 
'; 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 .= 'New & Exclusive Mobile Elite - Free Shipping & Free LockboxFree Shipping & Free Lockbox'; 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 = '
Order Now
'; 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 = '

*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.
†Fall Detection does not detect 100% of all falls. Users should always push their button when they need help.

'; 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 = '

*Disclaimer:
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.
Free month, free shipping and free lockbox offer available only on annual plans.
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 does not detect 100% of all falls. Users should always push their button when they need help.
Pendant coverage is subject to device location, environment, equipment and facility conditions.

'; 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 = '
Hurry! Offer Ends Soon!
'; //$lpc = '
Hurry! Offer Ends Soon!
'; $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 .= '

Medical Alert Systems

Order your Medical Alert system today! Keep your independence and get peace of mind knowing that you’re protected at home 24/7 and on the go with our GPS-enabled mobile Medical Alert options. Have a question? Call us at ' . get_phone() . ' and we’ll help you choose a Medical Alert system that’s perfect for you!

Home System

Our Most Affordable System


In Home Medical Alert

24/7/365 Continuous Monitoring

Button can be worn in shower or bath

Base Station with Two-way Speaker

Up to 36-hour Back-up Battery

Select

Mobile System

Our Most Flexible System


Medical Alert with GPS

24/7/365 Continuous Monitoring

Button can be worn in shower or bath

Battery Life Up to 5 Days

No Landline Phone Required

AT&T Network

GPS with Location-based Services

Interchangeable Pendant & Bracelet

Select
'; 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() { ?> $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', '00DDh0000009Umu'); update_option( 'sfdc_oid', '00D8C0000004aiW' ); 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
"; $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
"; $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
"; 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 .= '
' .$html_apfm .'
'; return $apfm; global $apfm; } /** * Rewrite WordPress URLs to Include /blog/ in Post Permalink Structure * * @author Golden Oak Web Design * @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); }