WordPress not recognizing function during plugin activation

I get this error when I try to activate my plugin:

call_user_func_array() expects parameter 1 to be a valid callback, function ‘fancy_lists_create_table’ not found or invalid function name in /Applications/XAMPP/xamppfiles/htdocs/intranet/wp-includes/plugin.php on line 525

Read More

This was output from a plugin that debugs the “xxx characters of unexpected output” error that is commonly seen. I don’t understand why the function isn’t valid. Code below:

namespace fancy_lists; 
register_activation_hook( __FILE__, 'fancy_lists_create_table' );

function fancy_lists_create_table(){
    global $wpdb;

    $table_name = $wpdb->prefix.'fancy_lists';

    if($wpdb->get_var("SHOW TABLES LIKE '$table_name'") != $table_name) {

        $charset_collate = $wpdb->get_charset_collate();

        $sql = "CREATE TABLE $table_name (
          id mediumint(9) NOT NULL AUTO_INCREMENT,
          created datetime DEFAULT NOW() NOT NULL,
          created_by text NOT NULL,
          list_name text NOT NULL,
          column_config text NOT NULL,
          permissions text NOT NULL,
          notifications text NOT NULL,
          UNIQUE KEY id (id)
        ) $charset_collate;";

        require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
        dbDelta( $sql );
    }

}

Related posts

Leave a Reply

1 comment

  1. register_activation_hook() isn’t aware of the namespace. You must specify it:

    register_activation_hook( __FILE__, __NAMESPACE__ . 'fancy_lists_create_table' );