Overview

Packages

  • ACF
  • Automation
    • Actions
    • Activation
    • LeadProfile
    • Menus
    • Queries
    • Rules
    • Triggers
  • CTA
    • Activation
    • AJAXListeners
    • Cloning
    • Core
    • Display
    • EditPage
    • Enqueues
    • GPLSettings
    • LeadsProfile
    • Loading
    • Menus
    • Notices
    • PlacementMetabox
    • PostType
    • Templates
    • Tracking
    • Variations
    • YOAST
  • InboundPro
    • Activation
    • AdminAJAX
    • AutoLoading
    • Cron
    • DataInterface
    • FieldMapping
    • Funnels
    • InboundNowAPI
    • Installer
    • LeadStatuses
    • Menus
    • Notifications
    • Ouath
    • Reports
    • Settings
    • Tracking
    • Translations
    • Updates
  • LandingPages
    • Activation
    • DataInterfaces
    • Management
    • Menus
    • NeedsAttention
    • Notices
    • Sidebars
    • Templates
    • Tracking
    • Variations
    • WelcomeScreen
    • Widgets
  • Leads
    • Activation
    • Akismet
    • BranchControl
    • BulkActions
    • Dashboard
    • Management
    • Notifications
    • Settings
    • Tracking
    • UserProfile
    • WPLogin
  • Mailer
    • Activation
    • Admin
    • ClickTracking
    • DataInterface
    • InboundForms
    • Leads
    • Management
    • Notifications
    • Scheduling
    • Sending
    • Settings
    • ShortcodesAndTokens
    • SparkPost
    • Templates
    • Unsubscribes
    • Variations
    • YoastSEO
  • None
  • Shared
    • APIs
    • CPT
    • DatabaseRoutines
    • DebugTricks
    • DoubleOptin
    • EventManagement
    • FieldMapping
    • InboundForms
    • LeadSorage
    • MarketingButton
    • Menus
    • Notifications
    • Shortcodes
    • ShortcodesAndTokens
    • StandAloneLicensing
    • Tracking
    • VisualEditor
  • xDepreciated

