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:  669:  670:  671:  672:  673:  674:  675:  676:  677:  678:  679:  680:  681:  682:  683:  684:  685:  686:  687:  688:  689:  690:  691:  692:  693:  694:  695:  696:  697:  698:  699:  700:  701:  702:  703:  704:  705:  706:  707:  708:  709:  710:  711:  712:  713:  714:  715:  716:  717:  718:  719:  720:  721:  722:  723:  724:  725:  726:  727:  728:  729:  730:  731:  732:  733:  734:  735:  736:  737:  738:  739:  740:  741:  742:  743:  744:  745:  746:  747:  748:  749:  750:  751:  752:  753:  754:  755:  756:  757:  758:  759:  760:  761:  762:  763:  764:  765:  766:  767:  768:  769:  770:  771:  772:  773:  774:  775:  776:  777:  778:  779:  780:  781:  782:  783:  784:  785:  786:  787:  788:  789:  790:  791:  792:  793:  794:  795:  796:  797:  798:  799:  800:  801:  802:  803:  804:  805:  806:  807:  808:  809:  810:  811:  812:  813:  814:  815:  816:  817:  818:  819:  820:  821:  822:  823:  824:  825:  826:  827:  828:  829:  830:  831:  832:  833:  834:  835:  836:  837:  838:  839:  840:  841:  842:  843:  844:  845:  846:  847:  848:  849:  850:  851:  852:  853:  854:  855:  856:  857:  858:  859:  860:  861:  862:  863:  864:  865:  866:  867:  868:  869:  870:  871:  872:  873:  874:  875:  876:  877:  878:  879:  880:  881:  882:  883:  884:  885:  886:  887:  888:  889:  890:  891:  892:  893:  894:  895:  896:  897:  898:  899:  900:  901:  902:  903:  904:  905:  906:  907:  908:  909:  910:  911:  912:  913:  914:  915:  916:  917:  918:  919:  920:  921:  922:  923:  924:  925:  926:  927:  928:  929:  930:  931:  932:  933:  934:  935:  936:  937:  938:  939:  940:  941:  942:  943:  944:  945:  946:  947:  948:  949:  950:  951:  952:  953:  954:  955:  956:  957:  958:  959:  960:  961:  962:  963:  964:  965:  966:  967:  968:  969:  970:  971:  972:  973:  974:  975:  976:  977:  978:  979:  980:  981:  982:  983:  984:  985:  986:  987:  988:  989:  990:  991:  992:  993:  994:  995:  996:  997:  998:  999: 1000: 1001: 1002: 1003: 1004: 1005: 1006: 1007: 1008: 1009: 1010: 1011: 1012: 1013: 1014: 1015: 1016: 1017: 1018: 1019: 1020: 1021: 1022: 1023: 1024: 1025: 1026: 1027: 1028: 1029: 1030: 1031: 1032: 1033: 1034: 1035: 1036: 1037: 1038: 1039: 1040: 1041: 1042: 1043: 1044: 1045: 1046: 1047: 1048: 1049: 1050: 1051: 1052: 1053: 1054: 1055: 1056: 1057: 1058: 1059: 1060: 1061: 1062: 1063: 1064: 1065: 1066: 1067: 1068: 1069: 1070: 1071: 1072: 1073: 1074: 1075: 1076: 1077: 1078: 1079: 1080: 1081: 1082: 1083: 1084: 1085: 1086: 1087: 1088: 1089: 1090: 1091: 1092: 1093: 1094: 1095: 1096: 1097: 1098: 1099: 1100: 1101: 1102: 1103: 1104: 1105: 1106: 1107: 1108: 1109: 1110: 1111: 1112: 1113: 1114: 1115: 1116: 1117: 1118: 1119: 1120: 1121: 1122: 1123: 1124: 
<?php

/**
 * Class adds 'Bulk Actions' section that provides for batch actions against lead searches. This class is meant to improve on the
 *
 * @package Leads
 * @subpackage BulkActions
 */


class Leads_Manager {

    static $relation;
    static $page;
    static $per_page;
    static $paged;
    static $order;
    static $orderby;
    static $orderbys;
    static $orderbys_flip;
    static $num; /* number of leads affected */
    static $on;
    static $what;
    static $tag;
    static $keyword;
    static $query; /* query object */
    static $taxonomies; /* array of wp-lead taxonomies */
    static $statuses; /* array of wp-lead taxonomies */

    /**
     *  Initiate class
     */
    public function __construct() {

        self::load_static_vars();
        self::load_hooks();

    }

    /**
     *  Load hooks and filters
     */
    public static function load_hooks() {

        /* load static vars */
        add_action('admin_init', array(__CLASS__, 'load_static_vars'));
        /* load admin scripts */
        add_action('admin_enqueue_scripts', array(__CLASS__, 'enqueue_admin_scripts'));
        /* perform lead manage actions by ajax*/
        add_action('wp_ajax_perform_actions', array(__CLASS__, 'ajax_perform_actions'));
        /* ajax listener for loading more leads */
        add_action('wp_ajax_leads_ajax_load_more_leads', array(__CLASS__, 'ajax_load_more_leads'));
        /* ajax listener for deleting lead from list */
        add_action('wp_ajax_leads_delete_from_list', array(__CLASS__, 'ajax_delete_from_list'));
        /* ajax listener export opration */
        add_action('wp_ajax_leads_export_list', array(__CLASS__, 'ajax_leads_export_list'));


    }

