/** * Hooks into list table cell. * * Executed on all, so need to only apply to messages. * * @since 0.1 */ function wp_list_table_cell($cell_data) { global $wp_crm, $wpdb; if ($cell_data['table_scope'] != 'wp_crm_contact_messages') { return $cell_data; } $object = $cell_data['object']; $user_id = $object['user_id']; if ($associated_object = $object['associated_object']) { $associated_object = get_post($associated_object); //** Only allow specific post types to be "associated "*/ if (apply_filters('wp_crm_associated_post_types', false, $associated_object->post_type)) { $post_type = get_post_type_object($associated_object->post_type); } else { unset($associated_object); } } switch ($cell_data['column_name']) { case 'user_card': $r .= WP_CRM_F::render_user_card(array('user_id' => $user_id)); break; case 'messages': $total_messages = $object['total_messages']; $additional_messages = $total_messages - 1; ob_start(); ?> <ul> <li><?php echo CRM_UD_F::parse_urls(nl2br($object['text']), 100, '_blank'); ?> </li> <?php if ($associated_object) { ?> <li><?php echo sprintf(__('Related %s:', 'wp_crm'), $post_type->labels->singular_name); ?> <a href="<?php echo admin_url("post.php?post={$associated_object->post_ID}&action=edit"); ?> " target="_blank"><?php echo $associated_object->post_title; ?> </a></li> <?php } ?> <li><?php echo human_time_diff(strtotime($object['time'])); ?> <?php _e('ago'); ?> . <?php if ($additional_messages) { echo '<a href="' . admin_url("admin.php?page=wp_crm_add_new&user_id={$user_id}") . '">' . $additional_messages . ' ' . __('other messages.') . '</a>'; } ?> </li> </ul> <?php $row_actions = array('trash_message' => __('Trash')); if ($object['status'] != 'archived') { $row_actions['archive_message'] = __('Archive', 'wp_crm'); } //** Only allow Trashing of recently registered users */ $week_ago = date('Y-m-d', strtotime('-3 days')); if ($wpdb->get_var("SELECT ID FROM {$wpdb->users} WHERE ID = {$user_id} AND user_registered > '{$week_ago}'") && get_user_meta($user_id, 'wpc_cm_generated_account')) { $row_actions['trash_message_and_user'] = __('Trash Message and User', 'wp_crm'); $verify_actions['trash_message_and_user'] = true; } $row_actions = apply_filters('wp_crm_message_quick_actions', $row_actions); $verify_actions = apply_filters('wp_crm_message_quick_actions_verification', $verify_actions); ?> <?php if ($row_actions) { ?> <div class="row-actions"> <?php foreach ($row_actions as $action => $title) { ?> <span wp_crm_action="<?php echo $action; ?> " <?php echo $verify_actions[$action] ? 'verify_action="true"' : ''; ?> object_id="<?php echo $object['ID']; ?> " class="<?php echo $action; ?> wp_crm_message_quick_action"><?php echo $title; ?> </span> <?php } ?> </div> <?php } ?> <?php $content = ob_get_contents(); ob_end_clean(); $r .= $content; break; case 'other_messages': break; } return $r; }
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; }