Skip to:
Content

BuddyPress.org

Changeset 7128


Ignore:
Timestamp:
05/29/2013 02:29:43 AM (12 years ago)
Author:
johnjamesjacoby
Message:

Tweak theme compatibility to hook to loop_start and loop_end, to maximize compatibility with third party plugins and existing WordPress themes. Props r-a-y for the proof of concept. See #5021.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-core/bp-core-theme-compatibility.php

    r6867 r7128  
    519519     * should be coded without superfluous mark-up and logic (prev/next
    520520     * navigation, comments, date/time, etc...)
     521     *
     522     * Hook into 'bp_get_buddypress_template' to override the array of
     523     * possible templates, or 'bp_buddypress_template' to override the result.
    521524     */
    522525    if ( bp_is_theme_compat_active() ) {
    523526
    524         // Remove all filters from the_content
    525         bp_remove_all_filters( 'the_content' );
    526 
    527         // Add a filter on the_content late, which we will later remove
    528         if ( ! has_filter( 'the_content', 'bp_replace_the_content' ) ) {
    529             add_filter( 'the_content', 'bp_replace_the_content' );
    530         }
     527        // Hook to the beginning of the main post loop to remove all filters
     528        // from the_content as late as possible.
     529        add_action( 'loop_start', 'bp_theme_compat_main_loop_start',  9999 );
     530
     531        // Hook to the end of the main post loop to restore all filters to
     532        // the_content as early as possible.
     533        add_action( 'loop_end',   'bp_theme_compat_main_loop_end',   -9999 );
    531534
    532535        // Add BuddyPress's head action to wp_head
     
    573576    // Return possibly hi-jacked content
    574577    return $content;
     578}
     579
     580/**
     581 * Helper function to conditionally toggle the_content filters in the main
     582 * query loop. Aids with theme compatibility.
     583 *
     584 * @since BuddyPress (1.8)
     585 * @internal Used only by theme compatibilty
     586 * @see bp_template_include_theme_compat()
     587 * @see bp_theme_compat_main_loop_end()
     588 */
     589function bp_theme_compat_main_loop_start() {
     590
     591    // Bail if not the main query
     592    if ( ! in_the_loop() )
     593        return;
     594
     595    // Remove all of the filters from the_content
     596    bp_remove_all_filters( 'the_content' );
     597
     598    // Make sure we replace the content
     599    add_filter( 'the_content', 'bp_replace_the_content' );
     600}
     601
     602/**
     603 * Helper function to conditionally toggle the_content filters in the main
     604 * query loop. Aids with theme compatibility.
     605 *
     606 * @since BuddyPress (1.8)
     607 * @internal Used only by theme compatibilty
     608 * @see bp_template_include_theme_compat()
     609 * @see bp_theme_compat_main_loop_start()
     610 */
     611function bp_theme_compat_main_loop_end() {
     612
     613    // Bail if not the main query
     614    if ( ! in_the_loop() )
     615        return;
     616
     617    // Put all the filters back
     618    bp_restore_all_filters( 'the_content' );
    575619}
    576620
Note: See TracChangeset for help on using the changeset viewer.