    /**
     *  Load constants
     */
    public static function load_static_vars() {

        if (!isset($_REQUEST['page']) || $_REQUEST['page'] != 'lead_management') {
            return;
        }

        /* clean POST and REQUEST arrays of added slashes */
        $_POST = stripslashes_deep($_POST);
        $_REQUEST = stripslashes_deep($_REQUEST);

        /* set ordering & paging vars */
        self::$per_page = 60;
        self::$page = empty($_REQUEST['pull_page']) ? 1 : intval($_REQUEST['pull_page']);
        self::$paged = empty($_REQUEST['paged']) ? 1 : intval($_REQUEST['paged']);
        self::$orderby = (isset($_REQUEST['orderby'])) ? sanitize_text_field($_REQUEST['orderby']) : '';
        self::$order = (isset($_REQUEST['order'])) ? strtoupper(sanitize_text_field($_REQUEST['order'])) : 'ASC';

        /* set ordering vars */
        self::$orderbys = array(
            __('Date First Created', 'inbound-pro' ) => 'date',
            __('Date Last Modified', 'inbound-pro' ) => 'modified',
            __('Alphabetical Sort', 'inbound-pro' ) => 'title',
            __('Status', 'inbound-pro' ) => 'post_status'
        );

        /* set ordering vars */
        self::$orderbys_flip = array_flip(self::$orderbys);

        /* number of leads affected by action if any */
        self::$num = (isset($_REQUEST['num'])) ? intval($_REQUEST['num']) : 0;

        self::$what = (isset($_REQUEST['what'])) ? sanitize_text_field($_REQUEST['what']) : "";

        self::$relation = (isset($_REQUEST['relation'])) ? sanitize_text_field($_REQUEST['relation']) : "AND";
        self::$tag = (isset($_REQUEST['t'])) ? sanitize_text_field($_REQUEST['t']) : '';

        self::$keyword = (isset($_REQUEST['s'])) ? sanitize_text_field($_REQUEST['s']) : '';

        self::$taxonomies = get_object_taxonomies('wp-lead', 'objects');

        self::$statuses = Inbound_Leads::get_lead_statuses();

    }

    /**
     *  Enqueues admin scripts
     */
    public static function enqueue_admin_scripts() {
        $screen = get_current_screen();

        if ($screen->id != 'wp-lead_page_lead_management') {
            return;
        }

        wp_enqueue_script(array('jquery', 'jqueryui', 'jquery-ui-selectable', 'editor', 'thickbox', 'media-upload'));

        wp_enqueue_script('selectjs', INBOUNDNOW_SHARED_URLPATH . 'assets/includes/Select2/select2.min.js', array() , null , false );
        wp_enqueue_style('selectjs', INBOUNDNOW_SHARED_URLPATH . 'assets/includes/Select2/select2.min.css');


        wp_enqueue_script('tablesort', WPL_URLPATH . 'assets/js/management/tablesort.min.js');

        wp_enqueue_script('light-table-filter', WPL_URLPATH . 'assets/js/management/light-table-filter.min.js');
        wp_enqueue_script('modernizr', WPL_URLPATH . 'assets/js/management/modernizr.custom.js');
        wp_enqueue_script('tablesort', WPL_URLPATH . 'assets/js/management/tablesort.min.js');
        wp_enqueue_script('jquery-dropdown', WPL_URLPATH . 'assets/js/management/jquery.dropdown.js');
        wp_enqueue_script('jquery-ui', WPL_URLPATH . 'assets/js/management/jquery-ui.js');
        wp_enqueue_script('bulk-manage-leads', WPL_URLPATH . 'assets/js/management/admin.js' );

        wp_localize_script('bulk-manage-leads', 'bulk_manage_leads', array('admin_url' => admin_url('admin-ajax.php'), 'taxonomies' => self::$taxonomies ));
        wp_enqueue_style('wpleads-list-css', WPL_URLPATH . '/assets/css/admin-management.css');
        wp_enqueue_style('jquery-ui-css', WPL_URLPATH . '/assets/css/jquery-ui.css');
        wp_admin_css('thickbox');
        add_thickbox();
    }

    /**
     *  Displays main UI container
     */
    public static function display_ui() {
        global $wpdb;

        /* listen for and display notications */
        self::display_notifications();
        /* display header */
        self::display_headers();
        /* display filters */
        self::display_filters();
        /* build query */
        self::build_query();
        /* display pagination if applicable */
        self::display_pagination();
        /* display query reseults messages */
        self::display_results_message();
        /* display results table */
        self::display_results_table();
        /* display actions */
        self::display_row_actions();

    }


    /**
     *  display notifications
     */
    public static function display_notifications() {

        // Deal with any update messages we might have:
        if (!isset($_REQUEST['done'])) {
            return;
        }

        switch ($_REQUEST['done']) {
            case 'add':
                $message = sprintf(__("Added %d posts to the list '%s'", 'inbound-pro' ), self::$num, self::$what);
                break;
            case 'remove':
                $message = sprintf(__("Removed %d posts from the list '%s'.", 'inbound-pro' ), self::$num, self::$what);
                break;
            case 'tag':
                $message = sprintf(__("Tagged %d posts with &ldquo; %s &rdquo;", 'inbound-pro' ), self::$num, self::$what);
                break;
            case 'untag':
                $message = sprintf(__("Untagged %d posts with '%s'", 'inbound-pro' ), self::$num, self::$what);
                break;
            case 'delete_leads':
                $message = sprintf(__("%d leads permanently deleted", 'inbound-pro' ), self::$num);
                break;
        }

        ?>
        <div id='message' class='updated'>
            <p><strong><?php echo $message; ?></strong></p>
        </div>
        <?php
    }

