Hiya I am trying to create a plugin in wordpress.
The aim is it will create a table in the database, however even by just adding an echo inside the hook it seems that this does not get triggered.
wp version 6.11, mysql 8.0.16, php 8.1.9
Folder structure is
wp-content
|____ plugins
|my_plugin
| index.php
To follow, this is what is inside the index.php,
I’ve tried also an external function, but nothing.
If the echo is outside then I can see it.
Debugging is enabled and no error are thrown.
Any ideas? Thanks
<?php
/**
Plugin Name: test tickles
*/
echo(LOG_ERR. 'Testing @ ' . date('Y-m-d H:i:s') . ' ' . __FILE__ . "<br>");
echo(LOG_ERR.'WP_PLUGIN_DIR = ' . WP_PLUGIN_DIR . "<br>");
echo(LOG_ERR.'plugin base name = ' . plugin_basename(__FILE__) . "<br>");
register_activation_hook(__FILE__, function() {
echo "poo";
});
?>
2
Answers
It won’t run on every page load – in case that’s what you’re expecting. It will only run when the plugin is initially activated – so to test, you will need to deactivate and then re-activate your plugin.
Also, please note that the activation hook does not work with mu-plugins.
The documentation also mentions a redirect – so you may want to try
die('my plugin activated');
instead of justecho
.Relevant part of docs
To see the output of your plugin, remove LOG_ERR from your echo statements.
Your code should look like this, please try this hope it should work: