/** * Creates a new forum query and checks if there are any forums found. * * @since 1.0.0 * @access public * @return bool */ function mb_forum_query() { $mb = message_board(); if (!is_null($mb->forum_query->query)) { $have_posts = $mb->forum_query->have_posts(); if (empty($have_posts)) { wp_reset_postdata(); } return $have_posts; } if (mb_is_forum_archive() || mb_is_user_page(array('forums', 'forum-subscriptions'))) { global $wp_query; $mb->forum_query = $wp_query; } else { $per_page = mb_get_forums_per_page(); $statuses = array(mb_get_open_post_status(), mb_get_close_post_status(), mb_get_publish_post_status(), mb_get_private_post_status(), mb_get_archive_post_status()); if (current_user_can('read_hidden_forums')) { $statuses[] = mb_get_hidden_post_status(); } $defaults = array('post_type' => mb_get_forum_post_type(), 'post_status' => $statuses, 'posts_per_page' => $per_page, 'paged' => get_query_var('paged'), 'orderby' => array('menu_order' => 'ASC', 'title' => 'ASC'), 'ignore_sticky_posts' => true); if (mb_is_single_forum()) { $defaults['post_parent'] = get_queried_object_id(); } add_filter('the_posts', 'mb_posts_hierarchy_filter', 10, 2); $mb->forum_query = new WP_Query($defaults); } return $mb->forum_query->have_posts(); }
/** * Creates a new topic query and checks if there are any topics found. Note that we ue the main * WordPress query if viewing the topic archive or a single topic. This function is a wrapper * function for the standard WP `have_posts()`, but this function should be used instead because * it must also create a query of its own under some circumstances. * * @since 1.0.0 * @access public * @return bool */ function mb_topic_query() { $mb = message_board(); /* If a query has already been created, let's roll. */ if (!is_null($mb->topic_query->query)) { $have_posts = $mb->topic_query->have_posts(); if (empty($have_posts)) { wp_reset_postdata(); } return $have_posts; } /* Use the main WP query when viewing a single topic or topic archive. */ if (mb_is_single_topic() || mb_is_topic_archive() || mb_is_user_page(array('topics', 'topic-subscriptions', 'bookmarks'))) { global $wp_the_query; $mb->topic_query = $wp_the_query; } else { $statuses = array(mb_get_open_post_status(), mb_get_close_post_status(), mb_get_publish_post_status(), mb_get_private_post_status()); if (current_user_can('read_hidden_topics')) { $statuses[] = mb_get_hidden_post_status(); } $per_page = mb_get_topics_per_page(); $defaults = array('post_type' => mb_get_topic_post_type(), 'post_status' => $statuses, 'posts_per_page' => $per_page, 'paged' => get_query_var('paged'), 'orderby' => 'menu_order', 'order' => 'DESC', 'ignore_sticky_posts' => true); if (mb_is_single_forum()) { $defaults['post_parent'] = get_queried_object_id(); add_filter('the_posts', 'mb_posts_sticky_filter', 10, 2); add_filter('the_posts', 'mb_posts_super_filter', 10, 2); } $mb->topic_query = new WP_Query($defaults); } return $mb->topic_query->have_posts(); }
/** * Creates a new reply query and checks if there are any replies found. * * @since 1.0.0 * @access public * @return bool */ function mb_reply_query() { $mb = message_board(); if (!is_null($mb->reply_query->query)) { $have_posts = $mb->reply_query->have_posts(); if (empty($have_posts)) { wp_reset_postdata(); } return $have_posts; } if (mb_is_reply_archive() || mb_is_single_reply() || mb_is_user_page('replies')) { global $wp_query; $mb->reply_query = $wp_query; } else { $per_page = mb_get_replies_per_page(); $defaults = array('post_type' => mb_get_reply_post_type(), 'post_status' => mb_get_publish_post_status(), 'posts_per_page' => $per_page, 'paged' => get_query_var('paged'), 'orderby' => 'menu_order', 'order' => 'ASC', 'hierarchical' => false, 'ignore_sticky_posts' => true); if ($mb->topic_query->in_the_loop || mb_is_single_topic()) { $defaults['post_parent'] = mb_get_topic_id(); } $mb->reply_query = new WP_Query($defaults); } return $mb->reply_query->have_posts(); }
?> <?php mb_the_topic(); // Sets up the topic data. ?> <tr <?php post_class(); ?> > <td class="mb-col-title"> <?php if (!mb_is_user_page()) { echo get_avatar(mb_get_topic_author_id()); } ?> <?php mb_topic_link(); ?> <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());
/** * Overwrites the `do_trail_items()` method and creates custom trail items. * * @since 1.0.0 * @access public * @return void */ public function do_trail_items() { /* Add the network and site home links. */ $this->do_network_home_link(); $this->do_site_home_link(); $this->mb_do_board_home_link(); /* Single forum, topic, or reply. */ if (mb_is_single_forum() || mb_is_single_topic() || mb_is_single_reply()) { $this->do_singular_items(); } elseif (mb_is_forum_archive() || mb_is_topic_archive() || mb_is_reply_archive()) { $this->do_post_type_archive_items(); } elseif (mb_is_role_archive()) { $this->mb_do_user_archive_link(); if (is_paged()) { $this->items[] = sprintf('<a href="%s">%s</a>', mb_get_role_archive_url(), mb_get_role_archive_title()); } elseif ($this->args['show_title']) { $this->items[] = mb_get_role_archive_title(); } } elseif (mb_is_single_role()) { $this->mb_do_user_archive_link(); $this->mb_do_role_archive_link(); if (is_paged()) { $this->items[] = sprintf('<a href="%s">%s</a>', mb_get_role_url(), mb_get_single_role_title()); } elseif ($this->args['show_title']) { $this->items[] = mb_get_single_role_title(); } } elseif (mb_is_user_archive()) { if (is_paged()) { $this->items[] = sprintf('<a href="%s">%s</a>', mb_get_user_archive_url(), mb_get_user_archive_title()); } elseif ($this->args['show_title']) { $this->items[] = mb_get_user_archive_title(); } } elseif (mb_is_single_user()) { $this->mb_do_user_archive_link(); /* If single user subpage. */ if (mb_is_user_page()) { $this->items[] = sprintf('<a href="%s">%s</a>', mb_get_user_url(), get_the_author_meta('display_name', mb_get_user_id())); if (is_paged()) { if (mb_is_user_forums()) { $this->items[] = sprintf('<a href="%s">%s</a>', mb_get_user_forums_url(), mb_get_user_forums_title()); } elseif (mb_is_user_topics()) { $this->items[] = sprintf('<a href="%s">%s</a>', mb_get_user_topics_url(), mb_get_user_topics_title()); } elseif (mb_is_user_replies()) { $this->items[] = sprintf('<a href="%s">%s</a>', mb_get_user_replies_url(), mb_get_user_replies_title()); } elseif (mb_is_user_bookmarks()) { $this->items[] = sprintf('<a href="%s">%s</a>', mb_get_user_bookmarks_url(), mb_get_user_bookmarks_title()); } elseif (mb_is_user_forum_subscriptions()) { $this->items[] = sprintf('<a href="%s">%s</a>', mb_get_user_forum_subscriptions_url(), mb_get_user_forum_subscriptions_title()); } elseif (mb_is_user_topic_subscriptions()) { $this->items[] = sprintf('<a href="%s">%s</a>', mb_get_user_topic_subscriptions_url(), mb_get_user_topic_subscriptions_title()); } } elseif ($this->args['show_title']) { $this->items[] = mb_get_user_page_title(); } /* If viewing the single user page but not a subpage. */ } elseif ($this->args['show_title']) { $this->items[] = mb_get_single_user_title(); } /* Login page. */ } elseif (mb_is_forum_login()) { $this->items[] = mb_get_login_page_title(); } /* Add paged items. */ $this->do_paged_items(); /* Return the board breadcrumb trail items. */ $this->items = apply_filters('mb_get_breadcrumb_trail_items', $this->items, $this->args); }
/** * Builds the template hierarchy for the plugin. This function figures out what the current page * is and returns an array of possible templates to use. Note that this function only returns * the templates name and not a full paths. It is meant to be used within other functions that actually * locate/load the templates. * * @since 1.0.0 * @access public * @return array */ function mb_get_template_hierarchy() { $hierarchy = array(); /* If viewing a single forum page. */ if (mb_is_single_forum()) { $hierarchy[] = 'single-forum.php'; /* If viewing the forum archive (default forum front). */ } elseif (mb_is_forum_archive()) { $hierarchy[] = 'archive-forum.php'; /* If viewing a single topic. */ } elseif (mb_is_single_topic()) { $hierarchy[] = "single-topic.php"; /* If viewing the topic archive (possible forum front page). */ } elseif (mb_is_topic_archive()) { $hierarchy[] = 'archive-topic.php'; /* If viewing a single reply. */ } elseif (mb_is_single_reply()) { $hierarchy[] = "single-reply.php"; /* If viewing the reply archive. */ } elseif (mb_is_reply_archive()) { $hierarchy[] = 'archive-reply.php'; } elseif (mb_is_role_archive()) { $hierarchy[] = 'archive-role.php'; } elseif (mb_is_single_role()) { $hierarchy[] = 'single-role.php'; /* If viewing a user sub-page. */ } elseif (mb_is_user_page()) { $page = sanitize_key(get_query_var('mb_user_page')); $hierarchy[] = "single-user-{$page}.php"; $hierarchy[] = 'single-user.php'; /* If viewing a user profile page. */ } elseif (mb_is_single_user()) { $hierarchy[] = 'single-user.php'; /* If viewing the user archive. */ } elseif (mb_is_user_archive()) { $hierarchy[] = 'archive-user.php'; /* If viewing a search results page. */ } elseif (mb_is_search_results()) { $hierarchy[] = 'search-results.php'; /* If viewing the advanced search page. */ } elseif (mb_is_search()) { $hierarchy[] = 'search.php'; /* If viewing the forum login page. */ } elseif (mb_is_forum_login()) { $hierarchy[] = 'login.php'; /* If viewing an edit page. */ } elseif (mb_is_edit()) { if (mb_is_forum_edit()) { $hierarchy[] = 'edit-forum.php'; } elseif (mb_is_topic_edit()) { $hierarchy[] = 'edit-topic.php'; } elseif (mb_is_reply_edit()) { $hierarchy[] = 'edit-reply.php'; } elseif (mb_is_user_edit()) { $hierarchy[] = 'edit-user.php'; } $hierarchy[] = 'edit.php'; } /* Add the fallback template. */ $hierarchy[] = 'board.php'; return apply_filters('mb_get_template_hierarchy', $hierarchy); }
/** * Overwrites the main query depending on the situation. * * @since 1.0.0 * @access public * @param object $query * @return void */ function mb_pre_get_posts($query) { /* If viewing an admin page or this isn't the main query, bail. */ if (is_admin() || !$query->is_main_query()) { return; } /* If viewing the forum archive page. */ if (mb_is_forum_archive()) { $statuses = array(mb_get_open_post_status(), mb_get_close_post_status(), mb_get_publish_post_status(), mb_get_private_post_status(), mb_get_archive_post_status()); if (current_user_can('read_hidden_forums')) { $statuses[] = mb_get_hidden_post_status(); } $query->set('post_type', mb_get_forum_post_type()); $query->set('post_status', $statuses); $query->set('posts_per_page', mb_get_forums_per_page()); $query->set('orderby', array('menu_order' => 'ASC', 'title' => 'ASC')); $query->set('post_parent', 0); add_filter('the_posts', 'mb_posts_hierarchy_filter', 10, 2); } elseif (mb_is_topic_archive()) { $statuses = array(mb_get_open_post_status(), mb_get_close_post_status(), mb_get_publish_post_status(), mb_get_private_post_status()); if (current_user_can('read_hidden_topics')) { $statuses[] = mb_get_hidden_post_status(); } $query->set('post_type', mb_get_topic_post_type()); $query->set('post_status', $statuses); $query->set('posts_per_page', mb_get_topics_per_page()); $query->set('order', 'DESC'); $query->set('orderby', 'menu_order'); add_filter('the_posts', 'mb_posts_super_filter', 10, 2); } elseif (mb_is_user_page()) { /* Single user forums created page. */ if (mb_is_user_page('forums')) { $query->set('post_type', mb_get_forum_post_type()); $query->set('posts_per_page', mb_get_forums_per_page()); $query->set('order', 'ASC'); $query->set('orderby', 'title'); /* Single user topics created page. */ } elseif (mb_is_user_page('topics')) { $query->set('post_type', mb_get_topic_post_type()); $query->set('posts_per_page', mb_get_topics_per_page()); $query->set('order', 'DESC'); $query->set('orderby', 'menu_order'); /* Single user replies created page. */ } elseif (mb_is_user_page('replies')) { $query->set('post_type', mb_get_reply_post_type()); $query->set('posts_per_page', mb_get_replies_per_page()); $query->set('order', 'DESC'); $query->set('orderby', 'date'); /* Single user bookmarks saved page. */ } elseif (mb_is_user_page('bookmarks')) { $user = get_user_by('slug', get_query_var('author_name')); $favs = get_user_meta($user->ID, mb_get_user_topic_bookmarks_meta_key(), true); $favs = wp_parse_id_list($favs); /* Empty array with `post_in` hack. @link https://core.trac.wordpress.org/ticket/28099 */ if (empty($favs)) { $favs = array(0); } $query->set('post__in', $favs); $query->set('post_type', mb_get_topic_post_type()); $query->set('posts_per_page', mb_get_topics_per_page()); $query->set('order', 'DESC'); $query->set('orderby', 'menu_order'); add_filter('posts_where', 'mb_auth_posts_where', 10, 2); /* Single user topic subscriptions page. */ } elseif (mb_is_user_page('topic-subscriptions')) { $user = get_user_by('slug', get_query_var('author_name')); $subs = mb_get_user_topic_subscriptions($user->ID); /* Empty array with `post_in` hack. @link https://core.trac.wordpress.org/ticket/28099 */ if (empty($subs)) { $subs = array(0); } $query->set('post__in', $subs); $query->set('post_type', mb_get_topic_post_type()); $query->set('posts_per_page', mb_get_topics_per_page()); $query->set('order', 'DESC'); $query->set('orderby', 'menu_order'); add_filter('posts_where', 'mb_auth_posts_where', 10, 2); /* Single user forum subscriptions page. */ } elseif (mb_is_user_page('forum-subscriptions')) { $user = get_user_by('slug', get_query_var('author_name')); $subs = mb_get_user_forum_subscriptions($user->ID); /* Empty array with `post_in` hack. @link https://core.trac.wordpress.org/ticket/28099 */ if (empty($subs)) { $subs = array(0); } $query->set('post__in', $subs); $query->set('post_type', mb_get_forum_post_type()); $query->set('posts_per_page', mb_get_forums_per_page()); $query->set('order', 'DESC'); $query->set('orderby', 'menu_order'); add_filter('posts_where', 'mb_auth_posts_where', 10, 2); } } elseif (mb_is_search_results()) { $post_type = $query->get('post_type'); /* If not searching a specific post type, make sure to search all forum-related post types. */ if (empty($post_type) || 'any' === $post_type || !isset($_GET['mb_search_mode'])) { $query->set('post_type', array(mb_get_forum_post_type(), mb_get_topic_post_type(), mb_get_reply_post_type())); } $query->set('post_status', array(mb_get_open_post_status(), mb_get_close_post_status(), mb_get_publish_post_status())); $query->set('posts_per_page', mb_get_topics_per_page()); } elseif (mb_is_user_archive() && get_query_var('mb_role')) { $role = get_query_var('mb_role'); if ($role && in_array("mb_{$role}", array_keys(mb_get_dynamic_roles()))) { $query->set('mb_role', "mb_{$role}"); } } elseif ($query->is_single && isset($query->query_vars['post_type']) && in_array($query->query_vars['post_type'], array(mb_get_forum_post_type(), mb_get_topic_post_type(), mb_get_reply_post_type()))) { add_filter('the_posts', 'mb_posts_can_read_parent'); } }
?> <?php mb_get_template_part('loop-forum', mb_show_hierarchical_forums() ? 'hierarchical' : 'flat'); ?> <?php } elseif (mb_is_user_page(array('topics', 'topic-subscriptions', 'bookmarks'))) { ?> <?php mb_get_template_part('loop-topic'); ?> <?php } elseif (mb_is_user_page('replies')) { ?> <?php mb_get_template_part('loop-reply'); ?> <?php } else { ?> <?php echo get_avatar(mb_get_user_id()); ?> <div class="mb-user-info">
/** * Filters `wp_title` to handle the title on the forum front page since this is a non-standard WP page. * * @since 1.0.0 * @access public * @param string $title * @return string */ function mb_wp_title($title) { if (!mb_is_message_board()) { return $title; } if (mb_is_single_forum()) { $title = mb_get_single_forum_title(); } elseif (mb_is_forum_archive()) { $title = mb_get_forum_archive_title(); } elseif (mb_is_single_topic()) { $title = mb_get_single_topic_title(); } elseif (mb_is_topic_archive()) { $title = mb_get_topic_archive_title(); } elseif (mb_is_single_reply()) { $title = mb_get_single_reply_title(); } elseif (mb_is_reply_archive()) { $title = mb_get_reply_archive_title(); } elseif (mb_is_single_role()) { $title = mb_get_single_role_title(); } elseif (mb_is_role_archive()) { $title = mb_get_role_archive_title(); } elseif (mb_is_user_page()) { $title = mb_get_user_page_title(); } elseif (mb_is_single_user()) { $title = mb_get_single_user_title(); } elseif (mb_is_user_archive()) { $title = mb_get_user_archive_title(); } elseif (mb_is_search()) { $title = mb_get_search_page_title(); } elseif (mb_is_forum_login()) { $title = mb_get_login_page_title(); } else { $title = __('Board', 'message-board'); } return apply_filters('mb_wp_title', $title); }