    /**
     *  display headers
     */
public static function display_headers() {

    ?>
    <div class="wrap">
        <h2><?php _e('Lead Bulk Management', 'inbound-pro' ); ?></h2>

        <?php

        /* echo starter text if search not being ran yet */
        if (!isset($_REQUEST['submit'])) {
            echo '<p class="starter-text">' . __('To get started, select the lead criteria below to see all matching leads.', 'inbound-pro' ) . '</p>';
        }

        /* hide current page div */
        echo "<div id='paged-current'>" . self::$paged . "</div>";

        }

        /**
         *  Display filters
         */
        public static function display_filters() {
            ?>
            <div id="filters" class="inbound-lead-filters">
                <form id="lead-management-form" method="get" action="edit.php">
                    <input type="hidden" name="page" value="lead_management"/>
                    <input type="hidden" name="post_type" value="wp-lead"/>

                    <div id="top-filters"><?php
                        foreach (self::$taxonomies as $key => $taxonomy) {
                            if (!$taxonomy->hierarchical) {
                                //continue;
                            }
                            ?>

                            <div id="inbound-filter">
                                <div class="filter-label">
                                    <label for="taxonomy"><?php _e(sprintf('Select by %s:', $taxonomy->labels->singular_name), 'inbound-pro' ); ?></label>
                                </div>
                                <?php echo self::build_taxonomy_select($taxonomy, 'multiple'); ?>
                            </div>
                            <?php
                        }
                        ?>
                        <div id="inbound-filter">
                            <div class="filter-label">
                                <label for="wp_lead_status"><?php _e('Select by Status:', 'inbound-pro' ); ?>
                                </label>
                            </div>
                            <?php echo self::build_lead_status_select(); ?>
                        </div>
                        <div id="inbound-filter">
                            <div class="filter-label">
                                <label for="orderby"><?php _e('Match Condition:', 'inbound-pro' ); ?></label></div>
                            <select name="relation" id="relation">
                                <option value="AND" <?php echo(self::$relation == 'AND' ? ' selected="selected"' : ''); ?>><?php _e('Match All', 'inbound-pro' ); ?></option>
                                <option value="OR" <?php echo(self::$relation == 'OR' ? ' selected="selected"' : 'test'); ?>><?php _e('Match Any', 'inbound-pro' ); ?></option>

                            </select>
                        </div>
                    </div>
                    <div id="bottom-filters">
                        <div class="filter" id="lead-sort-by">
                            <div class="filter-label"><label for="orderby"><?php _e('Sort by:', 'inbound-pro' ); ?></label>
                            </div>
                            <select name="orderby" id="orderby">
                                <?php
                                foreach (self::$orderbys as $title => $value) {
                                    $selected = (self::$orderby == $value) ? ' selected="selected"' : '';
                                    echo "<option value='$value'$selected>$title</option>\n";
                                }
                                ?>
                            </select>
                            <select name="order" id="order">
                                <option value="asc" <?php (self::$order == 'ASC' ? ' selected="selected"' : ''); ?>><?php _e('Ascending', 'inbound-pro' ); ?></option>
                                <option value="desc" <?php (self::$order == 'DESC' ? ' selected="selected"' : ''); ?>><?php _e('Descending', 'inbound-pro' ); ?></option>
                            </select>
                        </div>


                        <div class="filter" id="lead-keyword-filter">
                            <label for="s"><?php _e('Keyword:', 'inbound-pro' ); ?></label>
                            <input type="text" name="s" id="s" value="<?php echo htmlentities(self::$keyword); ?>" title="<?php _e('Use % for wildcards.', 'inbound-pro' ); ?>"/>
                        </div>


                        <div class="filter" id="lead-tag-filter">
                            <label for="s"><?php _e('Tag:', 'inbound-pro' ); ?></label>
                            <input type="text" name="t" id="t" value="<?php echo htmlentities(self::$tag); ?>" title="'foo, bar': posts tagged with 'foo' or 'bar'. 'foo+bar': posts tagged with both 'foo' and 'bar'"/>
                        </div>

                        <div class="filter">
                            <input type="submit" class="button-primary" value="<?php _e('Search Leads', 'inbound-pro' ); ?>" name="submit"/>
                        </div>

                    </div>
                </form>
            </div>
            <?php
        }

        /**
         *  Display hidden input fields
         */
        public static function display_hidden_action_fields() {

            wp_nonce_field('lead_management-edit');

            if (isset($_REQUEST['s']) && !empty($_REQUEST['s'])) {
                echo '<input type="hidden" name="s" value="' . urlencode($_REQUEST['s']) . '" />';
            }

            if (isset($_REQUEST['t']) && !empty($_REQUEST['t'])) {
                echo '<input type="hidden" name="t" value="' . urlencode($_REQUEST['t']) . '" />';
            }
        }

        /**
         *  Display pagination
         */
        public static function display_pagination() {

            $pagination = '';
            if (isset($query) && $query->max_num_pages > 1) {
                $current = preg_replace('/&?paged=[0-9]+/i', '', strip_tags($_SERVER['REQUEST_URI'])); // I'll happily take suggestions on a better way to do this, but it's 3am so

                $pagination .= "<div class='tablenav-pages'>";

                if (self::$paged > 1) {
                    $prev = self::$paged - 1;
                    $pagination .= "<a class='prev page-numbers' href='$current&amp;paged=$prev'>&laquo; " . __('Previous', 'inbound-pro' ) . "</a>";
                }

                for ($i = 1; $i <= $query->max_num_pages; $i++) {
                    if ($i == self::$paged) {
                        $pagination .= "<span class='page-numbers current'>$i</span>";
                    } else {
                        $pagination .= "<a class='page-numbers' href='$current&amp;paged=$i'>$i</a>";
                    }
                }

                if (self::$paged < $query->max_num_pages) {
                    $next = self::$paged + 1;
                    $pagination .= "<a class='next page-numbers' href='$current&amp;paged=$next'>" . __('Next', 'inbound-pro' ) . " &raquo;</a>";
                }

                $pagination .= "</div>";
            }

            echo $pagination;

        }

