Update WP and plugins
This commit is contained in:
parent
10a4713229
commit
1fb77fc4ff
864 changed files with 101724 additions and 78262 deletions
|
@ -21,7 +21,6 @@ final class WP_Theme implements ArrayAccess {
|
|||
/**
|
||||
* Headers for style.css files.
|
||||
*
|
||||
* @static
|
||||
* @var array
|
||||
*/
|
||||
private static $file_headers = array(
|
||||
|
@ -41,7 +40,6 @@ final class WP_Theme implements ArrayAccess {
|
|||
/**
|
||||
* Default themes.
|
||||
*
|
||||
* @static
|
||||
* @var array
|
||||
*/
|
||||
private static $default_themes = array(
|
||||
|
@ -61,7 +59,6 @@ final class WP_Theme implements ArrayAccess {
|
|||
/**
|
||||
* Renamed theme tags.
|
||||
*
|
||||
* @static
|
||||
* @var array
|
||||
*/
|
||||
private static $tag_map = array(
|
||||
|
@ -159,7 +156,6 @@ final class WP_Theme implements ArrayAccess {
|
|||
*
|
||||
* Default is false. Can be set with the {@see 'wp_cache_themes_persistently'} filter.
|
||||
*
|
||||
* @static
|
||||
* @var bool
|
||||
*/
|
||||
private static $persistently_cache;
|
||||
|
@ -169,7 +165,6 @@ final class WP_Theme implements ArrayAccess {
|
|||
*
|
||||
* By default the bucket is not cached, so this value is useless.
|
||||
*
|
||||
* @static
|
||||
* @var bool
|
||||
*/
|
||||
private static $cache_expiration = 1800;
|
||||
|
@ -194,8 +189,9 @@ final class WP_Theme implements ArrayAccess {
|
|||
self::$persistently_cache = apply_filters( 'wp_cache_themes_persistently', false, 'WP_Theme' );
|
||||
if ( self::$persistently_cache ) {
|
||||
wp_cache_add_global_groups( 'themes' );
|
||||
if ( is_int( self::$persistently_cache ) )
|
||||
if ( is_int( self::$persistently_cache ) ) {
|
||||
self::$cache_expiration = self::$persistently_cache;
|
||||
}
|
||||
} else {
|
||||
wp_cache_add_non_persistent_groups( 'themes' );
|
||||
}
|
||||
|
@ -211,50 +207,79 @@ final class WP_Theme implements ArrayAccess {
|
|||
}
|
||||
|
||||
$this->cache_hash = md5( $this->theme_root . '/' . $this->stylesheet );
|
||||
$theme_file = $this->stylesheet . '/style.css';
|
||||
$theme_file = $this->stylesheet . '/style.css';
|
||||
|
||||
$cache = $this->cache_get( 'theme' );
|
||||
|
||||
if ( is_array( $cache ) ) {
|
||||
foreach ( array( 'errors', 'headers', 'template' ) as $key ) {
|
||||
if ( isset( $cache[ $key ] ) )
|
||||
if ( isset( $cache[ $key ] ) ) {
|
||||
$this->$key = $cache[ $key ];
|
||||
}
|
||||
}
|
||||
if ( $this->errors )
|
||||
if ( $this->errors ) {
|
||||
return;
|
||||
if ( isset( $cache['theme_root_template'] ) )
|
||||
}
|
||||
if ( isset( $cache['theme_root_template'] ) ) {
|
||||
$theme_root_template = $cache['theme_root_template'];
|
||||
}
|
||||
} elseif ( ! file_exists( $this->theme_root . '/' . $theme_file ) ) {
|
||||
$this->headers['Name'] = $this->stylesheet;
|
||||
if ( ! file_exists( $this->theme_root . '/' . $this->stylesheet ) )
|
||||
if ( ! file_exists( $this->theme_root . '/' . $this->stylesheet ) ) {
|
||||
$this->errors = new WP_Error( 'theme_not_found', sprintf( __( 'The theme directory "%s" does not exist.' ), esc_html( $this->stylesheet ) ) );
|
||||
else
|
||||
} else {
|
||||
$this->errors = new WP_Error( 'theme_no_stylesheet', __( 'Stylesheet is missing.' ) );
|
||||
}
|
||||
$this->template = $this->stylesheet;
|
||||
$this->cache_add( 'theme', array( 'headers' => $this->headers, 'errors' => $this->errors, 'stylesheet' => $this->stylesheet, 'template' => $this->template ) );
|
||||
if ( ! file_exists( $this->theme_root ) ) // Don't cache this one.
|
||||
$this->cache_add(
|
||||
'theme',
|
||||
array(
|
||||
'headers' => $this->headers,
|
||||
'errors' => $this->errors,
|
||||
'stylesheet' => $this->stylesheet,
|
||||
'template' => $this->template,
|
||||
)
|
||||
);
|
||||
if ( ! file_exists( $this->theme_root ) ) { // Don't cache this one.
|
||||
$this->errors->add( 'theme_root_missing', __( 'ERROR: The themes directory is either empty or doesn’t exist. Please check your installation.' ) );
|
||||
}
|
||||
return;
|
||||
} elseif ( ! is_readable( $this->theme_root . '/' . $theme_file ) ) {
|
||||
$this->headers['Name'] = $this->stylesheet;
|
||||
$this->errors = new WP_Error( 'theme_stylesheet_not_readable', __( 'Stylesheet is not readable.' ) );
|
||||
$this->template = $this->stylesheet;
|
||||
$this->cache_add( 'theme', array( 'headers' => $this->headers, 'errors' => $this->errors, 'stylesheet' => $this->stylesheet, 'template' => $this->template ) );
|
||||
$this->errors = new WP_Error( 'theme_stylesheet_not_readable', __( 'Stylesheet is not readable.' ) );
|
||||
$this->template = $this->stylesheet;
|
||||
$this->cache_add(
|
||||
'theme',
|
||||
array(
|
||||
'headers' => $this->headers,
|
||||
'errors' => $this->errors,
|
||||
'stylesheet' => $this->stylesheet,
|
||||
'template' => $this->template,
|
||||
)
|
||||
);
|
||||
return;
|
||||
} else {
|
||||
$this->headers = get_file_data( $this->theme_root . '/' . $theme_file, self::$file_headers, 'theme' );
|
||||
// Default themes always trump their pretenders.
|
||||
// Properly identify default themes that are inside a directory within wp-content/themes.
|
||||
if ( $default_theme_slug = array_search( $this->headers['Name'], self::$default_themes ) ) {
|
||||
if ( basename( $this->stylesheet ) != $default_theme_slug )
|
||||
if ( basename( $this->stylesheet ) != $default_theme_slug ) {
|
||||
$this->headers['Name'] .= '/' . $this->stylesheet;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! $this->template && $this->stylesheet === $this->headers['Template'] ) {
|
||||
/* translators: %s: Template */
|
||||
$this->errors = new WP_Error( 'theme_child_invalid', sprintf( __( 'The theme defines itself as its parent theme. Please check the %s header.' ), '<code>Template</code>' ) );
|
||||
$this->cache_add( 'theme', array( 'headers' => $this->headers, 'errors' => $this->errors, 'stylesheet' => $this->stylesheet ) );
|
||||
$this->cache_add(
|
||||
'theme',
|
||||
array(
|
||||
'headers' => $this->headers,
|
||||
'errors' => $this->errors,
|
||||
'stylesheet' => $this->stylesheet,
|
||||
)
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
@ -271,7 +296,15 @@ final class WP_Theme implements ArrayAccess {
|
|||
'<code>style.css</code>'
|
||||
);
|
||||
$this->errors = new WP_Error( 'theme_no_index', $error_message );
|
||||
$this->cache_add( 'theme', array( 'headers' => $this->headers, 'errors' => $this->errors, 'stylesheet' => $this->stylesheet, 'template' => $this->template ) );
|
||||
$this->cache_add(
|
||||
'theme',
|
||||
array(
|
||||
'headers' => $this->headers,
|
||||
'errors' => $this->errors,
|
||||
'stylesheet' => $this->stylesheet,
|
||||
'template' => $this->template,
|
||||
)
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -290,7 +323,15 @@ final class WP_Theme implements ArrayAccess {
|
|||
} else {
|
||||
// Parent theme is missing.
|
||||
$this->errors = new WP_Error( 'theme_no_parent', sprintf( __( 'The parent theme is missing. Please install the "%s" parent theme.' ), esc_html( $this->template ) ) );
|
||||
$this->cache_add( 'theme', array( 'headers' => $this->headers, 'errors' => $this->errors, 'stylesheet' => $this->stylesheet, 'template' => $this->template ) );
|
||||
$this->cache_add(
|
||||
'theme',
|
||||
array(
|
||||
'headers' => $this->headers,
|
||||
'errors' => $this->errors,
|
||||
'stylesheet' => $this->stylesheet,
|
||||
'template' => $this->template,
|
||||
)
|
||||
);
|
||||
$this->parent = new WP_Theme( $this->template, $this->theme_root, $this );
|
||||
return;
|
||||
}
|
||||
|
@ -302,11 +343,27 @@ final class WP_Theme implements ArrayAccess {
|
|||
if ( $_child instanceof WP_Theme && $_child->template == $this->stylesheet ) {
|
||||
$_child->parent = null;
|
||||
$_child->errors = new WP_Error( 'theme_parent_invalid', sprintf( __( 'The "%s" theme is not a valid parent theme.' ), esc_html( $_child->template ) ) );
|
||||
$_child->cache_add( 'theme', array( 'headers' => $_child->headers, 'errors' => $_child->errors, 'stylesheet' => $_child->stylesheet, 'template' => $_child->template ) );
|
||||
$_child->cache_add(
|
||||
'theme',
|
||||
array(
|
||||
'headers' => $_child->headers,
|
||||
'errors' => $_child->errors,
|
||||
'stylesheet' => $_child->stylesheet,
|
||||
'template' => $_child->template,
|
||||
)
|
||||
);
|
||||
// The two themes actually reference each other with the Template header.
|
||||
if ( $_child->stylesheet == $this->template ) {
|
||||
$this->errors = new WP_Error( 'theme_parent_invalid', sprintf( __( 'The "%s" theme is not a valid parent theme.' ), esc_html( $this->template ) ) );
|
||||
$this->cache_add( 'theme', array( 'headers' => $this->headers, 'errors' => $this->errors, 'stylesheet' => $this->stylesheet, 'template' => $this->template ) );
|
||||
$this->cache_add(
|
||||
'theme',
|
||||
array(
|
||||
'headers' => $this->headers,
|
||||
'errors' => $this->errors,
|
||||
'stylesheet' => $this->stylesheet,
|
||||
'template' => $this->template,
|
||||
)
|
||||
);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
@ -316,10 +373,16 @@ final class WP_Theme implements ArrayAccess {
|
|||
|
||||
// We're good. If we didn't retrieve from cache, set it.
|
||||
if ( ! is_array( $cache ) ) {
|
||||
$cache = array( 'headers' => $this->headers, 'errors' => $this->errors, 'stylesheet' => $this->stylesheet, 'template' => $this->template );
|
||||
$cache = array(
|
||||
'headers' => $this->headers,
|
||||
'errors' => $this->errors,
|
||||
'stylesheet' => $this->stylesheet,
|
||||
'template' => $this->template,
|
||||
);
|
||||
// If the parent theme is in another root, we'll want to cache this. Avoids an entire branch of filesystem calls above.
|
||||
if ( isset( $theme_root_template ) )
|
||||
if ( isset( $theme_root_template ) ) {
|
||||
$cache['theme_root_template'] = $theme_root_template;
|
||||
}
|
||||
$this->cache_add( 'theme', $cache );
|
||||
}
|
||||
}
|
||||
|
@ -332,7 +395,7 @@ final class WP_Theme implements ArrayAccess {
|
|||
* @return string Theme name, ready for display (translated)
|
||||
*/
|
||||
public function __toString() {
|
||||
return (string) $this->display('Name');
|
||||
return (string) $this->display( 'Name' );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -347,8 +410,20 @@ final class WP_Theme implements ArrayAccess {
|
|||
*/
|
||||
public function __isset( $offset ) {
|
||||
static $properties = array(
|
||||
'name', 'title', 'version', 'parent_theme', 'template_dir', 'stylesheet_dir', 'template', 'stylesheet',
|
||||
'screenshot', 'description', 'author', 'tags', 'theme_root', 'theme_root_uri',
|
||||
'name',
|
||||
'title',
|
||||
'version',
|
||||
'parent_theme',
|
||||
'template_dir',
|
||||
'stylesheet_dir',
|
||||
'template',
|
||||
'stylesheet',
|
||||
'screenshot',
|
||||
'description',
|
||||
'author',
|
||||
'tags',
|
||||
'theme_root',
|
||||
'theme_root_uri',
|
||||
);
|
||||
|
||||
return in_array( $offset, $properties );
|
||||
|
@ -364,36 +439,36 @@ final class WP_Theme implements ArrayAccess {
|
|||
*/
|
||||
public function __get( $offset ) {
|
||||
switch ( $offset ) {
|
||||
case 'name' :
|
||||
case 'title' :
|
||||
return $this->get('Name');
|
||||
case 'version' :
|
||||
return $this->get('Version');
|
||||
case 'parent_theme' :
|
||||
return $this->parent() ? $this->parent()->get('Name') : '';
|
||||
case 'template_dir' :
|
||||
case 'name':
|
||||
case 'title':
|
||||
return $this->get( 'Name' );
|
||||
case 'version':
|
||||
return $this->get( 'Version' );
|
||||
case 'parent_theme':
|
||||
return $this->parent() ? $this->parent()->get( 'Name' ) : '';
|
||||
case 'template_dir':
|
||||
return $this->get_template_directory();
|
||||
case 'stylesheet_dir' :
|
||||
case 'stylesheet_dir':
|
||||
return $this->get_stylesheet_directory();
|
||||
case 'template' :
|
||||
case 'template':
|
||||
return $this->get_template();
|
||||
case 'stylesheet' :
|
||||
case 'stylesheet':
|
||||
return $this->get_stylesheet();
|
||||
case 'screenshot' :
|
||||
case 'screenshot':
|
||||
return $this->get_screenshot( 'relative' );
|
||||
// 'author' and 'description' did not previously return translated data.
|
||||
case 'description' :
|
||||
return $this->display('Description');
|
||||
case 'author' :
|
||||
return $this->display('Author');
|
||||
case 'tags' :
|
||||
case 'description':
|
||||
return $this->display( 'Description' );
|
||||
case 'author':
|
||||
return $this->display( 'Author' );
|
||||
case 'tags':
|
||||
return $this->get( 'Tags' );
|
||||
case 'theme_root' :
|
||||
case 'theme_root':
|
||||
return $this->get_theme_root();
|
||||
case 'theme_root_uri' :
|
||||
case 'theme_root_uri':
|
||||
return $this->get_theme_root_uri();
|
||||
// For cases where the array was converted to an object.
|
||||
default :
|
||||
default:
|
||||
return $this->offsetGet( $offset );
|
||||
}
|
||||
}
|
||||
|
@ -429,9 +504,25 @@ final class WP_Theme implements ArrayAccess {
|
|||
*/
|
||||
public function offsetExists( $offset ) {
|
||||
static $keys = array(
|
||||
'Name', 'Version', 'Status', 'Title', 'Author', 'Author Name', 'Author URI', 'Description',
|
||||
'Template', 'Stylesheet', 'Template Files', 'Stylesheet Files', 'Template Dir', 'Stylesheet Dir',
|
||||
'Screenshot', 'Tags', 'Theme Root', 'Theme Root URI', 'Parent Theme',
|
||||
'Name',
|
||||
'Version',
|
||||
'Status',
|
||||
'Title',
|
||||
'Author',
|
||||
'Author Name',
|
||||
'Author URI',
|
||||
'Description',
|
||||
'Template',
|
||||
'Stylesheet',
|
||||
'Template Files',
|
||||
'Stylesheet Files',
|
||||
'Template Dir',
|
||||
'Stylesheet Dir',
|
||||
'Screenshot',
|
||||
'Tags',
|
||||
'Theme Root',
|
||||
'Theme Root URI',
|
||||
'Parent Theme',
|
||||
);
|
||||
|
||||
return in_array( $offset, $keys );
|
||||
|
@ -454,47 +545,47 @@ final class WP_Theme implements ArrayAccess {
|
|||
*/
|
||||
public function offsetGet( $offset ) {
|
||||
switch ( $offset ) {
|
||||
case 'Name' :
|
||||
case 'Title' :
|
||||
case 'Name':
|
||||
case 'Title':
|
||||
/*
|
||||
* See note above about using translated data. get() is not ideal.
|
||||
* It is only for backward compatibility. Use display().
|
||||
*/
|
||||
return $this->get('Name');
|
||||
case 'Author' :
|
||||
return $this->display( 'Author');
|
||||
case 'Author Name' :
|
||||
return $this->display( 'Author', false);
|
||||
case 'Author URI' :
|
||||
return $this->display('AuthorURI');
|
||||
case 'Description' :
|
||||
return $this->display( 'Description');
|
||||
case 'Version' :
|
||||
case 'Status' :
|
||||
return $this->get( 'Name' );
|
||||
case 'Author':
|
||||
return $this->display( 'Author' );
|
||||
case 'Author Name':
|
||||
return $this->display( 'Author', false );
|
||||
case 'Author URI':
|
||||
return $this->display( 'AuthorURI' );
|
||||
case 'Description':
|
||||
return $this->display( 'Description' );
|
||||
case 'Version':
|
||||
case 'Status':
|
||||
return $this->get( $offset );
|
||||
case 'Template' :
|
||||
case 'Template':
|
||||
return $this->get_template();
|
||||
case 'Stylesheet' :
|
||||
case 'Stylesheet':
|
||||
return $this->get_stylesheet();
|
||||
case 'Template Files' :
|
||||
case 'Template Files':
|
||||
return $this->get_files( 'php', 1, true );
|
||||
case 'Stylesheet Files' :
|
||||
case 'Stylesheet Files':
|
||||
return $this->get_files( 'css', 0, false );
|
||||
case 'Template Dir' :
|
||||
case 'Template Dir':
|
||||
return $this->get_template_directory();
|
||||
case 'Stylesheet Dir' :
|
||||
case 'Stylesheet Dir':
|
||||
return $this->get_stylesheet_directory();
|
||||
case 'Screenshot' :
|
||||
case 'Screenshot':
|
||||
return $this->get_screenshot( 'relative' );
|
||||
case 'Tags' :
|
||||
return $this->get('Tags');
|
||||
case 'Theme Root' :
|
||||
case 'Tags':
|
||||
return $this->get( 'Tags' );
|
||||
case 'Theme Root':
|
||||
return $this->get_theme_root();
|
||||
case 'Theme Root URI' :
|
||||
case 'Theme Root URI':
|
||||
return $this->get_theme_root_uri();
|
||||
case 'Parent Theme' :
|
||||
return $this->parent() ? $this->parent()->get('Name') : '';
|
||||
default :
|
||||
case 'Parent Theme':
|
||||
return $this->parent() ? $this->parent()->get( 'Name' ) : '';
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -570,10 +661,11 @@ final class WP_Theme implements ArrayAccess {
|
|||
* @since 3.4.0
|
||||
*/
|
||||
public function cache_delete() {
|
||||
foreach ( array( 'theme', 'screenshot', 'headers', 'post_templates' ) as $key )
|
||||
foreach ( array( 'theme', 'screenshot', 'headers', 'post_templates' ) as $key ) {
|
||||
wp_cache_delete( $key . '-' . $this->cache_hash, 'themes' );
|
||||
}
|
||||
$this->template = $this->textdomain_loaded = $this->theme_root_uri = $this->parent = $this->errors = $this->headers_sanitized = $this->name_translated = null;
|
||||
$this->headers = array();
|
||||
$this->headers = array();
|
||||
$this->__construct( $this->stylesheet, $this->theme_root );
|
||||
}
|
||||
|
||||
|
@ -594,22 +686,26 @@ final class WP_Theme implements ArrayAccess {
|
|||
* @return string|false String on success, false on failure.
|
||||
*/
|
||||
public function get( $header ) {
|
||||
if ( ! isset( $this->headers[ $header ] ) )
|
||||
if ( ! isset( $this->headers[ $header ] ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( ! isset( $this->headers_sanitized ) ) {
|
||||
$this->headers_sanitized = $this->cache_get( 'headers' );
|
||||
if ( ! is_array( $this->headers_sanitized ) )
|
||||
if ( ! is_array( $this->headers_sanitized ) ) {
|
||||
$this->headers_sanitized = array();
|
||||
}
|
||||
}
|
||||
|
||||
if ( isset( $this->headers_sanitized[ $header ] ) )
|
||||
if ( isset( $this->headers_sanitized[ $header ] ) ) {
|
||||
return $this->headers_sanitized[ $header ];
|
||||
}
|
||||
|
||||
// If themes are a persistent group, sanitize everything and cache it. One cache add is better than many cache sets.
|
||||
if ( self::$persistently_cache ) {
|
||||
foreach ( array_keys( $this->headers ) as $_header )
|
||||
foreach ( array_keys( $this->headers ) as $_header ) {
|
||||
$this->headers_sanitized[ $_header ] = $this->sanitize_header( $_header, $this->headers[ $_header ] );
|
||||
}
|
||||
$this->cache_add( 'headers', $this->headers_sanitized );
|
||||
} else {
|
||||
$this->headers_sanitized[ $header ] = $this->sanitize_header( $header, $this->headers[ $header ] );
|
||||
|
@ -634,14 +730,17 @@ final class WP_Theme implements ArrayAccess {
|
|||
return false;
|
||||
}
|
||||
|
||||
if ( $translate && ( empty( $value ) || ! $this->load_textdomain() ) )
|
||||
if ( $translate && ( empty( $value ) || ! $this->load_textdomain() ) ) {
|
||||
$translate = false;
|
||||
}
|
||||
|
||||
if ( $translate )
|
||||
if ( $translate ) {
|
||||
$value = $this->translate_header( $header, $value );
|
||||
}
|
||||
|
||||
if ( $markup )
|
||||
if ( $markup ) {
|
||||
$value = $this->markup_header( $header, $value, $translate );
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
@ -660,13 +759,13 @@ final class WP_Theme implements ArrayAccess {
|
|||
*/
|
||||
private function sanitize_header( $header, $value ) {
|
||||
switch ( $header ) {
|
||||
case 'Status' :
|
||||
case 'Status':
|
||||
if ( ! $value ) {
|
||||
$value = 'publish';
|
||||
break;
|
||||
}
|
||||
// Fall through otherwise.
|
||||
case 'Name' :
|
||||
case 'Name':
|
||||
static $header_tags = array(
|
||||
'abbr' => array( 'title' => true ),
|
||||
'acronym' => array( 'title' => true ),
|
||||
|
@ -674,29 +773,32 @@ final class WP_Theme implements ArrayAccess {
|
|||
'em' => true,
|
||||
'strong' => true,
|
||||
);
|
||||
$value = wp_kses( $value, $header_tags );
|
||||
$value = wp_kses( $value, $header_tags );
|
||||
break;
|
||||
case 'Author' :
|
||||
case 'Author':
|
||||
// There shouldn't be anchor tags in Author, but some themes like to be challenging.
|
||||
case 'Description' :
|
||||
case 'Description':
|
||||
static $header_tags_with_a = array(
|
||||
'a' => array( 'href' => true, 'title' => true ),
|
||||
'a' => array(
|
||||
'href' => true,
|
||||
'title' => true,
|
||||
),
|
||||
'abbr' => array( 'title' => true ),
|
||||
'acronym' => array( 'title' => true ),
|
||||
'code' => true,
|
||||
'em' => true,
|
||||
'strong' => true,
|
||||
);
|
||||
$value = wp_kses( $value, $header_tags_with_a );
|
||||
$value = wp_kses( $value, $header_tags_with_a );
|
||||
break;
|
||||
case 'ThemeURI' :
|
||||
case 'AuthorURI' :
|
||||
case 'ThemeURI':
|
||||
case 'AuthorURI':
|
||||
$value = esc_url_raw( $value );
|
||||
break;
|
||||
case 'Tags' :
|
||||
case 'Tags':
|
||||
$value = array_filter( array_map( 'trim', explode( ',', strip_tags( $value ) ) ) );
|
||||
break;
|
||||
case 'Version' :
|
||||
case 'Version':
|
||||
$value = strip_tags( $value );
|
||||
break;
|
||||
}
|
||||
|
@ -707,7 +809,7 @@ final class WP_Theme implements ArrayAccess {
|
|||
/**
|
||||
* Mark up a theme header.
|
||||
*
|
||||
* @since 3.4.0
|
||||
* @since 3.4.0
|
||||
*
|
||||
* @staticvar string $comma
|
||||
*
|
||||
|
@ -718,22 +820,22 @@ final class WP_Theme implements ArrayAccess {
|
|||
*/
|
||||
private function markup_header( $header, $value, $translate ) {
|
||||
switch ( $header ) {
|
||||
case 'Name' :
|
||||
case 'Name':
|
||||
if ( empty( $value ) ) {
|
||||
$value = esc_html( $this->get_stylesheet() );
|
||||
}
|
||||
break;
|
||||
case 'Description' :
|
||||
case 'Description':
|
||||
$value = wptexturize( $value );
|
||||
break;
|
||||
case 'Author' :
|
||||
if ( $this->get('AuthorURI') ) {
|
||||
case 'Author':
|
||||
if ( $this->get( 'AuthorURI' ) ) {
|
||||
$value = sprintf( '<a href="%1$s">%2$s</a>', $this->display( 'AuthorURI', true, $translate ), $value );
|
||||
} elseif ( ! $value ) {
|
||||
$value = __( 'Anonymous' );
|
||||
}
|
||||
break;
|
||||
case 'Tags' :
|
||||
case 'Tags':
|
||||
static $comma = null;
|
||||
if ( ! isset( $comma ) ) {
|
||||
/* translators: used between list items, there is a space after the comma */
|
||||
|
@ -741,8 +843,8 @@ final class WP_Theme implements ArrayAccess {
|
|||
}
|
||||
$value = implode( $comma, $value );
|
||||
break;
|
||||
case 'ThemeURI' :
|
||||
case 'AuthorURI' :
|
||||
case 'ThemeURI':
|
||||
case 'AuthorURI':
|
||||
$value = esc_url( $value );
|
||||
break;
|
||||
}
|
||||
|
@ -763,13 +865,15 @@ final class WP_Theme implements ArrayAccess {
|
|||
*/
|
||||
private function translate_header( $header, $value ) {
|
||||
switch ( $header ) {
|
||||
case 'Name' :
|
||||
case 'Name':
|
||||
// Cached for sorting reasons.
|
||||
if ( isset( $this->name_translated ) )
|
||||
if ( isset( $this->name_translated ) ) {
|
||||
return $this->name_translated;
|
||||
$this->name_translated = translate( $value, $this->get('TextDomain' ) );
|
||||
}
|
||||
// phpcs:ignore WordPress.WP.I18n.LowLevelTranslationFunction,WordPress.WP.I18n.NonSingularStringLiteralText,WordPress.WP.I18n.NonSingularStringLiteralDomain
|
||||
$this->name_translated = translate( $value, $this->get( 'TextDomain' ) );
|
||||
return $this->name_translated;
|
||||
case 'Tags' :
|
||||
case 'Tags':
|
||||
if ( empty( $value ) || ! function_exists( 'get_theme_feature_list' ) ) {
|
||||
return $value;
|
||||
}
|
||||
|
@ -778,14 +882,27 @@ final class WP_Theme implements ArrayAccess {
|
|||
if ( ! isset( $tags_list ) ) {
|
||||
$tags_list = array(
|
||||
// As of 4.6, deprecated tags which are only used to provide translation for older themes.
|
||||
'black' => __( 'Black' ), 'blue' => __( 'Blue' ), 'brown' => __( 'Brown' ),
|
||||
'gray' => __( 'Gray' ), 'green' => __( 'Green' ), 'orange' => __( 'Orange' ),
|
||||
'pink' => __( 'Pink' ), 'purple' => __( 'Purple' ), 'red' => __( 'Red' ),
|
||||
'silver' => __( 'Silver' ), 'tan' => __( 'Tan' ), 'white' => __( 'White' ),
|
||||
'yellow' => __( 'Yellow' ), 'dark' => __( 'Dark' ), 'light' => __( 'Light' ),
|
||||
'fixed-layout' => __( 'Fixed Layout' ), 'fluid-layout' => __( 'Fluid Layout' ),
|
||||
'responsive-layout' => __( 'Responsive Layout' ), 'blavatar' => __( 'Blavatar' ),
|
||||
'photoblogging' => __( 'Photoblogging' ), 'seasonal' => __( 'Seasonal' ),
|
||||
'black' => __( 'Black' ),
|
||||
'blue' => __( 'Blue' ),
|
||||
'brown' => __( 'Brown' ),
|
||||
'gray' => __( 'Gray' ),
|
||||
'green' => __( 'Green' ),
|
||||
'orange' => __( 'Orange' ),
|
||||
'pink' => __( 'Pink' ),
|
||||
'purple' => __( 'Purple' ),
|
||||
'red' => __( 'Red' ),
|
||||
'silver' => __( 'Silver' ),
|
||||
'tan' => __( 'Tan' ),
|
||||
'white' => __( 'White' ),
|
||||
'yellow' => __( 'Yellow' ),
|
||||
'dark' => __( 'Dark' ),
|
||||
'light' => __( 'Light' ),
|
||||
'fixed-layout' => __( 'Fixed Layout' ),
|
||||
'fluid-layout' => __( 'Fluid Layout' ),
|
||||
'responsive-layout' => __( 'Responsive Layout' ),
|
||||
'blavatar' => __( 'Blavatar' ),
|
||||
'photoblogging' => __( 'Photoblogging' ),
|
||||
'seasonal' => __( 'Seasonal' ),
|
||||
);
|
||||
|
||||
$feature_list = get_theme_feature_list( false ); // No API
|
||||
|
@ -804,8 +921,9 @@ final class WP_Theme implements ArrayAccess {
|
|||
|
||||
return $value;
|
||||
|
||||
default :
|
||||
$value = translate( $value, $this->get('TextDomain') );
|
||||
default:
|
||||
// phpcs:ignore WordPress.WP.I18n.LowLevelTranslationFunction,WordPress.WP.I18n.NonSingularStringLiteralText,WordPress.WP.I18n.NonSingularStringLiteralDomain
|
||||
$value = translate( $value, $this->get( 'TextDomain' ) );
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
|
@ -849,8 +967,9 @@ final class WP_Theme implements ArrayAccess {
|
|||
* @return string Absolute path of the stylesheet directory.
|
||||
*/
|
||||
public function get_stylesheet_directory() {
|
||||
if ( $this->errors() && in_array( 'theme_root_missing', $this->errors()->get_error_codes() ) )
|
||||
if ( $this->errors() && in_array( 'theme_root_missing', $this->errors()->get_error_codes() ) ) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return $this->theme_root . '/' . $this->stylesheet;
|
||||
}
|
||||
|
@ -866,10 +985,11 @@ final class WP_Theme implements ArrayAccess {
|
|||
* @return string Absolute path of the template directory.
|
||||
*/
|
||||
public function get_template_directory() {
|
||||
if ( $this->parent() )
|
||||
if ( $this->parent() ) {
|
||||
$theme_root = $this->parent()->theme_root;
|
||||
else
|
||||
} else {
|
||||
$theme_root = $this->theme_root;
|
||||
}
|
||||
|
||||
return $theme_root . '/' . $this->template;
|
||||
}
|
||||
|
@ -899,10 +1019,11 @@ final class WP_Theme implements ArrayAccess {
|
|||
* @return string URL to the template directory.
|
||||
*/
|
||||
public function get_template_directory_uri() {
|
||||
if ( $this->parent() )
|
||||
if ( $this->parent() ) {
|
||||
$theme_root_uri = $this->parent()->get_theme_root_uri();
|
||||
else
|
||||
} else {
|
||||
$theme_root_uri = $this->get_theme_root_uri();
|
||||
}
|
||||
|
||||
return $theme_root_uri . '/' . str_replace( '%2F', '/', rawurlencode( $this->template ) );
|
||||
}
|
||||
|
@ -932,8 +1053,9 @@ final class WP_Theme implements ArrayAccess {
|
|||
* @return string Theme root URI.
|
||||
*/
|
||||
public function get_theme_root_uri() {
|
||||
if ( ! isset( $this->theme_root_uri ) )
|
||||
if ( ! isset( $this->theme_root_uri ) ) {
|
||||
$this->theme_root_uri = get_theme_root_uri( $this->stylesheet, $this->theme_root );
|
||||
}
|
||||
return $this->theme_root_uri;
|
||||
}
|
||||
|
||||
|
@ -953,8 +1075,9 @@ final class WP_Theme implements ArrayAccess {
|
|||
public function get_screenshot( $uri = 'uri' ) {
|
||||
$screenshot = $this->cache_get( 'screenshot' );
|
||||
if ( $screenshot ) {
|
||||
if ( 'relative' == $uri )
|
||||
if ( 'relative' == $uri ) {
|
||||
return $screenshot;
|
||||
}
|
||||
return $this->get_stylesheet_directory_uri() . '/' . $screenshot;
|
||||
} elseif ( 0 === $screenshot ) {
|
||||
return false;
|
||||
|
@ -963,8 +1086,9 @@ final class WP_Theme implements ArrayAccess {
|
|||
foreach ( array( 'png', 'gif', 'jpg', 'jpeg' ) as $ext ) {
|
||||
if ( file_exists( $this->get_stylesheet_directory() . "/screenshot.$ext" ) ) {
|
||||
$this->cache_add( 'screenshot', 'screenshot.' . $ext );
|
||||
if ( 'relative' == $uri )
|
||||
if ( 'relative' == $uri ) {
|
||||
return 'screenshot.' . $ext;
|
||||
}
|
||||
return $this->get_stylesheet_directory_uri() . '/' . 'screenshot.' . $ext;
|
||||
}
|
||||
}
|
||||
|
@ -1013,7 +1137,7 @@ final class WP_Theme implements ArrayAccess {
|
|||
if ( ! is_array( $post_templates ) ) {
|
||||
$post_templates = array();
|
||||
|
||||
$files = (array) $this->get_files( 'php', 1, true);
|
||||
$files = (array) $this->get_files( 'php', 1, true );
|
||||
|
||||
foreach ( $files as $file => $full_path ) {
|
||||
if ( ! preg_match( '|Template Name:(.*)$|mi', file_get_contents( $full_path ), $header ) ) {
|
||||
|
@ -1090,7 +1214,7 @@ final class WP_Theme implements ArrayAccess {
|
|||
* @since 4.4.0 Converted to allow complete control over the `$page_templates` array.
|
||||
* @since 4.7.0 Added the `$post_type` parameter.
|
||||
*
|
||||
* @param array $post_templates Array of page templates. Keys are filenames,
|
||||
* @param string[] $post_templates Array of page templates. Keys are filenames,
|
||||
* values are translated names.
|
||||
* @param WP_Theme $this The theme object.
|
||||
* @param WP_Post|null $post The post being edited, provided for context, or null.
|
||||
|
@ -1106,8 +1230,6 @@ final class WP_Theme implements ArrayAccess {
|
|||
*
|
||||
* @since 3.4.0
|
||||
*
|
||||
* @static
|
||||
*
|
||||
* @param string $path Absolute path to search.
|
||||
* @param array|string|null $extensions Optional. Array of extensions to find, string of a single extension,
|
||||
* or null for all extensions. Default null.
|
||||
|
@ -1125,7 +1247,7 @@ final class WP_Theme implements ArrayAccess {
|
|||
}
|
||||
|
||||
if ( $extensions ) {
|
||||
$extensions = (array) $extensions;
|
||||
$extensions = (array) $extensions;
|
||||
$_extensions = implode( '|', $extensions );
|
||||
}
|
||||
|
||||
|
@ -1135,14 +1257,14 @@ final class WP_Theme implements ArrayAccess {
|
|||
}
|
||||
|
||||
$results = scandir( $path );
|
||||
$files = array();
|
||||
$files = array();
|
||||
|
||||
/**
|
||||
* Filters the array of excluded directories and files while scanning theme folder.
|
||||
*
|
||||
* @since 4.7.4
|
||||
*
|
||||
* @param array $exclusions Array of excluded directories and files.
|
||||
* @param string[] $exclusions Array of excluded directories and files.
|
||||
*/
|
||||
$exclusions = (array) apply_filters( 'theme_scandir_exclusions', array( 'CVS', 'node_modules', 'vendor', 'bower_components' ) );
|
||||
|
||||
|
@ -1154,7 +1276,7 @@ final class WP_Theme implements ArrayAccess {
|
|||
if ( ! $depth ) {
|
||||
continue;
|
||||
}
|
||||
$found = self::scandir( $path . '/' . $result, $extensions, $depth - 1 , $relative_path . $result );
|
||||
$found = self::scandir( $path . '/' . $result, $extensions, $depth - 1, $relative_path . $result );
|
||||
$files = array_merge_recursive( $files, $found );
|
||||
} elseif ( ! $extensions || preg_match( '~\.(' . $_extensions . ')$~', $result ) ) {
|
||||
$files[ $relative_path . $result ] = $path . '/' . $result;
|
||||
|
@ -1173,13 +1295,14 @@ final class WP_Theme implements ArrayAccess {
|
|||
* @since 3.4.0
|
||||
*
|
||||
* @return bool True if the textdomain was successfully loaded or has already been loaded.
|
||||
* False if no textdomain was specified in the file headers, or if the domain could not be loaded.
|
||||
* False if no textdomain was specified in the file headers, or if the domain could not be loaded.
|
||||
*/
|
||||
public function load_textdomain() {
|
||||
if ( isset( $this->textdomain_loaded ) )
|
||||
if ( isset( $this->textdomain_loaded ) ) {
|
||||
return $this->textdomain_loaded;
|
||||
}
|
||||
|
||||
$textdomain = $this->get('TextDomain');
|
||||
$textdomain = $this->get( 'TextDomain' );
|
||||
if ( ! $textdomain ) {
|
||||
$this->textdomain_loaded = false;
|
||||
return false;
|
||||
|
@ -1191,10 +1314,11 @@ final class WP_Theme implements ArrayAccess {
|
|||
}
|
||||
|
||||
$path = $this->get_stylesheet_directory();
|
||||
if ( $domainpath = $this->get('DomainPath') )
|
||||
if ( $domainpath = $this->get( 'DomainPath' ) ) {
|
||||
$path .= $domainpath;
|
||||
else
|
||||
} else {
|
||||
$path .= '/languages';
|
||||
}
|
||||
|
||||
$this->textdomain_loaded = load_theme_textdomain( $textdomain, $path );
|
||||
return $this->textdomain_loaded;
|
||||
|
@ -1206,24 +1330,27 @@ final class WP_Theme implements ArrayAccess {
|
|||
* @since 3.4.0
|
||||
*
|
||||
* @param string $check Optional. Whether to check only the 'network'-wide settings, the 'site'
|
||||
* settings, or 'both'. Defaults to 'both'.
|
||||
* settings, or 'both'. Defaults to 'both'.
|
||||
* @param int $blog_id Optional. Ignored if only network-wide settings are checked. Defaults to current site.
|
||||
* @return bool Whether the theme is allowed for the network. Returns true in single-site.
|
||||
*/
|
||||
public function is_allowed( $check = 'both', $blog_id = null ) {
|
||||
if ( ! is_multisite() )
|
||||
if ( ! is_multisite() ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ( 'both' == $check || 'network' == $check ) {
|
||||
$allowed = self::get_allowed_on_network();
|
||||
if ( ! empty( $allowed[ $this->get_stylesheet() ] ) )
|
||||
if ( ! empty( $allowed[ $this->get_stylesheet() ] ) ) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if ( 'both' == $check || 'site' == $check ) {
|
||||
$allowed = self::get_allowed_on_site( $blog_id );
|
||||
if ( ! empty( $allowed[ $this->get_stylesheet() ] ) )
|
||||
if ( ! empty( $allowed[ $this->get_stylesheet() ] ) ) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
|
@ -1253,10 +1380,8 @@ final class WP_Theme implements ArrayAccess {
|
|||
*
|
||||
* @since 3.4.0
|
||||
*
|
||||
* @static
|
||||
*
|
||||
* @param int $blog_id Optional. ID of the site. Defaults to the current site.
|
||||
* @return array Array of stylesheet names.
|
||||
* @return string[] Array of stylesheet names.
|
||||
*/
|
||||
public static function get_allowed( $blog_id = null ) {
|
||||
/**
|
||||
|
@ -1267,8 +1392,8 @@ final class WP_Theme implements ArrayAccess {
|
|||
*
|
||||
* @since 4.5.0
|
||||
*
|
||||
* @param array $allowed_themes An array of theme stylesheet names.
|
||||
* @param int $blog_id ID of the site.
|
||||
* @param string[] $allowed_themes An array of theme stylesheet names.
|
||||
* @param int $blog_id ID of the site.
|
||||
*/
|
||||
$network = (array) apply_filters( 'network_allowed_themes', self::get_allowed_on_network(), $blog_id );
|
||||
return $network + self::get_allowed_on_site( $blog_id );
|
||||
|
@ -1279,11 +1404,9 @@ final class WP_Theme implements ArrayAccess {
|
|||
*
|
||||
* @since 3.4.0
|
||||
*
|
||||
* @static
|
||||
*
|
||||
* @staticvar array $allowed_themes
|
||||
*
|
||||
* @return array Array of stylesheet names.
|
||||
* @return string[] Array of stylesheet names.
|
||||
*/
|
||||
public static function get_allowed_on_network() {
|
||||
static $allowed_themes;
|
||||
|
@ -1296,7 +1419,7 @@ final class WP_Theme implements ArrayAccess {
|
|||
*
|
||||
* @since MU (3.0.0)
|
||||
*
|
||||
* @param array $allowed_themes An array of theme stylesheet names.
|
||||
* @param string[] $allowed_themes An array of theme stylesheet names.
|
||||
*/
|
||||
$allowed_themes = apply_filters( 'allowed_themes', $allowed_themes );
|
||||
|
||||
|
@ -1308,18 +1431,17 @@ final class WP_Theme implements ArrayAccess {
|
|||
*
|
||||
* @since 3.4.0
|
||||
*
|
||||
* @static
|
||||
*
|
||||
* @staticvar array $allowed_themes
|
||||
*
|
||||
* @param int $blog_id Optional. ID of the site. Defaults to the current site.
|
||||
* @return array Array of stylesheet names.
|
||||
* @return string[] Array of stylesheet names.
|
||||
*/
|
||||
public static function get_allowed_on_site( $blog_id = null ) {
|
||||
static $allowed_themes = array();
|
||||
|
||||
if ( ! $blog_id || ! is_multisite() )
|
||||
if ( ! $blog_id || ! is_multisite() ) {
|
||||
$blog_id = get_current_blog_id();
|
||||
}
|
||||
|
||||
if ( isset( $allowed_themes[ $blog_id ] ) ) {
|
||||
/**
|
||||
|
@ -1327,8 +1449,8 @@ final class WP_Theme implements ArrayAccess {
|
|||
*
|
||||
* @since 4.5.0
|
||||
*
|
||||
* @param array $allowed_themes An array of theme stylesheet names.
|
||||
* @param int $blog_id ID of the site. Defaults to current site.
|
||||
* @param string[] $allowed_themes An array of theme stylesheet names.
|
||||
* @param int $blog_id ID of the site. Defaults to current site.
|
||||
*/
|
||||
return (array) apply_filters( 'site_allowed_themes', $allowed_themes[ $blog_id ], $blog_id );
|
||||
}
|
||||
|
@ -1358,10 +1480,11 @@ final class WP_Theme implements ArrayAccess {
|
|||
$allowed_themes[ $blog_id ] = array();
|
||||
} else {
|
||||
$converted = array();
|
||||
$themes = wp_get_themes();
|
||||
$themes = wp_get_themes();
|
||||
foreach ( $themes as $stylesheet => $theme_data ) {
|
||||
if ( isset( $allowed_themes[ $blog_id ][ $theme_data->get('Name') ] ) )
|
||||
if ( isset( $allowed_themes[ $blog_id ][ $theme_data->get( 'Name' ) ] ) ) {
|
||||
$converted[ $stylesheet ] = true;
|
||||
}
|
||||
}
|
||||
$allowed_themes[ $blog_id ] = $converted;
|
||||
}
|
||||
|
@ -1387,9 +1510,8 @@ final class WP_Theme implements ArrayAccess {
|
|||
* Enables a theme for all sites on the current network.
|
||||
*
|
||||
* @since 4.6.0
|
||||
* @static
|
||||
*
|
||||
* @param string|array $stylesheets Stylesheet name or array of stylesheet names.
|
||||
* @param string|string[] $stylesheets Stylesheet name or array of stylesheet names.
|
||||
*/
|
||||
public static function network_enable_theme( $stylesheets ) {
|
||||
if ( ! is_multisite() ) {
|
||||
|
@ -1412,9 +1534,8 @@ final class WP_Theme implements ArrayAccess {
|
|||
* Disables a theme for all sites on the current network.
|
||||
*
|
||||
* @since 4.6.0
|
||||
* @static
|
||||
*
|
||||
* @param string|array $stylesheets Stylesheet name or array of stylesheet names.
|
||||
* @param string|string[] $stylesheets Stylesheet name or array of stylesheet names.
|
||||
*/
|
||||
public static function network_disable_theme( $stylesheets ) {
|
||||
if ( ! is_multisite() ) {
|
||||
|
@ -1440,14 +1561,15 @@ final class WP_Theme implements ArrayAccess {
|
|||
*
|
||||
* @since 3.4.0
|
||||
*
|
||||
* @static
|
||||
*
|
||||
* @param array $themes Array of themes to sort (passed by reference).
|
||||
* @param WP_Theme[] $themes Array of theme objects to sort (passed by reference).
|
||||
*/
|
||||
public static function sort_by_name( &$themes ) {
|
||||
if ( 0 === strpos( get_user_locale(), 'en_' ) ) {
|
||||
uasort( $themes, array( 'WP_Theme', '_name_sort' ) );
|
||||
} else {
|
||||
foreach ( $themes as $key => $theme ) {
|
||||
$theme->translate_header( 'Name', $theme->headers['Name'] );
|
||||
}
|
||||
uasort( $themes, array( 'WP_Theme', '_name_sort_i18n' ) );
|
||||
}
|
||||
}
|
||||
|
@ -1460,8 +1582,6 @@ final class WP_Theme implements ArrayAccess {
|
|||
*
|
||||
* @since 3.4.0
|
||||
*
|
||||
* @static
|
||||
*
|
||||
* @param string $a First name.
|
||||
* @param string $b Second name.
|
||||
* @return int Negative if `$a` falls lower in the natural order than `$b`. Zero if they fall equally.
|
||||
|
@ -1472,19 +1592,16 @@ final class WP_Theme implements ArrayAccess {
|
|||
}
|
||||
|
||||
/**
|
||||
* Name sort (with translation).
|
||||
* Callback function for usort() to naturally sort themes by translated name.
|
||||
*
|
||||
* @since 3.4.0
|
||||
*
|
||||
* @static
|
||||
*
|
||||
* @param string $a First name.
|
||||
* @param string $b Second name.
|
||||
* @return int Negative if `$a` falls lower in the natural order than `$b`. Zero if they fall equally.
|
||||
* Greater than 0 if `$a` falls higher in the natural order than `$b`. Used with usort().
|
||||
*/
|
||||
private static function _name_sort_i18n( $a, $b ) {
|
||||
// Don't mark up; Do translate.
|
||||
return strnatcasecmp( $a->display( 'Name', false, true ), $b->display( 'Name', false, true ) );
|
||||
return strnatcasecmp( $a->name_translated, $b->name_translated );
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue