wp/wp-admin/includes/theme.php
author ymh <ymh.work@gmail.com>
Tue, 09 Jun 2015 11:14:17 +0000
changeset 6 490d5cc509ed
parent 5 5e2f62d02dcd
child 7 cf61fcea0001
permissions -rw-r--r--
update portfolio
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
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    14
 * @param string $stylesheet Stylesheet of the theme to delete
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    15
 * @param string $redirect Redirect to page when complete.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    16
 * @return mixed
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    17
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    18
function delete_theme($stylesheet, $redirect = '') {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    19
	global $wp_filesystem;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    20
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    21
	if ( empty($stylesheet) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    22
		return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    23
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    24
	ob_start();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    25
	if ( empty( $redirect ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    26
		$redirect = wp_nonce_url('themes.php?action=delete&stylesheet=' . urlencode( $stylesheet ), 'delete-theme_' . $stylesheet);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    27
	if ( false === ($credentials = request_filesystem_credentials($redirect)) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    28
		$data = ob_get_contents();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    29
		ob_end_clean();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    30
		if ( ! empty($data) ){
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    31
			include_once( ABSPATH . 'wp-admin/admin-header.php');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    32
			echo $data;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    33
			include( ABSPATH . 'wp-admin/admin-footer.php');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    34
			exit;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    35
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    36
		return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    37
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    38
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    39
	if ( ! WP_Filesystem($credentials) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    40
		request_filesystem_credentials($redirect, '', true); // Failed to connect, Error and request again
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    41
		$data = ob_get_contents();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    42
		ob_end_clean();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    43
		if ( ! empty($data) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    44
			include_once( ABSPATH . 'wp-admin/admin-header.php');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    45
			echo $data;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    46
			include( ABSPATH . 'wp-admin/admin-footer.php');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    47
			exit;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    48
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    49
		return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    50
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    51
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    52
	if ( ! is_object($wp_filesystem) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    53
		return new WP_Error('fs_unavailable', __('Could not access filesystem.'));
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    54
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    55
	if ( is_wp_error($wp_filesystem->errors) && $wp_filesystem->errors->get_error_code() )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    56
		return new WP_Error('fs_error', __('Filesystem error.'), $wp_filesystem->errors);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    57
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    58
	// Get the base plugin folder.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    59
	$themes_dir = $wp_filesystem->wp_themes_dir();
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    60
	if ( empty( $themes_dir ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    61
		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
    62
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    63
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    64
	$themes_dir = trailingslashit( $themes_dir );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    65
	$theme_dir = trailingslashit( $themes_dir . $stylesheet );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    66
	$deleted = $wp_filesystem->delete( $theme_dir, true );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    67
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    68
	if ( ! $deleted ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    69
		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
    70
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    71
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    72
	$theme_translations = wp_get_installed_translations( 'themes' );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    73
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    74
	// Remove language files, silently.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    75
	if ( ! empty( $theme_translations[ $stylesheet ] ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    76
		$translations = $theme_translations[ $stylesheet ];
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    77
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    78
		foreach ( $translations as $translation => $data ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    79
			$wp_filesystem->delete( WP_LANG_DIR . '/themes/' . $stylesheet . '-' . $translation . '.po' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    80
			$wp_filesystem->delete( WP_LANG_DIR . '/themes/' . $stylesheet . '-' . $translation . '.mo' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    81
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    82
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    83
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    84
	// Force refresh of theme update information.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    85
	delete_site_transient( 'update_themes' );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    86
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    87
	return true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    88
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    89
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    90
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    91
 * Get the Page Templates available in this theme
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    92
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    93
 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    94
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    95
 * @param WP_Post|null $post Optional. The post being edited, provided for context.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    96
 * @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
    97
 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    98
function get_page_templates( $post = null ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    99
	return array_flip( wp_get_theme()->get_page_templates( $post ) );
0
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
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   103
 * Tidies a filename for url display by the theme editor.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   104
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   105
 * @since 2.9.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   106
 * @access private
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   107
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   108
 * @param string $fullpath Full path to the theme file
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   109
 * @param string $containingfolder Path of the theme parent folder
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   110
 * @return string
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   111
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   112
function _get_template_edit_filename($fullpath, $containingfolder) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   113
	return str_replace(dirname(dirname( $containingfolder )) , '', $fullpath);
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
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   117
 * Check if there is an update for a theme available.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   118
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   119
 * Will display link, if there is an update available.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   120
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   121
 * @since 2.7.0
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   122
 * @see get_theme_update_available()
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   123
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   124
 * @param object $theme Theme data object.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   125
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   126
function theme_update_available( $theme ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   127
	echo get_theme_update_available( $theme );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   128
}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   129
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   130
/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   131
 * Retrieve the update link if there is a theme update available.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   132
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   133
 * Will return a link if there is an update available.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   134
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   135
 * @since 3.8.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   136
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   137
 * @param WP_Theme $theme WP_Theme object.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   138
 * @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
   139
 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   140
function get_theme_update_available( $theme ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   141
	static $themes_update;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   142
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   143
	if ( !current_user_can('update_themes' ) )
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   144
		return false;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   145
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   146
	if ( !isset($themes_update) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   147
		$themes_update = get_site_transient('update_themes');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   148
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   149
	if ( ! ( $theme instanceof WP_Theme ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   150
		return false;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   151
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   152
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   153
	$stylesheet = $theme->get_stylesheet();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   154
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   155
	$html = '';
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   156
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   157
	if ( isset($themes_update->response[ $stylesheet ]) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   158
		$update = $themes_update->response[ $stylesheet ];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   159
		$theme_name = $theme->display('Name');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   160
		$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
   161
		$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
   162
		$update_onclick = 'onclick="if ( confirm(\'' . esc_js( __("Updating this theme will lose any customizations you have made. 'Cancel' to stop, 'OK' to update.") ) . '\') ) {return true;}return false;"';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   163
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   164
		if ( !is_multisite() ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   165
			if ( ! current_user_can('update_themes') ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   166
				$html = sprintf( '<p><strong>' . __( 'There is a new version of %1$s available. <a href="%2$s" class="thickbox" title="%3$s">View version %4$s details</a>.' ) . '</strong></p>',
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   167
					$theme_name, esc_url( $details_url ), esc_attr( $theme['Name'] ), $update['new_version'] );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   168
			} elseif ( empty( $update['package'] ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   169
				$html = sprintf( '<p><strong>' . __( 'There is a new version of %1$s available. <a href="%2$s" class="thickbox" title="%3$s">View version %4$s details</a>. <em>Automatic update is unavailable for this theme.</em>' ) . '</strong></p>',
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   170
					$theme_name, esc_url( $details_url ), esc_attr( $theme['Name'] ), $update['new_version'] );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   171
			} else {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   172
				$html = sprintf( '<p><strong>' . __( 'There is a new version of %1$s available. <a href="%2$s" class="thickbox" title="%3$s">View version %4$s details</a> or <a href="%5$s">update now</a>.' ) . '</strong></p>',
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   173
					$theme_name, esc_url( $details_url ), esc_attr( $theme['Name'] ), $update['new_version'], $update_url, $update_onclick );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   174
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   175
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   176
	}
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   177
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   178
	return $html;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   179
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   180
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   181
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   182
 * Retrieve list of WordPress theme features (aka theme tags)
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   183
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   184
 * @since 3.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   185
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   186
 * @param bool $api Optional. Whether try to fetch tags from the WP.org API. Defaults to true.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   187
 * @return array Array of features keyed by category with translations keyed by slug.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   188
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   189
function get_theme_feature_list( $api = true ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   190
	// Hard-coded list is used if api not accessible.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   191
	$features = array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   192
			__( 'Colors' ) => array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   193
				'black'   => __( 'Black' ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   194
				'blue'    => __( 'Blue' ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   195
				'brown'   => __( 'Brown' ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   196
				'gray'    => __( 'Gray' ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   197
				'green'   => __( 'Green' ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   198
				'orange'  => __( 'Orange' ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   199
				'pink'    => __( 'Pink' ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   200
				'purple'  => __( 'Purple' ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   201
				'red'     => __( 'Red' ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   202
				'silver'  => __( 'Silver' ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   203
				'tan'     => __( 'Tan' ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   204
				'white'   => __( 'White' ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   205
				'yellow'  => __( 'Yellow' ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   206
				'dark'    => __( 'Dark' ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   207
				'light'   => __( 'Light' ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   208
			),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   209
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   210
		__( 'Layout' ) => array(
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   211
			'fixed-layout'      => __( 'Fixed Layout' ),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   212
			'fluid-layout'      => __( 'Fluid Layout' ),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   213
			'responsive-layout' => __( 'Responsive Layout' ),
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   214
			'one-column'    => __( 'One Column' ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   215
			'two-columns'   => __( 'Two Columns' ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   216
			'three-columns' => __( 'Three Columns' ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   217
			'four-columns'  => __( 'Four Columns' ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   218
			'left-sidebar'  => __( 'Left Sidebar' ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   219
			'right-sidebar' => __( 'Right Sidebar' ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   220
		),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   221
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   222
		__( 'Features' ) => array(
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   223
			'accessibility-ready'   => __( 'Accessibility Ready' ),
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   224
			'blavatar'              => __( 'Blavatar' ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   225
			'buddypress'            => __( 'BuddyPress' ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   226
			'custom-background'     => __( 'Custom Background' ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   227
			'custom-colors'         => __( 'Custom Colors' ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   228
			'custom-header'         => __( 'Custom Header' ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   229
			'custom-menu'           => __( 'Custom Menu' ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   230
			'editor-style'          => __( 'Editor Style' ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   231
			'featured-image-header' => __( 'Featured Image Header' ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   232
			'featured-images'       => __( 'Featured Images' ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   233
			'flexible-header'       => __( 'Flexible Header' ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   234
			'front-page-post-form'  => __( 'Front Page Posting' ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   235
			'full-width-template'   => __( 'Full Width Template' ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   236
			'microformats'          => __( 'Microformats' ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   237
			'post-formats'          => __( 'Post Formats' ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   238
			'rtl-language-support'  => __( 'RTL Language Support' ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   239
			'sticky-post'           => __( 'Sticky Post' ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   240
			'theme-options'         => __( 'Theme Options' ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   241
			'threaded-comments'     => __( 'Threaded Comments' ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   242
			'translation-ready'     => __( 'Translation Ready' ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   243
		),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   244
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   245
		__( 'Subject' )  => array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   246
			'holiday'       => __( 'Holiday' ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   247
			'photoblogging' => __( 'Photoblogging' ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   248
			'seasonal'      => __( 'Seasonal' ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   249
		)
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   250
	);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   251
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   252
	if ( ! $api || ! current_user_can( 'install_themes' ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   253
		return $features;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   254
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   255
	if ( !$feature_list = get_site_transient( 'wporg_theme_feature_list' ) )
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   256
		set_site_transient( 'wporg_theme_feature_list', array(), 3 * HOUR_IN_SECONDS );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   257
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   258
	if ( !$feature_list ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   259
		$feature_list = themes_api( 'feature_list', array() );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   260
		if ( is_wp_error( $feature_list ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   261
			return $features;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   262
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   263
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   264
	if ( !$feature_list )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   265
		return $features;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   266
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   267
	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
   268
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   269
	$category_translations = array(
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   270
		'Colors'   => __( 'Colors' ),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   271
		'Layout'   => __( 'Layout' ),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   272
		'Features' => __( 'Features' ),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   273
		'Subject'  => __( 'Subject' )
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   274
	);
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   275
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   276
	// Loop over the wporg canonical list and apply translations
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   277
	$wporg_features = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   278
	foreach ( (array) $feature_list as $feature_category => $feature_items ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   279
		if ( isset($category_translations[$feature_category]) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   280
			$feature_category = $category_translations[$feature_category];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   281
		$wporg_features[$feature_category] = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   282
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   283
		foreach ( $feature_items as $feature ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   284
			if ( isset($features[$feature_category][$feature]) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   285
				$wporg_features[$feature_category][$feature] = $features[$feature_category][$feature];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   286
			else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   287
				$wporg_features[$feature_category][$feature] = $feature;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   288
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   289
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   290
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   291
	return $wporg_features;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   292
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   293
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   294
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   295
 * Retrieve theme installer pages from WordPress Themes API.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   296
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   297
 * 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
   298
 * 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
   299
 * 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
   300
 * overriding the filters.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   301
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   302
 * The first filter, 'themes_api_args', is for the args and gives the action as
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   303
 * the second parameter. The hook for 'themes_api_args' must ensure that an
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   304
 * object is returned.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   305
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   306
 * The second filter, 'themes_api', is the result that would be returned.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   307
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   308
 * @since 2.8.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   309
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   310
 * @param string       $action The requested action. Likely values are 'theme_information',
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   311
 *                             'feature_list', or 'query_themes'.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   312
 * @param array|object $args   Optional. Arguments to serialize for the Theme Info API.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   313
 * @return mixed
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   314
 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   315
function themes_api( $action, $args = null ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   316
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   317
	if ( is_array( $args ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   318
		$args = (object) $args;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   319
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   320
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   321
	if ( ! isset( $args->per_page ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   322
		$args->per_page = 24;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   323
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   324
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   325
	if ( ! isset( $args->locale ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   326
		$args->locale = get_locale();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   327
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   328
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   329
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   330
	 * Filter 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
   331
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   332
	 * Important: An object MUST be returned to this filter.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   333
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   334
	 * @since 2.8.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   335
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   336
	 * @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
   337
	 * @param string $action Requested action. Likely values are 'theme_information',
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   338
	 *                       'feature_list', or 'query_themes'.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   339
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   340
	$args = apply_filters( 'themes_api_args', $args, $action );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   341
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   342
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   343
	 * Filter whether to override the WordPress.org Themes API.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   344
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   345
	 * Returning a value of true to this filter allows a theme to completely
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   346
	 * override the built-in WordPress.org API.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   347
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   348
	 * @since 2.8.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   349
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   350
	 * @param bool   $bool   Whether to override the WordPress.org Themes API. Default false.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   351
	 * @param string $action Requested action. Likely values are 'theme_information',
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   352
	 *                       'feature_list', or 'query_themes'.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   353
	 * @param object $args   Arguments used to query for installer pages from the Themes API.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   354
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   355
	$res = apply_filters( 'themes_api', false, $action, $args );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   356
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   357
	if ( ! $res ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   358
		$url = $http_url = 'http://api.wordpress.org/themes/info/1.0/';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   359
		if ( $ssl = wp_http_supports( array( 'ssl' ) ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   360
			$url = set_url_scheme( $url, 'https' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   361
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   362
		$http_args = array(
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   363
			'body' => array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   364
				'action' => $action,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   365
				'request' => serialize( $args )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   366
			)
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   367
		);
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   368
		$request = wp_remote_post( $url, $http_args );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   369
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   370
		if ( $ssl && is_wp_error( $request ) ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   371
			if ( ! defined( 'DOING_AJAX' ) || ! DOING_AJAX ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   372
				trigger_error( __( '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="https://wordpress.org/support/">support forums</a>.' ) . ' ' . __( '(WordPress could not establish a secure connection to WordPress.org. Please contact your server administrator.)' ), headers_sent() || WP_DEBUG ? E_USER_WARNING : E_USER_NOTICE );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   373
			}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   374
			$request = wp_remote_post( $http_url, $http_args );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   375
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   376
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   377
		if ( is_wp_error($request) ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   378
			$res = new WP_Error('themes_api_failed', __( '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="https://wordpress.org/support/">support forums</a>.' ), $request->get_error_message() );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   379
		} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   380
			$res = maybe_unserialize( wp_remote_retrieve_body( $request ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   381
			if ( ! is_object( $res ) && ! is_array( $res ) )
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   382
				$res = new WP_Error('themes_api_failed', __( '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="https://wordpress.org/support/">support forums</a>.' ), wp_remote_retrieve_body( $request ) );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   383
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   384
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   385
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   386
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   387
	 * Filter the returned WordPress.org Themes API response.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   388
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   389
	 * @since 2.8.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   390
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   391
	 * @param array|object $res    WordPress.org Themes API response.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   392
	 * @param string       $action Requested action. Likely values are 'theme_information',
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   393
	 *                             'feature_list', or 'query_themes'.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   394
	 * @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
   395
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   396
	return apply_filters( 'themes_api_result', $res, $action, $args );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   397
}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   398
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   399
/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   400
 * Prepare themes for JavaScript.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   401
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   402
 * @since 3.8.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   403
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   404
 * @param array $themes Optional. Array of WP_Theme objects to prepare.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   405
 *                      Defaults to all allowed themes.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   406
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   407
 * @return array An associative array of theme data, sorted by name.
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
function wp_prepare_themes_for_js( $themes = null ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   410
	$current_theme = get_stylesheet();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   411
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   412
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   413
	 * Filter theme data before it is prepared for JavaScript.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   414
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   415
	 * 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
   416
	 * early with that value instead.
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 4.2.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 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
   421
	 * @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
   422
	 * @param string     $current_theme   The current theme slug.
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
	$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
   425
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   426
	if ( ! empty( $prepared_themes ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   427
		return $prepared_themes;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   428
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   429
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   430
	// Make sure the current theme is listed first.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   431
	$prepared_themes[ $current_theme ] = array();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   432
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   433
	if ( null === $themes ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   434
		$themes = wp_get_themes( array( 'allowed' => true ) );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   435
		if ( ! isset( $themes[ $current_theme ] ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   436
			$themes[ $current_theme ] = wp_get_theme();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   437
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   438
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   439
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   440
	$updates = array();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   441
	if ( current_user_can( 'update_themes' ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   442
		$updates_transient = get_site_transient( 'update_themes' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   443
		if ( isset( $updates_transient->response ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   444
			$updates = $updates_transient->response;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   445
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   446
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   447
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   448
	WP_Theme::sort_by_name( $themes );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   449
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   450
	$parents = array();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   451
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   452
	foreach ( $themes as $theme ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   453
		$slug = $theme->get_stylesheet();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   454
		$encoded_slug = urlencode( $slug );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   455
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   456
		$parent = false;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   457
		if ( $theme->parent() ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   458
			$parent = $theme->parent()->display( 'Name' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   459
			$parents[ $slug ] = $theme->parent()->get_stylesheet();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   460
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   461
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   462
		$prepared_themes[ $slug ] = array(
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   463
			'id'           => $slug,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   464
			'name'         => $theme->display( 'Name' ),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   465
			'screenshot'   => array( $theme->get_screenshot() ), // @todo multiple
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   466
			'description'  => $theme->display( 'Description' ),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   467
			'author'       => $theme->display( 'Author', false, true ),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   468
			'authorAndUri' => $theme->display( 'Author' ),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   469
			'version'      => $theme->display( 'Version' ),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   470
			'tags'         => $theme->display( 'Tags' ),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   471
			'parent'       => $parent,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   472
			'active'       => $slug === $current_theme,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   473
			'hasUpdate'    => isset( $updates[ $slug ] ),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   474
			'update'       => get_theme_update_available( $theme ),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   475
			'actions'      => array(
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   476
				'activate' => current_user_can( 'switch_themes' ) ? wp_nonce_url( admin_url( 'themes.php?action=activate&amp;stylesheet=' . $encoded_slug ), 'switch-theme_' . $slug ) : null,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   477
				'customize' => ( current_user_can( 'edit_theme_options' ) && current_user_can( 'customize' ) ) ? wp_customize_url( $slug ) : null,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   478
				'preview'   => add_query_arg( array(
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   479
					'preview'        => 1,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   480
					'template'       => urlencode( $theme->get_template() ),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   481
					'stylesheet'     => urlencode( $slug ),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   482
					'preview_iframe' => true,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   483
					'TB_iframe'      => true,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   484
				), home_url( '/' ) ),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   485
				'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
   486
			),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   487
		);
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   488
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   489
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   490
	// Remove 'delete' action if theme has an active child
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   491
	if ( ! empty( $parents ) && array_key_exists( $current_theme, $parents ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   492
		unset( $prepared_themes[ $parents[ $current_theme ] ]['actions']['delete'] );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   493
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   494
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
	 * Filter the themes prepared for JavaScript, for themes.php.
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
	 * 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
   499
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   500
	 * @since 3.8.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   501
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   502
	 * @param array $prepared_themes Array of themes.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   503
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   504
	$prepared_themes = apply_filters( 'wp_prepare_themes_for_js', $prepared_themes );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   505
	$prepared_themes = array_values( $prepared_themes );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   506
	return array_filter( $prepared_themes );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   507
}
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   508
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
 * Print JS templates for the theme-browsing UI in the Customizer.
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
 * @since 4.2.0
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
function customize_themes_print_templates() {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   515
	$preview_url = esc_url( add_query_arg( 'theme', '__THEME__' ) ); // Token because esc_url() strips curly braces.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   516
	$preview_url = str_replace( '__THEME__', '{{ data.id }}', $preview_url );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   517
	?>
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   518
	<script type="text/html" id="tmpl-customize-themes-details-view">
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   519
		<div class="theme-backdrop"></div>
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   520
		<div class="theme-wrap">
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   521
			<div class="theme-header">
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   522
				<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
   523
				<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
   524
				<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
   525
			</div>
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   526
			<div class="theme-about">
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   527
				<div class="theme-screenshots">
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   528
				<# if ( data.screenshot[0] ) { #>
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   529
					<div class="screenshot"><img src="{{ data.screenshot[0] }}" alt="" /></div>
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   530
				<# } else { #>
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   531
					<div class="screenshot blank"></div>
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   532
				<# } #>
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   533
				</div>
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   534
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   535
				<div class="theme-info">
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   536
					<# if ( data.active ) { #>
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   537
						<span class="current-label"><?php _e( 'Current Theme' ); ?></span>
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   538
					<# } #>
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   539
					<h3 class="theme-name">{{{ data.name }}}<span class="theme-version"><?php printf( __( 'Version: %s' ), '{{ data.version }}' ); ?></span></h3>
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   540
					<h4 class="theme-author"><?php printf( __( 'By %s' ), '{{{ data.authorAndUri }}}' ); ?></h4>
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   541
					<p class="theme-description">{{{ data.description }}}</p>
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   542
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   543
					<# if ( data.parent ) { #>
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   544
						<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
   545
					<# } #>
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   546
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   547
					<# if ( data.tags ) { #>
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   548
						<p class="theme-tags"><span><?php _e( 'Tags:' ); ?></span> {{ data.tags }}</p>
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
				</div>
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   551
			</div>
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   552
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   553
			<# if ( ! data.active ) { #>
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   554
				<div class="theme-actions">
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   555
					<div class="inactive-theme">
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   556
						<a href="<?php echo $preview_url; ?>" target="_top" class="button button-primary"><?php _e( 'Live Preview' ); ?></a>
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   557
					</div>
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   558
				</div>
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   559
			<# } #>
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   560
		</div>
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   561
	</script>
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   562
	<?php
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
add_action( 'customize_controls_print_footer_scripts', 'customize_themes_print_templates' );