462 | | function locate_template($template_names, $load = false, $require_once = true ) { |
463 | | $located = ''; |
464 | | foreach ( (array) $template_names as $template_name ) { |
465 | | if ( !$template_name ) |
466 | | continue; |
467 | | if ( file_exists(STYLESHEETPATH . '/' . $template_name)) { |
468 | | $located = STYLESHEETPATH . '/' . $template_name; |
469 | | break; |
470 | | } else if ( file_exists(TEMPLATEPATH . '/' . $template_name) ) { |
471 | | $located = TEMPLATEPATH . '/' . $template_name; |
472 | | break; |
| 462 | function locate_template( $template_names, $load = false, $require_once = true ) { |
| 463 | /** |
| 464 | * Filter the file path of the template to load. |
| 465 | * |
| 466 | * Returning a non-empty value will preempt searching for the template |
| 467 | * in the stylesheet and template paths. |
| 468 | * |
| 469 | * @since 3.9.0 |
| 470 | * |
| 471 | * @param string $located Path to the template file to load. Default empty. |
| 472 | * @param string|array $template_names Template file or array of files to search for, in order. |
| 473 | * @param bool $load Whether to the load the template file if found. Default false. |
| 474 | * @param bool $require_once Whether to require_once or require. True for require_once, |
| 475 | * false for require. |
| 476 | */ |
| 477 | $located = apply_filters( 'pre_locate_template', '', $template_names, $load, $require_once ); |
| 478 | |
| 479 | if ( empty( $located ) ) { |
| 480 | foreach ( (array) $template_names as $template_name ) { |
| 481 | if ( ! $template_name ) { |
| 482 | continue; |
| 483 | } |
| 484 | if ( file_exists( STYLESHEETPATH . '/' . $template_name ) ) { |
| 485 | $located = STYLESHEETPATH . '/' . $template_name; |
| 486 | break; |
| 487 | } else if ( file_exists( TEMPLATEPATH . '/' . $template_name ) ) { |
| 488 | $located = TEMPLATEPATH . '/' . $template_name; |
| 489 | break; |
| 490 | } |