WordPress как на ладони
Недорогой хостинг для сайтов на WordPress: wordpress.jino.ru
функция не описана

Automattic\WooCommerce\Admin\API

Plugins::install_plugins() public WC 1.0

Installs the requested plugins.

{} Это метод класса: Plugins{}

Хуки из метода

Возвращает

WP_Error|Массив. Plugin Status

Использование

$Plugins = new Plugins();
$Plugins->install_plugins( $request );
$request(WP_REST_Request) (обязательный)
Full details about the request.

Код Plugins::install_plugins() WC 5.8.0

public function install_plugins( $request ) {
	$plugins = explode( ',', $request['plugins'] );

	/**
	 * Filter the list of plugins to install.
	 *
	 * @param array $plugins A list of the plugins to install.
	 */
	$plugins = apply_filters( 'woocommerce_admin_plugins_pre_install', $plugins );

	if ( empty( $request['plugins'] ) || ! is_array( $plugins ) ) {
		return new \WP_Error( 'woocommerce_rest_invalid_plugins', __( 'Plugins must be a non-empty array.', 'woocommerce' ), 404 );
	}

	require_once ABSPATH . 'wp-admin/includes/plugin.php';
	include_once ABSPATH . '/wp-admin/includes/admin.php';
	include_once ABSPATH . '/wp-admin/includes/plugin-install.php';
	include_once ABSPATH . '/wp-admin/includes/plugin.php';
	include_once ABSPATH . '/wp-admin/includes/class-wp-upgrader.php';
	include_once ABSPATH . '/wp-admin/includes/class-plugin-upgrader.php';

	$existing_plugins  = PluginsHelper::get_installed_plugins_paths();
	$installed_plugins = array();
	$results           = array();
	$errors            = new \WP_Error();

	foreach ( $plugins as $plugin ) {
		$slug = sanitize_key( $plugin );

		if ( isset( $existing_plugins[ $slug ] ) ) {
			$installed_plugins[] = $plugin;
			continue;
		}

		$api = plugins_api(
			'plugin_information',
			array(
				'slug'   => $slug,
				'fields' => array(
					'sections' => false,
				),
			)
		);

		if ( is_wp_error( $api ) ) {
			$properties = array(
				/* translators: %s: plugin slug (example: woocommerce-services) */
				'error_message' => __( 'The requested plugin `%s` could not be installed. Plugin API call failed.', 'woocommerce' ),
				'api'           => $api,
				'slug'          => $slug,
			);
			wc_admin_record_tracks_event( 'install_plugin_error', $properties );

			$this->create_install_plugin_error_inbox_notification_for_jetpack_installs( $slug );

			$errors->add(
				$plugin,
				sprintf(
					/* translators: %s: plugin slug (example: woocommerce-services) */
					__( 'The requested plugin `%s` could not be installed. Plugin API call failed.', 'woocommerce' ),
					$slug
				)
			);

			continue;
		}

		$upgrader           = new \Plugin_Upgrader( new \Automatic_Upgrader_Skin() );
		$result             = $upgrader->install( $api->download_link );
		$results[ $plugin ] = $result;

		if ( is_wp_error( $result ) || is_null( $result ) ) {
			$properties = array(
				/* translators: %s: plugin slug (example: woocommerce-services) */
				'error_message' => __( 'The requested plugin `%s` could not be installed.', 'woocommerce' ),
				'slug'          => $slug,
				'api'           => $api,
				'upgrader'      => $upgrader,
				'result'        => $result,
			);
			wc_admin_record_tracks_event( 'install_plugin_error', $properties );

			$this->create_install_plugin_error_inbox_notification_for_jetpack_installs( $slug );

			$errors->add(
				$plugin,
				sprintf(
					/* translators: %s: plugin slug (example: woocommerce-services) */
					__( 'The requested plugin `%s` could not be installed. Upgrader install failed.', 'woocommerce' ),
					$slug
				)
			);
			continue;
		}

		$installed_plugins[] = $plugin;
	}

	return array(
		'data'    => array(
			'installed' => $installed_plugins,
			'results'   => $results,
		),
		'errors'  => $errors,
		'success' => count( $errors->errors ) === 0,
		'message' => count( $errors->errors ) === 0
			? __( 'Plugins were successfully installed.', 'woocommerce' )
			: __( 'There was a problem installing some of the requested plugins.', 'woocommerce' ),
	);
}