function wp_cta_render_metabox($key, $custom_fields, $post) { //print_r($custom_fields);exit; // Use nonce for verification echo "<input type='hidden' name='wp_cta_{$key}_custom_fields_nonce' value='" . wp_create_nonce('wp-cta-nonce') . "' />"; // Begin the field table and loop echo '<div class="form-table" id="inbound-meta">'; //print_r($custom_fields);exit; $current_var = wp_cta_ab_testing_get_current_variation_id(); foreach ($custom_fields as $field) { $field_id = $key . "-" . $field['id']; $field_name = $field['id']; $label_class = $field['id'] . "-label"; $type_class = " inbound-" . $field['type']; $type_class_row = " inbound-" . $field['type'] . "-row"; $type_class_option = " inbound-" . $field['type'] . "-option"; $option_class = isset($field['class']) ? $field['class'] : ''; // get value of this field if it exists for this post $meta = get_post_meta($post->ID, $field_id, true); $global_meta = get_post_meta($post->ID, $field_name, true); if (empty($global_meta)) { $global_meta = $field['default']; } //print_r($field); if (!isset($meta) && isset($field['default']) && !is_numeric($meta) || isset($meta) && empty($meta) && isset($field['default']) && !is_numeric($meta)) { //echo $field['id'].":".$meta; //echo "<br>"; $meta = $field['default']; } // Remove prefixes on global => true template options if (isset($field['global']) && $field['global'] === true) { $field_id = $field_name; $meta = get_post_meta($post->ID, $field_name, true); } // begin a table row with echo '<div class="' . $field['id'] . $type_class_row . ' div-' . $option_class . ' wp-call-to-action-option-row inbound-meta-box-row">'; if ($field['type'] != "description-block" && $field['type'] != "custom-css") { echo '<div id="inbound-' . $field_id . '" data-actual="' . $field_id . '" class="inbound-meta-box-label wp-call-to-action-table-header ' . $label_class . $type_class . '"><label for="' . $field_id . '">' . $field['label'] . '</label></div>'; } echo '<div class="wp-call-to-action-option-td inbound-meta-box-option ' . $type_class_option . '" data-field-type="' . $field['type'] . '">'; switch ($field['type']) { // default content for the_content case 'default-content': echo '<span id="overwrite-content" class="button-secondary">Insert Default Content into main Content area</span><div style="display:none;"><textarea name="' . $field_id . '" id="' . $field_id . '" class="default-content" cols="106" rows="6" style="width: 75%; display:hidden;">' . $meta . '</textarea></div>'; break; case 'description-block': echo '<div id="' . $field_id . '" class="description-block">' . $field['description'] . '</div>'; break; case 'custom-css': echo '<style type="text/css">' . $field['default'] . '</style>'; break; // text // text case 'colorpicker': if (!$meta) { $meta = $field['default']; } $var_id = isset($_GET['new_meta_key']) ? "-" . $_GET['new_meta_key'] : ''; echo '<input type="text" class="jpicker" style="background-color:#' . $meta . '" name="' . $field_id . '" id="' . $field_id . '" value="' . $meta . '" size="5" /><span class="button-primary new-save-wp-cta" data-field-type="text" id="' . $field_id . $var_id . '" style="margin-left:10px; display:none;">Update</span> <div class="wp_cta_tooltip tool_color" title="' . $field['description'] . '"></div>'; break; case 'datepicker': echo '<div class="jquery-date-picker inbound-datepicker" id="date-picking" data-field-type="text"> <span class="datepair" data-language="javascript"> Date: <input type="text" id="date-picker-' . $key . '" class="date start" /></span> Time: <input id="time-picker-' . $key . '" type="text" class="time time-picker" /> <input type="hidden" name="' . $field_id . '" id="' . $field_id . '" value="' . $meta . '" class="new-date" value="" > <p class="description">' . $field['description'] . '</p> </div>'; break; case 'text': echo '<input type="text" name="' . $field_id . '" id="' . $field_id . '" value="' . $meta . '" size="30" /> <div class="wp_cta_tooltip" title="' . $field['description'] . '"></div>'; break; case 'number': echo '<input type="number" class="' . $option_class . '" name="' . $field_id . '" id="' . $field_id . '" value="' . $meta . '" size="30" /> <div class="wp_cta_tooltip" title="' . $field['description'] . '"></div>'; break; // textarea // textarea case 'textarea': echo '<textarea name="' . $field_id . '" id="' . $field_id . '" cols="106" rows="6" style="width: 75%;">' . $meta . '</textarea> <div class="wp_cta_tooltip tool_textarea" title="' . $field['description'] . '"></div>'; break; // wysiwyg // wysiwyg case 'wysiwyg': echo "<div class='iframe-options iframe-options-" . $field_id . "' id='" . $field['id'] . "'>"; wp_editor($meta, $field_id, $settings = array('editor_class' => $field_name)); echo '<p class="description">' . $field['description'] . '</p></div>'; break; // media // media case 'media': //echo 1; exit; echo '<label for="upload_image" data-field-type="text">'; echo '<input name="' . $field_id . '" id="' . $field_id . '" type="text" size="36" name="upload_image" value="' . $meta . '" />'; echo '<input class="upload_image_button" id="uploader_' . $field_id . '" type="button" value="Upload Image" />'; echo '<p class="description">' . $field['description'] . '</p>'; break; // checkbox // checkbox case 'checkbox': $i = 1; echo "<table class='wp_cta_check_box_table'>"; if (!isset($meta)) { $meta = array(); } elseif (!is_array($meta)) { $meta = array($meta); } foreach ($field['options'] as $value => $label) { if ($i == 5 || $i == 1) { echo "<tr>"; $i = 1; } echo '<td data-field-type="checkbox"><input type="checkbox" name="' . $field_id . '[]" id="' . $field_id . '" value="' . $value . '" ', in_array($value, $meta) ? ' checked="checked"' : '', '/>'; echo '<label for="' . $value . '"> ' . $label . '</label></td>'; if ($i == 4) { echo "</tr>"; } $i++; } echo "</table>"; echo '<div class="wp_cta_tooltip tool_checkbox" title="' . $field['description'] . '"></div>'; break; // radio // radio case 'radio': foreach ($field['options'] as $value => $label) { //echo $meta.":".$field_id; //echo "<br>"; echo '<input type="radio" name="' . $field_id . '" id="' . $field_id . '" value="' . $value . '" ', $meta == $value ? ' checked="checked"' : '', '/>'; echo '<label for="' . $value . '"> ' . $label . '</label> '; } echo '<div class="wp_cta_tooltip" title="' . $field['description'] . '"></div>'; break; // select // select case 'dropdown': echo '<select name="' . $field_id . '" id="' . $field_id . '" class="' . $field['id'] . '">'; foreach ($field['options'] as $value => $label) { echo '<option', $meta == $value ? ' selected="selected"' : '', ' value="' . $value . '">' . $label . '</option>'; } echo '</select><div class="wp_cta_tooltip" title="' . $field['description'] . '"></div>'; break; } //end switch echo '</div></div>'; } // end foreach echo '</div>'; // end table //exit; }
function wp_cta_ab_testing_add_tabs() { global $post; $post_type_is = get_post_type($post->ID); $permalink = get_permalink($post->ID); // Only show wp-cta tabs on landing pages post types (for now) if ($post_type_is === "wp-call-to-action") { $current_variation_id = wp_cta_ab_testing_get_current_variation_id(); if (isset($_GET['new_meta_key'])) { $current_variation_id = $_GET['new_meta_key']; } echo "<input type='hidden' id='open_variation' value='{$current_variation_id}'>"; if (isset($_GET['new_meta_key'])) { echo "<input type='hidden' id='variation_new_meta_key' value='" . $_GET['new_meta_key'] . "'>"; } if (isset($_GET['clone'])) { echo "<input type='hidden' id='clone_variation_id' value='" . $_GET['clone'] . "'>"; } $variations = get_post_meta($post->ID, 'cta_ab_variations', true); if ($variations === "0" && isset($_GET['new_meta_key']) && !isset($_GET['clone'])) { $variations = $variations . ', 1'; } $array_variations = explode(',', $variations); $variations = array_filter($array_variations, 'is_numeric'); $lid = end($array_variations); $new_variation_id = $lid + 1; if ($current_variation_id > 0 || isset($_GET['new-variation'])) { $first_class = 'inactive'; } else { $first_class = 'active'; } echo '<h2 class="nav-tab-wrapper a_b_tabs">'; echo '<a href="?post=' . $post->ID . '&wp-cta-variation-id=0&action=edit" class="wp-cta-ab-tab nav-tab nav-tab-special-' . $first_class . '" id="tabs-0">Version A</a>'; $var_id_marker = 1; foreach ($array_variations as $i => $vid) { if ($vid != 0) { $letter = wp_cta_ab_key_to_letter($i); //alert (variation.new_variation); if ($current_variation_id == $vid && !isset($_GET['new-variation']) || $current_variation_id == $vid && isset($_GET['clone'])) { $cur_class = 'active'; } else { $cur_class = 'inactive'; } echo '<a href="?post=' . $post->ID . '&wp-cta-variation-id=' . $vid . '&action=edit" class="wp-cta-nav-tab nav-tab nav-tab-special-' . $cur_class . '" id="tabs-add-variation">Version ' . $letter . '</a>'; } } if (!isset($_GET['new-variation'])) { echo '<a href="?post=' . $post->ID . '&wp-cta-variation-id=' . $new_variation_id . '&action=edit&new-variation=1" class="wp-cta-nav-tab nav-tab nav-tab-special-inactive nav-tab-add-new-variation" id="tabs-add-variation">Add New Variation <i data-code="f132" style="vertical-align:bottom;" class="dashicons dashicons-plus"></i></a>'; } else { $variation_count = count($array_variations); $vid = isset($_GET['new_meta_key']) ? $_GET['new_meta_key'] : $_GET['wp-cta-variation-id']; $letter = wp_cta_ab_key_to_letter($vid); echo '<a href="?post=' . $post->ID . '&wp-cta-variation-id=' . $new_variation_id . '&action=edit" class="wp-cta-nav-tab nav-tab nav-tab-special-active" id="tabs-add-variation">' . $letter . '</a>'; } $edit_link = isset($_GET['wp-cta-variation-id']) ? '?wp-cta-variation-id=' . $_GET['wp-cta-variation-id'] . '' : '?wp-cta-variation-id=0'; $post_link = get_permalink($post->ID); $post_link = preg_replace('/\\?.*/', '', $post_link); echo "<a rel='" . $post_link . "' id='cta-launch-front' class='button-primary new-save-wp-cta-frontend' href='{$post_link}{$edit_link}&cta-template-customize=on'>" . __('Launch Visual Editor', 'cta') . "</a>"; echo '</h2>'; } }
function wp_cta_ab_testing_alter_title_area($content) { global $post; $variation_id = wp_cta_ab_testing_get_current_variation_id(); if ($variation_id > 0) { if (isset($post)) { $post_id = $post->ID; } else { if (isset($_REQUEST['post_id'])) { $post_id = $_REQUEST['post_id']; } } //echo $post_id;exit; $content = do_shortcode(get_post_meta($post_id, 'wp-cta-main-headline-' . $variation_id, true)); } return $content; }