Automattic\WooCommerce\Blueprint\Importers
ImportInstallPlugin::process
Processes the schema to install and optionally activate a plugin.
Method of the class: ImportInstallPlugin{}
No Hooks.
Returns
StepProcessorResult
. Result of the processing.
Usage
$ImportInstallPlugin = new ImportInstallPlugin(); $ImportInstallPlugin->process( $schema ): StepProcessorResult;
- $schema(object) (required)
- Schema object containing plugin information.
ImportInstallPlugin::process() ImportInstallPlugin::process code WC 9.9.5
public function process( $schema ): StepProcessorResult { $result = StepProcessorResult::success( InstallPlugin::get_step_name() ); $installed_plugins = $this->get_installed_plugins_paths(); // phpcs:ignore $plugin = $schema->pluginData; // We only support CorePluginReference at the moment. if ( 'wordpress.org/plugins' !== $plugin->resource ) { $result->add_info( "Skipped installing a plugin. Unsupported resource type. Only 'wordpress.org/plugins' is supported at the moment." ); return $result; } // If the plugin is already installed, skip the installation. if ( isset( $installed_plugins[ $plugin->slug ] ) ) { $result->add_info( "Skipped installing {$plugin->slug}. It is already installed." ); return $result; } // If the resource type is not supported, return an error. if ( $this->storage->is_supported_resource( $plugin->resource ) === false ) { $result->add_error( "Invalid resource type for {$plugin->slug}." ); return $result; } // Download the plugin. $downloaded_path = $this->storage->download( $plugin->slug, $plugin->resource ); if ( ! $downloaded_path ) { $result->add_error( "Unable to download {$plugin->slug} with {$plugin->resource} resource type." ); return $result; } // Install the plugin. $install = $this->install( $downloaded_path ); if ( is_wp_error( $install ) ) { $result->add_error( "Failed to install {$plugin->slug}." ); return $result; } $result->add_info( "Installed {$plugin->slug}." ); // If the plugin should be activated, activate it. $should_activate = isset( $schema->options, $schema->options->activate ) && true === $schema->options->activate; if ( $should_activate ) { $activate = $this->activate( $plugin->slug ); if ( $activate instanceof \WP_Error ) { $result->add_error( "Failed to activate {$plugin->slug}." ); return $result; } $result->add_info( "Activated {$plugin->slug}." ); } return $result; }