function test_add_contact() { $this->assertEquals(0, sizeof(get_posts(array('post_type' => rtbiz_get_contact_post_type())))); $this->Rt_Contact->add_contact('sherlock holmes', '', '*****@*****.**'); $posts = get_posts(array('post_type' => rtbiz_get_contact_post_type())); $this->assertEquals(1, sizeof($posts)); $this->assertEquals(false, rtbiz_is_primary_email_unique('*****@*****.**')); $this->assertEquals(true, rtbiz_is_primary_email_unique('*****@*****.**')); }
/** * @param $id int WP_USER ID * export single contact from user to rtbiz contact * it will check if contact exists then it will map or else create new contact and will map with p2p * * @return mixed|null */ function export_biz_contact($id) { $user = get_userdata($id); if (empty($user)) { return false; } $email = $user->user_email; $post_id = null; $meta_query_args = array(array('key' => Rtbiz_Entity::$meta_key_prefix . self::$primary_email_key, 'value' => $email)); $args = array('post_type' => rtbiz_get_contact_post_type(), 'meta_query' => $meta_query_args); $posts = get_posts($args); if (rtbiz_is_primary_email_unique($email) && empty($posts)) { $post_id = rtbiz_add_contact($user->display_name, '', $email); } else { if (!empty($posts)) { $post_id = $posts[0]->ID; } } if (!empty($post_id)) { rtbiz_connect_contact_to_user($post_id, $id); } return $post_id; }
public function save_old_data($post_id) { if (!isset($_POST['post_type'])) { return; } if ($this->post_type != $_POST['post_type']) { return; } $meta_fields = $this->get_meta_fields(); $body = ''; $flag = false; $post = get_post($post_id); if ($_POST['post_title'] != $post->post_title) { $body = '<strong>' . __('Contact Title') . '</strong> : '; $body .= rtbiz_text_diff($post->post_title, $_POST['post_title']); } if (isset($_POST['tax_input'])) { foreach ($_POST['tax_input'] as $key => $val) { $tmp = rtbiz_get_tex_diff($post_id, $key); if ('' != $tmp) { $body .= $tmp; $flag = true; } } } $meta_key = ''; switch ($_POST['post_type']) { case rtbiz_get_contact_post_type(): $meta_key = 'contact_meta'; break; case rtbiz_get_company_post_type(): $meta_key = 'company_meta'; break; } foreach ($meta_fields as $field) { if (!isset($_POST[$meta_key][$field['key']])) { continue; } if ('contact_primary_email' == $field['key']) { if (!rtbiz_is_primary_email_unique($_POST['contact_meta'][$field['key']])) { continue; } } if (Rtbiz_Company::$primary_email == $field['key']) { if (!rtbiz_is_primary_email_unique_company($_POST['company_meta'][$field['key']])) { continue; } } if ('true' == $field['is_multiple']) { $val = self::get_meta($post_id, $field['key']); $filerval = array_filter($val); $filerpost = array_filter($_POST[$meta_key][$field['key']]); $diff = array_diff($filerval, $filerpost); $diff2 = array_diff($filerpost, $filerval); $difftxt = rtbiz_text_diff(implode(' ', $diff), implode(' ', $diff2)); if (!empty($difftxt) || '' != $difftxt) { $skip_enter = str_replace('Enter', '', $field['label']); $body .= "<strong>{ {$skip_enter} }</strong> : " . $difftxt; $flag = true; } } else { $val = self::get_meta($post_id, $field['key'], true); $newval = $_POST[$meta_key][$field['key']]; if ($val != $newval) { $difftxt = rtbiz_text_diff($val, $newval); $difftxt = trim($difftxt); if (!empty($difftxt)) { $skip_enter = str_replace('Enter', '', $field['label']); $body .= "<strong>{ {$skip_enter} }</strong> : " . $difftxt; $flag = true; } } } } if ($flag) { $user = wp_get_current_user(); $body = 'Updated by <strong>' . $user->display_name . '</strong> <br/>' . $body; $data = array('comment_post_ID' => $post_id, 'comment_content' => $body, 'comment_type' => 'rt_bot', 'comment_approved' => 1, 'comment_author' => 'rtBiz' . ' Bot'); wp_insert_comment($data); } }