当我试图激活一个插件,我写的,WordPress的尝试做激活错误的插件,我说我去Plugins->Installed Plugins
和激活,WordPress返回错误消息,'anspress'插件找不到。
我的插件的名称“学院”,文件夹名称“学院”,插件文件名“academy.php”.
academy.php content:
<?php
/**
* @package Academy
*/
/*
Plugin Name: Academy
Description: Academy features
Version: 0.1
Author: Victor Aurélio Santos
Text Domain: academy
*/
/* is_plugin_active */
include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
define ('ACADEMY_INCLUDE', plugin_dir_path( __FILE__ ) . '/include');
define ('ACADEMY_TEMAPLE', ACADEMY_INCLUDE . '/templates');
global $academy_err; $academy_err = array();
$plugin_dependencies = array('woocommerce' => false,
'anspress' => false);
/* Dependencies check */
foreach ($plugin_dependencies as $plugin => &$enabled) {
if (! $enabled = is_plugin_active("{$plugin}/{$plugin}.php") ) {
$academy_err[] = "The {$plugin} plugin isn't installed and/or activated.";
}
}
/* Check current theme, if not 'Academy' don't load files that depends... */
if ( "Academy" == wp_get_theme()->Name ) {
include ACADEMY_INCLUDE . '/buddypress/bp-loader.php';
include ACADEMY_INCLUDE . '/news-feed.php';
} else {
$academy_err[] = "Current theme isn't \"Academy\" not loading NewsFeed...";
}
/* Check for woocommerce */
if ( $plugin_dependencies['woocommerce'] && $plugin_dependencies['anspress'] ){
include ACADEMY_INCLUDE . '/anspress-woocommerce.php';
}
include (ACADEMY_INCLUDE . '/settings.php');
function academy_admin_notices() {
global $academy_err;
foreach ($academy_err as $err) {
?>
<div class="update-nag">
<p>Academy Error: <?php echo $err; ?></p>
</div>
<?php
}
}
add_action('admin_notices', 'academy_admin_notices');
function academy_init() {
$plugin_dir = basename(dirname(__FILE__)) . '/languages';
load_plugin_textdomain( 'academy', false, $plugin_dir );
}
add_action('plugins_loaded', 'academy_init');
function academy_plugin_action_links ($links, $file) {
static $this_plugin;
if (!$this_plugin) {
$this_plugin = plugin_basename(__FILE__);
}
if ($file == $this_plugin) {
$settings_link = '<a href="' . get_bloginfo('wpurl') . '/wp-admin/admin.php? page=academy-settings">' . __('Settings', 'academy') . '</a>';
array_unshift($links, $settings_link);
}
return $links;
}
add_filter('plugin_action_links', 'academy_plugin_action_links', 10, 2);
字符串
我认为这是我的插件有问题,但找不到什么.
2条答案
按热度按时间c90pui9n1#
在插件的基础上,我们应该不惜一切代价避免直接调用WordPress函数。最好的做法是将所有内容封装在相关的钩子中。
函数
get_option
使用起来是安全的,我们用它来处理include
s。对于其余部分,我们使用
register_activation_hook
来获取激活时的活动插件。要检查所需插件的激活/停用,我们可以使用hookactivate_$pluginName
和deactivate_$pluginName
。主题状态更改可以使用hookafter_switch_theme
捕获。字符串
define
s和global
s*,here's a nice plugin base。zhte4eai2#
你的插件依赖于另一个名为'anspress'的插件,这就是为什么你会得到这个错误。这段代码是问题的根源:
字符串
要么添加插件'anspress',它被标记为依赖项,要么将其从该数组中删除。