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:
<?php
class Leads_Field_Map {
static $field_map;
public function __construct() {
self::load_hooks();
}
public static function load_hooks() {
if (!isset($_GET['disable_shortcodes'])) {
add_shortcode('lead-field', array(__CLASS__, 'process_lead_field_shortcode'));
}
}
public static function get_lead_fields() {
$lead_fields = array(
array(
'label' => __( 'First Name', 'inbound-pro' ) ,
'key' => 'wpleads_first_name',
'priority' => 1,
'type' => 'text',
'nature' => 'core'
),
array(
'label' => __( 'Last Name', 'inbound-pro' ) ,
'key' => 'wpleads_last_name',
'priority' => 2,
'type' => 'text',
'nature' => 'core'
),
array(
'label' => __( 'Email', 'inbound-pro' ) ,
'key' => 'wpleads_email_address',
'priority' => 3,
'type' => 'text',
'nature' => 'core'
),
array(
'label' => __( 'Website', 'inbound-pro' ) ,
'key' => 'wpleads_website',
'priority' => 4,
'type' => 'text',
'nature' => 'core'
),
array(
'label' => __( 'Job Title', 'inbound-pro' ) ,
'key' => 'wpleads_job_title',
'priority' => 5,
'type' => 'text',
'nature' => 'core'
),
array(
'label' => __( 'Company Name', 'inbound-pro' ) ,
'key' => 'wpleads_company_name',
'priority' => 6,
'type' => 'text',
'nature' => 'core'
),
array(
'label' => __( 'Mobile Phone', 'inbound-pro' ) ,
'key' => 'wpleads_mobile_phone',
'priority' => 7,
'type' => 'text',
'nature' => 'core'
),
array(
'label' => __( 'Work Phone', 'inbound-pro' ) ,
'key' => 'wpleads_work_phone',
'priority' => 8,
'type' => 'text',
'nature' => 'core'
),
array(
'label' => __( 'Address', 'inbound-pro' ) ,
'key' => 'wpleads_address_line_1',
'priority' => 9,
'type' => 'text',
'nature' => 'core'
),
array(
'label' => __( 'Address Continued', 'inbound-pro' ) ,
'key' => 'wpleads_address_line_2',
'priority' => 10,
'type' => 'text',
'nature' => 'core'
),
array(
'label' => __( 'City', 'inbound-pro' ) ,
'key' => 'wpleads_city',
'priority' => 11,
'type' => 'text',
'nature' => 'core'
),
array(
'label' => __( 'State/Region', 'inbound-pro' ) ,
'key' => 'wpleads_region_name',
'priority' => 12,
'type' => 'text',
'nature' => 'core'
),
array(
'label' => __( 'Zip-code', 'inbound-pro' ) ,
'key' => 'wpleads_zip',
'priority' => 13,
'type' => 'text',
'nature' => 'core'
),
array(
'label' => __( 'Country', 'inbound-pro' ) ,
'key' => 'wpleads_country_code',
'priority' => 14,
'type' => 'text',
'nature' => 'core'
),
array(
'label' => __( 'Billing First Name', 'inbound-pro' ) ,
'key' => 'wpleads_billing_first_name',
'priority' => 15,
'type' => 'text',
'nature' => 'core'
),
array(
'label' => __( 'Billing Last Name', 'inbound-pro' ) ,
'key' => 'wpleads_billing_last_name',
'priority' => 16,
'type' => 'text',
'nature' => 'core'
),
array(
'label' => __( 'Billing Company', 'inbound-pro' ) ,
'key' => 'wpleads_billing_company_name',
'priority' => 17,
'type' => 'text',
'nature' => 'core'
),
array(
'label' => __( 'Billing Address', 'inbound-pro' ) ,
'key' => 'wpleads_billing_address_line_1',
'priority' => 18,
'type' => 'text',
'nature' => 'core'
),
array(
'label' => __( 'Billing Address Continued', 'inbound-pro' ) ,
'key' => 'wpleads_billing_address_line_2',
'priority' => 19,
'type' => 'text',
'nature' => 'core'
),
array(
'label' => __( 'Billing City', 'inbound-pro' ) ,
'key' => 'wpleads_billing_city',
'priority' => 20,
'type' => 'text',
'nature' => 'core'
),
array(
'label' => __( 'Billing State/Region', 'inbound-pro' ) ,
'key' => 'wpleads_billing_region_name',
'priority' => 21,
'type' => 'text',
'nature' => 'core'
),
array(
'label' => __( 'Billing Zip-code', 'inbound-pro' ) ,
'key' => 'wpleads_billing_zip',
'priority' => 22,
'type' => 'text',
'nature' => 'core'
),
array(
'label' => __( 'Billing Country', 'inbound-pro' ) ,
'key' => 'wpleads_billing_country_code',
'priority' => 23,
'type' => 'text',
'nature' => 'core'
),
array(
'label' => __( 'Shipping First Name', 'inbound-pro' ) ,
'key' => 'wpleads_shipping_first_name',
'priority' => 24,
'type' => 'text',
'nature' => 'core'
),
array(
'label' => __( 'Shipping Last Name', 'inbound-pro' ) ,
'key' => 'wpleads_shipping_last_name',
'priority' => 25,
'type' => 'text',
'nature' => 'core'
),
array(
'label' => __( 'Shipping Company Name', 'inbound-pro' ) ,
'key' => 'wpleads_shipping_company_name',
'priority' => 26,
'type' => 'text',
'nature' => 'core'
),
array(
'label' => __( 'Shipping Address', 'inbound-pro' ) ,
'key' => 'wpleads_shipping_address_line_1',
'priority' => 27,
'type' => 'text',
'nature' => 'core'
),
array(
'label' => __( 'Shipping Address Continued', 'inbound-pro' ) ,
'key' => 'wpleads_shipping_address_line_2',
'priority' => 28,
'type' => 'text',
'nature' => 'core'
),
array(
'label' => __( 'Shipping City', 'inbound-pro' ) ,
'key' => 'wpleads_shipping_city',
'priority' => 29,
'type' => 'text',
'nature' => 'core'
),
array(
'label' => __( 'Shipping State/Region', 'inbound-pro' ) ,
'key' => 'wpleads_shipping_region_name',
'priority' => 30,
'type' => 'text',
'nature' => 'core'
),
array(
'label' => __( 'Shipping Zip-code', 'inbound-pro' ) ,
'key' => 'wpleads_shipping_zip',
'priority' => 31,
'type' => 'text',
'nature' => 'core'
),
array(
'label' => __( 'Shipping Country', 'inbound-pro' ) ,
'key' => 'wpleads_shipping_country_code',
'priority' => 32,
'type' => 'text',
'nature' => 'core'
),
array(
'label' => __( 'Related Websites', 'inbound-pro' ) ,
'key' => 'wpleads_websites',
'priority' => 33,
'type' => 'links',
'nature' => 'core'
),
array(
'label' => __( 'Notes', 'inbound-pro' ) ,
'key' => 'wpleads_notes',
'priority' => 34,
'type' => 'textarea',
'nature' => 'core'
),
array(
'label' => __( 'Twitter Account', 'inbound-pro' ) ,
'key' => 'wpleads_social_twitter',
'priority' => 35,
'type' => 'text',
'nature' => 'core'
),
array(
'label' => __( 'Youtube Account', 'inbound-pro' ) ,
'key' => 'wpleads_social_youtube',
'priority' => 36,
'type' => 'text',
'nature' => 'core'
),
array(
'label' => __( 'Facebook Account', 'inbound-pro' ) ,
'key' => 'wpleads_social_facebook',
'priority' => 37,
'type' => 'text',
'nature' => 'core'
)
);
$lead_fields = apply_filters('wp_leads_add_lead_field',$lead_fields);
return $lead_fields;
}
public static function build_map_array( $include_placeholder = true ) {
$lead_fields = Leads_Field_Map::get_lead_fields();
$lead_fields = Leads_Field_Map::prioritize_lead_fields( $lead_fields );
$field_map = array();
if($include_placeholder) {
$field_map[''] = __('Not set.','inbound-pro');
}
foreach ($lead_fields as $key=>$field) {
if (!isset($field['key'])) {
continue;
}
$label = $field['label'];
$key = $field['key'];
$field_map[$key] = $label;
}
return $field_map;
}
public static function build_field_types_array() {
return apply_filters( 'wp_leads_field_types', array(
'text' => __( 'text', 'inbound-pro' ),
'textarea' => __( 'textarea', 'inbound-pro' ),
'radio' => __( 'radio', 'inbound-pro' ),
'checkbox' => __( 'checkbox', 'inbound-pro' ),
'dropdown' => __( 'dropdown', 'inbound-pro' ),
'dropdown-country' => __( 'dropdown-country', 'inbound-pro' ),
'links' => __( 'links', 'inbound-pro' ),
'wysiwyg' => __( 'wysiwyg', 'inbound-pro' ),
'media' => __( 'media', 'inbound-pro' )
) );
}
public static function prioritize_lead_fields( $fields, $sort_flags=SORT_ASC) {
$prioritized = array();
foreach ($fields as $key => $value) {
while (isset($prioritized[$value['priority']])) {
$value['priority']++;
}
$prioritized[$value['priority']] = $value;
}
ksort($prioritized, $sort_flags);
return array_values($prioritized);
}
public static function get_field( $lead_id, $field_key ) {
return get_post_meta( $lead_id, $field_key, true);
}
public static function process_lead_field_shortcode($params) {
global $post;
$lead_id = null;
$params = shortcode_atts(array('default' => '', 'id' => '','key' => '', 'lead_id' => null), $params);
if (isset($params['lead_id']) && $params['lead_id']) {
$params['lead_id'] = intval($params['lead_id']);
} else if (isset($_REQUEST['lead_id'])) {
$params['lead_id'] = intval($_REQUEST['lead_id']);
} else if (isset($_COOKIE['wp_lead_id'])) {
$params['lead_id'] = intval($_COOKIE['wp_lead_id']);
}
if (!$params['lead_id']) {
return $params['default'];
}
$params['key'] = (isset($params['key']) && $params['key']) ? $params['key']: $params['id'] ;
$value = Leads_Field_Map::get_field($params['lead_id'], $params['key']);
if ($value) {
return (is_array($value)) ? implode(',' , $value ) : $value;
} else {
return $params['default'];
}
}
}
new Leads_Field_Map;