| 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 | // Get the forum ID |
| | 1455 | $forum_id = bbp_get_forum_id( $forum_id ); |
| 1475 | | foreach ( (array) $ancestors as $ancestor ) { |
| 1476 | | if ( bbp_is_forum_category( $ancestor, false ) && bbp_is_forum_closed( $ancestor, false ) ) { |
| 1477 | | $retval = true; |
| 1478 | | } |
| 1479 | | } |
| 1480 | | } |
| | 1463 | /** |
| | 1464 | * Is the forum closed? |
| | 1465 | * |
| | 1466 | * @since bbPress (r2746) |
| | 1467 | * |
| | 1468 | * @param int $forum_id Optional. Forum id |
| | 1469 | * @param bool $check_ancestors Check if the ancestors are closed (only |
| | 1470 | * if they're a category) |
| | 1471 | * @uses bbp_get_forum_id() To get the forum ID |
| | 1472 | * @uses bbp_is_forum_status_id() To check the forum status |
| | 1473 | * @return bool True if closed, false if not |
| | 1474 | */ |
| | 1475 | 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 |
| | 1492 | * @param bool $status_name The forum status name to check |
| | 1493 | * @param bool $check_ancestors Check if the forum ancestors |
| | 1494 | * @param string $operator The logical operation to perform. |
| | 1495 | * 'OR' means only one forum from the tree needs to match; |
| | 1496 | * 'AND' means all forums must match. The default is 'AND'. |
| | 1497 | * @uses bbp_get_forum_id() To get the forum ID |
| | 1498 | * @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 | | } |
| | 1518 | switch( $operator ) { |
| | 1519 | |
| | 1520 | default: |
| | 1521 | case 'AND': |
| | 1522 | $check_ancestors = ( $count > 0 ); |
| | 1523 | break; |
| | 1524 | |
| | 1525 | case 'OR': |
| | 1526 | $check_ancestors = ( $count < 1 ); |
| | 1527 | break; |
| | 1528 | |
| | 1529 | } |
| | 1530 | |
| | 1531 | if ( $check_ancestors ) { |
| | 1532 | |
| | 1533 | // Loop through the forum ancestors |
| | 1534 | foreach ( (array) bbp_get_forum_ancestors( $forum_id ) as $ancestor ) { |
| | 1535 | |
| | 1536 | // Check the post type |
| | 1537 | if ( bbp_is_forum_category( $ancestor ) ) { |
| | 1538 | |
| | 1539 | // Check the ancestor forum status |
| | 1540 | $retval = bbp_is_forum_status_id( $ancestor, $status_name, false ); |
| | 1541 | |
| | 1542 | if ( $retval ) |
| | 1543 | $count++; |
| | 1544 | |
| | 1545 | } |
| | 1546 | |
| | 1547 | // Break when it reach the max count |
| | 1548 | if ( $operator == 'OR' && $count >= 1 ) |
| | 1549 | break; |
| | 1550 | |
| | 1551 | } |
| | 1552 | |
| | 1553 | } |
| | 1554 | |
| | 1557 | return (bool) apply_filters( 'bbp_is_forum_status_id', (bool) $retval, $forum_id, $status_name, $check_ancestors, $operator ); |
| | 1558 | } |
| | 1559 | |
| | 1560 | /** |
| | 1561 | * Is the forum public? |
| | 1562 | * |
| | 1563 | * @since bbPress (r2997) |
| | 1564 | * |
| | 1565 | * @param int $forum_id Optional. Forum id |
| | 1566 | * @param bool $check_ancestors Check if the ancestors are public |
| | 1567 | * @uses bbp_get_forum_id() To get the forum ID |
| | 1568 | * @uses bbp_is_forum_visibility_id() To check the forum visibility ID |
| | 1569 | * @return bool True if public, false if not |
| | 1570 | */ |
| | 1571 | function bbp_is_forum_public( $forum_id = 0, $check_ancestors = true ) { |
| | 1572 | |
| | 1573 | // Get the forum ID |
| | 1574 | $forum_id = bbp_get_forum_id( $forum_id ); |
| | 1575 | |
| | 1576 | // Check if the forum and all of it's ancestors are public |
| | 1577 | $retval = bbp_is_forum_visibility_id( $forum_id, bbp_get_public_status_id(), $check_ancestors ); |
| | 1578 | |
| 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 |
| | 1588 | * @param bool $check_ancestors Check if the ancestors are private |
| | 1589 | * @uses bbp_get_forum_id() To get the forum ID |
| | 1590 | * @uses bbp_is_forum_visibility_id() To check the forum visibility ID |
| | 1591 | * @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 |
| | 1612 | * @uses bbp_get_forum_id() To get the forum ID |
| | 1613 | * @uses bbp_is_forum_visibility_id() To check the forum visibility ID |
| | 1614 | * @return bool True if hidden, false if not |
| 1579 | | // Check ancestors and inherit their privacy setting for display |
| | 1624 | return (bool) apply_filters( 'bbp_is_forum_hidden', (bool) $retval, $forum_id, $check_ancestors ); |
| | 1625 | } |
| | 1626 | |
| | 1627 | /** |
| | 1628 | * Check the forum visibility ID |
| | 1629 | * |
| | 1630 | * @since bbPress (rX) |
| | 1631 | * |
| | 1632 | * @param int $forum_id Optional. Forum id |
| | 1633 | * @param bool $status_name The post status name to check |
| | 1634 | * @param bool $check_ancestors Check the forum ancestors |
| | 1635 | * @param string $operator The logical operation to perform. |
| | 1636 | * 'OR' means only one forum from the tree needs to match; |
| | 1637 | * 'AND' means all forums must match. The default is 'AND'. |
| | 1638 | * @uses bbp_get_forum_id() To get the forum ID |
| | 1639 | * @uses bbp_get_forum_visibility() To get the forum visibility |
| | 1640 | * @uses bbp_get_forum_ancestors() To get the forum ancestors |
| | 1641 | * @uses bbp_is_forum() To check the post type |
| | 1642 | * @return bool True if match, false if not |
| | 1643 | */ |
| | 1644 | function bbp_is_forum_visibility_id( $forum_id, $status_name, $check_ancestors = true, $operator = 'AND' ) { |
| | 1645 | |
| | 1646 | $count = 0; |
| | 1647 | $retval = false; |
| | 1648 | $operator = strtoupper( $operator ); |
| | 1649 | $forum_id = bbp_get_forum_id( $forum_id ); |
| | 1650 | $visibility = bbp_get_forum_visibility( $forum_id ); |
| | 1651 | |
| | 1652 | if ( $status_name == $visibility ){ |
| | 1653 | $retval = true; |
| | 1654 | $count++; |
| | 1655 | } |
| | 1656 | |
| 1583 | | foreach ( (array) $ancestors as $ancestor ) { |
| 1584 | | if ( bbp_is_forum( $ancestor ) && bbp_is_forum_hidden( $ancestor, false ) ) { |
| 1585 | | $retval = true; |
| 1586 | | } |
| 1587 | | } |
| | 1659 | switch( $operator ) { |
| | 1660 | |
| | 1661 | default: |
| | 1662 | case 'AND': |
| | 1663 | $check_ancestors = ( $count > 0 ); |
| | 1664 | break; |
| | 1665 | |
| | 1666 | case 'OR': |
| | 1667 | $check_ancestors = ( $count < 1 ); |
| | 1668 | break; |
| | 1669 | |
| | 1670 | } |
| | 1671 | |
| | 1672 | if ( $check_ancestors ) { |
| | 1673 | |
| | 1674 | // Loop through the forum ancestors |
| | 1675 | foreach ( (array) bbp_get_forum_ancestors( $forum_id ) as $ancestor ) { |
| | 1676 | |
| | 1677 | // Check the post type |
| | 1678 | if ( bbp_is_forum( $ancestor ) ) { |
| | 1679 | |
| | 1680 | // Check the forum visibility |
| | 1681 | $retval = bbp_is_forum_visibility_id( $ancestor, $status_name, false ); |
| | 1682 | |
| | 1683 | if ( $retval ) |
| | 1684 | $count++; |
| | 1685 | |
| | 1686 | } |
| | 1687 | |
| | 1688 | // Break when it reach the max count |
| | 1689 | if ( $operator == 'OR' && $count >= 1 ) |
| | 1690 | break; |
| | 1691 | |
| | 1692 | } |
| | 1693 | |
| | 1694 | } |
| | 1695 | |