Changeset 42343 for trunk/src/wp-admin/includes/theme.php
- Timestamp:
- 11/30/2017 11:09:33 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/includes/theme.php
r42006 r42343 18 18 * @return void|bool|WP_Error When void, echoes content. 19 19 */ 20 function delete_theme( $stylesheet, $redirect = '') {20 function delete_theme( $stylesheet, $redirect = '' ) { 21 21 global $wp_filesystem; 22 22 23 if ( empty( $stylesheet) )23 if ( empty( $stylesheet ) ) { 24 24 return false; 25 } 25 26 26 27 if ( empty( $redirect ) ) { 27 $redirect = wp_nonce_url( 'themes.php?action=delete&stylesheet=' . urlencode( $stylesheet ), 'delete-theme_' . $stylesheet);28 $redirect = wp_nonce_url( 'themes.php?action=delete&stylesheet=' . urlencode( $stylesheet ), 'delete-theme_' . $stylesheet ); 28 29 } 29 30 30 31 ob_start(); 31 32 $credentials = request_filesystem_credentials( $redirect ); 32 $data = ob_get_clean();33 $data = ob_get_clean(); 33 34 34 35 if ( false === $credentials ) { 35 if ( ! empty( $data ) ) {36 include_once( ABSPATH . 'wp-admin/admin-header.php' );36 if ( ! empty( $data ) ) { 37 include_once( ABSPATH . 'wp-admin/admin-header.php' ); 37 38 echo $data; 38 include( ABSPATH . 'wp-admin/admin-footer.php' );39 include( ABSPATH . 'wp-admin/admin-footer.php' ); 39 40 exit; 40 41 } … … 47 48 $data = ob_get_clean(); 48 49 49 if ( ! empty( $data) ) {50 include_once( ABSPATH . 'wp-admin/admin-header.php' );50 if ( ! empty( $data ) ) { 51 include_once( ABSPATH . 'wp-admin/admin-header.php' ); 51 52 echo $data; 52 include( ABSPATH . 'wp-admin/admin-footer.php' );53 include( ABSPATH . 'wp-admin/admin-footer.php' ); 53 54 exit; 54 55 } … … 56 57 } 57 58 58 if ( ! is_object($wp_filesystem) ) 59 return new WP_Error('fs_unavailable', __('Could not access filesystem.')); 60 61 if ( is_wp_error($wp_filesystem->errors) && $wp_filesystem->errors->get_error_code() ) 62 return new WP_Error('fs_error', __('Filesystem error.'), $wp_filesystem->errors); 59 if ( ! is_object( $wp_filesystem ) ) { 60 return new WP_Error( 'fs_unavailable', __( 'Could not access filesystem.' ) ); 61 } 62 63 if ( is_wp_error( $wp_filesystem->errors ) && $wp_filesystem->errors->get_error_code() ) { 64 return new WP_Error( 'fs_error', __( 'Filesystem error.' ), $wp_filesystem->errors ); 65 } 63 66 64 67 // Get the base plugin folder. … … 69 72 70 73 $themes_dir = trailingslashit( $themes_dir ); 71 $theme_dir = trailingslashit( $themes_dir . $stylesheet );72 $deleted = $wp_filesystem->delete( $theme_dir, true );74 $theme_dir = trailingslashit( $themes_dir . $stylesheet ); 75 $deleted = $wp_filesystem->delete( $theme_dir, true ); 73 76 74 77 if ( ! $deleted ) { … … 123 126 * @return string 124 127 */ 125 function _get_template_edit_filename( $fullpath, $containingfolder) {126 return str_replace( dirname(dirname( $containingfolder )) , '', $fullpath);128 function _get_template_edit_filename( $fullpath, $containingfolder ) { 129 return str_replace( dirname( dirname( $containingfolder ) ), '', $fullpath ); 127 130 } 128 131 … … 156 159 static $themes_update = null; 157 160 158 if ( ! current_user_can('update_themes' ) )161 if ( ! current_user_can( 'update_themes' ) ) { 159 162 return false; 160 161 if ( !isset($themes_update) ) 162 $themes_update = get_site_transient('update_themes'); 163 } 164 165 if ( ! isset( $themes_update ) ) { 166 $themes_update = get_site_transient( 'update_themes' ); 167 } 163 168 164 169 if ( ! ( $theme instanceof WP_Theme ) ) { … … 170 175 $html = ''; 171 176 172 if ( isset($themes_update->response[ $stylesheet ]) ) { 173 $update = $themes_update->response[ $stylesheet ]; 174 $theme_name = $theme->display('Name'); 175 $details_url = add_query_arg(array('TB_iframe' => 'true', 'width' => 1024, 'height' => 800), $update['url']); //Theme browser inside WP? replace this, Also, theme preview JS will override this on the available list. 176 $update_url = wp_nonce_url( admin_url( 'update.php?action=upgrade-theme&theme=' . urlencode( $stylesheet ) ), 'upgrade-theme_' . $stylesheet ); 177 178 if ( !is_multisite() ) { 179 if ( ! current_user_can('update_themes') ) { 177 if ( isset( $themes_update->response[ $stylesheet ] ) ) { 178 $update = $themes_update->response[ $stylesheet ]; 179 $theme_name = $theme->display( 'Name' ); 180 $details_url = add_query_arg( 181 array( 182 'TB_iframe' => 'true', 183 'width' => 1024, 184 'height' => 800, 185 ), $update['url'] 186 ); //Theme browser inside WP? replace this, Also, theme preview JS will override this on the available list. 187 $update_url = wp_nonce_url( admin_url( 'update.php?action=upgrade-theme&theme=' . urlencode( $stylesheet ) ), 'upgrade-theme_' . $stylesheet ); 188 189 if ( ! is_multisite() ) { 190 if ( ! current_user_can( 'update_themes' ) ) { 180 191 /* translators: 1: theme name, 2: theme details URL, 3: additional link attributes, 4: version number */ 181 $html = sprintf( '<p><strong>' . __( 'There is a new version of %1$s available. <a href="%2$s" %3$s>View version %4$s details</a>.' ) . '</strong></p>', 192 $html = sprintf( 193 '<p><strong>' . __( 'There is a new version of %1$s available. <a href="%2$s" %3$s>View version %4$s details</a>.' ) . '</strong></p>', 182 194 $theme_name, 183 195 esc_url( $details_url ), 184 sprintf( 'class="thickbox open-plugin-details-modal" aria-label="%s"', 196 sprintf( 197 'class="thickbox open-plugin-details-modal" aria-label="%s"', 185 198 /* translators: 1: theme name, 2: version number */ 186 199 esc_attr( sprintf( __( 'View %1$s version %2$s details' ), $theme_name, $update['new_version'] ) ) … … 190 203 } elseif ( empty( $update['package'] ) ) { 191 204 /* translators: 1: theme name, 2: theme details URL, 3: additional link attributes, 4: version number */ 192 $html = sprintf( '<p><strong>' . __( 'There is a new version of %1$s available. <a href="%2$s" %3$s>View version %4$s details</a>. <em>Automatic update is unavailable for this theme.</em>' ) . '</strong></p>', 205 $html = sprintf( 206 '<p><strong>' . __( 'There is a new version of %1$s available. <a href="%2$s" %3$s>View version %4$s details</a>. <em>Automatic update is unavailable for this theme.</em>' ) . '</strong></p>', 193 207 $theme_name, 194 208 esc_url( $details_url ), 195 sprintf( 'class="thickbox open-plugin-details-modal" aria-label="%s"', 209 sprintf( 210 'class="thickbox open-plugin-details-modal" aria-label="%s"', 196 211 /* translators: 1: theme name, 2: version number */ 197 212 esc_attr( sprintf( __( 'View %1$s version %2$s details' ), $theme_name, $update['new_version'] ) ) … … 201 216 } else { 202 217 /* translators: 1: theme name, 2: theme details URL, 3: additional link attributes, 4: version number, 5: update URL, 6: additional link attributes */ 203 $html = sprintf( '<p><strong>' . __( 'There is a new version of %1$s available. <a href="%2$s" %3$s>View version %4$s details</a> or <a href="%5$s" %6$s>update now</a>.' ) . '</strong></p>', 218 $html = sprintf( 219 '<p><strong>' . __( 'There is a new version of %1$s available. <a href="%2$s" %3$s>View version %4$s details</a> or <a href="%5$s" %6$s>update now</a>.' ) . '</strong></p>', 204 220 $theme_name, 205 221 esc_url( $details_url ), 206 sprintf( 'class="thickbox open-plugin-details-modal" aria-label="%s"', 222 sprintf( 223 'class="thickbox open-plugin-details-modal" aria-label="%s"', 207 224 /* translators: 1: theme name, 2: version number */ 208 225 esc_attr( sprintf( __( 'View %1$s version %2$s details' ), $theme_name, $update['new_version'] ) ) … … 210 227 $update['new_version'], 211 228 $update_url, 212 sprintf( 'aria-label="%s" id="update-theme" data-slug="%s"', 229 sprintf( 230 'aria-label="%s" id="update-theme" data-slug="%s"', 213 231 /* translators: %s: theme name */ 214 232 esc_attr( sprintf( __( 'Update %s now' ), $theme_name ) ), … … 263 281 ), 264 282 265 __( 'Layout' ) => array(283 __( 'Layout' ) => array( 266 284 'grid-layout' => __( 'Grid Layout' ), 267 285 'one-column' => __( 'One Column' ), … … 271 289 'left-sidebar' => __( 'Left Sidebar' ), 272 290 'right-sidebar' => __( 'Right Sidebar' ), 273 ) 291 ), 274 292 275 293 ); 276 294 277 if ( ! $api || ! current_user_can( 'install_themes' ) ) 295 if ( ! $api || ! current_user_can( 'install_themes' ) ) { 278 296 return $features; 279 280 if ( !$feature_list = get_site_transient( 'wporg_theme_feature_list' ) ) 297 } 298 299 if ( ! $feature_list = get_site_transient( 'wporg_theme_feature_list' ) ) { 281 300 set_site_transient( 'wporg_theme_feature_list', array(), 3 * HOUR_IN_SECONDS ); 282 283 if ( !$feature_list ) { 301 } 302 303 if ( ! $feature_list ) { 284 304 $feature_list = themes_api( 'feature_list', array() ); 285 if ( is_wp_error( $feature_list ) ) 305 if ( is_wp_error( $feature_list ) ) { 286 306 return $features; 287 } 288 289 if ( !$feature_list ) 307 } 308 } 309 310 if ( ! $feature_list ) { 290 311 return $features; 312 } 291 313 292 314 set_site_transient( 'wporg_theme_feature_list', $feature_list, 3 * HOUR_IN_SECONDS ); … … 301 323 $wporg_features = array(); 302 324 foreach ( (array) $feature_list as $feature_category => $feature_items ) { 303 if ( isset($category_translations[$feature_category]) ) 304 $feature_category = $category_translations[$feature_category]; 305 $wporg_features[$feature_category] = array(); 325 if ( isset( $category_translations[ $feature_category ] ) ) { 326 $feature_category = $category_translations[ $feature_category ]; 327 } 328 $wporg_features[ $feature_category ] = array(); 306 329 307 330 foreach ( $feature_items as $feature ) { 308 if ( isset($features[$feature_category][$feature]) ) 309 $wporg_features[$feature_category][$feature] = $features[$feature_category][$feature]; 310 else 311 $wporg_features[$feature_category][$feature] = $feature; 331 if ( isset( $features[ $feature_category ][ $feature ] ) ) { 332 $wporg_features[ $feature_category ][ $feature ] = $features[ $feature_category ][ $feature ]; 333 } else { 334 $wporg_features[ $feature_category ][ $feature ] = $feature; 335 } 312 336 } 313 337 } … … 446 470 447 471 $url = $http_url = 'http://api.wordpress.org/themes/info/1.0/'; 448 if ( $ssl = wp_http_supports( array( 'ssl' ) ) ) 472 if ( $ssl = wp_http_supports( array( 'ssl' ) ) ) { 449 473 $url = set_url_scheme( $url, 'https' ); 474 } 450 475 451 476 $http_args = array( 452 477 'user-agent' => 'WordPress/' . $wp_version . '; ' . home_url( '/' ), 453 'body' => array(454 'action' => $action,455 'request' => serialize( $args ) 456 ) 478 'body' => array( 479 'action' => $action, 480 'request' => serialize( $args ), 481 ), 457 482 ); 458 $request = wp_remote_post( $url, $http_args );483 $request = wp_remote_post( $url, $http_args ); 459 484 460 485 if ( $ssl && is_wp_error( $request ) ) { … … 472 497 } 473 498 474 if ( is_wp_error($request) ) { 475 $res = new WP_Error( 'themes_api_failed', 499 if ( is_wp_error( $request ) ) { 500 $res = new WP_Error( 501 'themes_api_failed', 476 502 sprintf( 477 503 /* translators: %s: support forums URL */ … … 484 510 $res = maybe_unserialize( wp_remote_retrieve_body( $request ) ); 485 511 if ( ! is_object( $res ) && ! is_array( $res ) ) { 486 $res = new WP_Error( 'themes_api_failed', 512 $res = new WP_Error( 513 'themes_api_failed', 487 514 sprintf( 488 515 /* translators: %s: support forums URL */ … … 563 590 564 591 foreach ( $themes as $theme ) { 565 $slug = $theme->get_stylesheet();592 $slug = $theme->get_stylesheet(); 566 593 $encoded_slug = urlencode( $slug ); 567 594 568 595 $parent = false; 569 596 if ( $theme->parent() ) { 570 $parent = $theme->parent();597 $parent = $theme->parent(); 571 598 $parents[ $slug ] = $parent->get_stylesheet(); 572 $parent = $parent->display( 'Name' );599 $parent = $parent->display( 'Name' ); 573 600 } 574 601 575 602 $customize_action = null; 576 603 if ( current_user_can( 'edit_theme_options' ) && current_user_can( 'customize' ) ) { 577 $customize_action = esc_url( add_query_arg( 578 array( 579 'return' => urlencode( esc_url_raw( remove_query_arg( wp_removable_query_args(), wp_unslash( $_SERVER['REQUEST_URI'] ) ) ) ), 580 ), 581 wp_customize_url( $slug ) 582 ) ); 604 $customize_action = esc_url( 605 add_query_arg( 606 array( 607 'return' => urlencode( esc_url_raw( remove_query_arg( wp_removable_query_args(), wp_unslash( $_SERVER['REQUEST_URI'] ) ) ) ), 608 ), 609 wp_customize_url( $slug ) 610 ) 611 ); 583 612 } 584 613 … … 595 624 'active' => $slug === $current_theme, 596 625 'hasUpdate' => isset( $updates[ $slug ] ), 597 'hasPackage' => isset( $updates[ $slug ] ) && ! empty( $updates[ $slug ][ 'package'] ),626 'hasPackage' => isset( $updates[ $slug ] ) && ! empty( $updates[ $slug ]['package'] ), 598 627 'update' => get_theme_update_available( $theme ), 599 628 'actions' => array( 600 'activate' => current_user_can( 'switch_themes' ) ? wp_nonce_url( admin_url( 'themes.php?action=activate&stylesheet=' . $encoded_slug ), 'switch-theme_' . $slug ) : null,629 'activate' => current_user_can( 'switch_themes' ) ? wp_nonce_url( admin_url( 'themes.php?action=activate&stylesheet=' . $encoded_slug ), 'switch-theme_' . $slug ) : null, 601 630 'customize' => $customize_action, 602 'delete' => current_user_can( 'delete_themes' ) ? wp_nonce_url( admin_url( 'themes.php?action=delete&stylesheet=' . $encoded_slug ), 'delete-theme_' . $slug ) : null,631 'delete' => current_user_can( 'delete_themes' ) ? wp_nonce_url( admin_url( 'themes.php?action=delete&stylesheet=' . $encoded_slug ), 'delete-theme_' . $slug ) : null, 603 632 ), 604 633 );
Note: See TracChangeset
for help on using the changeset viewer.