[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

title

Body

[close]

/wp-includes/ -> template-loader.php (source)

   1  <?php
   2  /**
   3   * Loads the correct template based on the visitor's url
   4   *
   5   * @package WordPress
   6   */
   7  if ( wp_using_themes() ) {
   8      /**
   9       * Fires before determining which template to load.
  10       *
  11       * @since 1.5.0
  12       */
  13      do_action( 'template_redirect' );
  14  }
  15  
  16  /**
  17   * Filters whether to allow 'HEAD' requests to generate content.
  18   *
  19   * Provides a significant performance bump by exiting before the page
  20   * content loads for 'HEAD' requests. See #14348.
  21   *
  22   * @since 3.5.0
  23   *
  24   * @param bool $exit Whether to exit without generating any content for 'HEAD' requests. Default true.
  25   */
  26  if ( 'HEAD' === $_SERVER['REQUEST_METHOD'] && apply_filters( 'exit_on_http_head', true ) ) {
  27      exit;
  28  }
  29  
  30  // Process feeds and trackbacks even if not using themes.
  31  if ( is_robots() ) {
  32      /**
  33       * Fired when the template loader determines a robots.txt request.
  34       *
  35       * @since 2.1.0
  36       */
  37      do_action( 'do_robots' );
  38      return;
  39  } elseif ( is_favicon() ) {
  40      /**
  41       * Fired when the template loader determines a favicon.ico request.
  42       *
  43       * @since 5.4.0
  44       */
  45      do_action( 'do_favicon' );
  46      return;
  47  } elseif ( is_feed() ) {
  48      do_feed();
  49      return;
  50  } elseif ( is_trackback() ) {
  51      require  ABSPATH . 'wp-trackback.php';
  52      return;
  53  }
  54  
  55  if ( wp_using_themes() ) {
  56  
  57      $tag_templates = array(
  58          'is_embed'             => 'get_embed_template',
  59          'is_404'               => 'get_404_template',
  60          'is_search'            => 'get_search_template',
  61          'is_front_page'        => 'get_front_page_template',
  62          'is_home'              => 'get_home_template',
  63          'is_privacy_policy'    => 'get_privacy_policy_template',
  64          'is_post_type_archive' => 'get_post_type_archive_template',
  65          'is_tax'               => 'get_taxonomy_template',
  66          'is_attachment'        => 'get_attachment_template',
  67          'is_single'            => 'get_single_template',
  68          'is_page'              => 'get_page_template',
  69          'is_singular'          => 'get_singular_template',
  70          'is_category'          => 'get_category_template',
  71          'is_tag'               => 'get_tag_template',
  72          'is_author'            => 'get_author_template',
  73          'is_date'              => 'get_date_template',
  74          'is_archive'           => 'get_archive_template',
  75      );
  76      $template      = false;
  77  
  78      // Loop through each of the template conditionals, and find the appropriate template file.
  79      foreach ( $tag_templates as $tag => $template_getter ) {
  80          if ( call_user_func( $tag ) ) {
  81              $template = call_user_func( $template_getter );
  82          }
  83  
  84          if ( $template ) {
  85              if ( 'is_attachment' === $tag ) {
  86                  remove_filter( 'the_content', 'prepend_attachment' );
  87              }
  88  
  89              break;
  90          }
  91      }
  92  
  93      if ( ! $template ) {
  94          $template = get_index_template();
  95      }
  96  
  97      /**
  98       * Filters the path of the current template before including it.
  99       *
 100       * @since 3.0.0
 101       *
 102       * @param string $template The path of the template to include.
 103       */
 104      $template = apply_filters( 'template_include', $template );
 105      if ( $template ) {
 106          include $template;
 107      } elseif ( current_user_can( 'switch_themes' ) ) {
 108          $theme = wp_get_theme();
 109          if ( $theme->errors() ) {
 110              wp_die( $theme->errors() );
 111          }
 112      }
 113      return;
 114  }


Generated : Thu Nov 21 08:20:01 2024 Cross-referenced by PHPXref