Title: Plugin development, install
Last modified: August 19, 2016

---

# Plugin development, install

 *  [ckruse](https://wordpress.org/support/users/ckruse/)
 * (@ckruse)
 * [16 years, 9 months ago](https://wordpress.org/support/topic/plugin-development-install/)
 * I am attempting to create my own plugin, and am running into a fatal error when
   I attempt to activate it. I cannot figure out why. As of now, the only thing 
   the plugin does is create a new DB table at activation. Here is the code
 *     ```
       $rbVersion = "1.0";
   
       //install DB tables
       function rb_install() {
       	global $wpdb;
   
       	//first check to see if the DB table already exists
       	$tableName = $wpdb->prefix . "rusty_beard";
   
       	if($wpdb->getvar("SHOW TABLES LIKE '" . $tableName . "'") != $tableName) {
       		//create DB tables
       		$install = "CREATE TABLE " . $tableName . "(
       				field_id  KEY INT NOT NULL AUTO_INCREMENT,
       				field_name VARCHAR(50),
       				field_type VARCHAR(50),
       				field_default VARCHAR(240),
       				field_required INT,
       				field_label VARCHAR(240)
       				field_order INT)";
   
       		require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
   
       		dbDelta($install);
   
       		//add version to DB
       		add_option("rb_version", $rbVersion);
   
       	}
       }
   
       //install the plugin
       register_activation_hook(__FILE__, 'rb_install');
       ```
   
 * This is all located in the main plugin file, the only plugin file I have.
 * When I attempt to activate it, WP gives the following error:
 *     ```
       Plugin could not be activated because it triggered a fatal error.
   
       Fatal error: Cannot redeclare rb_install() (previously declared in /home/dir/public_html/dir/wp-content/plugins/RustyBeard/rusty_beard.php:21) in /home/dir/public_html/dir/wp-content/plugins/RustyBeard/rusty_beard.php on line 45
       ```
   

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

 *  [gale-andrews](https://wordpress.org/support/users/gale-andrews/)
 * (@gale-andrews)
 * [16 years, 8 months ago](https://wordpress.org/support/topic/plugin-development-install/#post-1184789)
 * I am having the same problem. I see you have other threads about register_activation_hook.
   Did you get it resolved?
 *  [allgood](https://wordpress.org/support/users/allgood/)
 * (@allgood)
 * [16 years, 4 months ago](https://wordpress.org/support/topic/plugin-development-install/#post-1184832)
 * You need to wrap the above code with the following if statement…
 *     ```
       if(!function_exists("rb_install")){
           function rb_install() {
       	global $wpdb;
   
       	//first check to see if the DB table already exists
       	$tableName = $wpdb->prefix . "rusty_beard";
   
       	if($wpdb->getvar("SHOW TABLES LIKE '" . $tableName . "'") != $tableName) {
       		//create DB tables
       		$install = "CREATE TABLE " . $tableName . "(
       				field_id  KEY INT NOT NULL AUTO_INCREMENT,
       				field_name VARCHAR(50),
       				field_type VARCHAR(50),
       				field_default VARCHAR(240),
       				field_required INT,
       				field_label VARCHAR(240)
       				field_order INT)";
   
       		require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
   
       		dbDelta($install);
   
       		//add version to DB
       		add_option("rb_version", $rbVersion);
   
       	}
           }
   
           //install the plugin
           register_activation_hook(__FILE__, 'rb_install');
       }
       ```
   

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

The topic ‘Plugin development, install’ is closed to new replies.

## Tags

 * [develop](https://wordpress.org/support/topic-tag/develop/)
 * [register_activation_hook](https://wordpress.org/support/topic-tag/register_activation_hook/)

 * 2 replies
 * 3 participants
 * Last reply from: [allgood](https://wordpress.org/support/users/allgood/)
 * Last activity: [16 years, 4 months ago](https://wordpress.org/support/topic/plugin-development-install/#post-1184832)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