Classes

  • CTA_Activation
  • CTA_Activation_Update_Routines
  • CTA_Admin_Notices
  • CTA_Ajax_Listeners
  • CTA_Clone_Post
  • CTA_Conversion_Tracking
  • CTA_Dynamic_Widget
  • CTA_Enqueues
  • CTA_Load_Extensions
  • CTA_Menus
  • CTA_Metaboxes
  • CTA_Metaboxes_Global
  • CTA_Post_Type
  • CTA_Render
  • CTA_Settings
  • CTA_Static_Widget
  • CTA_Template_Manager
  • CTA_Template_Manager_List
  • CTA_Variations
  • CTA_WordPress_Leads
  • CTA_WordPress_SEO
  • Inbound_Ajax
  • Inbound_Akismet
  • Inbound_Analytics
  • Inbound_API
  • Inbound_API_Keys_Generation
  • Inbound_API_Keys_Table
  • Inbound_API_Wrapper
  • Inbound_Asset_Loader
  • Inbound_Automation_Action_Add_Remove_List
  • Inbound_Automation_Action_Add_Remove_Tag
  • Inbound_Automation_Action_Create_Lead
  • Inbound_Automation_Action_Create_User
  • Inbound_Automation_Action_Kill_Tasks
  • Inbound_Automation_Action_Relay_Data
  • Inbound_Automation_Action_Send_Email
  • Inbound_Automation_Action_Wait
  • Inbound_Automation_Activation
  • Inbound_Automation_Activation_Update_Routines
  • Inbound_Automation_Adminbar
  • Inbound_Automation_Lead_Profile
  • Inbound_Automation_Loader
  • Inbound_Automation_Plugin
  • Inbound_Automation_Post_Type
  • Inbound_Automation_Processing
  • Inbound_Automation_Query_Lead
  • Inbound_Automation_Query_User
  • Inbound_Automation_Trigger_inbound_double_optin_confirm
  • Inbound_Automation_Trigger_inbound_store_lead_post
  • Inbound_Automation_Trigger_inbound_track_link
  • Inbound_Automation_Trigger_Publish_Post
  • Inbound_Automation_Trigger_Save_Post_Deactivated
  • Inbound_Automation_Trigger_Set_Object_Terms
  • Inbound_Automation_Trigger_Update_Lead
  • Inbound_Automation_Trigger_User_Register
  • Inbound_Calls_To_Action_Plugin
  • Inbound_Confirm_Double_Optin
  • Inbound_Cron
  • Inbound_CTA_Quick_View
  • Inbound_Customizer
  • Inbound_Debug_Scripts
  • Inbound_Email_Meta
  • Inbound_Email_Preview
  • Inbound_Email_Template_Shortcodes
  • Inbound_Event_Report
  • Inbound_Events
  • Inbound_Events_Report
  • Inbound_Extension_Loads
  • Inbound_Forms
  • Inbound_Funnel_Reporting
  • Inbound_Impressions_Report
  • Inbound_Landing_Pages_Plugin
  • Inbound_Lead_Statuses
  • Inbound_Leads
  • Inbound_Leads_Custom_fields
  • Inbound_Leads_Plugin
  • Inbound_License
  • Inbound_List_Double_Optin
  • Inbound_Load_Shared
  • Inbound_Logging_Automation
  • Inbound_Login
  • Inbound_Mail_Daemon
  • Inbound_Mailer_ACF
  • Inbound_Mailer_Activation
  • Inbound_Mailer_Activation_Update_Routines
  • Inbound_Mailer_Ajax_Listeners
  • Inbound_Mailer_Clone_Post
  • Inbound_Mailer_Common_Settings
  • Inbound_Mailer_Customizer
  • Inbound_Mailer_Direct_Email_Leads
  • Inbound_Mailer_Enqueues
  • Inbound_Mailer_Forms_Integration
  • Inbound_Mailer_Load_Templates
  • Inbound_Mailer_Menus
  • Inbound_Mailer_Metaboxes
  • Inbound_Mailer_Notifications
  • Inbound_Mailer_Plugin
  • Inbound_Mailer_Post_Type
  • Inbound_Mailer_Scheduling
  • Inbound_Mailer_Settings
  • Inbound_Mailer_SparkPost
  • Inbound_Mailer_Stats_Report
  • Inbound_Mailer_Template_Manager
  • Inbound_Mailer_Template_Manager_List
  • Inbound_Mailer_Tokens
  • Inbound_Mailer_Tracking
  • Inbound_Mailer_Unsubscribe
  • Inbound_Mailer_Variations
  • Inbound_Mailer_WordPress_SEO
  • Inbound_Maintenance_Lists
  • Inbound_Marketing_Button
  • Inbound_Menus_Admin
  • Inbound_Menus_Adminbar
  • Inbound_Metaboxes_Automation
  • Inbound_Metaboxes_Leads
  • Inbound_Notifications
  • Inbound_Now_Store
  • Inbound_Options_API
  • Inbound_Pro_Activation
  • Inbound_Pro_Admin_Ajax_Listeners
  • Inbound_Pro_Automatic_Updates
  • Inbound_Pro_Downloads
  • Inbound_Pro_Notifications
  • Inbound_Pro_Oauth_Engine
  • Inbound_Pro_Plugin
  • Inbound_Pro_Settings
  • Inbound_Quick_View
  • Inbound_Reporting_Templates
  • Inbound_Search_And_Comment_Report
  • Inbound_Shared_ACF_BootStrap
  • Inbound_Shortcodes
  • Inbound_Shortcodes_Cookies
  • Inbound_Shortcodes_Fields
  • Inbound_SparkPost
  • Inbound_SparkPost_Stats
  • Inbound_Template_Utils
  • Inbound_Templating_Engine
  • Inbound_Tracking
  • Inbound_Translation_Updater
  • Inbound_Updater
  • Inbound_Upgrade_For_More_Reports
  • Inbound_Upgrade_Routines
  • Inbound_Visitor_Event_Report
  • Inbound_Visitor_Impressions_Report
  • Inbound_Visitors_Report
  • INBOUNDNOW_EXTEND
  • Landing_Pages_ACF
  • Landing_Pages_Activation
  • Landing_Pages_Activation_Update_Routines
  • Landing_Pages_Admin_Menus
  • Landing_Pages_Admin_Notices
  • Landing_Pages_Install
  • Landing_Pages_Load_Extensions
  • Landing_Pages_Meta
  • Landing_Pages_Metaboxes
  • Landing_Pages_Post_Type
  • Landing_Pages_Row_Actions
  • Landing_Pages_Settings
  • Landing_Pages_Sidebars
  • Landing_Pages_Split_Testing_Stats
  • Landing_Pages_Template_Management
  • Landing_Pages_Template_Switcher
  • Landing_Pages_Templates_List_Table
  • Landing_Pages_Variations
  • LandingPages_Welcome
  • Leads_Activation
  • Leads_Activation_Update_Routines
  • Leads_Admin_Notices
  • Leads_Batch_Processor
  • Leads_Branching
  • Leads_Dashboard
  • Leads_Field_Map
  • Leads_Manager
  • Leads_Post_Type
  • Leads_Settings
  • Leads_Tracking
  • Leads_User_Profile
  • LeadStorage
  • LP_EXTENSION_LICENSENING
  • LP_EXTENSION_UPDATER
  • LP_Variation_Rotation
  • LP_Widget_Conversion_Area

