IM目前正在构建我的自定义插件,它将与woocommerce和ACF有依赖关系。因为我可以复制粘贴代码并且它可以正常工作,因为它试图以它应该的方式实现TGM ...插件正在激活而不检查依赖项。
关于谁在哪里以及希望有人可以帮助我的信息很少。
我的激活功能:
function activate_cat_and_prod_importer() {
require_once plugin_dir_path( __FILE__ ) . 'includes/class-cat-and-prod-importer-activator.php';
$activator = new Cat_And_Prod_Importer_Activator();
$activator->activate(); }
register_activation_hook( __FILE__, 'activate_cat_and_prod_importer' );
关于激活:
public function activate() {
add_action( 'init', array( 'tgmpa_register', 'cat_prod_sync_register_required_plugins' ) );
}
/**
* Register the required plugins for this plugin.
*/
public function cat_prod_sync_register_required_plugins() {
/*
* Array of plugin arrays. Required keys are name and slug.
* If the source is NOT from the .org repo, then source is also required.
*/
$plugins = array(
// This is an example of how to include a plugin from the WordPress Plugin Repository.
array(
'name' => 'Advanced Custom Fields',
'slug' => 'advanced-custom-fields',
'required' => true,
),
array(
'name' => 'Woocommerce',
'slug' => 'woocommerce',
'required' => true,
)
);
/*
* Array of configuration settings. Amend each line as needed.
*
*/
$config = array(
'id' => 'cat-prod-sync', // Unique ID for hashing notices for multiple instances of TGMPA.
'default_path' => '', // Default absolute path to bundled plugins.
'menu' => 'tgmpa-install-plugins', // Menu slug.
'parent_slug' => 'plugins.php', // Parent menu slug.
'capability' => 'manage_options', // Capability needed to view plugin install page, should be a capability associated with the parent menu used.
'has_notices' => true, // Show admin notices or not.
'dismissable' => false, // If false, a user cannot dismiss the nag message.
'dismiss_msg' => '', // If 'dismissable' is false, this message will be output at top of nag.
'is_automatic' => true, // Automatically activate plugins after installation or not.
'message' => '', // Message to output right before the plugins table.
);
tgmpa( $plugins, $config );
}
通过load dependencies方法加载tgm所需的类。
我现在可以根据需要激活和停用我的插件......没有触发任何内容而且没有错误。