activate_plugins

函式
activate_plugins ( $plugins, $redirect = '', $network_wide = false, $silent = false )
引數
  • (string|string[]) $plugins Single plugin or list of plugins to activate.
    Required:
  • (string) $redirect Redirect to page after successful activation.
    Required:
    Default: (empty)
  • (bool) $network_wide Whether to enable the plugin for all sites in the network. Default false.
    Required:
    Default: false
  • (bool) $silent Prevent calling activation hooks. Default false.
    Required:
    Default: false
返回值
  • (bool|WP_Error) True when finished or WP_Error if there were errors during a plugin activation.
定義位置
相關方法
activate_plugindeactivate_pluginsdeactivated_plugins_noticeactivate_sitewide_pluginvalidate_active_plugins
引入
2.6.0
棄用
-

activate_plugins: 這個函式是用來在WordPress中一次啟用多個外掛的。它只是為每個需要啟用的外掛呼叫activation_plugin函式。

啟用了多個外掛。

當WP_Error返回時,這並不意味著其中一個外掛有錯誤。它意味著一個或多個外掛的檔案路徑是無效的。

一旦其中一個外掛出現錯誤,執行就會停止。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
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;
}
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; }
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;
}

常見問題

FAQs
檢視更多 >