wp/wp-includes/class-wp-theme.php
author ymh <ymh.work@gmail.com>
Mon, 14 Oct 2019 17:39:30 +0200
changeset 7 cf61fcea0001
parent 5 5e2f62d02dcd
child 9 177826044cd9
permissions -rw-r--r--
resynchronize code repo with production
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     1
<?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     2
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     3
 * WP_Theme Class
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     4
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     5
 * @package WordPress
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     6
 * @subpackage Theme
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
     7
 * @since 3.4.0
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     8
 */
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
     9
final class WP_Theme implements ArrayAccess {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    10
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    11
	/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    12
	 * Whether the theme has been marked as updateable.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    13
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    14
	 * @since 4.4.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    15
	 * @var bool
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    16
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    17
	 * @see WP_MS_Themes_List_Table
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    18
	 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    19
	public $update = false;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    20
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    21
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    22
	 * Headers for style.css files.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    23
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    24
	 * @static
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    25
	 * @var array
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    26
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    27
	private static $file_headers = array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    28
		'Name'        => 'Theme Name',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    29
		'ThemeURI'    => 'Theme URI',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    30
		'Description' => 'Description',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    31
		'Author'      => 'Author',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    32
		'AuthorURI'   => 'Author URI',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    33
		'Version'     => 'Version',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    34
		'Template'    => 'Template',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    35
		'Status'      => 'Status',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    36
		'Tags'        => 'Tags',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    37
		'TextDomain'  => 'Text Domain',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    38
		'DomainPath'  => 'Domain Path',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    39
	);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    40
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    41
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    42
	 * Default themes.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    43
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    44
	 * @static
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    45
	 * @var array
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    46
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    47
	private static $default_themes = array(
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    48
		'classic'         => 'WordPress Classic',
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    49
		'default'         => 'WordPress Default',
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    50
		'twentyten'       => 'Twenty Ten',
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    51
		'twentyeleven'    => 'Twenty Eleven',
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    52
		'twentytwelve'    => 'Twenty Twelve',
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    53
		'twentythirteen'  => 'Twenty Thirteen',
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    54
		'twentyfourteen'  => 'Twenty Fourteen',
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    55
		'twentyfifteen'   => 'Twenty Fifteen',
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    56
		'twentysixteen'   => 'Twenty Sixteen',
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    57
		'twentyseventeen' => 'Twenty Seventeen',
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    58
	);
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    59
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    60
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    61
	 * Renamed theme tags.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    62
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    63
	 * @static
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    64
	 * @var array
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    65
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    66
	private static $tag_map = array(
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    67
		'fixed-width'    => 'fixed-layout',
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    68
		'flexible-width' => 'fluid-layout',
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    69
	);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    70
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    71
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    72
	 * Absolute path to the theme root, usually wp-content/themes
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    73
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    74
	 * @var string
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    75
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    76
	private $theme_root;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    77
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    78
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    79
	 * Header data from the theme's style.css file.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    80
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    81
	 * @var array
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    82
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    83
	private $headers = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    84
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    85
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    86
	 * Header data from the theme's style.css file after being sanitized.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    87
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    88
	 * @var array
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    89
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    90
	private $headers_sanitized;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    91
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    92
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    93
	 * Header name from the theme's style.css after being translated.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    94
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    95
	 * Cached due to sorting functions running over the translated name.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    96
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    97
	 * @var string
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    98
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    99
	private $name_translated;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   100
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   101
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   102
	 * Errors encountered when initializing the theme.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   103
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   104
	 * @var WP_Error
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   105
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   106
	private $errors;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   107
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   108
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   109
	 * The directory name of the theme's files, inside the theme root.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   110
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   111
	 * In the case of a child theme, this is directory name of the child theme.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   112
	 * Otherwise, 'stylesheet' is the same as 'template'.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   113
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   114
	 * @var string
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   115
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   116
	private $stylesheet;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   117
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   118
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   119
	 * The directory name of the theme's files, inside the theme root.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   120
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   121
	 * In the case of a child theme, this is the directory name of the parent theme.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   122
	 * Otherwise, 'template' is the same as 'stylesheet'.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   123
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   124
	 * @var string
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   125
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   126
	private $template;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   127
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   128
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   129
	 * A reference to the parent theme, in the case of a child theme.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   130
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   131
	 * @var WP_Theme
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   132
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   133
	private $parent;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   134
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   135
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   136
	 * URL to the theme root, usually an absolute URL to wp-content/themes
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   137
	 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   138
	 * @var string
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   139
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   140
	private $theme_root_uri;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   141
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   142
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   143
	 * Flag for whether the theme's textdomain is loaded.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   144
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   145
	 * @var bool
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   146
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   147
	private $textdomain_loaded;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   148
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   149
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   150
	 * Stores an md5 hash of the theme root, to function as the cache key.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   151
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   152
	 * @var string
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   153
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   154
	private $cache_hash;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   155
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   156
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   157
	 * Flag for whether the themes cache bucket should be persistently cached.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   158
	 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   159
	 * Default is false. Can be set with the {@see 'wp_cache_themes_persistently'} filter.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   160
	 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   161
	 * @static
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   162
	 * @var bool
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   163
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   164
	private static $persistently_cache;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   165
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   166
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   167
	 * Expiration time for the themes cache bucket.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   168
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   169
	 * By default the bucket is not cached, so this value is useless.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   170
	 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   171
	 * @static
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   172
	 * @var bool
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   173
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   174
	private static $cache_expiration = 1800;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   175
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   176
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   177
	 * Constructor for WP_Theme.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   178
	 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   179
	 * @since  3.4.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   180
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   181
	 * @global array $wp_theme_directories
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   182
	 *
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   183
	 * @param string $theme_dir Directory of the theme within the theme_root.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   184
	 * @param string $theme_root Theme root.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   185
	 * @param WP_Error|void $_child If this theme is a parent theme, the child may be passed for validation purposes.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   186
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   187
	public function __construct( $theme_dir, $theme_root, $_child = null ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   188
		global $wp_theme_directories;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   189
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   190
		// Initialize caching on first run.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   191
		if ( ! isset( self::$persistently_cache ) ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   192
			/** This action is documented in wp-includes/theme.php */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   193
			self::$persistently_cache = apply_filters( 'wp_cache_themes_persistently', false, 'WP_Theme' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   194
			if ( self::$persistently_cache ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   195
				wp_cache_add_global_groups( 'themes' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   196
				if ( is_int( self::$persistently_cache ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   197
					self::$cache_expiration = self::$persistently_cache;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   198
			} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   199
				wp_cache_add_non_persistent_groups( 'themes' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   200
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   201
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   202
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   203
		$this->theme_root = $theme_root;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   204
		$this->stylesheet = $theme_dir;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   205
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   206
		// Correct a situation where the theme is 'some-directory/some-theme' but 'some-directory' was passed in as part of the theme root instead.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   207
		if ( ! in_array( $theme_root, (array) $wp_theme_directories ) && in_array( dirname( $theme_root ), (array) $wp_theme_directories ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   208
			$this->stylesheet = basename( $this->theme_root ) . '/' . $this->stylesheet;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   209
			$this->theme_root = dirname( $theme_root );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   210
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   211
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   212
		$this->cache_hash = md5( $this->theme_root . '/' . $this->stylesheet );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   213
		$theme_file = $this->stylesheet . '/style.css';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   214
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   215
		$cache = $this->cache_get( 'theme' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   216
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   217
		if ( is_array( $cache ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   218
			foreach ( array( 'errors', 'headers', 'template' ) as $key ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   219
				if ( isset( $cache[ $key ] ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   220
					$this->$key = $cache[ $key ];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   221
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   222
			if ( $this->errors )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   223
				return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   224
			if ( isset( $cache['theme_root_template'] ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   225
				$theme_root_template = $cache['theme_root_template'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   226
		} elseif ( ! file_exists( $this->theme_root . '/' . $theme_file ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   227
			$this->headers['Name'] = $this->stylesheet;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   228
			if ( ! file_exists( $this->theme_root . '/' . $this->stylesheet ) )
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   229
				$this->errors = new WP_Error( 'theme_not_found', sprintf( __( 'The theme directory "%s" does not exist.' ), esc_html( $this->stylesheet ) ) );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   230
			else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   231
				$this->errors = new WP_Error( 'theme_no_stylesheet', __( 'Stylesheet is missing.' ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   232
			$this->template = $this->stylesheet;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   233
			$this->cache_add( 'theme', array( 'headers' => $this->headers, 'errors' => $this->errors, 'stylesheet' => $this->stylesheet, 'template' => $this->template ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   234
			if ( ! file_exists( $this->theme_root ) ) // Don't cache this one.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   235
				$this->errors->add( 'theme_root_missing', __( 'ERROR: The themes directory is either empty or doesn&#8217;t exist. Please check your installation.' ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   236
			return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   237
		} elseif ( ! is_readable( $this->theme_root . '/' . $theme_file ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   238
			$this->headers['Name'] = $this->stylesheet;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   239
			$this->errors = new WP_Error( 'theme_stylesheet_not_readable', __( 'Stylesheet is not readable.' ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   240
			$this->template = $this->stylesheet;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   241
			$this->cache_add( 'theme', array( 'headers' => $this->headers, 'errors' => $this->errors, 'stylesheet' => $this->stylesheet, 'template' => $this->template ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   242
			return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   243
		} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   244
			$this->headers = get_file_data( $this->theme_root . '/' . $theme_file, self::$file_headers, 'theme' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   245
			// Default themes always trump their pretenders.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   246
			// Properly identify default themes that are inside a directory within wp-content/themes.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   247
			if ( $default_theme_slug = array_search( $this->headers['Name'], self::$default_themes ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   248
				if ( basename( $this->stylesheet ) != $default_theme_slug )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   249
					$this->headers['Name'] .= '/' . $this->stylesheet;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   250
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   251
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   252
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   253
		if ( ! $this->template && $this->stylesheet === $this->headers['Template'] ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   254
			/* translators: %s: Template */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   255
			$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>' ) );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   256
			$this->cache_add( 'theme', array( 'headers' => $this->headers, 'errors' => $this->errors, 'stylesheet' => $this->stylesheet ) );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   257
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   258
			return;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   259
		}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   260
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   261
		// (If template is set from cache [and there are no errors], we know it's good.)
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   262
		if ( ! $this->template && ! ( $this->template = $this->headers['Template'] ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   263
			$this->template = $this->stylesheet;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   264
			if ( ! file_exists( $this->theme_root . '/' . $this->stylesheet . '/index.php' ) ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   265
				$error_message = sprintf(
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   266
					/* translators: 1: index.php, 2: Codex URL, 3: style.css */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   267
					__( 'Template is missing. Standalone themes need to have a %1$s template file. <a href="%2$s">Child themes</a> need to have a Template header in the %3$s stylesheet.' ),
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   268
					'<code>index.php</code>',
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   269
					__( 'https://codex.wordpress.org/Child_Themes' ),
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   270
					'<code>style.css</code>'
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   271
				);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   272
				$this->errors = new WP_Error( 'theme_no_index', $error_message );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   273
				$this->cache_add( 'theme', array( 'headers' => $this->headers, 'errors' => $this->errors, 'stylesheet' => $this->stylesheet, 'template' => $this->template ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   274
				return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   275
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   276
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   277
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   278
		// If we got our data from cache, we can assume that 'template' is pointing to the right place.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   279
		if ( ! is_array( $cache ) && $this->template != $this->stylesheet && ! file_exists( $this->theme_root . '/' . $this->template . '/index.php' ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   280
			// If we're in a directory of themes inside /themes, look for the parent nearby.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   281
			// wp-content/themes/directory-of-themes/*
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   282
			$parent_dir = dirname( $this->stylesheet );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   283
			if ( '.' != $parent_dir && file_exists( $this->theme_root . '/' . $parent_dir . '/' . $this->template . '/index.php' ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   284
				$this->template = $parent_dir . '/' . $this->template;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   285
			} elseif ( ( $directories = search_theme_directories() ) && isset( $directories[ $this->template ] ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   286
				// Look for the template in the search_theme_directories() results, in case it is in another theme root.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   287
				// We don't look into directories of themes, just the theme root.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   288
				$theme_root_template = $directories[ $this->template ]['theme_root'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   289
			} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   290
				// Parent theme is missing.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   291
				$this->errors = new WP_Error( 'theme_no_parent', sprintf( __( 'The parent theme is missing. Please install the "%s" parent theme.' ), esc_html( $this->template ) ) );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   292
				$this->cache_add( 'theme', array( 'headers' => $this->headers, 'errors' => $this->errors, 'stylesheet' => $this->stylesheet, 'template' => $this->template ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   293
				$this->parent = new WP_Theme( $this->template, $this->theme_root, $this );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   294
				return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   295
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   296
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   297
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   298
		// Set the parent, if we're a child theme.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   299
		if ( $this->template != $this->stylesheet ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   300
			// If we are a parent, then there is a problem. Only two generations allowed! Cancel things out.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   301
			if ( $_child instanceof WP_Theme && $_child->template == $this->stylesheet ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   302
				$_child->parent = null;
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   303
				$_child->errors = new WP_Error( 'theme_parent_invalid', sprintf( __( 'The "%s" theme is not a valid parent theme.' ), esc_html( $_child->template ) ) );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   304
				$_child->cache_add( 'theme', array( 'headers' => $_child->headers, 'errors' => $_child->errors, 'stylesheet' => $_child->stylesheet, 'template' => $_child->template ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   305
				// The two themes actually reference each other with the Template header.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   306
				if ( $_child->stylesheet == $this->template ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   307
					$this->errors = new WP_Error( 'theme_parent_invalid', sprintf( __( 'The "%s" theme is not a valid parent theme.' ), esc_html( $this->template ) ) );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   308
					$this->cache_add( 'theme', array( 'headers' => $this->headers, 'errors' => $this->errors, 'stylesheet' => $this->stylesheet, 'template' => $this->template ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   309
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   310
				return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   311
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   312
			// Set the parent. Pass the current instance so we can do the crazy checks above and assess errors.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   313
			$this->parent = new WP_Theme( $this->template, isset( $theme_root_template ) ? $theme_root_template : $this->theme_root, $this );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   314
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   315
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   316
		// We're good. If we didn't retrieve from cache, set it.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   317
		if ( ! is_array( $cache ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   318
			$cache = array( 'headers' => $this->headers, 'errors' => $this->errors, 'stylesheet' => $this->stylesheet, 'template' => $this->template );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   319
			// If the parent theme is in another root, we'll want to cache this. Avoids an entire branch of filesystem calls above.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   320
			if ( isset( $theme_root_template ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   321
				$cache['theme_root_template'] = $theme_root_template;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   322
			$this->cache_add( 'theme', $cache );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   323
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   324
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   325
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   326
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   327
	 * When converting the object to a string, the theme name is returned.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   328
	 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   329
	 * @since  3.4.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   330
	 *
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   331
	 * @return string Theme name, ready for display (translated)
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   332
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   333
	public function __toString() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   334
		return (string) $this->display('Name');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   335
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   336
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   337
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   338
	 * __isset() magic method for properties formerly returned by current_theme_info()
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   339
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   340
	 * @staticvar array $properties
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   341
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   342
	 * @since  3.4.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   343
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   344
	 * @param string $offset Property to check if set.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   345
	 * @return bool Whether the given property is set.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   346
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   347
	public function __isset( $offset ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   348
		static $properties = array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   349
			'name', 'title', 'version', 'parent_theme', 'template_dir', 'stylesheet_dir', 'template', 'stylesheet',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   350
			'screenshot', 'description', 'author', 'tags', 'theme_root', 'theme_root_uri',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   351
		);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   352
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   353
		return in_array( $offset, $properties );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   354
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   355
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   356
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   357
	 * __get() magic method for properties formerly returned by current_theme_info()
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   358
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   359
	 * @since  3.4.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   360
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   361
	 * @param string $offset Property to get.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   362
	 * @return mixed Property value.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   363
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   364
	public function __get( $offset ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   365
		switch ( $offset ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   366
			case 'name' :
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   367
			case 'title' :
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   368
				return $this->get('Name');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   369
			case 'version' :
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   370
				return $this->get('Version');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   371
			case 'parent_theme' :
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   372
				return $this->parent() ? $this->parent()->get('Name') : '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   373
			case 'template_dir' :
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   374
				return $this->get_template_directory();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   375
			case 'stylesheet_dir' :
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   376
				return $this->get_stylesheet_directory();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   377
			case 'template' :
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   378
				return $this->get_template();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   379
			case 'stylesheet' :
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   380
				return $this->get_stylesheet();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   381
			case 'screenshot' :
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   382
				return $this->get_screenshot( 'relative' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   383
			// 'author' and 'description' did not previously return translated data.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   384
			case 'description' :
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   385
				return $this->display('Description');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   386
			case 'author' :
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   387
				return $this->display('Author');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   388
			case 'tags' :
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   389
				return $this->get( 'Tags' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   390
			case 'theme_root' :
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   391
				return $this->get_theme_root();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   392
			case 'theme_root_uri' :
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   393
				return $this->get_theme_root_uri();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   394
			// For cases where the array was converted to an object.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   395
			default :
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   396
				return $this->offsetGet( $offset );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   397
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   398
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   399
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   400
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   401
	 * Method to implement ArrayAccess for keys formerly returned by get_themes()
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   402
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   403
	 * @since  3.4.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   404
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   405
	 * @param mixed $offset
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   406
	 * @param mixed $value
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   407
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   408
	public function offsetSet( $offset, $value ) {}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   409
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   410
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   411
	 * Method to implement ArrayAccess for keys formerly returned by get_themes()
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   412
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   413
	 * @since  3.4.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   414
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   415
	 * @param mixed $offset
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   416
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   417
	public function offsetUnset( $offset ) {}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   418
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   419
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   420
	 * Method to implement ArrayAccess for keys formerly returned by get_themes()
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   421
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   422
	 * @staticvar array $keys
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   423
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   424
	 * @since  3.4.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   425
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   426
	 * @param mixed $offset
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   427
	 * @return bool
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   428
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   429
	public function offsetExists( $offset ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   430
		static $keys = array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   431
			'Name', 'Version', 'Status', 'Title', 'Author', 'Author Name', 'Author URI', 'Description',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   432
			'Template', 'Stylesheet', 'Template Files', 'Stylesheet Files', 'Template Dir', 'Stylesheet Dir',
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   433
			'Screenshot', 'Tags', 'Theme Root', 'Theme Root URI', 'Parent Theme',
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   434
		);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   435
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   436
		return in_array( $offset, $keys );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   437
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   438
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   439
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   440
	 * Method to implement ArrayAccess for keys formerly returned by get_themes().
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   441
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   442
	 * Author, Author Name, Author URI, and Description did not previously return
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   443
	 * translated data. We are doing so now as it is safe to do. However, as
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   444
	 * Name and Title could have been used as the key for get_themes(), both remain
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   445
	 * untranslated for back compatibility. This means that ['Name'] is not ideal,
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   446
	 * and care should be taken to use `$theme::display( 'Name' )` to get a properly
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   447
	 * translated header.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   448
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   449
	 * @since  3.4.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   450
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   451
	 * @param mixed $offset
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   452
	 * @return mixed
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   453
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   454
	public function offsetGet( $offset ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   455
		switch ( $offset ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   456
			case 'Name' :
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   457
			case 'Title' :
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   458
				/*
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   459
				 * See note above about using translated data. get() is not ideal.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   460
				 * It is only for backward compatibility. Use display().
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   461
				 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   462
				return $this->get('Name');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   463
			case 'Author' :
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   464
				return $this->display( 'Author');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   465
			case 'Author Name' :
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   466
				return $this->display( 'Author', false);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   467
			case 'Author URI' :
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   468
				return $this->display('AuthorURI');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   469
			case 'Description' :
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   470
				return $this->display( 'Description');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   471
			case 'Version' :
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   472
			case 'Status' :
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   473
				return $this->get( $offset );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   474
			case 'Template' :
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   475
				return $this->get_template();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   476
			case 'Stylesheet' :
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   477
				return $this->get_stylesheet();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   478
			case 'Template Files' :
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   479
				return $this->get_files( 'php', 1, true );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   480
			case 'Stylesheet Files' :
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   481
				return $this->get_files( 'css', 0, false );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   482
			case 'Template Dir' :
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   483
				return $this->get_template_directory();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   484
			case 'Stylesheet Dir' :
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   485
				return $this->get_stylesheet_directory();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   486
			case 'Screenshot' :
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   487
				return $this->get_screenshot( 'relative' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   488
			case 'Tags' :
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   489
				return $this->get('Tags');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   490
			case 'Theme Root' :
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   491
				return $this->get_theme_root();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   492
			case 'Theme Root URI' :
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   493
				return $this->get_theme_root_uri();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   494
			case 'Parent Theme' :
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   495
				return $this->parent() ? $this->parent()->get('Name') : '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   496
			default :
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   497
				return null;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   498
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   499
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   500
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   501
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   502
	 * Returns errors property.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   503
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   504
	 * @since 3.4.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   505
	 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   506
	 * @return WP_Error|false WP_Error if there are errors, or false.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   507
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   508
	public function errors() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   509
		return is_wp_error( $this->errors ) ? $this->errors : false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   510
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   511
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   512
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   513
	 * Whether the theme exists.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   514
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   515
	 * A theme with errors exists. A theme with the error of 'theme_not_found',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   516
	 * meaning that the theme's directory was not found, does not exist.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   517
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   518
	 * @since 3.4.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   519
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   520
	 * @return bool Whether the theme exists.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   521
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   522
	public function exists() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   523
		return ! ( $this->errors() && in_array( 'theme_not_found', $this->errors()->get_error_codes() ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   524
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   525
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   526
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   527
	 * Returns reference to the parent theme.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   528
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   529
	 * @since 3.4.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   530
	 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   531
	 * @return WP_Theme|false Parent theme, or false if the current theme is not a child theme.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   532
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   533
	public function parent() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   534
		return isset( $this->parent ) ? $this->parent : false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   535
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   536
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   537
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   538
	 * Adds theme data to cache.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   539
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   540
	 * Cache entries keyed by the theme and the type of data.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   541
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   542
	 * @since 3.4.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   543
	 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   544
	 * @param string $key Type of data to store (theme, screenshot, headers, post_templates)
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   545
	 * @param string $data Data to store
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   546
	 * @return bool Return value from wp_cache_add()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   547
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   548
	private function cache_add( $key, $data ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   549
		return wp_cache_add( $key . '-' . $this->cache_hash, $data, 'themes', self::$cache_expiration );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   550
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   551
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   552
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   553
	 * Gets theme data from cache.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   554
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   555
	 * Cache entries are keyed by the theme and the type of data.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   556
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   557
	 * @since 3.4.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   558
	 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   559
	 * @param string $key Type of data to retrieve (theme, screenshot, headers, post_templates)
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   560
	 * @return mixed Retrieved data
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   561
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   562
	private function cache_get( $key ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   563
		return wp_cache_get( $key . '-' . $this->cache_hash, 'themes' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   564
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   565
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   566
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   567
	 * Clears the cache for the theme.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   568
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   569
	 * @since 3.4.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   570
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   571
	public function cache_delete() {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   572
		foreach ( array( 'theme', 'screenshot', 'headers', 'post_templates' ) as $key )
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   573
			wp_cache_delete( $key . '-' . $this->cache_hash, 'themes' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   574
		$this->template = $this->textdomain_loaded = $this->theme_root_uri = $this->parent = $this->errors = $this->headers_sanitized = $this->name_translated = null;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   575
		$this->headers = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   576
		$this->__construct( $this->stylesheet, $this->theme_root );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   577
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   578
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   579
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   580
	 * Get a raw, unformatted theme header.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   581
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   582
	 * The header is sanitized, but is not translated, and is not marked up for display.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   583
	 * To get a theme header for display, use the display() method.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   584
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   585
	 * Use the get_template() method, not the 'Template' header, for finding the template.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   586
	 * The 'Template' header is only good for what was written in the style.css, while
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   587
	 * get_template() takes into account where WordPress actually located the theme and
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   588
	 * whether it is actually valid.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   589
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   590
	 * @since 3.4.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   591
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   592
	 * @param string $header Theme header. Name, Description, Author, Version, ThemeURI, AuthorURI, Status, Tags.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   593
	 * @return string|false String on success, false on failure.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   594
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   595
	public function get( $header ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   596
		if ( ! isset( $this->headers[ $header ] ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   597
			return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   598
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   599
		if ( ! isset( $this->headers_sanitized ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   600
			$this->headers_sanitized = $this->cache_get( 'headers' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   601
			if ( ! is_array( $this->headers_sanitized ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   602
				$this->headers_sanitized = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   603
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   604
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   605
		if ( isset( $this->headers_sanitized[ $header ] ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   606
			return $this->headers_sanitized[ $header ];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   607
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   608
		// If themes are a persistent group, sanitize everything and cache it. One cache add is better than many cache sets.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   609
		if ( self::$persistently_cache ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   610
			foreach ( array_keys( $this->headers ) as $_header )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   611
				$this->headers_sanitized[ $_header ] = $this->sanitize_header( $_header, $this->headers[ $_header ] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   612
			$this->cache_add( 'headers', $this->headers_sanitized );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   613
		} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   614
			$this->headers_sanitized[ $header ] = $this->sanitize_header( $header, $this->headers[ $header ] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   615
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   616
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   617
		return $this->headers_sanitized[ $header ];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   618
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   619
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   620
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   621
	 * Gets a theme header, formatted and translated for display.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   622
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   623
	 * @since 3.4.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   624
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   625
	 * @param string $header Theme header. Name, Description, Author, Version, ThemeURI, AuthorURI, Status, Tags.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   626
	 * @param bool $markup Optional. Whether to mark up the header. Defaults to true.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   627
	 * @param bool $translate Optional. Whether to translate the header. Defaults to true.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   628
	 * @return string|false Processed header, false on failure.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   629
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   630
	public function display( $header, $markup = true, $translate = true ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   631
		$value = $this->get( $header );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   632
		if ( false === $value ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   633
			return false;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   634
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   635
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   636
		if ( $translate && ( empty( $value ) || ! $this->load_textdomain() ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   637
			$translate = false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   638
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   639
		if ( $translate )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   640
			$value = $this->translate_header( $header, $value );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   641
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   642
		if ( $markup )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   643
			$value = $this->markup_header( $header, $value, $translate );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   644
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   645
		return $value;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   646
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   647
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   648
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   649
	 * Sanitize a theme header.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   650
	 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   651
	 * @since 3.4.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   652
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   653
	 * @staticvar array $header_tags
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   654
	 * @staticvar array $header_tags_with_a
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   655
	 *
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   656
	 * @param string $header Theme header. Name, Description, Author, Version, ThemeURI, AuthorURI, Status, Tags.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   657
	 * @param string $value Value to sanitize.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   658
	 * @return mixed
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   659
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   660
	private function sanitize_header( $header, $value ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   661
		switch ( $header ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   662
			case 'Status' :
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   663
				if ( ! $value ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   664
					$value = 'publish';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   665
					break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   666
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   667
				// Fall through otherwise.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   668
			case 'Name' :
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   669
				static $header_tags = array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   670
					'abbr'    => array( 'title' => true ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   671
					'acronym' => array( 'title' => true ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   672
					'code'    => true,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   673
					'em'      => true,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   674
					'strong'  => true,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   675
				);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   676
				$value = wp_kses( $value, $header_tags );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   677
				break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   678
			case 'Author' :
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   679
				// There shouldn't be anchor tags in Author, but some themes like to be challenging.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   680
			case 'Description' :
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   681
				static $header_tags_with_a = array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   682
					'a'       => array( 'href' => true, 'title' => true ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   683
					'abbr'    => array( 'title' => true ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   684
					'acronym' => array( 'title' => true ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   685
					'code'    => true,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   686
					'em'      => true,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   687
					'strong'  => true,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   688
				);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   689
				$value = wp_kses( $value, $header_tags_with_a );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   690
				break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   691
			case 'ThemeURI' :
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   692
			case 'AuthorURI' :
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   693
				$value = esc_url_raw( $value );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   694
				break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   695
			case 'Tags' :
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   696
				$value = array_filter( array_map( 'trim', explode( ',', strip_tags( $value ) ) ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   697
				break;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   698
			case 'Version' :
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   699
				$value = strip_tags( $value );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   700
				break;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   701
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   702
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   703
		return $value;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   704
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   705
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   706
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   707
	 * Mark up a theme header.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   708
	 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   709
     * @since 3.4.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   710
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   711
	 * @staticvar string $comma
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   712
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   713
	 * @param string $header Theme header. Name, Description, Author, Version, ThemeURI, AuthorURI, Status, Tags.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   714
	 * @param string $value Value to mark up.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   715
	 * @param string $translate Whether the header has been translated.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   716
	 * @return string Value, marked up.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   717
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   718
	private function markup_header( $header, $value, $translate ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   719
		switch ( $header ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   720
			case 'Name' :
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   721
				if ( empty( $value ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   722
					$value = esc_html( $this->get_stylesheet() );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   723
				}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   724
				break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   725
			case 'Description' :
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   726
				$value = wptexturize( $value );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   727
				break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   728
			case 'Author' :
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   729
				if ( $this->get('AuthorURI') ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   730
					$value = sprintf( '<a href="%1$s">%2$s</a>', $this->display( 'AuthorURI', true, $translate ), $value );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   731
				} elseif ( ! $value ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   732
					$value = __( 'Anonymous' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   733
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   734
				break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   735
			case 'Tags' :
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   736
				static $comma = null;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   737
				if ( ! isset( $comma ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   738
					/* translators: used between list items, there is a space after the comma */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   739
					$comma = __( ', ' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   740
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   741
				$value = implode( $comma, $value );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   742
				break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   743
			case 'ThemeURI' :
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   744
			case 'AuthorURI' :
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   745
				$value = esc_url( $value );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   746
				break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   747
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   748
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   749
		return $value;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   750
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   751
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   752
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   753
	 * Translate a theme header.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   754
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   755
	 * @since 3.4.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   756
	 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   757
	 * @staticvar array $tags_list
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   758
	 *
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   759
	 * @param string $header Theme header. Name, Description, Author, Version, ThemeURI, AuthorURI, Status, Tags.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   760
	 * @param string $value Value to translate.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   761
	 * @return string Translated value.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   762
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   763
	private function translate_header( $header, $value ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   764
		switch ( $header ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   765
			case 'Name' :
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   766
				// Cached for sorting reasons.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   767
				if ( isset( $this->name_translated ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   768
					return $this->name_translated;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   769
				$this->name_translated = translate( $value, $this->get('TextDomain' ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   770
				return $this->name_translated;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   771
			case 'Tags' :
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   772
				if ( empty( $value ) || ! function_exists( 'get_theme_feature_list' ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   773
					return $value;
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   774
				}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   775
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   776
				static $tags_list;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   777
				if ( ! isset( $tags_list ) ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   778
					$tags_list = array(
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   779
						// As of 4.6, deprecated tags which are only used to provide translation for older themes.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   780
						'black' => __( 'Black' ), 'blue' => __( 'Blue' ), 'brown'  => __( 'Brown' ),
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   781
						'gray' => __( 'Gray' ), 'green'  => __( 'Green' ), 'orange' => __( 'Orange' ),
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   782
						'pink' => __( 'Pink' ), 'purple' => __( 'Purple' ), 'red' => __( 'Red' ),
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   783
						'silver' => __( 'Silver' ), 'tan' => __( 'Tan' ), 'white' => __( 'White' ),
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   784
						'yellow' => __( 'Yellow' ), 'dark' => __( 'Dark' ), 'light' => __( 'Light' ),
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   785
						'fixed-layout' => __( 'Fixed Layout' ), 'fluid-layout' => __( 'Fluid Layout' ),
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   786
						'responsive-layout' => __( 'Responsive Layout' ), 'blavatar' => __( 'Blavatar' ),
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   787
						'photoblogging' => __( 'Photoblogging' ), 'seasonal' => __( 'Seasonal' ),
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   788
					);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   789
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   790
					$feature_list = get_theme_feature_list( false ); // No API
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   791
					foreach ( $feature_list as $tags ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   792
						$tags_list += $tags;
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   793
					}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   794
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   795
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   796
				foreach ( $value as &$tag ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   797
					if ( isset( $tags_list[ $tag ] ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   798
						$tag = $tags_list[ $tag ];
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   799
					} elseif ( isset( self::$tag_map[ $tag ] ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   800
						$tag = $tags_list[ self::$tag_map[ $tag ] ];
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   801
					}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   802
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   803
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   804
				return $value;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   805
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   806
			default :
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   807
				$value = translate( $value, $this->get('TextDomain') );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   808
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   809
		return $value;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   810
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   811
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   812
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   813
	 * The directory name of the theme's "stylesheet" files, inside the theme root.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   814
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   815
	 * In the case of a child theme, this is directory name of the child theme.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   816
	 * Otherwise, get_stylesheet() is the same as get_template().
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   817
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   818
	 * @since 3.4.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   819
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   820
	 * @return string Stylesheet
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   821
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   822
	public function get_stylesheet() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   823
		return $this->stylesheet;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   824
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   825
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   826
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   827
	 * The directory name of the theme's "template" files, inside the theme root.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   828
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   829
	 * In the case of a child theme, this is the directory name of the parent theme.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   830
	 * Otherwise, the get_template() is the same as get_stylesheet().
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   831
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   832
	 * @since 3.4.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   833
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   834
	 * @return string Template
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   835
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   836
	public function get_template() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   837
		return $this->template;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   838
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   839
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   840
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   841
	 * Returns the absolute path to the directory of a theme's "stylesheet" files.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   842
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   843
	 * In the case of a child theme, this is the absolute path to the directory
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   844
	 * of the child theme's files.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   845
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   846
	 * @since 3.4.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   847
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   848
	 * @return string Absolute path of the stylesheet directory.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   849
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   850
	public function get_stylesheet_directory() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   851
		if ( $this->errors() && in_array( 'theme_root_missing', $this->errors()->get_error_codes() ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   852
			return '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   853
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   854
		return $this->theme_root . '/' . $this->stylesheet;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   855
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   856
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   857
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   858
	 * Returns the absolute path to the directory of a theme's "template" files.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   859
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   860
	 * In the case of a child theme, this is the absolute path to the directory
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   861
	 * of the parent theme's files.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   862
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   863
	 * @since 3.4.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   864
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   865
	 * @return string Absolute path of the template directory.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   866
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   867
	public function get_template_directory() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   868
		if ( $this->parent() )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   869
			$theme_root = $this->parent()->theme_root;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   870
		else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   871
			$theme_root = $this->theme_root;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   872
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   873
		return $theme_root . '/' . $this->template;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   874
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   875
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   876
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   877
	 * Returns the URL to the directory of a theme's "stylesheet" files.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   878
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   879
	 * In the case of a child theme, this is the URL to the directory of the
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   880
	 * child theme's files.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   881
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   882
	 * @since 3.4.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   883
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   884
	 * @return string URL to the stylesheet directory.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   885
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   886
	public function get_stylesheet_directory_uri() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   887
		return $this->get_theme_root_uri() . '/' . str_replace( '%2F', '/', rawurlencode( $this->stylesheet ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   888
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   889
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   890
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   891
	 * Returns the URL to the directory of a theme's "template" files.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   892
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   893
	 * In the case of a child theme, this is the URL to the directory of the
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   894
	 * parent theme's files.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   895
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   896
	 * @since 3.4.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   897
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   898
	 * @return string URL to the template directory.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   899
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   900
	public function get_template_directory_uri() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   901
		if ( $this->parent() )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   902
			$theme_root_uri = $this->parent()->get_theme_root_uri();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   903
		else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   904
			$theme_root_uri = $this->get_theme_root_uri();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   905
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   906
		return $theme_root_uri . '/' . str_replace( '%2F', '/', rawurlencode( $this->template ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   907
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   908
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   909
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   910
	 * The absolute path to the directory of the theme root.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   911
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   912
	 * This is typically the absolute path to wp-content/themes.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   913
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   914
	 * @since 3.4.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   915
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   916
	 * @return string Theme root.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   917
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   918
	public function get_theme_root() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   919
		return $this->theme_root;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   920
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   921
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   922
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   923
	 * Returns the URL to the directory of the theme root.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   924
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   925
	 * This is typically the absolute URL to wp-content/themes. This forms the basis
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   926
	 * for all other URLs returned by WP_Theme, so we pass it to the public function
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   927
	 * get_theme_root_uri() and allow it to run the {@see 'theme_root_uri'} filter.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   928
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   929
	 * @since 3.4.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   930
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   931
	 * @return string Theme root URI.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   932
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   933
	public function get_theme_root_uri() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   934
		if ( ! isset( $this->theme_root_uri ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   935
			$this->theme_root_uri = get_theme_root_uri( $this->stylesheet, $this->theme_root );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   936
		return $this->theme_root_uri;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   937
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   938
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   939
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   940
	 * Returns the main screenshot file for the theme.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   941
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   942
	 * The main screenshot is called screenshot.png. gif and jpg extensions are also allowed.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   943
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   944
	 * Screenshots for a theme must be in the stylesheet directory. (In the case of child
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   945
	 * themes, parent theme screenshots are not inherited.)
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   946
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   947
	 * @since 3.4.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   948
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   949
	 * @param string $uri Type of URL to return, either 'relative' or an absolute URI. Defaults to absolute URI.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   950
	 * @return string|false Screenshot file. False if the theme does not have a screenshot.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   951
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   952
	public function get_screenshot( $uri = 'uri' ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   953
		$screenshot = $this->cache_get( 'screenshot' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   954
		if ( $screenshot ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   955
			if ( 'relative' == $uri )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   956
				return $screenshot;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   957
			return $this->get_stylesheet_directory_uri() . '/' . $screenshot;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   958
		} elseif ( 0 === $screenshot ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   959
			return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   960
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   961
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   962
		foreach ( array( 'png', 'gif', 'jpg', 'jpeg' ) as $ext ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   963
			if ( file_exists( $this->get_stylesheet_directory() . "/screenshot.$ext" ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   964
				$this->cache_add( 'screenshot', 'screenshot.' . $ext );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   965
				if ( 'relative' == $uri )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   966
					return 'screenshot.' . $ext;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   967
				return $this->get_stylesheet_directory_uri() . '/' . 'screenshot.' . $ext;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   968
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   969
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   970
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   971
		$this->cache_add( 'screenshot', 0 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   972
		return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   973
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   974
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   975
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   976
	 * Return files in the theme's directory.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   977
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   978
	 * @since 3.4.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   979
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   980
	 * @param mixed $type Optional. Array of extensions to return. Defaults to all files (null).
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   981
	 * @param int $depth Optional. How deep to search for files. Defaults to a flat scan (0 depth). -1 depth is infinite.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   982
	 * @param bool $search_parent Optional. Whether to return parent files. Defaults to false.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   983
	 * @return array Array of files, keyed by the path to the file relative to the theme's directory, with the values
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   984
	 *               being absolute paths.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   985
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   986
	public function get_files( $type = null, $depth = 0, $search_parent = false ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   987
		$files = (array) self::scandir( $this->get_stylesheet_directory(), $type, $depth );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   988
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   989
		if ( $search_parent && $this->parent() ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   990
			$files += (array) self::scandir( $this->get_template_directory(), $type, $depth );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   991
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   992
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   993
		return $files;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   994
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   995
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   996
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   997
	 * Returns the theme's post templates.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   998
	 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   999
	 * @since 4.7.0
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1000
	 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1001
	 * @return array Array of page templates, keyed by filename and post type,
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1002
	 *               with the value of the translated header name.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1003
	 */
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1004
	public function get_post_templates() {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1005
		// If you screw up your current theme and we invalidate your parent, most things still work. Let it slide.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1006
		if ( $this->errors() && $this->errors()->get_error_codes() !== array( 'theme_parent_invalid' ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1007
			return array();
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1008
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1009
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1010
		$post_templates = $this->cache_get( 'post_templates' );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1011
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1012
		if ( ! is_array( $post_templates ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1013
			$post_templates = array();
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1014
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1015
			$files = (array) $this->get_files( 'php', 1, true);
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1016
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1017
			foreach ( $files as $file => $full_path ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1018
				if ( ! preg_match( '|Template Name:(.*)$|mi', file_get_contents( $full_path ), $header ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1019
					continue;
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1020
				}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1021
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1022
				$types = array( 'page' );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1023
				if ( preg_match( '|Template Post Type:(.*)$|mi', file_get_contents( $full_path ), $type ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1024
					$types = explode( ',', _cleanup_header_comment( $type[1] ) );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1025
				}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1026
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1027
				foreach ( $types as $type ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1028
					$type = sanitize_key( $type );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1029
					if ( ! isset( $post_templates[ $type ] ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1030
						$post_templates[ $type ] = array();
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1031
					}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1032
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1033
					$post_templates[ $type ][ $file ] = _cleanup_header_comment( $header[1] );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1034
				}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1035
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1036
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1037
			$this->cache_add( 'post_templates', $post_templates );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1038
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1039
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1040
		if ( $this->load_textdomain() ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1041
			foreach ( $post_templates as &$post_type ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1042
				foreach ( $post_type as &$post_template ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1043
					$post_template = $this->translate_header( 'Template Name', $post_template );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1044
				}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1045
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1046
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1047
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1048
		return $post_templates;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1049
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1050
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1051
	/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1052
	 * Returns the theme's post templates for a given post type.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1053
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1054
	 * @since 3.4.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1055
	 * @since 4.7.0 Added the `$post_type` parameter.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1056
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1057
	 * @param WP_Post|null $post      Optional. The post being edited, provided for context.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1058
	 * @param string       $post_type Optional. Post type to get the templates for. Default 'page'.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1059
	 *                                If a post is provided, its post type is used.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1060
	 * @return array Array of page templates, keyed by filename, with the value of the translated header name.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1061
	 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1062
	public function get_page_templates( $post = null, $post_type = 'page' ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1063
		if ( $post ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1064
			$post_type = get_post_type( $post );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1065
		}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1066
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1067
		$post_templates = $this->get_post_templates();
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1068
		$post_templates = isset( $post_templates[ $post_type ] ) ? $post_templates[ $post_type ] : array();
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1069
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1070
		/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1071
		 * Filters list of page templates for a theme.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1072
		 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1073
		 * @since 4.9.6
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1074
		 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1075
		 * @param string[]     $post_templates Array of page templates. Keys are filenames,
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1076
		 *                                     values are translated names.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1077
		 * @param WP_Theme     $this           The theme object.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1078
		 * @param WP_Post|null $post           The post being edited, provided for context, or null.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1079
		 * @param string       $post_type      Post type to get the templates for.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1080
		 */
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1081
		$post_templates = (array) apply_filters( 'theme_templates', $post_templates, $this, $post, $post_type );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1082
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1083
		/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1084
		 * Filters list of page templates for a theme.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1085
		 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1086
		 * The dynamic portion of the hook name, `$post_type`, refers to the post type.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1087
		 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1088
		 * @since 3.9.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1089
		 * @since 4.4.0 Converted to allow complete control over the `$page_templates` array.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1090
		 * @since 4.7.0 Added the `$post_type` parameter.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1091
		 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1092
		 * @param array        $post_templates Array of page templates. Keys are filenames,
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1093
		 *                                     values are translated names.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1094
		 * @param WP_Theme     $this           The theme object.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1095
		 * @param WP_Post|null $post           The post being edited, provided for context, or null.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1096
		 * @param string       $post_type      Post type to get the templates for.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1097
		 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1098
		$post_templates = (array) apply_filters( "theme_{$post_type}_templates", $post_templates, $this, $post, $post_type );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1099
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1100
		return $post_templates;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1101
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1102
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1103
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1104
	 * Scans a directory for files of a certain extension.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1105
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1106
	 * @since 3.4.0
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1107
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1108
	 * @static
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1109
	 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1110
	 * @param string            $path          Absolute path to search.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1111
	 * @param array|string|null $extensions    Optional. Array of extensions to find, string of a single extension,
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1112
	 *                                         or null for all extensions. Default null.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1113
	 * @param int               $depth         Optional. How many levels deep to search for files. Accepts 0, 1+, or
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1114
	 *                                         -1 (infinite depth). Default 0.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1115
	 * @param string            $relative_path Optional. The basename of the absolute path. Used to control the
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1116
	 *                                         returned path for the found files, particularly when this function
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1117
	 *                                         recurses to lower depths. Default empty.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1118
	 * @return array|false Array of files, keyed by the path to the file relative to the `$path` directory prepended
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1119
	 *                     with `$relative_path`, with the values being absolute paths. False otherwise.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1120
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1121
	private static function scandir( $path, $extensions = null, $depth = 0, $relative_path = '' ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1122
		if ( ! is_dir( $path ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1123
			return false;
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1124
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1125
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1126
		if ( $extensions ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1127
			$extensions = (array) $extensions;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1128
			$_extensions = implode( '|', $extensions );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1129
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1130
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1131
		$relative_path = trailingslashit( $relative_path );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1132
		if ( '/' == $relative_path ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1133
			$relative_path = '';
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1134
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1135
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1136
		$results = scandir( $path );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1137
		$files = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1138
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1139
		/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1140
		 * Filters the array of excluded directories and files while scanning theme folder.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1141
		 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1142
		 * @since 4.7.4
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1143
		 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1144
		 * @param array $exclusions Array of excluded directories and files.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1145
		 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1146
		$exclusions = (array) apply_filters( 'theme_scandir_exclusions', array( 'CVS', 'node_modules', 'vendor', 'bower_components' ) );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1147
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1148
		foreach ( $results as $result ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1149
			if ( '.' == $result[0] || in_array( $result, $exclusions, true ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1150
				continue;
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1151
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1152
			if ( is_dir( $path . '/' . $result ) ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1153
				if ( ! $depth ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1154
					continue;
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1155
				}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1156
				$found = self::scandir( $path . '/' . $result, $extensions, $depth - 1 , $relative_path . $result );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1157
				$files = array_merge_recursive( $files, $found );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1158
			} elseif ( ! $extensions || preg_match( '~\.(' . $_extensions . ')$~', $result ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1159
				$files[ $relative_path . $result ] = $path . '/' . $result;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1160
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1161
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1162
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1163
		return $files;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1164
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1165
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1166
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1167
	 * Loads the theme's textdomain.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1168
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1169
	 * Translation files are not inherited from the parent theme. Todo: if this fails for the
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1170
	 * child theme, it should probably try to load the parent theme's translations.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1171
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1172
	 * @since 3.4.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1173
	 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1174
	 * @return bool True if the textdomain was successfully loaded or has already been loaded.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1175
	 * 	False if no textdomain was specified in the file headers, or if the domain could not be loaded.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1176
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1177
	public function load_textdomain() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1178
		if ( isset( $this->textdomain_loaded ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1179
			return $this->textdomain_loaded;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1180
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1181
		$textdomain = $this->get('TextDomain');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1182
		if ( ! $textdomain ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1183
			$this->textdomain_loaded = false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1184
			return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1185
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1186
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1187
		if ( is_textdomain_loaded( $textdomain ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1188
			$this->textdomain_loaded = true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1189
			return true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1190
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1191
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1192
		$path = $this->get_stylesheet_directory();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1193
		if ( $domainpath = $this->get('DomainPath') )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1194
			$path .= $domainpath;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1195
		else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1196
			$path .= '/languages';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1197
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1198
		$this->textdomain_loaded = load_theme_textdomain( $textdomain, $path );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1199
		return $this->textdomain_loaded;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1200
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1201
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1202
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1203
	 * Whether the theme is allowed (multisite only).
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1204
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1205
	 * @since 3.4.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1206
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1207
	 * @param string $check Optional. Whether to check only the 'network'-wide settings, the 'site'
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1208
	 * 	settings, or 'both'. Defaults to 'both'.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1209
	 * @param int $blog_id Optional. Ignored if only network-wide settings are checked. Defaults to current site.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1210
	 * @return bool Whether the theme is allowed for the network. Returns true in single-site.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1211
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1212
	public function is_allowed( $check = 'both', $blog_id = null ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1213
		if ( ! is_multisite() )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1214
			return true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1215
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1216
		if ( 'both' == $check || 'network' == $check ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1217
			$allowed = self::get_allowed_on_network();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1218
			if ( ! empty( $allowed[ $this->get_stylesheet() ] ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1219
				return true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1220
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1221
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1222
		if ( 'both' == $check || 'site' == $check ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1223
			$allowed = self::get_allowed_on_site( $blog_id );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1224
			if ( ! empty( $allowed[ $this->get_stylesheet() ] ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1225
				return true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1226
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1227
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1228
		return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1229
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1230
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1231
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1232
	 * Determines the latest WordPress default theme that is installed.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1233
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1234
	 * This hits the filesystem.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1235
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1236
	 * @since  4.4.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1237
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1238
	 * @return WP_Theme|false Object, or false if no theme is installed, which would be bad.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1239
	 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1240
	public static function get_core_default_theme() {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1241
		foreach ( array_reverse( self::$default_themes ) as $slug => $name ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1242
			$theme = wp_get_theme( $slug );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1243
			if ( $theme->exists() ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1244
				return $theme;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1245
			}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1246
		}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1247
		return false;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1248
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1249
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1250
	/**
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1251
	 * Returns array of stylesheet names of themes allowed on the site or network.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1252
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1253
	 * @since 3.4.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1254
	 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1255
	 * @static
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1256
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1257
	 * @param int $blog_id Optional. ID of the site. Defaults to the current site.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1258
	 * @return array Array of stylesheet names.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1259
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1260
	public static function get_allowed( $blog_id = null ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1261
		/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1262
		 * Filters the array of themes allowed on the network.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1263
		 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1264
		 * Site is provided as context so that a list of network allowed themes can
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1265
		 * be filtered further.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1266
		 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1267
		 * @since 4.5.0
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1268
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1269
		 * @param array $allowed_themes An array of theme stylesheet names.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1270
		 * @param int   $blog_id        ID of the site.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1271
		 */
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1272
		$network = (array) apply_filters( 'network_allowed_themes', self::get_allowed_on_network(), $blog_id );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1273
		return $network + self::get_allowed_on_site( $blog_id );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1274
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1275
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1276
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1277
	 * Returns array of stylesheet names of themes allowed on the network.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1278
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1279
	 * @since 3.4.0
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1280
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1281
	 * @static
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1282
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1283
	 * @staticvar array $allowed_themes
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1284
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1285
	 * @return array Array of stylesheet names.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1286
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1287
	public static function get_allowed_on_network() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1288
		static $allowed_themes;
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1289
		if ( ! isset( $allowed_themes ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1290
			$allowed_themes = (array) get_site_option( 'allowedthemes' );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1291
		}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1292
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1293
		/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1294
		 * Filters the array of themes allowed on the network.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1295
		 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1296
		 * @since MU (3.0.0)
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1297
		 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1298
		 * @param array $allowed_themes An array of theme stylesheet names.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1299
		 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1300
		$allowed_themes = apply_filters( 'allowed_themes', $allowed_themes );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1301
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1302
		return $allowed_themes;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1303
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1304
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1305
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1306
	 * Returns array of stylesheet names of themes allowed on the site.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1307
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1308
	 * @since 3.4.0
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1309
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1310
	 * @static
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1311
	 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1312
	 * @staticvar array $allowed_themes
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1313
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1314
	 * @param int $blog_id Optional. ID of the site. Defaults to the current site.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1315
	 * @return array Array of stylesheet names.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1316
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1317
	public static function get_allowed_on_site( $blog_id = null ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1318
		static $allowed_themes = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1319
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1320
		if ( ! $blog_id || ! is_multisite() )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1321
			$blog_id = get_current_blog_id();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1322
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1323
		if ( isset( $allowed_themes[ $blog_id ] ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1324
			/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1325
			 * Filters the array of themes allowed on the site.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1326
			 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1327
			 * @since 4.5.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1328
			 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1329
			 * @param array $allowed_themes An array of theme stylesheet names.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1330
			 * @param int   $blog_id        ID of the site. Defaults to current site.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1331
			 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1332
			return (array) apply_filters( 'site_allowed_themes', $allowed_themes[ $blog_id ], $blog_id );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1333
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1334
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1335
		$current = $blog_id == get_current_blog_id();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1336
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1337
		if ( $current ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1338
			$allowed_themes[ $blog_id ] = get_option( 'allowedthemes' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1339
		} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1340
			switch_to_blog( $blog_id );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1341
			$allowed_themes[ $blog_id ] = get_option( 'allowedthemes' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1342
			restore_current_blog();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1343
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1344
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1345
		// This is all super old MU back compat joy.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1346
		// 'allowedthemes' keys things by stylesheet. 'allowed_themes' keyed things by name.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1347
		if ( false === $allowed_themes[ $blog_id ] ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1348
			if ( $current ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1349
				$allowed_themes[ $blog_id ] = get_option( 'allowed_themes' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1350
			} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1351
				switch_to_blog( $blog_id );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1352
				$allowed_themes[ $blog_id ] = get_option( 'allowed_themes' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1353
				restore_current_blog();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1354
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1355
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1356
			if ( ! is_array( $allowed_themes[ $blog_id ] ) || empty( $allowed_themes[ $blog_id ] ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1357
				$allowed_themes[ $blog_id ] = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1358
			} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1359
				$converted = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1360
				$themes = wp_get_themes();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1361
				foreach ( $themes as $stylesheet => $theme_data ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1362
					if ( isset( $allowed_themes[ $blog_id ][ $theme_data->get('Name') ] ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1363
						$converted[ $stylesheet ] = true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1364
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1365
				$allowed_themes[ $blog_id ] = $converted;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1366
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1367
			// Set the option so we never have to go through this pain again.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1368
			if ( is_admin() && $allowed_themes[ $blog_id ] ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1369
				if ( $current ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1370
					update_option( 'allowedthemes', $allowed_themes[ $blog_id ] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1371
					delete_option( 'allowed_themes' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1372
				} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1373
					switch_to_blog( $blog_id );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1374
					update_option( 'allowedthemes', $allowed_themes[ $blog_id ] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1375
					delete_option( 'allowed_themes' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1376
					restore_current_blog();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1377
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1378
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1379
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1380
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1381
		/** This filter is documented in wp-includes/class-wp-theme.php */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1382
		return (array) apply_filters( 'site_allowed_themes', $allowed_themes[ $blog_id ], $blog_id );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1383
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1384
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1385
	/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1386
	 * Enables a theme for all sites on the current network.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1387
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1388
	 * @since 4.6.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1389
	 * @static
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1390
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1391
	 * @param string|array $stylesheets Stylesheet name or array of stylesheet names.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1392
	 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1393
	public static function network_enable_theme( $stylesheets ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1394
		if ( ! is_multisite() ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1395
			return;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1396
		}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1397
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1398
		if ( ! is_array( $stylesheets ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1399
			$stylesheets = array( $stylesheets );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1400
		}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1401
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1402
		$allowed_themes = get_site_option( 'allowedthemes' );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1403
		foreach ( $stylesheets as $stylesheet ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1404
			$allowed_themes[ $stylesheet ] = true;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1405
		}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1406
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1407
		update_site_option( 'allowedthemes', $allowed_themes );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1408
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1409
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1410
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1411
	 * Disables a theme for all sites on the current network.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1412
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1413
	 * @since 4.6.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1414
	 * @static
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1415
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1416
	 * @param string|array $stylesheets Stylesheet name or array of stylesheet names.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1417
	 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1418
	public static function network_disable_theme( $stylesheets ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1419
		if ( ! is_multisite() ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1420
			return;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1421
		}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1422
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1423
		if ( ! is_array( $stylesheets ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1424
			$stylesheets = array( $stylesheets );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1425
		}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1426
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1427
		$allowed_themes = get_site_option( 'allowedthemes' );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1428
		foreach ( $stylesheets as $stylesheet ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1429
			if ( isset( $allowed_themes[ $stylesheet ] ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1430
				unset( $allowed_themes[ $stylesheet ] );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1431
			}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1432
		}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1433
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1434
		update_site_option( 'allowedthemes', $allowed_themes );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1435
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1436
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1437
	/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1438
	 * Sorts themes by name.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1439
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1440
	 * @since 3.4.0
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1441
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1442
	 * @static
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1443
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1444
	 * @param array $themes Array of themes to sort (passed by reference).
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1445
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1446
	public static function sort_by_name( &$themes ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1447
		if ( 0 === strpos( get_user_locale(), 'en_' ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1448
			uasort( $themes, array( 'WP_Theme', '_name_sort' ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1449
		} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1450
			uasort( $themes, array( 'WP_Theme', '_name_sort_i18n' ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1451
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1452
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1453
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1454
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1455
	 * Callback function for usort() to naturally sort themes by name.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1456
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1457
	 * Accesses the Name header directly from the class for maximum speed.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1458
	 * Would choke on HTML but we don't care enough to slow it down with strip_tags().
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1459
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1460
	 * @since 3.4.0
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1461
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1462
	 * @static
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1463
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1464
	 * @param string $a First name.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1465
	 * @param string $b Second name.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1466
	 * @return int Negative if `$a` falls lower in the natural order than `$b`. Zero if they fall equally.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1467
	 *             Greater than 0 if `$a` falls higher in the natural order than `$b`. Used with usort().
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1468
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1469
	private static function _name_sort( $a, $b ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1470
		return strnatcasecmp( $a->headers['Name'], $b->headers['Name'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1471
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1472
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1473
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1474
	 * Name sort (with translation).
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1475
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1476
	 * @since 3.4.0
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1477
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1478
	 * @static
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1479
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1480
	 * @param string $a First name.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1481
	 * @param string $b Second name.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1482
	 * @return int Negative if `$a` falls lower in the natural order than `$b`. Zero if they fall equally.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1483
	 *             Greater than 0 if `$a` falls higher in the natural order than `$b`. Used with usort().
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1484
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1485
	private static function _name_sort_i18n( $a, $b ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1486
		// Don't mark up; Do translate.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1487
		return strnatcasecmp( $a->display( 'Name', false, true ), $b->display( 'Name', false, true ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1488
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1489
}