Exemplo n.º 1
0
/**
 * Is the forum hidden?
 *
 * @since bbPress (r2997)
 *
 * @param int $forum_id Optional. Forum id
 * @param bool $check_ancestors Check if the ancestors are private (only if
 *                               they're a category)
 * @uses get_post_meta() To get the forum private meta
 * @uses bbp_get_forum_ancestors() To get the forum ancestors
 * @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
 * @return bool True if closed, false if not
 */
function bbp_is_forum_hidden($forum_id = 0, $check_ancestors = true)
{
    $forum_id = bbp_get_forum_id($forum_id);
    $visibility = bbp_get_forum_visibility($forum_id);
    // If post status is private, return true
    $retval = bbp_get_hidden_status_id() == $visibility;
    // Check ancestors and inherit their privacy setting for display
    if (!empty($check_ancestors)) {
        $ancestors = bbp_get_forum_ancestors($forum_id);
        foreach ((array) $ancestors as $ancestor) {
            if (bbp_is_forum($ancestor) && bbp_is_forum_hidden($ancestor, false)) {
                $retval = true;
            }
        }
    }
    return (bool) apply_filters('bbp_is_forum_hidden', (bool) $retval, $forum_id, $check_ancestors);
}
Exemplo n.º 2
0
/**
 * Check the forum visibility ID
 *
 * @since 2.6.0 bbPress (r5499)
 *
 * @param int $forum_id Optional. Forum id
 * @param bool $status_name The post status name to check
 * @param bool $check_ancestors Check the forum ancestors
 * @param string $operator The logical operation to perform.
 *      'OR' means only one forum from the tree needs to match;
 *      'AND' means all forums must match. The default is 'AND'.
 * @uses bbp_get_forum_id() To get the forum ID
 * @uses bbp_get_forum_visibility() To get the forum visibility
 * @uses bbp_get_forum_ancestors() To get the forum ancestors
 * @uses bbp_is_forum() To check the post type
 * @return bool True if match, false if not
 */
function bbp_is_forum_visibility($forum_id, $status_name, $check_ancestors = true, $operator = 'AND')
{
    // Setup some default variables
    $count = 0;
    $retval = false;
    $operator = strtoupper($operator);
    $forum_id = bbp_get_forum_id($forum_id);
    $visibility = bbp_get_forum_visibility($forum_id);
    // Quickly compare visibility of first forum ID
    if ($status_name === $visibility) {
        $retval = true;
        $count++;
    }
    // Let's check the forum's ancestors too
    if (!empty($check_ancestors)) {
        // Adjust the ancestor check based on the count
        switch ($operator) {
            // Adjust the ancestor check based on the count
            default:
            case 'AND':
                $check_ancestors = $count > 0;
                break;
            case 'OR':
                $check_ancestors = $count < 1;
                break;
        }
        // Ancestor check passed, so continue looping through them
        if (!empty($check_ancestors)) {
            // Loop through the forum ancestors
            foreach ((array) bbp_get_forum_ancestors($forum_id) as $ancestor) {
                // Check if the forum is not a category
                if (bbp_is_forum($ancestor)) {
                    // Check the forum visibility
                    $retval = bbp_is_forum_visibility($ancestor, $status_name, false);
                    if (true === $retval) {
                        $count++;
                    }
                }
                // Break when it reach the max count
                if ($operator === 'OR' && $count >= 1) {
                    break;
                }
            }
        }
    }
    // Filter and return
    return (bool) apply_filters('bbp_is_forum_visibility', $retval, $count, $forum_id, $status_name, $check_ancestors, $operator);
}