/** * @introduced: 2.0.8 * @migration-type: Meta pair migragtion * @mirgration: convert meta key cta_ab_variations to wp-cta-variations & delete cta_ab_variations * @mirgration: convert meta key wp-cta-variation-notes to a sub key of wp-cta-variations object * @migration: convert all meta keys that do not have an -{{vid}} suffix to a -0 suffix */ public static function create_variation_objects() { $ctas = get_posts(array('post_type' => 'wp-call-to-action', 'posts_per_page' => -1)); /* loop through ctas and migrate data */ foreach ($ctas as $cta) { $variations = array(); /* If CTA already has our upgraded meta key then continue to next cta*/ if (get_post_meta($cta->ID, 'wp-cta-variations', true)) { continue; } $legacy_value = get_post_meta($cta->ID, 'cta_ab_variations', true); $variation_ids_array = explode(',', $legacy_value); $variation_ids_array = $variation_ids_array ? $variation_ids_array : array(0 => 0); foreach ($variation_ids_array as $vid) { /* get variation status */ $status = get_post_meta($cta->ID, 'wp_cta_ab_variation_status', true); /* Get variation notes & alter key for variations with vid=0 */ if (!$vid) { /* for each meta without an variation id add one */ $meta = get_post_meta($cta->ID); $notes = get_post_meta($cta->ID, 'wp-cta-variation-notes', true); foreach ($meta as $key => $value) { if (!is_numeric(substr($key, -1))) { add_post_meta($cta->ID, $key . '-0', $value[0], true); //echo $cta->ID . ' ' . $key . '-0 ' . $value[0] . '<br>'; } } } else { $notes = get_post_meta($cta->ID, 'wp-cta-variation-notes-' . $vid, true); } if ($status == 2) { $status = 'paused'; } else { $status = 'active'; } $variations[$vid]['status'] = $status; $variations[$vid]['notes'] = $notes; } CTA_Variations::update_variations($cta->ID, $variations); //echo '<hr>'; } //exit; }
/** * Returns conversion rate for given cta and variation id * * @param INT $cta_id id of call to action * @param INT $vid id of variation belonging to call to action * * @return INT conversion rate */ public static function get_conversion_rate($cta_id, $vid) { $impressions = CTA_Variations::get_impressions($cta_id, $vid); $conversions = CTA_Variations::get_conversions($cta_id, $vid); if ($impressions > 0) { $conversion_rate = $conversions / $impressions; $conversion_rate_number = $conversion_rate * 100; $conversion_rate_number = round($conversion_rate_number, 2); $conversion_rate = $conversion_rate_number; } else { $conversion_rate = 0; } return $conversion_rate; }
/** * Prints / Returns Custom JS & CSS Related to Call to Action */ public static function load_custom_js_css($selected_cta = null, $return = false) { global $post; $inline_content = ""; $selected_cta ? $selected_cta : ($selected_cta = self::$instance->selected_cta); if (!isset($selected_cta['id'])) { return; } foreach ($selected_cta['variations'] as $vid => $variation) { /* account for preview mode */ if (isset($_GET['wp-cta-variation-id']) && $vid != $_GET['wp-cta-variation-id']) { continue; } $meta = $selected_cta['meta'][$vid]; $vid < 1 ? $suffix = '' : ($suffix = '-' . $vid); $template_slug = $selected_cta['meta'][$vid]['wp-cta-selected-template-' . $vid]; $custom_css = CTA_Variations::get_variation_custom_css($selected_cta['id'], $vid); /* This is printing CTA CSS Twice on Preview Mode */ /* We may reserve this function only for custom css and custom js */ $dynamic_css = self::$instance->cta_templates[$template_slug]['css-template']; $dynamic_css = self::$instance->replace_template_variables($selected_cta, $dynamic_css, $vid); $css_id_preface = "#wp_cta_" . $selected_cta['id'] . "_variation_" . $vid; $dynamic_css = str_replace("{{", "", $dynamic_css); $dynamic_css = str_replace("}}", "", $dynamic_css); $dynamic_css = self::$instance->parse_css_template($dynamic_css, $css_id_preface); /****** New Parse - DO NOT DELTE *******/ // http://regexr.com/?36e6v // http://regex101.com/r/rF9iR9 /* IN PROGRESS */ /* $css = explode("}", $dynamic_css); $pattern = "/.-?[_a-zA-Z]+[_a-zA-Z0-9-]*(?=[^}]*\{)/"; // close. matches all ids and classes but separates //$pattern = "/(?![^{]*})(#\S+)\b/"; preg_match_all($pattern, $dynamic_css, $match_css); print_r($match_css[0]); $matched_css_names = $match_css[0]; foreach ($matched_css_names as $key => $value) { if (!preg_match("/:/", $value)){ echo $value . "<br>"; } } echo "<pre>"; print_r($css); echo "</pre>"; /**/ /****** End New Parse - DO NOT DELTE *******/ $css_styleblock_class = apply_filters('wp_cta_styleblock_class', '', $selected_cta['id'], $vid); if (!stristr($custom_css, '<style')) { $custom_css = strip_tags($custom_css); } /* If style.css exists in root cta directory, insert here */ $slug = $selected_cta['templates'][$vid]['slug']; $has_style = WP_CTA_PATH . 'templates/' . $slug . '/style.css'; $has_style_url = WP_CTA_URLPATH . 'templates/' . $slug . '/style.css'; if (file_exists($has_style)) { $inline_content .= '<link rel="stylesheet" href="' . $has_style_url . '">'; } /* Print Cusom CSS */ $inline_content .= '<style type="text/css" id="wp_cta_css_custom_' . $selected_cta['id'] . '_' . $vid . '" class="wp_cta_css_' . $selected_cta['id'] . ' ' . $css_styleblock_class . '">' . $custom_css . ' ' . $dynamic_css . '</style>'; $custom_js = get_post_meta($selected_cta['id'], 'wp-cta-custom-js' . $suffix, true); if (!stristr($custom_css, '<script')) { $inline_content .= '<script type="text/javascript" id="wp_cta_js_custom">jQuery(document).ready(function($) { ' . $custom_js . ' });</script>'; } else { $inline_content .= $custom_js; } } if ($return) { return $inline_content; } else { echo $inline_content; } }
/** * Prints / Returns Custom JS & CSS Related to Call to Action */ public static function load_custom_js_css($selected_cta = null, $return = false) { global $post; $inline_content = ""; $selected_cta ? $selected_cta : ($selected_cta = self::$instance->selected_cta); if (!isset($selected_cta['id'])) { return; } foreach ($selected_cta['variations'] as $vid => $variation) { /* account for preview mode */ if (isset($_GET['wp-cta-variation-id']) && $vid != $_GET['wp-cta-variation-id']) { continue; } $meta = $selected_cta['meta'][$vid]; $template_slug = $selected_cta['meta'][$vid]['wp-cta-selected-template-' . $vid]; $custom_css = CTA_Variations::get_variation_custom_css($selected_cta['id'], $vid); $dynamic_css = self::$instance->cta_templates[$template_slug]['css-template']; $dynamic_css = self::$instance->replace_template_variables($selected_cta, $dynamic_css, $vid); $css_id_preface = "#wp_cta_" . $selected_cta['id'] . "_variation_" . $vid; $dynamic_css = str_replace("{{", "", $dynamic_css); $dynamic_css = str_replace("}}", "", $dynamic_css); $dynamic_css = self::$instance->parse_css_template($dynamic_css, $css_id_preface); $css_styleblock_class = apply_filters('wp_cta_styleblock_class', '', $selected_cta['id'], $vid); $custom_css = strip_tags($custom_css, '<style>'); /* If style.css exists in root cta directory, insert here */ $slug = $selected_cta['templates'][$vid]['slug']; $has_style = WP_CTA_PATH . 'templates/' . $slug . '/style.css'; $has_style_url = WP_CTA_URLPATH . 'templates/' . $slug . '/style.css'; if (file_exists($has_style)) { $inline_content .= '<link rel="stylesheet" href="' . $has_style_url . '">'; } /* Print Cusom CSS */ $inline_content .= '<style type="text/css" id="wp_cta_css_custom_' . $selected_cta['id'] . '_' . $vid . '" class="wp_cta_css_' . $selected_cta['id'] . ' ' . $css_styleblock_class . '">' . $custom_css . ' ' . $dynamic_css . '</style>'; $custom_js = CTA_Variations::get_variation_custom_js($selected_cta['id'], $vid); if (!stristr($custom_css, '<script')) { $inline_content .= '<script type="text/javascript">jQuery(document).ready(function($) { ' . $custom_js . ' });</script>'; } else { $inline_content .= $custom_js; } } if ($return) { return $inline_content; } else { echo $inline_content; } }
/** * Renders shortcode data for user to copy for user */ public static function add_hidden_inputs() { global $post, $CTA_Variations; if (!$post || $post->post_type != 'wp-call-to-action') { return; } /* Add hidden param for visual editor */ if (isset($_REQUEST['frontend']) && $_REQUEST['frontend'] == 'true') { echo '<input type="hidden" name="frontend" id="frontend-on" value="true" />'; } /* Get current variation id */ $vid = CTA_Variations::get_current_variation_id(); /* Add variation status */ $variations_status = $CTA_Variations->get_variation_status($post->ID, $vid); echo '<input type="hidden" name="wp-cta-variation-status[' . $vid . ']" value = "' . $variations_status . '">'; /* Add variation id */ echo '<input type="hidden" name="wp-cta-variation-id" id="open_variation" value = "' . $vid . '">'; /* Add call to action permalink */ }