/** * 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); }
/** * Function for inserting topic data when it's first published. * * @since 1.0.0 * @access public * @param object $post * @return void */ function mb_insert_topic_data($post) { /* Hook for before inserting topic data. */ do_action('mb_before_insert_topic_data', $post); /* Get the topic ID. */ $topic_id = mb_get_topic_id($post->ID); /* Get the forum ID. */ $forum_id = mb_get_forum_id($post->post_parent); /* 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); /* Add topic meta. */ mb_set_topic_activity_datetime($topic_id, $post_date); mb_set_topic_activity_epoch($topic_id, $post_epoch); mb_set_topic_voices($topic_id, $user_id); mb_set_topic_voice_count($topic_id, 1); mb_set_topic_reply_count($topic_id, 0); /* If we have a forum ID. */ if (0 < $forum_id) { $topic_count = mb_get_forum_topic_count($forum_id); /* 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_topic_id($forum_id, $topic_id); mb_set_forum_topic_count($forum_id, absint($topic_count) + 1); } /* Notify subscribers that there's a new topic. */ mb_notify_subscribers($post); /* Hook for after inserting topic data. */ do_action('mb_after_insert_topic_data', $post); }
/** * Returns a user's post count (topics + replies). * * @since 1.0.0 * @access public * @param int $user_id * @return int */ function mb_get_user_post_count($user_id = 0) { $user_id = mb_get_user_id($user_id); $topic_count = mb_get_user_topic_count($user_id); $reply_count = mb_get_user_reply_count($user_id); $count = $topic_count + $reply_count; return apply_filters('mb_get_user_post_count', $count, $user_id); }
echo get_avatar(mb_get_user_id()); ?> <div class="mb-user-info"> <ul> <li><?php printf(__('Forum role: %s', 'message-board'), mb_get_role_link(mb_get_user_role())); ?> </li> <li><?php printf(__('Forums created: %s', 'message-board'), mb_get_user_forum_count()); ?> </li> <li><?php printf(__('Topics started: %s', 'message-board'), mb_get_user_topic_count()); ?> </li> <li><?php printf(__('Replies posted: %s', 'message-board'), mb_get_user_reply_count()); ?> </li> <li><?php printf(__('Member since: %s', 'message-board'), date(get_option('date_format'), strtotime(get_the_author_meta('user_registered', get_query_var('author'))))); ?> </li> <li><?php printf(__('Web site: %s', 'message-board'), make_clickable(get_the_author_meta('url', get_query_var('author')))); ?> </li> </ul>
/** * Handles the output for custom columns. * * @since 1.0.0 * @access public * @param string $column * @param string $column_name * @param int $post_id */ public function custom_column($column, $column_name, $user_id) { /* Post status column. */ if ('topics' === $column_name) { $user_id = mb_get_user_id($user_id); $topic_count = mb_get_user_topic_count($user_id); /* If the current user can create topics, link the topic count back to the edit topics screen. */ if (!empty($topic_count) && current_user_can('create_topics')) { $url = add_query_arg(array('post_type' => mb_get_topic_post_type(), 'author' => $user_id), admin_url('edit.php')); $column = sprintf('<a href="%s" title="%s">%s</a>', esc_url($url), __('View topics by this user', 'message-board'), $topic_count); /* Else, display the count. */ } else { $column = !empty($topic_count) ? $topic_count : number_format_i18n(0); } /* Replies column. */ } elseif ('replies' === $column_name) { $user_id = mb_get_user_id($user_id); $reply_count = mb_get_user_reply_count($user_id); /* If the current user can create replies, link the topic count back to the edit replies screen. */ if (!empty($reply_count) && current_user_can('create_replies')) { $url = add_query_arg(array('post_type' => mb_get_reply_post_type(), 'author' => $user_id), admin_url('edit.php')); $column = sprintf('<a href="%s" title="%s">%s</a>', esc_url($url), __('View replies by this user', 'message-board'), $reply_count); /* Else, display the count. */ } else { $column = !empty($reply_count) ? $reply_count : number_format_i18n(0); } } /* Return the filtered column. */ return $column; }
if (get_the_author_meta('url')) { ?> <br /> <a href="<?php echo esc_url(get_the_author_meta('url'), mb_get_reply_author_id()); ?> "><?php _e('Web Site', 'message-board'); ?> </a> <?php } ?> <br /> <span class="mb-user-topic-count"><?php printf(__('Topics: %s', 'message-board'), mb_get_user_topic_count(mb_get_reply_author_id())); ?> </span> <br /> <span class="mb-user-reply-count"><?php printf(__('Replies: %s', 'message-board'), mb_get_user_reply_count(mb_get_reply_author_id())); ?> </span> </div><!-- .mb-author-info --> </div><!-- .mb-author-box --> <div class="mb-reply-content"> <?php mb_reply_content(); ?>