activate_plugins

The timeline below displays how wordpress function activate_plugins has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 6.4

/**
 * Activates multiple plugins.
 *
 * When WP_Error is returned, it does not mean that one of the plugins had
 * errors. It means that one or more of the plugin file paths were invalid.
 *
 * The execution will be halted as soon as one of the plugins has an error.
 *
 * @since 2.6.0
 *
 * @param string|string[] $plugins      Single plugin or list of plugins to activate.
 * @param string          $redirect     Redirect to page after successful activation.
 * @param bool            $network_wide Whether to enable the plugin for all sites in the network.
 *                                      Default false.
 * @param bool            $silent       Prevent calling activation hooks. Default false.
 * @return true|WP_Error True when finished or WP_Error if there were errors during a plugin activation.
 */
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_wp_error($result)) {
            $errors[$plugin] = $result;
        }
    }
    if (!empty($errors)) {
        return new WP_Error('plugins_invalid', __('One of the plugins is invalid.'), $errors);
    }
    return true;
}

WordPress Version: 6.1

/**
 * Activates multiple plugins.
 *
 * When WP_Error is returned, it does not mean that one of the plugins had
 * errors. It means that one or more of the plugin file paths were invalid.
 *
 * The execution will be halted as soon as one of the plugins has an error.
 *
 * @since 2.6.0
 *
 * @param string|string[] $plugins      Single plugin or list of plugins to activate.
 * @param string          $redirect     Redirect to page after successful activation.
 * @param bool            $network_wide Whether to enable the plugin for all sites in the network.
 *                                      Default false.
 * @param bool            $silent       Prevent calling activation hooks. Default false.
 * @return bool|WP_Error True when finished or WP_Error if there were errors during a plugin activation.
 */
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_wp_error($result)) {
            $errors[$plugin] = $result;
        }
    }
    if (!empty($errors)) {
        return new WP_Error('plugins_invalid', __('One of the plugins is invalid.'), $errors);
    }
    return true;
}

WordPress Version: 5.5

/**
 * Activate multiple plugins.
 *
 * When WP_Error is returned, it does not mean that one of the plugins had
 * errors. It means that one or more of the plugin file paths were invalid.
 *
 * The execution will be halted as soon as one of the plugins has an error.
 *
 * @since 2.6.0
 *
 * @param string|string[] $plugins      Single plugin or list of plugins to activate.
 * @param string          $redirect     Redirect to page after successful activation.
 * @param bool            $network_wide Whether to enable the plugin for all sites in the network.
 *                                      Default false.
 * @param bool            $silent       Prevent calling activation hooks. Default false.
 * @return bool|WP_Error True when finished or WP_Error if there were errors during a plugin activation.
 */
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_wp_error($result)) {
            $errors[$plugin] = $result;
        }
    }
    if (!empty($errors)) {
        return new WP_Error('plugins_invalid', __('One of the plugins is invalid.'), $errors);
    }
    return true;
}

WordPress Version: 5.4

/**
 * Activate multiple plugins.
 *
 * When WP_Error is returned, it does not mean that one of the plugins had
 * errors. It means that one or more of the plugin file paths were invalid.
 *
 * The execution will be halted as soon as one of the plugins has an error.
 *
 * @since 2.6.0
 *
 * @param string|string[] $plugins      Single plugin or list of plugins to activate.
 * @param string          $redirect     Redirect to page after successful activation.
 * @param bool            $network_wide Whether to enable the plugin for all sites in the network.
 *                                      Default false.
 * @param bool $silent                  Prevent calling activation hooks. Default false.
 * @return bool|WP_Error True when finished or WP_Error if there were errors during a plugin activation.
 */
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_wp_error($result)) {
            $errors[$plugin] = $result;
        }
    }
    if (!empty($errors)) {
        return new WP_Error('plugins_invalid', __('One of the plugins is invalid.'), $errors);
    }
    return true;
}

WordPress Version: 4.0

/**
 * Activate multiple plugins.
 *
 * When WP_Error is returned, it does not mean that one of the plugins had
 * errors. It means that one or more of the plugins file path was invalid.
 *
 * The execution will be halted as soon as one of the plugins has an error.
 *
 * @since 2.6.0
 *
 * @param string|array $plugins Single plugin or list of plugins to activate.
 * @param string $redirect Redirect to page after successful activation.
 * @param bool $network_wide Whether to enable the plugin for all sites in the network.
 * @param bool $silent Prevent calling activation hooks. Default is false.
 * @return bool|WP_Error True when finished or WP_Error if there were errors during a plugin activation.
 */
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_wp_error($result)) {
            $errors[$plugin] = $result;
        }
    }
    if (!empty($errors)) {
        return new WP_Error('plugins_invalid', __('One of the plugins is invalid.'), $errors);
    }
    return true;
}

WordPress Version: 3.7

/**
 * Activate multiple plugins.
 *
 * When WP_Error is returned, it does not mean that one of the plugins had
 * errors. It means that one or more of the plugins file path was invalid.
 *
 * The execution will be halted as soon as one of the plugins has an error.
 *
 * @since 2.6.0
 *
 * @param string|array $plugins
 * @param string $redirect Redirect to page after successful activation.
 * @param bool $network_wide Whether to enable the plugin for all sites in the network.
 * @param bool $silent Prevent calling activation hooks. Default is false.
 * @return bool|WP_Error True when finished or WP_Error if there were errors during a plugin activation.
 */
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_wp_error($result)) {
            $errors[$plugin] = $result;
        }
    }
    if (!empty($errors)) {
        return new WP_Error('plugins_invalid', __('One of the plugins is invalid.'), $errors);
    }
    return true;
}