Title: Need Help on plugin Dev
Last modified: August 19, 2016

---

# Need Help on plugin Dev

 *  [awls99](https://wordpress.org/support/users/awls99/)
 * (@awls99)
 * [15 years, 10 months ago](https://wordpress.org/support/topic/need-help-on-plugin-dev/)
 * Hi there,
    I’m trying to write a simple plugin for wordpress, I’ve followed instructions
   here: [http://codex.wordpress.org/Creating_Tables_with_Plugins](http://codex.wordpress.org/Creating_Tables_with_Plugins)
   because I needed two new tables for my plugin. Here’s the sample code:
 *     ```
       function wat_install ()
       {
       	$table1 = $wpdb->prefix.'wat_ads';
       	$table2 = $wpdb->prefix.'wat_clicks';
   
       	if($wpdb->get_var("show tables like '$table1'") != $table1) {
       		$sql1="CREATE TABLE <code>$table1</code> (
       			  <code>id</code> INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
       			  <code>html</code> TEXT DEFAULT ' ',
       			  PRIMARY KEY (<code>id</code>)
       			)
       			ENGINE = MyISAM;
       		";
   
       	}
       	if($wpdb->get_var("show tables like '$table2'") != $table2) {
       		$sql2="CREATE TABLE <code>$table2</code> (
       			  <code>id</code> INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
       			  <code>html</code> TEXT DEFAULT ' ',
       			  PRIMARY KEY (<code>id</code>)
       			)
       			ENGINE = MyISAM;
       		";
   
       	}
       	$wpdb->query($sql1);
       	$wpdb->query($sql2);
       }
       register_activation_hook(__FILE__,'wat_install');
       ```
   
 * When I try to activate the plugin I get:
 * > Plugin could not be activated because it triggered a fatal error.
   >  Fatal error:
   > Cannot redeclare wat_install() (previously declared in C:\*****\wp-content\
   > plugins\wp-ad-tracking\wp-ad-tracking.php:14) in C:\*****\wp-content\plugins\
   > wp-ad-tracking\wp-ad-tracking.php on line 39
 * Even though I get that error the plugin still shows up as activated on the plugin
   list, if I comment out “register_activation_hook(__FILE__,’wat_install’);” no
   error will be produced, but I won’t get my fancy tables.
    Note: Line 14 is the
   first line inside the function that has some code while line 39 is the line here
   the end function bracket (}) is
 * I’ve tried several things and a lot of googling, but I’m lost, can anyone give
   me a hand?

Viewing 4 replies - 1 through 4 (of 4 total)

 *  [stephane02](https://wordpress.org/support/users/stephane02/)
 * (@stephane02)
 * [15 years, 10 months ago](https://wordpress.org/support/topic/need-help-on-plugin-dev/#post-1593095)
 * Well, fix the error first, then ftp connect to wordpress plugin folder, remove
   your plugin files, try uploading the plugin again and test it.
 *  Thread Starter [awls99](https://wordpress.org/support/users/awls99/)
 * (@awls99)
 * [15 years, 10 months ago](https://wordpress.org/support/topic/need-help-on-plugin-dev/#post-1593112)
 * I’m trying to figure out what’s the error 🙁
    (and it’s on local machine)
 *  Thread Starter [awls99](https://wordpress.org/support/users/awls99/)
 * (@awls99)
 * [15 years, 10 months ago](https://wordpress.org/support/topic/need-help-on-plugin-dev/#post-1593185)
 * I need to get this plugin working soon, so I made a small workaround, not preatty,
   but works like a charm:
 * on the install function added (right before the end): `add_option('wat_installed',
   true, '', 'no');`
    and used that option to make sure it runs the first time:
 *     ```
       //register_activation_hook(__FILE__,'wat_install');
       if(!get_option('wat_installed'))wat_install();
       add_action('admin_menu', 'wat_admin_options');
       ```
   
 *  Thread Starter [awls99](https://wordpress.org/support/users/awls99/)
 * (@awls99)
 * [15 years, 10 months ago](https://wordpress.org/support/topic/need-help-on-plugin-dev/#post-1593401)
 * bump
    Could really use some help on this I got this plugin working for my own
   use but I’d like to share it and the way it is now is just not elegant

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Need Help on plugin Dev’ is closed to new replies.

## Tags

 * [development](https://wordpress.org/support/topic-tag/development/)
 * [plugin activation](https://wordpress.org/support/topic-tag/plugin-activation/)
 * [register_activation_hook](https://wordpress.org/support/topic-tag/register_activation_hook/)
 * [workaround](https://wordpress.org/support/topic-tag/workaround/)

 * 4 replies
 * 2 participants
 * Last reply from: [awls99](https://wordpress.org/support/users/awls99/)
 * Last activity: [15 years, 10 months ago](https://wordpress.org/support/topic/need-help-on-plugin-dev/#post-1593401)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
