/** * Function for inserting reply data when it's first published. * * @since 1.0.0 * @access public * @param object $post * @return void */ function mb_insert_reply_data($post) { /* Hook for before inserting reply data. */ do_action('mb_before_insert_reply_data', $post); /* Get the reply ID. */ $reply_id = mb_get_reply_id($post->ID); /* Get the topic ID. */ $topic_id = mb_get_topic_id($post->post_parent); /* Get the forum ID. */ $forum_id = mb_get_topic_forum_id($topic_id); /* Get the user ID. */ $user_id = mb_get_user_id($post->post_author); /* Get the post date. */ $post_date = $post->post_date; $post_epoch = mysql2date('U', $post_date); /* Update user meta. */ $topic_count = mb_get_user_topic_count($user_id); update_user_meta($user_id, mb_get_user_topic_count_meta_key(), $topic_count + 1); /* Update topic position. */ mb_set_topic_position($topic_id, $post_epoch); /* Update topic meta. */ mb_set_topic_activity_datetime($topic_id, $post_date); mb_set_topic_activity_epoch($topic_id, $post_epoch); mb_set_topic_last_reply_id($topic_id, $reply_id); $voices = mb_get_topic_voices($topic_id); if (!in_array($user_id, $voices)) { $voices[] = $user_id; mb_set_topic_voices($topic_id, $voices); mb_set_topic_voice_count($topic_id, count($voices)); } $topic_reply_count = mb_get_topic_reply_count($topic_id); mb_set_topic_reply_count($topic_id, absint($topic_reply_count) + 1); $forum_reply_count = absint(mb_get_forum_reply_count($forum_id)) + 1; /* Update forum meta. */ mb_set_forum_activity_datetime($forum_id, $post_date); mb_set_forum_activity_epoch($forum_id, $post_epoch); mb_set_forum_last_reply_id($forum_id, $reply_id); mb_set_forum_last_topic_id($forum_id, $topic_id); mb_set_forum_reply_count($forum_id, $forum_reply_count); /* Notify subscribers that there's a new reply. */ mb_notify_subscribers($post); /* Hook for after inserting reply data. */ do_action('mb_after_insert_reply_data', $post); }
<div class="mb-topic-meta"> <?php mb_topic_states(); ?> <?php /* Translators: Topic author and date. 1 is the topic author. 2 is the topic date. */ printf(__('Started by %1$s %2$s', 'message-board'), mb_get_topic_author_profile_link(), mb_get_topic_natural_time()); ?> </div><!-- .mb-topic-meta --> </td><!-- .mb-col-title --> <td class="mb-col-count"> <?php printf(__('Replies: %s', 'message-board'), mb_get_topic_reply_count()); ?> <br /> <?php printf(__('Voices: %s', 'message-board'), mb_get_topic_voice_count()); ?> </td><!-- .mb-col-count --> <td class="mb-col-latest"> <?php mb_topic_last_poster(); ?> <br /> <a href="<?php mb_topic_last_post_url(); ?>
/** * Handles the output for custom columns. * * @since 1.0.0 * @access public * @param string $column * @param int $post_id */ public function manage_columns($column, $post_id) { /* Post status column. */ if ('status' === $column) { $post_type = mb_get_topic_post_type(); $status = get_post_status_object(mb_get_topic_status($post_id)); if (mb_get_publish_post_status() === $status->name) { wp_update_post(array('ID' => $post_id, 'post_status' => mb_get_open_post_status())); } $url = add_query_arg(array('post_status' => $status->name, 'post_type' => $post_type), admin_url('edit.php')); printf('<a href="%s">%s</a>', $url, $status->label); /* Topic forum column. */ } elseif ('forum' === $column) { $post_type = mb_get_topic_post_type(); $forum_id = mb_get_topic_forum_id($post_id); $url = add_query_arg(array('post_type' => $post_type, 'post_parent' => $forum_id), admin_url('edit.php')); printf('<a href="%s">%s</a>', $url, mb_get_forum_title($forum_id)); /* Replies column. */ } elseif ('replies' === $column) { $reply_count = mb_get_topic_reply_count($post_id); $reply_count = !empty($reply_count) ? absint($reply_count) : number_format_i18n(0); if (0 < $reply_count && current_user_can('edit_replies')) { printf('<a href="%s">%s</a>', add_query_arg(array('post_type' => mb_get_reply_post_type(), 'post_parent' => $post_id), admin_url('edit.php')), $reply_count); } else { echo $reply_count; } /* Voices column. */ } elseif ('voices' === $column) { $voice_count = mb_get_topic_voice_count($post_id); echo !empty($voice_count) ? absint($voice_count) : number_format_i18n(0); /* Datetime column. */ } elseif ('datetime' === $column) { the_time(get_option('date_format')); echo '<br />'; the_time(get_option('time_format')); } }
/** * Returns the topic post count (topic + reply count). * * @since 1.0.0 * @access public * @param int $topic_id * @return string */ function mb_get_topic_post_count($topic_id = 0) { $post_count = 1 + mb_get_topic_reply_count($topic_id); return apply_filters('mb_get_topic_post_count', $post_count, $topic_id); }