Redeclaring functions – error on my own plugin
-
Hello there,
After reading a lot about WordPress plugins I thought about creating my own plugin. It’s a very simple plugin, I actually copied and pasted a lot from the WordPress documentation.
When I activate the plugin I get an error:
Fatal error: Cannot redeclare poll_installation() (previously declared in ~\wp-content\plugins\wp_poll_engine\poll_engine.php:31) in ~\wp-content\plugins\wp_poll_engine\poll_engine.php on line 74
I activated and deactivated the plugin several times while testing.
Here is the code:
<?php global $wp_poll_db_version; $wp_poll_db_version = '0.1'; function poll_installation(){ global $wp_poll_db_version; global $wpdb; $table_name = $wpdb->prefix . 'poll_engine'; if($wpdb->get_var("SHOW TABLES LIKE '" . $table_name . "'") != $table_name){ $sql = "CREATE TABLE " . $table_name . " ( id mediumint(9) NOT NULL AUTO_INCREMENT, time bigint(11) DEFAULT '0' NOT NULL, name tinytext NOT NULL, text text NOT NULL, url VARCHAR(55) NOT NULL, UNIQUE KEY id (id) );"; require_once(ABSPATH . 'wp-admin/include/upgrade.php'); dbDelta($sql); $welcome_name = "Admin"; $welcome_text = "Congratulations, you just completed the installation!"; $insert = "INSERT INTO " . $table_name . " (time, name, text) " . "VALUES ('" . time() . "','" . $wpdb->escape($welcome_name) . "','" . $wpdb->escape($welcome_text) . "')"; $results = $wpdb->query( $insert ); add_option('wp_poll_db_version', $wp_poll_db_version); } $installed_ver = get_option( "wp_poll_db_version" ); if( $installed_ver != $wp_poll_db_version ) { $sql = "CREATE TABLE " . $table_name . " ( id mediumint(9) NOT NULL AUTO_INCREMENT, time bigint(11) DEFAULT '0' NOT NULL, name tinytext NOT NULL, text text NOT NULL, url VARCHAR(55) NOT NULL, UNIQUE KEY id (id) );"; require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); dbDelta($sql); update_option( "wp_poll_db_version", $wp_poll_db_version ); } } function wp_poll_menu(){ add_menu_page('WP Poll Engine', 'Poll Settings', 8, 'poll_settings', 'wp_poll_page'); add_submenu_page('poll_settings', 'Subpage for Poll Settings', 'Subpage', 8, 'poll_settings_sub', 'wp_poll_subpage'); } function wp_poll_page() { echo '<h2>Title</h2>'; } function wp_poll_subpage(){ echo '<h2>Subpage</h2>'; } register_activation_hook(__FILE__, 'poll_installation'); add_action('admin_menu', 'wp_poll_menu'); ?>
Is there anyone who can solve the problem?
Viewing 7 replies - 1 through 7 (of 7 total)
Viewing 7 replies - 1 through 7 (of 7 total)
- The topic ‘Redeclaring functions – error on my own plugin’ is closed to new replies.