function single_cell($full_column_name, $user_object, $user_id) { global $wp_crm; $column_name = str_replace('wp_crm_', '', $full_column_name); $this_attribute = $wp_crm['data_structure']['attributes'][$column_name]; switch ($column_name) { case 'cb': $r .= "<input type='checkbox' name='users[]' id='user_{$user_id}' value='{$user_id}' />"; break; case 'user_card': $r .= WP_CRM_F::render_user_card(array('user_id' => $user_id, 'user_object' => $user_object, 'full_column_name' => $full_column_name, 'show_user_actions' => true)); break; case 'role': $r .= $role_name; break; case 'posts': if ($numposts > 0) { $r .= "<a href='edit.php?author={$user_id}' title='" . esc_attr__('View posts by this author') . "' class='edit'>"; $r .= $numposts; $r .= '</a>'; } else { $r .= 0; } break; default: if (is_array($user_object[$column_name])) { foreach ($user_object[$column_name] as $option_slug => $values) { if (($this_attribute['input_type'] == 'text' || $this_attribute['input_type'] == 'date' || $this_attribute['input_type'] == 'textarea') && $this_attribute['has_options']) { //** We have a text input with options (dropdown) */ $r .= wp_crm_get_value($column_name, $user_id); } elseif ($wp_crm['data_structure']['attributes'][$column_name]['has_options']) { //** Get label and only show when enabled */ $visible_options = WP_CRM_F::list_options($user_object, $column_name); } else { //** Regular value, no need to get option title */ foreach ($values as $single_value) { $visible_options[] = nl2br($single_value); } } } } if (is_array($visible_options)) { foreach ($visible_options as $key => $single_value) { $visible_options[$key] = nl2br($single_value); } $r .= '<ul><li>' . implode('</li><li>', $visible_options) . '</li></ul>'; } $r = apply_filters('wp_crm_overview_cell', $r, array('column_name' => $column_name, 'user_object' => $user_object, 'user_id' => $user_id)); break; } return $r; }
/** * Returns user's information as set in Overview Page User Card * * @since 0.21 * */ static function render_user_card($args = false) { global $wp_crm, $current_user; if (!$args) { return; } $defaults = array('avatar_width' => 50, 'do_not_display_user_avatars' => !empty($wp_crm['configuration']['do_not_display_user_avatars']) && $wp_crm['configuration']['do_not_display_user_avatars'] == 'true' ? true : false, 'show_user_actions' => false); $args = wp_parse_args($args, $defaults); extract($args); if (!isset($user_object)) { $user_object = wp_crm_get_user($user_id); } if ($show_user_actions && is_array($wp_crm['overview_user_actions'])) { foreach ($wp_crm['overview_user_actions'] as $action => $data) { if (!empty($data['enable']) && $data['enable'] == 'true') { $html = $data['label']; if ($action == 'reset_password' && $current_user->ID == (int) $user_id) { continue; } //** Apply filters to action */ $action = apply_filters('wp_crm_user_action', array('html' => $html, 'action' => $action, 'data' => $data, 'user_object' => $user_object, 'user_id' => $user_id)); $user_actions[] = '<li class="wp_crm_user_action" user_id="' . $action['user_id'] . '" action="' . $action['action'] . '">' . $action['html'] . '</li>'; } } } //** Get selected attributes from Settings page */ $user_card_attributes = $wp_crm['configuration']['overview_table_options']['main_view']; //** Load Default user card values to avoid having blank user cards */ if (!is_array($user_card_attributes)) { $user_card_attributes[] = 'display_name'; $user_card_attributes[] = 'user_email'; } ob_start(); ?> <?php if (!$do_not_display_user_avatars) { ?> <div class='user_avatar'> <?php if (current_user_can('WP-CRM: View Profiles')) { ?> <a href='<?php echo admin_url("admin.php?page=wp_crm_add_new&user_id={$user_id}"); ?> '><?php echo get_avatar($user_id, $avatar_width); ?> </a> <?php } else { ?> <?php echo get_avatar($user_id, $avatar_width); ?> <?php } ?> </div> <?php } ?> <div class="user_card_inner_wrapper"> <ul class="user_card_data"> <li class='primary'> <?php if (current_user_can('WP-CRM: View Profiles')) { ?> <a href='<?php echo admin_url("admin.php?page=wp_crm_add_new&user_id={$user_id}"); ?> '><?php echo WP_CRM_F::get_primary_display_value($user_object); ?> </a> <?php } else { ?> <?php echo WP_CRM_F::get_primary_display_value($user_object); ?> <?php } ?> </li> <?php foreach ($user_card_attributes as $key) { ?> <li class="<?php echo $key; ?> "> <?php unset($visible_options); if (!empty($wp_crm['data_structure']['attributes'][$key]['has_options'])) { $visible_options = WP_CRM_F::list_options($user_object, $key); } else { $visible_options[] = apply_filters('wp_crm_display_' . $key, WP_CRM_F::get_first_value($user_object[$key]), $user_id, $user_object, 'user_card'); } if (is_array($visible_options)) { foreach ($visible_options as $this_key => $option) { if (CRM_UD_F::is_url($option)) { $visible_options[$this_key] = "<a href='{$option}'>{$option}</a>"; } } } if (is_array($visible_options)) { echo '<ul><li>' . implode('</li><li>', $visible_options) . '</li></ul>'; } ?> </li> <?php } ?> </ul> <?php if (!empty($user_actions) && is_array($user_actions)) { echo '<ul class="wp_crm_user_row_actions">' . implode('<li class="wp_crm_divider"> | </li>', $user_actions) . '</ul>'; } ?> </div> <?php $content = ob_get_contents(); ob_end_clean(); return $content; }
/** * Get a value of a user. * * Ideally an attribute key should be passed, in which case the first value will be returned by default. * If a full meta key is passed, the value will be returned. * If a value of an option is passed, a boolean will be returned depending on if the option is enabled for the user. * * @since 0.1 * */ function wp_crm_get_value($meta_key, $user_id = false, $args = '') { global $current_user, $wp_crm; $args = wp_parse_args($args, array('return' => 'value', 'concat_char' => ', ', 'meta_key' => $meta_key, 'option_key' => '')); if (!$user_id) { $user_id = $current_user->ID; } $quantifiable_attributes = array_keys(WP_CRM_F::get_quantifiable_attributes()); //** Check if meta key exists as key and as label */ $attributes = $wp_crm['data_structure']['attributes']; $full_meta_keys = $wp_crm['data_structure']['full_meta_keys']; $meta_keys = $wp_crm['data_structure']['meta_keys']; //* If passed key is an attribute key (as intended) */ if (is_array($attributes) && in_array($meta_key, array_keys($attributes))) { $args['attribute_key'] = $meta_key; } //* If passed meta_key is actually a label name */ if (is_array($meta_keys) && in_array($meta_key, $meta_keys)) { $meta_value_flip = array_flip($meta_keys); $args['attribute_key'] = $meta_value_flip[$meta_key]; $meta_key = $args['attribute_key']; } //* If a full meta key is passed (for pre-defined values) */ if (is_array($full_meta_keys) && in_array($meta_key, array_keys($full_meta_keys))) { $args['full_meta_key'] = $meta_key; $args['attribute_key'] = $full_meta_keys[$meta_key]; } //** If all else fails, use the passed $meta_key (it may be a main user table key) */ if (empty($args['attribute_key'])) { $args['attribute_key'] = $meta_key; } //** Get the full attribute data once we have the attribute_key */ $attribute = WP_CRM_F::get_attribute($args['attribute_key']); //* Make sure we have a user object */ if (!empty($user_id) && is_numeric($user_id)) { $user_object = (array) wp_crm_get_user($user_id); } //** If we have the full meta key then we can get value easily from get_user_meta() */ if (!empty($args['full_meta_key']) && $args['full_meta_key'] != $args['attribute_key']) { $args['value'] = get_user_meta($user_id, $args['full_meta_key'], true); } else { //** Attribute has options, we return the label of the option */ if (!empty($attribute['has_options'])) { if ($attribute['input_type'] == 'text' || $attribute['input_type'] == 'textarea' || $attribute['input_type'] == 'date') { //** Try to get value by option key. */ $option_key = !empty($args['option_key']) ? $args['option_key'] : (is_array($attribute['option_keys']) ? key($attribute['option_keys']) : false); if (!empty($option_key)) { $args['value'] = get_user_meta($user_id, $args['attribute_key'] . '_option_' . $option_key, true); if (!empty($args['value'])) { $args['label'] = $meta_keys[$args['attribute_key'] . '_option_' . $option_key]; $args['return_option_label'] = true; $args['value'] .= ', ' . $args['label']; } } if (empty($args['value'])) { $args['value'] = WP_CRM_F::get_first_value(!empty($user_object[$args['attribute_key']]) ? $user_object[$args['attribute_key']] : array()); } } else { $options = WP_CRM_F::list_options($user_object, $args['attribute_key']); if (is_array($options)) { $args['value'] = implode($args['concat_char'], $options); } } } else { $args['value'] = WP_CRM_F::get_first_value(!empty($user_object[$args['attribute_key']]) ? $user_object[$args['attribute_key']] : array()); } } //** Check if this should be a boolean response */ if ((empty($args['return_option_label']) || !$args['return_option_label']) && in_array($args['attribute_key'], $quantifiable_attributes)) { if (!empty($args['value']) && $args['value'] == 'on') { $args['value'] = true; } } switch ($args['return']) { case 'value': $result = !empty($args['value']) ? $args['value'] : ''; break; case 'detail': $result = $args; break; default: $result = $args[$args['return']]; break; } return $result; }