wp/wp-includes/theme.php
author ymh <ymh.work@gmail.com>
Mon, 14 Oct 2019 18:28:13 +0200
changeset 9 177826044cd9
parent 7 cf61fcea0001
child 16 a86126ab1dd4
permissions -rw-r--r--
upgrade wordpress to 5.2.3
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
 * Theme, template, and stylesheet functions.
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
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     7
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     8
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     9
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    10
 * Returns an array of WP_Theme objects based on the arguments.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    11
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    12
 * Despite advances over get_themes(), this function is quite expensive, and grows
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    13
 * linearly with additional themes. Stick to wp_get_theme() if possible.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    14
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    15
 * @since 3.4.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    16
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    17
 * @global array $wp_theme_directories
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    18
 * @staticvar array $_themes
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    19
 *
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    20
 * @param array $args {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    21
 *     Optional. The search arguments.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    22
 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    23
 *     @type mixed $errors  True to return themes with errors, false to return themes without errors, null to return all themes.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    24
 *                          Defaults to false.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    25
 *     @type mixed $allowed (Multisite) True to return only allowed themes for a site. False to return only disallowed themes for a site.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    26
 *                          'site' to return only site-allowed themes. 'network' to return only network-allowed themes.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    27
 *                          Null to return all themes. Defaults to null.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    28
 *     @type int   $blog_id (Multisite) The blog ID used to calculate which themes are allowed.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    29
 *                          Defaults to 0, synonymous for the current blog.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    30
 * }
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    31
 * @return WP_Theme[] Array of WP_Theme objects.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    32
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    33
function wp_get_themes( $args = array() ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    34
	global $wp_theme_directories;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    35
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    36
	$defaults = array(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    37
		'errors'  => false,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    38
		'allowed' => null,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    39
		'blog_id' => 0,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    40
	);
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    41
	$args     = wp_parse_args( $args, $defaults );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    42
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    43
	$theme_directories = search_theme_directories();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    44
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    45
	if ( is_array( $wp_theme_directories ) && count( $wp_theme_directories ) > 1 ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    46
		// Make sure the current theme wins out, in case search_theme_directories() picks the wrong
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    47
		// one in the case of a conflict. (Normally, last registered theme root wins.)
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    48
		$current_theme = get_stylesheet();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    49
		if ( isset( $theme_directories[ $current_theme ] ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    50
			$root_of_current_theme = get_raw_theme_root( $current_theme );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    51
			if ( ! in_array( $root_of_current_theme, $wp_theme_directories ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    52
				$root_of_current_theme = WP_CONTENT_DIR . $root_of_current_theme;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    53
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    54
			$theme_directories[ $current_theme ]['theme_root'] = $root_of_current_theme;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    55
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    56
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    57
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    58
	if ( empty( $theme_directories ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    59
		return array();
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    60
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    61
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    62
	if ( is_multisite() && null !== $args['allowed'] ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    63
		$allowed = $args['allowed'];
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    64
		if ( 'network' === $allowed ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    65
			$theme_directories = array_intersect_key( $theme_directories, WP_Theme::get_allowed_on_network() );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    66
		} elseif ( 'site' === $allowed ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    67
			$theme_directories = array_intersect_key( $theme_directories, WP_Theme::get_allowed_on_site( $args['blog_id'] ) );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    68
		} elseif ( $allowed ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    69
			$theme_directories = array_intersect_key( $theme_directories, WP_Theme::get_allowed( $args['blog_id'] ) );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    70
		} else {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    71
			$theme_directories = array_diff_key( $theme_directories, WP_Theme::get_allowed( $args['blog_id'] ) );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    72
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    73
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    74
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    75
	$themes         = array();
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    76
	static $_themes = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    77
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    78
	foreach ( $theme_directories as $theme => $theme_root ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    79
		if ( isset( $_themes[ $theme_root['theme_root'] . '/' . $theme ] ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    80
			$themes[ $theme ] = $_themes[ $theme_root['theme_root'] . '/' . $theme ];
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    81
		} else {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    82
			$themes[ $theme ] = $_themes[ $theme_root['theme_root'] . '/' . $theme ] = new WP_Theme( $theme, $theme_root['theme_root'] );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    83
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    84
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    85
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    86
	if ( null !== $args['errors'] ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    87
		foreach ( $themes as $theme => $wp_theme ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    88
			if ( $wp_theme->errors() != $args['errors'] ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    89
				unset( $themes[ $theme ] );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    90
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    91
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    92
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    93
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    94
	return $themes;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    95
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    96
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    97
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    98
 * Gets a WP_Theme object for a theme.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    99
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   100
 * @since 3.4.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   101
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   102
 * @global array $wp_theme_directories
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   103
 *
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   104
 * @param string $stylesheet Directory name for the theme. Optional. Defaults to current theme.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   105
 * @param string $theme_root Absolute path of the theme root to look in. Optional. If not specified, get_raw_theme_root()
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   106
 *                           is used to calculate the theme root for the $stylesheet provided (or current theme).
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   107
 * @return WP_Theme Theme object. Be sure to check the object's exists() method if you need to confirm the theme's existence.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   108
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   109
function wp_get_theme( $stylesheet = null, $theme_root = null ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   110
	global $wp_theme_directories;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   111
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   112
	if ( empty( $stylesheet ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   113
		$stylesheet = get_stylesheet();
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   114
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   115
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   116
	if ( empty( $theme_root ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   117
		$theme_root = get_raw_theme_root( $stylesheet );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   118
		if ( false === $theme_root ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   119
			$theme_root = WP_CONTENT_DIR . '/themes';
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   120
		} elseif ( ! in_array( $theme_root, (array) $wp_theme_directories ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   121
			$theme_root = WP_CONTENT_DIR . $theme_root;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   122
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   123
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   124
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   125
	return new WP_Theme( $stylesheet, $theme_root );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   126
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   127
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   128
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   129
 * Clears the cache held by get_theme_roots() and 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
 * @since 3.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   132
 * @param bool $clear_update_cache Whether to clear the Theme updates cache
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   133
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   134
function wp_clean_themes_cache( $clear_update_cache = true ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   135
	if ( $clear_update_cache ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   136
		delete_site_transient( 'update_themes' );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   137
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   138
	search_theme_directories( true );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   139
	foreach ( wp_get_themes( array( 'errors' => null ) ) as $theme ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   140
		$theme->cache_delete();
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   141
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   142
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   143
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   144
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   145
 * Whether a child theme is in use.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   146
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   147
 * @since 3.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   148
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   149
 * @return bool true if a child theme is in use, false otherwise.
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   150
 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   151
function is_child_theme() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   152
	return ( TEMPLATEPATH !== STYLESHEETPATH );
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
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   156
 * Retrieve name of the current stylesheet.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   157
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   158
 * The theme name that the administrator has currently set the front end theme
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   159
 * as.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   160
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   161
 * For all intents and purposes, the template name and the stylesheet name are
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   162
 * going to be the same for most cases.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   163
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   164
 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   165
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   166
 * @return string Stylesheet name.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   167
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   168
function get_stylesheet() {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   169
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   170
	 * Filters the name of current stylesheet.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   171
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   172
	 * @since 1.5.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   173
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   174
	 * @param string $stylesheet Name of the current stylesheet.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   175
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   176
	return apply_filters( 'stylesheet', get_option( 'stylesheet' ) );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   177
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   178
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   179
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   180
 * Retrieve stylesheet directory path for current theme.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   181
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   182
 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   183
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   184
 * @return string Path to current theme directory.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   185
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   186
function get_stylesheet_directory() {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   187
	$stylesheet     = get_stylesheet();
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   188
	$theme_root     = get_theme_root( $stylesheet );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   189
	$stylesheet_dir = "$theme_root/$stylesheet";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   190
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   191
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   192
	 * Filters the stylesheet directory path for current theme.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   193
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   194
	 * @since 1.5.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   195
	 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   196
	 * @param string $stylesheet_dir Absolute path to the current theme.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   197
	 * @param string $stylesheet     Directory name of the current theme.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   198
	 * @param string $theme_root     Absolute path to themes directory.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   199
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   200
	return apply_filters( 'stylesheet_directory', $stylesheet_dir, $stylesheet, $theme_root );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   201
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   202
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   203
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   204
 * Retrieve stylesheet directory URI.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   205
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   206
 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   207
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   208
 * @return string
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   209
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   210
function get_stylesheet_directory_uri() {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   211
	$stylesheet         = str_replace( '%2F', '/', rawurlencode( get_stylesheet() ) );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   212
	$theme_root_uri     = get_theme_root_uri( $stylesheet );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   213
	$stylesheet_dir_uri = "$theme_root_uri/$stylesheet";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   214
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   215
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   216
	 * Filters the stylesheet directory URI.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   217
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   218
	 * @since 1.5.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   219
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   220
	 * @param string $stylesheet_dir_uri Stylesheet directory URI.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   221
	 * @param string $stylesheet         Name of the activated theme's directory.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   222
	 * @param string $theme_root_uri     Themes root URI.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   223
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   224
	return apply_filters( 'stylesheet_directory_uri', $stylesheet_dir_uri, $stylesheet, $theme_root_uri );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   225
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   226
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   227
/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   228
 * Retrieves the URI of current theme stylesheet.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   229
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   230
 * The stylesheet file name is 'style.css' which is appended to the stylesheet directory URI path.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   231
 * See get_stylesheet_directory_uri().
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   232
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   233
 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   234
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   235
 * @return string
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   236
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   237
function get_stylesheet_uri() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   238
	$stylesheet_dir_uri = get_stylesheet_directory_uri();
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   239
	$stylesheet_uri     = $stylesheet_dir_uri . '/style.css';
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   240
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   241
	 * Filters the URI of the current theme stylesheet.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   242
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   243
	 * @since 1.5.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   244
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   245
	 * @param string $stylesheet_uri     Stylesheet URI for the current theme/child theme.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   246
	 * @param string $stylesheet_dir_uri Stylesheet directory URI for the current theme/child theme.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   247
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   248
	return apply_filters( 'stylesheet_uri', $stylesheet_uri, $stylesheet_dir_uri );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   249
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   250
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   251
/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   252
 * Retrieves the localized stylesheet URI.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   253
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   254
 * The stylesheet directory for the localized stylesheet files are located, by
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   255
 * default, in the base theme directory. The name of the locale file will be the
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   256
 * locale followed by '.css'. If that does not exist, then the text direction
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   257
 * stylesheet will be checked for existence, for example 'ltr.css'.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   258
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   259
 * The theme may change the location of the stylesheet directory by either using
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   260
 * the {@see 'stylesheet_directory_uri'} or {@see 'locale_stylesheet_uri'} filters.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   261
 *
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   262
 * If you want to change the location of the stylesheet files for the entire
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   263
 * WordPress workflow, then change the former. If you just have the locale in a
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   264
 * separate folder, then change the latter.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   265
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   266
 * @since 2.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   267
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   268
 * @global WP_Locale $wp_locale
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   269
 *
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   270
 * @return string
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   271
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   272
function get_locale_stylesheet_uri() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   273
	global $wp_locale;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   274
	$stylesheet_dir_uri = get_stylesheet_directory_uri();
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   275
	$dir                = get_stylesheet_directory();
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   276
	$locale             = get_locale();
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   277
	if ( file_exists( "$dir/$locale.css" ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   278
		$stylesheet_uri = "$stylesheet_dir_uri/$locale.css";
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   279
	} elseif ( ! empty( $wp_locale->text_direction ) && file_exists( "$dir/{$wp_locale->text_direction}.css" ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   280
		$stylesheet_uri = "$stylesheet_dir_uri/{$wp_locale->text_direction}.css";
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   281
	} else {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   282
		$stylesheet_uri = '';
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   283
	}
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   284
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   285
	 * Filters the localized stylesheet URI.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   286
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   287
	 * @since 2.1.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   288
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   289
	 * @param string $stylesheet_uri     Localized stylesheet URI.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   290
	 * @param string $stylesheet_dir_uri Stylesheet directory URI.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   291
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   292
	return apply_filters( 'locale_stylesheet_uri', $stylesheet_uri, $stylesheet_dir_uri );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   293
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   294
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   295
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   296
 * Retrieve name of the current theme.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   297
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   298
 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   299
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   300
 * @return string Template name.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   301
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   302
function get_template() {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   303
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   304
	 * Filters the name of the current theme.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   305
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   306
	 * @since 1.5.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   307
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   308
	 * @param string $template Current theme's directory name.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   309
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   310
	return apply_filters( 'template', get_option( 'template' ) );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   311
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   312
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   313
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   314
 * Retrieve current theme directory.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   315
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   316
 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   317
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   318
 * @return string Template directory path.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   319
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   320
function get_template_directory() {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   321
	$template     = get_template();
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   322
	$theme_root   = get_theme_root( $template );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   323
	$template_dir = "$theme_root/$template";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   324
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   325
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   326
	 * Filters the current theme directory path.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   327
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   328
	 * @since 1.5.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   329
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   330
	 * @param string $template_dir The URI of the current theme directory.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   331
	 * @param string $template     Directory name of the current theme.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   332
	 * @param string $theme_root   Absolute path to the themes directory.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   333
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   334
	return apply_filters( 'template_directory', $template_dir, $template, $theme_root );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   335
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   336
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   337
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   338
 * Retrieve theme directory URI.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   339
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   340
 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   341
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   342
 * @return string Template directory URI.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   343
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   344
function get_template_directory_uri() {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   345
	$template         = str_replace( '%2F', '/', rawurlencode( get_template() ) );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   346
	$theme_root_uri   = get_theme_root_uri( $template );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   347
	$template_dir_uri = "$theme_root_uri/$template";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   348
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   349
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   350
	 * Filters the current theme directory URI.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   351
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   352
	 * @since 1.5.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   353
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   354
	 * @param string $template_dir_uri The URI of the current theme directory.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   355
	 * @param string $template         Directory name of the current theme.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   356
	 * @param string $theme_root_uri   The themes root URI.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   357
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   358
	return apply_filters( 'template_directory_uri', $template_dir_uri, $template, $theme_root_uri );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   359
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   360
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   361
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   362
 * Retrieve theme roots.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   363
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   364
 * @since 2.9.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   365
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   366
 * @global array $wp_theme_directories
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   367
 *
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   368
 * @return array|string An array of theme roots keyed by template/stylesheet or a single theme root if all themes have the same root.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   369
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   370
function get_theme_roots() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   371
	global $wp_theme_directories;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   372
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   373
	if ( ! is_array( $wp_theme_directories ) || count( $wp_theme_directories ) <= 1 ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   374
		return '/themes';
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   375
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   376
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   377
	$theme_roots = get_site_transient( 'theme_roots' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   378
	if ( false === $theme_roots ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   379
		search_theme_directories( true ); // Regenerate the transient.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   380
		$theme_roots = get_site_transient( 'theme_roots' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   381
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   382
	return $theme_roots;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   383
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   384
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   385
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   386
 * Register a directory that contains themes.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   387
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   388
 * @since 2.9.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   389
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   390
 * @global array $wp_theme_directories
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   391
 *
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   392
 * @param string $directory Either the full filesystem path to a theme folder or a folder within WP_CONTENT_DIR
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   393
 * @return bool
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   394
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   395
function register_theme_directory( $directory ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   396
	global $wp_theme_directories;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   397
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   398
	if ( ! file_exists( $directory ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   399
		// Try prepending as the theme directory could be relative to the content directory
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   400
		$directory = WP_CONTENT_DIR . '/' . $directory;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   401
		// If this directory does not exist, return and do not register
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   402
		if ( ! file_exists( $directory ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   403
			return false;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   404
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   405
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   406
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   407
	if ( ! is_array( $wp_theme_directories ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   408
		$wp_theme_directories = array();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   409
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   410
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   411
	$untrailed = untrailingslashit( $directory );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   412
	if ( ! empty( $untrailed ) && ! in_array( $untrailed, $wp_theme_directories ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   413
		$wp_theme_directories[] = $untrailed;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   414
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   415
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   416
	return true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   417
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   418
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   419
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   420
 * Search all registered theme directories for complete and valid themes.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   421
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   422
 * @since 2.9.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   423
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   424
 * @global array $wp_theme_directories
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   425
 * @staticvar array $found_themes
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   426
 *
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   427
 * @param bool $force Optional. Whether to force a new directory scan. Defaults to false.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   428
 * @return array|false Valid themes found
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   429
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   430
function search_theme_directories( $force = false ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   431
	global $wp_theme_directories;
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   432
	static $found_themes = null;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   433
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   434
	if ( empty( $wp_theme_directories ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   435
		return false;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   436
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   437
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   438
	if ( ! $force && isset( $found_themes ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   439
		return $found_themes;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   440
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   441
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   442
	$found_themes = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   443
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   444
	$wp_theme_directories = (array) $wp_theme_directories;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   445
	$relative_theme_roots = array();
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   446
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   447
	// Set up maybe-relative, maybe-absolute array of theme directories.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   448
	// We always want to return absolute, but we need to cache relative
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   449
	// to use in get_theme_root().
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   450
	foreach ( $wp_theme_directories as $theme_root ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   451
		if ( 0 === strpos( $theme_root, WP_CONTENT_DIR ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   452
			$relative_theme_roots[ str_replace( WP_CONTENT_DIR, '', $theme_root ) ] = $theme_root;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   453
		} else {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   454
			$relative_theme_roots[ $theme_root ] = $theme_root;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   455
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   456
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   457
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   458
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   459
	 * Filters whether to get the cache of the registered theme directories.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   460
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   461
	 * @since 3.4.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   462
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   463
	 * @param bool   $cache_expiration Whether to get the cache of the theme directories. Default false.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   464
	 * @param string $cache_directory  Directory to be searched for the cache.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   465
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   466
	if ( $cache_expiration = apply_filters( 'wp_cache_themes_persistently', false, 'search_theme_directories' ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   467
		$cached_roots = get_site_transient( 'theme_roots' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   468
		if ( is_array( $cached_roots ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   469
			foreach ( $cached_roots as $theme_dir => $theme_root ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   470
				// A cached theme root is no longer around, so skip it.
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   471
				if ( ! isset( $relative_theme_roots[ $theme_root ] ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   472
					continue;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   473
				}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   474
				$found_themes[ $theme_dir ] = array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   475
					'theme_file' => $theme_dir . '/style.css',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   476
					'theme_root' => $relative_theme_roots[ $theme_root ], // Convert relative to absolute.
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
			return $found_themes;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   480
		}
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   481
		if ( ! is_int( $cache_expiration ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   482
			$cache_expiration = 1800; // half hour
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   483
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   484
	} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   485
		$cache_expiration = 1800; // half hour
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   486
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   487
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   488
	/* Loop the registered theme directories and extract all themes */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   489
	foreach ( $wp_theme_directories as $theme_root ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   490
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   491
		// Start with directories in the root of the current theme directory.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   492
		$dirs = @ scandir( $theme_root );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   493
		if ( ! $dirs ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   494
			trigger_error( "$theme_root is not readable", E_USER_NOTICE );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   495
			continue;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   496
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   497
		foreach ( $dirs as $dir ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   498
			if ( ! is_dir( $theme_root . '/' . $dir ) || $dir[0] == '.' || $dir == 'CVS' ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   499
				continue;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   500
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   501
			if ( file_exists( $theme_root . '/' . $dir . '/style.css' ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   502
				// wp-content/themes/a-single-theme
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   503
				// wp-content/themes is $theme_root, a-single-theme is $dir
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   504
				$found_themes[ $dir ] = array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   505
					'theme_file' => $dir . '/style.css',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   506
					'theme_root' => $theme_root,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   507
				);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   508
			} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   509
				$found_theme = false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   510
				// wp-content/themes/a-folder-of-themes/*
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   511
				// wp-content/themes is $theme_root, a-folder-of-themes is $dir, then themes are $sub_dirs
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   512
				$sub_dirs = @ scandir( $theme_root . '/' . $dir );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   513
				if ( ! $sub_dirs ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   514
					trigger_error( "$theme_root/$dir is not readable", E_USER_NOTICE );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   515
					continue;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   516
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   517
				foreach ( $sub_dirs as $sub_dir ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   518
					if ( ! is_dir( $theme_root . '/' . $dir . '/' . $sub_dir ) || $dir[0] == '.' || $dir == 'CVS' ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   519
						continue;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   520
					}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   521
					if ( ! file_exists( $theme_root . '/' . $dir . '/' . $sub_dir . '/style.css' ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   522
						continue;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   523
					}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   524
					$found_themes[ $dir . '/' . $sub_dir ] = array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   525
						'theme_file' => $dir . '/' . $sub_dir . '/style.css',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   526
						'theme_root' => $theme_root,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   527
					);
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   528
					$found_theme                           = true;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   529
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   530
				// Never mind the above, it's just a theme missing a style.css.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   531
				// Return it; WP_Theme will catch the error.
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   532
				if ( ! $found_theme ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   533
					$found_themes[ $dir ] = array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   534
						'theme_file' => $dir . '/style.css',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   535
						'theme_root' => $theme_root,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   536
					);
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   537
				}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   538
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   539
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   540
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   541
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   542
	asort( $found_themes );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   543
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   544
	$theme_roots          = array();
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   545
	$relative_theme_roots = array_flip( $relative_theme_roots );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   546
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   547
	foreach ( $found_themes as $theme_dir => $theme_data ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   548
		$theme_roots[ $theme_dir ] = $relative_theme_roots[ $theme_data['theme_root'] ]; // Convert absolute to relative.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   549
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   550
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   551
	if ( $theme_roots != get_site_transient( 'theme_roots' ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   552
		set_site_transient( 'theme_roots', $theme_roots, $cache_expiration );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   553
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   554
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   555
	return $found_themes;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   556
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   557
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   558
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   559
 * Retrieve path to themes directory.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   560
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   561
 * Does not have trailing slash.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   562
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   563
 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   564
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   565
 * @global array $wp_theme_directories
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   566
 *
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   567
 * @param string $stylesheet_or_template The stylesheet or template name of the theme
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   568
 * @return string Theme path.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   569
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   570
function get_theme_root( $stylesheet_or_template = false ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   571
	global $wp_theme_directories;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   572
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   573
	if ( $stylesheet_or_template && $theme_root = get_raw_theme_root( $stylesheet_or_template ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   574
		// Always prepend WP_CONTENT_DIR unless the root currently registered as a theme directory.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   575
		// This gives relative theme roots the benefit of the doubt when things go haywire.
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   576
		if ( ! in_array( $theme_root, (array) $wp_theme_directories ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   577
			$theme_root = WP_CONTENT_DIR . $theme_root;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   578
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   579
	} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   580
		$theme_root = WP_CONTENT_DIR . '/themes';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   581
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   582
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   583
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   584
	 * Filters the absolute path to the themes directory.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   585
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   586
	 * @since 1.5.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   587
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   588
	 * @param string $theme_root Absolute path to themes directory.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   589
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   590
	return apply_filters( 'theme_root', $theme_root );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   591
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   592
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   593
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   594
 * Retrieve URI for themes directory.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   595
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   596
 * Does not have trailing slash.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   597
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   598
 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   599
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   600
 * @global array $wp_theme_directories
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   601
 *
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   602
 * @param string $stylesheet_or_template Optional. The stylesheet or template name of the theme.
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   603
 *                                       Default is to leverage the main theme root.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   604
 * @param string $theme_root             Optional. The theme root for which calculations will be based, preventing
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   605
 *                                       the need for a get_raw_theme_root() call.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   606
 * @return string Themes URI.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   607
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   608
function get_theme_root_uri( $stylesheet_or_template = false, $theme_root = false ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   609
	global $wp_theme_directories;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   610
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   611
	if ( $stylesheet_or_template && ! $theme_root ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   612
		$theme_root = get_raw_theme_root( $stylesheet_or_template );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   613
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   614
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   615
	if ( $stylesheet_or_template && $theme_root ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   616
		if ( in_array( $theme_root, (array) $wp_theme_directories ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   617
			// Absolute path. Make an educated guess. YMMV -- but note the filter below.
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   618
			if ( 0 === strpos( $theme_root, WP_CONTENT_DIR ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   619
				$theme_root_uri = content_url( str_replace( WP_CONTENT_DIR, '', $theme_root ) );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   620
			} elseif ( 0 === strpos( $theme_root, ABSPATH ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   621
				$theme_root_uri = site_url( str_replace( ABSPATH, '', $theme_root ) );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   622
			} elseif ( 0 === strpos( $theme_root, WP_PLUGIN_DIR ) || 0 === strpos( $theme_root, WPMU_PLUGIN_DIR ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   623
				$theme_root_uri = plugins_url( basename( $theme_root ), $theme_root );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   624
			} else {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   625
				$theme_root_uri = $theme_root;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   626
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   627
		} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   628
			$theme_root_uri = content_url( $theme_root );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   629
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   630
	} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   631
		$theme_root_uri = content_url( 'themes' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   632
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   633
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   634
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   635
	 * Filters the URI for themes directory.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   636
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   637
	 * @since 1.5.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   638
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   639
	 * @param string $theme_root_uri         The URI for themes directory.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   640
	 * @param string $siteurl                WordPress web address which is set in General Options.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   641
	 * @param string $stylesheet_or_template Stylesheet or template name of the theme.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   642
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   643
	return apply_filters( 'theme_root_uri', $theme_root_uri, get_option( 'siteurl' ), $stylesheet_or_template );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   644
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   645
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   646
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   647
 * Get the raw theme root relative to the content directory with no filters applied.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   648
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   649
 * @since 3.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   650
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   651
 * @global array $wp_theme_directories
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   652
 *
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   653
 * @param string $stylesheet_or_template The stylesheet or template name of the theme
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   654
 * @param bool   $skip_cache             Optional. Whether to skip the cache.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   655
 *                                       Defaults to false, meaning the cache is used.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   656
 * @return string Theme root
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   657
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   658
function get_raw_theme_root( $stylesheet_or_template, $skip_cache = false ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   659
	global $wp_theme_directories;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   660
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   661
	if ( ! is_array( $wp_theme_directories ) || count( $wp_theme_directories ) <= 1 ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   662
		return '/themes';
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   663
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   664
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   665
	$theme_root = false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   666
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   667
	// If requesting the root for the current theme, consult options to avoid calling get_theme_roots()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   668
	if ( ! $skip_cache ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   669
		if ( get_option( 'stylesheet' ) == $stylesheet_or_template ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   670
			$theme_root = get_option( 'stylesheet_root' );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   671
		} elseif ( get_option( 'template' ) == $stylesheet_or_template ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   672
			$theme_root = get_option( 'template_root' );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   673
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   674
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   675
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   676
	if ( empty( $theme_root ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   677
		$theme_roots = get_theme_roots();
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   678
		if ( ! empty( $theme_roots[ $stylesheet_or_template ] ) ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   679
			$theme_root = $theme_roots[ $stylesheet_or_template ];
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   680
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   681
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   682
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   683
	return $theme_root;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   684
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   685
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   686
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   687
 * Display localized stylesheet link element.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   688
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   689
 * @since 2.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   690
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   691
function locale_stylesheet() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   692
	$stylesheet = get_locale_stylesheet_uri();
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   693
	if ( empty( $stylesheet ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   694
		return;
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
	echo '<link rel="stylesheet" href="' . $stylesheet . '" type="text/css" media="screen" />';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   697
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   698
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   699
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   700
 * Switches the theme.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   701
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   702
 * Accepts one argument: $stylesheet of the theme. It also accepts an additional function signature
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   703
 * of two arguments: $template then $stylesheet. This is for backward compatibility.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   704
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   705
 * @since 2.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   706
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   707
 * @global array                $wp_theme_directories
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   708
 * @global WP_Customize_Manager $wp_customize
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   709
 * @global array                $sidebars_widgets
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   710
 *
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   711
 * @param string $stylesheet Stylesheet name
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   712
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   713
function switch_theme( $stylesheet ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   714
	global $wp_theme_directories, $wp_customize, $sidebars_widgets;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   715
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   716
	$_sidebars_widgets = null;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   717
	if ( 'wp_ajax_customize_save' === current_action() ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   718
		$old_sidebars_widgets_data_setting = $wp_customize->get_setting( 'old_sidebars_widgets_data' );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   719
		if ( $old_sidebars_widgets_data_setting ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   720
			$_sidebars_widgets = $wp_customize->post_value( $old_sidebars_widgets_data_setting );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   721
		}
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   722
	} elseif ( is_array( $sidebars_widgets ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   723
		$_sidebars_widgets = $sidebars_widgets;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   724
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   725
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   726
	if ( is_array( $_sidebars_widgets ) ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   727
		set_theme_mod(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   728
			'sidebars_widgets',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   729
			array(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   730
				'time' => time(),
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   731
				'data' => $_sidebars_widgets,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   732
			)
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   733
		);
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   734
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   735
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   736
	$nav_menu_locations = get_theme_mod( 'nav_menu_locations' );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   737
	update_option( 'theme_switch_menu_locations', $nav_menu_locations );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   738
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   739
	if ( func_num_args() > 1 ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   740
		$stylesheet = func_get_arg( 1 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   741
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   742
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   743
	$old_theme = wp_get_theme();
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   744
	$new_theme = wp_get_theme( $stylesheet );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   745
	$template  = $new_theme->get_template();
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   746
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   747
	if ( wp_is_recovery_mode() ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   748
		$paused_themes = wp_paused_themes();
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   749
		$paused_themes->delete( $old_theme->get_stylesheet() );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   750
		$paused_themes->delete( $old_theme->get_template() );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   751
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   752
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   753
	update_option( 'template', $template );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   754
	update_option( 'stylesheet', $stylesheet );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   755
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   756
	if ( count( $wp_theme_directories ) > 1 ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   757
		update_option( 'template_root', get_raw_theme_root( $template, true ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   758
		update_option( 'stylesheet_root', get_raw_theme_root( $stylesheet, true ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   759
	} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   760
		delete_option( 'template_root' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   761
		delete_option( 'stylesheet_root' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   762
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   763
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   764
	$new_name = $new_theme->get( 'Name' );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   765
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   766
	update_option( 'current_theme', $new_name );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   767
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   768
	// Migrate from the old mods_{name} option to theme_mods_{slug}.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   769
	if ( is_admin() && false === get_option( 'theme_mods_' . $stylesheet ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   770
		$default_theme_mods = (array) get_option( 'mods_' . $new_name );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   771
		if ( ! empty( $nav_menu_locations ) && empty( $default_theme_mods['nav_menu_locations'] ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   772
			$default_theme_mods['nav_menu_locations'] = $nav_menu_locations;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   773
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   774
		add_option( "theme_mods_$stylesheet", $default_theme_mods );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   775
	} else {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   776
		/*
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   777
		 * Since retrieve_widgets() is called when initializing a theme in the Customizer,
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   778
		 * we need to remove the theme mods to avoid overwriting changes made via
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   779
		 * the Customizer when accessing wp-admin/widgets.php.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   780
		 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   781
		if ( 'wp_ajax_customize_save' === current_action() ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   782
			remove_theme_mod( 'sidebars_widgets' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   783
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   784
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   785
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   786
	update_option( 'theme_switched', $old_theme->get_stylesheet() );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   787
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   788
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   789
	 * Fires after the theme is switched.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   790
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   791
	 * @since 1.5.0
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   792
	 * @since 4.5.0 Introduced the `$old_theme` parameter.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   793
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   794
	 * @param string   $new_name  Name of the new theme.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   795
	 * @param WP_Theme $new_theme WP_Theme instance of the new theme.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   796
	 * @param WP_Theme $old_theme WP_Theme instance of the old theme.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   797
	 */
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   798
	do_action( 'switch_theme', $new_name, $new_theme, $old_theme );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   799
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   800
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   801
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   802
 * Checks that current theme files 'index.php' and 'style.css' exists.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   803
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   804
 * Does not initially check the default theme, which is the fallback and should always exist.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   805
 * But if it doesn't exist, it'll fall back to the latest core default theme that does exist.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   806
 * Will switch theme to the fallback theme if current theme does not validate.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   807
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   808
 * You can use the {@see 'validate_current_theme'} filter to return false to
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   809
 * disable this functionality.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   810
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   811
 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   812
 * @see WP_DEFAULT_THEME
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   813
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   814
 * @return bool
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   815
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   816
function validate_current_theme() {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   817
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   818
	 * Filters whether to validate the current theme.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   819
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   820
	 * @since 2.7.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   821
	 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   822
	 * @param bool $validate Whether to validate the current theme. Default true.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   823
	 */
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   824
	if ( wp_installing() || ! apply_filters( 'validate_current_theme', true ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   825
		return true;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   826
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   827
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   828
	if ( ! file_exists( get_template_directory() . '/index.php' ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   829
		// Invalid.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   830
	} elseif ( ! file_exists( get_template_directory() . '/style.css' ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   831
		// Invalid.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   832
	} elseif ( is_child_theme() && ! file_exists( get_stylesheet_directory() . '/style.css' ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   833
		// Invalid.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   834
	} else {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   835
		// Valid.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   836
		return true;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   837
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   838
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   839
	$default = wp_get_theme( WP_DEFAULT_THEME );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   840
	if ( $default->exists() ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   841
		switch_theme( WP_DEFAULT_THEME );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   842
		return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   843
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   844
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   845
	/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   846
	 * If we're in an invalid state but WP_DEFAULT_THEME doesn't exist,
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   847
	 * switch to the latest core default theme that's installed.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   848
	 * If it turns out that this latest core default theme is our current
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   849
	 * theme, then there's nothing we can do about that, so we have to bail,
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   850
	 * rather than going into an infinite loop. (This is why there are
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   851
	 * checks against WP_DEFAULT_THEME above, also.) We also can't do anything
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   852
	 * if it turns out there is no default theme installed. (That's `false`.)
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   853
	 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   854
	$default = WP_Theme::get_core_default_theme();
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   855
	if ( false === $default || get_stylesheet() == $default->get_stylesheet() ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   856
		return true;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   857
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   858
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   859
	switch_theme( $default->get_stylesheet() );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   860
	return false;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   861
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   862
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   863
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   864
 * Retrieve all theme modifications.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   865
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   866
 * @since 3.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   867
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   868
 * @return array|void Theme modifications.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   869
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   870
function get_theme_mods() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   871
	$theme_slug = get_option( 'stylesheet' );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   872
	$mods       = get_option( "theme_mods_$theme_slug" );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   873
	if ( false === $mods ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   874
		$theme_name = get_option( 'current_theme' );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   875
		if ( false === $theme_name ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   876
			$theme_name = wp_get_theme()->get( 'Name' );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   877
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   878
		$mods = get_option( "mods_$theme_name" ); // Deprecated location.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   879
		if ( is_admin() && false !== $mods ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   880
			update_option( "theme_mods_$theme_slug", $mods );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   881
			delete_option( "mods_$theme_name" );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   882
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   883
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   884
	return $mods;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   885
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   886
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   887
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   888
 * Retrieve theme modification value for the current theme.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   889
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   890
 * If the modification name does not exist, then the $default will be passed
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   891
 * through {@link https://secure.php.net/sprintf sprintf()} PHP function with the first
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   892
 * string the template directory URI and the second string the stylesheet
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   893
 * directory URI.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   894
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   895
 * @since 2.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   896
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   897
 * @param string      $name    Theme modification name.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   898
 * @param bool|string $default
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   899
 * @return mixed
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   900
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   901
function get_theme_mod( $name, $default = false ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   902
	$mods = get_theme_mods();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   903
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   904
	if ( isset( $mods[ $name ] ) ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   905
		/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   906
		 * Filters the theme modification, or 'theme_mod', value.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   907
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   908
		 * The dynamic portion of the hook name, `$name`, refers to
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   909
		 * the key name of the modification array. For example,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   910
		 * 'header_textcolor', 'header_image', and so on depending
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   911
		 * on the theme options.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   912
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   913
		 * @since 2.2.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   914
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   915
		 * @param string $current_mod The value of the current theme modification.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   916
		 */
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   917
		return apply_filters( "theme_mod_{$name}", $mods[ $name ] );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   918
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   919
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   920
	if ( is_string( $default ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   921
		$default = sprintf( $default, get_template_directory_uri(), get_stylesheet_directory_uri() );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   922
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   923
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   924
	/** This filter is documented in wp-includes/theme.php */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   925
	return apply_filters( "theme_mod_{$name}", $default );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   926
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   927
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   928
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   929
 * Update theme modification value for the current theme.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   930
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   931
 * @since 2.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   932
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   933
 * @param string $name  Theme modification name.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   934
 * @param mixed  $value Theme modification value.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   935
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   936
function set_theme_mod( $name, $value ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   937
	$mods      = get_theme_mods();
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   938
	$old_value = isset( $mods[ $name ] ) ? $mods[ $name ] : false;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   939
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   940
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   941
	 * Filters the theme mod value on save.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   942
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   943
	 * The dynamic portion of the hook name, `$name`, refers to the key name of
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   944
	 * the modification array. For example, 'header_textcolor', 'header_image',
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   945
	 * and so on depending on the theme options.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   946
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   947
	 * @since 3.9.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   948
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   949
	 * @param string $value     The new value of the theme mod.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   950
	 * @param string $old_value The current value of the theme mod.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   951
	 */
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   952
	$mods[ $name ] = apply_filters( "pre_set_theme_mod_{$name}", $value, $old_value );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   953
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   954
	$theme = get_option( 'stylesheet' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   955
	update_option( "theme_mods_$theme", $mods );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   956
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   957
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   958
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   959
 * Remove theme modification name from current theme list.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   960
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   961
 * If removing the name also removes all elements, then the entire option will
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   962
 * be removed.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   963
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   964
 * @since 2.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   965
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   966
 * @param string $name Theme modification name.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   967
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   968
function remove_theme_mod( $name ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   969
	$mods = get_theme_mods();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   970
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   971
	if ( ! isset( $mods[ $name ] ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   972
		return;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   973
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   974
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   975
	unset( $mods[ $name ] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   976
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   977
	if ( empty( $mods ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   978
		remove_theme_mods();
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   979
		return;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   980
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   981
	$theme = get_option( 'stylesheet' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   982
	update_option( "theme_mods_$theme", $mods );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   983
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   984
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   985
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   986
 * Remove theme modifications option for current theme.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   987
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   988
 * @since 2.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   989
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   990
function remove_theme_mods() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   991
	delete_option( 'theme_mods_' . get_option( 'stylesheet' ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   992
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   993
	// Old style.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   994
	$theme_name = get_option( 'current_theme' );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   995
	if ( false === $theme_name ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   996
		$theme_name = wp_get_theme()->get( 'Name' );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   997
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   998
	delete_option( 'mods_' . $theme_name );
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
/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1002
 * Retrieves the custom header text color in 3- or 6-digit hexadecimal form.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1003
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1004
 * @since 2.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1005
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1006
 * @return string Header text color in 3- or 6-digit hexadecimal form (minus the hash symbol).
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1007
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1008
function get_header_textcolor() {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1009
	return get_theme_mod( 'header_textcolor', get_theme_support( 'custom-header', 'default-text-color' ) );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1010
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1011
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1012
/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1013
 * Displays the custom header text color in 3- or 6-digit hexadecimal form (minus the hash symbol).
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1014
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1015
 * @since 2.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1016
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1017
function header_textcolor() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1018
	echo get_header_textcolor();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1019
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1020
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1021
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1022
 * Whether to display the header text.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1023
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1024
 * @since 3.4.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1025
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1026
 * @return bool
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1027
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1028
function display_header_text() {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1029
	if ( ! current_theme_supports( 'custom-header', 'header-text' ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1030
		return false;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1031
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1032
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1033
	$text_color = get_theme_mod( 'header_textcolor', get_theme_support( 'custom-header', 'default-text-color' ) );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1034
	return 'blank' !== $text_color;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1035
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1036
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1037
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1038
 * Check whether a header image is set or not.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1039
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1040
 * @since 4.2.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1041
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1042
 * @see get_header_image()
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1043
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1044
 * @return bool Whether a header image is set or not.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1045
 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1046
function has_header_image() {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1047
	return (bool) get_header_image();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1048
}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1049
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1050
/**
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1051
 * Retrieve header image for custom header.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1052
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1053
 * @since 2.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1054
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1055
 * @return string|false
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
function get_header_image() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1058
	$url = get_theme_mod( 'header_image', get_theme_support( 'custom-header', 'default-image' ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1059
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1060
	if ( 'remove-header' == $url ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1061
		return false;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1062
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1063
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1064
	if ( is_random_header_image() ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1065
		$url = get_random_header_image();
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1066
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1067
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1068
	return esc_url_raw( set_url_scheme( $url ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1069
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1070
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1071
/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1072
 * Create image tag markup for a custom header image.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1073
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1074
 * @since 4.4.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1075
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1076
 * @param array $attr Optional. Additional attributes for the image tag. Can be used
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1077
 *                              to override the default attributes. Default empty.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1078
 * @return string HTML image element markup or empty string on failure.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1079
 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1080
function get_header_image_tag( $attr = array() ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1081
	$header      = get_custom_header();
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1082
	$header->url = get_header_image();
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1083
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1084
	if ( ! $header->url ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1085
		return '';
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1086
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1087
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1088
	$width  = absint( $header->width );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1089
	$height = absint( $header->height );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1090
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1091
	$attr = wp_parse_args(
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1092
		$attr,
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1093
		array(
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1094
			'src'    => $header->url,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1095
			'width'  => $width,
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1096
			'height' => $height,
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1097
			'alt'    => get_bloginfo( 'name' ),
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1098
		)
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1099
	);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1100
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1101
	// Generate 'srcset' and 'sizes' if not already present.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1102
	if ( empty( $attr['srcset'] ) && ! empty( $header->attachment_id ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1103
		$image_meta = get_post_meta( $header->attachment_id, '_wp_attachment_metadata', true );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1104
		$size_array = array( $width, $height );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1105
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1106
		if ( is_array( $image_meta ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1107
			$srcset = wp_calculate_image_srcset( $size_array, $header->url, $image_meta, $header->attachment_id );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1108
			$sizes  = ! empty( $attr['sizes'] ) ? $attr['sizes'] : wp_calculate_image_sizes( $size_array, $header->url, $image_meta, $header->attachment_id );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1109
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1110
			if ( $srcset && $sizes ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1111
				$attr['srcset'] = $srcset;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1112
				$attr['sizes']  = $sizes;
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1113
			}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1114
		}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1115
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1116
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1117
	$attr = array_map( 'esc_attr', $attr );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1118
	$html = '<img';
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1119
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1120
	foreach ( $attr as $name => $value ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1121
		$html .= ' ' . $name . '="' . $value . '"';
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1122
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1123
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1124
	$html .= ' />';
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1125
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1126
	/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1127
	 * Filters the markup of header images.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1128
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1129
	 * @since 4.4.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1130
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1131
	 * @param string $html   The HTML image tag markup being filtered.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1132
	 * @param object $header The custom header object returned by 'get_custom_header()'.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1133
	 * @param array  $attr   Array of the attributes for the image tag.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1134
	 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1135
	return apply_filters( 'get_header_image_tag', $html, $header, $attr );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1136
}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1137
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1138
/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1139
 * Display the image markup for a custom header image.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1140
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1141
 * @since 4.4.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1142
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1143
 * @param array $attr Optional. Attributes for the image markup. Default empty.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1144
 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1145
function the_header_image_tag( $attr = array() ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1146
	echo get_header_image_tag( $attr );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1147
}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1148
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1149
/**
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1150
 * Get random header image data from registered images in theme.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1151
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1152
 * @since 3.4.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1153
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1154
 * @access private
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1155
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1156
 * @global array  $_wp_default_headers
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1157
 * @staticvar object $_wp_random_header
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1158
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1159
 * @return object
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1160
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1161
function _get_random_header_data() {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1162
	static $_wp_random_header = null;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1163
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1164
	if ( empty( $_wp_random_header ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1165
		global $_wp_default_headers;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1166
		$header_image_mod = get_theme_mod( 'header_image', '' );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1167
		$headers          = array();
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1168
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1169
		if ( 'random-uploaded-image' == $header_image_mod ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1170
			$headers = get_uploaded_header_images();
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1171
		} elseif ( ! empty( $_wp_default_headers ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1172
			if ( 'random-default-image' == $header_image_mod ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1173
				$headers = $_wp_default_headers;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1174
			} else {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1175
				if ( current_theme_supports( 'custom-header', 'random-default' ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1176
					$headers = $_wp_default_headers;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1177
				}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1178
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1179
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1180
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1181
		if ( empty( $headers ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1182
			return new stdClass;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1183
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1184
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1185
		$_wp_random_header = (object) $headers[ array_rand( $headers ) ];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1186
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1187
		$_wp_random_header->url           = sprintf( $_wp_random_header->url, get_template_directory_uri(), get_stylesheet_directory_uri() );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1188
		$_wp_random_header->thumbnail_url = sprintf( $_wp_random_header->thumbnail_url, get_template_directory_uri(), get_stylesheet_directory_uri() );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1189
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1190
	return $_wp_random_header;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1191
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1192
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1193
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1194
 * Get random header image url from registered images in theme.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1195
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1196
 * @since 3.2.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1197
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1198
 * @return string Path to header image
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1199
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1200
function get_random_header_image() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1201
	$random_image = _get_random_header_data();
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1202
	if ( empty( $random_image->url ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1203
		return '';
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1204
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1205
	return $random_image->url;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1206
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1207
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1208
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1209
 * Check if random header image is in use.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1210
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1211
 * Always true if user expressly chooses the option in Appearance > Header.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1212
 * Also true if theme has multiple header images registered, no specific header image
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1213
 * is chosen, and theme turns on random headers with add_theme_support().
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1214
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1215
 * @since 3.2.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1216
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1217
 * @param string $type The random pool to use. any|default|uploaded
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1218
 * @return bool
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1219
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1220
function is_random_header_image( $type = 'any' ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1221
	$header_image_mod = get_theme_mod( 'header_image', get_theme_support( 'custom-header', 'default-image' ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1222
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1223
	if ( 'any' == $type ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1224
		if ( 'random-default-image' == $header_image_mod || 'random-uploaded-image' == $header_image_mod || ( '' != get_random_header_image() && empty( $header_image_mod ) ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1225
			return true;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1226
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1227
	} else {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1228
		if ( "random-$type-image" == $header_image_mod ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1229
			return true;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1230
		} elseif ( 'default' == $type && empty( $header_image_mod ) && '' != get_random_header_image() ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1231
			return true;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1232
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1233
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1234
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1235
	return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1236
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1237
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1238
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1239
 * Display header image URL.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1240
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1241
 * @since 2.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1242
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1243
function header_image() {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1244
	$image = get_header_image();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1245
	if ( $image ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1246
		echo esc_url( $image );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1247
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1248
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1249
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1250
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1251
 * Get the header images uploaded for the current theme.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1252
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1253
 * @since 3.2.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1254
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1255
 * @return array
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1256
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1257
function get_uploaded_header_images() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1258
	$header_images = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1259
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1260
	// @todo caching
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1261
	$headers = get_posts(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1262
		array(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1263
			'post_type'  => 'attachment',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1264
			'meta_key'   => '_wp_attachment_is_custom_header',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1265
			'meta_value' => get_option( 'stylesheet' ),
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1266
			'orderby'    => 'none',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1267
			'nopaging'   => true,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1268
		)
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1269
	);
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1270
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1271
	if ( empty( $headers ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1272
		return array();
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1273
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1274
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1275
	foreach ( (array) $headers as $header ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1276
		$url          = esc_url_raw( wp_get_attachment_url( $header->ID ) );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1277
		$header_data  = wp_get_attachment_metadata( $header->ID );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1278
		$header_index = $header->ID;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1279
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1280
		$header_images[ $header_index ]                      = array();
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1281
		$header_images[ $header_index ]['attachment_id']     = $header->ID;
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1282
		$header_images[ $header_index ]['url']               = $url;
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1283
		$header_images[ $header_index ]['thumbnail_url']     = $url;
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1284
		$header_images[ $header_index ]['alt_text']          = get_post_meta( $header->ID, '_wp_attachment_image_alt', true );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1285
		$header_images[ $header_index ]['attachment_parent'] = isset( $header_data['attachment_parent'] ) ? $header_data['attachment_parent'] : '';
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1286
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1287
		if ( isset( $header_data['width'] ) ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1288
			$header_images[ $header_index ]['width'] = $header_data['width'];
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1289
		}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1290
		if ( isset( $header_data['height'] ) ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1291
			$header_images[ $header_index ]['height'] = $header_data['height'];
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1292
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1293
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1294
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1295
	return $header_images;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1296
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1297
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1298
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1299
 * Get the header image data.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1300
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1301
 * @since 3.4.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1302
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1303
 * @global array $_wp_default_headers
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1304
 *
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1305
 * @return object
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1306
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1307
function get_custom_header() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1308
	global $_wp_default_headers;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1309
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1310
	if ( is_random_header_image() ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1311
		$data = _get_random_header_data();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1312
	} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1313
		$data = get_theme_mod( 'header_image_data' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1314
		if ( ! $data && current_theme_supports( 'custom-header', 'default-image' ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1315
			$directory_args = array( get_template_directory_uri(), get_stylesheet_directory_uri() );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1316
			$data           = array();
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1317
			$data['url']    = $data['thumbnail_url'] = vsprintf( get_theme_support( 'custom-header', 'default-image' ), $directory_args );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1318
			if ( ! empty( $_wp_default_headers ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1319
				foreach ( (array) $_wp_default_headers as $default_header ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1320
					$url = vsprintf( $default_header['url'], $directory_args );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1321
					if ( $data['url'] == $url ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1322
						$data                  = $default_header;
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1323
						$data['url']           = $url;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1324
						$data['thumbnail_url'] = vsprintf( $data['thumbnail_url'], $directory_args );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1325
						break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1326
					}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1327
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1328
			}
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
	$default = array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1333
		'url'           => '',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1334
		'thumbnail_url' => '',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1335
		'width'         => get_theme_support( 'custom-header', 'width' ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1336
		'height'        => get_theme_support( 'custom-header', 'height' ),
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1337
		'video'         => get_theme_support( 'custom-header', 'video' ),
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1338
	);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1339
	return (object) wp_parse_args( $data, $default );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1340
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1341
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1342
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1343
 * Register a selection of default headers to be displayed by the custom header admin UI.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1344
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1345
 * @since 3.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1346
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1347
 * @global array $_wp_default_headers
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1348
 *
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1349
 * @param array $headers Array of headers keyed by a string id. The ids point to arrays containing 'url', 'thumbnail_url', and 'description' keys.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1350
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1351
function register_default_headers( $headers ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1352
	global $_wp_default_headers;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1353
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1354
	$_wp_default_headers = array_merge( (array) $_wp_default_headers, (array) $headers );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1355
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1356
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1357
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1358
 * Unregister default headers.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1359
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1360
 * This function must be called after register_default_headers() has already added the
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1361
 * header you want to remove.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1362
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1363
 * @see register_default_headers()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1364
 * @since 3.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1365
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1366
 * @global array $_wp_default_headers
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1367
 *
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1368
 * @param string|array $header The header string id (key of array) to remove, or an array thereof.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1369
 * @return bool|void A single header returns true on success, false on failure.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1370
 *                   There is currently no return value for multiple headers.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1371
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1372
function unregister_default_headers( $header ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1373
	global $_wp_default_headers;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1374
	if ( is_array( $header ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1375
		array_map( 'unregister_default_headers', $header );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1376
	} elseif ( isset( $_wp_default_headers[ $header ] ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1377
		unset( $_wp_default_headers[ $header ] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1378
		return true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1379
	} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1380
		return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1381
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1382
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1383
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1384
/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1385
 * Check whether a header video is set or not.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1386
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1387
 * @since 4.7.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1388
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1389
 * @see get_header_video_url()
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1390
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1391
 * @return bool Whether a header video is set or not.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1392
 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1393
function has_header_video() {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1394
	return (bool) get_header_video_url();
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1395
}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1396
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1397
/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1398
 * Retrieve header video URL for custom header.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1399
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1400
 * Uses a local video if present, or falls back to an external video.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1401
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1402
 * @since 4.7.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1403
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1404
 * @return string|false Header video URL or false if there is no video.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1405
 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1406
function get_header_video_url() {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1407
	$id  = absint( get_theme_mod( 'header_video' ) );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1408
	$url = esc_url( get_theme_mod( 'external_header_video' ) );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1409
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1410
	if ( $id ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1411
		// Get the file URL from the attachment ID.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1412
		$url = wp_get_attachment_url( $id );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1413
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1414
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1415
	/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1416
	 * Filters the header video URL.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1417
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1418
	 * @since 4.7.3
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
	 * @param string $url Header video URL, if available.
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
	$url = apply_filters( 'get_header_video_url', $url );
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
	if ( ! $id && ! $url ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1425
		return false;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1426
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1427
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1428
	return esc_url_raw( set_url_scheme( $url ) );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1429
}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1430
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1431
/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1432
 * Display header video URL.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1433
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1434
 * @since 4.7.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1435
 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1436
function the_header_video_url() {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1437
	$video = get_header_video_url();
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1438
	if ( $video ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1439
		echo esc_url( $video );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1440
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1441
}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1442
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1443
/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1444
 * Retrieve header video settings.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1445
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1446
 * @since 4.7.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1447
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1448
 * @return array
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1449
 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1450
function get_header_video_settings() {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1451
	$header     = get_custom_header();
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1452
	$video_url  = get_header_video_url();
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1453
	$video_type = wp_check_filetype( $video_url, wp_get_mime_types() );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1454
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1455
	$settings = array(
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1456
		'mimeType'  => '',
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1457
		'posterUrl' => get_header_image(),
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1458
		'videoUrl'  => $video_url,
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1459
		'width'     => absint( $header->width ),
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1460
		'height'    => absint( $header->height ),
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1461
		'minWidth'  => 900,
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1462
		'minHeight' => 500,
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1463
		'l10n'      => array(
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1464
			'pause'      => __( 'Pause' ),
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1465
			'play'       => __( 'Play' ),
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1466
			'pauseSpeak' => __( 'Video is paused.' ),
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1467
			'playSpeak'  => __( 'Video is playing.' ),
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1468
		),
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1469
	);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1470
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1471
	if ( preg_match( '#^https?://(?:www\.)?(?:youtube\.com/watch|youtu\.be/)#', $video_url ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1472
		$settings['mimeType'] = 'video/x-youtube';
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1473
	} elseif ( ! empty( $video_type['type'] ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1474
		$settings['mimeType'] = $video_type['type'];
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1475
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1476
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1477
	/**
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1478
	 * Filters header video settings.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1479
	 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1480
	 * @since 4.7.0
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1481
	 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1482
	 * @param array $settings An array of header video settings.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1483
	 */
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1484
	return apply_filters( 'header_video_settings', $settings );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1485
}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1486
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1487
/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1488
 * Check whether a custom header is set or not.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1489
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1490
 * @since 4.7.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1491
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1492
 * @return bool True if a custom header is set. False if not.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1493
 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1494
function has_custom_header() {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1495
	if ( has_header_image() || ( has_header_video() && is_header_video_active() ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1496
		return true;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1497
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1498
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1499
	return false;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1500
}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1501
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1502
/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1503
 * Checks whether the custom header video is eligible to show on the current page.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1504
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1505
 * @since 4.7.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1506
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1507
 * @return bool True if the custom header video should be shown. False if not.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1508
 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1509
function is_header_video_active() {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1510
	if ( ! get_theme_support( 'custom-header', 'video' ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1511
		return false;
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
	$video_active_cb = get_theme_support( 'custom-header', 'video-active-callback' );
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
	if ( empty( $video_active_cb ) || ! is_callable( $video_active_cb ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1517
		$show_video = true;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1518
	} else {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1519
		$show_video = call_user_func( $video_active_cb );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1520
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1521
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1522
	/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1523
	 * Modify whether the custom header video is eligible to show on the current page.
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
	 * @since 4.7.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1526
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1527
	 * @param bool $show_video Whether the custom header video should be shown. Returns the value
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1528
	 *                         of the theme setting for the `custom-header`'s `video-active-callback`.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1529
	 *                         If no callback is set, the default value is that of `is_front_page()`.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1530
	 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1531
	return apply_filters( 'is_header_video_active', $show_video );
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
/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1535
 * Retrieve the markup for a custom header.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1536
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1537
 * The container div will always be returned in the Customizer preview.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1538
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1539
 * @since 4.7.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1540
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1541
 * @return string The markup for a custom header on success.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1542
 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1543
function get_custom_header_markup() {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1544
	if ( ! has_custom_header() && ! is_customize_preview() ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1545
		return '';
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1546
	}
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
	return sprintf(
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1549
		'<div id="wp-custom-header" class="wp-custom-header">%s</div>',
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1550
		get_header_image_tag()
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
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1554
/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1555
 * Print the markup for a custom header.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1556
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1557
 * A container div will always be printed in the Customizer preview.
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
 * @since 4.7.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1560
 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1561
function the_custom_header_markup() {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1562
	$custom_header = get_custom_header_markup();
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1563
	if ( empty( $custom_header ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1564
		return;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1565
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1566
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1567
	echo $custom_header;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1568
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1569
	if ( is_header_video_active() && ( has_header_video() || is_customize_preview() ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1570
		wp_enqueue_script( 'wp-custom-header' );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1571
		wp_localize_script( 'wp-custom-header', '_wpCustomHeaderSettings', get_header_video_settings() );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1572
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1573
}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1574
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1575
/**
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1576
 * Retrieve background image for custom background.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1577
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1578
 * @since 3.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1579
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1580
 * @return string
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1581
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1582
function get_background_image() {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1583
	return get_theme_mod( 'background_image', get_theme_support( 'custom-background', 'default-image' ) );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1584
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1585
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1586
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1587
 * Display background image path.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1588
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1589
 * @since 3.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1590
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1591
function background_image() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1592
	echo get_background_image();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1593
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1594
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1595
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1596
 * Retrieve value for custom background color.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1597
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1598
 * @since 3.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1599
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1600
 * @return string
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1601
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1602
function get_background_color() {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1603
	return get_theme_mod( 'background_color', get_theme_support( 'custom-background', 'default-color' ) );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1604
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1605
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1606
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1607
 * Display background color value.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1608
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1609
 * @since 3.0.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
function background_color() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1612
	echo get_background_color();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1613
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1614
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1615
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1616
 * Default custom background callback.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1617
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1618
 * @since 3.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1619
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1620
function _custom_background_cb() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1621
	// $background is the saved custom image, or the default image.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1622
	$background = set_url_scheme( get_background_image() );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1623
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1624
	// $color is the saved custom color.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1625
	// A default has to be specified in style.css. It will not be printed here.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1626
	$color = get_background_color();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1627
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1628
	if ( $color === get_theme_support( 'custom-background', 'default-color' ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1629
		$color = false;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1630
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1631
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1632
	if ( ! $background && ! $color ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1633
		if ( is_customize_preview() ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1634
			echo '<style type="text/css" id="custom-background-css"></style>';
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1635
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1636
		return;
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1637
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1638
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1639
	$style = $color ? "background-color: #$color;" : '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1640
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1641
	if ( $background ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1642
		$image = ' background-image: url("' . esc_url_raw( $background ) . '");';
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1643
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1644
		// Background Position.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1645
		$position_x = get_theme_mod( 'background_position_x', get_theme_support( 'custom-background', 'default-position-x' ) );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1646
		$position_y = get_theme_mod( 'background_position_y', get_theme_support( 'custom-background', 'default-position-y' ) );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1647
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1648
		if ( ! in_array( $position_x, array( 'left', 'center', 'right' ), true ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1649
			$position_x = 'left';
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1650
		}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1651
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1652
		if ( ! in_array( $position_y, array( 'top', 'center', 'bottom' ), true ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1653
			$position_y = 'top';
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1654
		}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1655
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1656
		$position = " background-position: $position_x $position_y;";
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1657
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1658
		// Background Size.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1659
		$size = get_theme_mod( 'background_size', get_theme_support( 'custom-background', 'default-size' ) );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1660
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1661
		if ( ! in_array( $size, array( 'auto', 'contain', 'cover' ), true ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1662
			$size = 'auto';
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1663
		}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1664
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1665
		$size = " background-size: $size;";
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1666
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1667
		// Background Repeat.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1668
		$repeat = get_theme_mod( 'background_repeat', get_theme_support( 'custom-background', 'default-repeat' ) );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1669
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1670
		if ( ! in_array( $repeat, array( 'repeat-x', 'repeat-y', 'repeat', 'no-repeat' ), true ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1671
			$repeat = 'repeat';
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1672
		}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1673
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1674
		$repeat = " background-repeat: $repeat;";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1675
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1676
		// Background Scroll.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1677
		$attachment = get_theme_mod( 'background_attachment', get_theme_support( 'custom-background', 'default-attachment' ) );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1678
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1679
		if ( 'fixed' !== $attachment ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1680
			$attachment = 'scroll';
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1681
		}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1682
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1683
		$attachment = " background-attachment: $attachment;";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1684
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1685
		$style .= $image . $position . $size . $repeat . $attachment;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1686
	}
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1687
	?>
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1688
<style type="text/css" id="custom-background-css">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1689
body.custom-background { <?php echo trim( $style ); ?> }
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1690
</style>
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1691
	<?php
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1692
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1693
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1694
/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1695
 * Render the Custom CSS style element.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1696
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1697
 * @since 4.7.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1698
 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1699
function wp_custom_css_cb() {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1700
	$styles = wp_get_custom_css();
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1701
	if ( $styles || is_customize_preview() ) :
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1702
		?>
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1703
		<style type="text/css" id="wp-custom-css">
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1704
			<?php echo strip_tags( $styles ); // Note that esc_html() cannot be used because `div &gt; span` is not interpreted properly. ?>
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1705
		</style>
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1706
		<?php
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1707
	endif;
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1708
}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1709
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1710
/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1711
 * Fetch the `custom_css` post for a given theme.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1712
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1713
 * @since 4.7.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1714
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1715
 * @param string $stylesheet Optional. A theme object stylesheet name. Defaults to the current theme.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1716
 * @return WP_Post|null The custom_css post or null if none exists.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1717
 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1718
function wp_get_custom_css_post( $stylesheet = '' ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1719
	if ( empty( $stylesheet ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1720
		$stylesheet = get_stylesheet();
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1721
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1722
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1723
	$custom_css_query_vars = array(
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1724
		'post_type'              => 'custom_css',
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1725
		'post_status'            => get_post_stati(),
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1726
		'name'                   => sanitize_title( $stylesheet ),
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1727
		'posts_per_page'         => 1,
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1728
		'no_found_rows'          => true,
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1729
		'cache_results'          => true,
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1730
		'update_post_meta_cache' => false,
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1731
		'update_post_term_cache' => false,
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1732
		'lazy_load_term_meta'    => false,
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1733
	);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1734
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1735
	$post = null;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1736
	if ( get_stylesheet() === $stylesheet ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1737
		$post_id = get_theme_mod( 'custom_css_post_id' );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1738
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1739
		if ( $post_id > 0 && get_post( $post_id ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1740
			$post = get_post( $post_id );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1741
		}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1742
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1743
		// `-1` indicates no post exists; no query necessary.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1744
		if ( ! $post && -1 !== $post_id ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1745
			$query = new WP_Query( $custom_css_query_vars );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1746
			$post  = $query->post;
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1747
			/*
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1748
			 * Cache the lookup. See wp_update_custom_css_post().
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1749
			 * @todo This should get cleared if a custom_css post is added/removed.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1750
			 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1751
			set_theme_mod( 'custom_css_post_id', $post ? $post->ID : -1 );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1752
		}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1753
	} else {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1754
		$query = new WP_Query( $custom_css_query_vars );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1755
		$post  = $query->post;
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1756
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1757
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1758
	return $post;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1759
}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1760
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1761
/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1762
 * Fetch the saved Custom CSS content for rendering.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1763
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1764
 * @since 4.7.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1765
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1766
 * @param string $stylesheet Optional. A theme object stylesheet name. Defaults to the current theme.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1767
 * @return string The Custom CSS Post content.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1768
 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1769
function wp_get_custom_css( $stylesheet = '' ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1770
	$css = '';
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1771
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1772
	if ( empty( $stylesheet ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1773
		$stylesheet = get_stylesheet();
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1774
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1775
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1776
	$post = wp_get_custom_css_post( $stylesheet );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1777
	if ( $post ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1778
		$css = $post->post_content;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1779
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1780
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1781
	/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1782
	 * Filters the Custom CSS Output into the <head>.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1783
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1784
	 * @since 4.7.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1785
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1786
	 * @param string $css        CSS pulled in from the Custom CSS CPT.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1787
	 * @param string $stylesheet The theme stylesheet name.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1788
	 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1789
	$css = apply_filters( 'wp_get_custom_css', $css, $stylesheet );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1790
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1791
	return $css;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1792
}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1793
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1794
/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1795
 * Update the `custom_css` post for a given theme.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1796
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1797
 * Inserts a `custom_css` post when one doesn't yet exist.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1798
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1799
 * @since 4.7.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1800
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1801
 * @param string $css CSS, stored in `post_content`.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1802
 * @param array  $args {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1803
 *     Args.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1804
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1805
 *     @type string $preprocessed Pre-processed CSS, stored in `post_content_filtered`. Normally empty string. Optional.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1806
 *     @type string $stylesheet   Stylesheet (child theme) to update. Optional, defaults to current theme/stylesheet.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1807
 * }
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1808
 * @return WP_Post|WP_Error Post on success, error on failure.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1809
 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1810
function wp_update_custom_css_post( $css, $args = array() ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1811
	$args = wp_parse_args(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1812
		$args,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1813
		array(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1814
			'preprocessed' => '',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1815
			'stylesheet'   => get_stylesheet(),
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1816
		)
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1817
	);
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1818
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1819
	$data = array(
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1820
		'css'          => $css,
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1821
		'preprocessed' => $args['preprocessed'],
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1822
	);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1823
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1824
	/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1825
	 * Filters the `css` (`post_content`) and `preprocessed` (`post_content_filtered`) args for a `custom_css` post being updated.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1826
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1827
	 * This filter can be used by plugin that offer CSS pre-processors, to store the original
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1828
	 * pre-processed CSS in `post_content_filtered` and then store processed CSS in `post_content`.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1829
	 * When used in this way, the `post_content_filtered` should be supplied as the setting value
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1830
	 * instead of `post_content` via a the `customize_value_custom_css` filter, for example:
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1831
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1832
	 * <code>
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1833
	 * add_filter( 'customize_value_custom_css', function( $value, $setting ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1834
	 *     $post = wp_get_custom_css_post( $setting->stylesheet );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1835
	 *     if ( $post && ! empty( $post->post_content_filtered ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1836
	 *         $css = $post->post_content_filtered;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1837
	 *     }
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1838
	 *     return $css;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1839
	 * }, 10, 2 );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1840
	 * </code>
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1841
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1842
	 * @since 4.7.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1843
	 * @param array $data {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1844
	 *     Custom CSS data.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1845
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1846
	 *     @type string $css          CSS stored in `post_content`.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1847
	 *     @type string $preprocessed Pre-processed CSS stored in `post_content_filtered`. Normally empty string.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1848
	 * }
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1849
	 * @param array $args {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1850
	 *     The args passed into `wp_update_custom_css_post()` merged with defaults.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1851
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1852
	 *     @type string $css          The original CSS passed in to be updated.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1853
	 *     @type string $preprocessed The original preprocessed CSS passed in to be updated.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1854
	 *     @type string $stylesheet   The stylesheet (theme) being updated.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1855
	 * }
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1856
	 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1857
	$data = apply_filters( 'update_custom_css_data', $data, array_merge( $args, compact( 'css' ) ) );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1858
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1859
	$post_data = array(
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1860
		'post_title'            => $args['stylesheet'],
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1861
		'post_name'             => sanitize_title( $args['stylesheet'] ),
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1862
		'post_type'             => 'custom_css',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1863
		'post_status'           => 'publish',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1864
		'post_content'          => $data['css'],
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1865
		'post_content_filtered' => $data['preprocessed'],
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1866
	);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1867
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1868
	// Update post if it already exists, otherwise create a new one.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1869
	$post = wp_get_custom_css_post( $args['stylesheet'] );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1870
	if ( $post ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1871
		$post_data['ID'] = $post->ID;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1872
		$r               = wp_update_post( wp_slash( $post_data ), true );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1873
	} else {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1874
		$r = wp_insert_post( wp_slash( $post_data ), true );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1875
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1876
		if ( ! is_wp_error( $r ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1877
			if ( get_stylesheet() === $args['stylesheet'] ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1878
				set_theme_mod( 'custom_css_post_id', $r );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1879
			}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1880
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1881
			// Trigger creation of a revision. This should be removed once #30854 is resolved.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1882
			if ( 0 === count( wp_get_post_revisions( $r ) ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1883
				wp_save_post_revision( $r );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1884
			}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1885
		}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1886
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1887
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1888
	if ( is_wp_error( $r ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1889
		return $r;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1890
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1891
	return get_post( $r );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1892
}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1893
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1894
/**
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1895
 * Add callback for custom TinyMCE editor stylesheets.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1896
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1897
 * The parameter $stylesheet is the name of the stylesheet, relative to
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1898
 * the theme root. It also accepts an array of stylesheets.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1899
 * It is optional and defaults to 'editor-style.css'.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1900
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1901
 * This function automatically adds another stylesheet with -rtl prefix, e.g. editor-style-rtl.css.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1902
 * If that file doesn't exist, it is removed before adding the stylesheet(s) to TinyMCE.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1903
 * If an array of stylesheets is passed to add_editor_style(),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1904
 * RTL is only added for the first stylesheet.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1905
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1906
 * Since version 3.4 the TinyMCE body has .rtl CSS class.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1907
 * It is a better option to use that class and add any RTL styles to the main stylesheet.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1908
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1909
 * @since 3.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1910
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1911
 * @global array $editor_styles
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1912
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1913
 * @param array|string $stylesheet Optional. Stylesheet name or array thereof, relative to theme root.
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1914
 *                                 Defaults to 'editor-style.css'
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1915
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1916
function add_editor_style( $stylesheet = 'editor-style.css' ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1917
	add_theme_support( 'editor-style' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1918
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1919
	if ( ! is_admin() ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1920
		return;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1921
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1922
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1923
	global $editor_styles;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1924
	$editor_styles = (array) $editor_styles;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1925
	$stylesheet    = (array) $stylesheet;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1926
	if ( is_rtl() ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1927
		$rtl_stylesheet = str_replace( '.css', '-rtl.css', $stylesheet[0] );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1928
		$stylesheet[]   = $rtl_stylesheet;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1929
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1930
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1931
	$editor_styles = array_merge( $editor_styles, $stylesheet );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1932
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1933
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1934
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1935
 * Removes all visual editor stylesheets.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1936
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1937
 * @since 3.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1938
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1939
 * @global array $editor_styles
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1940
 *
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1941
 * @return bool True on success, false if there were no stylesheets to remove.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1942
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1943
function remove_editor_styles() {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1944
	if ( ! current_theme_supports( 'editor-style' ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1945
		return false;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1946
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1947
	_remove_theme_support( 'editor-style' );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1948
	if ( is_admin() ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1949
		$GLOBALS['editor_styles'] = array();
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1950
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1951
	return true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1952
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1953
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1954
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1955
 * Retrieve any registered editor stylesheets
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1956
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1957
 * @since 4.0.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1958
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1959
 * @global array $editor_styles Registered editor stylesheets
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1960
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1961
 * @return array If registered, a list of editor stylesheet URLs.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1962
 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1963
function get_editor_stylesheets() {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1964
	$stylesheets = array();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1965
	// load editor_style.css if the current theme supports it
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1966
	if ( ! empty( $GLOBALS['editor_styles'] ) && is_array( $GLOBALS['editor_styles'] ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1967
		$editor_styles = $GLOBALS['editor_styles'];
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1968
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1969
		$editor_styles = array_unique( array_filter( $editor_styles ) );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1970
		$style_uri     = get_stylesheet_directory_uri();
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1971
		$style_dir     = get_stylesheet_directory();
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1972
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1973
		// Support externally referenced styles (like, say, fonts).
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1974
		foreach ( $editor_styles as $key => $file ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1975
			if ( preg_match( '~^(https?:)?//~', $file ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1976
				$stylesheets[] = esc_url_raw( $file );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1977
				unset( $editor_styles[ $key ] );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1978
			}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1979
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1980
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1981
		// Look in a parent theme first, that way child theme CSS overrides.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1982
		if ( is_child_theme() ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1983
			$template_uri = get_template_directory_uri();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1984
			$template_dir = get_template_directory();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1985
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1986
			foreach ( $editor_styles as $key => $file ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1987
				if ( $file && file_exists( "$template_dir/$file" ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1988
					$stylesheets[] = "$template_uri/$file";
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1989
				}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1990
			}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1991
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1992
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1993
		foreach ( $editor_styles as $file ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1994
			if ( $file && file_exists( "$style_dir/$file" ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1995
				$stylesheets[] = "$style_uri/$file";
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1996
			}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1997
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1998
	}
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1999
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2000
	/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2001
	 * Filters the array of stylesheets applied to the editor.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2002
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2003
	 * @since 4.3.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2004
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2005
	 * @param array $stylesheets Array of stylesheets to be applied to the editor.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2006
	 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2007
	return apply_filters( 'editor_stylesheets', $stylesheets );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2008
}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2009
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2010
/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2011
 * Expand a theme's starter content configuration using core-provided data.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2012
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2013
 * @since 4.7.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2014
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2015
 * @return array Array of starter content.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2016
 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2017
function get_theme_starter_content() {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2018
	$theme_support = get_theme_support( 'starter-content' );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2019
	if ( is_array( $theme_support ) && ! empty( $theme_support[0] ) && is_array( $theme_support[0] ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2020
		$config = $theme_support[0];
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2021
	} else {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2022
		$config = array();
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2023
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2024
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2025
	$core_content = array(
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2026
		'widgets'   => array(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2027
			'text_business_info' => array(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2028
				'text',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2029
				array(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2030
					'title'  => _x( 'Find Us', 'Theme starter content' ),
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2031
					'text'   => join(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2032
						'',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2033
						array(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2034
							'<strong>' . _x( 'Address', 'Theme starter content' ) . "</strong>\n",
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2035
							_x( '123 Main Street', 'Theme starter content' ) . "\n" . _x( 'New York, NY 10001', 'Theme starter content' ) . "\n\n",
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2036
							'<strong>' . _x( 'Hours', 'Theme starter content' ) . "</strong>\n",
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2037
							_x( 'Monday&mdash;Friday: 9:00AM&ndash;5:00PM', 'Theme starter content' ) . "\n" . _x( 'Saturday &amp; Sunday: 11:00AM&ndash;3:00PM', 'Theme starter content' ),
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2038
						)
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2039
					),
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2040
					'filter' => true,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2041
					'visual' => true,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2042
				),
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2043
			),
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2044
			'text_about'         => array(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2045
				'text',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2046
				array(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2047
					'title'  => _x( 'About This Site', 'Theme starter content' ),
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2048
					'text'   => _x( 'This may be a good place to introduce yourself and your site or include some credits.', 'Theme starter content' ),
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2049
					'filter' => true,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2050
					'visual' => true,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2051
				),
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2052
			),
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2053
			'archives'           => array(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2054
				'archives',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2055
				array(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2056
					'title' => _x( 'Archives', 'Theme starter content' ),
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2057
				),
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2058
			),
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2059
			'calendar'           => array(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2060
				'calendar',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2061
				array(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2062
					'title' => _x( 'Calendar', 'Theme starter content' ),
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2063
				),
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2064
			),
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2065
			'categories'         => array(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2066
				'categories',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2067
				array(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2068
					'title' => _x( 'Categories', 'Theme starter content' ),
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2069
				),
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2070
			),
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2071
			'meta'               => array(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2072
				'meta',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2073
				array(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2074
					'title' => _x( 'Meta', 'Theme starter content' ),
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2075
				),
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2076
			),
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2077
			'recent-comments'    => array(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2078
				'recent-comments',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2079
				array(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2080
					'title' => _x( 'Recent Comments', 'Theme starter content' ),
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2081
				),
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2082
			),
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2083
			'recent-posts'       => array(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2084
				'recent-posts',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2085
				array(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2086
					'title' => _x( 'Recent Posts', 'Theme starter content' ),
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2087
				),
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2088
			),
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2089
			'search'             => array(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2090
				'search',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2091
				array(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2092
					'title' => _x( 'Search', 'Theme starter content' ),
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2093
				),
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2094
			),
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2095
		),
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2096
		'nav_menus' => array(
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2097
			'link_home'       => array(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2098
				'type'  => 'custom',
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2099
				'title' => _x( 'Home', 'Theme starter content' ),
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2100
				'url'   => home_url( '/' ),
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2101
			),
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2102
			'page_home'       => array( // Deprecated in favor of link_home.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2103
				'type'      => 'post_type',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2104
				'object'    => 'page',
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2105
				'object_id' => '{{home}}',
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2106
			),
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2107
			'page_about'      => array(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2108
				'type'      => 'post_type',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2109
				'object'    => 'page',
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2110
				'object_id' => '{{about}}',
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2111
			),
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2112
			'page_blog'       => array(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2113
				'type'      => 'post_type',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2114
				'object'    => 'page',
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2115
				'object_id' => '{{blog}}',
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2116
			),
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2117
			'page_news'       => array(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2118
				'type'      => 'post_type',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2119
				'object'    => 'page',
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2120
				'object_id' => '{{news}}',
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2121
			),
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2122
			'page_contact'    => array(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2123
				'type'      => 'post_type',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2124
				'object'    => 'page',
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2125
				'object_id' => '{{contact}}',
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2126
			),
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2127
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2128
			'link_email'      => array(
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2129
				'title' => _x( 'Email', 'Theme starter content' ),
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2130
				'url'   => 'mailto:wordpress@example.com',
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2131
			),
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2132
			'link_facebook'   => array(
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2133
				'title' => _x( 'Facebook', 'Theme starter content' ),
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2134
				'url'   => 'https://www.facebook.com/wordpress',
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2135
			),
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2136
			'link_foursquare' => array(
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2137
				'title' => _x( 'Foursquare', 'Theme starter content' ),
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2138
				'url'   => 'https://foursquare.com/',
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2139
			),
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2140
			'link_github'     => array(
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2141
				'title' => _x( 'GitHub', 'Theme starter content' ),
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2142
				'url'   => 'https://github.com/wordpress/',
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2143
			),
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2144
			'link_instagram'  => array(
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2145
				'title' => _x( 'Instagram', 'Theme starter content' ),
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2146
				'url'   => 'https://www.instagram.com/explore/tags/wordcamp/',
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2147
			),
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2148
			'link_linkedin'   => array(
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2149
				'title' => _x( 'LinkedIn', 'Theme starter content' ),
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2150
				'url'   => 'https://www.linkedin.com/company/1089783',
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2151
			),
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2152
			'link_pinterest'  => array(
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2153
				'title' => _x( 'Pinterest', 'Theme starter content' ),
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2154
				'url'   => 'https://www.pinterest.com/',
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2155
			),
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2156
			'link_twitter'    => array(
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2157
				'title' => _x( 'Twitter', 'Theme starter content' ),
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2158
				'url'   => 'https://twitter.com/wordpress',
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2159
			),
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2160
			'link_yelp'       => array(
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2161
				'title' => _x( 'Yelp', 'Theme starter content' ),
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2162
				'url'   => 'https://www.yelp.com',
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2163
			),
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2164
			'link_youtube'    => array(
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2165
				'title' => _x( 'YouTube', 'Theme starter content' ),
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2166
				'url'   => 'https://www.youtube.com/channel/UCdof4Ju7amm1chz1gi1T2ZA',
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2167
			),
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2168
		),
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2169
		'posts'     => array(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2170
			'home'             => array(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2171
				'post_type'    => 'page',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2172
				'post_title'   => _x( 'Home', 'Theme starter content' ),
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2173
				'post_content' => _x( 'Welcome to your site! This is your homepage, which is what most visitors will see when they come to your site for the first time.', 'Theme starter content' ),
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2174
			),
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2175
			'about'            => array(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2176
				'post_type'    => 'page',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2177
				'post_title'   => _x( 'About', 'Theme starter content' ),
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2178
				'post_content' => _x( 'You might be an artist who would like to introduce yourself and your work here or maybe you&rsquo;re a business with a mission to describe.', 'Theme starter content' ),
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2179
			),
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2180
			'contact'          => array(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2181
				'post_type'    => 'page',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2182
				'post_title'   => _x( 'Contact', 'Theme starter content' ),
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2183
				'post_content' => _x( 'This is a page with some basic contact information, such as an address and phone number. You might also try a plugin to add a contact form.', 'Theme starter content' ),
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2184
			),
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2185
			'blog'             => array(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2186
				'post_type'  => 'page',
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2187
				'post_title' => _x( 'Blog', 'Theme starter content' ),
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2188
			),
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2189
			'news'             => array(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2190
				'post_type'  => 'page',
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2191
				'post_title' => _x( 'News', 'Theme starter content' ),
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2192
			),
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2193
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2194
			'homepage-section' => array(
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2195
				'post_type'    => 'page',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2196
				'post_title'   => _x( 'A homepage section', 'Theme starter content' ),
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2197
				'post_content' => _x( 'This is an example of a homepage section. Homepage sections can be any page other than the homepage itself, including the page that shows your latest blog posts.', 'Theme starter content' ),
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2198
			),
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2199
		),
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2200
	);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2201
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2202
	$content = array();
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2203
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2204
	foreach ( $config as $type => $args ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2205
		switch ( $type ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2206
			// Use options and theme_mods as-is.
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2207
			case 'options':
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2208
			case 'theme_mods':
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2209
				$content[ $type ] = $config[ $type ];
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2210
				break;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2211
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2212
			// Widgets are grouped into sidebars.
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2213
			case 'widgets':
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2214
				foreach ( $config[ $type ] as $sidebar_id => $widgets ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2215
					foreach ( $widgets as $id => $widget ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2216
						if ( is_array( $widget ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2217
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2218
							// Item extends core content.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2219
							if ( ! empty( $core_content[ $type ][ $id ] ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2220
								$widget = array(
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2221
									$core_content[ $type ][ $id ][0],
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2222
									array_merge( $core_content[ $type ][ $id ][1], $widget ),
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2223
								);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2224
							}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2225
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2226
							$content[ $type ][ $sidebar_id ][] = $widget;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2227
						} elseif ( is_string( $widget ) && ! empty( $core_content[ $type ] ) && ! empty( $core_content[ $type ][ $widget ] ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2228
							$content[ $type ][ $sidebar_id ][] = $core_content[ $type ][ $widget ];
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2229
						}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2230
					}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2231
				}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2232
				break;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2233
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2234
			// And nav menu items are grouped into nav menus.
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2235
			case 'nav_menus':
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2236
				foreach ( $config[ $type ] as $nav_menu_location => $nav_menu ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2237
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2238
					// Ensure nav menus get a name.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2239
					if ( empty( $nav_menu['name'] ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2240
						$nav_menu['name'] = $nav_menu_location;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2241
					}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2242
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2243
					$content[ $type ][ $nav_menu_location ]['name'] = $nav_menu['name'];
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2244
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2245
					foreach ( $nav_menu['items'] as $id => $nav_menu_item ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2246
						if ( is_array( $nav_menu_item ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2247
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2248
							// Item extends core content.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2249
							if ( ! empty( $core_content[ $type ][ $id ] ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2250
								$nav_menu_item = array_merge( $core_content[ $type ][ $id ], $nav_menu_item );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2251
							}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2252
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2253
							$content[ $type ][ $nav_menu_location ]['items'][] = $nav_menu_item;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2254
						} elseif ( is_string( $nav_menu_item ) && ! empty( $core_content[ $type ] ) && ! empty( $core_content[ $type ][ $nav_menu_item ] ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2255
							$content[ $type ][ $nav_menu_location ]['items'][] = $core_content[ $type ][ $nav_menu_item ];
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2256
						}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2257
					}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2258
				}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2259
				break;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2260
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2261
			// Attachments are posts but have special treatment.
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2262
			case 'attachments':
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2263
				foreach ( $config[ $type ] as $id => $item ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2264
					if ( ! empty( $item['file'] ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2265
						$content[ $type ][ $id ] = $item;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2266
					}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2267
				}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2268
				break;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2269
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2270
			// All that's left now are posts (besides attachments). Not a default case for the sake of clarity and future work.
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2271
			case 'posts':
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2272
				foreach ( $config[ $type ] as $id => $item ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2273
					if ( is_array( $item ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2274
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2275
						// Item extends core content.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2276
						if ( ! empty( $core_content[ $type ][ $id ] ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2277
							$item = array_merge( $core_content[ $type ][ $id ], $item );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2278
						}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2279
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2280
						// Enforce a subset of fields.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2281
						$content[ $type ][ $id ] = wp_array_slice_assoc(
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2282
							$item,
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2283
							array(
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2284
								'post_type',
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2285
								'post_title',
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2286
								'post_excerpt',
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2287
								'post_name',
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2288
								'post_content',
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2289
								'menu_order',
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2290
								'comment_status',
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2291
								'thumbnail',
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2292
								'template',
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2293
							)
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2294
						);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2295
					} elseif ( is_string( $item ) && ! empty( $core_content[ $type ][ $item ] ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2296
						$content[ $type ][ $item ] = $core_content[ $type ][ $item ];
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2297
					}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2298
				}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2299
				break;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2300
		}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2301
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2302
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2303
	/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2304
	 * Filters the expanded array of starter content.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2305
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2306
	 * @since 4.7.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2307
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2308
	 * @param array $content Array of starter content.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2309
	 * @param array $config  Array of theme-specific starter content configuration.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2310
	 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2311
	return apply_filters( 'get_theme_starter_content', $content, $config );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2312
}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2313
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2314
/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2315
 * Registers theme support for a given feature.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2316
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2317
 * Must be called in the theme's functions.php file to work.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2318
 * If attached to a hook, it must be {@see 'after_setup_theme'}.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2319
 * The {@see 'init'} hook may be too late for some features.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2320
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2321
 * @since 2.9.0
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2322
 * @since 3.6.0 The `html5` feature was added
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2323
 * @since 3.9.0 The `html5` feature now also accepts 'gallery' and 'caption'
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2324
 * @since 4.1.0 The `title-tag` feature was added
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2325
 * @since 4.5.0 The `customize-selective-refresh-widgets` feature was added
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2326
 * @since 4.7.0 The `starter-content` feature was added
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2327
 * @since 5.0.0 The `responsive-embeds`, `align-wide`, `dark-editor-style`, `disable-custom-colors`,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2328
 *              `disable-custom-font-sizes`, `editor-color-pallete`, `editor-font-sizes`,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2329
 *              `editor-styles`, and `wp-block-styles` features were added.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2330
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2331
 * @global array $_wp_theme_features
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2332
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2333
 * @param string $feature  The feature being added. Likely core values include 'post-formats',
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2334
 *                         'post-thumbnails', 'html5', 'custom-logo', 'custom-header-uploads',
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2335
 *                         'custom-header', 'custom-background', 'title-tag', 'starter-content',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2336
 *                         'responsive-embeds', etc.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2337
 * @param mixed  $args,... Optional extra arguments to pass along with certain features.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2338
 * @return void|bool False on failure, void otherwise.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2339
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2340
function add_theme_support( $feature ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2341
	global $_wp_theme_features;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2342
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2343
	if ( func_num_args() == 1 ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2344
		$args = true;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2345
	} else {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2346
		$args = array_slice( func_get_args(), 1 );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2347
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2348
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2349
	switch ( $feature ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2350
		case 'post-thumbnails':
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2351
			// All post types are already supported.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2352
			if ( true === get_theme_support( 'post-thumbnails' ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2353
				return;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2354
			}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2355
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2356
			/*
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2357
			 * Merge post types with any that already declared their support
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2358
			 * for post thumbnails.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2359
			 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2360
			if ( is_array( $args[0] ) && isset( $_wp_theme_features['post-thumbnails'] ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2361
				$args[0] = array_unique( array_merge( $_wp_theme_features['post-thumbnails'][0], $args[0] ) );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2362
			}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2363
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2364
			break;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2365
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2366
		case 'post-formats':
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2367
			if ( is_array( $args[0] ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2368
				$post_formats = get_post_format_slugs();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2369
				unset( $post_formats['standard'] );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2370
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2371
				$args[0] = array_intersect( $args[0], array_keys( $post_formats ) );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2372
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2373
			break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2374
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2375
		case 'html5':
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2376
			// You can't just pass 'html5', you need to pass an array of types.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2377
			if ( empty( $args[0] ) ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2378
				// Build an array of types for back-compat.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2379
				$args = array( 0 => array( 'comment-list', 'comment-form', 'search-form' ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2380
			} elseif ( ! is_array( $args[0] ) ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2381
				_doing_it_wrong( "add_theme_support( 'html5' )", __( 'You need to pass an array of types.' ), '3.6.1' );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2382
				return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2383
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2384
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2385
			// Calling 'html5' again merges, rather than overwrites.
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2386
			if ( isset( $_wp_theme_features['html5'] ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2387
				$args[0] = array_merge( $_wp_theme_features['html5'][0], $args[0] );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2388
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2389
			break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2390
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2391
		case 'custom-logo':
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2392
			if ( ! is_array( $args ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2393
				$args = array( 0 => array() );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2394
			}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2395
			$defaults = array(
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2396
				'width'       => null,
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2397
				'height'      => null,
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2398
				'flex-width'  => false,
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2399
				'flex-height' => false,
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2400
				'header-text' => '',
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2401
			);
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2402
			$args[0]  = wp_parse_args( array_intersect_key( $args[0], $defaults ), $defaults );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2403
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2404
			// Allow full flexibility if no size is specified.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2405
			if ( is_null( $args[0]['width'] ) && is_null( $args[0]['height'] ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2406
				$args[0]['flex-width']  = true;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2407
				$args[0]['flex-height'] = true;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2408
			}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2409
			break;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2410
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2411
		case 'custom-header-uploads':
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2412
			return add_theme_support( 'custom-header', array( 'uploads' => true ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2413
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2414
		case 'custom-header':
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2415
			if ( ! is_array( $args ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2416
				$args = array( 0 => array() );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2417
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2418
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2419
			$defaults = array(
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2420
				'default-image'          => '',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2421
				'random-default'         => false,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2422
				'width'                  => 0,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2423
				'height'                 => 0,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2424
				'flex-height'            => false,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2425
				'flex-width'             => false,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2426
				'default-text-color'     => '',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2427
				'header-text'            => true,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2428
				'uploads'                => true,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2429
				'wp-head-callback'       => '',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2430
				'admin-head-callback'    => '',
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2431
				'admin-preview-callback' => '',
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2432
				'video'                  => false,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2433
				'video-active-callback'  => 'is_front_page',
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2434
			);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2435
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2436
			$jit = isset( $args[0]['__jit'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2437
			unset( $args[0]['__jit'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2438
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2439
			// Merge in data from previous add_theme_support() calls.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2440
			// The first value registered wins. (A child theme is set up first.)
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2441
			if ( isset( $_wp_theme_features['custom-header'] ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2442
				$args[0] = wp_parse_args( $_wp_theme_features['custom-header'][0], $args[0] );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2443
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2444
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2445
			// Load in the defaults at the end, as we need to insure first one wins.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2446
			// This will cause all constants to be defined, as each arg will then be set to the default.
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2447
			if ( $jit ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2448
				$args[0] = wp_parse_args( $args[0], $defaults );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2449
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2450
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2451
			// If a constant was defined, use that value. Otherwise, define the constant to ensure
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2452
			// the constant is always accurate (and is not defined later,  overriding our value).
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2453
			// As stated above, the first value wins.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2454
			// Once we get to wp_loaded (just-in-time), define any constants we haven't already.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2455
			// Constants are lame. Don't reference them. This is just for backward compatibility.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2456
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2457
			if ( defined( 'NO_HEADER_TEXT' ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2458
				$args[0]['header-text'] = ! NO_HEADER_TEXT;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2459
			} elseif ( isset( $args[0]['header-text'] ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2460
				define( 'NO_HEADER_TEXT', empty( $args[0]['header-text'] ) );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2461
			}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2462
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2463
			if ( defined( 'HEADER_IMAGE_WIDTH' ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2464
				$args[0]['width'] = (int) HEADER_IMAGE_WIDTH;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2465
			} elseif ( isset( $args[0]['width'] ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2466
				define( 'HEADER_IMAGE_WIDTH', (int) $args[0]['width'] );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2467
			}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2468
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2469
			if ( defined( 'HEADER_IMAGE_HEIGHT' ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2470
				$args[0]['height'] = (int) HEADER_IMAGE_HEIGHT;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2471
			} elseif ( isset( $args[0]['height'] ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2472
				define( 'HEADER_IMAGE_HEIGHT', (int) $args[0]['height'] );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2473
			}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2474
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2475
			if ( defined( 'HEADER_TEXTCOLOR' ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2476
				$args[0]['default-text-color'] = HEADER_TEXTCOLOR;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2477
			} elseif ( isset( $args[0]['default-text-color'] ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2478
				define( 'HEADER_TEXTCOLOR', $args[0]['default-text-color'] );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2479
			}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2480
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2481
			if ( defined( 'HEADER_IMAGE' ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2482
				$args[0]['default-image'] = HEADER_IMAGE;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2483
			} elseif ( isset( $args[0]['default-image'] ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2484
				define( 'HEADER_IMAGE', $args[0]['default-image'] );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2485
			}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2486
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2487
			if ( $jit && ! empty( $args[0]['default-image'] ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2488
				$args[0]['random-default'] = false;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2489
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2490
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2491
			// If headers are supported, and we still don't have a defined width or height,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2492
			// we have implicit flex sizes.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2493
			if ( $jit ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2494
				if ( empty( $args[0]['width'] ) && empty( $args[0]['flex-width'] ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2495
					$args[0]['flex-width'] = true;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2496
				}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2497
				if ( empty( $args[0]['height'] ) && empty( $args[0]['flex-height'] ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2498
					$args[0]['flex-height'] = true;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2499
				}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2500
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2501
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2502
			break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2503
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2504
		case 'custom-background':
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2505
			if ( ! is_array( $args ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2506
				$args = array( 0 => array() );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2507
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2508
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2509
			$defaults = array(
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2510
				'default-image'          => '',
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2511
				'default-preset'         => 'default',
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2512
				'default-position-x'     => 'left',
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2513
				'default-position-y'     => 'top',
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2514
				'default-size'           => 'auto',
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2515
				'default-repeat'         => 'repeat',
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2516
				'default-attachment'     => 'scroll',
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2517
				'default-color'          => '',
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2518
				'wp-head-callback'       => '_custom_background_cb',
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2519
				'admin-head-callback'    => '',
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2520
				'admin-preview-callback' => '',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2521
			);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2522
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2523
			$jit = isset( $args[0]['__jit'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2524
			unset( $args[0]['__jit'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2525
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2526
			// Merge in data from previous add_theme_support() calls. The first value registered wins.
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2527
			if ( isset( $_wp_theme_features['custom-background'] ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2528
				$args[0] = wp_parse_args( $_wp_theme_features['custom-background'][0], $args[0] );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2529
			}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2530
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2531
			if ( $jit ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2532
				$args[0] = wp_parse_args( $args[0], $defaults );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2533
			}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2534
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2535
			if ( defined( 'BACKGROUND_COLOR' ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2536
				$args[0]['default-color'] = BACKGROUND_COLOR;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2537
			} elseif ( isset( $args[0]['default-color'] ) || $jit ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2538
				define( 'BACKGROUND_COLOR', $args[0]['default-color'] );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2539
			}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2540
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2541
			if ( defined( 'BACKGROUND_IMAGE' ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2542
				$args[0]['default-image'] = BACKGROUND_IMAGE;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2543
			} elseif ( isset( $args[0]['default-image'] ) || $jit ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2544
				define( 'BACKGROUND_IMAGE', $args[0]['default-image'] );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2545
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2546
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2547
			break;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2548
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2549
		// Ensure that 'title-tag' is accessible in the admin.
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2550
		case 'title-tag':
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2551
			// Can be called in functions.php but must happen before wp_loaded, i.e. not in header.php.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2552
			if ( did_action( 'wp_loaded' ) ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2553
				/* translators: 1: title-tag, 2: wp_loaded */
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2554
				_doing_it_wrong(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2555
					"add_theme_support( 'title-tag' )",
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2556
					sprintf(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2557
						__( 'Theme support for %1$s should be registered before the %2$s hook.' ),
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2558
						'<code>title-tag</code>',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2559
						'<code>wp_loaded</code>'
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2560
					),
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2561
					'4.1.0'
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2562
				);
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2563
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2564
				return false;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2565
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2566
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2567
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2568
	$_wp_theme_features[ $feature ] = $args;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2569
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2570
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2571
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2572
 * Registers the internal custom header and background routines.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2573
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2574
 * @since 3.4.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2575
 * @access private
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2576
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2577
 * @global Custom_Image_Header $custom_image_header
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2578
 * @global Custom_Background   $custom_background
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2579
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2580
function _custom_header_background_just_in_time() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2581
	global $custom_image_header, $custom_background;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2582
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2583
	if ( current_theme_supports( 'custom-header' ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2584
		// In case any constants were defined after an add_custom_image_header() call, re-run.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2585
		add_theme_support( 'custom-header', array( '__jit' => true ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2586
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2587
		$args = get_theme_support( 'custom-header' );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2588
		if ( $args[0]['wp-head-callback'] ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2589
			add_action( 'wp_head', $args[0]['wp-head-callback'] );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2590
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2591
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2592
		if ( is_admin() ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2593
			require_once( ABSPATH . 'wp-admin/custom-header.php' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2594
			$custom_image_header = new Custom_Image_Header( $args[0]['admin-head-callback'], $args[0]['admin-preview-callback'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2595
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2596
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2597
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2598
	if ( current_theme_supports( 'custom-background' ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2599
		// In case any constants were defined after an add_custom_background() call, re-run.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2600
		add_theme_support( 'custom-background', array( '__jit' => true ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2601
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2602
		$args = get_theme_support( 'custom-background' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2603
		add_action( 'wp_head', $args[0]['wp-head-callback'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2604
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2605
		if ( is_admin() ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2606
			require_once( ABSPATH . 'wp-admin/custom-background.php' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2607
			$custom_background = new Custom_Background( $args[0]['admin-head-callback'], $args[0]['admin-preview-callback'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2608
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2609
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2610
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2611
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2612
/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2613
 * Adds CSS to hide header text for custom logo, based on Customizer setting.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2614
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2615
 * @since 4.5.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2616
 * @access private
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2617
 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2618
function _custom_logo_header_styles() {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2619
	if ( ! current_theme_supports( 'custom-header', 'header-text' ) && get_theme_support( 'custom-logo', 'header-text' ) && ! get_theme_mod( 'header_text', true ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2620
		$classes = (array) get_theme_support( 'custom-logo', 'header-text' );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2621
		$classes = array_map( 'sanitize_html_class', $classes );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2622
		$classes = '.' . implode( ', .', $classes );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2623
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2624
		?>
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2625
		<!-- Custom Logo: hide header text -->
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2626
		<style id="custom-logo-css" type="text/css">
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2627
			<?php echo $classes; ?> {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2628
				position: absolute;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2629
				clip: rect(1px, 1px, 1px, 1px);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2630
			}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2631
		</style>
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2632
		<?php
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2633
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2634
}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2635
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2636
/**
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2637
 * Gets the theme support arguments passed when registering that support
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2638
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2639
 * @since 3.1.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2640
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2641
 * @global array $_wp_theme_features
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2642
 *
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2643
 * @param string $feature The feature to check.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2644
 * @return mixed The array of extra arguments or the value for the registered feature.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2645
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2646
function get_theme_support( $feature ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2647
	global $_wp_theme_features;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2648
	if ( ! isset( $_wp_theme_features[ $feature ] ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2649
		return false;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2650
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2651
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2652
	if ( func_num_args() <= 1 ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2653
		return $_wp_theme_features[ $feature ];
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2654
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2655
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2656
	$args = array_slice( func_get_args(), 1 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2657
	switch ( $feature ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2658
		case 'custom-logo':
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2659
		case 'custom-header':
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2660
		case 'custom-background':
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2661
			if ( isset( $_wp_theme_features[ $feature ][0][ $args[0] ] ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2662
				return $_wp_theme_features[ $feature ][0][ $args[0] ];
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2663
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2664
			return false;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2665
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2666
		default:
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2667
			return $_wp_theme_features[ $feature ];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2668
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2669
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2670
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2671
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2672
 * Allows a theme to de-register its support of a certain feature
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2673
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2674
 * Should be called in the theme's functions.php file. Generally would
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2675
 * be used for child themes to override support from the parent theme.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2676
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2677
 * @since 3.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2678
 * @see add_theme_support()
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2679
 * @param string $feature The feature being removed.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2680
 * @return bool|void Whether feature was removed.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2681
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2682
function remove_theme_support( $feature ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2683
	// Blacklist: for internal registrations not used directly by themes.
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2684
	if ( in_array( $feature, array( 'editor-style', 'widgets', 'menus' ) ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2685
		return false;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2686
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2687
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2688
	return _remove_theme_support( $feature );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2689
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2690
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2691
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2692
 * Do not use. Removes theme support internally, ignorant of the blacklist.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2693
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2694
 * @access private
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2695
 * @since 3.1.0
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2696
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2697
 * @global array               $_wp_theme_features
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2698
 * @global Custom_Image_Header $custom_image_header
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2699
 * @global Custom_Background   $custom_background
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2700
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2701
 * @param string $feature
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2702
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2703
function _remove_theme_support( $feature ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2704
	global $_wp_theme_features;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2705
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2706
	switch ( $feature ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2707
		case 'custom-header-uploads':
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2708
			if ( ! isset( $_wp_theme_features['custom-header'] ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2709
				return false;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2710
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2711
			add_theme_support( 'custom-header', array( 'uploads' => false ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2712
			return; // Do not continue - custom-header-uploads no longer exists.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2713
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2714
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2715
	if ( ! isset( $_wp_theme_features[ $feature ] ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2716
		return false;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2717
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2718
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2719
	switch ( $feature ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2720
		case 'custom-header':
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2721
			if ( ! did_action( 'wp_loaded' ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2722
				break;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2723
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2724
			$support = get_theme_support( 'custom-header' );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2725
			if ( isset( $support[0]['wp-head-callback'] ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2726
				remove_action( 'wp_head', $support[0]['wp-head-callback'] );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2727
			}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2728
			if ( isset( $GLOBALS['custom_image_header'] ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2729
				remove_action( 'admin_menu', array( $GLOBALS['custom_image_header'], 'init' ) );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2730
				unset( $GLOBALS['custom_image_header'] );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2731
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2732
			break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2733
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2734
		case 'custom-background':
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2735
			if ( ! did_action( 'wp_loaded' ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2736
				break;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2737
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2738
			$support = get_theme_support( 'custom-background' );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2739
			if ( isset( $support[0]['wp-head-callback'] ) ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2740
				remove_action( 'wp_head', $support[0]['wp-head-callback'] );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2741
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2742
			remove_action( 'admin_menu', array( $GLOBALS['custom_background'], 'init' ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2743
			unset( $GLOBALS['custom_background'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2744
			break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2745
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2746
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2747
	unset( $_wp_theme_features[ $feature ] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2748
	return true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2749
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2750
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2751
/**
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2752
 * Checks a theme's support for a given feature.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2753
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2754
 * @since 2.9.0
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2755
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2756
 * @global array $_wp_theme_features
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2757
 *
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2758
 * @param string $feature The feature being checked.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2759
 * @return bool True if the current theme supports the feature, false otherwise.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2760
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2761
function current_theme_supports( $feature ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2762
	global $_wp_theme_features;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2763
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2764
	if ( 'custom-header-uploads' == $feature ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2765
		return current_theme_supports( 'custom-header', 'uploads' );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2766
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2767
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2768
	if ( ! isset( $_wp_theme_features[ $feature ] ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2769
		return false;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2770
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2771
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2772
	// If no args passed then no extra checks need be performed
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2773
	if ( func_num_args() <= 1 ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2774
		return true;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2775
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2776
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2777
	$args = array_slice( func_get_args(), 1 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2778
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2779
	switch ( $feature ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2780
		case 'post-thumbnails':
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2781
			// post-thumbnails can be registered for only certain content/post types by passing
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2782
			// an array of types to add_theme_support(). If no array was passed, then
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2783
			// any type is accepted
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2784
			if ( true === $_wp_theme_features[ $feature ] ) {  // Registered for all types
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2785
				return true;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2786
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2787
			$content_type = $args[0];
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2788
			return in_array( $content_type, $_wp_theme_features[ $feature ][0] );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2789
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2790
		case 'html5':
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2791
		case 'post-formats':
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2792
			// specific post formats can be registered by passing an array of types to
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2793
			// add_theme_support()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2794
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2795
			// Specific areas of HTML5 support *must* be passed via an array to add_theme_support()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2796
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2797
			$type = $args[0];
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2798
			return in_array( $type, $_wp_theme_features[ $feature ][0] );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2799
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2800
		case 'custom-logo':
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2801
		case 'custom-header':
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2802
		case 'custom-background':
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2803
			// Specific capabilities can be registered by passing an array to add_theme_support().
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2804
			return ( isset( $_wp_theme_features[ $feature ][0][ $args[0] ] ) && $_wp_theme_features[ $feature ][0][ $args[0] ] );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2805
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2806
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2807
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2808
	 * Filters whether the current theme supports a specific feature.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2809
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2810
	 * The dynamic portion of the hook name, `$feature`, refers to the specific theme
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2811
	 * feature. Possible values include 'post-formats', 'post-thumbnails', 'custom-background',
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2812
	 * 'custom-header', 'menus', 'automatic-feed-links', 'html5',
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2813
	 * 'starter-content', and 'customize-selective-refresh-widgets'.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2814
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2815
	 * @since 3.4.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2816
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2817
	 * @param bool   true     Whether the current theme supports the given feature. Default true.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2818
	 * @param array  $args    Array of arguments for the feature.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2819
	 * @param string $feature The theme feature.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2820
	 */
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2821
	return apply_filters( "current_theme_supports-{$feature}", true, $args, $_wp_theme_features[ $feature ] );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2822
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2823
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2824
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2825
 * Checks a theme's support for a given feature before loading the functions which implement it.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2826
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2827
 * @since 2.9.0
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2828
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2829
 * @param string $feature The feature being checked.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2830
 * @param string $include Path to the file.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2831
 * @return bool True if the current theme supports the supplied feature, false otherwise.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2832
 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2833
function require_if_theme_supports( $feature, $include ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2834
	if ( current_theme_supports( $feature ) ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2835
		require( $include );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2836
		return true;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2837
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2838
	return false;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2839
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2840
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2841
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2842
 * Checks an attachment being deleted to see if it's a header or background image.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2843
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2844
 * If true it removes the theme modification which would be pointing at the deleted
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2845
 * attachment.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2846
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2847
 * @access private
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2848
 * @since 3.0.0
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2849
 * @since 4.3.0 Also removes `header_image_data`.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2850
 * @since 4.5.0 Also removes custom logo theme mods.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2851
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2852
 * @param int $id The attachment id.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2853
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2854
function _delete_attachment_theme_mod( $id ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2855
	$attachment_image = wp_get_attachment_url( $id );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2856
	$header_image     = get_header_image();
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2857
	$background_image = get_background_image();
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2858
	$custom_logo_id   = get_theme_mod( 'custom_logo' );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2859
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2860
	if ( $custom_logo_id && $custom_logo_id == $id ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2861
		remove_theme_mod( 'custom_logo' );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2862
		remove_theme_mod( 'header_text' );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2863
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2864
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2865
	if ( $header_image && $header_image == $attachment_image ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2866
		remove_theme_mod( 'header_image' );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2867
		remove_theme_mod( 'header_image_data' );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2868
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2869
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2870
	if ( $background_image && $background_image == $attachment_image ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2871
		remove_theme_mod( 'background_image' );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2872
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2873
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2874
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2875
/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2876
 * Checks if a theme has been changed and runs 'after_switch_theme' hook on the next WP load.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2877
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2878
 * See {@see 'after_switch_theme'}.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2879
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2880
 * @since 3.3.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2881
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2882
function check_theme_switched() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2883
	if ( $stylesheet = get_option( 'theme_switched' ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2884
		$old_theme = wp_get_theme( $stylesheet );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2885
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2886
		// Prevent widget & menu mapping from running since Customizer already called it up front
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2887
		if ( get_option( 'theme_switched_via_customizer' ) ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2888
			remove_action( 'after_switch_theme', '_wp_menus_changed' );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2889
			remove_action( 'after_switch_theme', '_wp_sidebars_changed' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2890
			update_option( 'theme_switched_via_customizer', false );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2891
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2892
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2893
		if ( $old_theme->exists() ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2894
			/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2895
			 * Fires on the first WP load after a theme switch if the old theme still exists.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2896
			 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2897
			 * This action fires multiple times and the parameters differs
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2898
			 * according to the context, if the old theme exists or not.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2899
			 * If the old theme is missing, the parameter will be the slug
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2900
			 * of the old theme.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2901
			 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2902
			 * @since 3.3.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2903
			 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2904
			 * @param string   $old_name  Old theme name.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2905
			 * @param WP_Theme $old_theme WP_Theme instance of the old theme.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2906
			 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2907
			do_action( 'after_switch_theme', $old_theme->get( 'Name' ), $old_theme );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2908
		} else {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2909
			/** This action is documented in wp-includes/theme.php */
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2910
			do_action( 'after_switch_theme', $stylesheet, $old_theme );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2911
		}
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2912
		flush_rewrite_rules();
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2913
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2914
		update_option( 'theme_switched', false );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2915
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2916
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2917
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2918
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2919
 * Includes and instantiates the WP_Customize_Manager class.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2920
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2921
 * Loads the Customizer at plugins_loaded when accessing the customize.php admin
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2922
 * page or when any request includes a wp_customize=on param or a customize_changeset
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2923
 * param (a UUID). This param is a signal for whether to bootstrap the Customizer when
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2924
 * WordPress is loading, especially in the Customizer preview
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2925
 * or when making Customizer Ajax requests for widgets or menus.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2926
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2927
 * @since 3.4.0
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2928
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2929
 * @global WP_Customize_Manager $wp_customize
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2930
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2931
function _wp_customize_include() {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2932
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2933
	$is_customize_admin_page = ( is_admin() && 'customize.php' == basename( $_SERVER['PHP_SELF'] ) );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2934
	$should_include          = (
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2935
		$is_customize_admin_page
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2936
		||
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2937
		( isset( $_REQUEST['wp_customize'] ) && 'on' == $_REQUEST['wp_customize'] )
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2938
		||
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2939
		( ! empty( $_GET['customize_changeset_uuid'] ) || ! empty( $_POST['customize_changeset_uuid'] ) )
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2940
	);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2941
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2942
	if ( ! $should_include ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2943
		return;
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2944
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2945
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2946
	/*
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2947
	 * Note that wp_unslash() is not being used on the input vars because it is
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2948
	 * called before wp_magic_quotes() gets called. Besides this fact, none of
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2949
	 * the values should contain any characters needing slashes anyway.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2950
	 */
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2951
	$keys       = array( 'changeset_uuid', 'customize_changeset_uuid', 'customize_theme', 'theme', 'customize_messenger_channel', 'customize_autosaved' );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2952
	$input_vars = array_merge(
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2953
		wp_array_slice_assoc( $_GET, $keys ),
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2954
		wp_array_slice_assoc( $_POST, $keys )
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2955
	);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2956
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2957
	$theme             = null;
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2958
	$changeset_uuid    = false; // Value false indicates UUID should be determined after_setup_theme to either re-use existing saved changeset or else generate a new UUID if none exists.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2959
	$messenger_channel = null;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2960
	$autosaved         = null;
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2961
	$branching         = false; // Set initially fo false since defaults to true for back-compat; can be overridden via the customize_changeset_branching filter.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2962
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2963
	if ( $is_customize_admin_page && isset( $input_vars['changeset_uuid'] ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2964
		$changeset_uuid = sanitize_key( $input_vars['changeset_uuid'] );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2965
	} elseif ( ! empty( $input_vars['customize_changeset_uuid'] ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2966
		$changeset_uuid = sanitize_key( $input_vars['customize_changeset_uuid'] );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2967
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2968
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2969
	// Note that theme will be sanitized via WP_Theme.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2970
	if ( $is_customize_admin_page && isset( $input_vars['theme'] ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2971
		$theme = $input_vars['theme'];
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2972
	} elseif ( isset( $input_vars['customize_theme'] ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2973
		$theme = $input_vars['customize_theme'];
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2974
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2975
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2976
	if ( ! empty( $input_vars['customize_autosaved'] ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2977
		$autosaved = true;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2978
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2979
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2980
	if ( isset( $input_vars['customize_messenger_channel'] ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2981
		$messenger_channel = sanitize_key( $input_vars['customize_messenger_channel'] );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2982
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2983
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2984
	/*
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2985
	 * Note that settings must be previewed even outside the customizer preview
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2986
	 * and also in the customizer pane itself. This is to enable loading an existing
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2987
	 * changeset into the customizer. Previewing the settings only has to be prevented
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2988
	 * here in the case of a customize_save action because this will cause WP to think
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2989
	 * there is nothing changed that needs to be saved.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2990
	 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2991
	$is_customize_save_action = (
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2992
		wp_doing_ajax()
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2993
		&&
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2994
		isset( $_REQUEST['action'] )
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2995
		&&
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2996
		'customize_save' === wp_unslash( $_REQUEST['action'] )
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2997
	);
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2998
	$settings_previewed       = ! $is_customize_save_action;
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2999
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3000
	require_once ABSPATH . WPINC . '/class-wp-customize-manager.php';
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3001
	$GLOBALS['wp_customize'] = new WP_Customize_Manager( compact( 'changeset_uuid', 'theme', 'messenger_channel', 'settings_previewed', 'autosaved', 'branching' ) );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3002
}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3003
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3004
/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3005
 * Publishes a snapshot's changes.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3006
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3007
 * @since 4.7.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3008
 * @access private
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3009
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3010
 * @global wpdb                 $wpdb         WordPress database abstraction object.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3011
 * @global WP_Customize_Manager $wp_customize Customizer instance.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3012
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3013
 * @param string  $new_status     New post status.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3014
 * @param string  $old_status     Old post status.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3015
 * @param WP_Post $changeset_post Changeset post object.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3016
 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3017
function _wp_customize_publish_changeset( $new_status, $old_status, $changeset_post ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3018
	global $wp_customize, $wpdb;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3019
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3020
	$is_publishing_changeset = (
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3021
		'customize_changeset' === $changeset_post->post_type
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3022
		&&
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3023
		'publish' === $new_status
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3024
		&&
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3025
		'publish' !== $old_status
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3026
	);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3027
	if ( ! $is_publishing_changeset ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3028
		return;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3029
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3030
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3031
	if ( empty( $wp_customize ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3032
		require_once ABSPATH . WPINC . '/class-wp-customize-manager.php';
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3033
		$wp_customize = new WP_Customize_Manager(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3034
			array(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3035
				'changeset_uuid'     => $changeset_post->post_name,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3036
				'settings_previewed' => false,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3037
			)
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3038
		);
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3039
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3040
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3041
	if ( ! did_action( 'customize_register' ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3042
		/*
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3043
		 * When running from CLI or Cron, the customize_register action will need
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3044
		 * to be triggered in order for core, themes, and plugins to register their
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3045
		 * settings. Normally core will add_action( 'customize_register' ) at
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3046
		 * priority 10 to register the core settings, and if any themes/plugins
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3047
		 * also add_action( 'customize_register' ) at the same priority, they
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3048
		 * will have a $wp_customize with those settings registered since they
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3049
		 * call add_action() afterward, normally. However, when manually doing
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3050
		 * the customize_register action after the setup_theme, then the order
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3051
		 * will be reversed for two actions added at priority 10, resulting in
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3052
		 * the core settings no longer being available as expected to themes/plugins.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3053
		 * So the following manually calls the method that registers the core
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3054
		 * settings up front before doing the action.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3055
		 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3056
		remove_action( 'customize_register', array( $wp_customize, 'register_controls' ) );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3057
		$wp_customize->register_controls();
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3058
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3059
		/** This filter is documented in /wp-includes/class-wp-customize-manager.php */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3060
		do_action( 'customize_register', $wp_customize );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3061
	}
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3062
	$wp_customize->_publish_changeset_values( $changeset_post->ID );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3063
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3064
	/*
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3065
	 * Trash the changeset post if revisions are not enabled. Unpublished
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3066
	 * changesets by default get garbage collected due to the auto-draft status.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3067
	 * When a changeset post is published, however, it would no longer get cleaned
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3068
	 * out. This is a problem when the changeset posts are never displayed anywhere,
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3069
	 * since they would just be endlessly piling up. So here we use the revisions
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3070
	 * feature to indicate whether or not a published changeset should get trashed
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3071
	 * and thus garbage collected.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3072
	 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3073
	if ( ! wp_revisions_enabled( $changeset_post ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3074
		$wp_customize->trash_changeset_post( $changeset_post->ID );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3075
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3076
}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3077
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3078
/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3079
 * Filters changeset post data upon insert to ensure post_name is intact.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3080
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3081
 * This is needed to prevent the post_name from being dropped when the post is
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3082
 * transitioned into pending status by a contributor.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3083
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3084
 * @since 4.7.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3085
 * @see wp_insert_post()
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3086
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3087
 * @param array $post_data          An array of slashed post data.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3088
 * @param array $supplied_post_data An array of sanitized, but otherwise unmodified post data.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3089
 * @returns array Filtered data.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3090
 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3091
function _wp_customize_changeset_filter_insert_post_data( $post_data, $supplied_post_data ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3092
	if ( isset( $post_data['post_type'] ) && 'customize_changeset' === $post_data['post_type'] ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3093
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3094
		// Prevent post_name from being dropped, such as when contributor saves a changeset post as pending.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3095
		if ( empty( $post_data['post_name'] ) && ! empty( $supplied_post_data['post_name'] ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3096
			$post_data['post_name'] = $supplied_post_data['post_name'];
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3097
		}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3098
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3099
	return $post_data;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3100
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3101
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3102
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3103
 * Adds settings for the customize-loader script.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3104
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3105
 * @since 3.4.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3106
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3107
function _wp_customize_loader_settings() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3108
	$admin_origin = parse_url( admin_url() );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3109
	$home_origin  = parse_url( home_url() );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3110
	$cross_domain = ( strtolower( $admin_origin['host'] ) != strtolower( $home_origin['host'] ) );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3111
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3112
	$browser = array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3113
		'mobile' => wp_is_mobile(),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3114
		'ios'    => wp_is_mobile() && preg_match( '/iPad|iPod|iPhone/', $_SERVER['HTTP_USER_AGENT'] ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3115
	);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3116
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3117
	$settings = array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3118
		'url'           => esc_url( admin_url( 'customize.php' ) ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3119
		'isCrossDomain' => $cross_domain,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3120
		'browser'       => $browser,
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3121
		'l10n'          => array(
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3122
			'saveAlert'       => __( 'The changes you made will be lost if you navigate away from this page.' ),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3123
			'mainIframeTitle' => __( 'Customizer' ),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3124
		),
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3125
	);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3126
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3127
	$script = 'var _wpCustomizeLoaderSettings = ' . wp_json_encode( $settings ) . ';';
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3128
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3129
	$wp_scripts = wp_scripts();
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3130
	$data       = $wp_scripts->get_data( 'customize-loader', 'data' );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3131
	if ( $data ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3132
		$script = "$data\n$script";
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3133
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3134
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3135
	$wp_scripts->add_data( 'customize-loader', 'data', $script );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3136
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3137
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3138
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3139
 * Returns a URL to load the Customizer.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3140
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3141
 * @since 3.4.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3142
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3143
 * @param string $stylesheet Optional. Theme to customize. Defaults to current theme.
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3144
 *                           The theme's stylesheet will be urlencoded if necessary.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3145
 * @return string
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3146
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3147
function wp_customize_url( $stylesheet = null ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3148
	$url = admin_url( 'customize.php' );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3149
	if ( $stylesheet ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3150
		$url .= '?theme=' . urlencode( $stylesheet );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3151
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3152
	return esc_url( $url );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3153
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3154
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3155
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3156
 * Prints a script to check whether or not the Customizer is supported,
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3157
 * and apply either the no-customize-support or customize-support class
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3158
 * to the body.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3159
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3160
 * This function MUST be called inside the body tag.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3161
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3162
 * Ideally, call this function immediately after the body tag is opened.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3163
 * This prevents a flash of unstyled content.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3164
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3165
 * It is also recommended that you add the "no-customize-support" class
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3166
 * to the body tag by default.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3167
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3168
 * @since 3.4.0
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3169
 * @since 4.7.0 Support for IE8 and below is explicitly removed via conditional comments.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3170
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3171
function wp_customize_support_script() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3172
	$admin_origin = parse_url( admin_url() );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3173
	$home_origin  = parse_url( home_url() );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3174
	$cross_domain = ( strtolower( $admin_origin['host'] ) != strtolower( $home_origin['host'] ) );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3175
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3176
	?>
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3177
	<!--[if lte IE 8]>
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3178
		<script type="text/javascript">
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3179
			document.body.className = document.body.className.replace( /(^|\s)(no-)?customize-support(?=\s|$)/, '' ) + ' no-customize-support';
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3180
		</script>
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3181
	<![endif]-->
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3182
	<!--[if gte IE 9]><!-->
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3183
		<script type="text/javascript">
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3184
			(function() {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3185
				var request, b = document.body, c = 'className', cs = 'customize-support', rcs = new RegExp('(^|\\s+)(no-)?'+cs+'(\\s+|$)');
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3186
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3187
		<?php	if ( $cross_domain ) : ?>
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3188
				request = (function(){ var xhr = new XMLHttpRequest(); return ('withCredentials' in xhr); })();
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3189
		<?php	else : ?>
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3190
				request = true;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3191
		<?php	endif; ?>
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3192
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3193
				b[c] = b[c].replace( rcs, ' ' );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3194
				// The customizer requires postMessage and CORS (if the site is cross domain)
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3195
				b[c] += ( window.postMessage && request ? ' ' : ' no-' ) + cs;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3196
			}());
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3197
		</script>
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3198
	<!--<![endif]-->
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3199
	<?php
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3200
}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3201
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3202
/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3203
 * Whether the site is being previewed in the Customizer.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3204
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3205
 * @since 4.0.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3206
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3207
 * @global WP_Customize_Manager $wp_customize Customizer instance.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3208
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3209
 * @return bool True if the site is being previewed in the Customizer, false otherwise.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3210
 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3211
function is_customize_preview() {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3212
	global $wp_customize;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3213
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3214
	return ( $wp_customize instanceof WP_Customize_Manager ) && $wp_customize->is_preview();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3215
}
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3216
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3217
/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3218
 * Make sure that auto-draft posts get their post_date bumped or status changed to draft to prevent premature garbage-collection.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3219
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3220
 * When a changeset is updated but remains an auto-draft, ensure the post_date
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3221
 * for the auto-draft posts remains the same so that it will be
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3222
 * garbage-collected at the same time by `wp_delete_auto_drafts()`. Otherwise,
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3223
 * if the changeset is updated to be a draft then update the posts
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3224
 * to have a far-future post_date so that they will never be garbage collected
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3225
 * unless the changeset post itself is deleted.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3226
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3227
 * When a changeset is updated to be a persistent draft or to be scheduled for
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3228
 * publishing, then transition any dependent auto-drafts to a draft status so
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3229
 * that they likewise will not be garbage-collected but also so that they can
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3230
 * be edited in the admin before publishing since there is not yet a post/page
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3231
 * editing flow in the Customizer. See #39752.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3232
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3233
 * @link https://core.trac.wordpress.org/ticket/39752
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3234
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3235
 * @since 4.8.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3236
 * @access private
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3237
 * @see wp_delete_auto_drafts()
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3238
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3239
 * @param string   $new_status Transition to this post status.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3240
 * @param string   $old_status Previous post status.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3241
 * @param \WP_Post $post       Post data.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3242
 * @global wpdb $wpdb
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3243
 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3244
function _wp_keep_alive_customize_changeset_dependent_auto_drafts( $new_status, $old_status, $post ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3245
	global $wpdb;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3246
	unset( $old_status );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3247
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3248
	// Short-circuit if not a changeset or if the changeset was published.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3249
	if ( 'customize_changeset' !== $post->post_type || 'publish' === $new_status ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3250
		return;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3251
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3252
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3253
	$data = json_decode( $post->post_content, true );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3254
	if ( empty( $data['nav_menus_created_posts']['value'] ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3255
		return;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3256
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3257
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3258
	/*
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3259
	 * Actually, in lieu of keeping alive, trash any customization drafts here if the changeset itself is
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3260
	 * getting trashed. This is needed because when a changeset transitions to a draft, then any of the
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3261
	 * dependent auto-draft post/page stubs will also get transitioned to customization drafts which
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3262
	 * are then visible in the WP Admin. We cannot wait for the deletion of the changeset in which
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3263
	 * _wp_delete_customize_changeset_dependent_auto_drafts() will be called, since they need to be
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3264
	 * trashed to remove from visibility immediately.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3265
	 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3266
	if ( 'trash' === $new_status ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3267
		foreach ( $data['nav_menus_created_posts']['value'] as $post_id ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3268
			if ( ! empty( $post_id ) && 'draft' === get_post_status( $post_id ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3269
				wp_trash_post( $post_id );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3270
			}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3271
		}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3272
		return;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3273
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3274
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3275
	$post_args = array();
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3276
	if ( 'auto-draft' === $new_status ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3277
		/*
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3278
		 * Keep the post date for the post matching the changeset
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3279
		 * so that it will not be garbage-collected before the changeset.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3280
		 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3281
		$post_args['post_date'] = $post->post_date; // Note wp_delete_auto_drafts() only looks at this date.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3282
	} else {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3283
		/*
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3284
		 * Since the changeset no longer has an auto-draft (and it is not published)
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3285
		 * it is now a persistent changeset, a long-lived draft, and so any
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3286
		 * associated auto-draft posts should likewise transition into having a draft
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3287
		 * status. These drafts will be treated differently than regular drafts in
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3288
		 * that they will be tied to the given changeset. The publish meta box is
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3289
		 * replaced with a notice about how the post is part of a set of customized changes
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3290
		 * which will be published when the changeset is published.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3291
		 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3292
		$post_args['post_status'] = 'draft';
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3293
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3294
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3295
	foreach ( $data['nav_menus_created_posts']['value'] as $post_id ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3296
		if ( empty( $post_id ) || 'auto-draft' !== get_post_status( $post_id ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3297
			continue;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3298
		}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3299
		$wpdb->update(
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3300
			$wpdb->posts,
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3301
			$post_args,
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3302
			array( 'ID' => $post_id )
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3303
		);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3304
		clean_post_cache( $post_id );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3305
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3306
}