web/wp-includes/theme.php
author hurons@caf4f556-3d62-0410-8435-a86758001935
Wed, 23 Dec 2009 17:55:33 +0000
branchwordpress
changeset 109 03b0d1493584
child 132 4d4862461b8d
permissions -rw-r--r--
wordpress 2.8 () with the following extensions : - add-to-any - categories page - Event calendar (a custom version for IRI-Theme) - Executable PHP widget - FD feedburner - ggis subscribe - Google Xml site maple - post of current category - page redirection - related post by category AND IRI-Theme
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
109
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
     1
<?php
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
     2
/**
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
     3
 * Theme, template, and stylesheet functions.
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
     4
 *
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
     5
 * @package WordPress
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
     6
 * @subpackage Template
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
     7
 */
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
     8
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
     9
/**
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    10
 * Retrieve name of the current stylesheet.
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    11
 *
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    12
 * The theme name that the administrator has currently set the front end theme
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    13
 * as.
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    14
 *
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    15
 * For all extensive purposes, the template name and the stylesheet name are
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    16
 * going to be the same for most cases.
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    17
 *
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    18
 * @since 1.5.0
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    19
 * @uses apply_filters() Calls 'stylesheet' filter on stylesheet name.
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    20
 *
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    21
 * @return string Stylesheet name.
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    22
 */
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    23
function get_stylesheet() {
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    24
	return apply_filters('stylesheet', get_option('stylesheet'));
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    25
}
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    26
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    27
/**
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    28
 * Retrieve stylesheet directory path for current theme.
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    29
 *
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    30
 * @since 1.5.0
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    31
 * @uses apply_filters() Calls 'stylesheet_directory' filter on stylesheet directory and theme name.
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    32
 *
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    33
 * @return string Path to current theme directory.
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    34
 */
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    35
function get_stylesheet_directory() {
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    36
	$stylesheet = get_stylesheet();
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    37
	$stylesheet_dir = get_theme_root() . "/$stylesheet";
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    38
	return apply_filters('stylesheet_directory', $stylesheet_dir, $stylesheet);
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    39
}
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    40
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    41
/**
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    42
 * Retrieve stylesheet directory URI.
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    43
 *
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    44
 * @since 1.5.0
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    45
 *
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    46
 * @return string
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    47
 */
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    48
function get_stylesheet_directory_uri() {
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    49
	$stylesheet = get_stylesheet();
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    50
	$stylesheet_dir_uri = get_theme_root_uri() . "/$stylesheet";
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    51
	return apply_filters('stylesheet_directory_uri', $stylesheet_dir_uri, $stylesheet);
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    52
}
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    53
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    54
/**
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    55
 * Retrieve URI of current theme stylesheet.
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    56
 *
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    57
 * The stylesheet file name is 'style.css' which is appended to {@link
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    58
 * get_stylesheet_directory_uri() stylesheet directory URI} path.
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    59
 *
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    60
 * @since 1.5.0
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    61
 * @uses apply_filters() Calls 'stylesheet_uri' filter on stylesheet URI path and stylesheet directory URI.
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    62
 *
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    63
 * @return string
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    64
 */
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    65
function get_stylesheet_uri() {
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    66
	$stylesheet_dir_uri = get_stylesheet_directory_uri();
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    67
	$stylesheet_uri = $stylesheet_dir_uri . "/style.css";
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    68
	return apply_filters('stylesheet_uri', $stylesheet_uri, $stylesheet_dir_uri);
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    69
}
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    70
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    71
/**
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    72
 * Retrieve localized stylesheet URI.
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    73
 *
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    74
 * The stylesheet directory for the localized stylesheet files are located, by
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    75
 * default, in the base theme directory. The name of the locale file will be the
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    76
 * locale followed by '.css'. If that does not exist, then the text direction
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    77
 * stylesheet will be checked for existence, for example 'ltr.css'.
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    78
 *
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    79
 * The theme may change the location of the stylesheet directory by either using
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    80
 * the 'stylesheet_directory_uri' filter or the 'locale_stylesheet_uri' filter.
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    81
 * If you want to change the location of the stylesheet files for the entire
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    82
 * WordPress workflow, then change the former. If you just have the locale in a
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    83
 * separate folder, then change the latter.
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    84
 *
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    85
 * @since 2.1.0
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    86
 * @uses apply_filters() Calls 'locale_stylesheet_uri' filter on stylesheet URI path and stylesheet directory URI.
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    87
 *
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    88
 * @return string
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    89
 */
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    90
function get_locale_stylesheet_uri() {
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    91
	global $wp_locale;
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    92
	$stylesheet_dir_uri = get_stylesheet_directory_uri();
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    93
	$dir = get_stylesheet_directory();
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    94
	$locale = get_locale();
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    95
	if ( file_exists("$dir/$locale.css") )
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    96
		$stylesheet_uri = "$stylesheet_dir_uri/$locale.css";
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    97
	elseif ( !empty($wp_locale->text_direction) && file_exists("$dir/{$wp_locale->text_direction}.css") )
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    98
		$stylesheet_uri = "$stylesheet_dir_uri/{$wp_locale->text_direction}.css";
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    99
	else
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   100
		$stylesheet_uri = '';
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   101
	return apply_filters('locale_stylesheet_uri', $stylesheet_uri, $stylesheet_dir_uri);
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   102
}
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   103
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   104
/**
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   105
 * Retrieve name of the current theme.
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   106
 *
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   107
 * @since 1.5.0
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   108
 * @uses apply_filters() Calls 'template' filter on template option.
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   109
 *
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   110
 * @return string Template name.
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   111
 */
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   112
function get_template() {
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   113
	return apply_filters('template', get_option('template'));
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   114
}
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   115
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   116
/**
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   117
 * Retrieve current theme directory.
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   118
 *
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   119
 * @since 1.5.0
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   120
 * @uses apply_filters() Calls 'template_directory' filter on template directory path and template name.
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   121
 *
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   122
 * @return string Template directory path.
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   123
 */
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   124
function get_template_directory() {
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   125
	$template = get_template();
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   126
	$template_dir = get_theme_root() . "/$template";
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   127
	return apply_filters('template_directory', $template_dir, $template);
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   128
}
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   129
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   130
/**
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   131
 * Retrieve theme directory URI.
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   132
 *
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   133
 * @since 1.5.0
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   134
 * @uses apply_filters() Calls 'template_directory_uri' filter on template directory URI path and template name.
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   135
 *
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   136
 * @return string Template directory URI.
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   137
 */
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   138
function get_template_directory_uri() {
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   139
	$template = get_template();
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   140
	$template_dir_uri = get_theme_root_uri() . "/$template";
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   141
	return apply_filters('template_directory_uri', $template_dir_uri, $template);
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   142
}
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   143
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   144
/**
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   145
 * Retrieve theme data from parsed theme file.
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   146
 *
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   147
 * The description will have the tags filtered with the following HTML elements
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   148
 * whitelisted. The <b>'a'</b> element with the <em>href</em> and <em>title</em>
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   149
 * attributes. The <b>abbr</b> element with the <em>title</em> attribute. The
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   150
 * <b>acronym<b> element with the <em>title</em> attribute allowed. The
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   151
 * <b>code</b>, <b>em</b>, and <b>strong</b> elements also allowed.
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   152
 *
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   153
 * The style.css file must contain theme name, theme URI, and description. The
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   154
 * data can also contain author URI, author, template (parent template),
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   155
 * version, status, and finally tags. Some of these are not used by WordPress
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   156
 * administration panels, but are used by theme directory web sites which list
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   157
 * the theme.
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   158
 *
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   159
 * @since 1.5.0
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   160
 *
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   161
 * @param string $theme_file Theme file path.
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   162
 * @return array Theme data.
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   163
 */
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   164
function get_theme_data( $theme_file ) {
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   165
	$themes_allowed_tags = array(
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   166
		'a' => array(
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   167
			'href' => array(),'title' => array()
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   168
			),
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   169
		'abbr' => array(
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   170
			'title' => array()
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   171
			),
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   172
		'acronym' => array(
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   173
			'title' => array()
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   174
			),
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   175
		'code' => array(),
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   176
		'em' => array(),
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   177
		'strong' => array()
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   178
	);
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   179
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   180
	$theme_data = implode( '', file( $theme_file ) );
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   181
	$theme_data = str_replace ( '\r', '\n', $theme_data );
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   182
	if ( preg_match( '|Theme Name:(.*)$|mi', $theme_data, $theme_name ) )
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   183
		$name = $theme = wp_kses( _cleanup_header_comment($theme_name[1]), $themes_allowed_tags );
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   184
	else
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   185
		$name = $theme = '';
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   186
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   187
	if ( preg_match( '|Theme URI:(.*)$|mi', $theme_data, $theme_uri ) )
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   188
		$theme_uri = esc_url( _cleanup_header_comment($theme_uri[1]) );
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   189
	else
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   190
		$theme_uri = '';
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   191
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   192
	if ( preg_match( '|Description:(.*)$|mi', $theme_data, $description ) )
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   193
		$description = wptexturize( wp_kses( _cleanup_header_comment($description[1]), $themes_allowed_tags ) );
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   194
	else
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   195
		$description = '';
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   196
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   197
	if ( preg_match( '|Author URI:(.*)$|mi', $theme_data, $author_uri ) )
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   198
		$author_uri = esc_url( _cleanup_header_comment($author_uri[1]) );
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   199
	else
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   200
		$author_uri = '';
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   201
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   202
	if ( preg_match( '|Template:(.*)$|mi', $theme_data, $template ) )
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   203
		$template = wp_kses( _cleanup_header_comment($template[1]), $themes_allowed_tags );
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   204
	else
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   205
		$template = '';
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   206
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   207
	if ( preg_match( '|Version:(.*)|i', $theme_data, $version ) )
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   208
		$version = wp_kses( _cleanup_header_comment($version[1]), $themes_allowed_tags );
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   209
	else
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   210
		$version = '';
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   211
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   212
	if ( preg_match('|Status:(.*)|i', $theme_data, $status) )
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   213
		$status = wp_kses( _cleanup_header_comment($status[1]), $themes_allowed_tags );
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   214
	else
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   215
		$status = 'publish';
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   216
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   217
	if ( preg_match('|Tags:(.*)|i', $theme_data, $tags) )
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   218
		$tags = array_map( 'trim', explode( ',', wp_kses( _cleanup_header_comment($tags[1]), array() ) ) );
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   219
	else
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   220
		$tags = array();
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   221
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   222
	if ( preg_match( '|Author:(.*)$|mi', $theme_data, $author_name ) ) {
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   223
		if ( empty( $author_uri ) ) {
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   224
			$author = wp_kses( _cleanup_header_comment($author_name[1]), $themes_allowed_tags );
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   225
		} else {
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   226
			$author = sprintf( '<a href="%1$s" title="%2$s">%3$s</a>', $author_uri, __( 'Visit author homepage' ), wp_kses( _cleanup_header_comment($author_name[1]), $themes_allowed_tags ) );
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   227
		}
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   228
	} else {
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   229
		$author = __('Anonymous');
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   230
	}
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   231
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   232
	return array( 'Name' => $name, 'Title' => $theme, 'URI' => $theme_uri, 'Description' => $description, 'Author' => $author, 'Version' => $version, 'Template' => $template, 'Status' => $status, 'Tags' => $tags );
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   233
}
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   234
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   235
/**
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   236
 * Retrieve list of themes with theme data in theme directory.
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   237
 *
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   238
 * The theme is broken, if it doesn't have a parent theme and is missing either
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   239
 * style.css and, or index.php. If the theme has a parent theme then it is
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   240
 * broken, if it is missing style.css; index.php is optional. The broken theme
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   241
 * list is saved in the {@link $wp_broken_themes} global, which is displayed on
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   242
 * the theme list in the administration panels.
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   243
 *
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   244
 * @since 1.5.0
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   245
 * @global array $wp_broken_themes Stores the broken themes.
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   246
 * @global array $wp_themes Stores the working themes.
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   247
 *
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   248
 * @return array Theme list with theme data.
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   249
 */
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   250
function get_themes() {
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   251
	global $wp_themes, $wp_broken_themes;
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   252
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   253
	if ( isset($wp_themes) )
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   254
		return $wp_themes;
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   255
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   256
	$themes = array();
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   257
	$wp_broken_themes = array();
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   258
	$theme_loc = $theme_root = get_theme_root();
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   259
	if ( '/' != WP_CONTENT_DIR ) // don't want to replace all forward slashes, see Trac #4541
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   260
		$theme_loc = str_replace(WP_CONTENT_DIR, '', $theme_root);
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   261
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   262
	// Files in wp-content/themes directory and one subdir down
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   263
	$themes_dir = @ opendir($theme_root);
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   264
	if ( !$themes_dir )
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   265
		return false;
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   266
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   267
	while ( ($theme_dir = readdir($themes_dir)) !== false ) {
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   268
		if ( is_dir($theme_root . '/' . $theme_dir) && is_readable($theme_root . '/' . $theme_dir) ) {
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   269
			if ( $theme_dir{0} == '.' || $theme_dir == '..' || $theme_dir == 'CVS' )
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   270
				continue;
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   271
			$stylish_dir = @ opendir($theme_root . '/' . $theme_dir);
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   272
			$found_stylesheet = false;
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   273
			while ( ($theme_file = readdir($stylish_dir)) !== false ) {
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   274
				if ( $theme_file == 'style.css' ) {
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   275
					$theme_files[] = $theme_dir . '/' . $theme_file;
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   276
					$found_stylesheet = true;
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   277
					break;
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   278
				}
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   279
			}
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   280
			@closedir($stylish_dir);
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   281
			if ( !$found_stylesheet ) { // look for themes in that dir
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   282
				$subdir = "$theme_root/$theme_dir";
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   283
				$subdir_name = $theme_dir;
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   284
				$theme_subdir = @ opendir( $subdir );
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   285
				while ( ($theme_dir = readdir($theme_subdir)) !== false ) {
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   286
					if ( is_dir( $subdir . '/' . $theme_dir) && is_readable($subdir . '/' . $theme_dir) ) {
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   287
						if ( $theme_dir{0} == '.' || $theme_dir == '..' || $theme_dir == 'CVS' )
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   288
							continue;
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   289
						$stylish_dir = @ opendir($subdir . '/' . $theme_dir);
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   290
						$found_stylesheet = false;
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   291
						while ( ($theme_file = readdir($stylish_dir)) !== false ) {
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   292
							if ( $theme_file == 'style.css' ) {
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   293
								$theme_files[] = $subdir_name . '/' . $theme_dir . '/' . $theme_file;
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   294
								$found_stylesheet = true;
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   295
								break;
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   296
							}
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   297
						}
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   298
						@closedir($stylish_dir);
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   299
					}
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   300
				}
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   301
				@closedir($theme_subdir);
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   302
				$wp_broken_themes[$theme_dir] = array('Name' => $theme_dir, 'Title' => $theme_dir, 'Description' => __('Stylesheet is missing.'));
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   303
			}
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   304
		}
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   305
	}
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   306
	if ( is_dir( $theme_dir ) )
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   307
		@closedir( $theme_dir );
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   308
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   309
	if ( !$themes_dir || !$theme_files )
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   310
		return $themes;
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   311
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   312
	sort($theme_files);
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   313
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   314
	foreach ( (array) $theme_files as $theme_file ) {
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   315
		if ( !is_readable("$theme_root/$theme_file") ) {
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   316
			$wp_broken_themes[$theme_file] = array('Name' => $theme_file, 'Title' => $theme_file, 'Description' => __('File not readable.'));
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   317
			continue;
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   318
		}
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   319
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   320
		$theme_data = get_theme_data("$theme_root/$theme_file");
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   321
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   322
		$name        = $theme_data['Name'];
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   323
		$title       = $theme_data['Title'];
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   324
		$description = wptexturize($theme_data['Description']);
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   325
		$version     = $theme_data['Version'];
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   326
		$author      = $theme_data['Author'];
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   327
		$template    = $theme_data['Template'];
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   328
		$stylesheet  = dirname($theme_file);
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   329
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   330
		$screenshot = false;
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   331
		foreach ( array('png', 'gif', 'jpg', 'jpeg') as $ext ) {
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   332
			if (file_exists("$theme_root/$stylesheet/screenshot.$ext")) {
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   333
				$screenshot = "screenshot.$ext";
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   334
				break;
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   335
			}
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   336
		}
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   337
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   338
		if ( empty($name) ) {
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   339
			$name = dirname($theme_file);
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   340
			$title = $name;
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   341
		}
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   342
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   343
		if ( empty($template) ) {
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   344
			if ( file_exists(dirname("$theme_root/$theme_file/index.php")) )
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   345
				$template = dirname($theme_file);
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   346
			else
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   347
				continue;
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   348
		}
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   349
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   350
		$template = trim($template);
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   351
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   352
		if ( !file_exists("$theme_root/$template/index.php") ) {
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   353
			$parent_dir = dirname(dirname($theme_file));
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   354
			if ( file_exists("$theme_root/$parent_dir/$template/index.php") ) {
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   355
				$template = "$parent_dir/$template";
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   356
			} else {
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   357
				$wp_broken_themes[$name] = array('Name' => $name, 'Title' => $title, 'Description' => __('Template is missing.'));
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   358
				continue;
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   359
			}
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   360
		}
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   361
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   362
		$stylesheet_files = array();
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   363
		$template_files = array();
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   364
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   365
		$stylesheet_dir = @ dir("$theme_root/$stylesheet");
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   366
		if ( $stylesheet_dir ) {
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   367
			while ( ($file = $stylesheet_dir->read()) !== false ) {
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   368
				if ( !preg_match('|^\.+$|', $file) ) {
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   369
					if ( preg_match('|\.css$|', $file) )
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   370
						$stylesheet_files[] = "$theme_loc/$stylesheet/$file";
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   371
					elseif ( preg_match('|\.php$|', $file) )
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   372
						$template_files[] = "$theme_loc/$stylesheet/$file";
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   373
				}
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   374
			}
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   375
			@ $stylesheet_dir->close();
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   376
		}
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   377
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   378
		$template_dir = @ dir("$theme_root/$template");
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   379
		if ( $template_dir ) {
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   380
			while ( ($file = $template_dir->read()) !== false ) {
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   381
				if ( preg_match('|^\.+$|', $file) )
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   382
					continue;
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   383
				if ( preg_match('|\.php$|', $file) ) {
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   384
					$template_files[] = "$theme_loc/$template/$file";
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   385
				} elseif ( is_dir("$theme_root/$template/$file") ) {
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   386
					$template_subdir = @ dir("$theme_root/$template/$file");
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   387
					while ( ($subfile = $template_subdir->read()) !== false ) {
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   388
						if ( preg_match('|^\.+$|', $subfile) )
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   389
							continue;
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   390
						if ( preg_match('|\.php$|', $subfile) )
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   391
							$template_files[] = "$theme_loc/$template/$file/$subfile";
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   392
					}
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   393
					@ $template_subdir->close();
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   394
				}
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   395
			}
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   396
			@ $template_dir->close();
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   397
		}
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   398
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   399
		$template_dir = dirname($template_files[0]);
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   400
		$stylesheet_dir = dirname($stylesheet_files[0]);
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   401
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   402
		if ( empty($template_dir) )
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   403
			$template_dir = '/';
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   404
		if ( empty($stylesheet_dir) )
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   405
			$stylesheet_dir = '/';
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   406
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   407
		// Check for theme name collision.  This occurs if a theme is copied to
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   408
		// a new theme directory and the theme header is not updated.  Whichever
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   409
		// theme is first keeps the name.  Subsequent themes get a suffix applied.
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   410
		// The Default and Classic themes always trump their pretenders.
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   411
		if ( isset($themes[$name]) ) {
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   412
			if ( ('WordPress Default' == $name || 'WordPress Classic' == $name) &&
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   413
					 ('default' == $stylesheet || 'classic' == $stylesheet) ) {
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   414
				// If another theme has claimed to be one of our default themes, move
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   415
				// them aside.
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   416
				$suffix = $themes[$name]['Stylesheet'];
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   417
				$new_name = "$name/$suffix";
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   418
				$themes[$new_name] = $themes[$name];
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   419
				$themes[$new_name]['Name'] = $new_name;
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   420
			} else {
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   421
				$name = "$name/$stylesheet";
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   422
			}
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   423
		}
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   424
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   425
		$themes[$name] = array('Name' => $name, 'Title' => $title, 'Description' => $description, 'Author' => $author, 'Version' => $version, 'Template' => $template, 'Stylesheet' => $stylesheet, 'Template Files' => $template_files, 'Stylesheet Files' => $stylesheet_files, 'Template Dir' => $template_dir, 'Stylesheet Dir' => $stylesheet_dir, 'Status' => $theme_data['Status'], 'Screenshot' => $screenshot, 'Tags' => $theme_data['Tags']);
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   426
	}
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   427
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   428
	// Resolve theme dependencies.
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   429
	$theme_names = array_keys($themes);
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   430
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   431
	foreach ( (array) $theme_names as $theme_name ) {
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   432
		$themes[$theme_name]['Parent Theme'] = '';
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   433
		if ( $themes[$theme_name]['Stylesheet'] != $themes[$theme_name]['Template'] ) {
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   434
			foreach ( (array) $theme_names as $parent_theme_name ) {
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   435
				if ( ($themes[$parent_theme_name]['Stylesheet'] == $themes[$parent_theme_name]['Template']) && ($themes[$parent_theme_name]['Template'] == $themes[$theme_name]['Template']) ) {
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   436
					$themes[$theme_name]['Parent Theme'] = $themes[$parent_theme_name]['Name'];
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   437
					break;
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   438
				}
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   439
			}
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   440
		}
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   441
	}
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   442
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   443
	$wp_themes = $themes;
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   444
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   445
	return $themes;
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   446
}
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   447
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   448
/**
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   449
 * Retrieve theme data.
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   450
 *
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   451
 * @since 1.5.0
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   452
 *
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   453
 * @param string $theme Theme name.
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   454
 * @return array|null Null, if theme name does not exist. Theme data, if exists.
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   455
 */
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   456
function get_theme($theme) {
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   457
	$themes = get_themes();
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   458
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   459
	if ( array_key_exists($theme, $themes) )
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   460
		return $themes[$theme];
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   461
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   462
	return null;
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   463
}
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   464
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   465
/**
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   466
 * Retrieve current theme display name.
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   467
 *
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   468
 * If the 'current_theme' option has already been set, then it will be returned
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   469
 * instead. If it is not set, then each theme will be iterated over until both
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   470
 * the current stylesheet and current template name.
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   471
 *
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   472
 * @since 1.5.0
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   473
 *
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   474
 * @return string
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   475
 */
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   476
function get_current_theme() {
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   477
	if ( $theme = get_option('current_theme') )
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   478
		return $theme;
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   479
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   480
	$themes = get_themes();
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   481
	$theme_names = array_keys($themes);
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   482
	$current_template = get_option('template');
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   483
	$current_stylesheet = get_option('stylesheet');
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   484
	$current_theme = 'WordPress Default';
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   485
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   486
	if ( $themes ) {
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   487
		foreach ( (array) $theme_names as $theme_name ) {
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   488
			if ( $themes[$theme_name]['Stylesheet'] == $current_stylesheet &&
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   489
					$themes[$theme_name]['Template'] == $current_template ) {
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   490
				$current_theme = $themes[$theme_name]['Name'];
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   491
				break;
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   492
			}
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   493
		}
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   494
	}
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   495
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   496
	update_option('current_theme', $current_theme);
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   497
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   498
	return $current_theme;
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   499
}
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   500
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   501
/**
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   502
 * Retrieve path to themes directory.
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   503
 *
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   504
 * Does not have trailing slash.
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   505
 *
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   506
 * @since 1.5.0
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   507
 * @uses apply_filters() Calls 'theme_root' filter on path.
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   508
 *
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   509
 * @return string Theme path.
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   510
 */
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   511
function get_theme_root() {
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   512
	return apply_filters('theme_root', WP_CONTENT_DIR . "/themes");
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   513
}
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   514
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   515
/**
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   516
 * Retrieve URI for themes directory.
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   517
 *
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   518
 * Does not have trailing slash.
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   519
 *
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   520
 * @since 1.5.0
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   521
 *
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   522
 * @return string Themes URI.
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   523
 */
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   524
function get_theme_root_uri() {
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   525
	return apply_filters('theme_root_uri', content_url('themes'), get_option('siteurl'));
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   526
}
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   527
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   528
/**
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   529
 * Retrieve path to file without the use of extension.
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   530
 *
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   531
 * Used to quickly retrieve the path of file without including the file
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   532
 * extension. It will also check the parent template, if the file exists, with
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   533
 * the use of {@link locate_template()}. Allows for more generic file location
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   534
 * without the use of the other get_*_template() functions.
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   535
 *
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   536
 * Can be used with include() or require() to retrieve path.
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   537
 * <code>
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   538
 * if( '' != get_query_template( '404' ) )
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   539
 *     include( get_query_template( '404' ) );
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   540
 * </code>
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   541
 * or the same can be accomplished with
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   542
 * <code>
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   543
 * if( '' != get_404_template() )
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   544
 *     include( get_404_template() );
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   545
 * </code>
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   546
 *
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   547
 * @since 1.5.0
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   548
 *
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   549
 * @param string $type Filename without extension.
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   550
 * @return string Full path to file.
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   551
 */
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   552
function get_query_template($type) {
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   553
	$type = preg_replace( '|[^a-z0-9-]+|', '', $type );
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   554
	return apply_filters("{$type}_template", locate_template(array("{$type}.php")));
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   555
}
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   556
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   557
/**
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   558
 * Retrieve path of 404 template in current or parent template.
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   559
 *
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   560
 * @since 1.5.0
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   561
 *
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   562
 * @return string
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   563
 */
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   564
function get_404_template() {
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   565
	return get_query_template('404');
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   566
}
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   567
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   568
/**
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   569
 * Retrieve path of archive template in current or parent template.
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   570
 *
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   571
 * @since 1.5.0
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   572
 *
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   573
 * @return string
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   574
 */
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   575
function get_archive_template() {
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   576
	return get_query_template('archive');
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   577
}
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   578
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   579
/**
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   580
 * Retrieve path of author template in current or parent template.
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   581
 *
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   582
 * @since 1.5.0
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   583
 *
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   584
 * @return string
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   585
 */
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   586
function get_author_template() {
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   587
	return get_query_template('author');
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   588
}
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   589
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   590
/**
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   591
 * Retrieve path of category template in current or parent template.
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   592
 *
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   593
 * Works by retrieving the current category ID, for example 'category-1.php' and
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   594
 * will fallback to category.php template, if the ID category file doesn't
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   595
 * exist.
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   596
 *
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   597
 * @since 1.5.0
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   598
 * @uses apply_filters() Calls 'category_template' on file path of category template.
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   599
 *
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   600
 * @return string
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   601
 */
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   602
function get_category_template() {
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   603
	$template = locate_template(array("category-" . absint( get_query_var('cat') ) . '.php', 'category.php'));
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   604
	return apply_filters('category_template', $template);
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   605
}
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   606
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   607
/**
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   608
 * Retrieve path of tag template in current or parent template.
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   609
 *
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   610
 * Works by retrieving the current tag name, for example 'tag-wordpress.php' and will
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   611
 * fallback to tag.php template, if the name tag file doesn't exist.
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   612
 *
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   613
 * @since 2.3.0
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   614
 * @uses apply_filters() Calls 'tag_template' on file path of tag template.
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   615
 *
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   616
 * @return string
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   617
 */
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   618
function get_tag_template() {
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   619
	$template = locate_template(array("tag-" . get_query_var('tag') . '.php', 'tag.php'));
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   620
	return apply_filters('tag_template', $template);
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   621
}
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   622
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   623
/**
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   624
 * Retrieve path of taxonomy template in current or parent template.
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   625
 *
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   626
 * Retrieves the taxonomy and term, if term is available. The template is
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   627
 * prepended with 'taxonomy-' and followed by both the taxonomy string and
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   628
 * the taxonomy string followed by a dash and then followed by the term.
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   629
 *
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   630
 * The taxonomy and term template is checked and used first, if it exists.
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   631
 * Second, just the taxonomy template is checked, and then finally, taxonomy.php
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   632
 * template is used. If none of the files exist, then it will fall back on to
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   633
 * index.php.
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   634
 *
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   635
 * @since unknown (2.6.0 most likely)
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   636
 * @uses apply_filters() Calls 'taxonomy_template' filter on found path.
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   637
 *
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   638
 * @return string
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   639
 */
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   640
function get_taxonomy_template() {
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   641
	$taxonomy = get_query_var('taxonomy');
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   642
	$term = get_query_var('term');
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   643
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   644
	$templates = array();
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   645
	if ( $taxonomy && $term )
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   646
		$templates[] = "taxonomy-$taxonomy-$term.php";
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   647
	if ( $taxonomy )
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   648
		$templates[] = "taxonomy-$taxonomy.php";
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   649
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   650
	$templates[] = "taxonomy.php";
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   651
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   652
	$template = locate_template($templates);
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   653
	return apply_filters('taxonomy_template', $template);
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   654
}
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   655
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   656
/**
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   657
 * Retrieve path of date template in current or parent template.
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   658
 *
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   659
 * @since 1.5.0
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   660
 *
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   661
 * @return string
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   662
 */
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   663
function get_date_template() {
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   664
	return get_query_template('date');
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   665
}
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   666
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   667
/**
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   668
 * Retrieve path of home template in current or parent template.
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   669
 *
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   670
 * Attempts to locate 'home.php' first before falling back to 'index.php'.
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   671
 *
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   672
 * @since 1.5.0
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   673
 * @uses apply_filters() Calls 'home_template' on file path of home template.
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   674
 *
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   675
 * @return string
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   676
 */
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   677
function get_home_template() {
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   678
	$template = locate_template(array('home.php', 'index.php'));
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   679
	return apply_filters('home_template', $template);
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   680
}
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   681
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   682
/**
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   683
 * Retrieve path of page template in current or parent template.
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   684
 *
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   685
 * First attempt is to look for the file in the '_wp_page_template' page meta
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   686
 * data. The second attempt, if the first has a file and is not empty, is to
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   687
 * look for 'page.php'.
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   688
 *
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   689
 * @since 1.5.0
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   690
 *
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   691
 * @return string
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   692
 */
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   693
function get_page_template() {
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   694
	global $wp_query;
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   695
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   696
	$id = (int) $wp_query->post->ID;
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   697
	$template = get_post_meta($id, '_wp_page_template', true);
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   698
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   699
	if ( 'default' == $template )
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   700
		$template = '';
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   701
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   702
	$templates = array();
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   703
	if ( !empty($template) && !validate_file($template) )
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   704
		$templates[] = $template;
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   705
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   706
	$templates[] = "page.php";
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   707
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   708
	return apply_filters('page_template', locate_template($templates));
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   709
}
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   710
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   711
/**
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   712
 * Retrieve path of paged template in current or parent template.
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   713
 *
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   714
 * @since 1.5.0
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   715
 *
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   716
 * @return string
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   717
 */
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   718
function get_paged_template() {
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   719
	return get_query_template('paged');
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   720
}
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   721
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   722
/**
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   723
 * Retrieve path of search template in current or parent template.
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   724
 *
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   725
 * @since 1.5.0
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   726
 *
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   727
 * @return string
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   728
 */
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   729
function get_search_template() {
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   730
	return get_query_template('search');
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   731
}
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   732
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   733
/**
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   734
 * Retrieve path of single template in current or parent template.
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   735
 *
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   736
 * @since 1.5.0
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   737
 *
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   738
 * @return string
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   739
 */
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   740
function get_single_template() {
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   741
	return get_query_template('single');
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   742
}
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   743
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   744
/**
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   745
 * Retrieve path of attachment template in current or parent template.
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   746
 *
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   747
 * The attachment path first checks if the first part of the mime type exists.
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   748
 * The second check is for the second part of the mime type. The last check is
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   749
 * for both types separated by an underscore. If neither are found then the file
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   750
 * 'attachment.php' is checked and returned.
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   751
 *
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   752
 * Some examples for the 'text/plain' mime type are 'text.php', 'plain.php', and
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   753
 * finally 'text_plain.php'.
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   754
 *
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   755
 * @since 2.0.0
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   756
 *
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   757
 * @return string
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   758
 */
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   759
function get_attachment_template() {
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   760
	global $posts;
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   761
	$type = explode('/', $posts[0]->post_mime_type);
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   762
	if ( $template = get_query_template($type[0]) )
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   763
		return $template;
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   764
	elseif ( $template = get_query_template($type[1]) )
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   765
		return $template;
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   766
	elseif ( $template = get_query_template("$type[0]_$type[1]") )
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   767
		return $template;
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   768
	else
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   769
		return get_query_template('attachment');
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   770
}
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   771
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   772
/**
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   773
 * Retrieve path of comment popup template in current or parent template.
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   774
 *
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   775
 * Checks for comment popup template in current template, if it exists or in the
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   776
 * parent template. If it doesn't exist, then it retrieves the comment-popup.php
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   777
 * file from the default theme. The default theme must then exist for it to
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   778
 * work.
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   779
 *
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   780
 * @since 1.5.0
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   781
 * @uses apply_filters() Calls 'comments_popup_template' filter on path.
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   782
 *
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   783
 * @return string
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   784
 */
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   785
function get_comments_popup_template() {
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   786
	$template = locate_template(array("comments-popup.php"));
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   787
	if ('' == $template)
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   788
		$template = get_theme_root() . '/default/comments-popup.php';
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   789
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   790
	return apply_filters('comments_popup_template', $template);
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   791
}
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   792
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   793
/**
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   794
 * Retrieve the name of the highest priority template file that exists.
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   795
 *
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   796
 * Searches in the STYLESHEETPATH before TEMPLATEPATH so that themes which
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   797
 * inherit from a parent theme can just overload one file.
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   798
 *
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   799
 * @since 2.7.0
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   800
 *
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   801
 * @param array $template_names Array of template files to search for in priority order.
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   802
 * @param bool $load If true the template file will be loaded if it is found.
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   803
 * @return string The template filename if one is located.
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   804
 */
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   805
function locate_template($template_names, $load = false) {
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   806
	if (!is_array($template_names))
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   807
		return '';
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   808
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   809
	$located = '';
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   810
	foreach($template_names as $template_name) {
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   811
		if ( file_exists(STYLESHEETPATH . '/' . $template_name)) {
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   812
			$located = STYLESHEETPATH . '/' . $template_name;
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   813
			break;
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   814
		} else if ( file_exists(TEMPLATEPATH . '/' . $template_name) ) {
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   815
			$located = TEMPLATEPATH . '/' . $template_name;
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   816
			break;
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   817
		}
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   818
	}
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   819
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   820
	if ($load && '' != $located)
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   821
		load_template($located);
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   822
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   823
	return $located;
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   824
}
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   825
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   826
/**
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   827
 * Require once the template file with WordPress environment.
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   828
 *
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   829
 * The globals are set up for the template file to ensure that the WordPress
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   830
 * environment is available from within the function. The query variables are
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   831
 * also available.
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   832
 *
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   833
 * @since 1.5.0
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   834
 *
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   835
 * @param string $_template_file Path to template file.
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   836
 */
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   837
function load_template($_template_file) {
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   838
	global $posts, $post, $wp_did_header, $wp_did_template_redirect, $wp_query, $wp_rewrite, $wpdb, $wp_version, $wp, $id, $comment, $user_ID;
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   839
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   840
	if ( is_array($wp_query->query_vars) )
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   841
		extract($wp_query->query_vars, EXTR_SKIP);
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   842
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   843
	require_once($_template_file);
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   844
}
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   845
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   846
/**
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   847
 * Display localized stylesheet link element.
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   848
 *
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   849
 * @since 2.1.0
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   850
 */
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   851
function locale_stylesheet() {
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   852
	$stylesheet = get_locale_stylesheet_uri();
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   853
	if ( empty($stylesheet) )
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   854
		return;
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   855
	echo '<link rel="stylesheet" href="' . $stylesheet . '" type="text/css" media="screen" />';
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   856
}
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   857
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   858
/**
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   859
 * Start preview theme output buffer.
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   860
 *
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   861
 * Will only preform task if the user has permissions and template and preview
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   862
 * query variables exist.
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   863
 *
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   864
 * @since 2.5.0
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   865
 */
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   866
function preview_theme() {
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   867
	if ( ! (isset($_GET['template']) && isset($_GET['preview'])) )
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   868
		return;
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   869
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   870
	if ( !current_user_can( 'switch_themes' ) )
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   871
		return;
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   872
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   873
	$_GET['template'] = preg_replace('|[^a-z0-9_./-]|i', '', $_GET['template']);
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   874
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   875
	if ( validate_file($_GET['template']) )
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   876
		return;
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   877
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   878
	add_filter( 'template', '_preview_theme_template_filter' );
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   879
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   880
	if ( isset($_GET['stylesheet']) ) {
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   881
		$_GET['stylesheet'] = preg_replace('|[^a-z0-9_./-]|i', '', $_GET['stylesheet']);
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   882
		if ( validate_file($_GET['stylesheet']) )
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   883
			return;
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   884
		add_filter( 'stylesheet', '_preview_theme_stylesheet_filter' );
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   885
	}
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   886
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   887
	// Prevent theme mods to current theme being used on theme being previewed
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   888
	add_filter( 'pre_option_mods_' . get_current_theme(), create_function( '', "return array();" ) );
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   889
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   890
	ob_start( 'preview_theme_ob_filter' );
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   891
}
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   892
add_action('setup_theme', 'preview_theme');
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   893
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   894
/**
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   895
 * Private function to modify the current template when previewing a theme
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   896
 * 
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   897
 * @return string
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   898
 */
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   899
function _preview_theme_template_filter() {
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   900
	return isset($_GET['template']) ? $_GET['template'] : '';
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   901
}
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   902
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   903
/**
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   904
 * Private function to modify the current stylesheet when previewing a theme
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   905
 * 
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   906
 * @return string
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   907
 */
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   908
function _preview_theme_stylesheet_filter() {
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   909
	return isset($_GET['stylesheet']) ? $_GET['stylesheet'] : '';
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   910
}
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   911
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   912
/**
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   913
 * Callback function for ob_start() to capture all links in the theme.
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   914
 *
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   915
 * @since unknown
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   916
 * @access private
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   917
 *
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   918
 * @param string $content
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   919
 * @return string
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   920
 */
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   921
function preview_theme_ob_filter( $content ) {
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   922
	return preg_replace_callback( "|(<a.*?href=([\"']))(.*?)([\"'].*?>)|", 'preview_theme_ob_filter_callback', $content );
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   923
}
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   924
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   925
/**
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   926
 * Manipulates preview theme links in order to control and maintain location.
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   927
 *
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   928
 * Callback function for preg_replace_callback() to accept and filter matches.
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   929
 *
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   930
 * @since unknown
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   931
 * @access private
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   932
 *
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   933
 * @param array $matches
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   934
 * @return string
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   935
 */
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   936
function preview_theme_ob_filter_callback( $matches ) {
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   937
	if ( strpos($matches[4], 'onclick') !== false )
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   938
		$matches[4] = preg_replace('#onclick=([\'"]).*?(?<!\\\)\\1#i', '', $matches[4]); //Strip out any onclicks from rest of <a>. (?<!\\\) means to ignore the '" if its escaped by \  to prevent breaking mid-attribute.
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   939
	if (
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   940
		( false !== strpos($matches[3], '/wp-admin/') )
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   941
	||
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   942
		( false !== strpos($matches[3], '://') && 0 !== strpos($matches[3], get_option('home')) )
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   943
	||
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   944
		( false !== strpos($matches[3], '/feed/') )
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   945
	||
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   946
		( false !== strpos($matches[3], '/trackback/') )
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   947
	)
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   948
		return $matches[1] . "#$matches[2] onclick=$matches[2]return false;" . $matches[4];
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   949
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   950
	$link = add_query_arg( array('preview' => 1, 'template' => $_GET['template'], 'stylesheet' => @$_GET['stylesheet'] ), $matches[3] );
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   951
	if ( 0 === strpos($link, 'preview=1') )
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   952
		$link = "?$link";
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   953
	return $matches[1] . esc_attr( $link ) . $matches[4];
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   954
}
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   955
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   956
/**
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   957
 * Switches current theme to new template and stylesheet names.
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   958
 *
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   959
 * @since unknown
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   960
 * @uses do_action() Calls 'switch_theme' action on updated theme display name.
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   961
 *
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   962
 * @param string $template Template name
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   963
 * @param string $stylesheet Stylesheet name.
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   964
 */
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   965
function switch_theme($template, $stylesheet) {
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   966
	update_option('template', $template);
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   967
	update_option('stylesheet', $stylesheet);
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   968
	delete_option('current_theme');
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   969
	$theme = get_current_theme();
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   970
	do_action('switch_theme', $theme);
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   971
}
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   972
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   973
/**
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   974
 * Checks that current theme files 'index.php' and 'style.css' exists.
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   975
 *
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   976
 * Does not check the 'default' theme. The 'default' theme should always exist
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   977
 * or should have another theme renamed to that template name and directory
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   978
 * path. Will switch theme to default if current theme does not validate.
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   979
 * You can use the 'validate_current_theme' filter to return FALSE to
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   980
 * disable this functionality.
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   981
 *
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   982
 * @since 1.5.0
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   983
 *
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   984
 * @return bool
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   985
 */
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   986
function validate_current_theme() {
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   987
	// Don't validate during an install/upgrade.
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   988
	if ( defined('WP_INSTALLING') || !apply_filters( 'validate_current_theme', true ) )
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   989
		return true;
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   990
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   991
	if ( get_template() != 'default' && !file_exists(get_template_directory() . '/index.php') ) {
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   992
		switch_theme('default', 'default');
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   993
		return false;
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   994
	}
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   995
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   996
	if ( get_stylesheet() != 'default' && !file_exists(get_template_directory() . '/style.css') ) {
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   997
		switch_theme('default', 'default');
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   998
		return false;
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   999
	}
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1000
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1001
	return true;
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1002
}
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1003
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1004
/**
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1005
 * Retrieve theme modification value for the current theme.
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1006
 *
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1007
 * If the modification name does not exist, then the $default will be passed
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1008
 * through {@link http://php.net/sprintf sprintf()} PHP function with the first
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1009
 * string the template directory URI and the second string the stylesheet
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1010
 * directory URI.
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1011
 *
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1012
 * @since 2.1.0
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1013
 * @uses apply_filters() Calls 'theme_mod_$name' filter on the value.
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1014
 *
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1015
 * @param string $name Theme modification name.
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1016
 * @param bool|string $default
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1017
 * @return string
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1018
 */
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1019
function get_theme_mod($name, $default = false) {
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1020
	$theme = get_current_theme();
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1021
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1022
	$mods = get_option("mods_$theme");
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1023
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1024
	if ( isset($mods[$name]) )
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1025
		return apply_filters( "theme_mod_$name", $mods[$name] );
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1026
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1027
	return apply_filters( "theme_mod_$name", sprintf($default, get_template_directory_uri(), get_stylesheet_directory_uri()) );
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1028
}
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1029
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1030
/**
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1031
 * Update theme modification value for the current theme.
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1032
 *
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1033
 * @since 2.1.0
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1034
 *
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1035
 * @param string $name Theme modification name.
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1036
 * @param string $value theme modification value.
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1037
 */
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1038
function set_theme_mod($name, $value) {
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1039
	$theme = get_current_theme();
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1040
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1041
	$mods = get_option("mods_$theme");
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1042
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1043
	$mods[$name] = $value;
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1044
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1045
	update_option("mods_$theme", $mods);
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1046
	wp_cache_delete("mods_$theme", 'options');
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1047
}
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1048
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1049
/**
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1050
 * Remove theme modification name from current theme list.
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1051
 *
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1052
 * If removing the name also removes all elements, then the entire option will
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1053
 * be removed.
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1054
 *
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1055
 * @since 2.1.0
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1056
 *
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1057
 * @param string $name Theme modification name.
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1058
 * @return null
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1059
 */
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1060
function remove_theme_mod( $name ) {
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1061
	$theme = get_current_theme();
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1062
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1063
	$mods = get_option("mods_$theme");
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1064
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1065
	if ( !isset($mods[$name]) )
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1066
		return;
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1067
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1068
	unset($mods[$name]);
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1069
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1070
	if ( empty($mods) )
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1071
		return remove_theme_mods();
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1072
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1073
	update_option("mods_$theme", $mods);
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1074
	wp_cache_delete("mods_$theme", 'options');
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1075
}
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1076
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1077
/**
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1078
 * Remove theme modifications option for current theme.
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1079
 *
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1080
 * @since 2.1.0
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1081
 */
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1082
function remove_theme_mods() {
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1083
	$theme = get_current_theme();
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1084
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1085
	delete_option("mods_$theme");
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1086
}
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1087
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1088
/**
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1089
 * Retrieve text color for custom header.
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1090
 *
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1091
 * @since 2.1.0
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1092
 * @uses HEADER_TEXTCOLOR
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1093
 *
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1094
 * @return string
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1095
 */
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1096
function get_header_textcolor() {
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1097
	return get_theme_mod('header_textcolor', HEADER_TEXTCOLOR);
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1098
}
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1099
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1100
/**
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1101
 * Display text color for custom header.
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1102
 *
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1103
 * @since 2.1.0
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1104
 */
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1105
function header_textcolor() {
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1106
	echo get_header_textcolor();
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1107
}
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1108
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1109
/**
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1110
 * Retrieve header image for custom header.
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1111
 *
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1112
 * @since 2.1.0
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1113
 * @uses HEADER_IMAGE
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1114
 *
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1115
 * @return string
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1116
 */
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1117
function get_header_image() {
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1118
	return get_theme_mod('header_image', HEADER_IMAGE);
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1119
}
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1120
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1121
/**
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1122
 * Display header image path.
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1123
 *
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1124
 * @since 2.1.0
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1125
 */
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1126
function header_image() {
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1127
	echo get_header_image();
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1128
}
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1129
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1130
/**
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1131
 * Add callbacks for image header display.
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1132
 *
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1133
 * The parameter $header_callback callback will be required to display the
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1134
 * content for the 'wp_head' action. The parameter $admin_header_callback
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1135
 * callback will be added to Custom_Image_Header class and that will be added
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1136
 * to the 'admin_menu' action.
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1137
 *
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1138
 * @since 2.1.0
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1139
 * @uses Custom_Image_Header Sets up for $admin_header_callback for administration panel display.
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1140
 *
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1141
 * @param callback $header_callback Call on 'wp_head' action.
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1142
 * @param callback $admin_header_callback Call on administration panels.
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1143
 */
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1144
function add_custom_image_header($header_callback, $admin_header_callback) {
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1145
	if ( ! empty($header_callback) )
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1146
		add_action('wp_head', $header_callback);
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1147
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1148
	if ( ! is_admin() )
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1149
		return;
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1150
	require_once(ABSPATH . 'wp-admin/custom-header.php');
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1151
	$GLOBALS['custom_image_header'] =& new Custom_Image_Header($admin_header_callback);
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1152
	add_action('admin_menu', array(&$GLOBALS['custom_image_header'], 'init'));
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1153
}
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1154
03b0d1493584 wordpress 2.8 ()
hurons@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1155
?>