        /**
         *  Display results query
         */
        public static function display_results_message() {
            // Criteria were given, but no posts were matched.
            if (empty(self::$query->posts)) {
                echo '<p>' . __('No posts matched that criteria, sorry! Try again with something different.', 'inbound-pro' ) . '</p>';
                return;
            }

            echo '<div style="margin-top:20px;font-style:italic">';
            echo '      <div id="display-lead-total">';
            echo '          ' . __('search returned ', 'inbound-pro' ) . '<strong><span id="lead-total-found">' . self::$query->found_posts . ' </span></strong>' . __('results', 'inbound-pro' );
            echo '      </div>';
            echo '      <div id="display-lead-count">';
            echo '          <i class="lead-spinner"></i>';
            echo '          <span id="lead-count-text">' . __('Grabbing Matching Leads', 'inbound-pro' ) . '</span>';
            echo '      </div>';
            echo '  <div class="table-search">';
            echo '      <input type="search" class="light-table-filter" data-table="widefat" placeholder="' . __('Filter Results Below', 'inbound-pro' ) . '" /><span id="search-icon"></span>';

            echo '  </div>';
            echo '</div>';

        }


        /**
         *  Display results table
         */
        public static function display_results_table() {

        if (!isset(self::$query->posts)) {
            return;
        }

        ?>
        <form method="post" id="man-table" action="<?php echo admin_url('admin.php'); ?>">
            <input type="hidden" name="action" value="lead_action"/>
            <?php
            if (isset($_GET['wplead_list_category'])){
                foreach($_GET['wplead_list_category'] as $list_id) {
                    echo '<input type="hidden" name="wplead_list_category[]" value="'. (int) $list_id.'"/>';
                }
            }
            ?>
            <div id="posts">

                <table class="widefat" id="lead-manage-table">
                    <thead>
                    <tr>
                        <th class="checkbox-header no-sort" scope="col">
                            <input type="checkbox" id="toggle" title="Select all posts"/></th>
                        <th class="count-sort-header" scope="col">#</th>
                        <th scope="col"><?php _e('Date', 'inbound-pro' ); ?></th>
                        <th scope="col"><?php _e('Email', 'inbound-pro' ); ?></th>
                        <th scope="col"><?php _e('Current Lists', 'inbound-pro' ); ?></th>
                        <th scope="col"><?php _e('Current Tags', 'inbound-pro' ); ?></th>
                        <th scope="col" class="no-sort"><?php _e('View', 'inbound-pro' ); ?></th>
                        <th scope="col"><?php _e('ID', 'inbound-pro' ); ?></th>
                        <?php do_action('inbound_bulk_lead_action_list_header');?>
                    </tr>
                    </thead>
                    <tbody id="the-list">
                    <?php

                    $loop_count = 1;
                    $i = 0;

                    foreach (self::$query->posts as $post) {

                        echo '<tr' . ($i++ % 2 == 0 ? ' class="alternate"' : '') . '>';

                        /* show checkbox */
                        echo '<td><input class="lead-select-checkbox" type="checkbox" name="ids[]" value="' . $post->ID . '" /></td>';

                        /* show count */
                        echo '<td class="count-sort"><span>' . $loop_count . '</span></td>';

                        /* show publish date */
                        echo '<td>';
                        if ('0000-00-00 00:00:00' == $post->post_date) {
                            _e('Unpublished', 'inbound-pro' );
                        } else {
                            echo date(__('Y/m/d'), strtotime($post->post_date));
                        }
                        echo '</td>';

                        /* show email */
                        echo '<td>';
                        echo '  <span class="lead-email">' . sanitize_text_field($post->post_title) . '</span>';
                        echo '</td>';

                        /* show lists */
                        echo '<td class="list-column-row">';
                        $terms = wp_get_post_terms($post->ID, 'wplead_list_category', 'id');
                        foreach ($terms as $term) {
                            echo '<span class="list-pill">' . $term->name . ' <i title="Remove This lead from the ' . $term->name . ' list" class="remove-from-list" data-lead-id="' . $post->ID . '" data-list-id="' . $term->term_id . '"></i></span> ';
                        }
                        echo '</td>';

                        /* show tags */
                        echo '<td class="tags-column-row">';
                        $tags = wp_get_post_terms($post->ID, 'lead-tags', 'id');

                        if ($tags) {
                            foreach ($tags as $tag) {
                                echo "<a title='Click to Edit Lead Tag Name' target='_blank' href='" . admin_url('edit-tags.php?action=edit&taxonomy=lead-tags&tag_ID=' . $tag->term_id . '&post_type=wp-lead') . "'>$tag->name</a>, ";
                            }
                        } else {
                            _e('No tags', 'inbound-pro' );
                        }
                        echo '</td>';

                        /* show link to lead */
                        echo '<td>';
                        echo '  <a class="thickbox inbound-thickbox" href="post.php?action=edit&post=' . $post->ID . '&amp;small_lead_preview=true&amp;TB_iframe=true&amp;width=1345&amp;height=244">' . __('View', 'inbound-pro' ) . '</a>';
                        echo '</td>';

                        /* show lead id */
                        echo '<td>' . $post->ID . '</td>';

                        /*add custom row content*/
                        do_action('inbound_bulk_lead_action_list_item', $post);

                        echo '</tr>';
                        $loop_count++;
                    }
                    echo '</tbody>';
                    echo '</table>';

                    }

