wp/wp-admin/includes/class-wp-theme-install-list-table.php
changeset 9 177826044cd9
parent 7 cf61fcea0001
child 16 a86126ab1dd4
equal deleted inserted replaced
8:c7c34916027a 9:177826044cd9
    18 class WP_Theme_Install_List_Table extends WP_Themes_List_Table {
    18 class WP_Theme_Install_List_Table extends WP_Themes_List_Table {
    19 
    19 
    20 	public $features = array();
    20 	public $features = array();
    21 
    21 
    22 	/**
    22 	/**
    23 	 *
       
    24 	 * @return bool
    23 	 * @return bool
    25 	 */
    24 	 */
    26 	public function ajax_user_can() {
    25 	public function ajax_user_can() {
    27 		return current_user_can( 'install_themes' );
    26 		return current_user_can( 'install_themes' );
    28 	}
    27 	}
    29 
    28 
    30 	/**
    29 	/**
    31 	 *
       
    32 	 * @global array  $tabs
    30 	 * @global array  $tabs
    33 	 * @global string $tab
    31 	 * @global string $tab
    34 	 * @global int    $paged
    32 	 * @global int    $paged
    35 	 * @global string $type
    33 	 * @global string $type
    36 	 * @global array  $theme_field_defaults
    34 	 * @global array  $theme_field_defaults
    39 		include( ABSPATH . 'wp-admin/includes/theme-install.php' );
    37 		include( ABSPATH . 'wp-admin/includes/theme-install.php' );
    40 
    38 
    41 		global $tabs, $tab, $paged, $type, $theme_field_defaults;
    39 		global $tabs, $tab, $paged, $type, $theme_field_defaults;
    42 		wp_reset_vars( array( 'tab' ) );
    40 		wp_reset_vars( array( 'tab' ) );
    43 
    41 
    44 		$search_terms = array();
    42 		$search_terms  = array();
    45 		$search_string = '';
    43 		$search_string = '';
    46 		if ( ! empty( $_REQUEST['s'] ) ){
    44 		if ( ! empty( $_REQUEST['s'] ) ) {
    47 			$search_string = strtolower( wp_unslash( $_REQUEST['s'] ) );
    45 			$search_string = strtolower( wp_unslash( $_REQUEST['s'] ) );
    48 			$search_terms = array_unique( array_filter( array_map( 'trim', explode( ',', $search_string ) ) ) );
    46 			$search_terms  = array_unique( array_filter( array_map( 'trim', explode( ',', $search_string ) ) ) );
    49 		}
    47 		}
    50 
    48 
    51 		if ( ! empty( $_REQUEST['features'] ) )
    49 		if ( ! empty( $_REQUEST['features'] ) ) {
    52 			$this->features = $_REQUEST['features'];
    50 			$this->features = $_REQUEST['features'];
       
    51 		}
    53 
    52 
    54 		$paged = $this->get_pagenum();
    53 		$paged = $this->get_pagenum();
    55 
    54 
    56 		$per_page = 36;
    55 		$per_page = 36;
    57 
    56 
    58 		// These are the tabs which are shown on the page,
    57 		// These are the tabs which are shown on the page,
    59 		$tabs = array();
    58 		$tabs              = array();
    60 		$tabs['dashboard'] = __( 'Search' );
    59 		$tabs['dashboard'] = __( 'Search' );
    61 		if ( 'search' === $tab )
    60 		if ( 'search' === $tab ) {
    62 			$tabs['search']	= __( 'Search Results' );
    61 			$tabs['search'] = __( 'Search Results' );
    63 		$tabs['upload'] = __( 'Upload' );
    62 		}
       
    63 		$tabs['upload']   = __( 'Upload' );
    64 		$tabs['featured'] = _x( 'Featured', 'themes' );
    64 		$tabs['featured'] = _x( 'Featured', 'themes' );
    65 		//$tabs['popular']  = _x( 'Popular', 'themes' );
    65 		//$tabs['popular']  = _x( 'Popular', 'themes' );
    66 		$tabs['new']      = _x( 'Latest', 'themes' );
    66 		$tabs['new']     = _x( 'Latest', 'themes' );
    67 		$tabs['updated']  = _x( 'Recently Updated', 'themes' );
    67 		$tabs['updated'] = _x( 'Recently Updated', 'themes' );
    68 
    68 
    69 		$nonmenu_tabs = array( 'theme-information' ); // Valid actions to perform which do not have a Menu item.
    69 		$nonmenu_tabs = array( 'theme-information' ); // Valid actions to perform which do not have a Menu item.
    70 
    70 
    71 		/** This filter is documented in wp-admin/theme-install.php */
    71 		/** This filter is documented in wp-admin/theme-install.php */
    72 		$tabs = apply_filters( 'install_themes_tabs', $tabs );
    72 		$tabs = apply_filters( 'install_themes_tabs', $tabs );
    74 		/**
    74 		/**
    75 		 * Filters tabs not associated with a menu item on the Install Themes screen.
    75 		 * Filters tabs not associated with a menu item on the Install Themes screen.
    76 		 *
    76 		 *
    77 		 * @since 2.8.0
    77 		 * @since 2.8.0
    78 		 *
    78 		 *
    79 		 * @param array $nonmenu_tabs The tabs that don't have a menu item on
    79 		 * @param string[] $nonmenu_tabs The tabs that don't have a menu item on
    80 		 *                            the Install Themes screen.
    80 		 *                               the Install Themes screen.
    81 		 */
    81 		 */
    82 		$nonmenu_tabs = apply_filters( 'install_themes_nonmenu_tabs', $nonmenu_tabs );
    82 		$nonmenu_tabs = apply_filters( 'install_themes_nonmenu_tabs', $nonmenu_tabs );
    83 
    83 
    84 		// If a non-valid menu tab has been selected, And it's not a non-menu action.
    84 		// If a non-valid menu tab has been selected, And it's not a non-menu action.
    85 		if ( empty( $tab ) || ( ! isset( $tabs[ $tab ] ) && ! in_array( $tab, (array) $nonmenu_tabs ) ) )
    85 		if ( empty( $tab ) || ( ! isset( $tabs[ $tab ] ) && ! in_array( $tab, (array) $nonmenu_tabs ) ) ) {
    86 			$tab = key( $tabs );
    86 			$tab = key( $tabs );
    87 
    87 		}
    88 		$args = array( 'page' => $paged, 'per_page' => $per_page, 'fields' => $theme_field_defaults );
    88 
       
    89 		$args = array(
       
    90 			'page'     => $paged,
       
    91 			'per_page' => $per_page,
       
    92 			'fields'   => $theme_field_defaults,
       
    93 		);
    89 
    94 
    90 		switch ( $tab ) {
    95 		switch ( $tab ) {
    91 			case 'search':
    96 			case 'search':
    92 				$type = isset( $_REQUEST['type'] ) ? wp_unslash( $_REQUEST['type'] ) : 'term';
    97 				$type = isset( $_REQUEST['type'] ) ? wp_unslash( $_REQUEST['type'] ) : 'term';
    93 				switch ( $type ) {
    98 				switch ( $type ) {
   101 						$args['author'] = $search_string;
   106 						$args['author'] = $search_string;
   102 						break;
   107 						break;
   103 				}
   108 				}
   104 
   109 
   105 				if ( ! empty( $this->features ) ) {
   110 				if ( ! empty( $this->features ) ) {
   106 					$args['tag'] = $this->features;
   111 					$args['tag']      = $this->features;
   107 					$_REQUEST['s'] = implode( ',', $this->features );
   112 					$_REQUEST['s']    = implode( ',', $this->features );
   108 					$_REQUEST['type'] = 'tag';
   113 					$_REQUEST['type'] = 'tag';
   109 				}
   114 				}
   110 
   115 
   111 				add_action( 'install_themes_table_header', 'install_theme_search_form', 10, 0 );
   116 				add_action( 'install_themes_table_header', 'install_theme_search_form', 10, 0 );
   112 				break;
   117 				break;
   113 
   118 
   114 			case 'featured':
   119 			case 'featured':
   115 			// case 'popular':
   120 				// case 'popular':
   116 			case 'new':
   121 			case 'new':
   117 			case 'updated':
   122 			case 'updated':
   118 				$args['browse'] = $tab;
   123 				$args['browse'] = $tab;
   119 				break;
   124 				break;
   120 
   125 
   134 		 *
   139 		 *
   135 		 * @param array $args An array of themes API arguments.
   140 		 * @param array $args An array of themes API arguments.
   136 		 */
   141 		 */
   137 		$args = apply_filters( "install_themes_table_api_args_{$tab}", $args );
   142 		$args = apply_filters( "install_themes_table_api_args_{$tab}", $args );
   138 
   143 
   139 		if ( ! $args )
   144 		if ( ! $args ) {
   140 			return;
   145 			return;
       
   146 		}
   141 
   147 
   142 		$api = themes_api( 'query_themes', $args );
   148 		$api = themes_api( 'query_themes', $args );
   143 
   149 
   144 		if ( is_wp_error( $api ) )
   150 		if ( is_wp_error( $api ) ) {
   145 			wp_die( $api->get_error_message() . '</p> <p><a href="#" onclick="document.location.reload(); return false;">' . __( 'Try again' ) . '</a>' );
   151 			wp_die( $api->get_error_message() . '</p> <p><a href="#" onclick="document.location.reload(); return false;">' . __( 'Try again' ) . '</a>' );
       
   152 		}
   146 
   153 
   147 		$this->items = $api->themes;
   154 		$this->items = $api->themes;
   148 
   155 
   149 		$this->set_pagination_args( array(
   156 		$this->set_pagination_args(
   150 			'total_items' => $api->info['results'],
   157 			array(
   151 			'per_page' => $args['per_page'],
   158 				'total_items'     => $api->info['results'],
   152 			'infinite_scroll' => true,
   159 				'per_page'        => $args['per_page'],
   153 		) );
   160 				'infinite_scroll' => true,
       
   161 			)
       
   162 		);
   154 	}
   163 	}
   155 
   164 
   156 	/**
   165 	/**
   157 	 */
   166 	 */
   158 	public function no_items() {
   167 	public function no_items() {
   159 		_e( 'No themes match your request.' );
   168 		_e( 'No themes match your request.' );
   160 	}
   169 	}
   161 
   170 
   162 	/**
   171 	/**
   163 	 *
       
   164 	 * @global array $tabs
   172 	 * @global array $tabs
   165 	 * @global string $tab
   173 	 * @global string $tab
   166 	 * @return array
   174 	 * @return array
   167 	 */
   175 	 */
   168 	protected function get_views() {
   176 	protected function get_views() {
   169 		global $tabs, $tab;
   177 		global $tabs, $tab;
   170 
   178 
   171 		$display_tabs = array();
   179 		$display_tabs = array();
   172 		foreach ( (array) $tabs as $action => $text ) {
   180 		foreach ( (array) $tabs as $action => $text ) {
   173 			$current_link_attributes = ( $action === $tab ) ? ' class="current" aria-current="page"' : '';
   181 			$current_link_attributes                    = ( $action === $tab ) ? ' class="current" aria-current="page"' : '';
   174 			$href = self_admin_url('theme-install.php?tab=' . $action);
   182 			$href                                       = self_admin_url( 'theme-install.php?tab=' . $action );
   175 			$display_tabs['theme-install-'.$action] = "<a href='$href'$current_link_attributes>$text</a>";
   183 			$display_tabs[ 'theme-install-' . $action ] = "<a href='$href'$current_link_attributes>$text</a>";
   176 		}
   184 		}
   177 
   185 
   178 		return $display_tabs;
   186 		return $display_tabs;
   179 	}
   187 	}
   180 
   188 
   181 	/**
   189 	/**
   182 	 */
   190 	 */
   183 	public function display() {
   191 	public function display() {
   184 		wp_nonce_field( "fetch-list-" . get_class( $this ), '_ajax_fetch_list_nonce' );
   192 		wp_nonce_field( 'fetch-list-' . get_class( $this ), '_ajax_fetch_list_nonce' );
   185 ?>
   193 		?>
   186 		<div class="tablenav top themes">
   194 		<div class="tablenav top themes">
   187 			<div class="alignleft actions">
   195 			<div class="alignleft actions">
   188 				<?php
   196 				<?php
   189 				/**
   197 				/**
   190 				 * Fires in the Install Themes list table header.
   198 				 * Fires in the Install Themes list table header.
   209 	/**
   217 	/**
   210 	 */
   218 	 */
   211 	public function display_rows() {
   219 	public function display_rows() {
   212 		$themes = $this->items;
   220 		$themes = $this->items;
   213 		foreach ( $themes as $theme ) {
   221 		foreach ( $themes as $theme ) {
       
   222 			?>
       
   223 				<div class="available-theme installable-theme">
       
   224 				<?php
       
   225 					$this->single_row( $theme );
   214 				?>
   226 				?>
   215 				<div class="available-theme installable-theme"><?php
   227 				</div>
   216 					$this->single_row( $theme );
   228 			<?php
   217 				?></div>
   229 		} // end foreach $theme_names
   218 		<?php } // end foreach $theme_names
       
   219 
   230 
   220 		$this->theme_installer();
   231 		$this->theme_installer();
   221 	}
   232 	}
   222 
   233 
   223 	/**
   234 	/**
   228 	 * @global array $themes_allowedtags
   239 	 * @global array $themes_allowedtags
   229 	 *
   240 	 *
   230 	 * @param object $theme {
   241 	 * @param object $theme {
   231 	 *     An object that contains theme data returned by the WordPress.org API.
   242 	 *     An object that contains theme data returned by the WordPress.org API.
   232 	 *
   243 	 *
   233 	 *     @type string $name           Theme name, e.g. 'Twenty Seventeen'.
   244 	 *     @type string $name           Theme name, e.g. 'Twenty Nineteen'.
   234 	 *     @type string $slug           Theme slug, e.g. 'twentyseventeen'.
   245 	 *     @type string $slug           Theme slug, e.g. 'twentynineteen'.
   235 	 *     @type string $version        Theme version, e.g. '1.1'.
   246 	 *     @type string $version        Theme version, e.g. '1.1'.
   236 	 *     @type string $author         Theme author username, e.g. 'melchoyce'.
   247 	 *     @type string $author         Theme author username, e.g. 'melchoyce'.
   237 	 *     @type string $preview_url    Preview URL, e.g. 'http://2017.wordpress.net/'.
   248 	 *     @type string $preview_url    Preview URL, e.g. 'http://2019.wordpress.net/'.
   238 	 *     @type string $screenshot_url Screenshot URL, e.g. 'https://wordpress.org/themes/twentyseventeen/'.
   249 	 *     @type string $screenshot_url Screenshot URL, e.g. 'https://wordpress.org/themes/twentynineteen/'.
   239 	 *     @type float  $rating         Rating score.
   250 	 *     @type float  $rating         Rating score.
   240 	 *     @type int    $num_ratings    The number of ratings.
   251 	 *     @type int    $num_ratings    The number of ratings.
   241 	 *     @type string $homepage       Theme homepage, e.g. 'https://wordpress.org/themes/twentyseventeen/'.
   252 	 *     @type string $homepage       Theme homepage, e.g. 'https://wordpress.org/themes/twentynineteen/'.
   242 	 *     @type string $description    Theme description.
   253 	 *     @type string $description    Theme description.
   243 	 *     @type string $download_link  Theme ZIP download URL.
   254 	 *     @type string $download_link  Theme ZIP download URL.
   244 	 * }
   255 	 * }
   245 	 */
   256 	 */
   246 	public function single_row( $theme ) {
   257 	public function single_row( $theme ) {
   247 		global $themes_allowedtags;
   258 		global $themes_allowedtags;
   248 
   259 
   249 		if ( empty( $theme ) )
   260 		if ( empty( $theme ) ) {
   250 			return;
   261 			return;
   251 
   262 		}
   252 		$name   = wp_kses( $theme->name,   $themes_allowedtags );
   263 
       
   264 		$name   = wp_kses( $theme->name, $themes_allowedtags );
   253 		$author = wp_kses( $theme->author, $themes_allowedtags );
   265 		$author = wp_kses( $theme->author, $themes_allowedtags );
   254 
   266 
   255 		$preview_title = sprintf( __('Preview &#8220;%s&#8221;'), $name );
   267 		/* translators: %s: theme name */
   256 		$preview_url   = add_query_arg( array(
   268 		$preview_title = sprintf( __( 'Preview &#8220;%s&#8221;' ), $name );
   257 			'tab'   => 'theme-information',
   269 		$preview_url   = add_query_arg(
   258 			'theme' => $theme->slug,
   270 			array(
   259 		), self_admin_url( 'theme-install.php' ) );
   271 				'tab'   => 'theme-information',
       
   272 				'theme' => $theme->slug,
       
   273 			),
       
   274 			self_admin_url( 'theme-install.php' )
       
   275 		);
   260 
   276 
   261 		$actions = array();
   277 		$actions = array();
   262 
   278 
   263 		$install_url = add_query_arg( array(
   279 		$install_url = add_query_arg(
   264 			'action' => 'install-theme',
   280 			array(
   265 			'theme'  => $theme->slug,
   281 				'action' => 'install-theme',
   266 		), self_admin_url( 'update.php' ) );
   282 				'theme'  => $theme->slug,
   267 
   283 			),
   268 		$update_url = add_query_arg( array(
   284 			self_admin_url( 'update.php' )
   269 			'action' => 'upgrade-theme',
   285 		);
   270 			'theme'  => $theme->slug,
   286 
   271 		), self_admin_url( 'update.php' ) );
   287 		$update_url = add_query_arg(
       
   288 			array(
       
   289 				'action' => 'upgrade-theme',
       
   290 				'theme'  => $theme->slug,
       
   291 			),
       
   292 			self_admin_url( 'update.php' )
       
   293 		);
   272 
   294 
   273 		$status = $this->_get_theme_status( $theme );
   295 		$status = $this->_get_theme_status( $theme );
   274 
   296 
   275 		switch ( $status ) {
   297 		switch ( $status ) {
   276 			case 'update_available':
   298 			case 'update_available':
   277 				$actions[] = '<a class="install-now" href="' . esc_url( wp_nonce_url( $update_url, 'upgrade-theme_' . $theme->slug ) ) . '" title="' . esc_attr( sprintf( __( 'Update to version %s' ), $theme->version ) ) . '">' . __( 'Update' ) . '</a>';
   299 				$actions[] = sprintf(
       
   300 					'<a class="install-now" href="%s" title="%s">%s</a>',
       
   301 					esc_url( wp_nonce_url( $update_url, 'upgrade-theme_' . $theme->slug ) ),
       
   302 					/* translators: %s: theme version */
       
   303 					esc_attr( sprintf( __( 'Update to version %s' ), $theme->version ) ),
       
   304 					__( 'Update' )
       
   305 				);
   278 				break;
   306 				break;
   279 			case 'newer_installed':
   307 			case 'newer_installed':
   280 			case 'latest_installed':
   308 			case 'latest_installed':
   281 				$actions[] = '<span class="install-now" title="' . esc_attr__( 'This theme is already installed and is up to date' ) . '">' . _x( 'Installed', 'theme' ) . '</span>';
   309 				$actions[] = sprintf(
       
   310 					'<span class="install-now" title="%s">%s</span>',
       
   311 					esc_attr__( 'This theme is already installed and is up to date' ),
       
   312 					_x( 'Installed', 'theme' )
       
   313 				);
   282 				break;
   314 				break;
   283 			case 'install':
   315 			case 'install':
   284 			default:
   316 			default:
   285 				$actions[] = '<a class="install-now" href="' . esc_url( wp_nonce_url( $install_url, 'install-theme_' . $theme->slug ) ) . '" title="' . esc_attr( sprintf( __( 'Install %s' ), $name ) ) . '">' . __( 'Install Now' ) . '</a>';
   317 				$actions[] = sprintf(
   286 				break;
   318 					'<a class="install-now" href="%s" title="%s">%s</a>',
   287 		}
   319 					esc_url( wp_nonce_url( $install_url, 'install-theme_' . $theme->slug ) ),
   288 
   320 					/* translators: %s: theme name */
   289 		$actions[] = '<a class="install-theme-preview" href="' . esc_url( $preview_url ) . '" title="' . esc_attr( sprintf( __( 'Preview %s' ), $name ) ) . '">' . __( 'Preview' ) . '</a>';
   321 					esc_attr( sprintf( __( 'Install %s' ), $name ) ),
       
   322 					__( 'Install Now' )
       
   323 				);
       
   324 				break;
       
   325 		}
       
   326 
       
   327 		$actions[] = sprintf(
       
   328 			'<a class="install-theme-preview" href="%s" title="%s">%s</a>',
       
   329 			esc_url( $preview_url ),
       
   330 			/* translators: %s: theme name */
       
   331 			esc_attr( sprintf( __( 'Preview %s' ), $name ) ),
       
   332 			__( 'Preview' )
       
   333 		);
   290 
   334 
   291 		/**
   335 		/**
   292 		 * Filters the install action links for a theme in the Install Themes list table.
   336 		 * Filters the install action links for a theme in the Install Themes list table.
   293 		 *
   337 		 *
   294 		 * @since 3.4.0
   338 		 * @since 3.4.0
   295 		 *
   339 		 *
   296 		 * @param array    $actions An array of theme action hyperlinks. Defaults are
   340 		 * @param string[] $actions An array of theme action links. Defaults are
   297 		 *                          links to Install Now, Preview, and Details.
   341 		 *                          links to Install Now, Preview, and Details.
   298 		 * @param WP_Theme $theme   Theme object.
   342 		 * @param WP_Theme $theme   Theme object.
   299 		 */
   343 		 */
   300 		$actions = apply_filters( 'theme_install_actions', $actions, $theme );
   344 		$actions = apply_filters( 'theme_install_actions', $actions, $theme );
   301 
   345 
   303 		<a class="screenshot install-theme-preview" href="<?php echo esc_url( $preview_url ); ?>" title="<?php echo esc_attr( $preview_title ); ?>">
   347 		<a class="screenshot install-theme-preview" href="<?php echo esc_url( $preview_url ); ?>" title="<?php echo esc_attr( $preview_title ); ?>">
   304 			<img src="<?php echo esc_url( $theme->screenshot_url ); ?>" width="150" alt="" />
   348 			<img src="<?php echo esc_url( $theme->screenshot_url ); ?>" width="150" alt="" />
   305 		</a>
   349 		</a>
   306 
   350 
   307 		<h3><?php echo $name; ?></h3>
   351 		<h3><?php echo $name; ?></h3>
   308 		<div class="theme-author"><?php printf( __( 'By %s' ), $author ); ?></div>
   352 		<div class="theme-author">
       
   353 		<?php
       
   354 			/* translators: %s: theme author */
       
   355 			printf( __( 'By %s' ), $author );
       
   356 		?>
       
   357 		</div>
   309 
   358 
   310 		<div class="action-links">
   359 		<div class="action-links">
   311 			<ul>
   360 			<ul>
   312 				<?php foreach ( $actions as $action ): ?>
   361 				<?php foreach ( $actions as $action ) : ?>
   313 					<li><?php echo $action; ?></li>
   362 					<li><?php echo $action; ?></li>
   314 				<?php endforeach; ?>
   363 				<?php endforeach; ?>
   315 				<li class="hide-if-no-js"><a href="#" class="theme-detail"><?php _e('Details') ?></a></li>
   364 				<li class="hide-if-no-js"><a href="#" class="theme-detail"><?php _e( 'Details' ); ?></a></li>
   316 			</ul>
   365 			</ul>
   317 		</div>
   366 		</div>
   318 
   367 
   319 		<?php
   368 		<?php
   320 		$this->install_theme_info( $theme );
   369 		$this->install_theme_info( $theme );
   373 	 * @param object $theme - A WordPress.org Theme API object.
   422 	 * @param object $theme - A WordPress.org Theme API object.
   374 	 */
   423 	 */
   375 	public function install_theme_info( $theme ) {
   424 	public function install_theme_info( $theme ) {
   376 		global $themes_allowedtags;
   425 		global $themes_allowedtags;
   377 
   426 
   378 		if ( empty( $theme ) )
   427 		if ( empty( $theme ) ) {
   379 			return;
   428 			return;
   380 
   429 		}
   381 		$name   = wp_kses( $theme->name,   $themes_allowedtags );
   430 
       
   431 		$name   = wp_kses( $theme->name, $themes_allowedtags );
   382 		$author = wp_kses( $theme->author, $themes_allowedtags );
   432 		$author = wp_kses( $theme->author, $themes_allowedtags );
   383 
   433 
   384 		$install_url = add_query_arg( array(
   434 		$install_url = add_query_arg(
   385 			'action' => 'install-theme',
   435 			array(
   386 			'theme'  => $theme->slug,
   436 				'action' => 'install-theme',
   387 		), self_admin_url( 'update.php' ) );
   437 				'theme'  => $theme->slug,
   388 
   438 			),
   389 		$update_url = add_query_arg( array(
   439 			self_admin_url( 'update.php' )
   390 			'action' => 'upgrade-theme',
   440 		);
   391 			'theme'  => $theme->slug,
   441 
   392 		), self_admin_url( 'update.php' ) );
   442 		$update_url = add_query_arg(
       
   443 			array(
       
   444 				'action' => 'upgrade-theme',
       
   445 				'theme'  => $theme->slug,
       
   446 			),
       
   447 			self_admin_url( 'update.php' )
       
   448 		);
   393 
   449 
   394 		$status = $this->_get_theme_status( $theme );
   450 		$status = $this->_get_theme_status( $theme );
   395 
   451 
   396 		?>
   452 		?>
   397 		<div class="install-theme-info"><?php
   453 		<div class="install-theme-info">
   398 			switch ( $status ) {
   454 		<?php
   399 				case 'update_available':
   455 		switch ( $status ) {
   400 					echo '<a class="theme-install button button-primary" href="' . esc_url( wp_nonce_url( $update_url, 'upgrade-theme_' . $theme->slug ) ) . '" title="' . esc_attr( sprintf( __( 'Update to version %s' ), $theme->version ) ) . '">' . __( 'Update' ) . '</a>';
   456 			case 'update_available':
   401 					break;
   457 				printf(
   402 				case 'newer_installed':
   458 					'<a class="theme-install button button-primary" href="%s" title="%s">%s</a>',
   403 				case 'latest_installed':
   459 					esc_url( wp_nonce_url( $update_url, 'upgrade-theme_' . $theme->slug ) ),
   404 					echo '<span class="theme-install" title="' . esc_attr__( 'This theme is already installed and is up to date' ) . '">' . _x( 'Installed', 'theme' ) . '</span>';
   460 					/* translators: %s: theme version */
   405 					break;
   461 					esc_attr( sprintf( __( 'Update to version %s' ), $theme->version ) ),
   406 				case 'install':
   462 					__( 'Update' )
   407 				default:
   463 				);
   408 					echo '<a class="theme-install button button-primary" href="' . esc_url( wp_nonce_url( $install_url, 'install-theme_' . $theme->slug ) ) . '">' . __( 'Install' ) . '</a>';
   464 				break;
   409 					break;
   465 			case 'newer_installed':
   410 			} ?>
   466 			case 'latest_installed':
       
   467 				printf(
       
   468 					'<span class="theme-install" title="%s">%s</span>',
       
   469 					esc_attr__( 'This theme is already installed and is up to date' ),
       
   470 					_x( 'Installed', 'theme' )
       
   471 				);
       
   472 				break;
       
   473 			case 'install':
       
   474 			default:
       
   475 				printf(
       
   476 					'<a class="theme-install button button-primary" href="%s">%s</a>',
       
   477 					esc_url( wp_nonce_url( $install_url, 'install-theme_' . $theme->slug ) ),
       
   478 					__( 'Install' )
       
   479 				);
       
   480 				break;
       
   481 		}
       
   482 		?>
   411 			<h3 class="theme-name"><?php echo $name; ?></h3>
   483 			<h3 class="theme-name"><?php echo $name; ?></h3>
   412 			<span class="theme-by"><?php printf( __( 'By %s' ), $author ); ?></span>
   484 			<span class="theme-by">
   413 			<?php if ( isset( $theme->screenshot_url ) ): ?>
   485 			<?php
       
   486 				/* translators: %s: theme author */
       
   487 				printf( __( 'By %s' ), $author );
       
   488 			?>
       
   489 			</span>
       
   490 			<?php if ( isset( $theme->screenshot_url ) ) : ?>
   414 				<img class="theme-screenshot" src="<?php echo esc_url( $theme->screenshot_url ); ?>" alt="" />
   491 				<img class="theme-screenshot" src="<?php echo esc_url( $theme->screenshot_url ); ?>" alt="" />
   415 			<?php endif; ?>
   492 			<?php endif; ?>
   416 			<div class="theme-details">
   493 			<div class="theme-details">
   417 				<?php wp_star_rating( array( 'rating' => $theme->rating, 'type' => 'percent', 'number' => $theme->num_ratings ) ); ?>
   494 				<?php
       
   495 				wp_star_rating(
       
   496 					array(
       
   497 						'rating' => $theme->rating,
       
   498 						'type'   => 'percent',
       
   499 						'number' => $theme->num_ratings,
       
   500 					)
       
   501 				);
       
   502 				?>
   418 				<div class="theme-version">
   503 				<div class="theme-version">
   419 					<strong><?php _e('Version:') ?> </strong>
   504 					<strong><?php _e( 'Version:' ); ?> </strong>
   420 					<?php echo wp_kses( $theme->version, $themes_allowedtags ); ?>
   505 					<?php echo wp_kses( $theme->version, $themes_allowedtags ); ?>
   421 				</div>
   506 				</div>
   422 				<div class="theme-description">
   507 				<div class="theme-description">
   423 					<?php echo wp_kses( $theme->description, $themes_allowedtags ); ?>
   508 					<?php echo wp_kses( $theme->description, $themes_allowedtags ); ?>
   424 				</div>
   509 				</div>
   454 	private function _get_theme_status( $theme ) {
   539 	private function _get_theme_status( $theme ) {
   455 		$status = 'install';
   540 		$status = 'install';
   456 
   541 
   457 		$installed_theme = wp_get_theme( $theme->slug );
   542 		$installed_theme = wp_get_theme( $theme->slug );
   458 		if ( $installed_theme->exists() ) {
   543 		if ( $installed_theme->exists() ) {
   459 			if ( version_compare( $installed_theme->get('Version'), $theme->version, '=' ) )
   544 			if ( version_compare( $installed_theme->get( 'Version' ), $theme->version, '=' ) ) {
   460 				$status = 'latest_installed';
   545 				$status = 'latest_installed';
   461 			elseif ( version_compare( $installed_theme->get('Version'), $theme->version, '>' ) )
   546 			} elseif ( version_compare( $installed_theme->get( 'Version' ), $theme->version, '>' ) ) {
   462 				$status = 'newer_installed';
   547 				$status = 'newer_installed';
   463 			else
   548 			} else {
   464 				$status = 'update_available';
   549 				$status = 'update_available';
       
   550 			}
   465 		}
   551 		}
   466 
   552 
   467 		return $status;
   553 		return $status;
   468 	}
   554 	}
   469 }
   555 }