| 373 | | if ( file_exists(STYLESHEETPATH . '/' . $template_name)) { |
| 374 | | $located = STYLESHEETPATH . '/' . $template_name; |
| 375 | | break; |
| 376 | | } else if ( file_exists(TEMPLATEPATH . '/' . $template_name) ) { |
| 377 | | $located = TEMPLATEPATH . '/' . $template_name; |
| 378 | | break; |
| | 375 | |
| | 376 | $template_name = ltrim( $template_name, '/' ); |
| | 377 | |
| | 378 | foreach ( (array) $template_stack as $template_location ) { |
| | 379 | // Continue if $template_location is empty |
| | 380 | if ( empty( $template_location ) ) |
| | 381 | continue; |
| | 382 | |
| | 383 | if ( file_exists( trailingslashit( $template_location ) . $template_name ) ) { |
| | 384 | $located = trailingslashit( $template_location ) . $template_name; |
| | 385 | break 2; |
| | 386 | } |
| | 420 | /** |
| | 421 | * This function adds a new template stack location. |
| | 422 | * |
| | 423 | * This allows for templates to live in places beyond just the parent/child |
| | 424 | * relationship, to allow for custom template locations. Used in conjunction |
| | 425 | * with locate_template(), this allows for easy template overrides. |
| | 426 | * |
| | 427 | * @since 3.6.0 |
| | 428 | * |
| | 429 | * @param string $location Path to template files |
| | 430 | * @param int $priority |
| | 431 | * |
| | 432 | * @return bool True if added. |
| | 433 | */ |
| | 434 | function add_template_stack( $location, $priority = 10 ) { |
| | 435 | global $wp_template_stack; |
| | 436 | |
| | 437 | $idx = md5( $location ); |
| | 438 | $r = ! isset( $wp_template_stack[ $priority ][ $idx ] ); |
| | 439 | |
| | 440 | if ( $r === true ) |
| | 441 | $wp_template_stack[ $priority ][ $idx ] = $location; |
| | 442 | |
| | 443 | return $r; |
| | 444 | } |
| | 445 | |
| | 446 | /** |
| | 447 | * This function removes a template stack location. |
| | 448 | * |
| | 449 | * @since 3.6.0 |
| | 450 | * |
| | 451 | * @param string $location Path to template files |
| | 452 | * @param int $priority |
| | 453 | * |
| | 454 | * @return bool True if removed. |
| | 455 | */ |
| | 456 | function remove_template_stack( $location, $priority = 10 ) { |
| | 457 | global $wp_template_stack; |
| | 458 | |
| | 459 | $idx = md5( $location ); |
| | 460 | $r = isset( $wp_template_stack[ $priority ][ $idx ] ); |
| | 461 | |
| | 462 | if ( $r === true ) |
| | 463 | unset( $wp_template_stack[ $priority ][ $idx ] ); |
| | 464 | |
| | 465 | return $r; |
| | 466 | } |
| | 467 | |
| | 468 | /** |
| | 469 | * This function checks if a template stack location exists. |
| | 470 | * |
| | 471 | * @since 3.6.0 |
| | 472 | * |
| | 473 | * @param string $location Path to template files |
| | 474 | * |
| | 475 | * @return bool True if found. |
| | 476 | */ |
| | 477 | function has_template_stack( $location ) { |
| | 478 | global $wp_template_stack; |
| | 479 | |
| | 480 | $idx = md5( $location ); |
| | 481 | |
| | 482 | // Loop through template locations |
| | 483 | foreach ( (array) $wp_template_stack as $stacks ) { |
| | 484 | if ( array_key_exists( $idx, $stacks ) ) |
| | 485 | return true; |
| | 486 | } |
| | 487 | |
| | 488 | return false; |
| | 489 | } |
| | 490 | |
| | 491 | /** |
| | 492 | * Return an array of the template locations added to the $wp_template_stack. |
| | 493 | * |
| | 494 | * @since 3.6.0 |
| | 495 | * |
| | 496 | * @return array Template locations. |
| | 497 | */ |
| | 498 | function get_template_stack() { |
| | 499 | global $wp_template_stack; |
| | 500 | |
| | 501 | // Setup default variables |
| | 502 | $stack = array(); |
| | 503 | if ( ! is_array( $wp_template_stack ) ) |
| | 504 | $wp_template_stack = array(); |
| | 505 | |
| | 506 | // Sort |
| | 507 | ksort( $wp_template_stack ); |
| | 508 | |
| | 509 | // Ensure we're always at the beginning of the array |
| | 510 | reset( $wp_template_stack ); |
| | 511 | |
| | 512 | // Loop through template locations |
| | 513 | foreach ( $wp_template_stack as $stacks ) { |
| | 514 | foreach ( $stacks as $location ) |
| | 515 | $stack[] = $location; |
| | 516 | } |
| | 517 | |
| | 518 | // Remove empties and duplicates |
| | 519 | $stack = array_unique( array_filter( $stack ) ); |
| | 520 | |
| | 521 | return (array) apply_filters( 'get_template_stack', $stack ); |
| | 522 | } |