Changeset 10520 for trunk/src/bp-groups/bp-groups-screens.php
- Timestamp:
- 02/05/2016 04:55:58 AM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bp-groups/bp-groups-screens.php
r10454 r10520 14 14 // Exit if accessed directly. 15 15 defined( 'ABSPATH' ) || exit; 16 17 require dirname( __FILE__ ) . '/classes/class-bp-groups-theme-compat.php'; 16 18 17 19 /** … … 1476 1478 /** Theme Compatibility *******************************************************/ 1477 1479 1478 /**1479 * The main theme compat class for BuddyPress Groups.1480 *1481 * This class sets up the necessary theme compatibility actions to safely output1482 * group template parts to the_title and the_content areas of a theme.1483 *1484 * @since 1.7.01485 */1486 class BP_Groups_Theme_Compat {1487 1488 /**1489 * Set up theme compatibility for the Groups component.1490 *1491 * @since 1.7.01492 */1493 public function __construct() {1494 add_action( 'bp_setup_theme_compat', array( $this, 'is_group' ) );1495 }1496 1497 /**1498 * Are we looking at something that needs group theme compatibility?1499 *1500 * @since 1.7.01501 */1502 public function is_group() {1503 1504 // Bail if not looking at a group.1505 if ( ! bp_is_groups_component() )1506 return;1507 1508 // Group Directory.1509 if ( ! bp_current_action() && ! bp_current_item() ) {1510 bp_update_is_directory( true, 'groups' );1511 1512 /**1513 * Fires at the start of the group theme compatibility setup.1514 *1515 * @since 1.1.01516 */1517 do_action( 'groups_directory_groups_setup' );1518 1519 add_filter( 'bp_get_buddypress_template', array( $this, 'directory_template_hierarchy' ) );1520 add_action( 'bp_template_include_reset_dummy_post_data', array( $this, 'directory_dummy_post' ) );1521 add_filter( 'bp_replace_the_content', array( $this, 'directory_content' ) );1522 1523 // Creating a group.1524 } elseif ( bp_is_groups_component() && bp_is_current_action( 'create' ) ) {1525 add_filter( 'bp_get_buddypress_template', array( $this, 'create_template_hierarchy' ) );1526 add_action( 'bp_template_include_reset_dummy_post_data', array( $this, 'create_dummy_post' ) );1527 add_filter( 'bp_replace_the_content', array( $this, 'create_content' ) );1528 1529 // Group page.1530 } elseif ( bp_is_single_item() ) {1531 add_filter( 'bp_get_buddypress_template', array( $this, 'single_template_hierarchy' ) );1532 add_action( 'bp_template_include_reset_dummy_post_data', array( $this, 'single_dummy_post' ) );1533 add_filter( 'bp_replace_the_content', array( $this, 'single_content' ) );1534 1535 }1536 }1537 1538 /** Directory *********************************************************/1539 1540 /**1541 * Add template hierarchy to theme compat for the group directory page.1542 *1543 * This is to mirror how WordPress has1544 * {@link https://codex.wordpress.org/Template_Hierarchy template hierarchy}.1545 *1546 * @since 1.8.01547 *1548 * @param string $templates The templates from bp_get_theme_compat_templates().1549 * @return array $templates Array of custom templates to look for.1550 */1551 public function directory_template_hierarchy( $templates ) {1552 1553 /**1554 * Filters the Groups directory page template hierarchy based on priority.1555 *1556 * @since 1.8.01557 *1558 * @param array $value Array of default template files to use.1559 */1560 $new_templates = apply_filters( 'bp_template_hierarchy_groups_directory', array(1561 'groups/index-directory.php'1562 ) );1563 1564 // Merge new templates with existing stack.1565 // @see bp_get_theme_compat_templates().1566 $templates = array_merge( (array) $new_templates, $templates );1567 1568 return $templates;1569 }1570 1571 /**1572 * Update the global $post with directory data.1573 *1574 * @since 1.7.01575 */1576 public function directory_dummy_post() {1577 bp_theme_compat_reset_post( array(1578 'ID' => 0,1579 'post_title' => bp_get_directory_title( 'groups' ),1580 'post_author' => 0,1581 'post_date' => 0,1582 'post_content' => '',1583 'post_type' => 'page',1584 'post_status' => 'publish',1585 'is_page' => true,1586 'comment_status' => 'closed'1587 ) );1588 }1589 1590 /**1591 * Filter the_content with the groups index template part.1592 *1593 * @since 1.7.01594 */1595 public function directory_content() {1596 return bp_buffer_template_part( 'groups/index', null, false );1597 }1598 1599 /** Create ************************************************************/1600 1601 /**1602 * Add custom template hierarchy to theme compat for the group create page.1603 *1604 * This is to mirror how WordPress has1605 * {@link https://codex.wordpress.org/Template_Hierarchy template hierarchy}.1606 *1607 * @since 1.8.01608 *1609 * @param string $templates The templates from bp_get_theme_compat_templates().1610 * @return array $templates Array of custom templates to look for.1611 */1612 public function create_template_hierarchy( $templates ) {1613 1614 /**1615 * Filters the Groups create page template hierarchy based on priority.1616 *1617 * @since 1.8.01618 *1619 * @param array $value Array of default template files to use.1620 */1621 $new_templates = apply_filters( 'bp_template_hierarchy_groups_create', array(1622 'groups/index-create.php'1623 ) );1624 1625 // Merge new templates with existing stack.1626 // @see bp_get_theme_compat_templates().1627 $templates = array_merge( $new_templates, $templates );1628 1629 return $templates;1630 }1631 1632 /**1633 * Update the global $post with create screen data.1634 *1635 * @since 1.7.01636 */1637 public function create_dummy_post() {1638 1639 $title = _x( 'Groups', 'Group creation page', 'buddypress' );1640 1641 bp_theme_compat_reset_post( array(1642 'ID' => 0,1643 'post_title' => $title,1644 'post_author' => 0,1645 'post_date' => 0,1646 'post_content' => '',1647 'post_type' => 'page',1648 'post_status' => 'publish',1649 'is_page' => true,1650 'comment_status' => 'closed'1651 ) );1652 }1653 1654 /**1655 * Filter the_content with the create screen template part.1656 *1657 * @since 1.7.01658 */1659 public function create_content() {1660 return bp_buffer_template_part( 'groups/create', null, false );1661 }1662 1663 /** Single ************************************************************/1664 1665 /**1666 * Add custom template hierarchy to theme compat for group pages.1667 *1668 * This is to mirror how WordPress has1669 * {@link https://codex.wordpress.org/Template_Hierarchy template hierarchy}.1670 *1671 * @since 1.8.01672 *1673 * @param string $templates The templates from bp_get_theme_compat_templates().1674 * @return array $templates Array of custom templates to look for.1675 */1676 public function single_template_hierarchy( $templates ) {1677 // Setup some variables we're going to reference in our custom templates.1678 $group = groups_get_current_group();1679 1680 /**1681 * Filters the Groups single pages template hierarchy based on priority.1682 *1683 * @since 1.8.01684 *1685 * @param array $value Array of default template files to use.1686 */1687 $new_templates = apply_filters( 'bp_template_hierarchy_groups_single_item', array(1688 'groups/single/index-id-' . sanitize_file_name( bp_get_current_group_id() ) . '.php',1689 'groups/single/index-slug-' . sanitize_file_name( bp_get_current_group_slug() ) . '.php',1690 'groups/single/index-action-' . sanitize_file_name( bp_current_action() ) . '.php',1691 'groups/single/index-status-' . sanitize_file_name( $group->status ) . '.php',1692 'groups/single/index.php'1693 ) );1694 1695 // Merge new templates with existing stack.1696 // @see bp_get_theme_compat_templates().1697 $templates = array_merge( (array) $new_templates, $templates );1698 1699 return $templates;1700 }1701 1702 /**1703 * Update the global $post with single group data.1704 *1705 * @since 1.7.01706 */1707 public function single_dummy_post() {1708 bp_theme_compat_reset_post( array(1709 'ID' => 0,1710 'post_title' => bp_get_current_group_name(),1711 'post_author' => 0,1712 'post_date' => 0,1713 'post_content' => '',1714 'post_type' => 'page',1715 'post_status' => 'publish',1716 'is_page' => true,1717 'comment_status' => 'closed'1718 ) );1719 }1720 1721 /**1722 * Filter the_content with the single group template part.1723 *1724 * @since 1.7.01725 */1726 public function single_content() {1727 return bp_buffer_template_part( 'groups/single/home', null, false );1728 }1729 }1730 1480 new BP_Groups_Theme_Compat();
Note: See TracChangeset
for help on using the changeset viewer.