1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191: 192: 193: 194: 195: 196: 197: 198: 199: 200: 201: 202: 203: 204: 205: 206: 207: 208: 209: 210: 211: 212: 213: 214: 215: 216: 217: 218: 219: 220: 221: 222: 223: 224: 225: 226: 227: 228: 229: 230: 231: 232: 233: 234: 235: 236: 237: 238: 239: 240: 241: 242: 243: 244: 245: 246: 247: 248: 249: 250: 251: 252: 253: 254: 255: 256: 257: 258: 259: 260: 261: 262: 263: 264: 265: 266: 267: 268: 269: 270: 271: 272: 273: 274: 275: 276: 277: 278: 279: 280: 281: 282: 283: 284: 285: 286: 287: 288: 289: 290: 291: 292: 293: 294: 295: 296: 297: 298: 299: 300: 301: 302: 303: 304: 305: 306: 307: 308: 309: 310: 311: 312: 313: 314: 315: 316: 317: 318: 319: 320: 321: 322: 323: 324: 325: 326: 327: 328: 329: 330: 331: 332: 333: 334: 335: 336: 337: 338: 339: 340: 341: 342: 343: 344: 345: 346: 347: 348: 349: 350: 351: 352: 353: 354: 355: 356: 357: 358: 359: 360: 361: 362: 363: 364: 365: 366: 367: 368: 369: 370: 371: 372: 373: 374: 375: 376: 377: 378: 379: 380: 381: 382: 383: 384: 385: 386: 387: 388: 389: 390: 391: 392: 393: 394: 395: 396: 397: 398: 399: 400: 401: 402: 403: 404: 405: 406: 407: 408: 409: 410: 411: 412: 413: 414: 415: 416: 417: 418: 419: 420: 421: 422: 423: 424: 425: 426: 427: 428: 429: 430: 431: 432: 433: 434: 435: 436: 437: 438: 439: 440: 441: 442: 443: 444: 445: 446: 447: 448: 449: 450: 451: 452: 453: 454: 455: 456: 457: 458: 459: 460: 461: 462: 463: 464: 465: 466: 467: 468: 469: 470: 471: 472: 473: 474: 475: 476: 477: 478: 479: 480: 481: 482: 483: 484: 485: 486: 487: 488: 489: 490: 491: 492: 493: 494: 495: 496: 497: 498: 499: 500: 501: 502: 503: 504: 505: 506: 507: 508: 509: 510: 511: 512: 513: 514: 515: 516: 517: 518: 519: 520: 521: 522: 523: 524: 525: 526: 527: 528: 529: 530: 531: 532: 533: 534: 535: 536: 537: 538: 539: 540: 541: 542: 543: 544: 545: 546: 547: 548: 549: 550: 551: 552: 553: 554: 555: 556: 557: 558: 559: 560: 561: 562: 563: 564: 565: 566: 567: 568: 569: 570: 571: 572: 573: 574: 575: 576: 577: 578: 579: 580: 581: 582: 583: 584: 585: 586: 587: 588: 589: 590: 591: 592: 593: 594: 595: 596: 597: 598: 599: 600: 601: 602: 603: 604: 605: 606: 607: 608: 609: 610: 611: 612: 613: 614: 615: 616: 617: 618: 619: 620: 621: 622: 623: 624: 625: 626: 627: 628: 629: 630: 631: 632: 633: 634: 635: 636: 637: 638: 639: 640: 641: 642: 643: 644: 645: 646: 647: 648: 649: 650: 651: 652: 653: 654: 655: 656: 657: 658: 659: 660: 661: 662: 663: 664: 665: 666: 667: 668:
<?php
class Landing_Pages_Post_Type {
function __construct() {
self::load_hooks();
}
private function load_hooks() {
add_action('init', array( __CLASS__ , 'register_post_type' ) );
add_action( 'admin_init' , array( __CLASS__ , 'register_role_capabilities' ) ,999);
add_action('init', array( __CLASS__ , 'register_taxonomies' ) );
add_action('init', array( __CLASS__ , 'add_rewrite_rules') );
add_filter('mod_rewrite_rules', array( __CLASS__ , 'filter_rewrite_rules' ) , 1);
add_filter("manage_edit-landing-page_columns", array( __CLASS__ , 'register_columns' ) );
add_action("manage_posts_custom_column", array( __CLASS__ , "display_columns" ) );
add_filter('landing-page_orderby', 'lp_column_orderby', 10, 2);
if ((isset($_GET['post_type']) && ($_GET['post_type'] == 'landing-page'))) {
add_filter('wpseo_use_page_analysis', '__return_false');
}
add_action('restrict_manage_posts', array( __CLASS__, 'sort_by_category' ) );
add_filter('parse_query', array( __CLASS__ , 'sort_by_category_prepare_query' ));
add_filter('manage_edit-landing-page_sortable_columns', array( __CLASS__ , 'define_sortable_columns' ));
add_filter('display_post_states', array( __CLASS__ , 'filter_custom_post_states' ) );
add_action( 'admin_enqueue_scripts' , array(__CLASS__, 'enqueue_admin_scripts' ) );
if (isset($_GET['dont_save'])
|| isset($_GET['iframe_window'])
|| isset($_GET['inbound-preview']) ) {
add_action('wp_enqueue_scripts', array(__CLASS__, 'stop_stat_tracking') , 20);
}
if (isset($_GET['iframe_window'])) {
add_action('admin_enqueue_scripts', array(__CLASS__, 'enqueue_scripts_iframe') );
}
add_action('wp_head', array(__CLASS__, 'wp_head' ));
}
public static function register_post_type() {
$slug = Landing_Pages_Settings::get_setting( 'lp-main-landing-page-permalink-prefix', 'go' );
$featured_images = Landing_Pages_Settings::get_setting( 'lp-main-landing-page-enable-featured-image', false );
$capabilities = array('title','custom-fields','editor', 'revisions');
if ($featured_images) {
array_push($capabilities , 'thumbnail');
}
$labels = array(
'name' => __('Landing Pages', 'inbound-pro' ),
'singular_name' => __('Landing Page', 'inbound-pro' ),
'add_new' => __('Add New', 'inbound-pro' ),
'add_new_item' => __('Add New Landing Page' , 'inbound-pro' ),
'edit_item' => __('Edit Landing Page' , 'inbound-pro' ),
'new_item' => __('New Landing Page' , 'inbound-pro' ),
'view_item' => __('View Landing Page' , 'inbound-pro' ),
'search_items' => __('Search Landing Page' , 'inbound-pro' ),
'not_found' => __('Nothing found' , 'inbound-pro' ),
'not_found_in_trash' => __('Nothing found in Trash' , 'inbound-pro' ),
'parent_item_colon' => ''
);
$args = array(
'labels' => $labels,
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'query_var' => true,
'menu_icon' => '',
'rewrite' => array("slug" => "$slug",'with_front' => false),
'capability_type' => array('landing_page','landing_pages'),
'map_meta_cap' => true,
'hierarchical' => false,
'menu_position' => 32,
'supports' => $capabilities
);
register_post_type( 'landing-page' , $args );
}
public static function register_role_capabilities() {
$roles = array('inbound_marketer','administrator');
foreach($roles as $the_role) {
$role = get_role($the_role);
if (!$role) {
continue;
}
$role->add_cap( 'read' );
$role->add_cap( 'read_landing_page');
$role->add_cap( 'read_private_landing_pages' );
$role->add_cap( 'edit_landing_page' );
$role->add_cap( 'edit_landing_pages' );
$role->add_cap( 'edit_others_landing_pages' );
$role->add_cap( 'edit_published_landing_pages' );
$role->add_cap( 'publish_landing_pages' );
$role->add_cap( 'delete_landing_pages' );
$role->add_cap( 'delete_others_landing_pages' );
$role->add_cap( 'delete_private_landing_pages' );
$role->add_cap( 'delete_published_landing_pages' );
}
}
public static function register_taxonomies() {
$args = array(
'hierarchical' => true,
'label' => __("Categories", 'inbound-pro'),
'singular_label' => __("Landing Page Category",
'landing-pages'),
'show_ui' => true,
'query_var' => true,
"rewrite" => true
);
register_taxonomy( 'landing_page_category', array('landing-page'), $args);
}
public static function register_columns($columns) {
$columns = array(
"cb" => "<input type=\"checkbox\" />",
"thumbnail-lander" => __("Preview", 'inbound-pro'),
"title" => __("Landing Page Title", 'inbound-pro'),
"stats" => __("Split Testing Results", 'inbound-pro'),
"impressions" => __("Total<br>Visits", 'inbound-pro'),
"actions" => __("Total<br>Conversions", 'inbound-pro'),
"cr" => __("Total<br>Conversion Rate", 'inbound-pro')
);
return $columns;
}
public static function enqueue_admin_scripts( $hook ) {
global $post;
$screen = get_current_screen();
if (!isset($post) ||$post->post_type != 'landing-page') {
return;
}
wp_enqueue_style('lp-content-stats', LANDINGPAGES_URLPATH . 'assets/css/admin/content-stats.css', array() , null);
if ($screen->id == 'edit-landing-page' ) {
wp_enqueue_script( 'lp-admin-clear-stats-ajax-request', LANDINGPAGES_URLPATH . 'assets/js/ajax.clearstats.js', array( 'jquery' ) , null );
wp_localize_script( 'lp-admin-clear-stats-ajax-request', 'ajaxadmin', array( 'ajaxurl' => admin_url('admin-ajax.php'), 'lp_clear_nonce' => wp_create_nonce('lp-clear-nonce') ) );
wp_enqueue_script('landing-page-list', LANDINGPAGES_URLPATH . 'assets/js/admin/admin.landing-page-list.js', array() , null);
wp_enqueue_style('landing-page-list-css', LANDINGPAGES_URLPATH.'assets/css/admin/landing-page-list.css', array() , null);
wp_enqueue_script('jqueryui');
}
if (isset($_GET['iframe_window'])) {
wp_enqueue_style('lp_ab_testing_customizer_css', LANDINGPAGES_URLPATH . 'assets/css/frontend/customizer-preview.css', array() , null);
}
}
public static function enqueue_frontend_scripts() {
global $post;
if ( !isset($post) && $post->post_type=='landing-page') {
return;
}
wp_enqueue_style('inbound-wordpress-base', LANDINGPAGES_URLPATH . 'assets/css/frontend/global-landing-page-style.css', array() , null);
wp_enqueue_style('inbound-shortcodes', INBOUND_FORMS.'css/frontend-render.css', array() , null);
}
public static function display_columns($column) {
global $post;
if ($post->post_type != 'landing-page') return;
switch ($column) {
case 'ID':
echo $post->ID;
BREAK;
case 'thumbnail-lander':
$template = get_post_meta($post->ID, 'lp-selected-template', true);
$permalink = get_permalink($post->ID);
$datetime = the_modified_date('YmjH', null, null, false);
$permalink = $permalink = $permalink . '?dt=' . $datetime;
if (in_array($_SERVER['REMOTE_ADDR'], array('127.0.0.1', '::1'))) {
if(file_exists(LANDINGPAGES_UPLOADS_PATH . $template . '/thumbnail.png')) {
$thumbnail = LANDINGPAGES_UPLOADS_URLPATH . $template . '/thumbnail.png';
} else if(file_exists(LANDINGPAGES_UPLOADS_PATH . $template . '/thumbnail.jpg')) {
$thumbnail = LANDINGPAGES_UPLOADS_URLPATH . $template . '/thumbnail.jpg';
} else {
$thumbnail = LANDINGPAGES_URLPATH . 'templates/' . $template . '/thumbnail.png';
}
} else {
$thumbnail = 'http://s.wordpress.com/mshots/v1/' . urlencode(esc_url($permalink)) . '?w=140';
}
echo "<a title='" . __('Click to Preview this variation', 'inbound-pro') . "' class='thickbox' href='" . $permalink . "?lp-variation-id=0&iframe_window=on&post_id=" . $post->ID . "&TB_iframe=true&width=640&height=703' target='_blank'><img src='" . $thumbnail . "' style='width:155px;height:110px;' title='Click to Preview'></a>";
BREAK;
case "stats":
self::show_stats();
BREAK;
case "impressions" :
echo self::show_aggregated_stats("impressions");
BREAK;
case "actions":
echo self::show_aggregated_stats("actions");
BREAK;
case "cr":
echo self::show_aggregated_stats("cr") . "%";
BREAK;
case "template":
$template_used = Landing_Pages_Variations::get_current_template( $post->ID );
echo $template_used;
BREAK;
}
}
public static function define_sortable_columns($columns) {
return array(
'title' => 'title',
'impressions' => 'impressions',
'actions' => 'actions',
'cr' => 'cr'
);
}
public static function filter_row_actions( $actions , $post ) {
if ($post->post_type=='wp-call-to-action') {
$actions['clear'] = '<a href="#clear-stats" id="wp_cta_clear_'.$post->ID.'" class="clear_stats" title="'
. __( 'Clear impression and conversion records', 'cta' )
. '" >' . __( 'Clear All Stats' , 'cta') . '</a>';
$actions['clear'] .= '<br><span style="color:#000;">' . __( 'Shortcode:' , 'cta' ) .'</span> <input type="text" style="width: 60%; text-align: center;" class="regular-text code short-shortcode-input" readonly="readonly" id="shortcode" name="shortcode" value="[cta id=\''.$post->ID.'\']">';
}
return $actions;
}
public static function show_aggregated_stats($type_of_stat) {
global $post;
$variations = get_post_meta($post->ID, 'lp-ab-variations', true);
$variations = explode(",", $variations);
$impressions = 0;
$conversions = 0;
foreach ($variations as $vid) {
$each_impression = (int) get_post_meta($post->ID, 'lp-ab-variation-impressions-' . $vid, true);
$each_conversion = (int) get_post_meta($post->ID, 'lp-ab-variation-conversions-' . $vid, true);
(($each_conversion === "")) ? $final_conversion = 0 : $final_conversion = $each_conversion;
$impressions += (int) get_post_meta($post->ID, 'lp-ab-variation-impressions-' . $vid, true);
$conversions += (int) get_post_meta($post->ID, 'lp-ab-variation-conversions-' . $vid, true);
}
if ($type_of_stat === "actions") {
return $conversions;
}
if ($type_of_stat === "impressions") {
return $impressions;
}
if ($type_of_stat === "cr") {
if ($impressions != 0) {
$conversion_rate = $conversions / $impressions;
} else {
$conversion_rate = 0;
}
$conversion_rate = round($conversion_rate, 2) * 100;
return $conversion_rate;
}
}
public static function add_rewrite_rules() {
if ( !class_exists('Inbound_Pro_Plugin')){
$this_path = LANDINGPAGES_PATH;
$this_path = explode('wp-content', $this_path);
$this_path = "wp-content" . $this_path[1];
} else {
$this_path = INBOUND_PRO_PATH;
$this_path = explode('wp-content', $this_path);
$this_path = "wp-content" . $this_path[1] . "core/landing-pages/";
}
$this_path = str_replace("\\" , "/" , $this_path);
$slug = Landing_Pages_Settings::get_setting( 'lp-main-landing-page-permalink-prefix', 'go' );
$ab_testing = Landing_Pages_Settings::get_setting('lp-main-landing-page-disable-turn-off-ab', "0");
if ($ab_testing === "0") {
add_rewrite_rule("$slug/([^/]*)/([0-9]+)/", "$slug/$1?lp-variation-id=$2", 'top');
add_rewrite_rule("$slug/([^/]*)?", $this_path . "modules/module.redirect-ab-testing.php?permalink_name=$1 ", 'top');
add_rewrite_rule("landing-page=([^/]*)?", $this_path . 'modules/module.redirect-ab-testing.php?permalink_name=$1', 'top');
}
}
public static function filter_rewrite_rules( $rules ) {
if (stristr($rules, 'RewriteCond %{QUERY_STRING} !lp-variation-id')) {
return $rules;
}
$rules_array = preg_split('/$\R?^/m', $rules);
if (count($rules_array) < 3) {
$rules_array = explode("\n", $rules);
$rules_array = array_filter($rules_array);
}
$slug = Landing_Pages_Settings::get_setting( 'lp-main-landing-page-permalink-prefix', 'go' );
$i = 0;
foreach ($rules_array as $key => $val) {
if (stristr($val, "RewriteRule ^{$slug}/([^/]*)? ") || stristr($val, "RewriteRule ^{$slug}/([^/]*)/([0-9]+)/ ")) {
$new_val = "RewriteCond %{QUERY_STRING} !lp-variation-id";
$rules_array[$i] = $new_val;
$i++;
$rules_array[$i] = $val;
$i++;
} else {
$rules_array[$i] = $val;
$i++;
}
}
$rules = implode("\r\n", $rules_array);
return $rules;
}
public static function show_stats() {
global $post;
$permalink = get_permalink($post->ID);
$variations = Landing_Pages_Variations::get_variations($post->ID);
echo "<span class='show-stats button'> " . __('Show Variation Stats', 'inbound-pro') . "</span>";
echo "<ul class='lp-varation-stat-ul'>";
$cr_array = array();
$i = 0;
foreach ($variations as $key => $vid) {
$letter = Landing_Pages_Variations::vid_to_letter($post->ID, $key);
$impressions = Landing_Pages_Variations::get_impressions($post->ID, $vid);
$conversions = Landing_Pages_Variations::get_conversions($post->ID, $vid);
$status = Landing_Pages_Variations::get_variation_status( $post->ID, $vid );
$each_notes = Landing_Pages_Variations::get_variation_notes( $post->ID, $vid );
if ($impressions) {
$conversion_rate = $conversions / $impressions;
} else {
$conversion_rate = 0;
}
$conversion_rate = round($conversion_rate, 2) * 100;
$cr_array[] = $conversion_rate;
$data_letter = "data-letter=\"" . $letter . "\"";
$edit_link = admin_url('post.php?post=' . $post->ID . '&lp-variation-id=' . $vid . '&action=edit');
echo "<li rel='" . $status . "' data-postid='" . $post->ID . "' data-letter='" . $letter . "' data-lp='' class='lp-stat-row-" . $vid . " " . $post->ID . '-' . $conversion_rate . " status-" . $status . "'><a class='lp-letter' title='click to edit this variation' href='" . $edit_link . "'>" . $letter . "</a><span class='lp-numbers'><span class='lp-visitors'><span class='visit-text'>" . __( 'Impressions' , 'inbound-pro' ) . "</span><span class='lp-impress-num'>" . $impressions . "</span></span> <span class='lp-conversions'> <span class='lp-conversion-txt'>" . __( 'Conversions' , 'inbound-pro' ) . "</span> <span class='lp-con-num'>" . $conversions . "</span> </span> </span><a ". $data_letter . " class='cr-number cr-empty-" . $conversion_rate . "' href='" . $edit_link . "'>" . $conversion_rate . "%</a></li>";
$i++;
}
echo "</ul>";
$winning_cr = max($cr_array);
if ($winning_cr != 0) {
echo "<span class='variation-winner-is'>" . $post->ID . "-" . $winning_cr . "</span>";
}
}
public static function sort_by_category() {
global $typenow;
if ($typenow != "landing-page") {
return;
}
$filters = get_object_taxonomies($typenow);
foreach ($filters as $tax_slug) {
$tax_obj = get_taxonomy($tax_slug);
(isset($_GET[$tax_slug])) ? $current = $_GET[$tax_slug] : $current = 0;
wp_dropdown_categories(
array(
'show_option_all' => __('Show All ' . $tax_obj->label),
'taxonomy' => $tax_slug,
'name' => $tax_obj->name,
'orderby' => 'name',
'selected' => $current,
'hierarchical' => $tax_obj->hierarchical,
'show_count' => false,
'hide_empty' => true
)
);
}
}
public static function sort_by_category_prepare_query() {
global $pagenow;
$qv = &$query->query_vars;
if ($pagenow == 'edit.php' && isset($qv['landing_page_category']) && is_numeric($qv['landing_page_category'])) {
$term = get_term_by('id', $qv['landing_page_category'], 'landing_page_category');
$qv['landing_page_category'] = $term->slug;
}
}
public static function filter_custom_post_states($post_states) {
foreach ($post_states as &$state) {
$state = '<span class="' . strtolower($state) . ' states">' . str_replace(' ', '-', $state) . '</span>';
}
return $post_states;
}
public static function load_preview_iframe() {
$variation_id = Landing_Pages_Variations::get_current_variation_id();
$landing_page_id = $_GET['post_id'];
$variations = Landing_Pages_Variations::get_variations( $landing_page_id );
?>
<link rel="stylesheet" href="<?php echo LANDINGPAGES_URLPATH . 'assets/css/customizer-ab-testing.css';?>"/>
<style type="text/css">
position: absolute;
top: 0px;
left: 0px;
padding-left: 5px;
}
text-decoration: none;
border-bottom: none;
}
display: inline-block;
}
display: none !important;
}
</style>
<script type="text/javascript">
jQuery(document).ready(function ($) {
var current_page = jQuery("#current_variation_id").text();
jQuery('.variation-lp').on('click', function (event) {
variation_is = jQuery(this).attr("id");
var original_url = jQuery(parent.document).find("#TB_iframeContent").attr("src");
var current_id = jQuery("#current-post-id").text();
someURL = original_url;
splitURL = someURL.split('?');
someURL = splitURL[0];
new_url = someURL + "?lp-variation-id=" + variation_is + "&iframe_window=on&post_id=" + current_id;
jQuery(parent.document).find("#TB_iframeContent").attr("src", new_url);
});
});
</script>
<?php
}
public static function stop_stat_tracking() {
show_admin_bar(false);
wp_enqueue_script('stop-inbound-stats-js', LANDINGPAGES_URLPATH . 'assets/js/stop_page_stats.js' , array('inbound-analytics') , null );
wp_enqueue_style('inbound-preview-window-css', LANDINGPAGES_URLPATH . 'assets/css/iframe-preview.css' , array() , null);
}
public static function wp_head() {
global $post;
if (isset($post) && $post->post_type !=='landing-page') {
return;
}
if (isset($_GET['dont_save'])) { ?>
<style type="text/css">
:root:root:root
display:none !important;
}
:root:root:root {
margin-top: 0px !important;
min-height: 714px !important;
}
</style>
<?php }
if (isset($_GET['lp-variation-id']) && !isset($_GET['inbound-customizer']) && !isset($_GET['iframe_window']) && !isset($_GET['live-preview-area'])) {
?>
<?php
if(!defined('Inbound_Now_Disable_URL_CLEAN')) {
?>
<script type="text/javascript">
if (typeof window.history.pushState == 'function') {
var cleanparams=window.location.href.split("?");
var clean_url= landing_pages_remove_variation_param();
history.replaceState({},"landing page",clean_url);
}
function landing_pages_remove_variation_param() {
var urlparts= window.location.href.split('?');
if (urlparts.length>=2) {
var prefix= encodeURIComponent('lp-variation-id')+'=';
var pars= urlparts[1].split(/[&;]/g);
for (var i= pars.length; i-- > 0;) {
if (pars[i].lastIndexOf(prefix, 0) !== -1) {
pars.splice(i, 1);
}
}
url= urlparts[0] + (pars.length > 0 ? '?' + pars.join('&') : "");
return url;
} else {
return url;
}
}
</script>
<?php
}
}
}
}
new Landing_Pages_Post_Type();