ExportInstallPluginSteps.php
1 year ago
ExportInstallThemeSteps.php
1 year ago
HasAlias.php
1 year ago
StepExporter.php
1 year ago
ExportInstallThemeSteps.php
93 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Automattic\WooCommerce\Blueprint\Exporters; |
| 4 | |
| 5 | use Automattic\WooCommerce\Blueprint\Steps\InstallTheme; |
| 6 | use Automattic\WooCommerce\Blueprint\UseWPFunctions; |
| 7 | |
| 8 | /** |
| 9 | * Class ExportInstallThemeSteps |
| 10 | * |
| 11 | * Exporter for the InstallTheme step. |
| 12 | * |
| 13 | * @package Automattic\WooCommerce\Blueprint\Exporters |
| 14 | */ |
| 15 | class ExportInstallThemeSteps implements StepExporter { |
| 16 | use UseWPFunctions; |
| 17 | |
| 18 | /** |
| 19 | * Filter callback. |
| 20 | * |
| 21 | * @var callable |
| 22 | */ |
| 23 | private $filter_callback; |
| 24 | |
| 25 | /** |
| 26 | * Register a filter callback to filter the plugins to export. |
| 27 | * |
| 28 | * @param callable $callback Filter callback. |
| 29 | * |
| 30 | * @return void |
| 31 | */ |
| 32 | public function filter( callable $callback ) { |
| 33 | $this->filter_callback = $callback; |
| 34 | } |
| 35 | /** |
| 36 | * Export the steps. |
| 37 | * |
| 38 | * @return array |
| 39 | */ |
| 40 | public function export() { |
| 41 | $steps = array(); |
| 42 | $themes = $this->wp_get_themes(); |
| 43 | if ( is_callable( $this->filter_callback ) ) { |
| 44 | $themes = call_user_func( $this->filter_callback, $themes ); |
| 45 | } |
| 46 | $active_theme = $this->wp_get_theme(); |
| 47 | |
| 48 | foreach ( $themes as $slug => $theme ) { |
| 49 | // Check if the theme is active. |
| 50 | $is_active = $theme->get( 'Name' ) === $active_theme->get( 'Name' ); |
| 51 | |
| 52 | $info = $this->wp_themes_api( |
| 53 | 'theme_information', |
| 54 | array( |
| 55 | 'slug' => $slug, |
| 56 | 'fields' => array( |
| 57 | 'sections' => false, |
| 58 | ), |
| 59 | ) |
| 60 | ); |
| 61 | if ( isset( $info->download_link ) ) { |
| 62 | $steps[] = new InstallTheme( |
| 63 | $slug, |
| 64 | 'wordpress.org/themes', |
| 65 | array( |
| 66 | 'activate' => $is_active, |
| 67 | ) |
| 68 | ); |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | return $steps; |
| 73 | } |
| 74 | |
| 75 | /** |
| 76 | * Get the step name. |
| 77 | * |
| 78 | * @return string |
| 79 | */ |
| 80 | public function get_step_name() { |
| 81 | return InstallTheme::get_step_name(); |
| 82 | } |
| 83 | |
| 84 | /** |
| 85 | * Check if the current user has the required capabilities for this step. |
| 86 | * |
| 87 | * @return bool True if the user has the required capabilities. False otherwise. |
| 88 | */ |
| 89 | public function check_step_capabilities(): bool { |
| 90 | return current_user_can( 'switch_themes' ); |
| 91 | } |
| 92 | } |
| 93 |