function bbppt_get_forum_parent_id($forum_id = 0) { if (function_exists('bbp_get_forum_parent_id')) { return bbp_get_forum_parent_id($forum_id); } return bbp_get_forum_parent($forum_id); }
/** * @group canonical * @covers ::bbp_insert_forum */ public function test_bbp_insert_forum() { $f = $this->factory->forum->create(array('post_title' => 'Forum 1', 'post_content' => 'Content of Forum 1')); $now = time(); $post_date = date('Y-m-d H:i:s', $now - 60 * 60 * 100); $t = $this->factory->topic->create(array('post_parent' => $f, 'post_date' => $post_date, 'topic_meta' => array('forum_id' => $f))); $r = $this->factory->reply->create(array('post_parent' => $t, 'post_date' => $post_date, 'reply_meta' => array('forum_id' => $f, 'topic_id' => $t))); // Get the forum. $forum = bbp_get_forum($f); // Forum post. $this->assertSame('Forum 1', bbp_get_forum_title($f)); $this->assertSame('Content of Forum 1', bbp_get_forum_content($f)); $this->assertSame('open', bbp_get_forum_status($f)); $this->assertSame('forum', bbp_get_forum_type($f)); $this->assertTrue(bbp_is_forum_public($f)); $this->assertSame(0, bbp_get_forum_parent_id($f)); $this->assertEquals('http://' . WP_TESTS_DOMAIN . '/?forum=' . $forum->post_name, $forum->guid); // Forum meta. $this->assertSame(0, bbp_get_forum_subforum_count($f, true)); $this->assertSame(1, bbp_get_forum_topic_count($f, false, true)); $this->assertSame(1, bbp_get_forum_topic_count($f, true, true)); $this->assertSame(0, bbp_get_forum_topic_count_hidden($f, true)); $this->assertSame(1, bbp_get_forum_reply_count($f, false, true)); $this->assertSame(1, bbp_get_forum_reply_count($f, true, true)); $this->assertSame(2, bbp_get_forum_post_count($f, false, true)); $this->assertSame(2, bbp_get_forum_post_count($f, true, true)); $this->assertSame($t, bbp_get_forum_last_topic_id($f)); $this->assertSame($r, bbp_get_forum_last_reply_id($f)); $this->assertSame($r, bbp_get_forum_last_active_id($f)); $this->assertSame('4 days, 4 hours ago', bbp_get_forum_last_active_time($f)); }
/** * Runs through the various bbPress conditional tags to check the current page being viewed. Once * a condition is met, add items to the $items array. * * @since 0.6.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(); /* Get the forum post type object. */ $post_type_object = get_post_type_object(bbp_get_forum_post_type()); /* If not viewing the forum root/archive page and a forum archive exists, add it. */ if (!empty($post_type_object->has_archive) && !bbp_is_forum_archive()) { $this->items[] = '<a href="' . get_post_type_archive_link(bbp_get_forum_post_type()) . '">' . bbp_get_forum_archive_title() . '</a>'; } /* If viewing the forum root/archive. */ if (bbp_is_forum_archive()) { if (true === $this->args['show_title']) { $this->items[] = bbp_get_forum_archive_title(); } } elseif (bbp_is_topic_archive()) { if (true === $this->args['show_title']) { $this->items[] = bbp_get_topic_archive_title(); } } elseif (bbp_is_topic_tag()) { if (true === $this->args['show_title']) { $this->items[] = bbp_get_topic_tag_name(); } } elseif (bbp_is_topic_tag_edit()) { $this->items[] = '<a href="' . bbp_get_topic_tag_link() . '">' . bbp_get_topic_tag_name() . '</a>'; if (true === $this->args['show_title']) { $this->items[] = __('Edit', 'breadcrumb-trail'); } } elseif (bbp_is_single_view()) { if (true === $this->args['show_title']) { $this->items[] = bbp_get_view_title(); } } elseif (bbp_is_single_topic()) { /* Get the queried topic. */ $topic_id = get_queried_object_id(); /* Get the parent items for the topic, which would be its forum (and possibly forum grandparents). */ $this->do_post_parents(bbp_get_topic_forum_id($topic_id)); /* If viewing a split, merge, or edit topic page, show the link back to the topic. Else, display topic title. */ if (bbp_is_topic_split() || bbp_is_topic_merge() || bbp_is_topic_edit()) { $this->items[] = '<a href="' . bbp_get_topic_permalink($topic_id) . '">' . bbp_get_topic_title($topic_id) . '</a>'; } elseif (true === $this->args['show_title']) { $this->items[] = bbp_get_topic_title($topic_id); } /* If viewing a topic split page. */ if (bbp_is_topic_split() && true === $this->args['show_title']) { $this->items[] = __('Split', 'breadcrumb-trail'); } elseif (bbp_is_topic_merge() && true === $this->args['show_title']) { $this->items[] = __('Merge', 'breadcrumb-trail'); } elseif (bbp_is_topic_edit() && true === $this->args['show_title']) { $this->items[] = __('Edit', 'breadcrumb-trail'); } } elseif (bbp_is_single_reply()) { /* Get the queried reply object ID. */ $reply_id = get_queried_object_id(); /* Get the parent items for the reply, which should be its topic. */ $this->do_post_parents(bbp_get_reply_topic_id($reply_id)); /* If viewing a reply edit page, link back to the reply. Else, display the reply title. */ if (bbp_is_reply_edit()) { $this->items[] = '<a href="' . bbp_get_reply_url($reply_id) . '">' . bbp_get_reply_title($reply_id) . '</a>'; if (true === $this->args['show_title']) { $this->items[] = __('Edit', 'breadcrumb-trail'); } } elseif (true === $this->args['show_title']) { $this->items[] = bbp_get_reply_title($reply_id); } } elseif (bbp_is_single_forum()) { /* Get the queried forum ID and its parent forum ID. */ $forum_id = get_queried_object_id(); $forum_parent_id = bbp_get_forum_parent_id($forum_id); /* If the forum has a parent forum, get its parent(s). */ if (0 !== $forum_parent_id) { $this->do_post_parents($forum_parent_id); } /* Add the forum title to the end of the trail. */ if (true === $this->args['show_title']) { $this->items[] = bbp_get_forum_title($forum_id); } } elseif (bbp_is_single_user() || bbp_is_single_user_edit()) { if (bbp_is_single_user_edit()) { $this->items[] = '<a href="' . bbp_get_user_profile_url() . '">' . bbp_get_displayed_user_field('display_name') . '</a>'; if (true === $this->args['show_title']) { $this->items[] = __('Edit', 'breadcrumb-trail'); } } elseif (true === $this->args['show_title']) { $this->items[] = bbp_get_displayed_user_field('display_name'); } } /* Return the bbPress breadcrumb trail items. */ $this->items = apply_filters('breadcrumb_trail_get_bbpress_items', $this->items, $this->args); }
/** * Handles the front end edit forum submission * * @param string $action The requested action to compare this function to * @uses bbPress:errors::add() To log various error messages * @uses bbp_get_forum() To get the forum * @uses bbp_verify_nonce_request() To verify the nonce and check the request * @uses bbp_is_forum_anonymous() To check if forum is by an anonymous user * @uses current_user_can() To check if the current user can edit the forum * @uses bbp_filter_anonymous_post_data() To filter anonymous data * @uses is_wp_error() To check if the value retrieved is a {@link WP_Error} * @uses esc_attr() For sanitization * @uses bbp_is_forum_category() To check if the forum is a category * @uses bbp_is_forum_closed() To check if the forum is closed * @uses bbp_is_forum_private() To check if the forum is private * @uses remove_filter() To remove kses filters if needed * @uses apply_filters() Calls 'bbp_edit_forum_pre_title' with the title and * forum id * @uses apply_filters() Calls 'bbp_edit_forum_pre_content' with the content * and forum id * @uses bbPress::errors::get_error_codes() To get the {@link WP_Error} errors * @uses wp_save_post_revision() To save a forum revision * @uses bbp_update_forum_revision_log() To update the forum revision log * @uses wp_update_post() To update the forum * @uses do_action() Calls 'bbp_edit_forum' with the forum id, forum id, * anonymous data and reply author * @uses bbp_move_forum_handler() To handle movement of a forum from one forum * to another * @uses bbp_get_forum_permalink() To get the forum permalink * @uses wp_safe_redirect() To redirect to the forum link * @uses bbPress::errors::get_error_messages() To get the {@link WP_Error} error * messages */ function bbp_edit_forum_handler($action = '') { // Bail if action is not bbp-edit-forum if ('bbp-edit-forum' !== $action) { return; } // Define local variable(s) $anonymous_data = array(); $forum = $forum_id = $forum_parent_id = 0; $forum_title = $forum_content = $forum_edit_reason = ''; /** Forum *****************************************************************/ // Forum id was not passed if (empty($_POST['bbp_forum_id'])) { bbp_add_error('bbp_edit_forum_id', __('<strong>ERROR</strong>: Forum ID not found.', 'bbpress')); return; // Forum id was passed } elseif (is_numeric($_POST['bbp_forum_id'])) { $forum_id = (int) $_POST['bbp_forum_id']; $forum = bbp_get_forum($forum_id); } // Nonce check if (!bbp_verify_nonce_request('bbp-edit-forum_' . $forum_id)) { bbp_add_error('bbp_edit_forum_nonce', __('<strong>ERROR</strong>: Are you sure you wanted to do that?', 'bbpress')); return; // Forum does not exist } elseif (empty($forum)) { bbp_add_error('bbp_edit_forum_not_found', __('<strong>ERROR</strong>: The forum you want to edit was not found.', 'bbpress')); return; // User cannot edit this forum } elseif (!current_user_can('edit_forum', $forum_id)) { bbp_add_error('bbp_edit_forum_permissions', __('<strong>ERROR</strong>: You do not have permission to edit that forum.', 'bbpress')); return; } // Remove kses filters from title and content for capable users and if the nonce is verified if (current_user_can('unfiltered_html') && !empty($_POST['_bbp_unfiltered_html_forum']) && wp_create_nonce('bbp-unfiltered-html-forum_' . $forum_id) === $_POST['_bbp_unfiltered_html_forum']) { remove_filter('bbp_edit_forum_pre_title', 'wp_filter_kses'); remove_filter('bbp_edit_forum_pre_content', 'bbp_encode_bad', 10); remove_filter('bbp_edit_forum_pre_content', 'bbp_filter_kses', 30); } /** Forum Parent ***********************************************************/ // Forum parent id was passed if (!empty($_POST['bbp_forum_parent_id'])) { $forum_parent_id = bbp_get_forum_id($_POST['bbp_forum_parent_id']); } // Current forum this forum is in $current_parent_forum_id = bbp_get_forum_parent_id($forum_id); // Forum exists if (!empty($forum_parent_id) && $forum_parent_id !== $current_parent_forum_id) { // Forum is closed and user cannot access if (bbp_is_forum_closed($forum_parent_id) && !current_user_can('edit_forum', $forum_parent_id)) { bbp_add_error('bbp_edit_forum_forum_closed', __('<strong>ERROR</strong>: This forum has been closed to new forums.', 'bbpress')); } // Forum is private and user cannot access if (bbp_is_forum_private($forum_parent_id) && !current_user_can('read_private_forums')) { bbp_add_error('bbp_edit_forum_forum_private', __('<strong>ERROR</strong>: This forum is private and you do not have the capability to read or create new forums in it.', 'bbpress')); } // Forum is hidden and user cannot access if (bbp_is_forum_hidden($forum_parent_id) && !current_user_can('read_hidden_forums')) { bbp_add_error('bbp_edit_forum_forum_hidden', __('<strong>ERROR</strong>: This forum is hidden and you do not have the capability to read or create new forums in it.', 'bbpress')); } } /** Forum Title ***********************************************************/ if (!empty($_POST['bbp_forum_title'])) { $forum_title = esc_attr(strip_tags($_POST['bbp_forum_title'])); } // Filter and sanitize $forum_title = apply_filters('bbp_edit_forum_pre_title', $forum_title, $forum_id); // No forum title if (empty($forum_title)) { bbp_add_error('bbp_edit_forum_title', __('<strong>ERROR</strong>: Your forum needs a title.', 'bbpress')); } /** Forum Content *********************************************************/ if (!empty($_POST['bbp_forum_content'])) { $forum_content = $_POST['bbp_forum_content']; } // Filter and sanitize $forum_content = apply_filters('bbp_edit_forum_pre_content', $forum_content, $forum_id); // No forum content if (empty($forum_content)) { bbp_add_error('bbp_edit_forum_content', __('<strong>ERROR</strong>: Your forum description cannot be empty.', 'bbpress')); } /** Forum Blacklist *******************************************************/ if (!bbp_check_for_blacklist($anonymous_data, bbp_get_forum_author_id($forum_id), $forum_title, $forum_content)) { bbp_add_error('bbp_forum_blacklist', __('<strong>ERROR</strong>: Your forum cannot be edited at this time.', 'bbpress')); } /** Forum Moderation ******************************************************/ $post_status = bbp_get_public_status_id(); if (!bbp_check_for_moderation($anonymous_data, bbp_get_forum_author_id($forum_id), $forum_title, $forum_content)) { $post_status = bbp_get_pending_status_id(); } /** Additional Actions (Before Save) **************************************/ do_action('bbp_edit_forum_pre_extras', $forum_id); // Bail if errors if (bbp_has_errors()) { return; } /** No Errors *************************************************************/ // Add the content of the form to $forum_data as an array // Just in time manipulation of forum data before being edited $forum_data = apply_filters('bbp_edit_forum_pre_insert', array('ID' => $forum_id, 'post_title' => $forum_title, 'post_content' => $forum_content, 'post_status' => $post_status, 'post_parent' => $forum_parent_id)); // Insert forum $forum_id = wp_update_post($forum_data); /** Revisions *************************************************************/ /** * @todo omitted for 2.1 // Revision Reason if ( !empty( $_POST['bbp_forum_edit_reason'] ) ) $forum_edit_reason = esc_attr( strip_tags( $_POST['bbp_forum_edit_reason'] ) ); // Update revision log if ( !empty( $_POST['bbp_log_forum_edit'] ) && ( "1" === $_POST['bbp_log_forum_edit'] ) && ( $revision_id = wp_save_post_revision( $forum_id ) ) ) { bbp_update_forum_revision_log( array( 'forum_id' => $forum_id, 'revision_id' => $revision_id, 'author_id' => bbp_get_current_user_id(), 'reason' => $forum_edit_reason ) ); } */ /** No Errors *************************************************************/ if (!empty($forum_id) && !is_wp_error($forum_id)) { // Update counts, etc... do_action('bbp_edit_forum', array('forum_id' => $forum_id, 'post_parent' => $forum_parent_id, 'forum_author' => $forum->post_author, 'last_topic_id' => 0, 'last_reply_id' => 0, 'last_active_id' => 0, 'last_active_time' => 0, 'last_active_status' => bbp_get_public_status_id())); // If the new forum parent id is not equal to the old forum parent // id, run the bbp_move_forum action and pass the forum's parent id // as the first arg and new forum parent id as the second. // @todo implement //if ( $forum_id !== $forum->post_parent ) // bbp_move_forum_handler( $forum_parent_id, $forum->post_parent, $forum_id ); /** Additional Actions (After Save) ***********************************/ do_action('bbp_edit_forum_post_extras', $forum_id); /** Redirect **********************************************************/ // Redirect to $redirect_to = bbp_get_redirect_to(); // View all? $view_all = bbp_get_view_all(); // Get the forum URL $forum_url = bbp_get_forum_permalink($forum_id, $redirect_to); // Add view all? if (!empty($view_all)) { $forum_url = bbp_add_view_all($forum_url); } // Allow to be filtered $forum_url = apply_filters('bbp_edit_forum_redirect_to', $forum_url, $view_all, $redirect_to); /** Successful Edit ***************************************************/ // Redirect back to new forum wp_safe_redirect($forum_url); // For good measure exit; /** Errors ****************************************************************/ } else { $append_error = is_wp_error($forum_id) && $forum_id->get_error_message() ? $forum_id->get_error_message() . ' ' : ''; bbp_add_error('bbp_forum_error', __('<strong>ERROR</strong>: The following problem(s) have been found with your forum:' . $append_error . 'Please try again.', 'bbpress')); } }
protected function _bbpress_items() { $item = array(); $post_type_object = get_post_type_object(bbp_get_forum_post_type()); if (!empty($post_type_object->has_archive) && !bbp_is_forum_archive()) { $item[] = '<span typeof="v:Breadcrumb"><a href="' . get_post_type_archive_link(bbp_get_forum_post_type()) . '" property="v:title" rel="v:url"><span>' . bbp_get_forum_archive_title() . '</span></a></span>'; } if (bbp_is_forum_archive()) { $item[] = bbp_get_forum_archive_title(); } elseif (bbp_is_topic_archive()) { $item[] = bbp_get_topic_archive_title(); } elseif (bbp_is_single_view()) { $item[] = bbp_get_view_title(); } elseif (bbp_is_single_topic()) { $topic_id = get_queried_object_id(); $item = array_merge($item, $this->_get_parents(bbp_get_topic_forum_id($topic_id))); if (bbp_is_topic_split() || bbp_is_topic_merge() || bbp_is_topic_edit()) { $item[] = '<span typeof="v:Breadcrumb"><a href="' . bbp_get_topic_permalink($topic_id) . '" property="v:title" rel="v:url"><span>' . bbp_get_topic_title($topic_id) . '</span></a></span>'; } else { $item[] = bbp_get_topic_title($topic_id); } if (bbp_is_topic_split()) { $item[] = __('Split', DH_DOMAIN); } elseif (bbp_is_topic_merge()) { $item[] = __('Merge', DH_DOMAIN); } elseif (bbp_is_topic_edit()) { $item[] = __('Edit', DH_DOMAIN); } } elseif (bbp_is_single_reply()) { $reply_id = get_queried_object_id(); $item = array_merge($item, $this->_get_parents(bbp_get_reply_topic_id($reply_id))); if (!bbp_is_reply_edit()) { $item[] = bbp_get_reply_title($reply_id); } else { $item[] = '<span typeof="v:Breadcrumb"><a href="' . bbp_get_reply_url($reply_id) . '" property="v:title" rel="v:url"><span>' . bbp_get_reply_title($reply_id) . '</span></a></span>'; $item[] = __('Edit', DH_DOMAIN); } } elseif (bbp_is_single_forum()) { $forum_id = get_queried_object_id(); $forum_parent_id = bbp_get_forum_parent_id($forum_id); if (0 !== $forum_parent_id) { $item = array_merge($item, $this->_get_parents($forum_parent_id)); } $item[] = bbp_get_forum_title($forum_id); } elseif (bbp_is_single_user() || bbp_is_single_user_edit()) { if (bbp_is_single_user_edit()) { $item[] = '<span typeof="v:Breadcrumb"><a href="' . bbp_get_user_profile_url() . '" property="v:title" rel="v:url" ><span>' . bbp_get_displayed_user_field('display_name') . '</span></a></span>'; $item[] = __('Edit', DH_DOMAIN); } else { $item[] = bbp_get_displayed_user_field('display_name'); } } return $item; }
function cupid_breadcrumb_get_bbpress_items() { $item = array(); $post_type_object = get_post_type_object(bbp_get_forum_post_type()); if (!empty($post_type_object->has_archive) && !bbp_is_forum_archive()) { $item[] = '<li typeof="v:Breadcrumb"><a rel="v:url" property="v:title" href="' . get_post_type_archive_link(bbp_get_forum_post_type()) . '">' . bbp_get_forum_archive_title() . '</a></li>'; } if (bbp_is_forum_archive()) { $item['last'] = bbp_get_forum_archive_title(); } elseif (bbp_is_topic_archive()) { $item['last'] = bbp_get_topic_archive_title(); } elseif (bbp_is_single_view()) { $item['last'] = bbp_get_view_title(); } elseif (bbp_is_single_topic()) { $topic_id = get_queried_object_id(); $item = array_merge($item, cupid_breadcrumb_get_parents(bbp_get_topic_forum_id($topic_id))); if (bbp_is_topic_split() || bbp_is_topic_merge() || bbp_is_topic_edit()) { $item[] = '<li typeof="v:Breadcrumb"><a rel="v:url" property="v:title" href="' . bbp_get_topic_permalink($topic_id) . '">' . bbp_get_topic_title($topic_id) . '</a></li>'; } else { $item['last'] = bbp_get_topic_title($topic_id); } if (bbp_is_topic_split()) { $item['last'] = __('Split', 'cupid'); } elseif (bbp_is_topic_merge()) { $item['last'] = __('Merge', 'cupid'); } elseif (bbp_is_topic_edit()) { $item['last'] = __('Edit', 'cupid'); } } elseif (bbp_is_single_reply()) { $reply_id = get_queried_object_id(); $item = array_merge($item, cupid_breadcrumb_get_parents(bbp_get_reply_topic_id($reply_id))); if (!bbp_is_reply_edit()) { $item['last'] = bbp_get_reply_title($reply_id); } else { $item[] = '<li typeof="v:Breadcrumb"><a rel="v:url" property="v:title" href="' . bbp_get_reply_url($reply_id) . '">' . bbp_get_reply_title($reply_id) . '</a></li>'; $item['last'] = __('Edit', 'cupid'); } } elseif (bbp_is_single_forum()) { $forum_id = get_queried_object_id(); $forum_parent_id = bbp_get_forum_parent_id($forum_id); if (0 !== $forum_parent_id) { $item = array_merge($item, cupid_breadcrumb_get_parents($forum_parent_id)); } $item['last'] = bbp_get_forum_title($forum_id); } elseif (bbp_is_single_user() || bbp_is_single_user_edit()) { if (bbp_is_single_user_edit()) { $item[] = '<li typeof="v:Breadcrumb"><a rel="v:url" property="v:title" href="' . bbp_get_user_profile_url() . '">' . bbp_get_displayed_user_field('display_name') . '</a></li>'; $item['last'] = __('Edit', 'cupid'); } else { $item['last'] = bbp_get_displayed_user_field('display_name'); } } return apply_filters('cupid_breadcrumb_get_bbpress_items', $item); }
/** * Return value of forum parent * * @since bbPress (r3551) * * @uses bbp_is_topic_edit() To check if it's the topic edit page * @uses bbp_get_forum_parent_id() To get the topic forum id * @uses apply_filters() Calls 'bbp_get_form_forum_parent' with the forum * @return string Value of topic content field */ function bbp_get_form_forum_parent() { // Get _POST data if ('post' == strtolower($_SERVER['REQUEST_METHOD']) && isset($_POST['bbp_forum_id'])) { $forum_parent = $_POST['bbp_forum_id']; } elseif (bbp_is_forum_edit()) { $forum_parent = bbp_get_forum_parent_id(); } else { $forum_parent = 0; } return apply_filters('bbp_get_form_forum_parent', esc_attr($forum_parent)); }
function mk_theme_breadcrumbs() { global $mk_options, $post; $post_id = global_get_post_id(); if ($post_id) { $local_skining = get_post_meta($post_id, '_enable_local_backgrounds', true); $breadcrumb_skin = get_post_meta($post_id, '_breadcrumb_skin', true); if ($local_skining == 'true' && !empty($breadcrumb_skin)) { $breadcrumb_skin_class = $breadcrumb_skin; } else { $breadcrumb_skin_class = $mk_options['breadcrumb_skin']; } } else { $breadcrumb_skin_class = $mk_options['breadcrumb_skin']; } $delimiter = ' / '; echo '<div id="mk-breadcrumbs"><div class="mk-breadcrumbs-inner ' . $breadcrumb_skin_class . '-skin">'; if (!is_front_page()) { echo '<a href="'; echo home_url(); echo '">' . __('Home', 'mk_framework'); echo "</a>" . $delimiter; } if (function_exists('is_woocommerce') && is_woocommerce() && is_archive()) { $shop_page_id = wc_get_page_id('shop'); $shop_page = get_post($shop_page_id); $permalinks = get_option('woocommerce_permalinks'); if ($shop_page_id && $shop_page && get_option('page_on_front') !== $shop_page_id) { echo '<a href="' . get_permalink($shop_page) . '">' . $shop_page->post_title . '</a> '; } } if (is_category() && !is_singular('portfolio')) { $category = get_the_category(); $ID = $category[0]->cat_ID; echo is_wp_error($cat_parents = get_category_parents($ID, TRUE, '', FALSE)) ? '' : '<span>' . $cat_parents . '</span>'; } else { if (is_singular('news')) { echo '<span>' . get_the_title() . '</span>'; } else { if (is_single() && !is_attachment()) { if (get_post_type() == 'product') { if ($terms = wc_get_product_terms($post->ID, 'product_cat', array('orderby' => 'parent', 'order' => 'DESC'))) { $main_term = $terms[0]; $ancestors = get_ancestors($main_term->term_id, 'product_cat'); $ancestors = array_reverse($ancestors); foreach ($ancestors as $ancestor) { $ancestor = get_term($ancestor, 'product_cat'); if (!is_wp_error($ancestor) && $ancestor) { echo '<a href="' . get_term_link($ancestor->slug, 'product_cat') . '">' . $ancestor->name . '</a>' . $delimiter; } } echo '<a href="' . get_term_link($main_term->slug, 'product_cat') . '">' . $main_term->name . '</a>' . $delimiter; } echo get_the_title(); } elseif (is_singular('portfolio')) { $portfolio_category = get_the_term_list($post->ID, 'portfolio_category', '', ' / '); if (!empty($portfolio_category)) { echo $portfolio_category . $delimiter; } echo '<span>' . get_the_title() . '</span>'; } elseif (get_post_type() != 'post') { if (function_exists('is_bbpress') && is_bbpress()) { } else { $post_type = get_post_type_object(get_post_type()); $slug = $post_type->rewrite; echo '<a href="' . get_post_type_archive_link(get_post_type()) . '">' . $post_type->labels->singular_name . '</a>' . $delimiter; echo get_the_title(); } } else { $cat = current(get_the_category()); echo get_category_parents($cat, true, $delimiter); echo get_the_title(); } } elseif (is_page() && !$post->post_parent) { echo get_the_title(); } elseif (is_page() && $post->post_parent) { $parent_id = $post->post_parent; $breadcrumbs = array(); while ($parent_id) { $page = get_page($parent_id); $breadcrumbs[] = '<a href="' . get_permalink($page->ID) . '">' . get_the_title($page->ID) . '</a>'; $parent_id = $page->post_parent; } $breadcrumbs = array_reverse($breadcrumbs); foreach ($breadcrumbs as $crumb) { echo $crumb . '' . $delimiter; } echo get_the_title(); } elseif (is_attachment()) { $parent = get_post($post->post_parent); $cat = get_the_category($parent->ID); $cat = $cat[0]; /* admin@innodron.com patch: Fix for Catchable fatal error: Object of class WP_Error could not be converted to string ref: https://wordpress.org/support/topic/catchable-fatal-error-object-of-class-wp_error-could-not-be-converted-to-string-11 */ echo is_wp_error($cat_parents = get_category_parents($cat, TRUE, '' . $delimiter . '')) ? '' : $cat_parents; /* end admin@innodron.com patch */ echo '<a href="' . get_permalink($parent) . '">' . $parent->post_title . '</a>' . $delimiter; echo get_the_title(); } elseif (is_search()) { echo __('Search results for “', 'mk_framework') . get_search_query() . '”'; } elseif (is_tag()) { echo __('Tag “', 'mk_framework') . single_tag_title('', false) . '”'; } elseif (is_author()) { $userdata = get_userdata(get_the_author_meta('ID')); echo __('Author:', 'mk_framework') . ' ' . $userdata->display_name; } elseif (is_day()) { echo '<a href="' . get_year_link(get_the_time('Y')) . '">' . get_the_time('Y') . '</a>' . $delimiter; echo '<a href="' . get_month_link(get_the_time('Y'), get_the_time('m')) . '">' . get_the_time('F') . '</a>' . $delimiter; echo get_the_time('d'); } elseif (is_month()) { echo '<a href="' . get_year_link(get_the_time('Y')) . '">' . get_the_time('Y') . '</a>' . $delimiter; echo get_the_time('F'); } elseif (is_year()) { echo get_the_time('Y'); } } } if (get_query_var('paged')) { echo ' (' . __('Page', 'mk_framework') . ' ' . get_query_var('paged') . ')'; } if (is_tax()) { $term = get_term_by('slug', get_query_var('term'), get_query_var('taxonomy')); if (function_exists('is_woocommerce') && is_woocommerce() && is_archive()) { echo $delimiter; } echo '<span>' . $term->name . '</span>'; } if (function_exists('is_bbpress') && is_bbpress()) { $item = array(); $post_type_object = get_post_type_object(bbp_get_forum_post_type()); if (!empty($post_type_object->has_archive) && !bbp_is_forum_archive()) { $item[] = '<a href="' . get_post_type_archive_link(bbp_get_forum_post_type()) . '">' . bbp_get_forum_archive_title() . '</a>'; } if (bbp_is_forum_archive()) { $item[] = bbp_get_forum_archive_title(); } elseif (bbp_is_topic_archive()) { $item[] = bbp_get_topic_archive_title(); } elseif (bbp_is_single_view()) { $item[] = bbp_get_view_title(); } elseif (bbp_is_single_topic()) { $topic_id = get_queried_object_id(); $item = array_merge($item, mk_breadcrumbs_get_parents(bbp_get_topic_forum_id($topic_id))); if (bbp_is_topic_split() || bbp_is_topic_merge() || bbp_is_topic_edit()) { $item[] = '<a href="' . bbp_get_topic_permalink($topic_id) . '">' . bbp_get_topic_title($topic_id) . '</a>'; } else { $item[] = bbp_get_topic_title($topic_id); } if (bbp_is_topic_split()) { $item[] = __('Split', 'mk_framework'); } elseif (bbp_is_topic_merge()) { $item[] = __('Merge', 'mk_framework'); } elseif (bbp_is_topic_edit()) { $item[] = __('Edit', 'mk_framework'); } } elseif (bbp_is_single_reply()) { $reply_id = get_queried_object_id(); $item = array_merge($item, mk_breadcrumbs_get_parents(bbp_get_reply_topic_id($reply_id))); if (!bbp_is_reply_edit()) { $item[] = bbp_get_reply_title($reply_id); } else { $item[] = '<a href="' . bbp_get_reply_url($reply_id) . '">' . bbp_get_reply_title($reply_id) . '</a>'; $item[] = __('Edit', 'mk_framework'); } } elseif (bbp_is_single_forum()) { $forum_id = get_queried_object_id(); $forum_parent_id = bbp_get_forum_parent_id($forum_id); if (0 !== $forum_parent_id) { $item = array_merge($item, mk_breadcrumbs_get_parents($forum_parent_id)); } $item[] = bbp_get_forum_title($forum_id); } elseif (bbp_is_single_user() || bbp_is_single_user_edit()) { if (bbp_is_single_user_edit()) { $item[] = '<a href="' . bbp_get_user_profile_url() . '">' . bbp_get_displayed_user_field('display_name') . '</a>'; $item[] = __('Edit', 'mk_framework'); } else { $item[] = bbp_get_displayed_user_field('display_name'); } } echo implode($delimiter, $item); } echo "</div></div>"; }
/** * Return value of forum parent * * @since bbPress (r3551) * * @uses bbp_is_topic_edit() To check if it's the topic edit page * @uses bbp_get_forum_parent_id() To get the topic forum id * @uses apply_filters() Calls 'bbp_get_form_forum_parent' with the forum * @return string Value of topic content field */ function bbp_get_form_forum_parent() { // Get _POST data if (bbp_is_post_request() && isset($_POST['bbp_forum_id'])) { $forum_parent = $_POST['bbp_forum_id']; // Get edit data } elseif (bbp_is_forum_edit()) { $forum_parent = bbp_get_forum_parent_id(); // No data } else { $forum_parent = 0; } return apply_filters('bbp_get_form_forum_parent', esc_attr($forum_parent)); }
/** * Gets the items for the breadcrumb item if bbPress is installed. * * @since 0.4 * * @param array $args Mixed arguments for the menu. * @return array List of items to be shown in the item. */ function breadcrumbs_plus_get_bbpress_items($args = array()) { $item = array(); $post_type_object = get_post_type_object(bbp_get_forum_post_type()); if (!empty($post_type_object->has_archive) && !bbp_is_forum_archive()) { if (function_exists('bp_is_active')) { global $bp; // we're outside the loop! // Assign some variables here $page1 = isset($bp->members->root_slug) ? $bp->members->root_slug : ''; // slug for the Members page. The BuddyPress default is 'members'. $page2 = isset($bp->groups->root_slug) ? $bp->groups->root_slug : ''; // slug for the Groups page. The BuddyPress default is 'groups'. $page3 = isset($bp->activity->root_slug) ? $bp->activity->root_slug : ''; // slug for the Activity page. The BuddyPress default is 'activity'. $page4 = isset($bp->forums->root_slug) ? $bp->forums->root_slug : ''; // slug for the Forums page. The BuddyPress default is 'forums'. $page5 = isset($bp->achievements->root_slug) ? $bp->achievements->root_slug : ''; // slug for the Achievements page. The BuddyPress default is 'achievements'. if (!bp_is_blog_page() && (is_page() || is_page($page1) || is_page($page2) || is_page($page3) || is_page($page4) || is_page($page5)) && !bp_is_user() && !bp_is_single_item() && !bp_is_register_page()) { $item[] = ''; } if (bp_is_user() && !bp_is_register_page()) { $item[] = ''; } } else { //$item[] = '<div class="vbreadcrumb" typeof="v:Breadcrumb"><a href="' . get_post_type_archive_link( bbp_get_forum_post_type() ) . '" rel="v:url" property="v:title">' . bbp_get_forum_archive_title() . '</a></div>'; } } if (bbp_is_forum_archive()) { $item[] = bbp_get_forum_archive_title(); } else { $item[] = '<div class="vbreadcrumb" typeof="v:Breadcrumb"><a href="' . get_post_type_archive_link(bbp_get_forum_post_type()) . '" rel="v:url" property="v:title">' . bbp_get_forum_archive_title() . '</a></div>'; } if (bbp_is_topic_archive()) { $item[] = bbp_get_topic_archive_title(); } elseif (bbp_is_single_view()) { $item[] = bbp_get_view_title(); } elseif (bbp_is_single_topic()) { $topic_id = get_queried_object_id(); $item = array_merge($item, breadcrumbs_plus_get_parents(bbp_get_topic_forum_id($topic_id))); if (bbp_is_topic_split() || bbp_is_topic_merge() || bbp_is_topic_edit()) { $item[] = '<div class="vbreadcrumb" typeof="v:Breadcrumb"><a href="' . bbp_get_topic_permalink($topic_id) . '" rel="v:url" property="v:title">' . bbp_get_topic_title($topic_id) . '</a></div>'; } else { $item[] = ''; } if (bbp_is_topic_split()) { $item[] = __('Split', 'framework'); } elseif (bbp_is_topic_merge()) { $item[] = __('Merge', 'framework'); } elseif (bbp_is_topic_edit()) { $item[] = __('Edit', 'framework'); } } elseif (bbp_is_single_reply()) { $reply_id = get_queried_object_id(); $item = array_merge($item, breadcrumbs_plus_get_parents(bbp_get_reply_topic_id($reply_id))); if (!bbp_is_reply_edit()) { $item[] = bbp_get_reply_title($reply_id); } else { $item[] = '<div class="vbreadcrumb" typeof="v:Breadcrumb"><a href="' . bbp_get_reply_url($reply_id) . '" rel="v:url" property="v:title">' . bbp_get_reply_title($reply_id) . '</a></div>'; $item[] = __('Edit', 'framework'); } } elseif (bbp_is_single_forum()) { $forum_id = get_queried_object_id(); $forum_parent_id = bbp_get_forum_parent_id($forum_id); if (0 !== $forum_parent_id) { $item = array_merge($item, breadcrumbs_plus_get_parents($forum_parent_id)); } $item[] = bbp_get_forum_title($forum_id); } elseif (bbp_is_single_user() || bbp_is_single_user_edit()) { if (bbp_is_single_user_edit()) { $item[] = '<div class="vbreadcrumb" typeof="v:Breadcrumb"><a href="' . bbp_get_user_profile_url() . '" rel="v:url" property="v:title">' . bbp_get_displayed_user_field('display_name') . '</a></div>'; $item[] = __('Edit', 'framework'); } else { $item[] = bbp_get_displayed_user_field('display_name'); } } return apply_filters('breadcrumbs_plus_get_bbpress_items', $item, $args); }
<ul id="forums-list-<?php bbp_forum_id(); ?> " class="bbp-forums"> <li class="bbp-body"> <?php while (bbp_forums()) { bbp_the_forum(); ?> <?php if (bbp_is_forum_category() && !bbp_get_forum_parent_id()) { ?> <div class="vwbb-forum-cat-section"> <div class="vwbb-forum-cat-head"> <ul class="forum-titles clearfix"> <li class="bbp-forum-info"><?php bbp_forum_title(); ?> </li> <li class="normal bbp-forum-topic-count"><?php _e('Topics', 'bbpress'); ?> / <?php bbp_show_lead_topic() ? _e('Replies', 'bbpress') : _e('Posts', 'bbpress'); ?>
/** * @group canonical * @covers ::bbp_create_initial_content */ public function test_bbp_create_initial_content() { $category_id = $this->factory->forum->create(array('forum_meta' => array('_bbp_forum_type' => 'category', '_bbp_status' => 'open'))); bbp_create_initial_content(array('forum_parent' => $category_id)); $forum_id = bbp_forum_query_subforum_ids($category_id); $forum_id = (int) $forum_id[0]; $topic_id = bbp_get_forum_last_topic_id($forum_id); $reply_id = bbp_get_forum_last_reply_id($forum_id); // Forum post $this->assertSame('General', bbp_get_forum_title($forum_id)); $this->assertSame('General chit-chat', bbp_get_forum_content($forum_id)); $this->assertSame('open', bbp_get_forum_status($forum_id)); $this->assertTrue(bbp_is_forum_public($forum_id)); $this->assertSame($category_id, bbp_get_forum_parent_id($forum_id)); // Topic post $this->assertSame($forum_id, bbp_get_topic_forum_id($topic_id)); $this->assertSame('Hello World!', bbp_get_topic_title($topic_id)); remove_all_filters('bbp_get_topic_content'); $topic_content = "I am the first topic in your new forums."; $this->assertSame($topic_content, bbp_get_topic_content($topic_id)); $this->assertSame('publish', bbp_get_topic_status($topic_id)); $this->assertTrue(bbp_is_topic_published($topic_id)); // Reply post $this->assertSame($forum_id, bbp_get_reply_forum_id($reply_id)); $this->assertSame('Reply To: Hello World!', bbp_get_reply_title($reply_id)); $this->assertSame($reply_id, bbp_get_reply_title_fallback($reply_id)); remove_all_filters('bbp_get_reply_content'); $reply_content = "Oh, and this is what a reply looks like."; $this->assertSame($reply_content, bbp_get_reply_content($reply_id)); $this->assertSame('publish', bbp_get_reply_status($reply_id)); $this->assertTrue(bbp_is_reply_published($reply_id)); // Category meta $this->assertSame(1, bbp_get_forum_subforum_count($category_id, true)); $this->assertSame(0, bbp_get_forum_topic_count($category_id, false, true)); $this->assertSame(0, bbp_get_forum_topic_count_hidden($category_id, true)); $this->assertSame(0, bbp_get_forum_reply_count($category_id, false, true)); $this->assertSame(1, bbp_get_forum_topic_count($category_id, true, true)); $this->assertSame(1, bbp_get_forum_reply_count($category_id, true, true)); $this->assertSame(0, bbp_get_forum_post_count($category_id, false, true)); $this->assertSame(2, bbp_get_forum_post_count($category_id, true, true)); $this->assertSame($topic_id, bbp_get_forum_last_topic_id($category_id)); $this->assertSame('Hello World!', bbp_get_forum_last_topic_title($category_id)); $this->assertSame($reply_id, bbp_get_forum_last_reply_id($category_id)); $this->assertSame('Reply To: Hello World!', bbp_get_forum_last_reply_title($category_id)); $this->assertSame($reply_id, bbp_get_forum_last_active_id($category_id)); $this->assertSame('1 day, 16 hours ago', bbp_get_forum_last_active_time($category_id)); // Forum meta $this->assertSame(0, bbp_get_forum_subforum_count($forum_id, true)); $this->assertSame(1, bbp_get_forum_topic_count($forum_id, false, true)); $this->assertSame(0, bbp_get_forum_topic_count_hidden($forum_id, true)); $this->assertSame(1, bbp_get_forum_reply_count($forum_id, false, true)); $this->assertSame(1, bbp_get_forum_topic_count($forum_id, true, true)); $this->assertSame(1, bbp_get_forum_reply_count($forum_id, true, true)); $this->assertSame(2, bbp_get_forum_post_count($forum_id, false, true)); $this->assertSame(2, bbp_get_forum_post_count($forum_id, true, true)); $this->assertSame($topic_id, bbp_get_forum_last_topic_id($forum_id)); $this->assertSame('Hello World!', bbp_get_forum_last_topic_title($forum_id)); $this->assertSame($reply_id, bbp_get_forum_last_reply_id($forum_id)); $this->assertSame('Reply To: Hello World!', bbp_get_forum_last_reply_title($forum_id)); $this->assertSame($reply_id, bbp_get_forum_last_active_id($forum_id)); $this->assertSame('1 day, 16 hours ago', bbp_get_forum_last_active_time($forum_id)); // Topic meta $this->assertSame('127.0.0.1', bbp_current_author_ip($topic_id)); $this->assertSame($forum_id, bbp_get_topic_forum_id($topic_id)); $this->assertSame(1, bbp_get_topic_voice_count($topic_id, true)); $this->assertSame(1, bbp_get_topic_reply_count($topic_id, true)); $this->assertSame(0, bbp_get_topic_reply_count_hidden($topic_id, true)); $this->assertSame($reply_id, bbp_get_topic_last_reply_id($topic_id)); $this->assertSame($reply_id, bbp_get_topic_last_active_id($topic_id)); $this->assertSame('1 day, 16 hours ago', bbp_get_topic_last_active_time($topic_id)); // Reply Meta $this->assertSame('127.0.0.1', bbp_current_author_ip($reply_id)); $this->assertSame($forum_id, bbp_get_reply_forum_id($reply_id)); $this->assertSame($topic_id, bbp_get_reply_topic_id($reply_id)); }
/** * Get the page context * @version 2.0 */ function get_context() { // Setup placeholders $title = SITENAME; $desc = get_bloginfo('description'); $classes = get_body_class(); $crumbs = array(); // Get some data $id = $this->queried_object_id; $object = $this->queried_object; $sep = " • "; /*-------------------------------------------- DEFAULT CONTEXT ---------------------------------------------*/ $classes[] = 0 == get_current_user_id() ? 'logged-out' : 'logged-in'; $crumbs[] = '<a href="' . SITEURL . '" title="' . SITENAME . '" rel="home" class="trail-home">Home</a>'; // Homepage if (is_home()) { $title = SITENAME . $sep . 'Home'; $classes[] = 'home'; $classes[] = 'sidebar'; $classes[] = 'archive'; /*-------------------------------------------- BUDDYPRESS CONTEXT ---------------------------------------------*/ } elseif (class_exists('BuddyPress') && is_buddypress()) { // BuddyPress Defaults $title = "BuddyPress Page"; $desc = "This is a BuddyPress page."; $classes[] = 'buddypress'; // User Profiles if (bp_is_user()) { $title = bp_get_displayed_user_fullname() . $sep . "User Profile"; $desc = SITENAME . " user profile for member " . bp_get_displayed_user_fullname(); // Your own profile if (bp_is_my_profile()) { $crumbs[] = 'Your Profile'; } else { $crumbs[] = '<a href="' . bp_get_members_directory_permalink() . '" title="Members Directory">Members</a>'; $crumbs[] = '<a href="' . bp_displayed_user_domain() . '" title="' . bp_get_displayed_user_fullname() . '">' . bp_get_displayed_user_fullname() . '</a>'; } // Display the profile component if it isnt the profile home if (!bp_is_user_profile()) { $crumbs[] = ucfirst(bp_current_component()); } // Display the current action if it is not the default public profile if (!in_array(bp_current_action(), array('public', 'just-me', 'my-friends'))) { $crumbs[] = ucfirst(bp_current_action()); } // Single Group } elseif (bp_is_group() || bp_is_group_create()) { // Group Creation if (bp_is_group_create()) { $title = 'Submit New Group'; $desc = 'Submit a new user group for listing on the ' . SITENAME . ' community groups directory.'; $crumbs[] = '<a href="' . SITEURL . '/' . bp_get_groups_root_slug() . '" title="Groups Directory">Groups</a>'; $crumbs[] = 'Create Group'; } elseif (bp_is_group()) { // Default entries $title = bp_get_group_name(); $desc = SITENAME . ' guild profile for ' . bp_get_group_name(); $classes = array_diff($classes, array('page', 'page-template-default')); $crumbs[] = '<a href="' . bp_get_groups_directory_permalink() . '" title="Groups Directory">Groups</a>'; // Group Profile Home if (bp_is_group_home()) { $title = $title . $sep . 'Profile'; $crumbs[] = bp_get_group_name(); // Advanced Component } else { // Link back to group profile $crumbs[] = '<a href="' . bp_get_group_permalink() . '" title="Return to Group Profile">' . bp_get_group_name() . '</a>'; // Members if (bp_is_group_members()) { $title = $title . $sep . 'Members'; $crumbs[] = 'Members'; // Activity } elseif (bp_is_group_activity()) { $title = $title . $sep . 'Activity'; $crumbs[] = 'Activity'; // Invites } elseif (bp_is_group_invites()) { $title = $title . $sep . 'Invitations'; $crumbs[] = 'Invitations'; // Admin } elseif (bp_is_group_admin_page()) { $title = $title . $sep . 'Admin'; $crumbs[] = 'Admin'; // Forum } else { // Forum Root if (NULL == bp_action_variable()) { $title = $title . $sep . 'Forum'; $crumbs[] = 'Forum'; // Sub-Component } else { $crumbs[] = '<a href="' . bp_get_group_permalink() . 'forum/" title="Group Forum">Forum</a>'; // Retrieve topic information from the database global $bp; global $wpdb; // Single Topic if (bp_is_action_variable('topic', 0)) { // Get the topic $topic = $wpdb->get_row($wpdb->prepare("SELECT post_title AS title, post_name AS url\n\t\t\t\t\t\t\t\t\t\tFROM {$wpdb->posts} \n\t\t\t\t\t\t\t\t\t\tWHERE post_name = %s", $bp->action_variables[1])); $title = $topic->title; $crumbs[] = $topic->title; // Replies } elseif (bp_is_action_variable('reply', 0)) { // Get the reply parent topic $topic = $wpdb->get_row($wpdb->prepare("SELECT post_title AS title, post_name AS url\n\t\t\t\t\t\t\t\t\t\tFROM {$wpdb->posts} \n\t\t\t\t\t\t\t\t\t\tWHERE ID = ( \n\t\t\t\t\t\t\t\t\t\t\tSELECT post_parent\n\t\t\t\t\t\t\t\t\t\t\tFROM {$wpdb->posts}\n\t\t\t\t\t\t\t\t\t\t\tWHERE post_name = %s \n\t\t\t\t\t\t\t\t\t\t)", $bp->action_variables[1])); $title = $topic->title; $crumbs[] = $topic->title; } // Topic and Reply Edits if (bp_is_action_variable('edit', 2)) { $crumbs[] = 'Edit'; } } } } } // Directories } elseif (bp_is_directory()) { // Sitewide Activity if (bp_is_activity_component()) { $title = SITENAME . ' Sitewide Activity Feed'; $desc = 'A listing of all recent activity happening throughout the ' . SITENAME . ' community.'; $crumbs[] = 'Sitewide Activity'; // Members Directory } elseif (bp_is_members_component()) { $title = SITENAME . ' Members Directory'; $desc = 'A listing of all registered members in the ' . SITENAME . ' community.'; $crumbs[] = 'Members Directory'; // Groups Directory } elseif (bp_is_groups_component()) { $title = SITENAME . ' Guilds Directory'; $desc = 'A directory listing of guilds active within in the ' . SITENAME . ' community.'; $crumbs[] = 'Guilds Directory'; } // Registration } elseif (bp_is_register_page()) { $title = SITENAME . ' User Registration'; $desc = "Register to join the " . SITENAME . " community."; $crumbs[] = "User Registration"; // Activation } elseif (bp_is_activation_page()) { $title = SITENAME . ' Account Activation'; $desc = "Activate a pending " . SITENAME . " user account."; $crumbs[] = "Account Activation"; } /*-------------------------------------------- BBPRESS CONTEXT ---------------------------------------------*/ } elseif (class_exists('bbPress') && is_bbpress()) { // bbPress Defaults $classes[] = 'bbpress'; $classes[] = 'forums'; $crumbs[] = bbp_is_forum_archive() ? "Forums" : '<a href="' . get_post_type_archive_link('forum') . '">Forums</a>'; // Main Forum Archive if (bbp_is_forum_archive()) { $title = SITENAME . " Forums"; $desc = "Get involved in the community on the " . SITENAME . " forums."; // Recent Topics } elseif (bbp_is_topic_archive()) { $title = "Recent Topics in the " . SITENAME . " Forums"; $desc = "Browse a list of the most recent topics in the " . SITENAME . " Forums."; $crumbs[] = "Recent Topics"; // Single Forum } elseif (bbp_is_single_forum()) { $title = $object->post_title; $desc = $object->post_content; // Loop through parent forums $parent_id = bbp_get_forum_parent_id($id); if (0 != $parent_id) { $crumbs = array_merge($crumbs, $this->parent_crumbs($parent_id)); } $crumbs[] = $object->post_title; // Single Topic } elseif (bbp_is_single_topic()) { $title = $object->post_title; $desc = bbp_get_topic_excerpt($id); $crumbs = array_merge($crumbs, $this->parent_crumbs(bbp_get_topic_forum_id($id))); $crumbs[] = $object->post_title; // Edit Topic } elseif (bbp_is_topic_split() || bbp_is_topic_merge() || bbp_is_topic_edit()) { $title = 'Edit Topic' . $sep . $object->post_title; $desc = bbp_get_topic_excerpt($id); $crumbs = array_merge($crumbs, $this->parent_crumbs($id)); // Tag the specific task if (bbp_is_topic_split()) { $crumbs[] = 'Split Topic'; } elseif (bbp_is_topic_merge()) { $crumbs[] = 'Merge Topic'; } elseif (bbp_is_topic_edit()) { $crumbs[] = 'Edit Topic'; } // Edit Reply } elseif (bbp_is_reply_edit()) { $title = 'Edit Reply' . $sep . bbp_get_reply_topic_title($id); $desc = bbp_get_reply_excerpt($id); $crumbs = array_merge($crumbs, $this->parent_crumbs(bbp_get_reply_topic_id($id))); $crumbs[] = 'Edit Reply'; } /*-------------------------------------------- WORDPRESS CONTEXT ---------------------------------------------*/ } else { // Singular Posts and Pages if (is_singular()) { $title = $object->post_title; $desc = get_post_meta($id, 'description', true); // If no description is found, use an excerpt if (empty($desc)) { $desc = get_post_field('post_excerpt', $id); } // Check for custom template $template = get_post_meta($id, "_wp_{$object->post_type}_template", true); if ('' != $template) { $template = str_replace(array("{$object->post_type}-template-", "{$object->post_type}-"), '', basename($template, '.php')); $classes[] = "{$template}-template"; } // Generate breadcrumbs by post type switch ($object->post_type) { // Single Posts case 'post': // Is the post in a category? $categories = get_the_category(); if ($categories) { // Start with the first category $term = $categories[0]; // If the category has a parent, add it to the trail. if (0 != $term->parent) { $crumbs = array_merge($crumbs, $this->parent_crumbs($term->parent, 'category')); } // Add the category archive link to the trail. $crumbs[] = '<a href="' . get_term_link($term) . '" title="' . esc_attr($term->name) . '">' . $term->name . '</a>'; } // Does the post have an ancestor? if ($object->post_parent) { $crumbs = array_merge($crumbs, $this->parent_crumbs($object->post_parent)); } // Editing a comment on this post if (is_comment_edit()) { $crumbs[] = '<a href="' . get_permalink() . '" title="Return to article">' . get_the_title() . '</a>'; $crumbs[] = 'Edit Comment'; // Reading the post } else { $crumbs[] = get_the_title(); } break; // Pages // Pages case 'page': // Does the page have an ancestor? if ($object->post_parent) { $crumbs = array_merge($crumbs, $this->parent_crumbs($object->post_parent)); } // Otherwise, viewing the page $crumbs[] = get_the_title(); break; // Events // Events case 'event': // Get the calendar the event belongs to $calendar = get_the_terms($object->ID, 'calendar'); $calendar = array_shift($calendar); $desc = 'Upcoming event on the ' . $calendar->name . ' calendar.'; $crumbs[] = '<a href="' . SITEURL . '/calendar/' . $calendar->slug . '" title="' . $calendar->name . ' Calendar">' . $calendar->name . ' Calendar</a>'; $crumbs[] = get_the_title(); break; } // Archives } elseif (is_archive()) { // Category Archives if (is_category()) { $crumbs[] = 'Category'; // If the category has a parent, add it to the trail. if ($object->parent != 0) { $crumbs = array_merge($crumbs, $this->trail_parents($object->parent)); } // Finish up with the term name $crumbs[] = $object->name; // Author Archive } elseif (is_author()) { $title = 'Author Archive' . $sep . $object->display_name; $desc = 'An archive of articles written by ' . $object->display_name; $crumbs[] = 'Author'; $crumbs[] = $object->display_name; // Advanced Search Page } elseif (is_search()) { $title = SITENAME . " Advanced Search"; $desc = "Search for a variety of content types throughout " . SITENAME; $crumbs[] = 'Advanced Search'; $classes[] = 'page'; // Calendar } elseif (is_calendar()) { $title = $object->name . " Calendar"; $desc = "Upcoming events on the " . $object->name . " calendar."; $crumbs[] = $object->name . " Calendar"; } // 404 } elseif (is_404()) { $title = "Error" . $sep . "Page Not Found"; $desc = "Sorry, but this page does not exist, or is not accessible at this time."; $classes[] = 'page'; $crumbs[] = '404 Page Not Found'; } } /*-------------------------------------------- RETURN DATA ---------------------------------------------*/ $this->title = html_entity_decode($title); $this->description = html_entity_decode($desc); $this->classes = $classes; $this->crumbs = $crumbs; }
/** * Gets the items for the breadcrumb trail if bbPress is installed. * * @since 0.5.0 * @access public * @param array $args Mixed arguments for the menu. * @return array List of items to be shown in the trail. */ function breadcrumb_trail_get_bbpress_items($args = array()) { /* Set up a new trail items array. */ $trail = array(); /* Get the forum post type object. */ $post_type_object = get_post_type_object(bbp_get_forum_post_type()); /* If not viewing the forum root/archive page and a forum archive exists, add it. */ if (!empty($post_type_object->has_archive) && !bbp_is_forum_archive()) { $trail[] = '<a href="' . get_post_type_archive_link(bbp_get_forum_post_type()) . '">' . bbp_get_forum_archive_title() . '</a>'; } /* If viewing the forum root/archive. */ if (bbp_is_forum_archive()) { $trail[] = "<span>" . bbp_get_forum_archive_title() . "</span>"; } elseif (bbp_is_topic_archive()) { $trail[] = "<span>" . bbp_get_topic_archive_title() . "</span>"; } elseif (bbp_is_topic_tag()) { $trail[] = "<span>" . bbp_get_topic_tag_name() . "</span>"; } elseif (bbp_is_topic_tag_edit()) { $trail[] = '<a href="' . bbp_get_topic_tag_link() . '">' . bbp_get_topic_tag_name() . '</a>'; $trail[] = "<span>" . __('Edit', 'kleo_framework') . "</span>"; } elseif (bbp_is_single_view()) { $trail[] = '<span>' . bbp_get_view_title() . '</span>'; } elseif (bbp_is_single_topic()) { /* Get the queried topic. */ $topic_id = get_queried_object_id(); /* Get the parent items for the topic, which would be its forum (and possibly forum grandparents). */ $trail = array_merge($trail, breadcrumb_trail_get_parents(bbp_get_topic_forum_id($topic_id))); /* If viewing a split, merge, or edit topic page, show the link back to the topic. Else, display topic title. */ if (bbp_is_topic_split() || bbp_is_topic_merge() || bbp_is_topic_edit()) { $trail[] = '<a href="' . bbp_get_topic_permalink($topic_id) . '">' . bbp_get_topic_title($topic_id) . '</a>'; } else { $trail[] = '<span>' . bbp_get_topic_title($topic_id) . '</span>'; } /* If viewing a topic split page. */ if (bbp_is_topic_split()) { $trail[] = "<span>" . __('Split', 'kleo_framework') . "</span>"; } elseif (bbp_is_topic_merge()) { $trail[] = "<span>" . __('Merge', 'kleo_framework') . "</span>"; } elseif (bbp_is_topic_edit()) { $trail[] = "<span>" . __('Edit', 'kleo_framework') . "</span>"; } } elseif (bbp_is_single_reply()) { /* Get the queried reply object ID. */ $reply_id = get_queried_object_id(); /* Get the parent items for the reply, which should be its topic. */ $trail = array_merge($trail, breadcrumb_trail_get_parents(bbp_get_reply_topic_id($reply_id))); /* If viewing a reply edit page, link back to the reply. Else, display the reply title. */ if (bbp_is_reply_edit()) { $trail[] = '<a href="' . bbp_get_reply_url($reply_id) . '">' . bbp_get_reply_title($reply_id) . '</a>'; $trail[] = "<span>" . __('Edit', 'kleo_framework') . "</span>"; } else { $trail[] = '<span>' . bbp_get_reply_title($reply_id) . '</span>'; } } elseif (bbp_is_single_forum()) { /* Get the queried forum ID and its parent forum ID. */ $forum_id = get_queried_object_id(); $forum_parent_id = bbp_get_forum_parent_id($forum_id); /* If the forum has a parent forum, get its parent(s). */ if (0 !== $forum_parent_id) { $trail = array_merge($trail, breadcrumb_trail_get_parents($forum_parent_id)); } /* Add the forum title to the end of the trail. */ $trail[] = '<span>' . bbp_get_forum_title($forum_id) . '</span>'; } elseif (bbp_is_single_user() || bbp_is_single_user_edit()) { if (bbp_is_single_user_edit()) { $trail[] = '<a href="' . bbp_get_user_profile_url() . '">' . bbp_get_displayed_user_field('display_name') . '</a>'; $trail[] = "<span>" . __('Edit', 'kleo_framework') . "</span>"; } else { $trail[] = '<span>' . bbp_get_displayed_user_field('display_name') . '</span>'; } } /* Return the bbPress breadcrumb trail items. */ return apply_filters('breadcrumb_trail_get_bbpress_items', $trail, $args); }
/** * @covers ::bbp_forum_parent_id * @covers ::bbp_get_forum_parent_id */ public function test_bbp_get_forum_parent_id() { $f1 = $this->factory->forum->create(); $forum_id = bbp_get_forum_parent_id($f1); $this->assertSame(0, $forum_id); $f2 = $this->factory->forum->create(array('post_parent' => $f1)); $forum_id = bbp_get_forum_parent_id($f2); $this->assertSame($f1, $forum_id); }
<ul id="forums-list-<?php bbp_forum_id(); ?> " class="bbp-forums"> <li class="bbp-header"> <ul class="forum-titles"> <li class="bbp-forum-info"><?php if (bbp_is_forum_category()) { ?> <a class="bbp-forum-title" href="<?php bbp_forum_permalink(bbp_get_forum_parent_id()); ?> "><?php bbp_forum_title(bbp_get_forum_parent_id()); ?> </a><?php } else { _e('Forum', 'bbpress'); } ?> </li> <li class="bbp-forum-topic-count"><?php _e('Topics', 'bbpress'); ?> /<?php bbp_show_lead_topic() ? _e('Replies', 'bbpress') : _e('Posts', 'bbpress'); ?> </li> <li class="bbp-forum-freshness"><?php