plugin_sandbox_scrape()
云策文档标注
概述
plugin_sandbox_scrape() 是一个 WordPress 函数,用于在沙盒环境中加载指定插件以尝试生成错误,主要用于插件激活前的错误检测。
关键要点
- 函数接受一个必需参数 $plugin,表示相对于 plugins 目录的插件文件路径。
- 在函数内部,如果未定义 WP_SANDBOX_SCRAPING,会将其定义为 true,以启用沙盒模式。
- 通过 wp_register_plugin_realpath() 注册插件的真实路径,然后使用 include_once 加载插件文件。
- 该函数主要用于 resume_plugin() 和 activate_plugin() 等函数中,以安全地测试插件激活。
- 自 WordPress 4.4.0 起,函数被移至 wp-admin/includes/plugin.php 文件中。
代码示例
function plugin_sandbox_scrape( $plugin ) {
if ( ! defined( 'WP_SANDBOX_SCRAPING' ) ) {
define( 'WP_SANDBOX_SCRAPING', true );
}
wp_register_plugin_realpath( WP_PLUGIN_DIR . '/' . $plugin );
include_once WP_PLUGIN_DIR . '/' . $plugin;
}
原文内容
Loads a given plugin attempt to generate errors.
Parameters
$pluginstringrequired-
Path to the plugin file relative to the plugins directory.
Source
function plugin_sandbox_scrape( $plugin ) {
if ( ! defined( 'WP_SANDBOX_SCRAPING' ) ) {
define( 'WP_SANDBOX_SCRAPING', true );
}
wp_register_plugin_realpath( WP_PLUGIN_DIR . '/' . $plugin );
include_once WP_PLUGIN_DIR . '/' . $plugin;
}