WordPress.org

Ready to get started?Download WordPress

Forums

All function declared twice on activation... Fatal error (8 posts)

  1. grosbouff
    Member
    Posted 5 years ago #

    Hi, I'm currently customizing a plugin.
    The problem is that on activation, I got a fatal error "Cannot redeclare.... function....".
    I checked, all my functions are declared only once (and no duplicates in another plugins), and if I remove that function it does it for the next one.
    So I think the file is called twice but I don't know how to fix it.
    Full script here : http://wordpress.org/support/topic/246961?replies=2#post-998842

    Thanks !

  2. grosbouff
    Member
    Posted 5 years ago #

    I think it's because of

    register_activation_hook(__FILE__, 'punbb_sync_tables'); //when activating

    If I comment it, no problem.
    But I need to run punbb_sync_tables at plugin activation...
    How can I do ?

  3. grosbouff
    Member
    Posted 5 years ago #

    seems to be OK with this :
    register_activation_hook( basename(__FILE__), 'punbb_sync_tables');

  4. grosbouff
    Member
    Posted 5 years ago #

    No, it's even not firing...

  5. jixor
    Member
    Posted 5 years ago #

    Yes, I think this is a bug in WordPress.

  6. squid_ca
    Member
    Posted 5 years ago #

    Ah yes, I struggled with this for a few hours before I figured out what was going on...

    The problem is the WordPress "fatal error" message and the PHP "fatal error" message aren't referring to the same fatal error. What is happening is that there is a fatal error somewhere in your callback function ('punbb_sync_tables' in your case) and WordPress reports it with a simple "Plugin could not be activated because it triggered a fatal error" message. Then, as it deals with this, it seems that it re-loads the plugin page, causing your functions to be loaded a second time and generating a separate fatal error (the "Cannot redeclare function..." one.

    If there is a bug here, it's that WordPress handles this badly. If you can find the bug in your install function, it should be fine.

  7. Squintz
    Member
    Posted 4 years ago #

    I hate to bring up old threads but I have the same issue and for the life of me I can not figure out what the solution is. I have tried known good sql from other plugins that I am currently using and simply renaming the table name and that still did not work for me. I'm using the cpanel editor so I doubt there are stray hidden characters but even if there were I am copying known good code and it's not working. There has to be another problem other than the SQL. Can someone please help me. I have been at this for 2 days now.

    /*--------------------------------------------------------------------------*/
    /*                      Database Table Setup                                */
    /*--------------------------------------------------------------------------*/
    
    $pr_db_version = "1.0";
       global $wpdb;
    
       // add database pointer
       $wpdb->pr_orders					= $wpdb->prefix . 'pr_orders';
       $wpdb->pr_vendors					= $wpdb->prefix . 'pr_vendors';
       $wpdb->pr_approvals					= $wpdb->prefix . 'pr_approvals';
       $wpdb->pr_items					= $wpdb->prefix . 'pr_items';
    
    function pr_db_install () {
       global $wpdb;
       global $pr_db_version;
    
    //Concat WordPress DB prefix to table name and Assign Table Names to Variables
       $pr_orders    = $wpdb->prefix . "pr_orders";
       $pr_vendors   = $wpdb->prefix . "pr_vendors";
       $pr_approvals = $wpdb->prefix . "pr_approvals";
       $pr_items     = $wpdb->prefix . "pr_items";
    
       //Check if pr_orders table already exist and create if not
       if($wpdb->get_var("SHOW TABLES LIKE '$pr_orders'") != $pr_orders){
    
    	$sql = "CREATE TABLE " . $pr_orders . " (
    	pr_approval_id BIGINT(20) NOT NULL AUTO_INCREMENT ,
    	user_id BIGINT(20) NOT NULL ,
    	pr_order_id BIGINT(20) NOT NULL ,
    	pr_voter_priority BIGINT(3) NOT NULL ,
    	pr_treasurer_approved BOOLEAN NULL ,
    	pr_president_approved BOOLEAN NULL ,
    	pr_secretary_approved BOOLEAN NULL,
    	pr_approval_date_added DATETIME NOT NULL ,
    	pr_approval_date_changed DATETIME NULL ,
    	pr_approval_comment VARCHAR(255) NULL ,
    	PRIMARY KEY  (pr_approval_id) ,
    	KEY pr_type (pr_type) ,
    	KEY pr_status(pr_status)
    	);";       
    
            dbDelta($sql);
    
       }
    }
    
    register_activation_hook(__FILE__,'pr_db_install');
    
    /*--------------------------------------------------------------------------*/
    /*                    End Database Table Setup                              */
    /*--------------------------------------------------------------------------*/
    //**************************************************************************//
  8. Squintz
    Member
    Posted 4 years ago #

    I have also tried it without the database pointers.

    /*--------------------------------------------------------------------------*/
    /*                      Database Table Setup                                */
    /*--------------------------------------------------------------------------*/
    
    $pr_db_version = "1.0";
    
    function pr_db_install () {
       global $wpdb;
       global $pr_db_version;
    
    //Concat WordPress DB prefix to table name and Assign Table Names to Variables
       $pr_orders    = $wpdb->prefix . "pr_orders";
       $pr_vendors   = $wpdb->prefix . "pr_vendors";
       $pr_approvals = $wpdb->prefix . "pr_approvals";
       $pr_items     = $wpdb->prefix . "pr_items";
    
       //Check if pr_orders table already exist and create if not
       if($wpdb->get_var("SHOW TABLES LIKE '$pr_orders'") != $pr_orders){
    
    	$sql = "CREATE TABLE " . $pr_orders . " (
    	pr_approval_id BIGINT(20) NOT NULL AUTO_INCREMENT ,
    	user_id BIGINT(20) NOT NULL ,
    	pr_order_id BIGINT(20) NOT NULL ,
    	pr_voter_priority BIGINT(3) NOT NULL ,
    	pr_treasurer_approved BOOLEAN NULL ,
    	pr_president_approved BOOLEAN NULL ,
    	pr_secretary_approved BOOLEAN NULL,
    	pr_approval_date_added DATETIME NOT NULL ,
    	pr_approval_date_changed DATETIME NULL ,
    	pr_approval_comment VARCHAR(255) NULL ,
    	PRIMARY KEY  (pr_approval_id) ,
    	KEY pr_type (pr_type) ,
    	KEY pr_status(pr_status)
    	);";       
    
            dbDelta($sql);
    
       }
    }
    
    register_activation_hook(__FILE__,'pr_db_install');
    
    /*--------------------------------------------------------------------------*/
    /*                    End Database Table Setup                              */
    /*--------------------------------------------------------------------------*/
    //**************************************************************************//

Topic Closed

This topic has been closed to new replies.

About this Topic