Custom multisite plugin not creating tables (2 posts)

  1. dyrk
    Posted 5 years ago #


    I'm trying to write a custom plugin for a multisite installation.
    I'm using Shiba's method from here

    It's not creating the tables and I'm getting this message on activation:

    The plugin generated 2412 characters of unexpected output during activation.

    Here's my complete plugin code:

    Plugin Name: Messages
    Plugin URI: http://www.whatever.com
    Description: Messages Plugin
    Version: 0.1
    Author: Whoever
    class msgLoader {
    	function msgLoader() {
    		register_activation_hook( __FILE__, 'multisiteActivate' );
    	function create_inbox_table($table_name) {
    		global $wpdb;
    			$sql = "CREATE TABLE IF NOT EXISTS '$table_name' (
    			  	id bigint(20) NOT NULL AUTO_INCREMENT,
    				from varchar(255) NOT NULL,
    			  	message varchar(255) DEFAULT NULL,
    			  	UNIQUE KEY id (id)
    		require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
    	function multisiteActivate() {
    		global $wpdb;
    		if (function_exists('is_multisite') && is_multisite()) {
    			// check if it is a network activation - if so, run the activation function for each blog id
    			if (isset($_GET['networkwide']) && ($_GET['networkwide'] == 1)) {
    		                $old_blog = $wpdb->blogid;
    				// Get all blog ids
    				$blogids = $wpdb->get_col($wpdb->prepare("SELECT blog_id FROM $wpdb->blogs"));
    				foreach ($blogids as $blog_id) {
    	function activate() {
    		global $wpdb;
    	        $table_name = $wpdb->prefix . 'inbox';
    			if ($wpdb->get_var( "SHOW TABLES LIKE '$table_name'") != $table_name) {
    global $msg;
    $msg = new msgLoader();

    Any help would be greatly appreciated.

    Thanks in advance


  2. 0blivian
    Posted 5 years ago #

    The problem in your code may lie in the interaction between HyperDb (which I suppose you have installed) and

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

    since Hyperdb::get_table_from_query() does not understand such queries.

    I posted a patch upstream for consideration as of today, I'll keep you posted if it gets into the mainline, in case this is your problem.

Topic Closed

This topic has been closed to new replies.

About this Topic