                    /**
                     *  Display Row Actions
                     */
                    public static function display_row_actions() {
                    ?>
                    </tbody>
                </table>
            </div>



            <div id="all-actions" class="tablenav">

                <div id="inbound-lead-management">
                    <span class="lead-actions-title"><?php _e('What do you want to do with the selected leads?', 'inbound-pro' ); ?></span>

                    <div id="controls">
                        <?php
                        self::display_action_controls();
                        ?>
                    </div>
                    <div id="lead-action-triggers">
                        <div class="action" id="lead-export">
                            <a href="#lead-export-process" class="manage-remove button-primary button export-leads-csv button-primary button"  title="<?php _e('Exports selected leads into a CSV format.', 'inbound-pro' ); ?>"> <?php _e('Exports selected as CSV', 'inbound-pro' ); ?></a>

                            <a style="visibility: hidden;" id="export-leads" href="#lead-export-process"> <?php _e('Exports selected as CSV', 'inbound-pro' ); ?></a>
                        </div>
                        <div class="action" id="lead-update-lists">
                            <label for="lead-update-lists"><?php _e('Choose List:', 'inbound-pro' ); ?></label>
                            <?php

                            /* get available terms in taxonomy */
                            $terms = get_terms('wplead_list_category', array('hide_empty' => false));

                            /* setup the select */
                            echo '<select name="wplead_list_category_action">';

                            /* print the first option */
                            echo '<option class="" value="" selected="selected">' . __('Select lead list ', 'inbound-pro' ) . '</option>';

                            /* loop through terms and create options */
                            foreach ($terms as $term) {
                                echo '<option class="" value="' . $term->term_id . '" >' . $term->name . ' (' . $term->count . ')</option>';
                            }

                            /* end select input */
                            echo '</select>';

                            ?>
                            <input type="submit" class="button-primary button" name="add" value="<?php _e('Add to', 'inbound-pro' ) ?>" title="<?php _e('Add the selected posts to this category.', 'inbound-pro' ); ?>"/>
                            <input type="submit" class="manage-remove button-primary button" name="remove" value="<?php _e('Remove from', 'inbound-pro' ) ?>" title="<?php _e('Remove the selected posts from this category.', 'inbound-pro' ); ?>"/>
                        </div>

                        <div class="action" id="lead-update-tags">
                            <label for="lead-update-tags"><?php _e('Tags:', 'inbound-pro' ); ?></label>
                            <input type="text" id="inbound-lead-tags-input" name="tags" placeholder="<?php _e('Separate multiple tags with commas. ', 'inbound-pro' ); ?>" title="<?php _e('Separate multiple tags with commas.', 'inbound-pro' ); ?>"/>
                            <input type="submit" name="replace_tags" class="manage-tag-replace button-primary button" value="<?php _e('Replace', 'inbound-pro' ); ?>" title="<?php _e('Replace the selected leads\'s current tags with these ones. Warning this will delete current tags and replace them ', 'inbound-pro' ); ?>"/>
                            <input type="submit" name="tag" class="manage-tag-add button-primary button" value="<?php _e('Add', 'inbound-pro' ) ?>" title="<?php _e('Add tags to the selected leads without altering the leads\' existing tags', 'inbound-pro' ); ?>"/>
                            <input type="submit" name="untag" class="manage-remove button-primary button" value="<?php _e('Remove', 'inbound-pro' ) ?>" title="<?php _e('Remove these tags from the selected leads.', 'inbound-pro' ); ?>"/>
                        </div>

                        <div class="action" id="lead-update-meta">
                            <label for="lead-update-meta"><?php _e('Meta:', 'inbound-pro' ); ?></label>
                            <input type="text" name="meta_val" title="<?php _e('Separate multiple tags with commas.', 'inbound-pro' ); ?>"/>
                            <input type="submit" name="replace_meta" value="<?php _e('Replace', 'inbound-pro' ); ?>" title="<?php _e('Replace the selected posts\' current meta values with these ones.', 'inbound-pro' ); ?>"/>
                            <input type="submit" name="meta" value="<?php _e('Add', 'inbound-pro' ); ?>" title="<?php _e('Add these meta values to the selected posts without altering the posts\' existing tags.', 'inbound-pro' ); ?>"/>
                            <input type="submit" name="unmeta" value="<?php _e('Remove', 'inbound-pro' ); ?>" title="<?php _e('Remove these meta values from the selected posts.', 'inbound-pro' ); ?>"/>
                        </div>

                        <div class="action" id="lead-delete">
                            <label for="lead-delete" id="del-label"><span style="color:red;"><?php _e('Delete Selected Leads (Warning! There is no UNDO):', 'inbound-pro' ); ?></span></label>

                            <input type="submit" class="manage-remove button-primary button" name="delete_leads" value="<?php _e('Permanently Delete Selected Leads', 'inbound-pro' ) ?>" title="<?php _e('This will delete the selected leads from your database. There is no undo.', 'inbound-pro' ); ?>"/>

                        </div>
                        <?php do_action('inbound_bulk_lead_action_triggers');?>
                    </div>
                </div>

                <?php
                self::display_hidden_action_fields();
                ?>

            </div>
        </form>
        <div id="lead-export-process" style="display: none;">
            <table id="progress-table" class="widefat">
                <thead>
                <tr>
                    <th width="50%" scope="col" class="">Count</th>
                    <th width="50%" scope="col" class="">Progress</th>
                </tr>
                </thead>
                <tbody id="the-progress-list" class="ui-selectable">
                </tbody>
            </table>
            <div class="download-leads-csv"></div>
        </div>

    </div>




    <?php
}

