activate_plugins()

最后更新于:2021-11-25 19:07:20

activate_plugins( string|string[]$plugins, string$redirect=”, bool$network_wide=false, bool$silent=false)

Activate multiple plugins.

参数

$plugins

(string|string[]) (Required) Single plugin or list of plugins to activate.

$redirect

(string) (Optional) Redirect to page after successful activation.

Default value: ”

$network_wide

(bool) (Optional) Whether to enable the plugin for all sites in the network.

Default value: false

$silent

(bool) (Optional) Prevent calling activation hooks.

Default value: false

响应

(bool|GC_Error) True when finished or GC_Error if there were errors during a plugin activation.

源文件

文件: gc-admin/includes/plugin.php

function activate_plugins( $plugins, $redirect = '', $network_wide = false, $silent = false ) {
	if ( ! is_array( $plugins ) ) {
		$plugins = array( $plugins );
	}

	$errors = array();
	foreach ( $plugins as $plugin ) {
		if ( ! empty( $redirect ) ) {
			$redirect = add_query_arg( 'plugin', $plugin, $redirect );
		}
		$result = activate_plugin( $plugin, $redirect, $network_wide, $silent );
		if ( is_gc_error( $result ) ) {
			$errors[ $plugin ] = $result;
		}
	}

	if ( ! empty( $errors ) ) {
		return new GC_Error( 'plugins_invalid', __( 'One of the plugins is invalid.' ), $errors );
	}

	return true;
}