WordPress 功能函数—— activate_plugins(激活多个插件)

描述

激活多个插件。

当WP_Error返回,但这并不意味着该插件的一个有错误。这意味着一个或多个插件文件路径无效。

只要其中一个插件出错,执行就会暂停。

用法

activate_plugins( string|array $plugins, string $redirect = '',bool $network_wide = false, bool $silent = false )

参数

$plugin

(string|array) (必需) 单个插件或要激活的插件列表。

$redirect

(string) (可选) 成功激活后重定向到页面。

默认值: ''

$network_wide

(bool) (可选) 是否为网络中的所有站点启用插件。

默认值:false

$silent

(bool) (可选) 阻止调用激活挂钩。默认值为false。

默认值:false

返回

(bool|WP_Error)完成后为True; 如果插件激活期间出现错误,则为WP_Error。

来源

文件:wp-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_wp_error( $result ) ) {
            $errors[ $plugin ] = $result;
        }
    }
 
    if ( ! empty( $errors ) ) {
        return new WP_Error( 'plugins_invalid', __( 'One of the plugins is invalid.' ), $errors );
    }
 
    return true;
}
本文原创,作者:萨龙龙,其版权均为萨龙网络所有。
如需转载,请注明出处:https://salongweb.com/wordpress-functions-activate-plugins.html