    /**
     *  Display action controls
     */
    public static function display_action_controls() {
        ?>
        <section id="set-3">
            <div class="fleft">
                <select id="cd-dropdown" class="cd-select">
                    <option value="-1" selected class="db-drop-label"><?php _e('Choose action to apply to selected leads', 'inbound-pro' ); ?></option>
                    <option value="lead-export" class="action-symbol lead-export-symbol db-drop-label"><?php _e('Export Selected Leads as CSV', 'inbound-pro' ); ?></option>
                    <option value="lead-update-lists" class="action-symbol lead-update-lists-symbol db-drop-label"><?php _e('Add or Remove Selected Leads from Lists', 'inbound-pro' ); ?></option>
                    <option value="lead-update-tags" class="action-symbol lead-update-tags-symbol db-drop-label"><?php _e('Add or Remove Tags to Selected Leads', 'inbound-pro' ); ?></option>
                    <option value="lead-delete" class="action-symbol lead-update-delete-symbol db-drop-label"><?php _e('Permanently Delete Selected Leads', 'inbound-pro' ); ?></option>
                    <?php do_action('inbound_bulk_lead_action_controls');?>
                </select>
            </div>
        </section>
        <script>
            jQuery(document).ready(function ($) {
                jQuery(function () {
                    jQuery('#cd-dropdown').dropdown();
                });

                jQuery("body").on('click', '.cd-dropdown li', function () {
                    var value = jQuery(this).attr('data-value'); // get selected value
                    console.log(value);

                    if (value) { // require a URL
                        jQuery(".action").hide();
                        jQuery("#" + value).show();
                    }
                    return false;
                });
            });
        </script>
        <?php
    }

    /**
     *  Build query
     */
    public static function build_query() {
        if (!isset($_REQUEST['submit']) && !defined('DOING_AJAX')) {
            self::$query = null;
            return;
        }

        /* set default args */
        $args = array(
            'post_type' => 'wp-lead',
            'order' => self::$order,
            'orderby' => self::$orderby,
            'posts_per_page' => self::$per_page,
        );


        /* set tax_query_relation */
        $tax_query = array('relation' => $_REQUEST['relation']);

        /* loop through taxonomies and check for filter */
        foreach (self::$taxonomies as $key => $taxonomy) {
            if (!$taxonomy->hierarchical) {
                //continue;
            }

            if (!isset($_REQUEST[$taxonomy->name]) || !$_REQUEST[$taxonomy->name] || $_REQUEST[$taxonomy->name][0] == 'all') {
                continue;
            }

            /* build tax_query */

            foreach ($_REQUEST[$taxonomy->name] as $values) {
                $tax_query[] = array(
                    'taxonomy' => $taxonomy->name,
                    'field' => 'id',
                    'terms' => array($values)
                );
            }
        }

        if (count($tax_query) > 1) {
            $args['tax_query'] = $tax_query;
        }

        /* Add tag to query */
        if ((isset($_REQUEST['t'])) && $_REQUEST['t'] != "") {
            $args['tag'] = $_REQUEST['t'];
        }

        /* set meta_query */
        if (isset($_REQUEST['wp_lead_status']) && $_REQUEST['wp_lead_status'] ) {
            $meta_query = array('relation' => $_REQUEST['relation']);
            foreach ($_REQUEST['wp_lead_status'] as $status) {

                if ($status == 'all') {
                   continue;
                } else {
                    $meta_query[] = array(
                        'key' => 'wp_lead_status',
                        'value' => $status,
                        'meta_compare' => '='
                    );
                }
            }

            $args['meta_query'] = $meta_query;
        }


        if ((isset($_REQUEST['paged'])) && $_REQUEST['paged'] != "1") {
            $args['paged'] = self::$paged;
        }

        self::$query = new WP_Query($args);

    }


    /**
     *  get taxnomy select
     */
    public static function build_taxonomy_select($taxonomy) {

        /* create the select input */
        echo '<select name="' . $taxonomy->name . '[]" id="' . $taxonomy->name . '" multiple class="select2 form-control">';

        /* get selected taxonomies */
        $list_array = (isset($_REQUEST[$taxonomy->name])) ? $_REQUEST[$taxonomy->name] : array();

        /* print the first option */
        echo '<option class="" value="all" ' . (isset($_REQUEST[$taxonomy->name]) && $_REQUEST[$taxonomy->name][0] === 'all' ? 'selected="selected"' : '') . '>' . __('All ', 'inbound-pro' ) . '</option>';

        /* get available terms in taxonomy */
        $terms = get_terms($taxonomy->name, array('hide_empty' => false));

        /* loop through terms and create options */

        foreach ($terms as $term) {
            echo '<option class="" value="' . $term->term_id . '" ' . (isset($_REQUEST[$taxonomy->name]) && in_array($term->term_id, $list_array) ? 'selected="selected"' : '') . '>' . $term->name . ' (' . $term->count . ')</option>';
        }

        /* end select input */
        echo '</select>';
        ?>
        <script type='text/javascript'>
            jQuery("#<?php echo $taxonomy->name; ?>").select2({
                allowClear: true,
                placeholder: '<?php _e(sprintf('Select %s From List', $taxonomy->labels->singular_name), 'inbound-pro' ); ?>'
            });

        </script>
        <?php

    }

