skip to Main Content

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


  1. 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 just echo.

    Relevant part of docs

    Login or Signup to reply.
  2. 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:

    <?php
    /**
    Plugin Name: test tickles
    */
    
    echo('Testing @ ' . date('Y-m-d H:i:s') . ' ' . __FILE__ . "<br>");
    echo('WP_PLUGIN_DIR = ' . WP_PLUGIN_DIR . "<br>");
    echo('plugin base name = ' . plugin_basename(__FILE__) . "<br>");
    
    register_activation_hook(__FILE__, function() {
    echo "poo";
    });
    ?>
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search