Cannot run the code after I activate the plugin

I wrote a plugin to write code into the wp-config.php – it should download a code file and add it to my wp-content. But I only can run the function manually. I want the plugin to run the function when I activate it. Here is my code: function test_write() { $file=””; $newfile=”../../advanced-cache.php”; copy($file,$newfile); $file = … Read more

Correct way to use register_activation_hook

Hi I am developing a plugin and got stuck at one point. I have tried exploring different forums as well as WordPress codex but its not 100% clear. Can anyone help me understand how register_activation_hook actually works. I have the following code that does not work: register_activation_hook(__FILE__, ‘plugin_activation_fn’ ); function plugin_activation_fn(){ define(‘PLUGIN_DIR’, plugin_dir_path( __FILE__ )); … Read more

The plugin generated x characters of unexpected output, $wpdb not defined

I’ve written a simple WordPress plugin to create a new database table. The new table ought to be created when the plugin is activated. When I try to activate the plugin, I get the following error: The plugin generated 3989 characters of unexpected output during activation. If you notice “headers already sent” messages, problems with … Read more

WordPress register_activation_hook table creation not working

I’ve created a simple Class for my wordpress plugin. The main file looks like this: <?php /* * Plugin Name: Codes * Description: Generates a coupon code after checkout * Version: 0.1.0 * Author: XXX */ require_once(‘inc/DatabaseUtils.php’); $codes = new Codes(); class Codes { private $databaseUtils; /** * Create a new instance * * @param … Read more

Plugin activation error due to unexpected output

I am getting the following error when I activate my plugin: The plugin generated 22 characters of unexpected output during activation. If you notice “headers already sent” messages, problems with syndication feeds or other issues, try deactivating or removing this plugin. And here’s my plugin code: <?php /* Plugin Name: Hello World */ echo “<h1>Hello, … Read more

Override pluggable functions in a plugin?

WordPress has a file called pluggable.php which contains a list of functions you can override in your plugin. The problem I am facing (I am overriding wp_authenticate) is for each blog in my network I try to activate this plugin, I get: failure, can’t re-declare wp_authenticate which was previously declared in pluggable.php This somewhat defeats … Read more