    /**
     *  get status select html
     */
    public static function build_lead_status_select() {

        /* create the select input */
        echo '<select name="wp_lead_status[]" id="wp_lead_status" multiple class="select2 form-control">';

        /* get selected taxonomies */
        $status_array = (isset($_REQUEST['wp_lead_status'])) ? $_REQUEST['wp_lead_status'] : array();

        /* print the first option */
        echo '<option class="" value="all" ' . (isset($_REQUEST['wp_lead_status']) && $_REQUEST['wp_lead_status'][0] === 'all' ? 'selected="selected"' : '') . '>' . __('All ', 'inbound-pro' ) . '</option>';

        /* loop through terms and create options */
        foreach (self::$statuses as $key=>$status) {
            echo '<option class="" value="' . $key . '" ' . (isset($_REQUEST['wp_lead_status']) && in_array($key, $status_array) ? 'selected="selected"' : '') . '>' . $status['label'] . ' (' . Inbound_Leads::get_status_lead_count($key) . ')</option>';
        }

        /* end select input */
        echo '</select>';
        ?>
        <script type='text/javascript'>
            jQuery("#wp_lead_status").select2({
                allowClear: true,
                placeholder: '<?php _e('Select Status From List', 'inbound-pro' ); ?>'
            });

        </script>
        <?php

    }

    /**
     *  Perform lead actions
     */
    public static function ajax_perform_actions() {

        /*permission check*/
        if (!current_user_can('level_9')) {
            die (__('User does not have admin level permissions.'));
        }

        if(empty($_POST) || empty($_POST['data']['action'])){
            die();
        }

        /*assemble the vars*/
        $action       = $_POST['data']['action']; //what kind of lead action is being taken.
        $limit        = $_POST['data']['limit']; //limit of how  many leads are being processed. eg. 100   //will be incremented on each pass
        $offset       = $_POST['data']['offset'];//lead progress pointer
        $total        = $_POST['data']['total'];  //total leads being dealt with
        $ids          = json_decode(stripslashes($_POST['data']['ids']));//the lead ids
        $lead_list_id = $_POST['data']['lead_list_id'];//the id of the lead list where the actions are taking place
        $tags         = $_POST['data']['tags'];//tags to be added, removed or replaced


        /*find out what the action is...*/
        if($action == 'add'){

            for($offset; $offset < $limit; $offset++) {
                Inbound_Leads::add_lead_to_list(intval($ids[$offset]), $lead_list_id); // add to list
            }

        } elseif($action == 'remove'){

            for($offset; $offset < $limit; $offset++) {
                Inbound_Leads::remove_lead_from_list(intval($ids[$offset]), $lead_list_id);
            }

        } elseif($action == 'tag'){
            $tags = explode(',', $tags);

            for($offset; $offset < $limit; $offset++) {
                Inbound_Leads::add_tag_to_lead(intval($ids[$offset]), $tags);
            }

        } elseif($action == 'untag'){
            $tags = explode(',', $tags);

            for($offset; $offset < $limit; $offset++) {
                Inbound_Leads::remove_tag_from_lead(intval($ids[$offset]), $tags);
            }

        } elseif($action == 'replace_tags'){
            $tags = explode(',', $tags);

            for($offset; $offset < $limit; $offset++) {
                wp_set_object_terms($ids[$offset], $tags, 'lead-tags');
            }

        } elseif($action == 'delete_leads'){

            for($offset; $offset < $limit; $offset++) {
                wp_delete_post(intval($ids[$offset]), true);
            }

        } else{
            /*if it wasn't on the list... die*/
            die(__('ERROR: unknown action'));
        }

        $err = print_r(error_get_last(), true);
        echo json_encode($err);
        die();
    }

    public static function ajax_leads_export_list(){

        $returnArray = array();

        if(!isset($_POST) || empty($_POST)){
            $returnArray = array(
                'status' => 0,
                'error' => 'Empty post values!!.',
                'url' => ''
            );
            die(json_encode($returnArray));

        }

        if(empty($_POST['data']['ids'])){
            $returnArray = array(
                'status' => 0,
                'error' => 'Please select leads to export!!.',
                'url' => ''
            );
            die(json_encode($returnArray));

        }


        /* handle posted data */
        $ids      = json_decode(stripslashes($_POST['data']['ids']));
        $limit    = $_POST['data']['limit'];
        $offset   = $_POST['data']['offset'];
        $total    = $_POST['data']['total'];
        $is_first = (!isset($_POST['data']['is_first']) || !$_POST['data']['is_first'] ) ? 0 : 1;
        $fields = Leads_Field_Map::build_map_array( false );

        /* add lead status & date created */
        $fields['wp_lead_status'] = __("Lead Status","inbound-pro");
        $fields['wpleads_last_updated'] = __("Last Updated","inbound-pro");
        $fields['wpleads_date_created'] = __("Date Created","inbound-pro");
        $fields['wpleads_ip_address'] = __("IP Address","inbound-pro");
        $fields['sources'] = __("Sources","inbound-pro");

        $upload_dir = wp_upload_dir();
        $uploads_path = 'leads/csv';

        /* GETTING CORRECT FILE PATH */
        $path = $upload_dir['path'].'/'.$uploads_path.'/';
        $url = $upload_dir['url'].'/'.$uploads_path.'/';
        $blogtime = current_time( 'mysql' );
        $hash = md5(serialize($ids));
        $filename = date("y.m.d.") . $hash ;

        list( $today_year, $today_month, $today_day, $hour, $minute, $second ) = preg_split( '([^0-9])', $blogtime );
        $path = str_replace($today_year.'/'.$today_month.'/','',$path);
        $url = str_replace($today_year.'/'.$today_month.'/','',$url);

        if(file_exists($path)){
            if($is_first == 1){
                @unlink($path.$filename.".csv");
            }
        } else {
            mkdir($path, 0755, true);
        }
        $exported = 0;

        header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
        header('Content-Description: File Transfer');
        header("Content-type: text/csv");
        header("Content-Disposition: attachment; filename=".$path."/".$filename.".csv");
        header("Expires: 0");
        header("Pragma: public");

        $file = @fopen($path.$filename.".csv","a");

        if(!$file){
            $returnArray = array(
                'status' => 0,
                'error' => 'Unable to create file. Please check you uploads folder permission!!.',
                'url' => ''
            );
            die(json_encode($returnArray));
        }


        if($is_first == 1){
            // Add a header row if it hasn't been added yet
            fputcsv($file, array_keys($fields));
            $headerDisplayed = true;
        }

        for($j = $offset;  $j < $limit; $j++)
        {
            unset($this_row_data);

            if (!isset($ids[$j])) {
                continue;
            }

            $lead = get_post($ids[$j]);
            $this_lead_data = get_post_custom($ids[$j]);

            foreach ($fields as $key => $val) {

                if (isset($this_lead_data[$key])) {
                    $val = $this_lead_data[$key];
                    if (is_array($val)) {
                        $val = implode(';', $val);
                    }
                } else {
                    $val = "";
                }

                /* account for date created */
                if ($key == 'wpleads_date_created') {
                    $val = $lead->post_date;
                } else if ($key == 'wpleads_last_updated') {
                    $val = $lead->post_modified;
                }

                $this_row_data[$key] = $val;
            }

            /* Add sources */
            $this_row_data['sources'] = json_encode(Inbound_Events::get_lead_sources($ids[$j]));
            fputcsv($file, $this_row_data);
            $exported++;
        }

        fclose($file);

        if($limit >= $total){
            $url = $url.$filename.'.csv';
            $returnArray = array(
                'status' => 1,
                'error' => '',
                'url' => $url
            );
        }else{
            $returnArray = array(
                'status' => 1,
                'error' => '',
                'url' => ''
            );
        }

        die(json_encode($returnArray));
    }




