Changeset 6537
- Timestamp:
- 11/29/2012 09:15:07 PM (12 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/bp-core/bp-core-template-loader.php
r6490 r6537 62 62 63 63 // 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 ); 64 $located = false; 65 $template_locations = bp_get_template_stack(); 72 66 73 67 // Try to find a template file 74 // Check the parent and child theme directories first75 68 foreach ( (array) $template_names as $template_name ) { 76 69 … … 80 73 81 74 // 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 ) ) { 98 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; 75 $template_name = ltrim( $template_name, '/' ); 76 77 // Loop through template stack 78 foreach ( (array) $template_locations as $template_location ) { 79 80 // Continue if $template_location is empty 81 if ( empty( $template_location ) ) 82 continue; 83 84 // Check child theme first 85 if ( file_exists( trailingslashit( $template_location ) . $template_name ) ) { 86 $located = trailingslashit( $template_location ) . $template_name; 87 break 2; 102 88 } 103 89 } 104 90 } 105 91 92 // Maybe load the template if one was located 106 93 if ( ( true == $load ) && !empty( $located ) ) 107 94 load_template( $located, $require_once ); 108 95 109 96 return $located; 97 } 98 99 /** 100 * This is really cool. This function registers a new template stack location, 101 * using WordPress's built in filters API. 102 * 103 * This allows for templates to live in places beyond just the parent/child 104 * relationship, to allow for custom template locations. Used in conjunction 105 * with bp_locate_template(), this allows for easy template overrides. 106 * 107 * @since BuddyPress (1.7) 108 * 109 * @param string $location Callback function that returns the 110 * @param int $priority 111 */ 112 function bp_register_template_stack( $location_callback = '', $priority = 10 ) { 113 114 // Bail if no location, or function does not exist 115 if ( empty( $location_callback ) || ! function_exists( $location_callback ) ) 116 return false; 117 118 // Add location callback to template stack 119 add_filter( 'bp_template_stack', $location_callback, (int) $priority ); 120 } 121 122 /** 123 * Call the functions added to the 'bp_template_stack' filter hook, and return 124 * an array of the template locations. 125 * 126 * @see bp_register_template_stack() 127 * 128 * @since BuddyPress (1.7) 129 * 130 * @global array $wp_filter Stores all of the filters 131 * @global array $merged_filters Merges the filter hooks using this function. 132 * @global array $wp_current_filter stores the list of current filters with the current one last 133 * 134 * @return array The filtered value after all hooked functions are applied to it. 135 */ 136 function bp_get_template_stack() { 137 global $wp_filter, $merged_filters, $wp_current_filter; 138 139 // Setup some default variables 140 $tag = 'bp_template_stack'; 141 $args = $stack = array(); 142 143 // Add 'bp_template_stack' to the current filter array 144 $wp_current_filter[] = $tag; 145 146 // Sort 147 if ( ! isset( $merged_filters[ $tag ] ) ) { 148 ksort( $wp_filter[$tag] ); 149 $merged_filters[ $tag ] = true; 150 } 151 152 // Ensure we're always at the beginning of the filter array 153 reset( $wp_filter[ $tag ] ); 154 155 // Loop through 'bp_template_stack' filters, and call callback functions 156 do { 157 foreach( (array) current( $wp_filter[$tag] ) as $the_ ) { 158 if ( ! is_null( $the_['function'] ) ) { 159 $args[1] = $stack; 160 $stack[] = call_user_func_array( $the_['function'], array_slice( $args, 1, (int) $the_['accepted_args'] ) ); 161 } 162 } 163 } while ( next( $wp_filter[$tag] ) !== false ); 164 165 // Remove 'bp_template_stack' from the current filter array 166 array_pop( $wp_current_filter ); 167 168 // Remove empties and duplicates 169 $stack = array_unique( array_filter( $stack ) ); 170 171 return (array) apply_filters( 'bp_get_template_stack', $stack ) ; 110 172 } 111 173 -
trunk/bp-loader.php
r6509 r6537 539 539 */ 540 540 public function register_theme_packages() { 541 542 // Register the default theme compatibility package 541 543 bp_register_theme_package( array( 542 544 'id' => 'legacy', … … 546 548 'url' => trailingslashit( $this->themes_url . '/bp-legacy' ) 547 549 ) ); 550 551 // Register the basic theme stack. This is really dope. 552 bp_register_template_stack( 'get_stylesheet_directory', 10 ); 553 bp_register_template_stack( 'get_template_directory', 12 ); 554 bp_register_template_stack( 'bp_get_theme_compat_dir', 14 ); 548 555 } 549 556
Note: See TracChangeset
for help on using the changeset viewer.