| 1572 | | /** |
| 1573 | | * Is the forum closed? |
| 1574 | | * |
| 1575 | | * @since bbPress (r2746) |
| 1576 | | * |
| 1577 | | * @param int $forum_id Optional. Forum id |
| 1578 | | * @param bool $check_ancestors Check if the ancestors are closed (only |
| 1579 | | * if they're a category) |
| 1580 | | * @uses bbp_get_forum_status() To get the forum status |
| 1581 | | * @uses bbp_get_forum_ancestors() To get the forum ancestors |
| 1582 | | * @uses bbp_is_forum_category() To check if the forum is a category |
| 1583 | | * @uses bbp_is_forum_closed() To check if the forum is closed |
| 1584 | | * @return bool True if closed, false if not |
| 1585 | | */ |
| 1586 | | function bbp_is_forum_closed( $forum_id = 0, $check_ancestors = true ) { |
| | 1575 | /** |
| | 1576 | * Is the forum closed? |
| | 1577 | * |
| | 1578 | * @since bbPress (r2746) |
| | 1579 | * |
| | 1580 | * @param int $forum_id Optional. Forum id |
| | 1581 | * @param bool $check_ancestors Check if the ancestors are closed (only |
| | 1582 | * if they're a category) |
| | 1583 | * @uses bbp_get_forum_id() To get the forum ID |
| | 1584 | * @uses bbp_is_forum_status_id() To check the forum status |
| | 1585 | * @return bool True if closed, false if not |
| | 1586 | */ |
| | 1587 | function bbp_is_forum_closed( $forum_id = 0, $check_ancestors = true ) { |
| 1594 | | foreach ( (array) $ancestors as $ancestor ) { |
| 1595 | | if ( bbp_is_forum_category( $ancestor, false ) && bbp_is_forum_closed( $ancestor, false ) ) { |
| 1596 | | $retval = true; |
| | 1595 | return (bool) apply_filters( 'bbp_is_forum_closed', (bool) $retval, $forum_id, $check_ancestors ); |
| | 1596 | } |
| | 1597 | |
| | 1598 | /** |
| | 1599 | * Check the forum status ID |
| | 1600 | * |
| | 1601 | * @since bbPress (rX) |
| | 1602 | * |
| | 1603 | * @param bool $status_name The forum status name to check |
| | 1604 | * @param bool $check_ancestors Check the forum ancestors |
| | 1605 | * @param string $operator The logical operation to perform. |
| | 1606 | * 'OR' means only one forum from the tree needs to match; |
| | 1607 | * 'AND' means all forums must match. The default is 'AND'. |
| | 1608 | * @uses bbp_get_forum_id() To get the forum ID |
| | 1609 | * @uses bbp_get_forum_status() To get the forum status |
| | 1610 | * @uses bbp_get_forum_ancestors() To get the forum ancestors |
| | 1611 | * @uses bbp_is_forum_category() To check the forum type |
| | 1612 | * @return bool True if match, false if not |
| | 1613 | */ |
| | 1614 | function bbp_is_forum_status_id( $forum_id, $status_name, $check_ancestors = true, $operator = 'AND' ) { |
| | 1615 | |
| | 1616 | $count = 0; |
| | 1617 | $retval = false; |
| | 1618 | $operator = strtoupper( $operator ); |
| | 1619 | $forum_id = bbp_get_forum_id( $forum_id ); |
| | 1620 | $forum_status = bbp_get_forum_status( $forum_id ); |
| | 1621 | |
| | 1622 | if ( $status_name == $forum_status ){ |
| | 1623 | $retval = true; |
| | 1624 | $count++; |
| | 1625 | } |
| | 1626 | |
| | 1627 | if ( !empty( $check_ancestors ) ) { |
| | 1628 | switch( $operator ) { |
| | 1629 | |
| | 1630 | default: |
| | 1631 | case 'AND': |
| | 1632 | $check_ancestors = ( $count > 0 ); |
| | 1633 | break; |
| | 1634 | |
| | 1635 | case 'OR': |
| | 1636 | $check_ancestors = ( $count < 1 ); |
| | 1637 | break; |
| | 1638 | } |
| | 1639 | |
| | 1640 | if ( $check_ancestors ) { |
| | 1641 | |
| | 1642 | // Loop through the forum ancestors |
| | 1643 | foreach ( (array) bbp_get_forum_ancestors( $forum_id ) as $ancestor ) { |
| | 1644 | |
| | 1645 | // Check the post type |
| | 1646 | if ( bbp_is_forum_category( $ancestor ) ) { |
| | 1647 | |
| | 1648 | // Check the ancestor forum status |
| | 1649 | $retval = bbp_is_forum_status_id( $ancestor, $status_name, false ); |
| | 1650 | |
| | 1651 | if ( $retval ) |
| | 1652 | $count++; |
| 1610 | | * @param bool $check_ancestors Check if the ancestors are public (only if |
| 1611 | | * they're a category) |
| 1612 | | * @uses get_post_meta() To get the forum public meta |
| 1613 | | * @uses bbp_get_forum_ancestors() To get the forum ancestors |
| 1614 | | * @uses bbp_is_forum_category() To check if the forum is a category |
| 1615 | | * @uses bbp_is_forum_closed() To check if the forum is closed |
| | 1670 | * @param bool $check_ancestors Check if the ancestors are public |
| | 1671 | * @uses bbp_get_forum_id() To get the forum ID |
| | 1672 | * @uses bbp_is_forum_visibility_id() To check the forum visibility ID |
| 1646 | | * @param bool $check_ancestors Check if the ancestors are private (only if |
| 1647 | | * they're a category) |
| 1648 | | * @uses get_post_meta() To get the forum private meta |
| 1649 | | * @uses bbp_get_forum_ancestors() To get the forum ancestors |
| 1650 | | * @uses bbp_is_forum_category() To check if the forum is a category |
| 1651 | | * @uses bbp_is_forum_closed() To check if the forum is closed |
| 1652 | | * @return bool True if closed, false if not |
| | 1692 | * @param bool $check_ancestors Check if the ancestors are private |
| | 1693 | * @uses bbp_get_forum_id() To get the forum ID |
| | 1694 | * @uses bbp_is_forum_visibility_id() To check the forum visibility ID |
| | 1695 | * @return bool True if private, false if not |
| 1684 | | * @uses get_post_meta() To get the forum private meta |
| 1685 | | * @uses bbp_get_forum_ancestors() To get the forum ancestors |
| 1686 | | * @uses bbp_is_forum_category() To check if the forum is a category |
| 1687 | | * @uses bbp_is_forum_closed() To check if the forum is closed |
| 1688 | | * @return bool True if closed, false if not |
| | 1716 | * @uses bbp_get_forum_id() To get the forum ID |
| | 1717 | * @uses bbp_is_forum_visibility_id() To check the forum visibility ID |
| | 1718 | * @return bool True if hidden, false if not |
| | 1722 | // Get the forum ID |
| | 1723 | $forum_id = bbp_get_forum_id( $forum_id ); |
| | 1724 | |
| | 1725 | // Check if the forum or one of it's ancestors is hidden |
| | 1726 | $retval = bbp_is_forum_visibility_id( $forum_id, bbp_get_hidden_status_id(), $check_ancestors, 'OR' ); |
| | 1727 | |
| | 1728 | return (bool) apply_filters( 'bbp_is_forum_hidden', (bool) $retval, $forum_id, $check_ancestors ); |
| | 1729 | } |
| | 1730 | |
| | 1731 | /** |
| | 1732 | * Check the forum visibility ID |
| | 1733 | * |
| | 1734 | * @since bbPress (rX) |
| | 1735 | * |
| | 1736 | * @param int $forum_id Optional. Forum id |
| | 1737 | * @param bool $status_name The post status name to check |
| | 1738 | * @param bool $check_ancestors Check the forum ancestors |
| | 1739 | * @param string $operator The logical operation to perform. |
| | 1740 | * 'OR' means only one forum from the tree needs to match; |
| | 1741 | * 'AND' means all forums must match. The default is 'AND'. |
| | 1742 | * @uses bbp_get_forum_id() To get the forum ID |
| | 1743 | * @uses bbp_get_forum_visibility() To get the forum visibility |
| | 1744 | * @uses bbp_get_forum_ancestors() To get the forum ancestors |
| | 1745 | * @uses bbp_is_forum() To check the post type |
| | 1746 | * @return bool True if match, false if not |
| | 1747 | */ |
| | 1748 | function bbp_is_forum_visibility_id( $forum_id, $status_name, $check_ancestors = true, $operator = 'AND' ) { |
| | 1749 | |
| | 1750 | $count = 0; |
| | 1751 | $retval = false; |
| | 1752 | $operator = strtoupper( $operator ); |
| 1702 | | foreach ( (array) $ancestors as $ancestor ) { |
| 1703 | | if ( bbp_is_forum( $ancestor ) && bbp_is_forum_hidden( $ancestor, false ) ) { |
| 1704 | | $retval = true; |
| | 1763 | switch( $operator ) { |
| | 1764 | |
| | 1765 | default: |
| | 1766 | case 'AND': |
| | 1767 | $check_ancestors = ( $count > 0 ); |
| | 1768 | break; |
| | 1769 | |
| | 1770 | case 'OR': |
| | 1771 | $check_ancestors = ( $count < 1 ); |
| | 1772 | break; |
| | 1773 | } |
| | 1774 | |
| | 1775 | if ( $check_ancestors ) { |
| | 1776 | |
| | 1777 | // Loop through the forum ancestors |
| | 1778 | foreach ( (array) bbp_get_forum_ancestors( $forum_id ) as $ancestor ) { |
| | 1779 | |
| | 1780 | // Check the post type |
| | 1781 | if ( bbp_is_forum( $ancestor ) ) { |
| | 1782 | |
| | 1783 | // Check the forum visibility |
| | 1784 | $retval = bbp_is_forum_visibility_id( $ancestor, $status_name, false ); |
| | 1785 | |
| | 1786 | if ( $retval ) |
| | 1787 | $count++; |
| | 1788 | } |
| | 1789 | |
| | 1790 | // Break when it reach the max count |
| | 1791 | if ( $operator == 'OR' && $count >= 1 ) |
| | 1792 | break; |