/** * Return the row class of a reply * * @since bbPress (r2678) * * @param int $reply_id Optional. Reply ID * @param array Extra classes you can pass when calling this function * @uses bbp_get_reply_id() To validate the reply id * @uses bbp_get_reply_forum_id() To get the reply's forum id * @uses bbp_get_reply_topic_id() To get the reply's topic id * @uses get_post_class() To get all the classes including ours * @uses apply_filters() Calls 'bbp_get_reply_class' with the classes * @return string Row class of the reply */ function bbp_get_reply_class($reply_id = 0, $classes = array()) { $bbp = bbpress(); $reply_id = bbp_get_reply_id($reply_id); $count = isset($bbp->reply_query->current_post) ? $bbp->reply_query->current_post : 1; $classes = (array) $classes; $classes[] = (int) $count % 2 ? 'even' : 'odd'; $classes[] = 'bbp-parent-forum-' . bbp_get_reply_forum_id($reply_id); $classes[] = 'bbp-parent-topic-' . bbp_get_reply_topic_id($reply_id); $classes[] = 'bbp-reply-position-' . bbp_get_reply_position($reply_id); $classes[] = 'user-id-' . bbp_get_reply_author_id($reply_id); $classes[] = bbp_get_reply_author_id($reply_id) === bbp_get_topic_author_id(bbp_get_reply_topic_id($reply_id)) ? 'topic-author' : ''; $classes = array_filter($classes); $classes = get_post_class($classes, $reply_id); $classes = apply_filters('bbp_get_reply_class', $classes, $reply_id); $retval = 'class="' . implode(' ', $classes) . '"'; return $retval; }
/** * Generate post report buttons * @version 2.0 */ function apoc_report_post_button($type) { // Only let members report stuff if (!is_user_logged_in()) { return false; } // Get the data by context switch ($type) { // Forum reply case 'reply': $post_id = bbp_get_reply_id(); $reported_user = bbp_get_reply_author(); $post_number = bbp_get_reply_position(); break; // Article comment // Article comment case 'comment': global $comment, $comment_count; $post_id = $comment->comment_ID; $reported_user = $comment->comment_author; $post_number = $comment_count['count']; break; // Private message // Private message case 'message': global $thread_template; $post_id = $thread_template->message->thread_id; $reported_user = $thread_template->message->sender_id; $post_number = $thread_template->current_message + 1; break; } // Echo the button $button = '<a class="report-post" title="Report This Post" data-id="' . $post_id . '" data-number="' . $post_number . '" data-user="******" data-type="' . $type . '"><i class="fa fa-warning"></i></a>'; echo $button; }
/** * Redirect to the group forum screen * * @since bbPress (r3653) */ public function new_reply_redirect_to($redirect_url = '', $redirect_to = '', $reply_id = 0) { global $wp_rewrite; if (bp_is_group()) { $topic_id = bbp_get_reply_topic_id($reply_id); $topic = bbp_get_topic($topic_id); $reply_position = bbp_get_reply_position($reply_id, $topic_id); $reply_page = ceil((int) $reply_position / (int) bbp_get_replies_per_page()); $reply_hash = '#post-' . $reply_id; $topic_url = trailingslashit(bp_get_group_permalink(groups_get_current_group())) . trailingslashit($this->slug) . trailingslashit($this->topic_slug) . trailingslashit($topic->post_name); // Don't include pagination if on first page if (1 >= $reply_page) { $redirect_url = trailingslashit($topic_url) . $reply_hash; // Include pagination } else { $redirect_url = trailingslashit($topic_url) . trailingslashit($wp_rewrite->pagination_base) . trailingslashit($reply_page) . $reply_hash; } // Add topic view query arg back to end if it is set if (bbp_get_view_all()) { $redirect_url = bbp_add_view_all($redirect_url); } } return $redirect_url; }
echo bp_core_time_since(strtotime(get_the_time('c')), current_time('timestamp')); ?> </time> <?php apoc_report_post_button('reply'); ?> <div class="reply-admin-links"> <?php apoc_reply_admin_links(bbp_get_reply_id()); ?> <a class="reply-permalink" href="<?php bbp_reply_url(); ?> ">#<?php echo bbp_get_reply_position(); ?> </a> </div> </header> <section class="reply-body"> <div class="reply-author"> <?php echo $author->block; ?> </div> <div class="reply-content"> <?php bbp_reply_content();
/** * @covers ::bbp_reply_position * @covers ::bbp_get_reply_position * * @ticket BBP2845 */ public function test_bbp_get_reply_position() { $f = $this->factory->forum->create(); $t = $this->factory->topic->create(array('post_parent' => $f, 'topic_meta' => array('forum_id' => $f))); $r = $this->factory->reply->create_many(7, array('post_parent' => $t, 'reply_meta' => array('forum_id' => $f, 'topic_id' => $t))); // Reply menu position is unaltered when bbp_show_lead_topic() true. add_filter('bbp_show_lead_topic', '__return_true'); $position = get_post_field('menu_order', $r[3]); $this->assertSame(4, $position); $position = bbp_get_reply_position_raw($r[3]); $this->assertSame(4, $position); $position = bbp_get_reply_position($r[3]); $this->assertSame(4, $position); // Force a reply's 'menu_order' to 0. wp_update_post(array('ID' => $r[3], 'menu_order' => 0)); $position = get_post_field('menu_order', $r[3]); $this->assertSame(0, $position); $position = bbp_get_reply_position_raw($r[3]); $this->assertSame(4, $position); $position = bbp_get_reply_position($r[3]); $this->assertSame(4, $position); // Remove the filter for WordPress < 4.0 compatibility. remove_filter('bbp_show_lead_topic', '__return_true'); // Reply menu position is bumped by 1 when bbp_show_lead_topic() false. add_filter('bbp_show_lead_topic', '__return_false'); $position = get_post_field('menu_order', $r[3]); $this->assertSame(4, $position); $position = bbp_get_reply_position_raw($r[3]); $this->assertSame(4, $position); $position = bbp_get_reply_position($r[3]); $this->assertSame(5, $position); // Force a reply's 'menu_order' to 0. wp_update_post(array('ID' => $r[3], 'menu_order' => 0)); $position = get_post_field('menu_order', $r[3]); $this->assertSame(0, $position); $position = bbp_get_reply_position_raw($r[3]); $this->assertSame(4, $position); $position = bbp_get_reply_position($r[3]); $this->assertSame(5, $position); // Remove the filter for WordPress < 4.0 compatibility. remove_filter('bbp_show_lead_topic', '__return_false'); }