wp/wp-admin/includes/theme.php
author ymh <ymh.work@gmail.com>
Mon, 14 Oct 2019 17:39:30 +0200
changeset 7 cf61fcea0001
parent 5 5e2f62d02dcd
child 9 177826044cd9
permissions -rw-r--r--
resynchronize code repo with production
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     1
<?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     2
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     3
 * WordPress Theme Administration API
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 Administration
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
 * Remove a theme
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    11
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    12
 * @since 2.8.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    13
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    14
 * @global WP_Filesystem_Base $wp_filesystem Subclass
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    15
 *
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    16
 * @param string $stylesheet Stylesheet of the theme to delete
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    17
 * @param string $redirect Redirect to page when complete.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    18
 * @return void|bool|WP_Error When void, echoes content.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    19
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    20
function delete_theme($stylesheet, $redirect = '') {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    21
	global $wp_filesystem;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    22
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    23
	if ( empty($stylesheet) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    24
		return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    25
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    26
	if ( empty( $redirect ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    27
		$redirect = wp_nonce_url('themes.php?action=delete&stylesheet=' . urlencode( $stylesheet ), 'delete-theme_' . $stylesheet);
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    28
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    29
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    30
	ob_start();
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    31
	$credentials = request_filesystem_credentials( $redirect );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    32
	$data = ob_get_clean();
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    33
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    34
	if ( false === $credentials ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    35
		if ( ! empty( $data ) ){
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    36
			include_once( ABSPATH . 'wp-admin/admin-header.php');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    37
			echo $data;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    38
			include( ABSPATH . 'wp-admin/admin-footer.php');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    39
			exit;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    40
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    41
		return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    42
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    43
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    44
	if ( ! WP_Filesystem( $credentials ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    45
		ob_start();
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    46
		request_filesystem_credentials( $redirect, '', true ); // Failed to connect, Error and request again.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    47
		$data = ob_get_clean();
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    48
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    49
		if ( ! empty($data) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    50
			include_once( ABSPATH . 'wp-admin/admin-header.php');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    51
			echo $data;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    52
			include( ABSPATH . 'wp-admin/admin-footer.php');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    53
			exit;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    54
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    55
		return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    56
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    57
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    58
	if ( ! is_object($wp_filesystem) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    59
		return new WP_Error('fs_unavailable', __('Could not access filesystem.'));
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    60
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    61
	if ( is_wp_error($wp_filesystem->errors) && $wp_filesystem->errors->get_error_code() )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    62
		return new WP_Error('fs_error', __('Filesystem error.'), $wp_filesystem->errors);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    63
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    64
	// Get the base plugin folder.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    65
	$themes_dir = $wp_filesystem->wp_themes_dir();
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    66
	if ( empty( $themes_dir ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    67
		return new WP_Error( 'fs_no_themes_dir', __( 'Unable to locate WordPress theme directory.' ) );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    68
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    69
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    70
	$themes_dir = trailingslashit( $themes_dir );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    71
	$theme_dir = trailingslashit( $themes_dir . $stylesheet );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    72
	$deleted = $wp_filesystem->delete( $theme_dir, true );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    73
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    74
	if ( ! $deleted ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    75
		return new WP_Error( 'could_not_remove_theme', sprintf( __( 'Could not fully remove the theme %s.' ), $stylesheet ) );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    76
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    77
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    78
	$theme_translations = wp_get_installed_translations( 'themes' );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    79
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    80
	// Remove language files, silently.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    81
	if ( ! empty( $theme_translations[ $stylesheet ] ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    82
		$translations = $theme_translations[ $stylesheet ];
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    83
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    84
		foreach ( $translations as $translation => $data ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    85
			$wp_filesystem->delete( WP_LANG_DIR . '/themes/' . $stylesheet . '-' . $translation . '.po' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    86
			$wp_filesystem->delete( WP_LANG_DIR . '/themes/' . $stylesheet . '-' . $translation . '.mo' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    87
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    88
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    89
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    90
	// Remove the theme from allowed themes on the network.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    91
	if ( is_multisite() ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    92
		WP_Theme::network_disable_theme( $stylesheet );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    93
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    94
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    95
	// Force refresh of theme update information.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    96
	delete_site_transient( 'update_themes' );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    97
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    98
	return true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    99
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   100
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   101
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   102
 * Get the Page Templates available in this theme
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   103
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   104
 * @since 1.5.0
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   105
 * @since 4.7.0 Added the `$post_type` parameter.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   106
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   107
 * @param WP_Post|null $post      Optional. The post being edited, provided for context.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   108
 * @param string       $post_type Optional. Post type to get the templates for. Default 'page'.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   109
 * @return array Key is the template name, value is the filename of the template
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   110
 */
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   111
function get_page_templates( $post = null, $post_type = 'page' ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   112
	return array_flip( wp_get_theme()->get_page_templates( $post, $post_type ) );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   113
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   114
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   115
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   116
 * Tidies a filename for url display by the theme editor.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   117
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   118
 * @since 2.9.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   119
 * @access private
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   120
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   121
 * @param string $fullpath Full path to the theme file
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   122
 * @param string $containingfolder Path of the theme parent folder
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   123
 * @return string
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   124
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   125
function _get_template_edit_filename($fullpath, $containingfolder) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   126
	return str_replace(dirname(dirname( $containingfolder )) , '', $fullpath);
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
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   130
 * Check if there is an update for a theme available.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   131
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   132
 * Will display link, if there is an update available.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   133
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   134
 * @since 2.7.0
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   135
 * @see get_theme_update_available()
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   136
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   137
 * @param WP_Theme $theme Theme data object.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   138
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   139
function theme_update_available( $theme ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   140
	echo get_theme_update_available( $theme );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   141
}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   142
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   143
/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   144
 * Retrieve the update link if there is a theme update available.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   145
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   146
 * Will return a link if there is an update available.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   147
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   148
 * @since 3.8.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   149
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   150
 * @staticvar object $themes_update
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   151
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   152
 * @param WP_Theme $theme WP_Theme object.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   153
 * @return false|string HTML for the update link, or false if invalid info was passed.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   154
 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   155
function get_theme_update_available( $theme ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   156
	static $themes_update = null;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   157
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   158
	if ( !current_user_can('update_themes' ) )
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   159
		return false;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   160
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   161
	if ( !isset($themes_update) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   162
		$themes_update = get_site_transient('update_themes');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   163
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   164
	if ( ! ( $theme instanceof WP_Theme ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   165
		return false;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   166
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   167
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   168
	$stylesheet = $theme->get_stylesheet();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   169
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   170
	$html = '';
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   171
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   172
	if ( isset($themes_update->response[ $stylesheet ]) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   173
		$update = $themes_update->response[ $stylesheet ];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   174
		$theme_name = $theme->display('Name');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   175
		$details_url = add_query_arg(array('TB_iframe' => 'true', 'width' => 1024, 'height' => 800), $update['url']); //Theme browser inside WP? replace this, Also, theme preview JS will override this on the available list.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   176
		$update_url = wp_nonce_url( admin_url( 'update.php?action=upgrade-theme&amp;theme=' . urlencode( $stylesheet ) ), 'upgrade-theme_' . $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
		if ( !is_multisite() ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   179
			if ( ! current_user_can('update_themes') ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   180
				/* translators: 1: theme name, 2: theme details URL, 3: additional link attributes, 4: version number */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   181
				$html = sprintf( '<p><strong>' . __( 'There is a new version of %1$s available. <a href="%2$s" %3$s>View version %4$s details</a>.' ) . '</strong></p>',
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   182
					$theme_name,
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   183
					esc_url( $details_url ),
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   184
					sprintf( 'class="thickbox open-plugin-details-modal" aria-label="%s"',
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   185
						/* translators: 1: theme name, 2: version number */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   186
						esc_attr( sprintf( __( 'View %1$s version %2$s details' ), $theme_name, $update['new_version'] ) )
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   187
					),
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   188
					$update['new_version']
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   189
				);
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   190
			} elseif ( empty( $update['package'] ) ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   191
				/* translators: 1: theme name, 2: theme details URL, 3: additional link attributes, 4: version number */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   192
				$html = sprintf( '<p><strong>' . __( 'There is a new version of %1$s available. <a href="%2$s" %3$s>View version %4$s details</a>. <em>Automatic update is unavailable for this theme.</em>' ) . '</strong></p>',
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   193
					$theme_name,
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   194
					esc_url( $details_url ),
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   195
					sprintf( 'class="thickbox open-plugin-details-modal" aria-label="%s"',
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   196
						/* translators: 1: theme name, 2: version number */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   197
						esc_attr( sprintf( __( 'View %1$s version %2$s details' ), $theme_name, $update['new_version'] ) )
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   198
					),
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   199
					$update['new_version']
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   200
				);
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   201
			} else {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   202
				/* translators: 1: theme name, 2: theme details URL, 3: additional link attributes, 4: version number, 5: update URL, 6: additional link attributes */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   203
				$html = sprintf( '<p><strong>' . __( 'There is a new version of %1$s available. <a href="%2$s" %3$s>View version %4$s details</a> or <a href="%5$s" %6$s>update now</a>.' ) . '</strong></p>',
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   204
					$theme_name,
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   205
					esc_url( $details_url ),
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   206
					sprintf( 'class="thickbox open-plugin-details-modal" aria-label="%s"',
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   207
						/* translators: 1: theme name, 2: version number */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   208
						esc_attr( sprintf( __( 'View %1$s version %2$s details' ), $theme_name, $update['new_version'] ) )
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   209
					),
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   210
					$update['new_version'],
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   211
					$update_url,
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   212
					sprintf( 'aria-label="%s" id="update-theme" data-slug="%s"',
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   213
						/* translators: %s: theme name */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   214
						esc_attr( sprintf( __( 'Update %s now' ), $theme_name ) ),
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   215
						$stylesheet
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   216
					)
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   217
				);
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   218
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   219
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   220
	}
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   221
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   222
	return $html;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   223
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   224
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   225
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   226
 * Retrieve list of WordPress theme features (aka theme tags)
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   227
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   228
 * @since 3.1.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
 * @param bool $api Optional. Whether try to fetch tags from the WordPress.org API. Defaults to true.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   231
 * @return array Array of features keyed by category with translations keyed by slug.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   232
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   233
function get_theme_feature_list( $api = true ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   234
	// Hard-coded list is used if api not accessible.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   235
	$features = array(
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   236
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   237
		__( 'Subject' )  => array(
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   238
			'blog'           => __( 'Blog' ),
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   239
			'e-commerce'     => __( 'E-Commerce' ),
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   240
			'education'      => __( 'Education' ),
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   241
			'entertainment'  => __( 'Entertainment' ),
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   242
			'food-and-drink' => __( 'Food & Drink' ),
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   243
			'holiday'        => __( 'Holiday' ),
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   244
			'news'           => __( 'News' ),
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   245
			'photography'    => __( 'Photography' ),
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   246
			'portfolio'      => __( 'Portfolio' ),
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   247
		),
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   248
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   249
		__( 'Features' ) => array(
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   250
			'accessibility-ready'   => __( 'Accessibility Ready' ),
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   251
			'custom-background'     => __( 'Custom Background' ),
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   252
			'custom-colors'         => __( 'Custom Colors' ),
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   253
			'custom-header'         => __( 'Custom Header' ),
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   254
			'custom-logo'           => __( 'Custom Logo' ),
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   255
			'editor-style'          => __( 'Editor Style' ),
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   256
			'featured-image-header' => __( 'Featured Image Header' ),
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   257
			'featured-images'       => __( 'Featured Images' ),
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   258
			'footer-widgets'        => __( 'Footer Widgets' ),
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   259
			'full-width-template'   => __( 'Full Width Template' ),
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   260
			'post-formats'          => __( 'Post Formats' ),
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   261
			'sticky-post'           => __( 'Sticky Post' ),
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   262
			'theme-options'         => __( 'Theme Options' ),
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   263
		),
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   264
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   265
		__( 'Layout' ) => array(
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   266
			'grid-layout'   => __( 'Grid Layout' ),
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   267
			'one-column'    => __( 'One Column' ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   268
			'two-columns'   => __( 'Two Columns' ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   269
			'three-columns' => __( 'Three Columns' ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   270
			'four-columns'  => __( 'Four Columns' ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   271
			'left-sidebar'  => __( 'Left Sidebar' ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   272
			'right-sidebar' => __( 'Right Sidebar' ),
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   273
		)
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   274
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   275
	);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   276
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   277
	if ( ! $api || ! current_user_can( 'install_themes' ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   278
		return $features;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   279
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   280
	if ( !$feature_list = get_site_transient( 'wporg_theme_feature_list' ) )
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   281
		set_site_transient( 'wporg_theme_feature_list', array(), 3 * HOUR_IN_SECONDS );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   282
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   283
	if ( !$feature_list ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   284
		$feature_list = themes_api( 'feature_list', array() );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   285
		if ( is_wp_error( $feature_list ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   286
			return $features;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   287
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   288
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   289
	if ( !$feature_list )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   290
		return $features;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   291
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   292
	set_site_transient( 'wporg_theme_feature_list', $feature_list, 3 * HOUR_IN_SECONDS );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   293
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   294
	$category_translations = array(
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   295
		'Layout'   => __( 'Layout' ),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   296
		'Features' => __( 'Features' ),
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   297
		'Subject'  => __( 'Subject' ),
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   298
	);
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
	// Loop over the wporg canonical list and apply translations
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   301
	$wporg_features = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   302
	foreach ( (array) $feature_list as $feature_category => $feature_items ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   303
		if ( isset($category_translations[$feature_category]) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   304
			$feature_category = $category_translations[$feature_category];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   305
		$wporg_features[$feature_category] = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   306
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   307
		foreach ( $feature_items as $feature ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   308
			if ( isset($features[$feature_category][$feature]) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   309
				$wporg_features[$feature_category][$feature] = $features[$feature_category][$feature];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   310
			else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   311
				$wporg_features[$feature_category][$feature] = $feature;
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
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   315
	return $wporg_features;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   316
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   317
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   318
/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   319
 * Retrieves theme installer pages from the WordPress.org Themes API.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   320
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   321
 * It is possible for a theme to override the Themes API result with three
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   322
 * filters. Assume this is for themes, which can extend on the Theme Info to
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   323
 * offer more choices. This is very powerful and must be used with care, when
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   324
 * overriding the filters.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   325
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   326
 * The first filter, {@see 'themes_api_args'}, is for the args and gives the action
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   327
 * as the second parameter. The hook for {@see 'themes_api_args'} must ensure that
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   328
 * an object is returned.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   329
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   330
 * The second filter, {@see 'themes_api'}, allows a plugin to override the WordPress.org
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   331
 * Theme API entirely. If `$action` is 'query_themes', 'theme_information', or 'feature_list',
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   332
 * an object MUST be passed. If `$action` is 'hot_tags', an array should be passed.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   333
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   334
 * Finally, the third filter, {@see 'themes_api_result'}, makes it possible to filter the
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   335
 * response object or array, depending on the `$action` type.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   336
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   337
 * Supported arguments per action:
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   338
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   339
 * | Argument Name      | 'query_themes' | 'theme_information' | 'hot_tags' | 'feature_list'   |
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   340
 * | -------------------| :------------: | :-----------------: | :--------: | :--------------: |
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   341
 * | `$slug`            | No             |  Yes                | No         | No               |
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   342
 * | `$per_page`        | Yes            |  No                 | No         | No               |
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   343
 * | `$page`            | Yes            |  No                 | No         | No               |
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   344
 * | `$number`          | No             |  No                 | Yes        | No               |
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   345
 * | `$search`          | Yes            |  No                 | No         | No               |
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   346
 * | `$tag`             | Yes            |  No                 | No         | No               |
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   347
 * | `$author`          | Yes            |  No                 | No         | No               |
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   348
 * | `$user`            | Yes            |  No                 | No         | No               |
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   349
 * | `$browse`          | Yes            |  No                 | No         | No               |
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   350
 * | `$locale`          | Yes            |  Yes                | No         | No               |
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   351
 * | `$fields`          | Yes            |  Yes                | No         | No               |
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   352
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   353
 * @since 2.8.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   354
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   355
 * @param string       $action API action to perform: 'query_themes', 'theme_information',
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   356
 *                             'hot_tags' or 'feature_list'.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   357
 * @param array|object $args   {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   358
 *     Optional. Array or object of arguments to serialize for the Themes API.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   359
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   360
 *     @type string  $slug     The theme slug. Default empty.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   361
 *     @type int     $per_page Number of themes per page. Default 24.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   362
 *     @type int     $page     Number of current page. Default 1.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   363
 *     @type int     $number   Number of tags to be queried.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   364
 *     @type string  $search   A search term. Default empty.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   365
 *     @type string  $tag      Tag to filter themes. Default empty.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   366
 *     @type string  $author   Username of an author to filter themes. Default empty.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   367
 *     @type string  $user     Username to query for their favorites. Default empty.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   368
 *     @type string  $browse   Browse view: 'featured', 'popular', 'updated', 'favorites'.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   369
 *     @type string  $locale   Locale to provide context-sensitive results. Default is the value of get_locale().
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   370
 *     @type array   $fields   {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   371
 *         Array of fields which should or should not be returned.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   372
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   373
 *         @type bool $description        Whether to return the theme full description. Default false.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   374
 *         @type bool $sections           Whether to return the theme readme sections: description, installation,
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   375
 *                                        FAQ, screenshots, other notes, and changelog. Default false.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   376
 *         @type bool $rating             Whether to return the rating in percent and total number of ratings.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   377
 *                                        Default false.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   378
 *         @type bool $ratings            Whether to return the number of rating for each star (1-5). Default false.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   379
 *         @type bool $downloaded         Whether to return the download count. Default false.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   380
 *         @type bool $downloadlink       Whether to return the download link for the package. Default false.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   381
 *         @type bool $last_updated       Whether to return the date of the last update. Default false.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   382
 *         @type bool $tags               Whether to return the assigned tags. Default false.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   383
 *         @type bool $homepage           Whether to return the theme homepage link. Default false.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   384
 *         @type bool $screenshots        Whether to return the screenshots. Default false.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   385
 *         @type int  $screenshot_count   Number of screenshots to return. Default 1.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   386
 *         @type bool $screenshot_url     Whether to return the URL of the first screenshot. Default false.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   387
 *         @type bool $photon_screenshots Whether to return the screenshots via Photon. Default false.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   388
 *         @type bool $template           Whether to return the slug of the parent theme. Default false.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   389
 *         @type bool $parent             Whether to return the slug, name and homepage of the parent theme. Default false.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   390
 *         @type bool $versions           Whether to return the list of all available versions. Default false.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   391
 *         @type bool $theme_url          Whether to return theme's URL. Default false.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   392
 *         @type bool $extended_author    Whether to return nicename or nicename and display name. Default false.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   393
 *     }
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   394
 * }
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   395
 * @return object|array|WP_Error Response object or array on success, WP_Error on failure. See the
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   396
 *         {@link https://developer.wordpress.org/reference/functions/themes_api/ function reference article}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   397
 *         for more information on the make-up of possible return objects depending on the value of `$action`.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   398
 */
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   399
function themes_api( $action, $args = array() ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   400
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   401
	if ( is_array( $args ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   402
		$args = (object) $args;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   403
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   404
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   405
	if ( ! isset( $args->per_page ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   406
		$args->per_page = 24;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   407
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   408
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   409
	if ( ! isset( $args->locale ) ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   410
		$args->locale = get_user_locale();
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   411
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   412
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   413
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   414
	 * Filters arguments used to query for installer pages from the WordPress.org Themes API.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   415
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   416
	 * Important: An object MUST be returned to this filter.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   417
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   418
	 * @since 2.8.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   419
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   420
	 * @param object $args   Arguments used to query for installer pages from the WordPress.org Themes API.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   421
	 * @param string $action Requested action. Likely values are 'theme_information',
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   422
	 *                       'feature_list', or 'query_themes'.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   423
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   424
	$args = apply_filters( 'themes_api_args', $args, $action );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   425
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   426
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   427
	 * Filters whether to override the WordPress.org Themes API.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   428
	 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   429
	 * Passing a non-false value will effectively short-circuit the WordPress.org API request.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   430
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   431
	 * If `$action` is 'query_themes', 'theme_information', or 'feature_list', an object MUST
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   432
	 * be passed. If `$action` is 'hot_tags', an array should be passed.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   433
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   434
	 * @since 2.8.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   435
	 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   436
	 * @param false|object|array $override Whether to override the WordPress.org Themes API. Default false.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   437
	 * @param string             $action   Requested action. Likely values are 'theme_information',
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   438
	 *                                    'feature_list', or 'query_themes'.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   439
	 * @param object             $args     Arguments used to query for installer pages from the Themes API.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   440
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   441
	$res = apply_filters( 'themes_api', false, $action, $args );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   442
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   443
	if ( ! $res ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   444
		// include an unmodified $wp_version
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   445
		include( ABSPATH . WPINC . '/version.php' );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   446
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   447
		$url = $http_url = 'http://api.wordpress.org/themes/info/1.0/';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   448
		if ( $ssl = wp_http_supports( array( 'ssl' ) ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   449
			$url = set_url_scheme( $url, 'https' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   450
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   451
		$http_args = array(
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   452
			'user-agent' => 'WordPress/' . $wp_version . '; ' . home_url( '/' ),
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   453
			'body' => array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   454
				'action' => $action,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   455
				'request' => serialize( $args )
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
		$request = wp_remote_post( $url, $http_args );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   459
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   460
		if ( $ssl && is_wp_error( $request ) ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   461
			if ( ! wp_doing_ajax() ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   462
				trigger_error(
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   463
					sprintf(
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   464
						/* translators: %s: support forums URL */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   465
						__( 'An unexpected error occurred. Something may be wrong with WordPress.org or this server&#8217;s configuration. If you continue to have problems, please try the <a href="%s">support forums</a>.' ),
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   466
						__( 'https://wordpress.org/support/' )
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   467
					) . ' ' . __( '(WordPress could not establish a secure connection to WordPress.org. Please contact your server administrator.)' ),
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   468
					headers_sent() || WP_DEBUG ? E_USER_WARNING : E_USER_NOTICE
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   469
				);
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   470
			}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   471
			$request = wp_remote_post( $http_url, $http_args );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   472
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   473
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   474
		if ( is_wp_error($request) ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   475
			$res = new WP_Error( 'themes_api_failed',
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   476
				sprintf(
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   477
					/* translators: %s: support forums URL */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   478
					__( 'An unexpected error occurred. Something may be wrong with WordPress.org or this server&#8217;s configuration. If you continue to have problems, please try the <a href="%s">support forums</a>.' ),
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   479
					__( 'https://wordpress.org/support/' )
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   480
				),
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   481
				$request->get_error_message()
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   482
			);
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   483
		} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   484
			$res = maybe_unserialize( wp_remote_retrieve_body( $request ) );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   485
			if ( ! is_object( $res ) && ! is_array( $res ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   486
				$res = new WP_Error( 'themes_api_failed',
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   487
					sprintf(
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   488
						/* translators: %s: support forums URL */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   489
						__( 'An unexpected error occurred. Something may be wrong with WordPress.org or this server&#8217;s configuration. If you continue to have problems, please try the <a href="%s">support forums</a>.' ),
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   490
						__( 'https://wordpress.org/support/' )
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   491
					),
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   492
					wp_remote_retrieve_body( $request )
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   493
				);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   494
			}
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   495
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   496
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   497
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   498
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   499
	 * Filters the returned WordPress.org Themes API response.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   500
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   501
	 * @since 2.8.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   502
	 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   503
	 * @param array|object|WP_Error $res    WordPress.org Themes API response.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   504
	 * @param string                $action Requested action. Likely values are 'theme_information',
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   505
	 *                                      'feature_list', or 'query_themes'.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   506
	 * @param object                $args   Arguments used to query for installer pages from the WordPress.org Themes API.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   507
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   508
	return apply_filters( 'themes_api_result', $res, $action, $args );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   509
}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   510
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   511
/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   512
 * Prepare themes for JavaScript.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   513
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   514
 * @since 3.8.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   515
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   516
 * @param array $themes Optional. Array of WP_Theme objects to prepare.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   517
 *                      Defaults to all allowed themes.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   518
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   519
 * @return array An associative array of theme data, sorted by name.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   520
 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   521
function wp_prepare_themes_for_js( $themes = null ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   522
	$current_theme = get_stylesheet();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   523
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   524
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   525
	 * Filters theme data before it is prepared for JavaScript.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   526
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   527
	 * Passing a non-empty array will result in wp_prepare_themes_for_js() returning
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   528
	 * early with that value instead.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   529
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   530
	 * @since 4.2.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   531
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   532
	 * @param array      $prepared_themes An associative array of theme data. Default empty array.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   533
	 * @param null|array $themes          An array of WP_Theme objects to prepare, if any.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   534
	 * @param string     $current_theme   The current theme slug.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   535
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   536
	$prepared_themes = (array) apply_filters( 'pre_prepare_themes_for_js', array(), $themes, $current_theme );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   537
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   538
	if ( ! empty( $prepared_themes ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   539
		return $prepared_themes;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   540
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   541
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   542
	// Make sure the current theme is listed first.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   543
	$prepared_themes[ $current_theme ] = array();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   544
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   545
	if ( null === $themes ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   546
		$themes = wp_get_themes( array( 'allowed' => true ) );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   547
		if ( ! isset( $themes[ $current_theme ] ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   548
			$themes[ $current_theme ] = wp_get_theme();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   549
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   550
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   551
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   552
	$updates = array();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   553
	if ( current_user_can( 'update_themes' ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   554
		$updates_transient = get_site_transient( 'update_themes' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   555
		if ( isset( $updates_transient->response ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   556
			$updates = $updates_transient->response;
0
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
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   560
	WP_Theme::sort_by_name( $themes );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   561
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   562
	$parents = array();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   563
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   564
	foreach ( $themes as $theme ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   565
		$slug = $theme->get_stylesheet();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   566
		$encoded_slug = urlencode( $slug );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   567
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   568
		$parent = false;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   569
		if ( $theme->parent() ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   570
			$parent = $theme->parent();
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   571
			$parents[ $slug ] = $parent->get_stylesheet();
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   572
			$parent = $parent->display( 'Name' );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   573
		}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   574
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   575
		$customize_action = null;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   576
		if ( current_user_can( 'edit_theme_options' ) && current_user_can( 'customize' ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   577
			$customize_action = esc_url( add_query_arg(
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   578
				array(
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   579
					'return' => urlencode( esc_url_raw( remove_query_arg( wp_removable_query_args(), wp_unslash( $_SERVER['REQUEST_URI'] ) ) ) ),
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   580
				),
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   581
				wp_customize_url( $slug )
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   582
			) );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   583
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   584
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   585
		$prepared_themes[ $slug ] = array(
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   586
			'id'           => $slug,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   587
			'name'         => $theme->display( 'Name' ),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   588
			'screenshot'   => array( $theme->get_screenshot() ), // @todo multiple
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   589
			'description'  => $theme->display( 'Description' ),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   590
			'author'       => $theme->display( 'Author', false, true ),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   591
			'authorAndUri' => $theme->display( 'Author' ),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   592
			'version'      => $theme->display( 'Version' ),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   593
			'tags'         => $theme->display( 'Tags' ),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   594
			'parent'       => $parent,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   595
			'active'       => $slug === $current_theme,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   596
			'hasUpdate'    => isset( $updates[ $slug ] ),
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   597
			'hasPackage'   => isset( $updates[ $slug ] ) && ! empty( $updates[ $slug ][ 'package' ] ),
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   598
			'update'       => get_theme_update_available( $theme ),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   599
			'actions'      => array(
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   600
				'activate' => current_user_can( 'switch_themes' ) ? wp_nonce_url( admin_url( 'themes.php?action=activate&amp;stylesheet=' . $encoded_slug ), 'switch-theme_' . $slug ) : null,
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   601
				'customize' => $customize_action,
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   602
				'delete'   => current_user_can( 'delete_themes' ) ? wp_nonce_url( admin_url( 'themes.php?action=delete&amp;stylesheet=' . $encoded_slug ), 'delete-theme_' . $slug ) : null,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   603
			),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   604
		);
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   605
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   606
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   607
	// Remove 'delete' action if theme has an active child
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   608
	if ( ! empty( $parents ) && array_key_exists( $current_theme, $parents ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   609
		unset( $prepared_themes[ $parents[ $current_theme ] ]['actions']['delete'] );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   610
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   611
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   612
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   613
	 * Filters the themes prepared for JavaScript, for themes.php.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   614
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   615
	 * Could be useful for changing the order, which is by name by default.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   616
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   617
	 * @since 3.8.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   618
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   619
	 * @param array $prepared_themes Array of themes.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   620
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   621
	$prepared_themes = apply_filters( 'wp_prepare_themes_for_js', $prepared_themes );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   622
	$prepared_themes = array_values( $prepared_themes );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   623
	return array_filter( $prepared_themes );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   624
}
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   625
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   626
/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   627
 * Print JS templates for the theme-browsing UI in the Customizer.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   628
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   629
 * @since 4.2.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   630
 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   631
function customize_themes_print_templates() {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   632
	?>
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   633
	<script type="text/html" id="tmpl-customize-themes-details-view">
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   634
		<div class="theme-backdrop"></div>
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   635
		<div class="theme-wrap wp-clearfix" role="document">
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   636
			<div class="theme-header">
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   637
				<button type="button" class="left dashicons dashicons-no"><span class="screen-reader-text"><?php _e( 'Show previous theme' ); ?></span></button>
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   638
				<button type="button" class="right dashicons dashicons-no"><span class="screen-reader-text"><?php _e( 'Show next theme' ); ?></span></button>
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   639
				<button type="button" class="close dashicons dashicons-no"><span class="screen-reader-text"><?php _e( 'Close details dialog' ); ?></span></button>
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   640
			</div>
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   641
			<div class="theme-about wp-clearfix">
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   642
				<div class="theme-screenshots">
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   643
				<# if ( data.screenshot && data.screenshot[0] ) { #>
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   644
					<div class="screenshot"><img src="{{ data.screenshot[0] }}" alt="" /></div>
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   645
				<# } else { #>
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   646
					<div class="screenshot blank"></div>
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   647
				<# } #>
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   648
				</div>
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   649
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   650
				<div class="theme-info">
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   651
					<# if ( data.active ) { #>
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   652
						<span class="current-label"><?php _e( 'Current Theme' ); ?></span>
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   653
					<# } #>
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   654
					<h2 class="theme-name">{{{ data.name }}}<span class="theme-version"><?php printf( __( 'Version: %s' ), '{{ data.version }}' ); ?></span></h2>
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   655
					<h3 class="theme-author"><?php printf( __( 'By %s' ), '{{{ data.authorAndUri }}}' ); ?></h3>
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   656
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   657
					<# if ( data.stars && 0 != data.num_ratings ) { #>
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   658
						<div class="theme-rating">
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   659
							{{{ data.stars }}}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   660
							<span class="num-ratings">
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   661
								<?php
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   662
								/* translators: %s: number of ratings */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   663
								echo sprintf( __( '(%s ratings)' ), '{{ data.num_ratings }}' );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   664
								?>
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   665
							</span>
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   666
						</div>
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   667
					<# } #>
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   668
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   669
					<# if ( data.hasUpdate ) { #>
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   670
						<div class="notice notice-warning notice-alt notice-large" data-slug="{{ data.id }}">
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   671
							<h3 class="notice-title"><?php _e( 'Update Available' ); ?></h3>
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   672
							{{{ data.update }}}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   673
						</div>
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   674
					<# } #>
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   675
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   676
					<# if ( data.parent ) { #>
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   677
						<p class="parent-theme"><?php printf( __( 'This is a child theme of %s.' ), '<strong>{{{ data.parent }}}</strong>' ); ?></p>
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   678
					<# } #>
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   679
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   680
					<p class="theme-description">{{{ data.description }}}</p>
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   681
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   682
					<# if ( data.tags ) { #>
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   683
						<p class="theme-tags"><span><?php _e( 'Tags:' ); ?></span> {{{ data.tags }}}</p>
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   684
					<# } #>
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   685
				</div>
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   686
			</div>
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   687
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   688
			<div class="theme-actions">
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   689
				<# if ( data.active ) { #>
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   690
					<button type="button" class="button button-primary customize-theme"><?php _e( 'Customize' ); ?></button>
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   691
				<# } else if ( 'installed' === data.type ) { #>
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   692
					<?php if ( current_user_can( 'delete_themes' ) ) { ?>
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   693
						<# if ( data.actions && data.actions['delete'] ) { #>
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   694
							<a href="{{{ data.actions['delete'] }}}" data-slug="{{ data.id }}" class="button button-secondary delete-theme"><?php _e( 'Delete' ); ?></a>
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   695
						<# } #>
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   696
					<?php } ?>
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   697
					<button type="button" class="button button-primary preview-theme" data-slug="{{ data.id }}"><?php _e( 'Live Preview' ); ?></button>
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   698
				<# } else { #>
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   699
					<button type="button" class="button theme-install" data-slug="{{ data.id }}"><?php _e( 'Install' ); ?></button>
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   700
					<button type="button" class="button button-primary theme-install preview" data-slug="{{ data.id }}"><?php _e( 'Install &amp; Preview' ); ?></button>
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   701
				<# } #>
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   702
			</div>
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   703
		</div>
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   704
	</script>
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   705
	<?php
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   706
}