Changeset 10356 for trunk/src/bp-core/bp-core-template-loader.php
- Timestamp:
- 11/15/2015 07:57:03 PM (10 years ago)
- File:
-
- 1 edited
-
trunk/src/bp-core/bp-core-template-loader.php (modified) (22 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bp-core/bp-core-template-loader.php
r10279 r10356 27 27 * @param string $name Optional. Template part name. Used to generate 28 28 * secondary filenames, eg 'personal' for 'activity-personal.php'. 29 *30 29 * @return string Path to located template. See {@link bp_locate_template()}. 31 30 */ … … 44 43 do_action( 'get_template_part_' . $slug, $slug, $name ); 45 44 46 // Setup possible parts 45 // Setup possible parts. 47 46 $templates = array(); 48 47 if ( isset( $name ) ) { … … 62 61 $templates = apply_filters( 'bp_get_template_part', $templates, $slug, $name ); 63 62 64 // Return the part that is found 63 // Return the part that is found. 65 64 return bp_locate_template( $templates, true, false ); 66 65 } … … 80 79 * @param bool $require_once Optional. Whether to require_once or require. Has 81 80 * no effect if $load is false. Default: true. 82 *83 81 * @return string The template filename if one is located. 84 82 */ 85 83 function bp_locate_template( $template_names, $load = false, $require_once = true ) { 86 84 87 // No file found yet 85 // No file found yet. 88 86 $located = false; 89 87 $template_locations = bp_get_template_stack(); 90 88 91 // Try to find a template file 89 // Try to find a template file. 92 90 foreach ( (array) $template_names as $template_name ) { 93 91 94 // Continue if template is empty 92 // Continue if template is empty. 95 93 if ( empty( $template_name ) ) { 96 94 continue; 97 95 } 98 96 99 // Trim off any slashes from the template name 97 // Trim off any slashes from the template name. 100 98 $template_name = ltrim( $template_name, '/' ); 101 99 102 // Loop through template stack 100 // Loop through template stack. 103 101 foreach ( (array) $template_locations as $template_location ) { 104 102 105 // Continue if $template_location is empty 103 // Continue if $template_location is empty. 106 104 if ( empty( $template_location ) ) { 107 105 continue; 108 106 } 109 107 110 // Check child theme first 108 // Check child theme first. 111 109 if ( file_exists( trailingslashit( $template_location ) . $template_name ) ) { 112 110 $located = trailingslashit( $template_location ) . $template_name; … … 125 123 do_action( 'bp_locate_template', $located, $template_name, $template_names, $template_locations, $load, $require_once ); 126 124 127 // Maybe load the template if one was located 125 // Maybe load the template if one was located. 128 126 $use_themes = defined( 'WP_USE_THEMES' ) && WP_USE_THEMES; 129 127 $doing_ajax = defined( 'DOING_AJAX' ) && DOING_AJAX; … … 147 145 * @param int $priority Optional. The priority parameter as passed to 148 146 * add_filter(). Default: 10. 149 *150 147 * @return bool See {@link add_filter()}. 151 148 */ 152 149 function bp_register_template_stack( $location_callback = '', $priority = 10 ) { 153 150 154 // Bail if no location, or function/method is not callable 151 // Bail if no location, or function/method is not callable. 155 152 if ( empty( $location_callback ) || ! is_callable( $location_callback ) ) { 156 153 return false; 157 154 } 158 155 159 // Add location callback to template stack 156 // Add location callback to template stack. 160 157 return add_filter( 'bp_template_stack', $location_callback, (int) $priority ); 161 158 } … … 171 168 * @param int $priority Optional. The priority parameter passed to 172 169 * {@link bp_register_template_stack()}. Default: 10. 173 *174 170 * @return bool See {@link remove_filter()}. 175 171 */ 176 172 function bp_deregister_template_stack( $location_callback = '', $priority = 10 ) { 177 173 178 // Bail if no location, or function/method is not callable 174 // Bail if no location, or function/method is not callable. 179 175 if ( empty( $location_callback ) || ! is_callable( $location_callback ) ) { 180 176 return false; 181 177 } 182 178 183 // Add location callback to template stack 179 // Add location callback to template stack. 184 180 return remove_filter( 'bp_template_stack', $location_callback, (int) $priority ); 185 181 } … … 199 195 * @global array $wp_current_filter Stores the list of current filters with 200 196 * the current one last. 201 *202 197 * @return array The filtered value after all hooked functions are applied to it. 203 198 */ … … 205 200 global $wp_filter, $merged_filters, $wp_current_filter; 206 201 207 // Setup some default variables 202 // Setup some default variables. 208 203 $tag = 'bp_template_stack'; 209 204 $args = $stack = array(); 210 205 211 // Add 'bp_template_stack' to the current filter array 206 // Add 'bp_template_stack' to the current filter array. 212 207 $wp_current_filter[] = $tag; 213 208 214 // Sort 209 // Sort. 215 210 if ( class_exists( 'WP_Hook' ) ) { 216 211 $filter = $wp_filter[ $tag ]->callbacks; … … 224 219 } 225 220 226 // Ensure we're always at the beginning of the filter array 221 // Ensure we're always at the beginning of the filter array. 227 222 reset( $filter ); 228 223 229 // Loop through 'bp_template_stack' filters, and call callback functions 224 // Loop through 'bp_template_stack' filters, and call callback functions. 230 225 do { 231 226 foreach( (array) current( $filter ) as $the_ ) { … … 237 232 } while ( next( $filter ) !== false ); 238 233 239 // Remove 'bp_template_stack' from the current filter array 234 // Remove 'bp_template_stack' from the current filter array. 240 235 array_pop( $wp_current_filter ); 241 236 242 // Remove empties and duplicates 237 // Remove empties and duplicates. 243 238 $stack = array_unique( array_filter( $stack ) ); 244 239 … … 264 259 * @param bool $echo If true, template content will be echoed. If false, 265 260 * returned. Default: true. 266 *267 261 * @return string|null If $echo, returns the template content. 268 262 */ … … 270 264 ob_start(); 271 265 272 // Remove 'bp_replace_the_content' filter to prevent infinite loops 266 // Remove 'bp_replace_the_content' filter to prevent infinite loops. 273 267 remove_filter( 'the_content', 'bp_replace_the_content' ); 274 268 275 269 bp_get_template_part( $slug, $name ); 276 270 277 // Remove 'bp_replace_the_content' filter to prevent infinite loops 271 // Remove 'bp_replace_the_content' filter to prevent infinite loops. 278 272 add_filter( 'the_content', 'bp_replace_the_content' ); 279 273 280 // Get the output buffer contents 274 // Get the output buffer contents. 281 275 $output = ob_get_clean(); 282 276 283 // Echo or return the output buffer contents 277 // Echo or return the output buffer contents. 284 278 if ( true === $echo ) { 285 279 echo $output; … … 305 299 * @param string $type Filename without extension. 306 300 * @param array $templates An optional list of template candidates. 307 *308 301 * @return string Full path to file. 309 302 */ … … 352 345 * 353 346 * @param array $templates Templates we are looking for. 354 *355 347 * @return array Possible subfolders to look in. 356 348 */ … … 379 371 * 380 372 * @param array $stacks Array of template locations. 381 *382 373 * @return array() Array of all template locations registered so far. 383 374 */ … … 385 376 $retval = array(); 386 377 387 // Get alternate locations 378 // Get alternate locations. 388 379 $locations = bp_get_template_locations(); 389 380 390 // Loop through locations and stacks and combine 381 // Loop through locations and stacks and combine. 391 382 foreach ( (array) $stacks as $stack ) { 392 383 foreach ( (array) $locations as $custom_location ) { … … 411 402 * @since 1.7.0 412 403 * 413 * @param WP_Query $posts_query 404 * @param WP_Query $posts_query WP_Query object. 414 405 */ 415 406 function bp_parse_query( $posts_query ) { 416 407 417 // Bail if $posts_query is not the main loop 408 // Bail if $posts_query is not the main loop. 418 409 if ( ! $posts_query->is_main_query() ) { 419 410 return; 420 411 } 421 412 422 // Bail if filters are suppressed on this query 413 // Bail if filters are suppressed on this query. 423 414 if ( true == $posts_query->get( 'suppress_filters' ) ) { 424 415 return; 425 416 } 426 417 427 // Bail if in admin 418 // Bail if in admin. 428 419 if ( is_admin() ) { 429 420 return; … … 454 445 * @since 1.7.0 455 446 * 456 * @param string $template 457 * 447 * @param string $template The path to the template file that is being used. 458 448 * @return string The path to the template file that is being used. 459 449 */ … … 492 482 * 493 483 * @param mixed $template Default: false. 494 *495 484 * @return mixed False if empty. Template name if template included. 496 485 */ … … 523 512 global $pagenow, $wp_query; 524 513 525 // do not load our custom BP functions file if theme compat is disabled514 // Do not load our custom BP functions file if theme compat is disabled. 526 515 if ( ! bp_use_theme_compat_with_current_theme() ) { 527 516 return; 528 517 } 529 518 530 // Do not include on BuddyPress deactivation 519 // Do not include on BuddyPress deactivation. 531 520 if ( bp_is_deactivation() ) { 532 521 return; … … 536 525 // or has been reset), load_template() will fail at setting certain 537 526 // global values. This does not happen on a normal page load, but can 538 // cause problems when running automated tests 527 // cause problems when running automated tests. 539 528 if ( ! is_a( $wp_query, 'WP_Query' ) ) { 540 529 return; 541 530 } 542 531 543 // Only include if not installing or if activating via wp-activate.php 532 // Only include if not installing or if activating via wp-activate.php. 544 533 if ( ! defined( 'WP_INSTALLING' ) || 'wp-activate.php' === $pagenow ) { 545 534 bp_locate_template( 'buddypress-functions.php', true );
Note: See TracChangeset
for help on using the changeset viewer.