Advertisement
helgatheviki

wp-includes/template.php mods for passing variables

Jun 20th, 2013
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.00 KB | None | 0 0
  1. /**
  2.  * Retrieve the name of the highest priority template file that exists.
  3.  *
  4.  * Searches in the STYLESHEETPATH before TEMPLATEPATH so that themes which
  5.  * inherit from a parent theme can just overload one file.
  6.  *
  7.  * @since 2.7.0
  8.  *
  9.  * @param string|array $template_names Template file(s) to search for, in order.
  10.  * @param bool $load If true the template file will be loaded if it is found.
  11.  * @param bool $require_once Whether to require_once or require. Default true. Has no effect if $load is false.
  12.  * @return string The template filename if one is located.
  13.  */
  14. function locate_template($template_names, $load = false, $require_once = true, $args = array() ) {
  15.     $located = '';
  16.     foreach ( (array) $template_names as $template_name ) {
  17.         if ( !$template_name )
  18.             continue;
  19.         if ( file_exists(STYLESHEETPATH . '/' . $template_name)) {
  20.             $located = STYLESHEETPATH . '/' . $template_name;
  21.             break;
  22.         } else if ( file_exists(TEMPLATEPATH . '/' . $template_name) ) {
  23.             $located = TEMPLATEPATH . '/' . $template_name;
  24.             break;
  25.         }
  26.     }
  27.  
  28.     if ( $load && '' != $located )
  29.         load_template( $located, $require_once, $args );
  30.  
  31.     return $located;
  32. }
  33.  
  34. /**
  35.  * Require the template file with WordPress environment.
  36.  *
  37.  * The globals are set up for the template file to ensure that the WordPress
  38.  * environment is available from within the function. The query variables are
  39.  * also available.
  40.  *
  41.  * @since 1.5.0
  42.  *
  43.  * @param string $_template_file Path to template file.
  44.  * @param bool $require_once Whether to require_once or require. Default true.
  45.  */
  46. function load_template( $_template_file, $require_once = true, $args = array() ) {
  47.     global $posts, $post, $wp_did_header, $wp_query, $wp_rewrite, $wpdb, $wp_version, $wp, $id, $comment, $user_ID;
  48.  
  49.     if ( is_array( $wp_query->query_vars ) )
  50.         extract( $wp_query->query_vars, EXTR_SKIP );
  51.  
  52.     if ( is_array( $args ) )
  53.         extract( $args );
  54.  
  55.     echo $foo;
  56.  
  57.  
  58.     if ( $require_once )
  59.         require_once( $_template_file );
  60.     else
  61.         require( $_template_file );
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement