下面是我的插件。将安装到wp-content
<?php // If this file is called directly, abort.
namespace Booker;
if ( ! defined( \'WPINC\' ) ) {
die;
}
/**
* Currently plugin version.
* Start at version 1.0.0 and use SemVer - https://semver.org
* Rename this for your plugin and update it as you release new versions.
*/
define( \'PLUGIN_NAME_VERSION\', \'1.0.0\' );
/**
* The code that runs during plugin activation.
* This action is documented in includes/class-booker-activator.php
*/
function activate_booker() {
require_once plugin_dir_path(__FILE__) . \'includes/class-booker-activator.php\';
error_log("Running Activation");
Booker_Activator::activate();
}
/**
* The code that runs during plugin deactivation.
* This action is documented in includes/class-booker-deactivator.php
*/
function deactivate_booker() {
require_once plugin_dir_path(__FILE__) . \'includes/class-booker-deactivator.php\';
error_log("Running Deactivation");
Booker_Deactivator::deactivate();
}
register_activation_hook( __FILE__, \'activate_booker\');
register_deactivation_hook( __FILE__, \'deactivate_booker\');
?>
它当然不会执行,但插件会按预期停用和激活。目前,这些函数中定义的函数调用中没有代码。。。。但缺少日志消息表明没有执行。然而,我遇到了一个问题:该插件在激活期间生成了2368个字符的意外输出。如果您注意到“headers ready sent”消息、联合提要问题或其他问题,请尝试停用或删除此插件。
在我的日志中,我得到:
[08-Oct-2019 23:51:20 UTC] PHP Warning: call_user_func_array() expects parameter 1 to be a valid callback, function \'activate_booker\' not found or invalid function name in G:\\wamp64\\www\\wordpress\\wp-includes\\class-wp-hook.php on line 286
[08-Oct-2019 23:51:20 UTC] PHP Stack trace:
[08-Oct-2019 23:51:20 UTC] PHP 1. {main}() G:\\wamp64\\www\\wordpress\\wp-admin\\plugins.php:0
[08-Oct-2019 23:51:20 UTC] PHP 2. activate_plugin() G:\\wamp64\\www\\wordpress\\wp-admin\\plugins.php:44
[08-Oct-2019 23:51:20 UTC] PHP 3. do_action() G:\\wamp64\\www\\wordpress\\wp-admin\\includes\\plugin.php:672
[08-Oct-2019 23:51:20 UTC] PHP 4. WP_Hook->do_action() G:\\wamp64\\www\\wordpress\\wp-includes\\plugin.php:465
[08-Oct-2019 23:51:20 UTC] PHP 5. WP_Hook->apply_filters() G:\\wamp64\\www\\wordpress\\wp-includes\\class-wp-hook.php:310
还有[09-Oct-2019 00:44:43 UTC] PHP Warning: call_user_func_array() expects parameter 1 to be a valid callback, function \'deactivate_booker\' not found or invalid function name in G:\\wamp64\\www\\wordpress\\wp-includes\\class-wp-hook.php on line 286
[09-Oct-2019 00:44:43 UTC] PHP Stack trace:
[09-Oct-2019 00:44:43 UTC] PHP 1. {main}() G:\\wamp64\\www\\wordpress\\wp-admin\\plugins.php:0
[09-Oct-2019 00:44:43 UTC] PHP 2. deactivate_plugins($plugins = *uninitialized*, $silent = *uninitialized*, $network_wide = *uninitialized*) G:\\wamp64\\www\\wordpress\\wp-admin\\plugins.php:192
[09-Oct-2019 00:44:43 UTC] PHP 3. do_action($tag = *uninitialized*, $arg = *uninitialized*) G:\\wamp64\\www\\wordpress\\wp-admin\\includes\\plugin.php:792
[09-Oct-2019 00:44:43 UTC] PHP 4. WP_Hook->do_action($args = *uninitialized*) G:\\wamp64\\www\\wordpress\\wp-includes\\plugin.php:465
[09-Oct-2019 00:44:43 UTC] PHP 5. WP_Hook->apply_filters($value = *uninitialized*, $args = *uninitialized*) G:\\wamp64\\www\\wordpress\\wp-includes\\class-wp-hook.php:310
更改函数名称时出现其他错误:[09-Oct-2019 02:08:03 UTC] PHP Warning: call_user_func_array() expects parameter 1 to be a valid callback, function \'booker_deactivate\' not found or invalid function name in G:\\wamp64\\www\\wordpress\\wp-includes\\class-wp-hook.php on line 286
[09-Oct-2019 02:08:03 UTC] PHP Stack trace:
[09-Oct-2019 02:08:03 UTC] PHP 1. {main}() G:\\wamp64\\www\\wordpress\\wp-admin\\plugins.php:0
[09-Oct-2019 02:08:03 UTC] PHP 2. deactivate_plugins() G:\\wamp64\\www\\wordpress\\wp-admin\\plugins.php:192
[09-Oct-2019 02:08:03 UTC] PHP 3. do_action() G:\\wamp64\\www\\wordpress\\wp-admin\\includes\\plugin.php:792
[09-Oct-2019 02:08:03 UTC] PHP 4. WP_Hook->do_action() G:\\wamp64\\www\\wordpress\\wp-includes\\plugin.php:465
[09-Oct-2019 02:08:03 UTC] PHP 5. WP_Hook->apply_filters() G:\\wamp64\\www\\wordpress\\wp-includes\\class-wp-hook.php:310