Ticket #4656: 4656-port+fix.01.patch
File 4656-port+fix.01.patch, 7.8 KB (added by , 12 years ago) |
---|
-
bp-core/bp-core-filters.php
add_filter( 'bp_core_render_message_content', 'shortcode_unautop' ); 61 61 add_filter( 'bp_template_include', 'bp_template_include_theme_supports', 2, 1 ); 62 62 add_filter( 'bp_template_include', 'bp_template_include_theme_compat', 4, 2 ); 63 63 64 // Run all template parts through additional template locations 65 add_filter( 'bp_locate_template', 'bp_add_template_locations' ); 66 add_filter( 'bp_get_template_part', 'bp_add_template_locations' ); 64 /** 65 * Adds custom locations as set in bp_get_template_locations(). 66 * 67 * @since BuddyPress (1.7) 68 * 69 * @uses bp_get_template_locations() Get the possible subdirectories to check for templates in 70 * @return array All possible locations a template can reside in 71 */ 72 function bp_template_stack_add_custom_locations( $stacks ) { 73 $locations = array(); 74 foreach ( $stacks as $stack ) { 75 // for each stack, add our custom location 76 foreach ( bp_get_template_locations() as $custom_location ) { 77 $locations[] = untrailingslashit( trailingslashit( $stack ) . $custom_location ); 78 } 79 } 80 81 return $locations; 82 } 83 add_filter( 'bp_get_template_stack', 'bp_template_stack_add_custom_locations' ); 67 84 68 85 // Turn comments off for BuddyPress pages 69 86 add_filter( 'comments_open', 'bp_comments_open', 10, 2 ); -
bp-core/bp-core-template-loader.php
function bp_get_template_part( $slug, $name = null ) { 32 32 33 33 // Setup possible parts 34 34 $templates = array(); 35 35 36 if ( isset( $name ) ) 36 37 $templates[] = $slug . '-' . $name . '.php'; 38 37 39 $templates[] = $slug . '.php'; 38 40 39 41 // Allow template parst to be filtered … … function bp_get_template_part( $slug, $name = null ) { 61 63 function bp_locate_template( $template_names, $load = false, $require_once = true ) { 62 64 63 65 // No file found yet 64 $located = false; 65 $child_theme = get_stylesheet_directory(); 66 $parent_theme = get_template_directory(); 67 $fallback_theme = bp_get_theme_compat_dir(); 68 69 // Allow templates to be filtered 70 // BuddyPress core automatically adds bp_add_template_locations() 71 $template_names = apply_filters( 'bp_locate_template', $template_names ); 66 $located = false; 67 $template_locations = bp_get_template_stack(); 72 68 73 // Try to find a template file 74 // Check the parent and child theme directories first 75 foreach ( (array) $template_names as $template_name ) { 69 // Loop through template stack 70 foreach ( (array) $template_locations as $template_location ) { 76 71 77 // Continue if templateis empty78 if ( empty( $template_ name) )72 // Continue if $template_location is empty 73 if ( empty( $template_location ) ) 79 74 continue; 80 75 81 // Trim off any slashes from the template name 82 $template_name = ltrim( $template_name, '/' ); 83 84 // Check child theme first 85 if ( file_exists( trailingslashit( $child_theme ) . $template_name ) ) { 86 $located = trailingslashit( $child_theme ) . $template_name; 87 break; 88 89 // Check parent theme next 90 } elseif ( file_exists( trailingslashit( $parent_theme ) . $template_name ) ) { 91 $located = trailingslashit( $parent_theme ) . $template_name; 92 break; 93 } 94 } 95 96 // Check theme compatibility last if no template is found in the current theme 97 if ( empty( $located ) ) { 76 // Try to find a template file 98 77 foreach ( (array) $template_names as $template_name ) { 99 if ( file_exists( trailingslashit( $fallback_theme ) . $template_name ) ) { 100 $located = trailingslashit( $fallback_theme ) . $template_name; 101 break; 78 79 // Continue if template is empty 80 if ( empty( $template_name ) ) 81 continue; 82 83 // Trim off any slashes from the template name 84 $template_name = ltrim( $template_name, '/' ); 85 86 // Check child theme first 87 if ( file_exists( trailingslashit( $template_location ) . $template_name ) ) { 88 $located = trailingslashit( $template_location ) . $template_name; 89 break 2; 102 90 } 103 91 } 104 92 } 105 93 94 // Maybe load the template if one was located 106 95 if ( ( true == $load ) && !empty( $located ) ) 107 96 load_template( $located, $require_once ); 108 97 … … function bp_buffer_template_part( $slug, $name = null, $echo = true ) { 144 133 } 145 134 146 135 /** 136 * This is really cool. This function registers a new template stack location, 137 * using WordPress's built in filters API. 138 * 139 * This allows for templates to live in places beyond just the parent/child 140 * relationship, to allow for custom template locations. Used in conjunction 141 * with bp_locate_template(), this allows for easy template overrides. 142 * 143 * @since BuddyPress (1.7) 144 * 145 * @param string $location Callback function that returns the 146 * @param int $priority 147 */ 148 function bp_register_template_stack( $location_callback = '', $priority = 10 ) { 149 150 // Bail if no location, or function does not exist 151 if ( empty( $location_callback ) || ! function_exists( $location_callback ) ) 152 return false; 153 154 // Add location callback to template stack 155 add_filter( 'bp_template_stack', $location_callback, (int) $priority ); 156 } 157 158 /** 159 * Call the functions added to the 'bp_template_stack' filter hook, and return 160 * an array of the template locations. 161 * 162 * @see bp_register_template_stack() 163 * 164 * @since BuddyPress (1.7) 165 * 166 * @global array $wp_filter Stores all of the filters 167 * @global array $merged_filters Merges the filter hooks using this function. 168 * @global array $wp_current_filter stores the list of current filters with the current one last 169 * 170 * @return array The filtered value after all hooked functions are applied to it. 171 */ 172 function bp_get_template_stack() { 173 global $wp_filter, $merged_filters, $wp_current_filter; 174 175 // Setup some default variables 176 $tag = 'bp_template_stack'; 177 $args = $stack = array(); 178 179 // Add 'bp_template_stack' to the current filter array 180 $wp_current_filter[] = $tag; 181 182 // Sort 183 if ( ! isset( $merged_filters[ $tag ] ) ) { 184 ksort( $wp_filter[$tag] ); 185 $merged_filters[ $tag ] = true; 186 } 187 188 // Ensure we're always at the beginning of the filter array 189 reset( $wp_filter[ $tag ] ); 190 191 // Loop through 'bp_template_stack' filters, and call callback functions 192 while ( next( $wp_filter[$tag] ) !== false ) { 193 foreach( (array) current( $wp_filter[$tag] ) as $the_ ) { 194 if ( ! is_null( $the_['function'] ) ) { 195 $args[1] = $stack; 196 $stack[] = call_user_func_array( $the_['function'], array_slice( $args, 1, (int) $the_['accepted_args'] ) ); 197 } 198 } 199 }; 200 201 // Remove 'bp_template_stack' from the current filter array 202 array_pop( $wp_current_filter ); 203 204 // Remove empties and duplicates 205 $stack = array_unique( array_filter( $stack ) ); 206 207 return (array) apply_filters( 'bp_get_template_stack', $stack ) ; 208 } 209 210 /** 147 211 * Retrieve path to a template 148 212 * 149 213 * Used to quickly retrieve the path of a template without including the file -
bp-loader.php
class BuddyPress { 527 527 * @since BuddyPress (1.7) 528 528 */ 529 529 public function register_theme_packages() { 530 // Register the default theme compatibility package 530 531 bp_register_theme_package( array( 531 532 'id' => 'legacy', 532 533 'name' => __( 'BuddyPress Default', 'buddypress' ), … … class BuddyPress { 534 535 'dir' => trailingslashit( $this->themes_dir . '/bp-legacy' ), 535 536 'url' => trailingslashit( $this->themes_url . '/bp-legacy' ) 536 537 ) ); 538 539 // Register the basic theme stack. This is really dope. 540 bp_register_template_stack( 'get_stylesheet_directory', 10 ); 541 bp_register_template_stack( 'get_template_directory', 12 ); 542 bp_register_template_stack( 'bp_get_theme_compat_dir', 14 ); 537 543 } 538 544 539 545 /**