public function change_link_to_admin($link, $item) { $cpt = rtbiz_get_contact_post_type(); if ($cpt == get_current_screen()->post_type && $cpt . '_to_user' === $item->p2p_type && current_user_can('edit_users')) { return get_edit_user_link($item->ID); } return $link; }
function test_get_contact_by_email() { $this->Rt_Contact->add_contact('sherlock holmes'); $this->Rt_Contact->add_contact('John Watson'); $posts = get_posts(array('post_type' => rtbiz_get_contact_post_type())); $this->assertEquals(2, sizeof($posts)); update_post_meta($posts[1]->ID, Rt_Entity::$meta_key_prefix . Rt_Contact::$primary_email_key, '*****@*****.**'); $contact = rtbiz_get_contact_by_email('*****@*****.**'); $this->assertEquals('sherlock holmes', $contact[0]->post_title); }
public function restrict_entity_by_attributes() { global $typenow, $wp_query, $rtbiz_rt_attributes; $post_types = array(rtbiz_get_contact_post_type(), rtbiz_get_company_post_type()); if (in_array($typenow, $post_types)) { $rtbiz_attributes_model = new RT_Attributes_Model(); $rtbiz_attributes_relationship_model = new RT_Attributes_Relationship_Model(); $relations = $rtbiz_attributes_relationship_model->get_relations_by_post_type($typenow); foreach ($relations as $r) { $attr = $rtbiz_attributes_model->get_attribute($r->attr_id); if ('taxonomy' == $attr->attribute_store_as) { $tax = get_taxonomy($rtbiz_rt_attributes->get_taxonomy_name($attr->attribute_name)); if (!empty($tax)) { $args = array('show_option_all' => __("Show All {$tax->label}"), 'taxonomy' => $rtbiz_rt_attributes->get_taxonomy_name($attr->attribute_name), 'name' => $rtbiz_rt_attributes->get_taxonomy_name($attr->attribute_name), 'orderby' => 'name', 'hierarchical' => true, 'depth' => 3, 'show_count' => false, 'hide_empty' => true); if (isset($wp_query->query[$rtbiz_rt_attributes->get_taxonomy_name($attr->attribute_name)])) { $args['selected'] = $wp_query->query[$rtbiz_rt_attributes->get_taxonomy_name($attr->attribute_name)]; } wp_dropdown_categories($args); } } } } }
/** * UI for group List View custom Columns * * @param type $display * @param type $column * @param type $term_id * * @return type */ function manage_team_column_body($display, $column, $term_id) { switch ($column) { case 'contacts': $term = get_term($term_id, self::$slug); $contacts_count = count(rtbiz_get_team_contacts($term_id)); $module = ''; $module = apply_filters('rtbiz_current_module_name', $module); echo '<a href="' . esc_url(admin_url('edit.php?post_type=' . rtbiz_get_contact_post_type() . '&contact_group=staff' . $module . '&' . self::$slug . '=' . $term->slug)) . '">' . $contacts_count . '</a>'; break; case 'email_address': $email_address = $this->get_team_meta('email_address', $term_id); if (isset($email_address) && !empty($email_address)) { echo esc_html($email_address); } break; } return; }
/** * @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 rtbiz_welcome_panel() { $admin_cap = rtbiz_get_access_role_cap(RTBIZ_TEXT_DOMAIN, 'admin'); $editor_cap = rtbiz_get_access_role_cap(RTBIZ_TEXT_DOMAIN, 'editor'); $welcome_label = __('rtBiz'); $contact_labels = rtbiz_get_contact_labels(); $company_labels = rtbiz_get_company_labels(); //$contact_group_labels = rtbiz_get_contact_group_labels(); ?> <div class="welcome-panel-content"> <h3><?php _e('Welcome to ' . $welcome_label); ?> </h3> <p class="about-description"><?php _e('We’ve assembled some links to get you started:'); ?> </p> <div class="welcome-panel-column-container"> <div class="welcome-panel-column"> <?php if (current_user_can($editor_cap)) { ?> <h4><?php _e('Get Started'); ?> </h4> <a id="rtbiz-customize-biz" class="button button-primary button-hero" href="<?php echo admin_url('admin.php?page=' . Rtbiz_Setting::$page_slug); ?> "><?php echo $welcome_label . ' ' . __('Settings'); ?> </a> <?php } ?> <?php do_action('rtbiz_welcome_panel_addon_link'); ?> </div> <div class="welcome-panel-column"> <h4><?php _e('Next Steps'); ?> </h4> <ul><?php if (current_user_can($editor_cap)) { $rtbiz_setting_url = admin_url('admin.php?page=rt-biz-settings'); echo '<li>'; echo '<a class="welcome-icon welcome-admin-users" href="' . $rtbiz_setting_url . '" style="display: inline-block;" >' . __('Import') . ' ' . strtolower($contact_labels['name']) . '</a>'; echo '</li>'; } if (current_user_can($editor_cap)) { ?> <li><?php printf('<a href="%s" class="welcome-icon welcome-universal-access-alt">' . __('Add new Team & assign them to') . ' ' . strtolower($contact_labels['singular_name']) . '</a>', admin_url('edit-tags.php?taxonomy=' . Rtbiz_Teams::$slug . '&post_type=' . rtbiz_get_contact_post_type())); ?> </li> <?php } if (current_user_can($admin_cap)) { ?> <li><?php printf('<a href="%s" class="welcome-icon welcome-lock">' . __('Define your Access Control for') . ' ' . $welcome_label . '</a>', admin_url('admin.php?page=' . Rtbiz_Access_Control::$page_slug)); ?> </li> <?php } ?> </ul> </div> <div class="welcome-panel-column welcome-panel-last"> <h4><?php _e('Quick Actions'); ?> </h4> <ul> <?php if (current_user_can($editor_cap)) { ?> <li><?php printf('<a id="rtiz-add-contact" href="%s" class="welcome-icon welcome-admin-users">' . __('Add new') . ' ' . $contact_labels['singular_name'] . '</a>', admin_url('post-new.php?post_type=' . rtbiz_get_contact_post_type())); ?> </li> <!--<li><?php /*printf( '<a href="%s" class="welcome-icon welcome-groups">' . __( 'Setup' ) . ' ' . $contact_group_labels['name'] . '</a>', admin_url( 'edit-tags.php?taxonomy=' . Rtbiz_Contact::$user_category_taxonomy . '&post_type=' . rtbiz_get_contact_post_type() ) ); */ ?> </li>--> <li><?php printf('<a href="%s" class="welcome-icon welcome-admin-home">' . __('Add new') . ' ' . $company_labels['singular_name'] . '</a>', admin_url('post-new.php?post_type=' . rtbiz_get_company_post_type())); ?> </li> <li><?php printf('<a href="%s" class="welcome-icon welcome-networking">' . __('Setup Attributes') . '</a>', admin_url('admin.php?page=' . Rtbiz_Attributes::$page_slug)); ?> </li> <?php } else { ?> <li><?php printf('<a href="%s" class="welcome-icon welcome-groups">' . __('View your') . ' ' . $contact_labels['name'] . '</a>', admin_url('edit.php?post_type=' . rtbiz_get_contact_post_type())); ?> </li> <li><?php printf('<a href="%s" class="welcome-icon welcome-admin-home">' . __('View your') . ' ' . $company_labels['name'] . '</a>', admin_url('edit.php?post_type=' . rtbiz_get_company_post_type())); ?> </li> <?php } ?> <li><?php printf('<a href="%s" class="welcome-icon welcome-learn-more">' . __('Learn more about getting started') . '</a>', 'http://docs.rtcamp.com/rtbiz/'); ?> </li> </ul> </div> </div> </div> <?php }
function rtbiz_is_primary_email_unique($email, $postid = null) { global $rtbiz_contact; $meta_query_args = array(array('key' => Rtbiz_Entity::$meta_key_prefix . Rtbiz_Contact::$primary_email_key, 'value' => $email)); $args = array('post_type' => rtbiz_get_contact_post_type(), 'meta_query' => $meta_query_args); if (!empty($postid)) { $args['post__not_in'] = array($postid); } $posts = get_posts($args); $count = count($posts); if (0 == $count) { return true; } return false; }
<tr> <th scope="col" class="manage-column"> </th> <?php foreach ($team as $ug) { ?> <th scope="col" class="manage-column"><strong><?php echo $ug->name . ' Team'; ?> </strong></th> <?php } ?> </tr> </tfoot> </table> <br/> <input type="submit" class="button-primary" value="Save Settings"/> <div style="margin-top: 25px"> <p class="description"> Access to individual contacts can be updated from their contact profile page. Go to <a target="_blank" href="<?php echo admin_url('edit.php?post_type=' . rtbiz_get_contact_post_type()); ?> ">People</a> section to find a contact.</p> </div> </form> </div> </div>
public static function ui($post) { if (rtbiz_get_contact_post_type() == $post->post_type) { $meta_fields = rtbiz_get_contact_meta_fields(); } elseif (rtbiz_get_company_post_type() == $post->post_type) { $meta_fields = rtbiz_get_company_meta_fields(); } do_action('rtbiz_before_render_meta_fields', $meta_fields); if (empty($meta_fields)) { return false; } ?> <div id="rtbiz-additional-detail-meta-box"> <?php $category = array_unique(wp_list_pluck($meta_fields, 'category')); $cathtml = array(); foreach ($category as $key => $value) { $cathtml[$value]['title'] = '<div><h3 class="rtbiz-category-title">' . __($value) . __(' information:') . ' </h3> </div>'; } $cathtml['other']['title'] = '<div><h3 class="rtbiz-category-title">' . __('Other information:') . '</h3></div>'; $other_flag = false; $is_our_team_mate = false; $postid = $post; if (is_object($post)) { $postid = $post->ID; } $wp_user = rtbiz_get_wp_user_for_contact($postid); //get wp user $cap = rtbiz_get_access_role_cap(RTBIZ_TEXT_DOMAIN, 'author'); if (!empty($wp_user[0])) { $is_our_team_mate = user_can($wp_user[0], $cap); } foreach ($meta_fields as $field) { ob_start(); $field = apply_filters('rtbiz_entity_fields_loop_single_field', $field); if (!$is_our_team_mate) { if (isset($field['hide_for_client']) && $field['hide_for_client']) { continue; } } if (isset($field['is_datepicker']) && $field['is_datepicker']) { $values = Rtbiz_Entity::get_meta($post->ID, $field['key'], true); ?> <script> jQuery(document).ready(function ($) { $(document).on('focus', ".datepicker", function () { $(this).datepicker({ 'dateFormat': 'dd/mm/yy', changeMonth: true, changeYear: true }); }); }); </script> <p class="rtbiz-form-group"><?php if (isset($field['label'])) { ?> <label for="<?php echo isset($field['id']) ? '' . $field['id'] . '' : ''; ?> "> <?php echo $field['label']; ?> </label><?php } ?> <input type="text" <?php echo isset($field['name']) ? 'name="' . $field['name'] . '"' : ''; echo isset($field['id']) ? 'id="' . $field['id'] . '"' : ''; ?> value='<?php echo $values; ?> ' <?php echo isset($field['class']) ? 'class="datepicker ' . $field['class'] . '"' : 'class="datepicker"'; ?> > <br/><span></span> </p> <?php } else { if (isset($field['is_multiple']) && $field['is_multiple']) { $values = Rtbiz_Entity::get_meta($post->ID, $field['key']); ?> <p class="rtbiz-form-group"><?php if (isset($field['label'])) { ?> <label for="<?php echo isset($field['id']) ? '' . $field['id'] . '' : ''; ?> "> <?php echo $field['label']; ?> </label><?php } ?> <input <?php echo isset($field['type']) ? 'type="' . $field['type'] . '"' : ''; ?> <?php echo isset($field['name']) ? 'name="' . $field['name'] . '"' : ''; ?> <?php echo isset($field['class']) ? 'class="' . $field['class'] . '"' : ''; ?> > <button data-type='<?php echo $field['type']; ?> ' type='button' class='button button-primary add-multiple'> + </button> <br/><span></span><?php foreach ($values as $value) { ?> <input <?php echo isset($field['type']) ? 'type="' . $field['type'] . '"' : ''; echo isset($field['name']) ? 'name="' . $field['name'] . '"' : ''; ?> value='<?php echo $value; ?> ' <?php echo isset($field['class']) ? 'class="second-multiple-input ' . $field['class'] . '"' : 'class="second-multiple-input"'; ?> > <button type='button' class='button delete-multiple'> -</button><?php } ?> </p> <?php } else { if (isset($field['type']) && 'textarea' == $field['type']) { $values = Rtbiz_Entity::get_meta($post->ID, $field['key'], true); ?> <p class="rtbiz-form-group"><?php if (isset($field['label'])) { ?> <label for="<?php echo isset($field['id']) ? '' . $field['id'] . '' : ''; ?> "><?php echo $field['label']; ?> </label> <?php } ?> <textarea <?php echo isset($field['name']) ? 'name="' . $field['name'] . '"' : ''; echo isset($field['id']) ? 'id="' . $field['id'] . '"' : ''; echo isset($field['class']) ? 'class="' . $field['class'] . '"' : ''; ?> > <?php echo $values; ?> </textarea> <br/><span></span> </p> <?php } else { if (isset($field['type']) && 'user_group' == $field['type']) { $user_id = Rtbiz_Entity::get_meta($post->ID, $field['key'], true); if (empty($user_id)) { continue; } ?> <p class="rtbiz-form-group"><?php call_user_func($field['data_source'], new WP_User($user_id)); ?> </p><?php } else { if (isset($field['type']) && 'checkbox' == $field['type']) { $values = Rtbiz_Entity::get_meta($post->ID, $field['key'], true); ?> <p class="rtbiz-form-group rtbiz-form-checkbox"> <label for="<?php echo isset($field['id']) ? '' . $field['id'] . '' : ''; ?> "> <input value='yes' <?php echo 'yes' == $values ? 'checked' : ''; ?> type='checkbox' <?php echo isset($field['name']) ? 'name="' . $field['name'] . '"' : ''; echo isset($field['id']) ? 'id="' . $field['id'] . '"' : ''; echo isset($field['class']) ? 'class="' . $field['class'] . '"' : ''; ?> /><?php echo $field['text']; ?> </label> <br/><span></span> </p> <?php } else { $values = Rtbiz_Entity::get_meta($post->ID, $field['key'], true); ?> <p class="rtbiz-form-group"><?php if (isset($field['label'])) { ?> <label for="<?php echo isset($field['id']) ? '' . $field['id'] . '' : ''; ?> "><?php echo $field['label']; ?> </label><?php } ?> <input <?php echo isset($field['type']) ? 'type="' . $field['type'] . '"' : ''; echo isset($field['name']) ? 'name="' . $field['name'] . '"' : ''; echo isset($field['id']) ? 'id="' . $field['id'] . '"' : ''; ?> value='<?php echo $values; ?> ' <?php echo isset($field['class']) ? 'class="' . $field['class'] . '"' : ''; ?> > <br/><span></span> </p> <?php } } } } } $tmphtml = ob_get_clean(); if (!isset($cathtml[$field['category']]['fields'])) { $cathtml[$field['category']]['fields'] = ''; } if (isset($field['category'])) { $cathtml[$field['category']]['fields'] .= $tmphtml; } else { $cathtml['other']['fields'] .= $tmphtml; $other_flag = true; } } $printimpload = array(); if (isset($cathtml['Contact'])) { $printimpload[] = $cathtml['Contact']; unset($cathtml['Contact']); } if (isset($cathtml['Social'])) { $printimpload[] = $cathtml['Social']; unset($cathtml['Social']); } if (isset($cathtml['HR'])) { if ($is_our_team_mate) { $printimpload[] = $cathtml['HR']; } unset($cathtml['HR']); } foreach ($cathtml as $key => $value) { if ('other' == $key) { if (true == $other_flag) { $printimpload[] = $value; } } else { $printimpload[] = $value; } } $filter = function ($category) { return $category['title'] . '<div class="rtbiz-category-group">' . $category['fields'] . '</div>'; }; $printimpload = array_map($filter, $printimpload); echo implode('<div class="add-gap-div"><hr></div>', $printimpload); ?> </div> <?php do_action('rtbiz_after_render_meta_fields', $post, $post->post_type); wp_nonce_field('rtbiz_additional_details_metabox', 'rtbiz_additional_details_metabox_nonce'); if (rtbiz_get_contact_post_type() == $post->post_type) { /* @var $rtbiz_contact Rtbiz_Contact */ global $rtbiz_contact; $rtbiz_contact->print_metabox_js($post); } elseif (rtbiz_get_company_post_type() == $post->post_type) { /* @var $rtbiz_company Rtbiz_Company */ global $rtbiz_company; $rtbiz_company->print_metabox_js($post); } do_action('print_metabox_js', $post, $post->post_type); }
public function get_module_users($module_key) { global $rtbiz_acl_model; // Include All the admins $module_user = get_users(array('fields' => 'ID', 'role' => 'administrator')); global $wpdb; // include other module user $sql = 'SELECT DISTINCT(acl.userid) FROM ' . $rtbiz_acl_model->table_name . ' as acl INNER JOIN ' . $wpdb->prefix . 'p2p as p2p on ( acl.userid = p2p.p2p_to ) INNER JOIN ' . $wpdb->posts . " as posts on (p2p.p2p_from = posts.ID ) where acl.module = '" . $module_key . "' and acl.permission > 0 and p2p.p2p_type = '" . rtbiz_get_contact_post_type() . "_to_user' and posts.post_status= 'publish' and posts.post_type= '" . rtbiz_get_contact_post_type() . "' "; $user_ids = $wpdb->get_col($sql); if (!empty($user_ids)) { $module_user = array_merge($module_user, $user_ids); } $module_user = array_unique($module_user); // get user object from user ids $user_obj = array(); if (!empty($module_user)) { $user_obj = get_users(array('include' => $module_user, 'orderby' => 'display_name', 'order' => 'ASC')); } return $user_obj; }
public function preprocess_comment_handler($commentdata) { // Contact and company comments needed on from end in furture need to remove else condition. if (is_admin()) { if (function_exists('get_current_screen')) { $screen = get_current_screen(); if (isset($screen->post_type) && (rtbiz_get_contact_post_type() != $screen->post_type && rtbiz_get_company_post_type() != $screen->post_type) && $screen->id != Rtbiz_Dashboard::$page_slug) { $types = isset($commentdata->query_vars['type__not_in']) ? $commentdata->query_vars['type__not_in'] : array(); if (!is_array($types)) { $types = array($types); } $types[] = 'rt_bot'; $commentdata->query_vars['type__not_in'] = $types; } } } else { $types = isset($commentdata->query_vars['type__not_in']) ? $commentdata->query_vars['type__not_in'] : array(); if (!is_array($types)) { $types = array($types); } $types[] = 'rt_bot'; $commentdata->query_vars['type__not_in'] = $types; } return $commentdata; }
/** * Register the JavaScript for the admin area. * * @since 1.0.0 */ public function enqueue_scripts() { /** * This function is provided for demonstration purposes only. * * An instance of this class should be passed to the run() function * defined in Plugin_Name_Loader as all of the hooks are defined * in that particular class. * * The Plugin_Name_Loader will then create the relationship * between the defined hooks and the functions defined in this * class. */ global $post; // Taxonomy menu hack for rtBiz if (isset($_REQUEST['taxonomy']) && isset($_REQUEST['post_type']) && in_array($_REQUEST['post_type'], array(rtbiz_get_contact_post_type(), rtbiz_get_company_post_type()))) { wp_localize_script(RTBIZ_TEXT_DOMAIN . 'admin-js', 'rtbiz_dashboard_screen', Rtbiz_Dashboard::$page_slug); wp_localize_script(RTBIZ_TEXT_DOMAIN . 'admin-js', 'rtbiz_menu_url', admin_url('edit-tags.php?taxonomy=' . $_REQUEST['taxonomy'] . '&post_type=' . $_REQUEST['post_type'])); } wp_enqueue_script('jquery-ui-autocomplete', '', array('jquery-ui-widget', 'jquery-ui-position'), '1.9.2', true); wp_enqueue_script(RTBIZ_TEXT_DOMAIN . 'admin-js', RTBIZ_URL . 'admin/js/admin.js', array('jquery'), RTBIZ_VERSION, true); wp_localize_script(RTBIZ_TEXT_DOMAIN . 'admin-js', 'rtbiz_ajax_url_admin', admin_url('admin-ajax.php')); }