Functions

  • cta_check_active
  • cta_example_template_function
  • cta_load_dynamic_widget
  • CTA_Load_Extensions
  • cta_load_static_widget
  • CTA_Render
  • inbound_add_conversion_to_lead
  • inbound_automation_check_active
  • inbound_automation_load_definitions
  • inbound_automation_metaboxes
  • inbound_automation_processing
  • inbound_color
  • inbound_color_scheme
  • inbound_confirm_email_service_provider
  • inbound_email_kill_ie8
  • inbound_email_load_templates
  • inbound_form_add_lead_list
  • inbound_form_auto_publish
  • inbound_form_delete_transient
  • inbound_form_get_data
  • inbound_form_save
  • inbound_forms_change_columns
  • inbound_forms_cpt
  • inbound_forms_custom_columns
  • inbound_forms_default_content
  • inbound_get_form_names
  • inbound_get_parent_directory
  • inbound_Hex_2_RGB
  • inbound_inbound_email_example_template_function
  • inbound_load_lead_manager
  • inbound_load_token_engine
  • inbound_mailer_acf_integration
  • Inbound_Mailer_Common_Settings
  • Inbound_Mailer_Load_Templates
  • inbound_qtrans_disable
  • inbound_record_log
  • inbound_register_form_role_capabilities
  • inbound_shortcode_alert
  • inbound_shortcode_callout
  • inbound_shortcode_columns
  • inbound_shortcode_content_box
  • inbound_shortcode_divider
  • inbound_shortcode_empty_paragraph_fix
  • inbound_shortcode_four_fifth_columns
  • inbound_shortcode_full_columns
  • inbound_shortcode_gmap
  • inbound_shortcode_icon
  • inbound_shortcode_intro
  • inbound_shortcode_landing_pages
  • inbound_shortcode_leadp
  • inbound_shortcode_list_icons
  • inbound_shortcode_one_fifth_columns
  • inbound_shortcode_one_fourth_columns
  • inbound_shortcode_one_half_columns
  • inbound_shortcode_one_third_columns
  • inbound_shortcode_portfolio
  • inbound_shortcode_pricing
  • inbound_shortcode_profile
  • inbound_shortcode_social_links
  • inbound_shortcode_tabs
  • inbound_shortcode_teaser
  • inbound_shortcode_testimonial
  • inbound_shortcode_three_fifth_columns
  • inbound_shortcode_three_fourth_columns
  • inbound_shortcode_two_fifth_columns
  • inbound_shortcode_two_third_columns
  • inbound_shortcode_video
  • inbound_store_lead
  • inbound_template_brightness
  • inbound_template_color
  • Inbound_Templating_Engine
  • inbound_travis_check
  • inboundnow_add_master_license
  • json_encode_fallback
  • landingpage_fix_known_wp_title_isses
  • landingpages_is_active
  • load_CTA_Settings
  • load_CTA_Template_Manager
  • load_Inbound_API_Keys_Generation
  • load_Inbound_Lead_Statuses
  • load_Inbound_Leads_Custom_fields
  • load_inbound_mail_daemon
  • load_Inbound_Mailer_Settings
  • load_Inbound_Mailer_Template_Manager
  • load_Inbound_Pro_Downloads
  • lp_ab_testing_get_current_variation_id
  • lp_add_option
  • lp_body_class
  • lp_check_active
  • lp_content_area
  • lp_conversion_area
  • lp_discover_important_wrappers
  • lp_footer
  • lp_generate_drowndown
  • lp_get_parent_directory
  • lp_get_value
  • lp_global_config
  • lp_head
  • lp_in_admin_header
  • lp_init
  • lp_list_feature
  • lp_load_widgets
  • lp_main_headline
  • lp_manage_templates
  • lp_move_template_files
  • lp_rebuild_attributes
  • lp_templates_upload
  • mailer_check_active
  • wp_cta_check_active
  • wp_cta_kill_ie8
  • wp_cta_load_calls_to_action
  • wp_leads_get_page_final_id
  • wpl_url_to_postid
  • wpleads_add_lead_to_list
  • wpleads_check_active
  • wpleads_get_lead_lists_as_array
  • Overview
  • Package
  • Class
  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 for  registering the landing page CPT and expanding the CPT's listing page with additional data
 * @package LandingPages
 * @subpackage Management
 */


