/** * Manage core column content. * * @since 3.0.0 * @param array $column Column currently processed * @param integer $post_id ID of the post being processed */ public function core_custom_columns_content($column, $post_id) { switch ($column) { case 'ticket_id': $link = add_query_arg(array('post' => $post_id, 'action' => 'edit'), admin_url('post.php')); echo "<a href='{$link}'>#{$post_id}</a>"; break; case 'wpas-assignee': $assignee = get_post_meta($post_id, '_wpas_assignee', true); $agent = get_user_by('id', $assignee); echo $agent->data->display_name; break; case 'wpas-activity': $latest = null; $tags = array(); $activity_meta = get_transient("wpas_activity_meta_post_{$post_id}"); if (false === $activity_meta) { $post = get_post($post_id); $activity_meta = array(); $activity_meta['ticket_date'] = $post->post_date; /* Get the last reply if any */ $latest = new WP_Query(array('posts_per_page' => 1, 'orderby' => 'post_date', 'order' => 'DESC', 'post_type' => 'ticket_reply', 'post_parent' => $post_id, 'post_status' => array('unread', 'read'), 'no_found_rows' => true, 'cache_results' => false, 'update_post_term_cache' => false, 'update_post_meta_cache' => false)); if (!empty($latest->posts)) { $user_data = get_user_by('id', $latest->post->post_author); $activity_meta['user_link'] = add_query_arg(array('user_id' => $latest->post->post_author), admin_url('user-edit.php')); $activity_meta['user_id'] = $latest->post->post_author; $activity_meta['user_nicename'] = $user_data->user_nicename; $activity_meta['reply_date'] = $latest->post->post_date; } set_transient("wpas_activity_meta_post_{$post_id}", $activity_meta, apply_filters('wpas_activity_meta_transient_lifetime', 60 * 60 * 1)); // Set to 1 hour by default } echo '<ul>'; // if ( isset( $mode ) && 'details' == $mode ): if (1 === 1) { ?> <li><?php printf(_x('Created %s ago.', 'Ticket created on', 'wpas'), human_time_diff(get_the_time('U', $post_id), current_time('timestamp'))); ?> </li><?php /** * We check when was the last reply (if there was a reply). * Then, we compute the ticket age and if it is considered as * old, we display an informational tag. */ if (!isset($activity_meta['reply_date'])) { echo '<li>'; echo _x('No reply yet.', 'No last reply', 'wpas'); echo '</li>'; } else { $args = array('post_parent' => $post_id, 'post_type' => 'ticket_reply', 'post_status' => array('unread', 'read'), 'posts_per_page' => -1, 'orderby' => 'date', 'order' => 'DESC', 'no_found_rows' => true, 'cache_results' => false, 'update_post_term_cache' => false, 'update_post_meta_cache' => false); $query = new WP_Query($args); $role = true === user_can($activity_meta['user_id'], 'edit_ticket') ? _x('agent', 'User role', 'wpas') : _x('client', 'User role', 'wpas'); ?> <li><?php echo _x(sprintf(_n('%s reply.', '%s replies.', $query->post_count, 'wpas'), $query->post_count), 'Number of replies to a ticket', 'wpas'); ?> </li><?php ?> <li><?php printf(_x('<a href="%s">Last replied</a> %s ago by %s (%s).', 'Last reply ago', 'wpas'), add_query_arg(array('post' => $post_id, 'action' => 'edit'), admin_url('post.php')) . '#wpas-post-' . $query->posts[0]->ID, human_time_diff(strtotime($activity_meta['reply_date']), current_time('timestamp')), '<a href="' . $activity_meta['user_link'] . '">' . $activity_meta['user_nicename'] . '</a>', $role); ?> </li><?php } } /** * Add tags */ if (true === wpas_is_reply_needed($post_id, $latest)) { $color = false !== ($c = wpas_get_option('color_awaiting_reply', false)) ? $c : '#0074a2'; array_push($tags, "<span class='wpas-label' style='background-color:{$color};'>" . __('Awaiting Support Reply', 'wpas') . "</span>"); } if (true === wpas_is_ticket_old($post_id, $latest)) { $old_color = wpas_get_option('color_old'); array_push($tags, "<span class='wpas-label' style='background-color:{$old_color};'>" . __('Old', 'wpas') . "</span>"); } if (!empty($tags)) { echo '<li>' . implode(' ', $tags) . '</li>'; } echo '</ul>'; break; } }
/** * Filter the list of CSS classes for the current post. * * @since 3.3 * * @param array $classes An array of post classes. * @param array $class An array of additional classes added to the post. * @param int $post_id The post ID. * * @return array */ public function ticket_row_class($classes, $class, $post_id) { global $pagenow; if ('edit.php' !== $pagenow || !isset($_GET['post_type']) || isset($_GET['post_type']) && 'ticket' !== $_GET['post_type']) { return $classes; } if (!is_admin()) { return $classes; } if ('ticket' !== get_post_type($post_id)) { return $classes; } $replies = $this->get_replies_query($post_id); if (true === wpas_is_reply_needed($post_id, $replies)) { $classes[] = 'wpas-awaiting-support-reply'; } return $classes; }