Order.php
3 years ago
OrderRefund.php
3 years ago
OrderTraits.php
9 months ago
ThemeUpgrader.php
4 years ago
ThemeUpgraderSkin.php
4 years ago
ThemeUpgrader.php
68 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Theme upgrader used in REST API response. |
| 4 | */ |
| 5 | |
| 6 | namespace Automattic\WooCommerce\Admin\Overrides; |
| 7 | |
| 8 | defined( 'ABSPATH' ) || exit; |
| 9 | |
| 10 | /** |
| 11 | * Admin\Overrides\ThemeUpgrader Class. |
| 12 | */ |
| 13 | class ThemeUpgrader extends \Theme_Upgrader { |
| 14 | /** |
| 15 | * Install a theme package. |
| 16 | * |
| 17 | * @param string $package The full local path or URI of the package. |
| 18 | * @param array $args { |
| 19 | * Optional. Other arguments for installing a theme package. Default empty array. |
| 20 | * |
| 21 | * @type bool $clear_update_cache Whether to clear the updates cache if successful. |
| 22 | * Default true. |
| 23 | * } |
| 24 | * |
| 25 | * @return bool|WP_Error True if the installation was successful, false or a WP_Error object otherwise. |
| 26 | */ |
| 27 | public function install( $package, $args = array() ) { |
| 28 | $defaults = array( |
| 29 | 'clear_update_cache' => true, |
| 30 | ); |
| 31 | $parsed_args = wp_parse_args( $args, $defaults ); |
| 32 | |
| 33 | $this->init(); |
| 34 | $this->install_strings(); |
| 35 | |
| 36 | add_filter( 'upgrader_source_selection', array( $this, 'check_package' ) ); |
| 37 | add_filter( 'upgrader_post_install', array( $this, 'check_parent_theme_filter' ), 10, 3 ); |
| 38 | if ( $parsed_args['clear_update_cache'] ) { |
| 39 | // Clear cache so wp_update_themes() knows about the new theme. |
| 40 | add_action( 'upgrader_process_complete', 'wp_clean_themes_cache', 9, 0 ); |
| 41 | } |
| 42 | |
| 43 | $result = $this->run( |
| 44 | array( |
| 45 | 'package' => $package, |
| 46 | 'destination' => get_theme_root(), |
| 47 | 'clear_destination' => false, // Do not overwrite files. |
| 48 | 'clear_working' => true, |
| 49 | 'hook_extra' => array( |
| 50 | 'type' => 'theme', |
| 51 | 'action' => 'install', |
| 52 | ), |
| 53 | ) |
| 54 | ); |
| 55 | |
| 56 | remove_action( 'upgrader_process_complete', 'wp_clean_themes_cache', 9 ); |
| 57 | remove_filter( 'upgrader_source_selection', array( $this, 'check_package' ) ); |
| 58 | remove_filter( 'upgrader_post_install', array( $this, 'check_parent_theme_filter' ) ); |
| 59 | |
| 60 | if ( $result && ! is_wp_error( $result ) ) { |
| 61 | // Refresh the Theme Update information. |
| 62 | wp_clean_themes_cache( $parsed_args['clear_update_cache'] ); |
| 63 | } |
| 64 | |
| 65 | return $result; |
| 66 | } |
| 67 | } |
| 68 |