| 1453 | | /** |
| 1454 | | * Is the forum closed? |
| 1455 | | * |
| 1456 | | * @since bbPress (r2746) |
| 1457 | | * |
| 1458 | | * @param int $forum_id Optional. Forum id |
| 1459 | | * @param bool $check_ancestors Check if the ancestors are closed (only |
| 1460 | | * if they're a category) |
| 1461 | | * @uses bbp_get_forum_status() To get the forum status |
| 1462 | | * @uses bbp_get_forum_ancestors() To get the forum ancestors |
| 1463 | | * @uses bbp_is_forum_category() To check if the forum is a category |
| 1464 | | * @uses bbp_is_forum_closed() To check if the forum is closed |
| 1465 | | * @return bool True if closed, false if not |
| 1466 | | */ |
| 1467 | | function bbp_is_forum_closed( $forum_id = 0, $check_ancestors = true ) { |
| | 1454 | /** |
| | 1455 | * Is the forum closed? |
| | 1456 | * |
| | 1457 | * @since bbPress (r2746) |
| | 1458 | * |
| | 1459 | * @param int $forum_id Optional. Forum id |
| | 1460 | * @param bool $check_ancestors Check if the ancestors are closed (only |
| | 1461 | * if they're a category) |
| | 1462 | * @uses bbp_get_forum_id() To get the forum ID |
| | 1463 | * @uses bbp_is_forum_status_id() To check the forum status |
| | 1464 | * @return bool True if closed, false if not |
| | 1465 | */ |
| | 1466 | function bbp_is_forum_closed( $forum_id = 0, $check_ancestors = true ) { |
| 1491 | | * @param bool $check_ancestors Check if the ancestors are public (only if |
| 1492 | | * they're a category) |
| 1493 | | * @uses get_post_meta() To get the forum public meta |
| | 1483 | * @param bool $status_name The forum status name to check |
| | 1484 | * @param bool $check_ancestors Check if the forum ancestors |
| | 1485 | * @param string $operator The logical operation to perform. |
| | 1486 | * 'OR' means only one forum from the tree needs to match; |
| | 1487 | * 'AND' means all forums must match. The default is 'AND'. |
| | 1488 | * @uses bbp_get_forum_id() To get the forum ID |
| | 1489 | * @uses bbp_get_forum_status() To get the forum status ID |
| 1511 | | foreach ( (array) $ancestors as $ancestor ) { |
| 1512 | | if ( bbp_is_forum( $ancestor ) && bbp_is_forum_public( $ancestor, false ) ) { |
| 1513 | | $retval = true; |
| 1514 | | } |
| 1515 | | } |
| | 1509 | switch( $operator ) { |
| | 1510 | |
| | 1511 | default: |
| | 1512 | case 'AND': |
| | 1513 | $check_ancestors = ( $count > 0 ); |
| | 1514 | break; |
| | 1515 | |
| | 1516 | case 'OR': |
| | 1517 | $check_ancestors = ( $count < 1 ); |
| | 1518 | break; |
| | 1519 | |
| | 1520 | } |
| | 1521 | |
| | 1522 | if ( $check_ancestors ) { |
| | 1523 | |
| | 1524 | // Loop through the forum ancestors |
| | 1525 | foreach ( (array) bbp_get_forum_ancestors( $forum_id ) as $ancestor ) { |
| | 1526 | |
| | 1527 | // Check the post type |
| | 1528 | if ( bbp_is_forum_category( $ancestor ) ) { |
| | 1529 | |
| | 1530 | // Check the ancestor forum status |
| | 1531 | $retval = bbp_is_forum_status_id( $ancestor, $status_name, false ); |
| | 1532 | |
| | 1533 | if ( $retval ) |
| | 1534 | $count++; |
| | 1535 | |
| | 1536 | } |
| | 1537 | |
| | 1538 | // Break when it reach the max count |
| | 1539 | if ( $operator == 'OR' && $count >= 1 ) |
| | 1540 | break; |
| | 1541 | |
| | 1542 | } |
| | 1543 | |
| | 1544 | } |
| | 1545 | |
| | 1548 | return (bool) $retval; |
| | 1549 | } |
| | 1550 | |
| | 1551 | /** |
| | 1552 | * Is the forum public? |
| | 1553 | * |
| | 1554 | * @since bbPress (r2997) |
| | 1555 | * |
| | 1556 | * @param int $forum_id Optional. Forum id |
| | 1557 | * @param bool $check_ancestors Check if the ancestors are public |
| | 1558 | * @uses bbp_get_forum_id() To get the forum ID |
| | 1559 | * @uses bbp_is_forum_visibility_id() To check the forum visibility ID |
| | 1560 | * @return bool True if public, false if not |
| | 1561 | */ |
| | 1562 | function bbp_is_forum_public( $forum_id = 0, $check_ancestors = true ) { |
| | 1563 | |
| | 1564 | // Get the forum ID |
| | 1565 | $forum_id = bbp_get_forum_id( $forum_id ); |
| | 1566 | |
| | 1567 | // Check if the forum and all of it's ancestors are public |
| | 1568 | $retval = bbp_is_forum_visibility_id( $forum_id, bbp_get_public_status_id(), $check_ancestors ); |
| | 1569 | |
| 1527 | | * @param bool $check_ancestors Check if the ancestors are private (only if |
| 1528 | | * they're a category) |
| 1529 | | * @uses get_post_meta() To get the forum private meta |
| 1530 | | * @uses bbp_get_forum_ancestors() To get the forum ancestors |
| 1531 | | * @uses bbp_is_forum_category() To check if the forum is a category |
| 1532 | | * @uses bbp_is_forum_closed() To check if the forum is closed |
| 1533 | | * @return bool True if closed, false if not |
| | 1579 | * @param bool $check_ancestors Check if the ancestors are private |
| | 1580 | * @uses bbp_get_forum_id() To get the forum ID |
| | 1581 | * @uses bbp_is_forum_visibility_id() To check the forum visibility ID |
| | 1582 | * @return bool True if private, false if not |
| 1565 | | * @uses get_post_meta() To get the forum private meta |
| 1566 | | * @uses bbp_get_forum_ancestors() To get the forum ancestors |
| 1567 | | * @uses bbp_is_forum_category() To check if the forum is a category |
| 1568 | | * @uses bbp_is_forum_closed() To check if the forum is closed |
| 1569 | | * @return bool True if closed, false if not |
| | 1603 | * @uses bbp_get_forum_id() To get the forum ID |
| | 1604 | * @uses bbp_is_forum_visibility_id() To check the forum visibility ID |
| | 1605 | * @return bool True if hidden, false if not |
| | 1609 | // Get the forum ID |
| | 1610 | $forum_id = bbp_get_forum_id( $forum_id ); |
| | 1611 | |
| | 1612 | // Check if the forum or one of it's ancestors is hidden |
| | 1613 | $retval = bbp_is_forum_visibility_id( $forum_id, bbp_get_hidden_status_id(), $check_ancestors, 'OR' ); |
| | 1614 | |
| | 1615 | return (bool) apply_filters( 'bbp_is_forum_hidden', (bool) $retval, $forum_id, $check_ancestors ); |
| | 1616 | } |
| | 1617 | |
| | 1618 | /** |
| | 1619 | * Check the forum visibility ID |
| | 1620 | * |
| | 1621 | * @since bbPress (rX) |
| | 1622 | * |
| | 1623 | * @param int $forum_id Optional. Forum id |
| | 1624 | * @param bool $status_name The post status name to check |
| | 1625 | * @param bool $check_ancestors Check the forum ancestors |
| | 1626 | * @param string $operator The logical operation to perform. |
| | 1627 | * 'OR' means only one forum from the tree needs to match; |
| | 1628 | * 'AND' means all forums must match. The default is 'AND'. |
| | 1629 | * @uses bbp_get_forum_id() To get the forum ID |
| | 1630 | * @uses bbp_get_forum_visibility() To get the forum visibility |
| | 1631 | * @uses bbp_get_forum_ancestors() To get the forum ancestors |
| | 1632 | * @uses bbp_is_forum() To check the post type |
| | 1633 | * @return bool True if match, false if not |
| | 1634 | */ |
| | 1635 | function bbp_is_forum_visibility_id( $forum_id, $status_name, $check_ancestors = true, $operator = 'AND' ) { |
| | 1636 | |
| | 1637 | $count = 0; |
| | 1638 | $retval = false; |
| | 1639 | $operator = strtoupper( $operator ); |
| 1583 | | foreach ( (array) $ancestors as $ancestor ) { |
| 1584 | | if ( bbp_is_forum( $ancestor ) && bbp_is_forum_hidden( $ancestor, false ) ) { |
| 1585 | | $retval = true; |
| 1586 | | } |
| 1587 | | } |
| | 1650 | switch( $operator ) { |
| | 1651 | |
| | 1652 | default: |
| | 1653 | case 'AND': |
| | 1654 | $check_ancestors = ( $count > 0 ); |
| | 1655 | break; |
| | 1656 | |
| | 1657 | case 'OR': |
| | 1658 | $check_ancestors = ( $count < 1 ); |
| | 1659 | break; |
| | 1660 | |
| | 1661 | } |
| | 1662 | |
| | 1663 | if ( $check_ancestors ) { |
| | 1664 | |
| | 1665 | // Loop through the forum ancestors |
| | 1666 | foreach ( (array) bbp_get_forum_ancestors( $forum_id ) as $ancestor ) { |
| | 1667 | |
| | 1668 | // Check the post type |
| | 1669 | if ( bbp_is_forum( $ancestor ) ) { |
| | 1670 | |
| | 1671 | // Check the forum visibility |
| | 1672 | $retval = bbp_is_forum_visibility_id( $ancestor, $status_name, false ); |
| | 1673 | |
| | 1674 | if ( $retval ) |
| | 1675 | $count++; |
| | 1676 | |
| | 1677 | } |
| | 1678 | |
| | 1679 | // Break when it reach the max count |
| | 1680 | if ( $operator == 'OR' && $count >= 1 ) |
| | 1681 | break; |
| | 1682 | |
| | 1683 | } |
| | 1684 | |
| | 1685 | } |
| | 1686 | |