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