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; }
\u6fc0\u6d3b\u591a\u4e2a\u63d2\u4ef6\u3002
\u5f53WP_Error\u8fd4\u56de\uff0c\u4f46\u8fd9\u5e76\u4e0d\u610f\u5473\u7740\u8be5\u63d2\u4ef6\u7684\u4e00\u4e2a\u6709\u9519\u8bef\u3002\u8fd9\u610f\u5473\u7740\u4e00\u4e2a\u6216\u591a\u2026","thumb":"https:\/\/demo.salongweb.com\/mnews\/images\/default-thumb.jpg","date":{"day":"03","year":"2019\/04"},"desc":"WordPress\u4e3b\u9898|WordPress \u4f01\u4e1a\u4e3b\u9898|WordPress \u5546\u57ce\u4e3b\u9898|\u9ad8\u54c1\u8d28\u7f51\u7ad9\u5b9a\u5236","style":{"light":{"logo":"https:\/\/pic.salongweb.com\/2022\/12\/logo-light.png","title":"#242F40","text":"#5B6B82","meta":"#9AA7B9","border":"#EFF5FF","bg":"#fff"},"dark":{"logo":"https:\/\/pic.salongweb.com\/2022\/12\/logo-dark.png","title":"#B1C1E8","text":"#b3bdd3","meta":"#565E75","border":"#1C2032","bg":"#171B2C"}}} :loading="posterLoading">