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:
<?php
class Leads_Post_Type {
public function __construct() {
self::load_hooks();
}
public static function load_hooks() {
add_filter("manage_wp-lead_posts_columns", array(__CLASS__, 'register_columns'));
add_action("manage_posts_custom_column", array(__CLASS__, 'render_columns'), 10, 2);
add_filter("manage_edit-wp-lead_sortable_columns", array(__CLASS__, 'define_sortable_columns'));
add_action('posts_clauses', array(__CLASS__, 'process_column_sorting'), 1, 2);
add_filter('post_row_actions', array(__CLASS__, 'filter_row_actions'), 10, 2);
add_action('restrict_manage_posts', array(__CLASS__, 'define_filters'));
add_filter('parse_query', array(__CLASS__, 'process_filters'), 10, 1);
add_action('admin_footer-edit.php', array(__CLASS__, 'register_bulk_edit_fields'));
add_action('load-edit.php', array(__CLASS__, 'process_bulk_actions'));
add_action('updated_post_meta', array(__CLASS__, 'record_meta_update'), 10, 4);
add_action('admin_init', array(__CLASS__, 'redirect_email_profile_links'));
add_action('wp_ajax_inbound_get_all_lead_data', array(__CLASS__, 'ajax_get_all_lead_data'));
add_action('wp_ajax_wp_leads_mark_as_read_save', array(__CLASS__, 'ajax_mark_lead_as_read'));
add_action('wp_ajax_wp_leads_mark_as_unread_save', array(__CLASS__, 'ajax_mark_lead_as_unread'));
add_action('wp_ajax_wp_leads_auto_mark_as_read', array(__CLASS__, 'ajax_auto_mark_as_read'));
add_action('wp_ajax_wp_leads_stop_waiting_for_double_optin', array(__CLASS__, 'ajax_stop_waiting_for_double_optin'));
add_action('admin_menu', array(__CLASS__, 'setup_admin_menu'));
add_action('admin_enqueue_scripts', array(__CLASS__, 'enqueue_admin_scripts'));
add_action('trash_wp-lead' , array( __CLASS__ , 'trash_lead_actions'));
add_action('delete_post' , array( __CLASS__ , 'delete_lead_actions'));
}
public static function register_columns($cols) {
$cols = array(
"cb" => "<input type=\"checkbox\" />",
"lead-picture" => __('Lead', 'inbound-pro' ),
"first-name" => __('First Name', 'inbound-pro' ),
"last-name" => __('Last Name', 'inbound-pro' ),
"title" => __('Email', 'inbound-pro' ),
"status" => __('Status', 'inbound-pro' ),
'action-count' => (class_exists('Inbound_Analytics')) ? __('Logs', 'inbound-pro' ) : __('Events', 'inbound-pro' ),
"page-views" => __('Page Views', 'inbound-pro' ),
"modified" => __('Updated', 'inbound-pro' )
);
if (isset($_GET['wp_leads_filter_field']) && $_GET['wp_leads_filter_field'] != "") {
$the_val = $_GET['wp_leads_filter_field'];
$nice_names = wpl_nice_field_names();
if (array_key_exists($the_val, $nice_names)) {
$the_val = $nice_names[$the_val];
}
$cols['custom'] = $the_val;
}
return $cols;
}
public static function render_columns($column, $lead_id) {
global $post;
if ($post->post_type != 'wp-lead') {
return $column;
}
switch ($column) {
case "lead-picture":
$gravatar = self::get_gravatar($post->ID);
echo '<img class="lead-grav-img" width="50" height="50" src="' . $gravatar . '">';
break;
case "first-name":
$first_name = get_post_meta($lead_id, 'wpleads_first_name', true);
if (!$first_name || $first_name == 'false') {
$first_name = __('n/a', 'inbound-pro' );
}
echo $first_name;
break;
case "last-name":
$last_name = get_post_meta($lead_id, 'wpleads_last_name', true);
if (!$last_name) {
$last_name = __('n/a', 'inbound-pro' );
}
echo $last_name;
break;
case "status":
$lead_status = get_post_meta($lead_id, 'wp_lead_status', true);
self::display_status_pill($lead_status);
break;
case "action-count":
if (class_exists('Inbound_Analytics')) {
$actions = Inbound_Events::get_total_activity($lead_id , 'any' , array());
?>
<a href='<?php echo admin_url('index.php?action=inbound_generate_report&class=Inbound_Events_Report&range=10000&lead_id='.$post->ID.'&show_graph=false&title='.__('Logs','inbound-pro') .'&tb_hide_nav=true&TB_iframe=true&width=1000&height=600'); ?>' class='thickbox inbound-thickbox' title="<?php echo sprintf(__('past %s days','inbound-pro') , 99999 ); ?>">
<?php echo $actions; ?>
</a>
<?php
} else {
$actions = Inbound_Events::get_total_activity($lead_id , 'any' , array('inbound_list_add','sparkpost_delivery'));
echo $actions;
}
break;
case "custom":
if (isset($_GET['wp_leads_filter_field'])) {
$the_val = $_GET['wp_leads_filter_field'];
}
$custom_val = get_post_meta($lead_id, $the_val, true);
if (!$custom_val) {
$custom_val = 'N/A';
}
echo $custom_val;
break;
case "page-views":
$page_view_count = Inbound_Events::get_page_views_count($lead_id);
if (class_exists('Inbound_Analytics')) {
?>
<a href='<?php echo admin_url('index.php?action=inbound_generate_report&class=Inbound_Visitor_Impressions_Report&range=10000&lead_id='.$post->ID.'&show_graph=false&title='.__('Logs','inbound-pro') .'&tb_hide_nav=true&TB_iframe=true&width=1000&height=600'); ?>' class='thickbox inbound-thickbox' title="<?php echo sprintf(__('past %s days','inbound-pro') , 99999 ); ?>">
<?php echo $page_view_count; ?>
</a>
<?php
} else {
echo($page_view_count ? $page_view_count : 0);
}
break;
case "company":
$company = get_post_meta($lead_id, 'wpleads_company_name', true);
echo $company;
break;
case 'modified':
$m_orig = get_post_field('post_modified', $lead_id, 'raw');
$m_stamp = strtotime($m_orig);
$modified = date('n/j/y g:i a', $m_stamp);
echo '<p class="mod-date">';
echo '<em>' . $modified . '</em><br />';
echo '</p>';
break;
}
}
public static function define_sortable_columns($columns) {
$columns['first-name'] = 'first-name';
$columns['last-name'] = 'last-name';
$columns['status'] = 'status';
$columns['company'] = 'company';
$columns['modified'] = 'modified';
$columns['action-count'] = 'action-count';
$columns['page-views'] = 'page-views';
if (isset($_GET['wp_leads_filter_field'])) {
$the_val = $_GET['wp_leads_filter_field'];
$columns['custom'] = $the_val;
}
return $columns;
}
public static function define_filters() {
global $typenow, $wpdb;
if ($typenow != "wp-lead") {
return;
}
$statuses = Inbound_Leads::get_lead_statuses();
echo '<select name="wp_lead_status">';
echo '<option value="0">'.__('Lead Status','inbound-pro').'</option>';
foreach( $statuses as $status) {
if (isset($_GET['wp_lead_status'])) {
$selected = $status['key'] == $_GET['wp_lead_status'] ? ' selected ' : '';
} else {
$selected = '';
}
echo '<option value="'.$status['key'].'" data-color="'.$status['color'].'" ' . $selected . '>' . $status['label'] . '</option>';
}
echo "</select>";
$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' => __($tax_obj->label), 'taxonomy' => $tax_slug, 'name' => $tax_obj->name, 'orderby' => 'name', 'selected' => $current, 'hierarchical' => $tax_obj->hierarchical, 'show_count' => true, 'hide_empty' => false));
}
$mapped_fields = Leads_Field_Map::get_lead_fields();
$mapped_fields = Leads_Field_Map::prioritize_lead_fields($mapped_fields);
echo '<select name="meta_key" id="lead-meta-filter">';
echo '<option value="0">'.__('Lead Field','inbound-pro').'</option>';
foreach( $mapped_fields as $field) {
if (isset($field['enable']) && $field['enable'] == 'off') {
continue;
}
if (isset($_GET['meta_key'])) {
$selected = $field['key'] == $_GET['meta_key'] ? ' selected ' : '';
} else {
$selected = '';
}
echo '<option value="'.$field['key'].'" data-field-key="'.$field['key'].'" ' . $selected . '>' . $field['label'] . '</option>';
}
echo "</select>";
echo '<input type="text" name="meta_value" id="lead-meta-value" placeholder="'.__('search value here...').'" value="'.(isset($_GET['meta_value']) ? sanitize_text_field($_GET['meta_value']) : '' ).'">';
}
public static function filter_row_actions($actions, $post) {
if ($post->post_type != 'wp-lead') {
return $actions;
}
if (isset( $actions['edit'])) {
$actions['edit'] = str_replace('Edit', __('View', 'inbound-pro' ), $actions['edit']);
}
unset($actions['inline hide-if-no-js']);
return $actions;
}
public static function process_column_sorting($pieces, $query) {
global $wpdb, $table_prefix;
if (!isset($_GET['post_type']) || $_GET['post_type'] != 'wp-lead' || isset($_GET['page'])) {
return $pieces;
}
if ($query->is_main_query() && ($orderby = $query->get('orderby'))) {
$order = strtoupper($query->get('order'));
if (!in_array($order, array('ASC', 'DESC'))) {
$order = 'ASC';
}
switch ($orderby) {
case 'first-name':
$pieces['join'] .= " LEFT JOIN $wpdb->postmeta wp_rd ON wp_rd.post_id = {$wpdb->posts}.ID AND wp_rd.meta_key = 'wpleads_first_name'";
$pieces['orderby'] = " wp_rd.meta_value $order , " . $pieces['orderby'];
break;
case 'last-name':
$pieces['join'] .= " LEFT JOIN $wpdb->postmeta wp_rd ON wp_rd.post_id = {$wpdb->posts}.ID AND wp_rd.meta_key = 'wpleads_last_name'";
$pieces['orderby'] = " wp_rd.meta_value $order , " . $pieces['orderby'];
break;
case 'status':
$pieces['join'] .= " LEFT JOIN $wpdb->postmeta wp_rd ON wp_rd.post_id = {$wpdb->posts}.ID AND wp_rd.meta_key = 'wp_lead_status'";
$pieces['orderby'] = " wp_rd.meta_value $order , " . $pieces['orderby'];
break;
case 'page-views':
$pieces['join'] .= " LEFT JOIN {$table_prefix}inbound_page_views ipv ON ipv.lead_id = {$wpdb->posts}.ID ";
$pieces['groupby'] = " {$wpdb->posts}.ID ";
$pieces['orderby'] = " COUNT(ipv.lead_id) " . $order;
break;
case 'action-count':
$pieces['join'] .= " LEFT JOIN {$table_prefix}inbound_events ie ON ie.lead_id = {$wpdb->posts}.ID ";
$pieces['groupby'] = " {$wpdb->posts}.ID ";
$pieces['orderby'] = "COUNT(ie.lead_id) $order ";
break;
}
} else {
$pieces['orderby'] = " post_modified DESC , " . $pieces['orderby'];
}
return $pieces;
}
public static function process_filters($query) {
global $pagenow, $post;
if (!isset($_REQUEST['post_type']) || $_REQUEST['post_type'] != 'wp-lead' || isset($_GET['page'])) {
return;
}
$filters = get_object_taxonomies('wp-lead');
$qv = &$query->query_vars;
foreach ($filters as $tax_slug) {
if ($pagenow == 'edit.php' && isset($qv[$tax_slug]) && is_numeric($qv[$tax_slug])) {
if ($qv[$tax_slug] != 0) {
$term = get_term_by('id', $qv[$tax_slug], $tax_slug);
$qv[$tax_slug] = $term->slug;
}
}
}
if (isset($_GET['current_date'])) {
$timezone_day = _x('d', 'timezone date format');
$wordpress_date_day = date_i18n($timezone_day);
set_query_var('day', $wordpress_date_day);
return;
}
if (isset($_GET['current_month'])) {
$timezone_month = _x('m', 'timezone date format');
$wordpress_date_month = date_i18n($timezone_month);
set_query_var('monthnum', $wordpress_date_month);
return;
}
if (isset($_GET['meta_value']) && $_GET['meta_value'] != '') {
$query->query_vars['meta_key'] = $_GET['meta_key'];
if (isset($_GET['meta_value']) && $_GET['meta_value'] != '') {
$query->query_vars['meta_value'] = $_GET['meta_value'];
}
}
if (isset($_GET['lead-email']) && $_GET['lead-email'] != '') {
$query->query_vars['meta_key'] = 'wpleads_email_address';
$query->query_vars['meta_value'] = $_GET['lead-email'];
}
if (isset($_GET['wp_lead_status']) && $_GET['wp_lead_status'] != '0') {
$query->query_vars['meta_key'] = 'wp_lead_status';
$query->query_vars['meta_value'] = $_GET['wp_lead_status'];
}
}
public static function register_bulk_edit_fields() {
global $post_type;
if ($post_type != 'wp-lead') {
return;
}
$lists = wpleads_get_lead_lists_as_array();
$html = "<select id='wordpress_list_select' name='action_wordpress_list_id'>";
foreach ($lists as $id => $label) {
$html .= "<option value='" . $id . "'>" . $label . "</option>";
}
$html .= "</select>";
?>
<script type="text/javascript">
jQuery(document).ready(function () {
jQuery('<option>').val('add-to-list').text('<?php _e('Add to Contact List', 'inbound-pro' ) ?>').appendTo("select[name='action']");
jQuery('<option>').val('add-to-list').text('<?php _e('Add to Contact List', 'inbound-pro' ) ?>').appendTo("select[name='action2']");
jQuery(document).on('change', 'select[name=action]', function () {
var this_id = jQuery(this).val();
if (this_id.indexOf("add-to-list") >= 0) {
var html = "<?php echo $html; ?>";
jQuery("select[name='action']").after(html);
}
else {
jQuery('#posts-filter').prop('target', 'self');
jQuery('#wordpress_list_select').remove();
}
});
});
</script>
<?php
}
public static function process_bulk_actions() {
if (!isset($_REQUEST['post_type']) || $_REQUEST['post_type'] != 'wp-lead' || !isset($_REQUEST['post'])) {
return;
}
$wp_list_table = _get_list_table('WP_Posts_List_Table');
$action = $wp_list_table->current_action();
if (!current_user_can('manage_options')) {
die();
}
$lead_ids = array_map('intval', $_REQUEST['post']);
switch ($action) {
case 'add-to-list':
$list_id = $_REQUEST['action_wordpress_list_id'];
$added = 0;
foreach ($lead_ids as $lead_id) {
$list_cpt = get_post($list_id, ARRAY_A);
$list_slug = $list_cpt['post_name'];
$list_title = $list_cpt['post_title'];
wpleads_add_lead_to_list($list_id, $lead_id, $add = true);
$added++;
}
$sendback = add_query_arg(array('added' => $added, 'post_type' => 'wp-lead', 'ids' => join(',', $lead_ids)), $sendback);
break;
default:
return;
}
wp_redirect($sendback);
exit();
}
public static function prepare_nice_names() {
$nice_names = array("wpleads_company_name" => "Company Name", "wpleads_city" => "City", "wpleads_areaCode" => "Area Code", "wpleads_country_name" => "Country Name", "wpleads_region_code" => "State Abbreviation", "wpleads_region_name" => "State Name", "wp_lead_status" => "Lead Status", "events_triggered" => "Number of Events Triggered", "lp_page_views_count" => "Page View Count");
$nice_names = apply_filters('wpleads_sort_by_custom_field_nice_names', $nice_names);
return $nice_names;
}
public static function record_meta_update($meta_id, $lead_id, $meta_key, $meta_value) {
$ignore = array('_edit_lock', '_edit_last');
$post_type = get_post_type($lead_id);
if ($post_type != 'wp-lead' || in_array($meta_key, $ignore)) {
return;
}
remove_action('updated_post_meta', 'wpleads_after_post_meta_change', 10);
remove_action('added_post_meta', 'wpleads_after_post_meta_change', 10);
$timezone_format = _x('Y-m-d G:i:s', 'timezone date format');
$wordpress_date_time = date_i18n($timezone_format);
update_post_meta($lead_id, 'wpleads_last_updated', $wordpress_date_time);
do_action('wpleads_after_post_meta_change', $lead_id);
}
public static function redirect_email_profile_links() {
global $wpdb;
if (!isset($_GET['lead-email-redirect']) || $_GET['lead-email-redirect'] == '') {
return;
}
$lead_id = LeadStorage::lookup_lead_by_email($_GET['lead-email-redirect']);
if ($lead_id) {
$redirect = 'post.php?post=' . $lead_id . '&action=edit';
wp_redirect($redirect, 301);
exit;
}
}
public static function display_plugin_quick_links($links) {
return array_merge(
array(
'settings' => '<a href="' . admin_url('edit.php?post_type=wp-lead&page=wpleads_global_settings') . '">' . __('Settings', 'ts-fab') . '</a>'
),
$links
);
}
public static function display_status_pill( $status ) {
global $lead_statuses;
if (!$lead_statuses) {
$lead_statuses = Inbound_Leads::get_lead_statuses();
}
$pill = ( isset($lead_statuses[$status]) ) ? $lead_statuses[$status] : $lead_statuses['new'];
echo '<label class="lead-status-pill lead-status-' . $pill['key'] . '" style="background-color:'.$pill['color'].'" data-status="'.$pill['key'].'">';
echo $pill['label'];
echo '</label>';
}
public static function convert_array_to_xml($mixed, $node_name) {
$xml = '';
if (is_array($mixed) || is_object($mixed)) {
foreach ($mixed as $key => $value) {
if (is_numeric($key)) {
$key = $node_name;
}
$xml .= ' <' . $key . '>' . "\n " . self::convert_array_to_xml($value, $node_name) . ' </' . $key . '>' . "\n";
}
} else {
$xml = htmlspecialchars($mixed, ENT_QUOTES) . "\n";
}
return $xml;
}
public static function build_lead_xml($array, $node_block = 'lead_data', $node_name = 'lead_data') {
$xml = "";
$xml .= ' <' . $node_block . '>' . "\n";
$xml .= "" . self::convert_array_to_xml($array, $node_name);
$xml .= ' </' . $node_block . '>' . "\n";
return $xml;
}
public static function setup_admin_menu() {
add_submenu_page(
'edit.php?post_type=wp-lead',
__('Bulk Actions', 'inbound-pro' ),
__('Bulk Actions', 'inbound-pro' ),
'edit_leads',
'lead_management',
array('Leads_Manager', 'display_ui')
);
if ( defined('INBOUND_PRO_PATH') ) {
add_submenu_page(
'edit.php?post_type=wp-lead',
__('Settings' , 'inbound-pro'),
__('Settings' , 'inbound-pro'),
'edit_leads',
'inbound-pro-leads',
array('Leads_Settings', 'redirect_inbound_pro_settings')
);
add_submenu_page(
'edit.php?post_type=wp-lead',
__('API Keys' , 'inbound-pro'),
__('API Keys' , 'inbound-pro'),
'activate_plugins',
'wpleads_global_settings',
array('Leads_Settings', 'display_stand_alone_settings')
);
}else {
add_submenu_page(
'edit.php?post_type=wp-lead',
__('Settings' , 'inbound-pro'),
__('Settings' , 'inbound-pro'),
'edit_leads',
'wpleads_global_settings',
array('Leads_Settings', 'display_stand_alone_settings')
);
}
}
public static function get_gravatar($lead_id, $size = 50) {
$email = get_post_meta($lead_id, 'wpleads_email_address', true);
$size = ($size) ? $size : 50;
$default = WPL_URLPATH . '/assets/images/gravatar_default_50.jpg';
$gravatar = "//www.gravatar.com/avatar/" . md5(strtolower(trim($email))) . "?d=" . urlencode($default) . "&s=" . $size;
$extra_image = get_post_meta($lead_id, 'lead_main_image', true);
if (in_array($_SERVER['REMOTE_ADDR'], array('127.0.0.1', '::1'))) {
$gravatar = $default;
}
if (preg_match("/gravatar_default_/", $gravatar) && $extra_image != "") {
$gravatar = $extra_image;
}
return $gravatar;
}
public static function enqueue_admin_scripts($hook) {
global $post;
$post_type = isset($post) ? get_post_type($post) : null;
$screen = get_current_screen();
if ($screen->id === 'edit-wplead_list_category') {
wp_enqueue_script('wpleads-list-page', WPL_URLPATH . 'assets/js/wpl.list-page.js', array('jquery'));
wp_enqueue_style('wpleads-list-page-css', WPL_URLPATH . 'assets/css/wpl.list-page.css');
return;
}
if ($screen->id === 'edit-wp-lead') {
wp_enqueue_script('wpleads-list', WPL_URLPATH . 'assets/js/wpl.leads-list.js');
wp_enqueue_style('wpleads-list-css', WPL_URLPATH . 'assets/css/wpl.leads-list.css');
return;
}
}
public static function delete_lead_actions( $lead_id ) {
if (did_action( 'delete_post' ) > 1) {
return;
}
if (get_post_type($lead_id) != 'wp-lead') {
return;
}
global $wpdb;
$wpdb->delete( $wpdb->prefix . "inbound_page_views", array( 'lead_id' => $lead_id ) );
$wpdb->delete( $wpdb->prefix . "inbound_events", array( 'lead_id' => $lead_id ) );
$lead = get_post($lead_id);
$wpdb->query("DELETE FROM ".$wpdb->prefix . "inbound_automation_queue WHERE `trigger_data` LIKE '%{$lead->post_title}%' AND `tasks` LIKE '%send_email%'");
error_log($lead->post_title);
}
public static function trash_lead_actions( $lead_id ) {
global $wpdb;
$lead = get_post($lead_id);
$wpdb->query("DELETE FROM ".$wpdb->prefix . "inbound_automation_queue WHERE `trigger_data` LIKE '%{$lead->post_title}%' AND `tasks` LIKE '%send_email%'");
}
public static function ajax_get_all_lead_data() {
if (!current_user_can('activate_plugins')) {
return;
}
$wp_lead_id = intval($_POST['wp_lead_id']);
if (isset($wp_lead_id) && is_numeric($wp_lead_id)) {
global $wpdb;
$data = array();
$wpdb->query($wpdb->prepare("
SELECT `meta_key`, `meta_value`
FROM $wpdb->postmeta
WHERE `post_id` = %d", $wp_lead_id
));
foreach ($wpdb->last_result as $k => $v) {
$data[$v->meta_key] = $v->meta_value;
};
echo json_encode($data, JSON_FORCE_OBJECT);
wp_die();
}
}
public static function ajax_mark_lead_as_read() {
global $wpdb;
$lead_id = intval($_POST['page_id']);
update_post_meta($lead_id, 'wp_lead_status', 'read');
header('HTTP/1.1 200 OK');
exit;
}
public static function ajax_mark_lead_as_unread() {
global $wpdb;
$lead_id = intval($_POST['page_id']);
update_post_meta($lead_id, 'wp_lead_status', 'new');
header('HTTP/1.1 200 OK');
exit;
}
public static function ajax_auto_mark_as_read() {
global $wpdb;
$lead_id = intval($_POST['page_id']);
update_post_meta($lead_id, 'wp_lead_status', 'read');
header('HTTP/1.1 200 OK');
}
public static function ajax_stop_waiting_for_double_optin() {
global $wpdb;
if(!defined('INBOUND_PRO_CURRENT_VERSION')){
$double_optin_list_id = get_option('list-double-optin-list-id', '');
}else{
$settings = Inbound_Options_API::get_option('inbound-pro', 'settings', array());
$double_optin_list_id = $settings['leads']['list-double-optin-list-id'];
}
$lead_id = intval($_POST['page_id']);
delete_post_meta($lead_id, 'double_optin_lists');
Inbound_Leads::remove_lead_from_list($lead_id, (int)$double_optin_list_id);
update_post_meta($lead_id, 'wp_lead_status', 'read');
header('HTTP/1.1 200 OK');
exit;
}
}
new Leads_Post_Type;