• Good evening.
    I am newbie @ wordpress plugin programming.
    Briefly..
    In my index plugin file i am requiring once for functions file in which i have writen IF function for “if installation file (setup.php) exists -> include setup.php and register_activation_hook for table installation function”.
    Here is setup.php code:

    //	Setting up table version for later upgrades
    	global $sarsauto_version;
    	$sarsauto_table_version	=	"0.1.";
    
    	//	Creating table
    	function sarsauto_table_setup() {
    		global $wpdb;
    		global $sarsauto_table_version;
    
    		$table_name = $wpdb->prefix . "sarsauto";
    
    		if( $wpdb->get_var( "show tables like '$table_name'" ) != $table_name ){
    			$sql = "CREATE TABLE " . $table_name . " (
    					id int(11) NOT NULL AUTO_INCREMENT,
    					UNIQUE KEY id (id)
    					);";
    		}
    
    		//	The dbDelta function examines the current table structure,
    		//	compares it to the desired table structure, and either adds
    		//	or modifies the table as necessary.
    		require_once( ABSPATH . "wp-admin/includes/upgrade.php" );
    		dbDelta( $sql );
    
    		add_option( "sarsauto_table_version", $sarsauto_table_version );
    	}

    And here is IF function of functions.php:

    //	Asking for setup.php file and if exists create function
    	if( file_exists( dINCLUDES . "setup.php" ) ){
    		//	Require setup.php file
    		include( dINCLUDES . "setup.php" );
    		//	On plugin activation ask for table setup function
    		register_activation_hook( __FILE__, "sarsauto_table_setup" );
    	}else{
    		echo "Error: file doesn't exists!";
    	}

    THE PROBLEM is whenever i am refreshing my database’s list of tables, no new table is added (in this case ‘sarsauto’ table).
    I have done everything like in wordpress plugin creation documentation.
    Please help. This issue is making me crazy.
    Thanks in advance,
    Ricards

  • The topic ‘Plugin can't create table’ is closed to new replies.