Changeset 3169
- Timestamp:
- 05/18/2011 09:42:58 AM (14 years ago)
- Location:
- branches/plugin/bbp-includes
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/plugin/bbp-includes/bbp-core-hooks.php
r3162 r3169 207 207 add_action( 'bbp_spammed_reply', 'bbp_update_reply_walker' ); 208 208 add_action( 'bbp_unspammed_reply', 'bbp_update_reply_walker' ); 209 210 // Custom Template - should be called at the end211 add_action( 'template_redirect', 'bbp_custom_template', 999 );212 209 213 210 /** FILTERS *******************************************************************/ -
branches/plugin/bbp-includes/bbp-general-template.php
r3167 r3169 1430 1430 1431 1431 /** 1432 * Load bbPress custom templates1433 *1434 * Loads custom templates for bbPress view page, user profile, user edit, topic1435 * edit and reply edit pages.1436 *1437 * @since bbPress (r2753)1438 *1439 * @uses bbp_is_user_profile_page() To check if it's a profile page1440 * @uses apply_filters() Calls 'bbp_profile_templates' with the profile1441 * templates array1442 * @uses bbp_is_user_profile_edit() To check if it's a profile edit page1443 * @uses apply_filters() Calls 'bbp_profile_edit_templates' with the profile1444 * edit templates array1445 * @uses bbp_is_view() To check if it's a view page1446 * @uses bbp_get_view_id() To get the view id1447 * @uses apply_filters() Calls 'bbp_view_templates' with the view templates array1448 * @uses bbp_is_topic_edit() To check if it's a topic edit page1449 * @uses bbp_get_topic_post_type() To get the topic post type1450 * @uses apply_filters() Calls 'bbp_topic_edit_templates' with the topic edit1451 * templates array1452 * @uses bbp_is_reply_edit() To check if it's a reply edit page1453 * @uses bbp_get_reply_post_type() To get the reply post type1454 * @uses apply_filters() Calls 'bbp_reply_edit_templates' with the reply edit1455 * templates array1456 * @uses apply_filters() Calls 'bbp_custom_template' with the template array1457 * @uses bbp_load_template() To load the template1458 */1459 function bbp_custom_template() {1460 global $bbp;1461 1462 // Bail if theme does not support bbPress1463 if ( !current_theme_supports( 'bbpress' ) )1464 return;1465 1466 $template = false;1467 1468 // Viewing a profile1469 if ( bbp_is_user_profile_page() ) {1470 $template = apply_filters( 'bbp_profile_templates', array(1471 'forums/user.php',1472 'bbpress/user.php',1473 'user.php',1474 'author.php',1475 'index.php'1476 ) );1477 1478 // Editing a profile1479 } elseif ( bbp_is_user_profile_edit() ) {1480 $template = apply_filters( 'bbp_profile_edit_templates', array(1481 'forums/user-edit.php',1482 'bbpress/user-edit.php',1483 'user-edit.php',1484 'forums/user.php',1485 'bbpress/user.php',1486 'user.php',1487 'author.php',1488 'index.php'1489 ) );1490 1491 // View page1492 } elseif ( bbp_is_view() ) {1493 $template = apply_filters( 'bbp_view_templates', array(1494 'forums/view-' . bbp_get_view_id(),1495 'bbpress/view-' . bbp_get_view_id(),1496 'forums/view.php',1497 'bbpress/view.php',1498 'view-' . bbp_get_view_id(),1499 'view.php',1500 'index.php'1501 ) );1502 1503 // Editing a topic1504 } elseif ( bbp_is_topic_edit() ) {1505 $template = array(1506 'forums/action-edit.php',1507 'bbpress/action-edit.php',1508 'forums/single-' . bbp_get_topic_post_type(),1509 'bbpress/single-' . bbp_get_topic_post_type(),1510 'action-bbp-edit.php',1511 'single-' . bbp_get_topic_post_type(),1512 'single.php',1513 'index.php'1514 );1515 1516 // Add split/merge to front of array if present in _GET1517 if ( !empty( $_GET['action'] ) && in_array( $_GET['action'], array( 'merge', 'split' ) ) ) {1518 array_unshift( $template,1519 'forums/action-split-merge.php',1520 'bbpress/action-split-merge.php',1521 'action-split-merge.php'1522 );1523 }1524 1525 $template = apply_filters( 'bbp_topic_edit_templates', $template );1526 1527 // Editing a reply1528 } elseif ( bbp_is_reply_edit() ) {1529 $template = apply_filters( 'bbp_reply_edit_templates', array(1530 'forums/action-edit.php',1531 'bbpress/action-edit.php',1532 'forums/single-' . bbp_get_reply_post_type(),1533 'bbpress/single-' . bbp_get_reply_post_type(),1534 'action-bbp-edit.php',1535 'single-' . bbp_get_reply_post_type(),1536 'single.php',1537 'index.php'1538 ) );1539 }1540 1541 if ( !$template = apply_filters( 'bbp_custom_template', $template ) )1542 return false;1543 1544 // Try to load a template file1545 bbp_load_template( $template );1546 }1547 1548 /**1549 * Load custom template1550 *1551 * @param string|array $files1552 * @uses locate_template() To locate and include the template1553 * @return bool False on failure (nothing on success)1554 */1555 function bbp_load_template( $templates ) {1556 1557 // Bail if nothing passed1558 if ( empty( $templates ) )1559 return;1560 1561 // Force array1562 elseif ( is_string( $templates ) )1563 $templates = (array) $templates;1564 1565 // Theme compat1566 if ( !current_theme_supports( 'bbpress' ) ) {1567 1568 // Snippet taken from locate_template()1569 $located = '';1570 foreach ( (array) $templates as $template_name ) {1571 1572 // Skip to next item in array if this one is empty1573 if ( empty( $template_name ) )1574 continue;1575 1576 // File exists in compat theme so exit the loop1577 if ( file_exists( bbp_get_theme_compat() . '/' . $template_name ) ) {1578 $located = bbp_get_theme_compat() . '/' . $template_name;1579 break;1580 }1581 }1582 1583 // Template file located1584 if ( !empty( $located ) ) {1585 load_template( $located, false );1586 exit();1587 }1588 1589 // Exit if file is found1590 } elseif ( locate_template( $templates, true ) ) {1591 exit();1592 }1593 }1594 1595 /**1596 1432 * Adds bbPress theme support to any active WordPress theme 1597 1433 * … … 1906 1742 * to appear. If the current theme does not explicitly support bbPress, it 1907 1743 * intercepts the page template and uses one served from the bbPress compatable 1908 * theme, set as the $bbp->theme_compat global. 1744 * theme, set as the $bbp->theme_compat global. If the current theme does 1745 * support bbPress, we'll explore the template hierarchy and try to locate one. 1909 1746 * 1910 1747 * @since bbPress (r3032) … … 1915 1752 * @return string 1916 1753 */ 1917 function bbp_template_include( $template ) {1754 function bbp_template_include( $template = false ) { 1918 1755 global $bbp; 1919 1756 1920 // Current theme does not support bbPress, so we need to do some heavy 1921 // lifting to see if a bbPress template is needed in the current context 1922 if ( !current_theme_supports( 'bbpress' ) ) { 1757 // Prevent debug notices 1758 $templates = array(); 1759 $new_template = ''; 1760 1761 // Current theme supports bbPress 1762 if ( current_theme_supports( 'bbpress' ) ) { 1763 1764 // Viewing a profile 1765 if ( bbp_is_user_profile_page() ) { 1766 $templates = apply_filters( 'bbp_profile_templates', array( 1767 'forums/user.php', 1768 'bbpress/user.php', 1769 'user.php', 1770 'author.php', 1771 'index.php' 1772 ) ); 1773 1774 // Editing a profile 1775 } elseif ( bbp_is_user_profile_edit() ) { 1776 $templates = apply_filters( 'bbp_profile_edit_templates', array( 1777 'forums/user-edit.php', 1778 'bbpress/user-edit.php', 1779 'user-edit.php', 1780 'forums/user.php', 1781 'bbpress/user.php', 1782 'user.php', 1783 'author.php', 1784 'index.php' 1785 ) ); 1786 1787 // View page 1788 } elseif ( bbp_is_view() ) { 1789 $templates = apply_filters( 'bbp_view_templates', array( 1790 'forums/view-' . bbp_get_view_id(), 1791 'bbpress/view-' . bbp_get_view_id(), 1792 'forums/view.php', 1793 'bbpress/view.php', 1794 'view-' . bbp_get_view_id(), 1795 'view.php', 1796 'index.php' 1797 ) ); 1798 1799 // Editing a topic 1800 } elseif ( bbp_is_topic_edit() ) { 1801 $templates = array( 1802 'forums/action-edit.php', 1803 'bbpress/action-edit.php', 1804 'forums/single-' . bbp_get_topic_post_type(), 1805 'bbpress/single-' . bbp_get_topic_post_type(), 1806 'action-bbp-edit.php', 1807 'single-' . bbp_get_topic_post_type(), 1808 'single.php', 1809 'index.php' 1810 ); 1811 1812 // Add split/merge to front of array if present in _GET 1813 if ( !empty( $_GET['action'] ) && in_array( $_GET['action'], array( 'merge', 'split' ) ) ) { 1814 array_unshift( $templates, 1815 'forums/action-split-merge.php', 1816 'bbpress/action-split-merge.php', 1817 'action-split-merge.php' 1818 ); 1819 } 1820 1821 $template = apply_filters( 'bbp_topic_edit_templates', $template ); 1822 1823 // Editing a reply 1824 } elseif ( bbp_is_reply_edit() ) { 1825 $templates = apply_filters( 'bbp_reply_edit_templates', array( 1826 'forums/action-edit.php', 1827 'bbpress/action-edit.php', 1828 'forums/single-' . bbp_get_reply_post_type(), 1829 'bbpress/single-' . bbp_get_reply_post_type(), 1830 'action-bbp-edit.php', 1831 'single-' . bbp_get_reply_post_type(), 1832 'single.php', 1833 'index.php' 1834 ) ); 1835 } 1836 1837 // Custom template file exists 1838 if ( !empty( $templates ) && ( $new_template = locate_template( $templates, false, false ) ) ) { 1839 $template = $new_template; 1840 } 1841 } 1842 1843 /** 1844 * In this next bit, either the current theme does not support bbPress, or 1845 * the theme author has incorrectly used add_theme_support( 'bbpress' ) 1846 * and we are going to help them out by silently filling in the blanks. 1847 */ 1848 if ( !current_theme_supports( 'bbpress' ) || ( !empty( $templates ) && empty( $new_template ) ) ) { 1923 1849 1924 1850 // Assume we are not in theme compat … … 2024 1950 } 2025 1951 2026 // Are we in theme compat mode? 1952 /** 1953 * If we are relying on bbPress's built in theme compatibility to load 1954 * the proper content, we need to intercept the_content, replace the 1955 * output, and display ours instead. 1956 * 1957 * To do this, we first remove all filters from 'the_content' and hook 1958 * our own function into it, which runs a series of checks to determine 1959 * the context, and then uses the built in shortcodes to output the 1960 * correct results. 1961 * 1962 * We default to using page.php, since it's most likely to exist and 1963 * should be coded to work without superfluous elements and logic, like 1964 * prev/next navigation, comments, date/time, etc... You can hook into 1965 * the 'bbp_template_include' filter to override page.php. 1966 */ 2027 1967 if ( true === $in_theme_compat ) { 2028 1968 1969 // Remove all filters from the_content 1970 remove_all_filters( 'the_content' ); 1971 2029 1972 // Add a filter on the_content late, which we will later remove 2030 add_filter( 'the_content', 'bbp_replace_the_content' , 99999);1973 add_filter( 'the_content', 'bbp_replace_the_content' ); 2031 1974 2032 1975 // Default to the page template 2033 $ default_template = apply_filters( 'bbp_template_include', 'page.php' );2034 $template = locate_template( $default_template, false, false);1976 $template = apply_filters( 'bbp_template_include', 'page.php' ); 1977 $template = locate_template( $template, false, false ); 2035 1978 } 2036 1979 } … … 2065 2008 2066 2009 // Remove the filter that was added in bbp_template_include() 2067 remove_filter( 'the_content', 'bbp_replace_the_content' , 99999);2010 remove_filter( 'the_content', 'bbp_replace_the_content' ); 2068 2011 2069 2012 // Bail if shortcodes are unset somehow
Note: See TracChangeset
for help on using the changeset viewer.