• Resolved johngeorge

    (@johngeorge)


    OK. I’m going crazy here. I’ve found a lot of threads devoted to the register_activation_hook function, but nothing with the problem I’m having.

    I’ve been trying to create another table during installation of a custom plugin, but nothing was working. I put WP into ‘debug’ mode, but it doesn’t throw any errors other than

    “Plugin could not be activated because it triggered a fatal error.”

    My code looked something like

    $wpdb->location_tracking = "{$wpdb->prefix}location_tracker";
    
    function location_tracker_activate()
    {
    	global $wpdb;
    
    	$create_table_sql = "
    		CREATE TABLE {$wpdb->location_tracking} (
    			id int AUTO_INCREMENT,
    			lat float(10,6),
    			lng float(10,6),
    			primary key (id)
    		)
    	";
    
    	require_once(ABSPATH . 'wp-admin/includes/install.php');
    
    	maybe_create_table($wpdb->location_tracking, $create_table_sql);
    
    }
    register_activation_hook(__FILE__, 'location_tracker_activate');

    So, I’m now just trying to kill the process during my installation, but I just get the same result. Nothing ‘dies’, I just get

    “Plugin could not be activated because it triggered a fatal error.”

    function location_tracker_activate()
    {
    	die('WTF?');
    }
    register_activation_hook(__FILE__, 'location_tracker_activate');

    Another strange thing is if I register a function that doesn’t exist, I have no errors thrown at all.
    register_activation_hook(__FILE__, 'mungy_mungy_mungy');

    I’m obviously doing something stupid… but what?

    (Oh, and everything’s being declared in the main plugin file “wp-content/plugins/location_tracker/location_tracker.php”)

Viewing 1 replies (of 1 total)
  • Thread Starter johngeorge

    (@johngeorge)

    OMG!

    I found the problem. Every function within that file has to wrapped within
    if (!function_exists('function_name')) { } (or use require_once to include another file).

    The reason that no errors were being reported is a bit of a surprise to me. It maybe something to do with a PHP 5.3.0 bug… it’s the first time PHP has released namespacing so it’s possible that error reporting is a bit mucked up.

Viewing 1 replies (of 1 total)

The topic ‘sorry… another ‘register_activation_hook’ problem’ is closed to new replies.