mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-07-01 07:40:07 +00:00
Introduce WP_Theme, wp_get_themes(), and wp_get_theme() to replace get_themes(), get_theme(), get_theme_data(), current_theme_info(), and others.
* Getters and Helpers: Introduces a series of methods to allow for easy generation of headers for display, and other theme metadata, including page templates. * Screenshots: Handles support for multiple screenshots. (see # Additional screenshots must be PNG and start with screenshot-2.png, and be sequential to be counted. see #19816. * Error Handling: Broken themes have a WP_Error object attached to them. * Caching: Introduces a wp_cache_themes_persistently filter (also in [20020]) to enable persistent caching of all filesystem and sanitization operations normally handled by WP_Theme (and formerly get_file_data() and get_themes()). Themes are cached individually and across five different cache keys for different data pieces. * Compatibility: A WP_Theme object is backwards compatible with a theme's array formerly returned by get_themes() and get_theme(), and an stdClass object formerly returned by current_theme_info(). * i18n/L10n: Theme headers are now localizable with proper Text Domain and Domain Path headers, like plugins. (Language packs may remove the requirement for headers.) For page templates, see #6007 (not fixed yet, but will be easy now). For headers, fixes #15858. * PHP and CSS files: New methods that fetch a list of theme files (for the theme editor) only on demand, rather than only loading them into memory. fixes #11214. Functions deprecated: * get_themes(), get_allowed_themes() and get_broken_themes() -- use wp_get_themes() * get_theme() and current_theme_info() -- use wp_get_theme() * get_site_allowed_themes() -- use WP_Theme::get_allowed_on_network() * wpmu_get_blog_allowedthemes() -- use WP_theme::get_allowed_on_site() see also [20016], [20018], [20019], [20020], [20021], [20022], [20025], [20026], [20027]. also fixes #19244. see #20103. git-svn-id: https://develop.svn.wordpress.org/trunk@20029 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -6,46 +6,6 @@
|
||||
* @subpackage Administration
|
||||
*/
|
||||
|
||||
/**
|
||||
* {@internal Missing Short Description}}
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @return unknown
|
||||
*/
|
||||
function current_theme_info() {
|
||||
$themes = get_themes();
|
||||
$current_theme = get_current_theme();
|
||||
|
||||
if ( ! $themes ) {
|
||||
$ct = new stdClass;
|
||||
$ct->name = $current_theme;
|
||||
return $ct;
|
||||
}
|
||||
|
||||
if ( ! isset( $themes[$current_theme] ) ) {
|
||||
delete_option( 'current_theme' );
|
||||
$current_theme = get_current_theme();
|
||||
}
|
||||
|
||||
$ct = new stdClass;
|
||||
$ct->name = $current_theme;
|
||||
$ct->title = $themes[$current_theme]['Title'];
|
||||
$ct->version = $themes[$current_theme]['Version'];
|
||||
$ct->parent_theme = $themes[$current_theme]['Parent Theme'];
|
||||
$ct->template_dir = $themes[$current_theme]['Template Dir'];
|
||||
$ct->stylesheet_dir = $themes[$current_theme]['Stylesheet Dir'];
|
||||
$ct->template = $themes[$current_theme]['Template'];
|
||||
$ct->stylesheet = $themes[$current_theme]['Stylesheet'];
|
||||
$ct->screenshot = $themes[$current_theme]['Screenshot'];
|
||||
$ct->description = $themes[$current_theme]['Description'];
|
||||
$ct->author = $themes[$current_theme]['Author'];
|
||||
$ct->tags = $themes[$current_theme]['Tags'];
|
||||
$ct->theme_root = $themes[$current_theme]['Theme Root'];
|
||||
$ct->theme_root_uri = $themes[$current_theme]['Theme Root URI'];
|
||||
return $ct;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a theme
|
||||
*
|
||||
@@ -113,59 +73,6 @@ function delete_theme($template, $redirect = '') {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@internal Missing Short Description}}
|
||||
*
|
||||
* @since 1.5.0
|
||||
*
|
||||
* @return unknown
|
||||
*/
|
||||
function get_broken_themes() {
|
||||
global $wp_broken_themes;
|
||||
|
||||
get_themes();
|
||||
return $wp_broken_themes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the allowed themes for the current blog.
|
||||
*
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @uses get_themes()
|
||||
* @uses current_theme_info()
|
||||
* @uses get_site_allowed_themes()
|
||||
* @uses wpmu_get_blog_allowedthemes
|
||||
*
|
||||
* @return array $themes Array of allowed themes.
|
||||
*/
|
||||
function get_allowed_themes() {
|
||||
if ( !is_multisite() )
|
||||
return get_themes();
|
||||
|
||||
$themes = get_themes();
|
||||
$ct = current_theme_info();
|
||||
$allowed_themes = apply_filters("allowed_themes", get_site_allowed_themes() );
|
||||
if ( $allowed_themes == false )
|
||||
$allowed_themes = array();
|
||||
|
||||
$blog_allowed_themes = wpmu_get_blog_allowedthemes();
|
||||
if ( is_array( $blog_allowed_themes ) )
|
||||
$allowed_themes = array_merge( $allowed_themes, $blog_allowed_themes );
|
||||
|
||||
if ( isset( $allowed_themes[ esc_html( $ct->stylesheet ) ] ) == false )
|
||||
$allowed_themes[ esc_html( $ct->stylesheet ) ] = true;
|
||||
|
||||
reset( $themes );
|
||||
foreach ( $themes as $key => $theme ) {
|
||||
if ( isset( $allowed_themes[ esc_html( $theme[ 'Stylesheet' ] ) ] ) == false )
|
||||
unset( $themes[ $key ] );
|
||||
}
|
||||
reset( $themes );
|
||||
|
||||
return $themes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Page Templates available in this theme
|
||||
*
|
||||
@@ -174,37 +81,7 @@ function get_allowed_themes() {
|
||||
* @return array Key is the template name, value is the filename of the template
|
||||
*/
|
||||
function get_page_templates() {
|
||||
$themes = get_themes();
|
||||
$theme = get_current_theme();
|
||||
$templates = $themes[$theme]['Template Files'];
|
||||
$page_templates = array();
|
||||
|
||||
if ( is_array( $templates ) ) {
|
||||
$base = array( trailingslashit(get_template_directory()), trailingslashit(get_stylesheet_directory()) );
|
||||
|
||||
foreach ( $templates as $template ) {
|
||||
$basename = str_replace($base, '', $template);
|
||||
|
||||
// don't allow template files in subdirectories
|
||||
if ( false !== strpos($basename, '/') )
|
||||
continue;
|
||||
|
||||
if ( 'functions.php' == $basename )
|
||||
continue;
|
||||
|
||||
$template_data = implode( '', file( $template ));
|
||||
|
||||
$name = '';
|
||||
if ( preg_match( '|Template Name:(.*)$|mi', $template_data, $name ) )
|
||||
$name = _cleanup_header_comment($name[1]);
|
||||
|
||||
if ( !empty( $name ) ) {
|
||||
$page_templates[trim( $name )] = $basename;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $page_templates;
|
||||
return wp_get_theme()->get_page_templates();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -240,16 +117,14 @@ function theme_update_available( $theme ) {
|
||||
if ( !isset($themes_update) )
|
||||
$themes_update = get_site_transient('update_themes');
|
||||
|
||||
if ( is_object($theme) && isset($theme->stylesheet) )
|
||||
$stylesheet = $theme->stylesheet;
|
||||
elseif ( is_array($theme) && isset($theme['Stylesheet']) )
|
||||
$stylesheet = $theme['Stylesheet'];
|
||||
else
|
||||
return false; //No valid info passed.
|
||||
if ( ! is_a( $theme, 'WP_Theme' ) )
|
||||
return;
|
||||
|
||||
$stylesheet = $theme->get_stylesheet();
|
||||
|
||||
if ( isset($themes_update->response[ $stylesheet ]) ) {
|
||||
$update = $themes_update->response[ $stylesheet ];
|
||||
$theme_name = is_object($theme) ? $theme->name : (is_array($theme) ? $theme['Name'] : '');
|
||||
$theme_name = $theme->get('Name');
|
||||
$details_url = add_query_arg(array('TB_iframe' => 'true', 'width' => 1024, 'height' => 800), $update['url']); //Theme browser inside WP? replace this, Also, theme preview JS will override this on the available list.
|
||||
$update_url = wp_nonce_url('update.php?action=upgrade-theme&theme=' . urlencode($stylesheet), 'upgrade-theme_' . $stylesheet);
|
||||
$update_onclick = 'onclick="if ( confirm(\'' . esc_js( __("Updating this theme will lose any customizations you have made. 'Cancel' to stop, 'OK' to update.") ) . '\') ) {return true;}return false;"';
|
||||
|
||||
Reference in New Issue
Block a user