Пример #1
0
/**
 * Are replies threaded
 *
 * @since 2.4.0 bbPress (r4944)
 *
 * @param bool $default Optional. Default value true
 * @uses apply_filters() Calls 'bbp_thread_replies' with the calculated value and
 *                        the thread replies depth
 * @uses get_option() To get thread replies option
 * @return bool Are replies threaded?
 */
function bbp_thread_replies()
{
    $depth = bbp_thread_replies_depth();
    $allow = bbp_allow_threaded_replies();
    $retval = (bool) ($depth >= 2 && true === $allow);
    return (bool) apply_filters('bbp_thread_replies', $retval, $depth, $allow);
}
Пример #2
0
/**
 * Return a select box allowing to pick which topic/reply a reply belongs.
 *
 * @since 2.6.0 bbPress (r5387)
 *
 * @param int $reply_id
 *
 * @uses BBP_Reply_Walker_Dropdown() As the default walker to generate the
 *                                   dropdown
 * @uses current_user_can()          To check if the current user can read
 *                                   private forums
 * @uses bbp_get_reply_id()          To get the reply ID
 * @uses bbp_get_reply_to()          To get the reply to ID
 * @uses bbp_get_reply_topic_id()    To get the replies topic ID
 * @uses bbp_get_reply_post_type()   To get the reply post type
 * @uses bbp_get_public_status_id()  To get the reply status
 * @uses bbp_thread_replies_depth()  To get the threaded replies depth
 *
 * @uses apply_filters() Calls 'bbp_get_dropdown' with the dropdown
 *                        and args
 * @return string The dropdown
 */
function bbp_get_reply_to_dropdown($reply_id = 0)
{
    // Validate the reply data
    $reply_id = bbp_get_reply_id($reply_id);
    $reply_to = bbp_get_reply_to($reply_id);
    $topic_id = bbp_get_reply_topic_id($reply_id);
    // Get the replies
    $posts = get_posts(array('post_type' => bbp_get_reply_post_type(), 'post_status' => bbp_get_public_status_id(), 'post_parent' => $topic_id, 'numberposts' => -1, 'orderby' => 'menu_order', 'order' => 'ASC'));
    // Append `reply_to` for each reply so it can be walked
    foreach ($posts as &$post) {
        // Check for reply post type
        $_reply_to = bbp_get_reply_to($post->ID);
        // Make sure it's a reply to a reply
        if (empty($_reply_to) || $topic_id === $_reply_to) {
            $_reply_to = 0;
        }
        // Add reply_to to the post object so we can walk it later
        $post->reply_to = $_reply_to;
    }
    // Get the dropdown and return it
    $retval = bbp_get_dropdown(array('show_none' => sprintf(esc_attr__('%1$s - %2$s', 'bbpress'), $topic_id, bbp_get_topic_title($topic_id)), 'select_id' => 'bbp_reply_to', 'select_class' => 'bbp_dropdown', 'exclude' => $reply_id, 'selected' => $reply_to, 'post_parent' => $topic_id, 'post_type' => bbp_get_reply_post_type(), 'max_depth' => bbp_thread_replies_depth(), 'page' => 1, 'per_page' => -1, 'walker' => new BBP_Walker_Reply_Dropdown(), 'posts' => $posts));
    // Filter and return
    return apply_filters('bbp_get_reply_to_dropdown', $retval, $reply_id, $reply_to, $topic_id);
}
/**
 * List replies
 *
 * @since bbPress (r4944)
 */
function bbp_list_replies($args = array())
{
    // Reset the reply depth
    bbpress()->reply_query->reply_depth = 0;
    // In reply loop
    bbpress()->reply_query->in_the_loop = true;
    $r = bbp_parse_args($args, array('walker' => null, 'max_depth' => bbp_thread_replies_depth(), 'style' => 'ul', 'callback' => null, 'end_callback' => null, 'page' => 1, 'per_page' => -1), 'list_replies');
    // Get replies to loop through in $_replies
    $walker = new BBP_Walker_Reply();
    $walker->paged_walk(bbpress()->reply_query->posts, $r['max_depth'], $r['page'], $r['per_page'], $r);
    bbpress()->max_num_pages = $walker->max_pages;
    bbpress()->reply_query->in_the_loop = false;
}
Пример #4
0
/**
 * Hierarchical reply maximum depth level setting field
 *
 * Replies will be threaded if depth is 2 or greater
 *
 * @since 2.4.0 bbPress (r4944)
 *
 * @uses apply_filters() Calls 'bbp_thread_replies_depth_max' to set a
 *                        maximum displayed level
 * @uses selected() To display the selected attribute
 */
function bbp_admin_setting_callback_thread_replies_depth()
{
    // Set maximum depth for dropdown
    $max_depth = (int) apply_filters('bbp_thread_replies_depth_max', 10);
    $current_depth = bbp_thread_replies_depth();
    // Start an output buffer for the select dropdown
    ob_start();
    ?>

	</label>
	<label for="_bbp_thread_replies_depth">
		<select name="_bbp_thread_replies_depth" id="_bbp_thread_replies_depth" <?php 
    bbp_maybe_admin_setting_disabled('_bbp_thread_replies_depth');
    ?>
>
		<?php 
    for ($i = 2; $i <= $max_depth; $i++) {
        ?>

			<option value="<?php 
        echo esc_attr($i);
        ?>
" <?php 
        selected($i, $current_depth);
        ?>
><?php 
        echo esc_html($i);
        ?>
</option>

		<?php 
    }
    ?>
		</select>

	<?php 
    $select = ob_get_clean();
    ?>

	<label for="_bbp_allow_threaded_replies">
		<input name="_bbp_allow_threaded_replies" id="_bbp_allow_threaded_replies" type="checkbox" value="1" <?php 
    checked('1', bbp_allow_threaded_replies(false));
    bbp_maybe_admin_setting_disabled('_bbp_allow_threaded_replies');
    ?>
 />
		<?php 
    printf(esc_html__('Enable threaded (nested) replies %s levels deep', 'bbpress'), $select);
    ?>
	</label>

<?php 
}