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:
<?php
class Inbound_Leads_Custom_fields {
static $custom_field_map;
public function __construct() {
self::get_custom_fields();
self::load_hooks();
}
public static function load_hooks() {
add_filter( 'wp_leads_add_lead_field' , array( __CLASS__ , 'merge_fields' ) , 99 );
}
public static function get_custom_fields() {
global $inbound_settings;
self::$custom_field_map = (isset($inbound_settings['leads-custom-fields']['fields'])) ? $inbound_settings['leads-custom-fields']['fields'] : Leads_Field_Map::get_lead_fields();
}
public static function merge_fields( $mappable_fields ) {
$combined = array();
foreach( self::$custom_field_map as $key => $field ) {
if (!isset($field['key']) && !is_numeric($key)) {
$field['key'] = $key;
}
$present = false;
foreach ($mappable_fields as $i => $f) {
if ( $f['key'] != $field['key']) {
continue;
}
$combined[$field['key']] = $f;
$combined[$field['key']]['priority'] = (is_numeric($field['priority'])) ? $field['priority'] : 99;
$combined[$field['key']]['label'] = $field['label'];
$combined[$field['key']]['enable'] = (isset($field['enable'])) ? $field['enable'] : 'on';
$combined[$field['key']]['enable'] = (isset($field['enable'])) ? $field['enable'] : 'on';
$present = true;
}
if (!$present) {
$combined[$field['key']] = $field;
}
}
return $combined;
}
}
add_action( 'plugins_loaded' , 'load_Inbound_Leads_Custom_fields' );
function load_Inbound_Leads_Custom_fields() {
new Inbound_Leads_Custom_fields;
}