public static function build_map_array() { $lead_fields = Leads_Field_Map::get_lead_fields(); $field_map = array(); $field_map[''] = 'No Mapping'; // default empty foreach ($lead_fields as $key => $field) { $label = $field['label']; $key = $field['key']; $field_map[$key] = $label; } return $field_map; }
function wpleads_save_user_fields($post_id) { global $post; if (!isset($post) || isset($_POST['split_test'])) { return; } if ($post->post_type == 'revision' || 'trash' == get_post_status($post_id)) { return; } if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE || isset($_POST['post_type']) && $_POST['post_type'] == 'revision') { return; } if ($post->post_type == 'wp-lead') { $Leads_Field_Map = new Leads_Field_Map(); $wpleads_user_fields = $Leads_Field_Map->get_lead_fields(); foreach ($wpleads_user_fields as $key => $field) { $old = get_post_meta($post_id, $field['key'], true); if (isset($_POST[$field['key']])) { $new = $_POST[$field['key']]; if (is_array($new)) { //echo $field['name'];exit; array_filter($new); $new = implode(';', $new); update_post_meta($post_id, $field['key'], $new); } else { if (isset($new) && $new != $old) { update_post_meta($post_id, $field['key'], $new); if ($field['key'] == 'wpleads_email_address') { $args = array('ID' => $post_id, 'post_title' => $new); wp_update_post($args); } } else { if ('' == $new && $old) { delete_post_meta($post_id, $field['key'], $old); } } } } } } }
/** * Gets an array of mappable lead meta keys with their labels */ public static function fieldmap_get() { $lead_fields = Leads_Field_Map::build_map_array(); array_shift($lead_fields); return $lead_fields; }
/** * Uses mapped data if not programatically set */ static function improve_mapping($mappedData, $lead) { /* check to see if there are any mapped values arriving through inbound_store_lead */ $fields = Leads_Field_Map::build_map_array(); foreach ($fields as $key => $label) { if (isset($lead[$key]) && !isset($mappedData[$key])) { $mappedData[$key] = $lead[$key]; } } /* remove instances of wpleads_ */ $newMap = array(); foreach ($mappedData as $key => $value) { $key = str_replace('wpleads_', '', $key); $newMap[$key] = $value; } /* Set names if not mapped */ $newMap['first_name'] = !isset($newMap['first_name']) ? $lead['first_name'] : $newMap['first_name']; $newMap['last_name'] = !isset($newMap['last_name']) ? $lead['last_name'] : $newMap['last_name']; /* improve mapped names */ $newMap = self::improve_lead_name($newMap); return $newMap; }
<?php /* Include & Variables * ----------------------------------------------------- */ global $shortcodes_config; $fontawesome = array("" => "None", "arrow-circle-o-right" => "Arrow Circle O Right", "arrow-circle-o-left" => "Arrow Circle O Left", "check" => "Check", "check-circle" => "Check Circle", "check-circle-o" => "Check Circle O", "check-square" => "Check Square", "check-square-o" => "Check Square O", "comment" => "Comment", "comment-o" => "Comment O", "comments" => "Comments", "comments-o" => "Comments O", "asterisk" => "Asterisk", "thumbs-o-up" => "Thumbs O Up", "thumbs-up" => "Thumbs Up", "check-square" => "Check Square", "check-square-o" => "Check Square O", "arrow-circle-down" => "Arrow Circle Down", "arrow-circle-left" => "Arrow Circle Left", "arrow-circle-o-down" => "Arrow Circle O Down", "arrow-circle-o-left" => "Arrow Circle O Left", "arrow-circle-o-right" => "Arrow Circle O Right", "arrow-circle-o-up" => "Arrow Circle O Up", "arrow-circle-right" => "Arrow Circle Right", "arrow-circle-up" => "Arrow Circle Up", "arrow-down" => "Arrow Down", "arrow-left" => "Arrow Left", "arrow-right" => "Arrow Right", "arrow-up" => "Arrow Up", "angle-double-down" => "Angle Double Down", "angle-double-left" => "Angle Double Left", "angle-double-right" => "Angle Double Right", "angle-double-up" => "Angle Double Up", "angle-down" => "Angle Down", "angle-left" => "Angle Left", "angle-right" => "Angle Right", "angle-up" => "Angle Up", "caret-down" => "Caret Down", "caret-left" => "Caret Left", "caret-right" => "Caret Right", "caret-square-o-down" => "Caret Square O Down", "caret-square-o-left" => "Caret Square O Left", "caret-square-o-right" => "Caret Square O Right", "caret-square-o-up" => "Caret Square O Up", "caret-up" => "Caret Up", "chevron-circle-down" => "Chevron Circle Down", "chevron-circle-left" => "Chevron Circle Left", "chevron-circle-right" => "Chevron Circle Right", "chevron-circle-up" => "Chevron Circle Up", "chevron-down" => "Chevron Down", "chevron-left" => "Chevron Left", "chevron-right" => "Chevron Right", "chevron-up" => "Chevron Up", "hand-o-down" => "Hand O Down", "hand-o-left" => "Hand O Left", "hand-o-right" => "Hand O Right", "hand-o-up" => "Hand O Up", "long-arrow-down" => "Long Arrow Down", "long-arrow-left" => "Long Arrow Left", "long-arrow-right" => "Long Arrow Right", "long-arrow-up" => "Long Arrow Up", "toggle-down" => "Toggle Down", "toggle-left" => "Toggle Left", "toggle-right" => "Toggle Right", "toggle-up" => "Toggle Up", "arrows-alt" => "Arrows Alt", "backward" => "Backward", "compress" => "Compress", "eject" => "Eject", "expand" => "Expand", "fast-backward" => "Fast Backward", "fast-forward" => "Fast Forward", "forward" => "Forward", "pause" => "Pause", "play" => "Play", "play-circle" => "Play Circle", "play-circle-o" => "Play Circle O", "step-backward" => "Step Backward", "step-forward" => "Step Forward", "rub" => "Rub", "ruble" => "Ruble", "rouble" => "Rouble", "pagelines" => "Pagelines", "stack-exchange" => "Stack Exchange", "caret-square-o-left" => "Caret Square O Left", "toggle-left" => "Toggle Left", "dot-circle-o" => "Dot Circle O", "wheelchair" => "Wheelchair", "vimeo-square" => "Vimeo Square", "try" => "Try", "turkish-lira" => "Turkish Lira", "plus-square-o" => "Plus Square O", "adjust" => "Adjust", "anchor" => "Anchor", "archive" => "Archive", "arrows" => "Arrows", "arrows-h" => "Arrows H", "arrows-v" => "Arrows V", "ban" => "Ban", "bar-chart-o" => "Bar Chart O", "barcode" => "Barcode", "bars" => "Bars", "beer" => "Beer", "bell" => "Bell", "bell-o" => "Bell O", "bolt" => "Bolt", "book" => "Book", "bookmark" => "Bookmark", "bookmark-o" => "Bookmark O", "briefcase" => "Briefcase", "bug" => "Bug", "building-o" => "Building O", "bullhorn" => "Bullhorn", "bullseye" => "Bullseye", "calendar" => "Calendar", "calendar-o" => "Calendar O", "camera" => "Camera", "camera-retro" => "Camera Retro", "caret-square-o-down" => "Caret Square O Down", "caret-square-o-left" => "Caret Square O Left", "caret-square-o-right" => "Caret Square O Right", "caret-square-o-up" => "Caret Square O Up", "certificate" => "Certificate", "circle" => "Circle", "circle-o" => "Circle O", "clock-o" => "Clock O", "cloud" => "Cloud", "cloud-download" => "Cloud Download", "cloud-upload" => "Cloud Upload", "code" => "Code", "code-fork" => "Code Fork", "coffee" => "Coffee", "cog" => "Cog", "cogs" => "Cogs", "compass" => "Compass", "credit-card" => "Credit Card", "crop" => "Crop", "crosshairs" => "Crosshairs", "cutlery" => "Cutlery", "dashboard" => "Dashboard", "desktop" => "Desktop", "dot-circle-o" => "Dot Circle O", "download" => "Download", "edit" => "Edit", "ellipsis-h" => "Ellipsis H", "ellipsis-v" => "Ellipsis V", "envelope" => "Envelope", "envelope-o" => "Envelope O", "eraser" => "Eraser", "exchange" => "Exchange", "exclamation" => "Exclamation", "exclamation-circle" => "Exclamation Circle", "exclamation-triangle" => "Exclamation Triangle", "external-link" => "External Link", "external-link-square" => "External Link Square", "eye" => "Eye", "eye-slash" => "Eye Slash", "female" => "Female", "fighter-jet" => "Fighter Jet", "film" => "Film", "filter" => "Filter", "fire" => "Fire", "fire-extinguisher" => "Fire Extinguisher", "flag" => "Flag", "flag-checkered" => "Flag Checkered", "flag-o" => "Flag O", "flash" => "Flash", "flask" => "Flask", "folder" => "Folder", "folder-o" => "Folder O", "folder-open" => "Folder Open", "folder-open-o" => "Folder Open O", "frown-o" => "Frown O", "gamepad" => "Gamepad", "gavel" => "Gavel", "gear" => "Gear", "gears" => "Gears", "gift" => "Gift", "glass" => "Glass", "globe" => "Globe", "group" => "Group", "hdd-o" => "Hdd O", "headphones" => "Headphones", "heart" => "Heart", "heart-o" => "Heart O", "home" => "Home", "inbox" => "Inbox", "info" => "Info", "info-circle" => "Info Circle", "key" => "Key", "keyboard-o" => "Keyboard O", "laptop" => "Laptop", "leaf" => "Leaf", "legal" => "Legal", "lemon-o" => "Lemon O", "level-down" => "Level Down", "level-up" => "Level Up", "lightbulb-o" => "Lightbulb O", "location-arrow" => "Location Arrow", "lock" => "Lock", "magic" => "Magic", "magnet" => "Magnet", "mail-forward" => "Mail Forward", "mail-reply" => "Mail Reply", "mail-reply-all" => "Mail Reply All", "male" => "Male", "map-marker" => "Map Marker", "meh-o" => "Meh O", "microphone" => "Microphone", "microphone-slash" => "Microphone Slash", "minus" => "Minus", "minus-circle" => "Minus Circle", "minus-square" => "Minus Square", "minus-square-o" => "Minus Square O", "mobile" => "Mobile", "mobile-phone" => "Mobile Phone", "money" => "Money", "moon-o" => "Moon O", "music" => "Music", "pencil" => "Pencil", "pencil-square" => "Pencil Square", "pencil-square-o" => "Pencil Square O", "phone" => "Phone", "phone-square" => "Phone Square", "picture-o" => "Picture O", "plane" => "Plane", "plus" => "Plus", "plus-circle" => "Plus Circle", "plus-square" => "Plus Square", "plus-square-o" => "Plus Square O", "power-off" => "Power Off", "print" => "Print", "puzzle-piece" => "Puzzle Piece", "qrcode" => "Qrcode", "question" => "Question", "question-circle" => "Question Circle", "quote-left" => "Quote Left", "quote-right" => "Quote Right", "random" => "Random", "refresh" => "Refresh", "reply" => "Reply", "reply-all" => "Reply All", "retweet" => "Retweet", "road" => "Road", "rocket" => "Rocket", "rss" => "Rss", "rss-square" => "Rss Square", "search" => "Search", "search-minus" => "Search Minus", "search-plus" => "Search Plus", "share" => "Share", "share-square" => "Share Square", "share-square-o" => "Share Square O", "shield" => "Shield", "shopping-cart" => "Shopping Cart", "sign-in" => "Sign In", "sign-out" => "Sign Out", "signal" => "Signal", "sitemap" => "Sitemap", "smile-o" => "Smile O", "sort" => "Sort", "sort-alpha-asc" => "Sort Alpha Asc", "sort-alpha-desc" => "Sort Alpha Desc", "sort-amount-asc" => "Sort Amount Asc", "sort-amount-desc" => "Sort Amount Desc", "sort-asc" => "Sort Asc", "sort-desc" => "Sort Desc", "sort-down" => "Sort Down", "sort-numeric-asc" => "Sort Numeric Asc", "sort-numeric-desc" => "Sort Numeric Desc", "sort-up" => "Sort Up", "spinner" => "Spinner", "square" => "Square", "square-o" => "Square O", "star" => "Star", "star-half" => "Star Half", "star-half-empty" => "Star Half Empty", "star-half-full" => "Star Half Full", "star-half-o" => "Star Half O", "star-o" => "Star O", "subscript" => "Subscript", "suitcase" => "Suitcase", "sun-o" => "Sun O", "superscript" => "Superscript", "tablet" => "Tablet", "tachometer" => "Tachometer", "tag" => "Tag", "tags" => "Tags", "tasks" => "Tasks", "terminal" => "Terminal", "thumb-tack" => "Thumb Tack", "thumbs-down" => "Thumbs Down", "thumbs-o-down" => "Thumbs O Down", "ticket" => "Ticket", "times" => "Times", "times-circle" => "Times Circle", "times-circle-o" => "Times Circle O", "tint" => "Tint", "toggle-down" => "Toggle Down", "toggle-left" => "Toggle Left", "toggle-right" => "Toggle Right", "toggle-up" => "Toggle Up", "trash-o" => "Trash O", "trophy" => "Trophy", "truck" => "Truck", "umbrella" => "Umbrella", "unlock" => "Unlock", "unlock-alt" => "Unlock Alt", "unsorted" => "Unsorted", "upload" => "Upload", "user" => "User", "users" => "Users", "video-camera" => "Video Camera", "volume-down" => "Volume Down", "volume-off" => "Volume Off", "volume-up" => "Volume Up", "warning" => "Warning", "wheelchair" => "Wheelchair", "wrench" => "Wrench", "circle" => "Circle", "circle-o" => "Circle O", "dot-circle-o" => "Dot Circle O", "minus-square" => "Minus Square", "minus-square-o" => "Minus Square O", "plus-square" => "Plus Square", "plus-square-o" => "Plus Square O", "square" => "Square", "square-o" => "Square O", "bitcoin" => "Bitcoin", "btc" => "Btc", "cny" => "Cny", "dollar" => "Dollar", "eur" => "Eur", "euro" => "Euro", "gbp" => "Gbp", "inr" => "Inr", "jpy" => "Jpy", "krw" => "Krw", "money" => "Money", "rmb" => "Rmb", "rouble" => "Rouble", "rub" => "Rub", "ruble" => "Ruble", "rupee" => "Rupee", "try" => "Try", "turkish-lira" => "Turkish Lira", "usd" => "Usd", "won" => "Won", "yen" => "Yen", "align-center" => "Align Center", "align-justify" => "Align Justify", "align-left" => "Align Left", "align-right" => "Align Right", "bold" => "Bold", "chain" => "Chain", "chain-broken" => "Chain Broken", "clipboard" => "Clipboard", "columns" => "Columns", "copy" => "Copy", "cut" => "Cut", "dedent" => "Dedent", "eraser" => "Eraser", "file" => "File", "file-o" => "File O", "file-text" => "File Text", "file-text-o" => "File Text O", "files-o" => "Files O", "floppy-o" => "Floppy O", "font" => "Font", "indent" => "Indent", "italic" => "Italic", "link" => "Link", "list" => "List", "list-alt" => "List Alt", "list-ol" => "List Ol", "list-ul" => "List Ul", "outdent" => "Outdent", "paperclip" => "Paperclip", "paste" => "Paste", "repeat" => "Repeat", "rotate-left" => "Rotate Left", "rotate-right" => "Rotate Right", "save" => "Save", "scissors" => "Scissors", "strikethrough" => "Strikethrough", "table" => "Table", "text-height" => "Text Height", "text-width" => "Text Width", "th" => "Th", "th-large" => "Th Large", "th-list" => "Th List", "underline" => "Underline", "undo" => "Undo", "unlink" => "Unlink", "arrows" => "Arrows", "arrows-alt" => "Arrows Alt", "arrows-h" => "Arrows H", "arrows-v" => "Arrows V", "stop" => "Stop", "youtube-play" => "Youtube Play", "adn" => "Adn", "android" => "Android", "apple" => "Apple", "bitbucket" => "Bitbucket", "bitbucket-square" => "Bitbucket Square", "bitcoin" => "Bitcoin", "btc" => "Btc", "css3" => "Css3", "dribbble" => "Dribbble", "dropbox" => "Dropbox", "facebook" => "Facebook", "facebook-square" => "Facebook Square", "flickr" => "Flickr", "foursquare" => "Foursquare", "github" => "Github", "github-alt" => "Github Alt", "github-square" => "Github Square", "gittip" => "Gittip", "google-plus" => "Google Plus", "google-plus-square" => "Google Plus Square", "html5" => "Html5", "instagram" => "Instagram", "linkedin" => "Linkedin", "linkedin-square" => "Linkedin Square", "linux" => "Linux", "maxcdn" => "Maxcdn", "pagelines" => "Pagelines", "pinterest" => "Pinterest", "pinterest-square" => "Pinterest Square", "renren" => "Renren", "skype" => "Skype", "stack-exchange" => "Stack Exchange", "stack-overflow" => "Stack Overflow", "trello" => "Trello", "tumblr" => "Tumblr", "tumblr-square" => "Tumblr Square", "twitter" => "Twitter", "twitter-square" => "Twitter Square", "vimeo-square" => "Vimeo Square", "vk" => "Vk", "weibo" => "Weibo", "windows" => "Windows", "xing" => "Xing", "xing-square" => "Xing Square", "youtube" => "Youtube", "youtube-play" => "Youtube Play", "youtube-square" => "Youtube Square", "ambulance" => "Ambulance", "h-square" => "H Square", "hospital-o" => "Hospital O", "medkit" => "Medkit", "plus-square" => "Plus Square", "stethoscope" => "Stethoscope", "user-md" => "User Md", "wheelchair" => "Wheelchair"); $lp_cats = get_transient('landing-page-cats'); // array of landing page categories $form_names = get_transient('inbound-form-names'); // array of landing page categories $lead_mapping_fields = Leads_Field_Map::build_map_array(); $lead_list_names = get_transient('inbound-list-names'); /* Global Inbound Now Shortcodes */ require_once 'shortcodes/forms.php'; // Form Builder require_once 'shortcodes/column.php'; // Columned Layouts require_once 'shortcodes/call-to-action.php'; require_once 'shortcodes/alert.php'; require_once 'shortcodes/button.php'; require_once 'shortcodes/lists.php'; require_once 'shortcodes/social-share.php'; require_once 'shortcodes/quick-forms.php'; // Leads only Shortcodes // Landing Page Only Shortcodes require_once 'shortcodes/landing_pages.php'; // Category specific landing pages do_action('inbound_shortcode_addon_include', $form_names); // Hook into shortcode engine /** * Fix issues when shortcodes are embedded in a block of content that is filtered by wpautop.
/** * Gets mapped field data for this lead provide and sets it into static variable */ public static function get_mapped_fields() { global $post; $fields = array(); $mapped_fields = Leads_Field_Map::get_lead_fields(); $mapped_fields = Leads_Field_Map::prioritize_lead_fields($mapped_fields); foreach ($mapped_fields as $key => $field) { $fields[$field['key']] = $field; /* Get related meta value if exists */ $fields[$field['key']]['value'] = get_post_meta($post->ID, $mapped_fields[$key]['key'], true); /* Get default mapped value if meta value does not exists */ if (!$fields[$field['key']]['value'] && isset($mapped_fields[$key]['default'])) { $fields[$field['key']]['value'] = $mapped_fields[$key]['default']; } elseif (!isset($fields[$field['key']]['value'])) { $fields[$field['key']]['value'] = ""; } } self::$mapped_fields = $fields; }
/** * Loop through field map looking for key matches in array * @param ARRAY $lead_data * @param ARRAY $args * @returns ARRAY $lead_data */ function inbound_search_args_for_mapped_data($lead_data, $args) { $lead_fields = Leads_Field_Map::build_map_array(); foreach ($lead_fields as $key => $label) { if (isset($args[$key]) && !empty($args[$key])) { $lead_data[$key] = $args[$key]; } } return $lead_data; }
/** * Updates raw form data object */ static function store_raw_form_data($lead) { /* Raw Form Values Store */ if ($lead_data['form_input_values']) { $raw_post_data = get_post_meta(${$lead}['id'], 'wpleads_raw_post_data', true); $a1 = json_decode($raw_post_data, true); $a2 = json_decode(stripslashes($lead_data['form_input_values']), true); $exclude_array = array('card_number', 'card_cvc', 'card_exp_month', 'card_exp_year'); // add filter $lead_mapping_fields = Leads_Field_Map::build_map_array(); foreach ($a2 as $key => $value) { if (array_key_exists($key, $exclude_array)) { unset($a2[$key]); continue; } if (preg_match("/\\[\\]/", $key)) { $key = str_replace("[]", "", $key); // fix array value keys } if (array_key_exists($key, $lead_mapping_fields)) { update_post_meta($lead_id, $key, $value); } if (stristr($key, 'company')) { update_post_meta($lead_id, 'wpleads_company_name', $value); } else { if (stristr($key, 'website')) { $websites = get_post_meta($lead_id, 'wpleads_websites', $value); if (is_array($websites)) { $array_websites = explode(';', $websites); } $array_websites[] = $value; $websites = implode(';', $array_websites); update_post_meta($lead_id, 'wpleads_websites', $websites); } } } // Merge form fields if exist if (is_array($a1)) { $new_raw_post_data = array_merge_recursive($a1, $a2); } else { $new_raw_post_data = $a2; } $new_raw_post_data = json_encode($new_raw_post_data); update_post_meta($lead_id, 'wpleads_raw_post_data', $new_raw_post_data); } }
function inbound_store_lead($args = array()) { global $user_ID, $wpdb; /** // simulate ajax fail header('HTTP/1.0 404 Not found'); exit; /**/ // Grab form values $time = current_time('timestamp', 0); // Current wordpress time from settings $lead_data['user_ID'] = $user_ID; $lead_data['wordpress_date_time'] = date("Y-m-d G:i:s T", $time); $lead_data['wpleads_email_address'] = isset($_POST['emailTo']) ? $_POST['emailTo'] : false; $lead_data['page_views'] = isset($_POST['page_views']) ? $_POST['page_views'] : false; $lead_data['form_input_values'] = isset($_POST['form_input_values']) ? $_POST['form_input_values'] : false; // raw post data $lead_data['Mapped_Data'] = isset($_POST['Mapped_Data']) ? $_POST['Mapped_Data'] : false; // mapped data $lead_data['Mapped_Data'] ? $mapped_data = json_decode(stripslashes($lead_data['Mapped_Data']), true) : ($mapped_data = array()); // mapped data array $lead_data['page_view_count'] = array_key_exists('page_view_count', $mapped_data) ? $mapped_data['page_view_count'] : 0; $lead_data['source'] = array_key_exists('source', $mapped_data) ? $mapped_data['source'] : 'NA'; $lead_data['page_id'] = array_key_exists('page_id', $mapped_data) ? $mapped_data['page_id'] : '0'; $lead_data['variation'] = array_key_exists('variation', $mapped_data) ? $mapped_data['variation'] : '0'; $lead_data['post_type'] = array_key_exists('post_type', $mapped_data) ? $mapped_data['post_type'] : 'na'; $lead_data['wp_lead_uid'] = array_key_exists('wp_lead_uid', $mapped_data) ? $mapped_data['wp_lead_uid'] : false; $lead_data['lead_lists'] = array_key_exists('leads_list', $mapped_data) ? explode(",", $mapped_data['leads_list']) : false; $lead_data['ip_address'] = array_key_exists('ip_address', $mapped_data) ? $mapped_data['ip_address'] : false; /* POST Vars */ $lead_data['page_id'] = !$lead_data['page_id'] && isset($_POST['page_id']) ? $_POST['page_id'] : $lead_data['page_id']; $lead_data['variation'] = array_key_exists('variation', $mapped_data) ? $mapped_data['variation'] : '0'; $raw_search_data = isset($_POST['Search_Data']) ? $_POST['Search_Data'] : false; $search_data = json_decode(stripslashes($raw_search_data), true); // mapped data array $lead_data['search_data'] = $search_data; $lead_data['wpleads_full_name'] = isset($_POST['full_name']) ? $_POST['full_name'] : ""; $lead_data['wpleads_first_name'] = isset($_POST['first_name']) ? $_POST['first_name'] : ""; $lead_data['wpleads_last_name'] = isset($_POST['last_name']) ? $_POST['last_name'] : ""; $lead_data['wpleads_company_name'] = isset($_POST['company_name']) ? $_POST['company_name'] : ""; $lead_data['wpleads_mobile_phone'] = isset($_POST['phone']) ? $_POST['phone'] : ""; $lead_data['wpleads_address_line_1'] = isset($_POST['address']) ? $_POST['address'] : ""; $lead_data['wpleads_address_line_2'] = isset($_POST['address_2']) ? $_POST['address_2'] : ""; $lead_data['wpleads_city'] = isset($_POST['city']) ? $_POST['city'] : ""; $lead_data['wpleads_region_name'] = isset($_POST['region']) ? $_POST['region'] : ""; $lead_data['wpleads_zip'] = isset($_POST['zip']) ? $_POST['zip'] : ""; /* Legacy - Phasing Out * $lead_data['first_name'] = (isset($_POST['first_name'])) ? $_POST['first_name'] : ""; $lead_data['last_name'] = (isset($_POST['last_name'])) ? $_POST['last_name'] : ""; $lead_data['email'] = (isset($_POST['emailTo'])) ? $_POST['emailTo'] : false; $lead_data['lp_variation'] = (array_key_exists('variation', $mapped_data)) ? $mapped_data['variation'] : '0'; //legacy for landing pages */ /* NEW MAPPING Loop In Progress */ /** $check_map = array( "phone" => 'wpleads_work_phone', "company" => "wpleads_company_name", 'first_name' => 'wpleads_first_name', 'last_name' => 'wpleads_last_name', 'address' => 'wpleads_address_line_1' ); // have filter foreach ($mapped_data as $key => $value) { if (array_key_exists($key, $check_map)) { //$lead_data['source'] = ''; //update_post_meta( $lead_data['lead_id'], $check_map[$key], $value); } //update_post_meta( $lead_data['lead_id'], 'FormData', $key); // replace times } if( array_key_exists('leads_list', $mapped_data)) { $lead_data['lead_lists'] = explode(",", $mapped_data['leads_list']); } /* END NEW MAPPING In Progress */ if ($args) { $lead_data = array_merge($lead_data, $args); } $lead_data = apply_filters('inboundnow_store_lead_pre_filter_data', $lead_data); do_action('inbound_store_lead_pre', $lead_data); // Global lead storage action hook // check for set email if (isset($lead_data['wpleads_email_address']) && !empty($lead_data['wpleads_email_address']) && strstr($lead_data['wpleads_email_address'], '@')) { $query = $wpdb->prepare('SELECT ID FROM ' . $wpdb->posts . ' WHERE post_title = %s AND post_type = \'wp-lead\'', $lead_data['wpleads_email_address']); $wpdb->query($query); /* Update Lead if Exists else Create New Lead */ if ($wpdb->num_rows) { /* Update Existing Lead */ $lead_data['lead_id'] = $wpdb->get_var($query); $lead_id = $lead_data['lead_id']; inbound_update_common_meta($lead_data); do_action('wpleads_existing_lead_update', $lead_data); // action hook on existing leads only } else { /* Create New Lead */ $post = array('post_title' => $lead_data['wpleads_email_address'], 'post_status' => 'publish', 'post_type' => 'wp-lead', 'post_author' => 1); //$post = add_filter('lp_leads_post_vars',$post); $lead_data['lead_id'] = wp_insert_post($post); $lead_id = $lead_data['lead_id']; update_post_meta($lead_id, 'wpleads_wordpress_user_id', $user_ID); /* updates common meta for new leads */ inbound_update_common_meta($lead_data); /* specific updates for new leads */ update_post_meta($lead_id, 'wpleads_email_address', $lead_data['wpleads_email_address']); update_post_meta($lead_id, 'page_views', $lead_data['page_views']); /* Store Page Views Object */ update_post_meta($lead_id, 'wpleads_page_view_count', $lead_data['page_view_count']); do_action('wpleads_new_lead_insert', $lead_data); // action hook on new leads only } /*** * Run Processes for all Leads below ***/ do_action('wpleads_after_conversion_lead_insert', $lead_id); // action hook on all lead inserts update_post_meta($lead_id, 'wpleads_inbound_form_mapped_data', $lead_data['Mapped_Data']); /* Add Leads to List on creation */ if (!empty($lead_data['lead_lists']) && is_array($lead_data['lead_lists'])) { global $Inbound_Leads; $Inbound_Leads->add_lead_to_list($lead_id, $lead_data['lead_lists'], 'wplead_list_category'); } /* Store past search history */ if ($lead_data['search_data']) { $search = $lead_data['search_data']; $search_data = get_post_meta($lead_id, 'wpleads_search_data', TRUE); $search_data = json_decode($search_data, true); if (is_array($search_data)) { $s_count = count($search_data) + 1; $loop_count = 1; foreach ($search as $key => $value) { $search_data[$s_count]['date'] = $search[$loop_count]['date']; $search_data[$s_count]['value'] = $search[$loop_count]['value']; $s_count++; $loop_count++; } } else { // Create search obj $s_count = 1; $loop_count = 1; foreach ($search as $key => $value) { $search_data[$s_count]['date'] = $search[$loop_count]['date']; $search_data[$s_count]['value'] = $search[$loop_count]['value']; $s_count++; $loop_count++; } } $search_data = json_encode($search_data); update_post_meta($lead_id, 'wpleads_search_data', $search_data); // Store search object } /* Store IP addresss & Store GEO Data */ if ($lead_data['ip_address']) { update_post_meta($lead_id, 'wpleads_ip_address', $lead_data['ip_address']); if ($lead_data['ip_address'] != "127.0.0.1") { // exclude localhost $geo_array = @unserialize(wp_remote_get('http://www.geoplugin.net/php.gp?ip=' . $lead_data['ip_address'])); isset($geo_array['geoplugin_areaCode']) ? update_post_meta($lead_id, 'wpleads_areaCode', $geo_array['geoplugin_areaCode']) : null; isset($geo_array['geoplugin_city']) ? update_post_meta($lead_id, 'wpleads_city', $geo_array['geoplugin_city']) : null; isset($geo_array['geoplugin_regionName']) ? update_post_meta($lead_id, 'wpleads_region_name', $geo_array['geoplugin_regionName']) : null; isset($geo_array['geoplugin_regionCode']) ? update_post_meta($lead_id, 'wpleads_region_code', $geo_array['geoplugin_regionCode']) : null; isset($geo_array['geoplugin_countryName']) ? update_post_meta($lead_id, 'wpleads_country_name', $geo_array['geoplugin_countryName']) : null; isset($geo_array['geoplugin_countryCode']) ? update_post_meta($lead_id, 'wpleads_country_code', $geo_array['geoplugin_countryCode']) : null; isset($geo_array['geoplugin_latitude']) ? update_post_meta($lead_id, 'wpleads_latitude', $geo_array['geoplugin_latitude']) : null; isset($geo_array['geoplugin_longitude']) ? update_post_meta($lead_id, 'wpleads_longitude', $geo_array['geoplugin_longitude']) : null; isset($geo_array['geoplugin_currencyCode']) ? update_post_meta($lead_id, 'wpleads_currency_code', $geo_array['geoplugin_currencyCode']) : null; isset($geo_array['geoplugin_currencySymbol_UTF8']) ? update_post_meta($lead_id, 'wpleads_currency_symbol', $geo_array['geoplugin_currencySymbol_UTF8']) : null; } } /* Store Conversion Data to Lead */ inbound_add_conversion_to_lead($lead_id, $lead_data); /* Store Lead Referral Source Data */ $referral_data = get_post_meta($lead_id, 'wpleads_referral_data', TRUE); $referral_data = json_decode($referral_data, true); if (is_array($referral_data)) { $r_count = count($referral_data) + 1; $referral_data[$r_count]['source'] = $lead_data['source']; $referral_data[$r_count]['datetime'] = $lead_data['wordpress_date_time']; } else { $referral_data[1]['source'] = $lead_data['source']; $referral_data[1]['datetime'] = $lead_data['wordpress_date_time']; $referral_data[1]['original_source'] = 1; } $lead_data['referral_data'] = json_encode($referral_data); update_post_meta($lead_id, 'wpleads_referral_data', $lead_data['referral_data']); // Store referral object /* Store Conversion Data to LANDING PAGE/CTA DATA */ if ($lead_data['post_type'] == 'landing-page' || $lead_data['post_type'] == 'wp-call-to-action') { $page_conversion_data = get_post_meta($lead_data['page_id'], 'inbound_conversion_data', TRUE); $page_conversion_data = json_decode($page_conversion_data, true); $version = $lead_data['variation'] != 'default' ? $lead_data['variation'] : '0'; if (is_array($page_conversion_data)) { $convert_count = count($page_conversion_data) + 1; $page_conversion_data[$convert_count]['lead_id'] = $lead_id; $page_conversion_data[$convert_count]['variation'] = $version; $page_conversion_data[$convert_count]['datetime'] = $lead_data['wordpress_date_time']; } else { $convert_count = 1; $page_conversion_data[$convert_count]['lead_id'] = $lead_id; $page_conversion_data[$convert_count]['variation'] = $version; $page_conversion_data[$convert_count]['datetime'] = $lead_data['wordpress_date_time']; } $page_conversion_data = json_encode($page_conversion_data); update_post_meta($lead_data['page_id'], 'inbound_conversion_data', $page_conversion_data); } /* Store page views for page tracking off */ $page_tracking_status = get_option('wpl-main-page-view-tracking', 1); if ($lead_data['page_views'] && $page_tracking_status == 0) { $page_view_data = get_post_meta($lead_id, 'page_views', TRUE); $page_view_data = json_decode($page_view_data, true); // If page_view meta exists do this if (is_array($page_view_data)) { $new_page_views = inbound_json_array_merge($page_view_data, $lead_data['page_views']); $page_views = json_encode($new_page_views); } else { // Create page_view meta if it doesn't exist $page_views = $lead_data['page_views']; $page_views = json_encode($page_views); } // View count $view_count = get_post_meta($lead_id, 'wpleads_page_view_count', TRUE); if ($view_count) { $page_view_count = $lead_data['page_view_count'] + $view_count; } else { $page_view_count = $lead_data['page_view_count']; } // update meta if ($lead_data['page_view_count']) { update_post_meta($lead_id, 'wpleads_page_view_count', $page_view_count); } update_post_meta($lead_id, 'page_views', $page_views); } /* Raw Form Values Store */ if ($lead_data['form_input_values']) { $raw_post_data = get_post_meta($lead_id, 'wpleads_raw_post_data', true); $a1 = json_decode($raw_post_data, true); $a2 = json_decode(stripslashes($lead_data['form_input_values']), true); $exclude_array = array('card_number', 'card_cvc', 'card_exp_month', 'card_exp_year'); // add filter $lead_mapping_fields = Leads_Field_Map::build_map_array(); foreach ($a2 as $key => $value) { if (array_key_exists($key, $exclude_array)) { unset($a2[$key]); continue; } if (preg_match("/\\[\\]/", $key)) { $key = str_replace("[]", "", $key); // fix array value keys } if (array_key_exists($key, $lead_mapping_fields)) { update_post_meta($lead_id, $key, $value); } if (stristr($key, 'company')) { update_post_meta($lead_id, 'wpleads_company_name', $value); } else { if (stristr($key, 'website')) { $websites = get_post_meta($lead_id, 'wpleads_websites', $value); if (is_array($websites)) { $array_websites = explode(';', $websites); } $array_websites[] = $value; $websites = implode(';', $array_websites); update_post_meta($lead_id, 'wpleads_websites', $websites); } } } // Merge form fields if exist if (is_array($a1)) { $new_raw_post_data = array_merge_recursive($a1, $a2); } else { $new_raw_post_data = $a2; } $new_raw_post_data = json_encode($new_raw_post_data); update_post_meta($lead_id, 'wpleads_raw_post_data', $new_raw_post_data); } setcookie('wp_lead_id', $lead_id, time() + 20 * 365 * 24 * 60 * 60, '/'); do_action('inbound_store_lead_post', $lead_data); do_action('wp_cta_store_lead_post', $lead_data); do_action('wpl_store_lead_post', $lead_data); do_action('lp_store_lead_post', $lead_data); if (!$args) { echo $lead_id; die; } else { return $lead_id; } } }