    /**
     *  Ajax listener to load more leads
     */
    public static function ajax_load_more_leads() {

        /* build query */
        self::build_query();

        $i = 0;

        $loop_page = self::$paged - 1;
        $loop_count = $loop_page * 60;
        $loop_count = $loop_count + 1;

        foreach (self::$query->posts as $post) {

            echo '<tr' . ($i++ % 2 == 0 ? ' class="alternate"' : '') . '>';

            /* show checkbox */
            echo '<td><input class="lead-select-checkbox" type="checkbox" name="ids[]" value="' . $post->ID . '" /></td>';

            /* show count */
            echo '<td class="count-sort"><span>' . $loop_count . '</span></td>';

            /* show publish date */
            echo '<td>';
            if ('0000-00-00 00:00:00' == $post->post_date) {
                _e('Unpublished', 'inbound-pro' );
            } else {
                echo date(__('Y/m/d'), strtotime($post->post_date));
            }
            echo '</td>';

            /* show email */
            echo '<td>';
            echo '  <span class="lead-email">' . $post->post_title . '</span>';
            echo '</td>';

            /* show lists */
            echo '<td class="list-column-row">';
            $terms = wp_get_post_terms($post->ID, 'wplead_list_category', 'id');
            foreach ($terms as $term) {
                echo '<span class="list-pill">' . $term->name . ' <i title="Remove This lead from the ' . $term->name . ' list" class="remove-from-list" data-lead-id="' . $post->ID . '" data-list-id="' . $term->term_id . '"></i></span> ';
            }
            echo '</td>';

            /* show tags */
            echo '<td class="tags-column-row">';
            $_tags = wp_get_post_terms($post->ID, 'lead-tags', 'id');

            if ($_tags) {
                foreach ($_tags as $tag) {
                    echo "<a title='Click to Edit Lead Tag Name' target='_blank' href='" . admin_url('edit-tags.php?action=edit&taxonomy=lead-tags&tag_ID=' . $tag->term_id . '&post_type=wp-lead') . "'>$tag->name</a>, ";
                }
            } else {
                _e('No tags', 'inbound-pro' );
            }
            echo '</td>';

            /* show link to lead */
            echo '<td>';
            echo '  <a class="thickbox" href="post.php?action=edit&post=' . $post->ID . '&amp;small_lead_preview=true&amp;TB_iframe=true&amp;width=1345&amp;height=244">' . __('View', 'inbound-pro' ) . '</a>';
            echo '</td>';

            /* show lead id */
            echo '<td>' . $post->ID . '</td>';

            /*add custom row content*/
            do_action('inbound_bulk_lead_action_list_item', $post);

            echo '</tr>';
            $loop_count++;
        }

    }


    /**
     *  Ajax listener to delete lead from list
     */
    public static function ajax_delete_from_list() {

        $lead_id = (isset($_POST['lead_id'])) ? $_POST['lead_id'] : '';
        $list_id = (isset($_POST['list_id'])) ? $_POST['list_id'] : '';

        $id = $lead_id;

        $current_terms = wp_get_post_terms($id, 'wplead_list_category', 'id');
        $current_terms_count = count($terms);
        //print_r($current_terms);
        $all_remove_terms = '';
        foreach ($current_terms as $term) {
            $add = $term->term_id;
            $all_remove_terms .= $add . ' ,';
        }
        $final = explode(' ,', $all_remove_terms);

        $final = array_filter($final, 'strlen');

        if (in_array($list_id, $final)) {
            $new = array_flip($final);
            unset($new[$list_id]);
            $save = array_flip($new);
            wp_set_object_terms($id, $save, 'wplead_list_category');
        }


    }

}

add_action('init', 'inbound_load_lead_manager', 1);
function inbound_load_lead_manager() {
    new Leads_Manager;
}

Inbound Pro Plugin - PHP Codex API documentation generated by ApiGen