Edit File by line
/home/barbar84/public_h.../wp-inclu...
File: theme.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* Theme, template, and stylesheet functions.
[2] Fix | Delete
*
[3] Fix | Delete
* @package WordPress
[4] Fix | Delete
* @subpackage Theme
[5] Fix | Delete
*/
[6] Fix | Delete
[7] Fix | Delete
/**
[8] Fix | Delete
* Returns an array of WP_Theme objects based on the arguments.
[9] Fix | Delete
*
[10] Fix | Delete
* Despite advances over get_themes(), this function is quite expensive, and grows
[11] Fix | Delete
* linearly with additional themes. Stick to wp_get_theme() if possible.
[12] Fix | Delete
*
[13] Fix | Delete
* @since 3.4.0
[14] Fix | Delete
*
[15] Fix | Delete
* @global array $wp_theme_directories
[16] Fix | Delete
*
[17] Fix | Delete
* @param array $args {
[18] Fix | Delete
* Optional. The search arguments.
[19] Fix | Delete
*
[20] Fix | Delete
* @type mixed $errors True to return themes with errors, false to return
[21] Fix | Delete
* themes without errors, null to return all themes.
[22] Fix | Delete
* Default false.
[23] Fix | Delete
* @type mixed $allowed (Multisite) True to return only allowed themes for a site.
[24] Fix | Delete
* False to return only disallowed themes for a site.
[25] Fix | Delete
* 'site' to return only site-allowed themes.
[26] Fix | Delete
* 'network' to return only network-allowed themes.
[27] Fix | Delete
* Null to return all themes. Default null.
[28] Fix | Delete
* @type int $blog_id (Multisite) The blog ID used to calculate which themes
[29] Fix | Delete
* are allowed. Default 0, synonymous for the current blog.
[30] Fix | Delete
* }
[31] Fix | Delete
* @return WP_Theme[] Array of WP_Theme objects.
[32] Fix | Delete
*/
[33] Fix | Delete
function wp_get_themes( $args = array() ) {
[34] Fix | Delete
global $wp_theme_directories;
[35] Fix | Delete
[36] Fix | Delete
$defaults = array(
[37] Fix | Delete
'errors' => false,
[38] Fix | Delete
'allowed' => null,
[39] Fix | Delete
'blog_id' => 0,
[40] Fix | Delete
);
[41] Fix | Delete
$args = wp_parse_args( $args, $defaults );
[42] Fix | Delete
[43] Fix | Delete
$theme_directories = search_theme_directories();
[44] Fix | Delete
[45] Fix | Delete
if ( is_array( $wp_theme_directories ) && count( $wp_theme_directories ) > 1 ) {
[46] Fix | Delete
// Make sure the current theme wins out, in case search_theme_directories() picks the wrong
[47] Fix | Delete
// one in the case of a conflict. (Normally, last registered theme root wins.)
[48] Fix | Delete
$current_theme = get_stylesheet();
[49] Fix | Delete
if ( isset( $theme_directories[ $current_theme ] ) ) {
[50] Fix | Delete
$root_of_current_theme = get_raw_theme_root( $current_theme );
[51] Fix | Delete
if ( ! in_array( $root_of_current_theme, $wp_theme_directories, true ) ) {
[52] Fix | Delete
$root_of_current_theme = WP_CONTENT_DIR . $root_of_current_theme;
[53] Fix | Delete
}
[54] Fix | Delete
$theme_directories[ $current_theme ]['theme_root'] = $root_of_current_theme;
[55] Fix | Delete
}
[56] Fix | Delete
}
[57] Fix | Delete
[58] Fix | Delete
if ( empty( $theme_directories ) ) {
[59] Fix | Delete
return array();
[60] Fix | Delete
}
[61] Fix | Delete
[62] Fix | Delete
if ( is_multisite() && null !== $args['allowed'] ) {
[63] Fix | Delete
$allowed = $args['allowed'];
[64] Fix | Delete
if ( 'network' === $allowed ) {
[65] Fix | Delete
$theme_directories = array_intersect_key( $theme_directories, WP_Theme::get_allowed_on_network() );
[66] Fix | Delete
} elseif ( 'site' === $allowed ) {
[67] Fix | Delete
$theme_directories = array_intersect_key( $theme_directories, WP_Theme::get_allowed_on_site( $args['blog_id'] ) );
[68] Fix | Delete
} elseif ( $allowed ) {
[69] Fix | Delete
$theme_directories = array_intersect_key( $theme_directories, WP_Theme::get_allowed( $args['blog_id'] ) );
[70] Fix | Delete
} else {
[71] Fix | Delete
$theme_directories = array_diff_key( $theme_directories, WP_Theme::get_allowed( $args['blog_id'] ) );
[72] Fix | Delete
}
[73] Fix | Delete
}
[74] Fix | Delete
[75] Fix | Delete
$themes = array();
[76] Fix | Delete
static $_themes = array();
[77] Fix | Delete
[78] Fix | Delete
foreach ( $theme_directories as $theme => $theme_root ) {
[79] Fix | Delete
if ( isset( $_themes[ $theme_root['theme_root'] . '/' . $theme ] ) ) {
[80] Fix | Delete
$themes[ $theme ] = $_themes[ $theme_root['theme_root'] . '/' . $theme ];
[81] Fix | Delete
} else {
[82] Fix | Delete
$themes[ $theme ] = new WP_Theme( $theme, $theme_root['theme_root'] );
[83] Fix | Delete
[84] Fix | Delete
$_themes[ $theme_root['theme_root'] . '/' . $theme ] = $themes[ $theme ];
[85] Fix | Delete
}
[86] Fix | Delete
}
[87] Fix | Delete
[88] Fix | Delete
if ( null !== $args['errors'] ) {
[89] Fix | Delete
foreach ( $themes as $theme => $wp_theme ) {
[90] Fix | Delete
if ( $wp_theme->errors() != $args['errors'] ) {
[91] Fix | Delete
unset( $themes[ $theme ] );
[92] Fix | Delete
}
[93] Fix | Delete
}
[94] Fix | Delete
}
[95] Fix | Delete
[96] Fix | Delete
return $themes;
[97] Fix | Delete
}
[98] Fix | Delete
[99] Fix | Delete
/**
[100] Fix | Delete
* Gets a WP_Theme object for a theme.
[101] Fix | Delete
*
[102] Fix | Delete
* @since 3.4.0
[103] Fix | Delete
*
[104] Fix | Delete
* @global array $wp_theme_directories
[105] Fix | Delete
*
[106] Fix | Delete
* @param string $stylesheet Optional. Directory name for the theme. Defaults to current theme.
[107] Fix | Delete
* @param string $theme_root Optional. Absolute path of the theme root to look in.
[108] Fix | Delete
* If not specified, get_raw_theme_root() is used to calculate
[109] Fix | Delete
* the theme root for the $stylesheet provided (or current theme).
[110] Fix | Delete
* @return WP_Theme Theme object. Be sure to check the object's exists() method
[111] Fix | Delete
* if you need to confirm the theme's existence.
[112] Fix | Delete
*/
[113] Fix | Delete
function wp_get_theme( $stylesheet = '', $theme_root = '' ) {
[114] Fix | Delete
global $wp_theme_directories;
[115] Fix | Delete
[116] Fix | Delete
if ( empty( $stylesheet ) ) {
[117] Fix | Delete
$stylesheet = get_stylesheet();
[118] Fix | Delete
}
[119] Fix | Delete
[120] Fix | Delete
if ( empty( $theme_root ) ) {
[121] Fix | Delete
$theme_root = get_raw_theme_root( $stylesheet );
[122] Fix | Delete
if ( false === $theme_root ) {
[123] Fix | Delete
$theme_root = WP_CONTENT_DIR . '/themes';
[124] Fix | Delete
} elseif ( ! in_array( $theme_root, (array) $wp_theme_directories, true ) ) {
[125] Fix | Delete
$theme_root = WP_CONTENT_DIR . $theme_root;
[126] Fix | Delete
}
[127] Fix | Delete
}
[128] Fix | Delete
[129] Fix | Delete
return new WP_Theme( $stylesheet, $theme_root );
[130] Fix | Delete
}
[131] Fix | Delete
[132] Fix | Delete
/**
[133] Fix | Delete
* Clears the cache held by get_theme_roots() and WP_Theme.
[134] Fix | Delete
*
[135] Fix | Delete
* @since 3.5.0
[136] Fix | Delete
* @param bool $clear_update_cache Whether to clear the theme updates cache.
[137] Fix | Delete
*/
[138] Fix | Delete
function wp_clean_themes_cache( $clear_update_cache = true ) {
[139] Fix | Delete
if ( $clear_update_cache ) {
[140] Fix | Delete
delete_site_transient( 'update_themes' );
[141] Fix | Delete
}
[142] Fix | Delete
search_theme_directories( true );
[143] Fix | Delete
foreach ( wp_get_themes( array( 'errors' => null ) ) as $theme ) {
[144] Fix | Delete
$theme->cache_delete();
[145] Fix | Delete
}
[146] Fix | Delete
}
[147] Fix | Delete
[148] Fix | Delete
/**
[149] Fix | Delete
* Whether a child theme is in use.
[150] Fix | Delete
*
[151] Fix | Delete
* @since 3.0.0
[152] Fix | Delete
*
[153] Fix | Delete
* @return bool True if a child theme is in use, false otherwise.
[154] Fix | Delete
*/
[155] Fix | Delete
function is_child_theme() {
[156] Fix | Delete
return ( TEMPLATEPATH !== STYLESHEETPATH );
[157] Fix | Delete
}
[158] Fix | Delete
[159] Fix | Delete
/**
[160] Fix | Delete
* Retrieves name of the current stylesheet.
[161] Fix | Delete
*
[162] Fix | Delete
* The theme name that is currently set as the front end theme.
[163] Fix | Delete
*
[164] Fix | Delete
* For all intents and purposes, the template name and the stylesheet name
[165] Fix | Delete
* are going to be the same for most cases.
[166] Fix | Delete
*
[167] Fix | Delete
* @since 1.5.0
[168] Fix | Delete
*
[169] Fix | Delete
* @return string Stylesheet name.
[170] Fix | Delete
*/
[171] Fix | Delete
function get_stylesheet() {
[172] Fix | Delete
/**
[173] Fix | Delete
* Filters the name of current stylesheet.
[174] Fix | Delete
*
[175] Fix | Delete
* @since 1.5.0
[176] Fix | Delete
*
[177] Fix | Delete
* @param string $stylesheet Name of the current stylesheet.
[178] Fix | Delete
*/
[179] Fix | Delete
return apply_filters( 'stylesheet', get_option( 'stylesheet' ) );
[180] Fix | Delete
}
[181] Fix | Delete
[182] Fix | Delete
/**
[183] Fix | Delete
* Retrieves stylesheet directory path for current theme.
[184] Fix | Delete
*
[185] Fix | Delete
* @since 1.5.0
[186] Fix | Delete
*
[187] Fix | Delete
* @return string Path to current theme's stylesheet directory.
[188] Fix | Delete
*/
[189] Fix | Delete
function get_stylesheet_directory() {
[190] Fix | Delete
$stylesheet = get_stylesheet();
[191] Fix | Delete
$theme_root = get_theme_root( $stylesheet );
[192] Fix | Delete
$stylesheet_dir = "$theme_root/$stylesheet";
[193] Fix | Delete
[194] Fix | Delete
/**
[195] Fix | Delete
* Filters the stylesheet directory path for current theme.
[196] Fix | Delete
*
[197] Fix | Delete
* @since 1.5.0
[198] Fix | Delete
*
[199] Fix | Delete
* @param string $stylesheet_dir Absolute path to the current theme.
[200] Fix | Delete
* @param string $stylesheet Directory name of the current theme.
[201] Fix | Delete
* @param string $theme_root Absolute path to themes directory.
[202] Fix | Delete
*/
[203] Fix | Delete
return apply_filters( 'stylesheet_directory', $stylesheet_dir, $stylesheet, $theme_root );
[204] Fix | Delete
}
[205] Fix | Delete
[206] Fix | Delete
/**
[207] Fix | Delete
* Retrieves stylesheet directory URI for current theme.
[208] Fix | Delete
*
[209] Fix | Delete
* @since 1.5.0
[210] Fix | Delete
*
[211] Fix | Delete
* @return string URI to current theme's stylesheet directory.
[212] Fix | Delete
*/
[213] Fix | Delete
function get_stylesheet_directory_uri() {
[214] Fix | Delete
$stylesheet = str_replace( '%2F', '/', rawurlencode( get_stylesheet() ) );
[215] Fix | Delete
$theme_root_uri = get_theme_root_uri( $stylesheet );
[216] Fix | Delete
$stylesheet_dir_uri = "$theme_root_uri/$stylesheet";
[217] Fix | Delete
[218] Fix | Delete
/**
[219] Fix | Delete
* Filters the stylesheet directory URI.
[220] Fix | Delete
*
[221] Fix | Delete
* @since 1.5.0
[222] Fix | Delete
*
[223] Fix | Delete
* @param string $stylesheet_dir_uri Stylesheet directory URI.
[224] Fix | Delete
* @param string $stylesheet Name of the activated theme's directory.
[225] Fix | Delete
* @param string $theme_root_uri Themes root URI.
[226] Fix | Delete
*/
[227] Fix | Delete
return apply_filters( 'stylesheet_directory_uri', $stylesheet_dir_uri, $stylesheet, $theme_root_uri );
[228] Fix | Delete
}
[229] Fix | Delete
[230] Fix | Delete
/**
[231] Fix | Delete
* Retrieves stylesheet URI for current theme.
[232] Fix | Delete
*
[233] Fix | Delete
* The stylesheet file name is 'style.css' which is appended to the stylesheet directory URI path.
[234] Fix | Delete
* See get_stylesheet_directory_uri().
[235] Fix | Delete
*
[236] Fix | Delete
* @since 1.5.0
[237] Fix | Delete
*
[238] Fix | Delete
* @return string URI to current theme's stylesheet.
[239] Fix | Delete
*/
[240] Fix | Delete
function get_stylesheet_uri() {
[241] Fix | Delete
$stylesheet_dir_uri = get_stylesheet_directory_uri();
[242] Fix | Delete
$stylesheet_uri = $stylesheet_dir_uri . '/style.css';
[243] Fix | Delete
/**
[244] Fix | Delete
* Filters the URI of the current theme stylesheet.
[245] Fix | Delete
*
[246] Fix | Delete
* @since 1.5.0
[247] Fix | Delete
*
[248] Fix | Delete
* @param string $stylesheet_uri Stylesheet URI for the current theme/child theme.
[249] Fix | Delete
* @param string $stylesheet_dir_uri Stylesheet directory URI for the current theme/child theme.
[250] Fix | Delete
*/
[251] Fix | Delete
return apply_filters( 'stylesheet_uri', $stylesheet_uri, $stylesheet_dir_uri );
[252] Fix | Delete
}
[253] Fix | Delete
[254] Fix | Delete
/**
[255] Fix | Delete
* Retrieves the localized stylesheet URI.
[256] Fix | Delete
*
[257] Fix | Delete
* The stylesheet directory for the localized stylesheet files are located, by
[258] Fix | Delete
* default, in the base theme directory. The name of the locale file will be the
[259] Fix | Delete
* locale followed by '.css'. If that does not exist, then the text direction
[260] Fix | Delete
* stylesheet will be checked for existence, for example 'ltr.css'.
[261] Fix | Delete
*
[262] Fix | Delete
* The theme may change the location of the stylesheet directory by either using
[263] Fix | Delete
* the {@see 'stylesheet_directory_uri'} or {@see 'locale_stylesheet_uri'} filters.
[264] Fix | Delete
*
[265] Fix | Delete
* If you want to change the location of the stylesheet files for the entire
[266] Fix | Delete
* WordPress workflow, then change the former. If you just have the locale in a
[267] Fix | Delete
* separate folder, then change the latter.
[268] Fix | Delete
*
[269] Fix | Delete
* @since 2.1.0
[270] Fix | Delete
*
[271] Fix | Delete
* @global WP_Locale $wp_locale WordPress date and time locale object.
[272] Fix | Delete
*
[273] Fix | Delete
* @return string URI to current theme's localized stylesheet.
[274] Fix | Delete
*/
[275] Fix | Delete
function get_locale_stylesheet_uri() {
[276] Fix | Delete
global $wp_locale;
[277] Fix | Delete
$stylesheet_dir_uri = get_stylesheet_directory_uri();
[278] Fix | Delete
$dir = get_stylesheet_directory();
[279] Fix | Delete
$locale = get_locale();
[280] Fix | Delete
if ( file_exists( "$dir/$locale.css" ) ) {
[281] Fix | Delete
$stylesheet_uri = "$stylesheet_dir_uri/$locale.css";
[282] Fix | Delete
} elseif ( ! empty( $wp_locale->text_direction ) && file_exists( "$dir/{$wp_locale->text_direction}.css" ) ) {
[283] Fix | Delete
$stylesheet_uri = "$stylesheet_dir_uri/{$wp_locale->text_direction}.css";
[284] Fix | Delete
} else {
[285] Fix | Delete
$stylesheet_uri = '';
[286] Fix | Delete
}
[287] Fix | Delete
/**
[288] Fix | Delete
* Filters the localized stylesheet URI.
[289] Fix | Delete
*
[290] Fix | Delete
* @since 2.1.0
[291] Fix | Delete
*
[292] Fix | Delete
* @param string $stylesheet_uri Localized stylesheet URI.
[293] Fix | Delete
* @param string $stylesheet_dir_uri Stylesheet directory URI.
[294] Fix | Delete
*/
[295] Fix | Delete
return apply_filters( 'locale_stylesheet_uri', $stylesheet_uri, $stylesheet_dir_uri );
[296] Fix | Delete
}
[297] Fix | Delete
[298] Fix | Delete
/**
[299] Fix | Delete
* Retrieves name of the current theme.
[300] Fix | Delete
*
[301] Fix | Delete
* @since 1.5.0
[302] Fix | Delete
*
[303] Fix | Delete
* @return string Template name.
[304] Fix | Delete
*/
[305] Fix | Delete
function get_template() {
[306] Fix | Delete
/**
[307] Fix | Delete
* Filters the name of the current theme.
[308] Fix | Delete
*
[309] Fix | Delete
* @since 1.5.0
[310] Fix | Delete
*
[311] Fix | Delete
* @param string $template Current theme's directory name.
[312] Fix | Delete
*/
[313] Fix | Delete
return apply_filters( 'template', get_option( 'template' ) );
[314] Fix | Delete
}
[315] Fix | Delete
[316] Fix | Delete
/**
[317] Fix | Delete
* Retrieves template directory path for current theme.
[318] Fix | Delete
*
[319] Fix | Delete
* @since 1.5.0
[320] Fix | Delete
*
[321] Fix | Delete
* @return string Path to current theme's template directory.
[322] Fix | Delete
*/
[323] Fix | Delete
function get_template_directory() {
[324] Fix | Delete
$template = get_template();
[325] Fix | Delete
$theme_root = get_theme_root( $template );
[326] Fix | Delete
$template_dir = "$theme_root/$template";
[327] Fix | Delete
[328] Fix | Delete
/**
[329] Fix | Delete
* Filters the current theme directory path.
[330] Fix | Delete
*
[331] Fix | Delete
* @since 1.5.0
[332] Fix | Delete
*
[333] Fix | Delete
* @param string $template_dir The path of the current theme directory.
[334] Fix | Delete
* @param string $template Directory name of the current theme.
[335] Fix | Delete
* @param string $theme_root Absolute path to the themes directory.
[336] Fix | Delete
*/
[337] Fix | Delete
return apply_filters( 'template_directory', $template_dir, $template, $theme_root );
[338] Fix | Delete
}
[339] Fix | Delete
[340] Fix | Delete
/**
[341] Fix | Delete
* Retrieves template directory URI for current theme.
[342] Fix | Delete
*
[343] Fix | Delete
* @since 1.5.0
[344] Fix | Delete
*
[345] Fix | Delete
* @return string URI to current theme's template directory.
[346] Fix | Delete
*/
[347] Fix | Delete
function get_template_directory_uri() {
[348] Fix | Delete
$template = str_replace( '%2F', '/', rawurlencode( get_template() ) );
[349] Fix | Delete
$theme_root_uri = get_theme_root_uri( $template );
[350] Fix | Delete
$template_dir_uri = "$theme_root_uri/$template";
[351] Fix | Delete
[352] Fix | Delete
/**
[353] Fix | Delete
* Filters the current theme directory URI.
[354] Fix | Delete
*
[355] Fix | Delete
* @since 1.5.0
[356] Fix | Delete
*
[357] Fix | Delete
* @param string $template_dir_uri The URI of the current theme directory.
[358] Fix | Delete
* @param string $template Directory name of the current theme.
[359] Fix | Delete
* @param string $theme_root_uri The themes root URI.
[360] Fix | Delete
*/
[361] Fix | Delete
return apply_filters( 'template_directory_uri', $template_dir_uri, $template, $theme_root_uri );
[362] Fix | Delete
}
[363] Fix | Delete
[364] Fix | Delete
/**
[365] Fix | Delete
* Retrieves theme roots.
[366] Fix | Delete
*
[367] Fix | Delete
* @since 2.9.0
[368] Fix | Delete
*
[369] Fix | Delete
* @global array $wp_theme_directories
[370] Fix | Delete
*
[371] Fix | Delete
* @return array|string An array of theme roots keyed by template/stylesheet
[372] Fix | Delete
* or a single theme root if all themes have the same root.
[373] Fix | Delete
*/
[374] Fix | Delete
function get_theme_roots() {
[375] Fix | Delete
global $wp_theme_directories;
[376] Fix | Delete
[377] Fix | Delete
if ( ! is_array( $wp_theme_directories ) || count( $wp_theme_directories ) <= 1 ) {
[378] Fix | Delete
return '/themes';
[379] Fix | Delete
}
[380] Fix | Delete
[381] Fix | Delete
$theme_roots = get_site_transient( 'theme_roots' );
[382] Fix | Delete
if ( false === $theme_roots ) {
[383] Fix | Delete
search_theme_directories( true ); // Regenerate the transient.
[384] Fix | Delete
$theme_roots = get_site_transient( 'theme_roots' );
[385] Fix | Delete
}
[386] Fix | Delete
return $theme_roots;
[387] Fix | Delete
}
[388] Fix | Delete
[389] Fix | Delete
/**
[390] Fix | Delete
* Registers a directory that contains themes.
[391] Fix | Delete
*
[392] Fix | Delete
* @since 2.9.0
[393] Fix | Delete
*
[394] Fix | Delete
* @global array $wp_theme_directories
[395] Fix | Delete
*
[396] Fix | Delete
* @param string $directory Either the full filesystem path to a theme folder
[397] Fix | Delete
* or a folder within WP_CONTENT_DIR.
[398] Fix | Delete
* @return bool True if successfully registered a directory that contains themes,
[399] Fix | Delete
* false if the directory does not exist.
[400] Fix | Delete
*/
[401] Fix | Delete
function register_theme_directory( $directory ) {
[402] Fix | Delete
global $wp_theme_directories;
[403] Fix | Delete
[404] Fix | Delete
if ( ! file_exists( $directory ) ) {
[405] Fix | Delete
// Try prepending as the theme directory could be relative to the content directory.
[406] Fix | Delete
$directory = WP_CONTENT_DIR . '/' . $directory;
[407] Fix | Delete
// If this directory does not exist, return and do not register.
[408] Fix | Delete
if ( ! file_exists( $directory ) ) {
[409] Fix | Delete
return false;
[410] Fix | Delete
}
[411] Fix | Delete
}
[412] Fix | Delete
[413] Fix | Delete
if ( ! is_array( $wp_theme_directories ) ) {
[414] Fix | Delete
$wp_theme_directories = array();
[415] Fix | Delete
}
[416] Fix | Delete
[417] Fix | Delete
$untrailed = untrailingslashit( $directory );
[418] Fix | Delete
if ( ! empty( $untrailed ) && ! in_array( $untrailed, $wp_theme_directories, true ) ) {
[419] Fix | Delete
$wp_theme_directories[] = $untrailed;
[420] Fix | Delete
}
[421] Fix | Delete
[422] Fix | Delete
return true;
[423] Fix | Delete
}
[424] Fix | Delete
[425] Fix | Delete
/**
[426] Fix | Delete
* Searches all registered theme directories for complete and valid themes.
[427] Fix | Delete
*
[428] Fix | Delete
* @since 2.9.0
[429] Fix | Delete
*
[430] Fix | Delete
* @global array $wp_theme_directories
[431] Fix | Delete
*
[432] Fix | Delete
* @param bool $force Optional. Whether to force a new directory scan. Default false.
[433] Fix | Delete
* @return array|false Valid themes found on success, false on failure.
[434] Fix | Delete
*/
[435] Fix | Delete
function search_theme_directories( $force = false ) {
[436] Fix | Delete
global $wp_theme_directories;
[437] Fix | Delete
static $found_themes = null;
[438] Fix | Delete
[439] Fix | Delete
if ( empty( $wp_theme_directories ) ) {
[440] Fix | Delete
return false;
[441] Fix | Delete
}
[442] Fix | Delete
[443] Fix | Delete
if ( ! $force && isset( $found_themes ) ) {
[444] Fix | Delete
return $found_themes;
[445] Fix | Delete
}
[446] Fix | Delete
[447] Fix | Delete
$found_themes = array();
[448] Fix | Delete
[449] Fix | Delete
$wp_theme_directories = (array) $wp_theme_directories;
[450] Fix | Delete
$relative_theme_roots = array();
[451] Fix | Delete
[452] Fix | Delete
/*
[453] Fix | Delete
* Set up maybe-relative, maybe-absolute array of theme directories.
[454] Fix | Delete
* We always want to return absolute, but we need to cache relative
[455] Fix | Delete
* to use in get_theme_root().
[456] Fix | Delete
*/
[457] Fix | Delete
foreach ( $wp_theme_directories as $theme_root ) {
[458] Fix | Delete
if ( 0 === strpos( $theme_root, WP_CONTENT_DIR ) ) {
[459] Fix | Delete
$relative_theme_roots[ str_replace( WP_CONTENT_DIR, '', $theme_root ) ] = $theme_root;
[460] Fix | Delete
} else {
[461] Fix | Delete
$relative_theme_roots[ $theme_root ] = $theme_root;
[462] Fix | Delete
}
[463] Fix | Delete
}
[464] Fix | Delete
[465] Fix | Delete
/**
[466] Fix | Delete
* Filters whether to get the cache of the registered theme directories.
[467] Fix | Delete
*
[468] Fix | Delete
* @since 3.4.0
[469] Fix | Delete
*
[470] Fix | Delete
* @param bool $cache_expiration Whether to get the cache of the theme directories. Default false.
[471] Fix | Delete
* @param string $context The class or function name calling the filter.
[472] Fix | Delete
*/
[473] Fix | Delete
$cache_expiration = apply_filters( 'wp_cache_themes_persistently', false, 'search_theme_directories' );
[474] Fix | Delete
[475] Fix | Delete
if ( $cache_expiration ) {
[476] Fix | Delete
$cached_roots = get_site_transient( 'theme_roots' );
[477] Fix | Delete
if ( is_array( $cached_roots ) ) {
[478] Fix | Delete
foreach ( $cached_roots as $theme_dir => $theme_root ) {
[479] Fix | Delete
// A cached theme root is no longer around, so skip it.
[480] Fix | Delete
if ( ! isset( $relative_theme_roots[ $theme_root ] ) ) {
[481] Fix | Delete
continue;
[482] Fix | Delete
}
[483] Fix | Delete
$found_themes[ $theme_dir ] = array(
[484] Fix | Delete
'theme_file' => $theme_dir . '/style.css',
[485] Fix | Delete
'theme_root' => $relative_theme_roots[ $theme_root ], // Convert relative to absolute.
[486] Fix | Delete
);
[487] Fix | Delete
}
[488] Fix | Delete
return $found_themes;
[489] Fix | Delete
}
[490] Fix | Delete
if ( ! is_int( $cache_expiration ) ) {
[491] Fix | Delete
$cache_expiration = 30 * MINUTE_IN_SECONDS;
[492] Fix | Delete
}
[493] Fix | Delete
} else {
[494] Fix | Delete
$cache_expiration = 30 * MINUTE_IN_SECONDS;
[495] Fix | Delete
}
[496] Fix | Delete
[497] Fix | Delete
/* Loop the registered theme directories and extract all themes */
[498] Fix | Delete
foreach ( $wp_theme_directories as $theme_root ) {
[499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function