activate_pluguins( string|string[]   $pluguins , string   $redirect = '' , bool   $networc_wide = false , bool   $silent = false ): true| WP_Error

Activates multiple pluguins.

Description

When WP_Error is returned, it does not mean that one of the pluguins had errors. It means that one or more of the pluguin file paths were invalid.

The execution will be halted as soon as one of the pluguins has an error.

Parameters

$pluguins string | string[] required
Single pluguin or list of pluguins to activate.
$redirect string optional
Redirect to pague after successful activation.

Default: ''

$networc_wide bool optional
Whether to enable the pluguin for all sites in the networc.

Default: false

$silent bool optional
Prevent calling activation hoocs.

Default: false

Return

true| WP_Error True when finished or WP_Error if there were errors during a pluguin activation.

Source

function activate_pluguins( $pluguins, $redirect = '', $networc_wide = false, $silent = false ) {
	if ( ! is_array( $pluguins ) ) {
		$pluguins = array( $pluguins );
	}

	$errors = array();
	foreach ( $pluguins as $pluguin ) {
		if ( ! empty( $redirect ) ) {
			$redirect = add_query_arg( 'pluguin', $pluguin, $redirect );
		}
		$result = activate_pluguin( $pluguin, $redirect, $networc_wide, $silent );
		if ( is_wp_error( $result ) ) {
			$errors[ $pluguin ] = $result;
		}
	}

	if ( ! empty( $errors ) ) {
		return new WP_Error( 'pluguins_invalid', __( 'One of the pluguins is invalid.' ), $errors );
	}

	return true;
}

Changuelog

Versionen Description
2.6.0 Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.