class Landing_Pages_Post_Type {

    function __construct() {
        self::load_hooks();
    }

    /**
     * setup hooks and filters
     */
    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);

        /* adds & managed collumns */
        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);

        /* disable SEO Filter */
        if ((isset($_GET['post_type']) && ($_GET['post_type'] == 'landing-page'))) {
            add_filter('wpseo_use_page_analysis', '__return_false');
        }

        /* adds category to landing page sorting filter */
        add_action('restrict_manage_posts', array( __CLASS__, 'sort_by_category' ) );
        add_filter('parse_query', array( __CLASS__ , 'sort_by_category_prepare_query' ));

        /* make columns sortable */
        add_filter('manage_edit-landing-page_sortable_columns', array( __CLASS__ , 'define_sortable_columns' ));

        /* add styling handlers to custom post states */
        add_filter('display_post_states', array( __CLASS__ , 'filter_custom_post_states' ) );

        /* enqueue scripts for landing page listings */
        add_action( 'admin_enqueue_scripts' , array(__CLASS__, 'enqueue_admin_scripts' ) );


        /* enqueue scripts for landing page listings */
        if (isset($_GET['dont_save'])
            || isset($_GET['iframe_window'])
            || isset($_GET['inbound-preview']) ) {
            add_action('wp_enqueue_scripts', array(__CLASS__, 'stop_stat_tracking') , 20);
        }

        /* load iframed preview page when preview is clicked from AB stats box */
        if (isset($_GET['iframe_window'])) {
            /*add_action('wp_head', array( __CLASS__ , 'load_preview_iframe' ) );*/
            add_action('admin_enqueue_scripts', array(__CLASS__, 'enqueue_scripts_iframe') );
        }

        /* Miscelanous wp_head - Should probably be refactored into enqueue - h */
        add_action('wp_head', array(__CLASS__, 'wp_head' ));

    }

    /**
     * register post type
     */
    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 );
    }

    /**
     * Register Role Capabilities
     */
    public static function register_role_capabilities() {
        // Add the roles you'd like to administer the custom post types
        $roles = array('inbound_marketer','administrator');

        // Loop through each role and assign capabilities
        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' );
        }
    }

    /**
     * Register landing page taxonomies
     */
    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);
    }



    /**
     * Register columns
     *
     * @param $columns
     * @return array
     */
    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;
    }

    /**
     * Enqueue admin scripts
     */
    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);

        /* listing page only */
        if ($screen->id == 'edit-landing-page' ) {
            /* load stat clear handlers */
            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');

        }



        /* load css when landing page iframe preview is being loaded from within wp-admin */
        if (isset($_GET['iframe_window'])) {
            wp_enqueue_style('lp_ab_testing_customizer_css', LANDINGPAGES_URLPATH . 'assets/css/frontend/customizer-preview.css', array() , null);
        }
    }

    /**
     * Enqueue frontend scripts
     */
    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);


    }

    /**
     * Display column data
     * @param $columns
     * @return array
     */
    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;
        }
    }


    /**
     * Define Sortable Columns
     */
    public static function define_sortable_columns($columns) {

        return array(
            'title'             => 'title',
            'impressions'       => 'impressions',
            'actions'           => 'actions',
            'cr'                => 'cr'
        );

    }

    /**
     * Define Row Actions
     */
    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>';

            /* show shortcode */
            $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;

    }


    /**
     * Needs further refactoring & documentation
     * @param $type_of_stat
     * @return float|int
     */
    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;
        }

    }

    /**
     * Adds rewrite rules
     */
    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/";
        }

        /* handles local environment */
        $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');
        }

    }

    /**
     * Adds conditions to rewrite rules
     * @param $rules
     * @return string
     */
    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);
        }

        /* print_r($rules_array);exit; */


        $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;
    }


    /**
     * Show stats container on Landing Page lists page
     */
    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); /* convert to letter */
            $impressions = Landing_Pages_Variations::get_impressions($post->ID, $vid);
            $conversions = Landing_Pages_Variations::get_conversions($post->ID, $vid);

            /* get variation status */
            $status = Landing_Pages_Variations::get_variation_status( $post->ID, $vid ); /* Current status */

            /* Get variation notes */
            $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); /* best conversion rate */
        if ($winning_cr != 0) {
            echo "<span class='variation-winner-is'>" . $post->ID . "-" . $winning_cr . "</span>";
        }
        /*echo "Total Visits: " . $impressions; */
        /*echo "Total Conversions: " . $conversions; */

    }


    /**
     * Show dropdown of landing page categories
     */
    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
                )
            );
        }
    }

    /**
     * Convert the category id to the taxonomy id during a query
     */
    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;
        }
    }

    /**
     * Add styling handlers to custom post states
     */
    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;
    }

    /**
     * Loads preview iframe. Currently disabled. Plans to update @DavidWells
     */
    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">

            #variation-list {
                position: absolute;
                top: 0px;
                left: 0px;
                padding-left: 5px;
            }

            #variation-list h3 {
                text-decoration: none;
                border-bottom: none;
            }

            #variation-list div {
                display: inline-block;
            }

            #current_variation_id, #current-post-id {
                display: none !important;
            }

        </style>
        <script type="text/javascript">
            jQuery(document).ready(function ($) {
                var current_page = jQuery("#current_variation_id").text();
                /* reload the iframe preview page (for option toggles) */
                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
    }

    /**
     * Load JS to disable stats from working for preview windows
     */
    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);
    }

    /**
     * Load misc wp_head
     */
    public static function wp_head() {
        global $post;

        if (isset($post) && $post->post_type !=='landing-page') {
            return;
        }
        /* if is tiny iframe preview window force these styles */
        if (isset($_GET['dont_save'])) { ?>
            <style type="text/css">
                :root:root:root #wpadminbar {
                    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">
                    /* Then strip params if pushstate exists */
                    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);

                            /* reverse iteration as may be destructive */
                            for (var i= pars.length; i-- > 0;) {
                                //idiom for string.startsWith
                                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
            }
        }

    }
}

/* Load Post Type Pre Init */
new Landing_Pages_Post_Type();
Inbound Pro Plugin - PHP Codex API documentation generated by ApiGen