Changeset 42343 for trunk/src/wp-admin/includes/class-theme-upgrader.php
- Timestamp:
- 11/30/2017 11:09:33 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/includes/class-theme-upgrader.php
r41909 r42343 44 44 */ 45 45 public function upgrade_strings() { 46 $this->strings['up_to_date'] = __( 'The theme is at the latest version.');47 $this->strings['no_package'] = __( 'Update package not available.');46 $this->strings['up_to_date'] = __( 'The theme is at the latest version.' ); 47 $this->strings['no_package'] = __( 'Update package not available.' ); 48 48 /* translators: %s: package URL */ 49 49 $this->strings['downloading_package'] = sprintf( __( 'Downloading update from %s…' ), '<span class="code">%s</span>' ); 50 $this->strings['unpack_package'] = __('Unpacking the update…');51 $this->strings['remove_old'] = __('Removing the old version of the theme…');52 $this->strings['remove_old_failed'] = __('Could not remove the old theme.');53 $this->strings['process_failed'] = __('Theme update failed.');54 $this->strings['process_success'] = __('Theme updated successfully.');50 $this->strings['unpack_package'] = __( 'Unpacking the update…' ); 51 $this->strings['remove_old'] = __( 'Removing the old version of the theme…' ); 52 $this->strings['remove_old_failed'] = __( 'Could not remove the old theme.' ); 53 $this->strings['process_failed'] = __( 'Theme update failed.' ); 54 $this->strings['process_success'] = __( 'Theme updated successfully.' ); 55 55 } 56 56 … … 61 61 */ 62 62 public function install_strings() { 63 $this->strings['no_package'] = __( 'Installation package not available.');63 $this->strings['no_package'] = __( 'Installation package not available.' ); 64 64 /* translators: %s: package URL */ 65 65 $this->strings['downloading_package'] = sprintf( __( 'Downloading installation package from %s…' ), '<span class="code">%s</span>' ); 66 $this->strings['unpack_package'] = __('Unpacking the package…');67 $this->strings['installing_package'] = __('Installing the theme…');68 $this->strings['no_files'] = __('The theme contains no files.');69 $this->strings['process_failed'] = __('Theme installation failed.');70 $this->strings['process_success'] = __('Theme installed successfully.');66 $this->strings['unpack_package'] = __( 'Unpacking the package…' ); 67 $this->strings['installing_package'] = __( 'Installing the theme…' ); 68 $this->strings['no_files'] = __( 'The theme contains no files.' ); 69 $this->strings['process_failed'] = __( 'Theme installation failed.' ); 70 $this->strings['process_success'] = __( 'Theme installed successfully.' ); 71 71 /* translators: 1: theme name, 2: version */ 72 $this->strings['process_success_specific'] = __( 'Successfully installed the theme <strong>%1$s %2$s</strong>.');73 $this->strings['parent_theme_search'] = __('This theme requires a parent theme. Checking if it is installed…');72 $this->strings['process_success_specific'] = __( 'Successfully installed the theme <strong>%1$s %2$s</strong>.' ); 73 $this->strings['parent_theme_search'] = __( 'This theme requires a parent theme. Checking if it is installed…' ); 74 74 /* translators: 1: theme name, 2: version */ 75 $this->strings['parent_theme_prepare_install'] = __( 'Preparing to install <strong>%1$s %2$s</strong>…');75 $this->strings['parent_theme_prepare_install'] = __( 'Preparing to install <strong>%1$s %2$s</strong>…' ); 76 76 /* translators: 1: theme name, 2: version */ 77 $this->strings['parent_theme_currently_installed'] = __( 'The parent theme, <strong>%1$s %2$s</strong>, is currently installed.');77 $this->strings['parent_theme_currently_installed'] = __( 'The parent theme, <strong>%1$s %2$s</strong>, is currently installed.' ); 78 78 /* translators: 1: theme name, 2: version */ 79 $this->strings['parent_theme_install_success'] = __( 'Successfully installed the parent theme, <strong>%1$s %2$s</strong>.');79 $this->strings['parent_theme_install_success'] = __( 'Successfully installed the parent theme, <strong>%1$s %2$s</strong>.' ); 80 80 /* translators: %s: theme name */ 81 81 $this->strings['parent_theme_not_found'] = sprintf( __( '<strong>The parent theme could not be found.</strong> You will need to install the parent theme, %s, before you can use this child theme.' ), '<strong>%s</strong>' ); … … 98 98 $theme_info = $this->theme_info(); 99 99 100 if ( ! $theme_info->parent() ) 100 if ( ! $theme_info->parent() ) { 101 101 return $install_result; 102 } 102 103 103 104 $this->skin->feedback( 'parent_theme_search' ); 104 105 105 106 if ( ! $theme_info->parent()->errors() ) { 106 $this->skin->feedback( 'parent_theme_currently_installed', $theme_info->parent()->display( 'Name'), $theme_info->parent()->display('Version') );107 $this->skin->feedback( 'parent_theme_currently_installed', $theme_info->parent()->display( 'Name' ), $theme_info->parent()->display( 'Version' ) ); 107 108 // We already have the theme, fall through. 108 109 return $install_result; … … 110 111 111 112 // We don't have the parent theme, let's install it. 112 $api = themes_api('theme_information', array('slug' => $theme_info->get('Template'), 'fields' => array('sections' => false, 'tags' => false) ) ); //Save on a bit of bandwidth. 113 114 if ( ! $api || is_wp_error($api) ) { 115 $this->skin->feedback( 'parent_theme_not_found', $theme_info->get('Template') ); 113 $api = themes_api( 114 'theme_information', array( 115 'slug' => $theme_info->get( 'Template' ), 116 'fields' => array( 117 'sections' => false, 118 'tags' => false, 119 ), 120 ) 121 ); //Save on a bit of bandwidth. 122 123 if ( ! $api || is_wp_error( $api ) ) { 124 $this->skin->feedback( 'parent_theme_not_found', $theme_info->get( 'Template' ) ); 116 125 // Don't show activate or preview actions after installation 117 add_filter( 'install_theme_complete_actions', array($this, 'hide_activate_preview_actions') );126 add_filter( 'install_theme_complete_actions', array( $this, 'hide_activate_preview_actions' ) ); 118 127 return $install_result; 119 128 } 120 129 121 130 // Backup required data we're going to override: 122 $child_api = $this->skin->api;131 $child_api = $this->skin->api; 123 132 $child_success_message = $this->strings['process_success']; 124 133 125 134 // Override them 126 $this->skin->api = $api;135 $this->skin->api = $api; 127 136 $this->strings['process_success_specific'] = $this->strings['parent_theme_install_success'];//, $api->name, $api->version); 128 137 129 $this->skin->feedback( 'parent_theme_prepare_install', $api->name, $api->version);130 131 add_filter( 'install_theme_complete_actions', '__return_false', 999); // Don't show any actions after installing the theme.138 $this->skin->feedback( 'parent_theme_prepare_install', $api->name, $api->version ); 139 140 add_filter( 'install_theme_complete_actions', '__return_false', 999 ); // Don't show any actions after installing the theme. 132 141 133 142 // Install the parent theme 134 $parent_result = $this->run( array( 135 'package' => $api->download_link, 136 'destination' => get_theme_root(), 137 'clear_destination' => false, //Do not overwrite files. 138 'clear_working' => true 139 ) ); 140 141 if ( is_wp_error($parent_result) ) 142 add_filter('install_theme_complete_actions', array($this, 'hide_activate_preview_actions') ); 143 $parent_result = $this->run( 144 array( 145 'package' => $api->download_link, 146 'destination' => get_theme_root(), 147 'clear_destination' => false, //Do not overwrite files. 148 'clear_working' => true, 149 ) 150 ); 151 152 if ( is_wp_error( $parent_result ) ) { 153 add_filter( 'install_theme_complete_actions', array( $this, 'hide_activate_preview_actions' ) ); 154 } 143 155 144 156 // Start cleaning up after the parents installation 145 remove_filter( 'install_theme_complete_actions', '__return_false', 999);157 remove_filter( 'install_theme_complete_actions', '__return_false', 999 ); 146 158 147 159 // Reset child's result and data 148 $this->result = $child_result;149 $this->skin->api = $child_api;160 $this->result = $child_result; 161 $this->skin->api = $child_api; 150 162 $this->strings['process_success'] = $child_success_message; 151 163 … … 166 178 */ 167 179 public function hide_activate_preview_actions( $actions ) { 168 unset( $actions['activate'], $actions['preview']);180 unset( $actions['activate'], $actions['preview'] ); 169 181 return $actions; 170 182 } … … 188 200 public function install( $package, $args = array() ) { 189 201 190 $defaults = array(202 $defaults = array( 191 203 'clear_update_cache' => true, 192 204 ); … … 196 208 $this->install_strings(); 197 209 198 add_filter( 'upgrader_source_selection', array($this, 'check_package') );199 add_filter( 'upgrader_post_install', array($this, 'check_parent_theme_filter'), 10, 3);210 add_filter( 'upgrader_source_selection', array( $this, 'check_package' ) ); 211 add_filter( 'upgrader_post_install', array( $this, 'check_parent_theme_filter' ), 10, 3 ); 200 212 if ( $parsed_args['clear_update_cache'] ) { 201 213 // Clear cache so wp_update_themes() knows about the new theme. … … 203 215 } 204 216 205 $this->run( array( 206 'package' => $package, 207 'destination' => get_theme_root(), 208 'clear_destination' => false, //Do not overwrite files. 209 'clear_working' => true, 210 'hook_extra' => array( 211 'type' => 'theme', 212 'action' => 'install', 213 ), 214 ) ); 217 $this->run( 218 array( 219 'package' => $package, 220 'destination' => get_theme_root(), 221 'clear_destination' => false, //Do not overwrite files. 222 'clear_working' => true, 223 'hook_extra' => array( 224 'type' => 'theme', 225 'action' => 'install', 226 ), 227 ) 228 ); 215 229 216 230 remove_action( 'upgrader_process_complete', 'wp_clean_themes_cache', 9 ); 217 remove_filter( 'upgrader_source_selection', array($this, 'check_package') );218 remove_filter( 'upgrader_post_install', array($this, 'check_parent_theme_filter'));219 220 if ( ! $this->result || is_wp_error( $this->result) )231 remove_filter( 'upgrader_source_selection', array( $this, 'check_package' ) ); 232 remove_filter( 'upgrader_post_install', array( $this, 'check_parent_theme_filter' ) ); 233 234 if ( ! $this->result || is_wp_error( $this->result ) ) { 221 235 return $this->result; 236 } 222 237 223 238 // Refresh the Theme Update information … … 244 259 public function upgrade( $theme, $args = array() ) { 245 260 246 $defaults = array(261 $defaults = array( 247 262 'clear_update_cache' => true, 248 263 ); … … 254 269 // Is an update available? 255 270 $current = get_site_transient( 'update_themes' ); 256 if ( ! isset( $current->response[ $theme ] ) ) {271 if ( ! isset( $current->response[ $theme ] ) ) { 257 272 $this->skin->before(); 258 $this->skin->set_result( false);273 $this->skin->set_result( false ); 259 274 $this->skin->error( 'up_to_date' ); 260 275 $this->skin->after(); … … 264 279 $r = $current->response[ $theme ]; 265 280 266 add_filter( 'upgrader_pre_install', array($this, 'current_before'), 10, 2);267 add_filter( 'upgrader_post_install', array($this, 'current_after'), 10, 2);268 add_filter( 'upgrader_clear_destination', array($this, 'delete_old_theme'), 10, 4);281 add_filter( 'upgrader_pre_install', array( $this, 'current_before' ), 10, 2 ); 282 add_filter( 'upgrader_post_install', array( $this, 'current_after' ), 10, 2 ); 283 add_filter( 'upgrader_clear_destination', array( $this, 'delete_old_theme' ), 10, 4 ); 269 284 if ( $parsed_args['clear_update_cache'] ) { 270 285 // Clear cache so wp_update_themes() knows about the new theme. … … 272 287 } 273 288 274 $this->run( array( 275 'package' => $r['package'], 276 'destination' => get_theme_root( $theme ), 277 'clear_destination' => true, 278 'clear_working' => true, 279 'hook_extra' => array( 280 'theme' => $theme, 281 'type' => 'theme', 282 'action' => 'update', 283 ), 284 ) ); 289 $this->run( 290 array( 291 'package' => $r['package'], 292 'destination' => get_theme_root( $theme ), 293 'clear_destination' => true, 294 'clear_working' => true, 295 'hook_extra' => array( 296 'theme' => $theme, 297 'type' => 'theme', 298 'action' => 'update', 299 ), 300 ) 301 ); 285 302 286 303 remove_action( 'upgrader_process_complete', 'wp_clean_themes_cache', 9 ); 287 remove_filter( 'upgrader_pre_install', array($this, 'current_before'));288 remove_filter( 'upgrader_post_install', array($this, 'current_after'));289 remove_filter( 'upgrader_clear_destination', array($this, 'delete_old_theme'));290 291 if ( ! $this->result || is_wp_error( $this->result) )304 remove_filter( 'upgrader_pre_install', array( $this, 'current_before' ) ); 305 remove_filter( 'upgrader_post_install', array( $this, 'current_after' ) ); 306 remove_filter( 'upgrader_clear_destination', array( $this, 'delete_old_theme' ) ); 307 308 if ( ! $this->result || is_wp_error( $this->result ) ) { 292 309 return $this->result; 310 } 293 311 294 312 wp_clean_themes_cache( $parsed_args['clear_update_cache'] ); … … 314 332 public function bulk_upgrade( $themes, $args = array() ) { 315 333 316 $defaults = array(334 $defaults = array( 317 335 'clear_update_cache' => true, 318 336 ); … … 325 343 $current = get_site_transient( 'update_themes' ); 326 344 327 add_filter( 'upgrader_pre_install', array($this, 'current_before'), 10, 2);328 add_filter( 'upgrader_post_install', array($this, 'current_after'), 10, 2);329 add_filter( 'upgrader_clear_destination', array($this, 'delete_old_theme'), 10, 4);345 add_filter( 'upgrader_pre_install', array( $this, 'current_before' ), 10, 2 ); 346 add_filter( 'upgrader_post_install', array( $this, 'current_after' ), 10, 2 ); 347 add_filter( 'upgrader_clear_destination', array( $this, 'delete_old_theme' ), 10, 4 ); 330 348 331 349 $this->skin->header(); 332 350 333 351 // Connect to the Filesystem first. 334 $res = $this->fs_connect( array( WP_CONTENT_DIR) );352 $res = $this->fs_connect( array( WP_CONTENT_DIR ) ); 335 353 if ( ! $res ) { 336 354 $this->skin->footer(); … … 345 363 // @TODO: For multisite, maintenance mode should only kick in for individual sites if at all possible. 346 364 $maintenance = ( is_multisite() && ! empty( $themes ) ); 347 foreach ( $themes as $theme ) 365 foreach ( $themes as $theme ) { 348 366 $maintenance = $maintenance || $theme == get_stylesheet() || $theme == get_template(); 349 if ( $maintenance ) 350 $this->maintenance_mode(true); 367 } 368 if ( $maintenance ) { 369 $this->maintenance_mode( true ); 370 } 351 371 352 372 $results = array(); 353 373 354 $this->update_count = count($themes);374 $this->update_count = count( $themes ); 355 375 $this->update_current = 0; 356 376 foreach ( $themes as $theme ) { 357 377 $this->update_current++; 358 378 359 $this->skin->theme_info = $this->theme_info( $theme);360 361 if ( ! isset( $current->response[ $theme ] ) ) {362 $this->skin->set_result( true);379 $this->skin->theme_info = $this->theme_info( $theme ); 380 381 if ( ! isset( $current->response[ $theme ] ) ) { 382 $this->skin->set_result( true ); 363 383 $this->skin->before(); 364 384 $this->skin->feedback( 'up_to_date' ); 365 385 $this->skin->after(); 366 $results[ $theme] = true;386 $results[ $theme ] = true; 367 387 continue; 368 388 } … … 371 391 $r = $current->response[ $theme ]; 372 392 373 $result = $this->run( array( 374 'package' => $r['package'], 375 'destination' => get_theme_root( $theme ), 376 'clear_destination' => true, 377 'clear_working' => true, 378 'is_multi' => true, 379 'hook_extra' => array( 380 'theme' => $theme 381 ), 382 ) ); 383 384 $results[$theme] = $this->result; 393 $result = $this->run( 394 array( 395 'package' => $r['package'], 396 'destination' => get_theme_root( $theme ), 397 'clear_destination' => true, 398 'clear_working' => true, 399 'is_multi' => true, 400 'hook_extra' => array( 401 'theme' => $theme, 402 ), 403 ) 404 ); 405 406 $results[ $theme ] = $this->result; 385 407 386 408 // Prevent credentials auth screen from displaying multiple times 387 if ( false === $result ) 409 if ( false === $result ) { 388 410 break; 411 } 389 412 } //end foreach $plugins 390 413 391 $this->maintenance_mode( false);414 $this->maintenance_mode( false ); 392 415 393 416 // Refresh the Theme Update information … … 395 418 396 419 /** This action is documented in wp-admin/includes/class-wp-upgrader.php */ 397 do_action( 'upgrader_process_complete', $this, array( 398 'action' => 'update', 399 'type' => 'theme', 400 'bulk' => true, 401 'themes' => $themes, 402 ) ); 420 do_action( 421 'upgrader_process_complete', $this, array( 422 'action' => 'update', 423 'type' => 'theme', 424 'bulk' => true, 425 'themes' => $themes, 426 ) 427 ); 403 428 404 429 $this->skin->bulk_footer(); … … 407 432 408 433 // Cleanup our hooks, in case something else does a upgrade on this connection. 409 remove_filter( 'upgrader_pre_install', array($this, 'current_before'));410 remove_filter( 'upgrader_post_install', array($this, 'current_after'));411 remove_filter( 'upgrader_clear_destination', array($this, 'delete_old_theme'));434 remove_filter( 'upgrader_pre_install', array( $this, 'current_before' ) ); 435 remove_filter( 'upgrader_post_install', array( $this, 'current_after' ) ); 436 remove_filter( 'upgrader_clear_destination', array( $this, 'delete_old_theme' ) ); 412 437 413 438 return $results; … … 431 456 global $wp_filesystem; 432 457 433 if ( is_wp_error( $source) )458 if ( is_wp_error( $source ) ) { 434 459 return $source; 460 } 435 461 436 462 // Check the folder contains a valid theme 437 $working_directory = str_replace( $wp_filesystem->wp_content_dir(), trailingslashit( WP_CONTENT_DIR), $source);438 if ( ! is_dir( $working_directory) )// Sanity check, if the above fails, let's not prevent installation.463 $working_directory = str_replace( $wp_filesystem->wp_content_dir(), trailingslashit( WP_CONTENT_DIR ), $source ); 464 if ( ! is_dir( $working_directory ) ) { // Sanity check, if the above fails, let's not prevent installation. 439 465 return $source; 466 } 440 467 441 468 // A proper archive should have a style.css file in the single subdirectory 442 469 if ( ! file_exists( $working_directory . 'style.css' ) ) { 443 return new WP_Error( 'incompatible_archive_theme_no_style', $this->strings['incompatible_archive'], 470 return new WP_Error( 471 'incompatible_archive_theme_no_style', $this->strings['incompatible_archive'], 444 472 /* translators: %s: style.css */ 445 sprintf( __( 'The theme is missing the %s stylesheet.' ), 473 sprintf( 474 __( 'The theme is missing the %s stylesheet.' ), 446 475 '<code>style.css</code>' 447 476 ) … … 449 478 } 450 479 451 $info = get_file_data( $working_directory . 'style.css', array( 'Name' => 'Theme Name', 'Template' => 'Template' ) ); 480 $info = get_file_data( 481 $working_directory . 'style.css', array( 482 'Name' => 'Theme Name', 483 'Template' => 'Template', 484 ) 485 ); 452 486 453 487 if ( empty( $info['Name'] ) ) { 454 return new WP_Error( 'incompatible_archive_theme_no_name', $this->strings['incompatible_archive'], 488 return new WP_Error( 489 'incompatible_archive_theme_no_name', $this->strings['incompatible_archive'], 455 490 /* translators: %s: style.css */ 456 sprintf( __( 'The %s stylesheet doesn’t contain a valid theme header.' ), 491 sprintf( 492 __( 'The %s stylesheet doesn’t contain a valid theme header.' ), 457 493 '<code>style.css</code>' 458 494 ) … … 462 498 // If it's not a child theme, it must have at least an index.php to be legit. 463 499 if ( empty( $info['Template'] ) && ! file_exists( $working_directory . 'index.php' ) ) { 464 return new WP_Error( 'incompatible_archive_theme_no_index', $this->strings['incompatible_archive'], 500 return new WP_Error( 501 'incompatible_archive_theme_no_index', $this->strings['incompatible_archive'], 465 502 /* translators: %s: index.php */ 466 sprintf( __( 'The theme is missing the %s file.' ), 503 sprintf( 504 __( 'The theme is missing the %s file.' ), 467 505 '<code>index.php</code>' 468 506 ) … … 485 523 * @return bool|WP_Error 486 524 */ 487 public function current_before( $return, $theme) {488 if ( is_wp_error( $return) )525 public function current_before( $return, $theme ) { 526 if ( is_wp_error( $return ) ) { 489 527 return $return; 490 491 $theme = isset($theme['theme']) ? $theme['theme'] : ''; 492 493 if ( $theme != get_stylesheet() ) //If not current 528 } 529 530 $theme = isset( $theme['theme'] ) ? $theme['theme'] : ''; 531 532 if ( $theme != get_stylesheet() ) { //If not current 494 533 return $return; 534 } 495 535 //Change to maintenance mode now. 496 if ( ! $this->bulk ) 497 $this->maintenance_mode(true); 536 if ( ! $this->bulk ) { 537 $this->maintenance_mode( true ); 538 } 498 539 499 540 return $return; … … 512 553 * @return bool|WP_Error 513 554 */ 514 public function current_after( $return, $theme) {515 if ( is_wp_error( $return) )555 public function current_after( $return, $theme ) { 556 if ( is_wp_error( $return ) ) { 516 557 return $return; 517 518 $theme = isset($theme['theme']) ? $theme['theme'] : ''; 519 520 if ( $theme != get_stylesheet() ) // If not current 558 } 559 560 $theme = isset( $theme['theme'] ) ? $theme['theme'] : ''; 561 562 if ( $theme != get_stylesheet() ) { // If not current 521 563 return $return; 564 } 522 565 523 566 // Ensure stylesheet name hasn't changed after the upgrade: … … 529 572 530 573 //Time to remove maintenance mode 531 if ( ! $this->bulk ) 532 $this->maintenance_mode(false); 574 if ( ! $this->bulk ) { 575 $this->maintenance_mode( false ); 576 } 533 577 return $return; 534 578 } … … 553 597 global $wp_filesystem; 554 598 555 if ( is_wp_error( $removed ) ) 599 if ( is_wp_error( $removed ) ) { 556 600 return $removed; // Pass errors through. 557 558 if ( ! isset( $theme['theme'] ) ) 601 } 602 603 if ( ! isset( $theme['theme'] ) ) { 559 604 return $removed; 560 561 $theme = $theme['theme']; 605 } 606 607 $theme = $theme['theme']; 562 608 $themes_dir = trailingslashit( $wp_filesystem->wp_themes_dir( $theme ) ); 563 609 if ( $wp_filesystem->exists( $themes_dir . $theme ) ) { 564 if ( ! $wp_filesystem->delete( $themes_dir . $theme, true ) ) 610 if ( ! $wp_filesystem->delete( $themes_dir . $theme, true ) ) { 565 611 return false; 612 } 566 613 } 567 614 … … 580 627 * and the last result isn't set. 581 628 */ 582 public function theme_info( $theme = null) {583 584 if ( empty( $theme) ) {585 if ( ! empty($this->result['destination_name']) )629 public function theme_info( $theme = null ) { 630 631 if ( empty( $theme ) ) { 632 if ( ! empty( $this->result['destination_name'] ) ) { 586 633 $theme = $this->result['destination_name']; 587 else634 } else { 588 635 return false; 636 } 589 637 } 590 638 return wp_get_theme( $theme );
Note: See TracChangeset
for help on using the changeset viewer.