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