creating table upon plugin activation doest work
-
I followed this
http://codex.wordpress.org/Creating_Tables_with_Plugins
it doesnt work. I didnt need the upgrade feature so i didnt add it.
heres the full code of my php file
//Installation Process global $westpac_store_version; $westpac_store_version = '1.0'; function westpac_store_install() { global $wpdb; global $westpac_store_version; $table_name = $wpdb->prefix . 'westpac_store'; /* * We'll set the default character set and collation for this table. * If we don't do this, some characters could end up being converted * to just ?'s when saved in our table. */ $charset_collate = ''; if ( ! empty( $wpdb->charset ) ) { $charset_collate = "DEFAULT CHARACTER SET {$wpdb->charset}"; } if ( ! empty( $wpdb->collate ) ) { $charset_collate .= " COLLATE {$wpdb->collate}"; } $sql = "CREATE TABLE " . $table_name . " ( itemID mediumint(9) NOT NULL AUTO_INCREMENT, itemModel varchar(55) NOT NULL, itemCat text NOT NULL, itemManuf varchar(55) NOT NULL, itemSpec text NOT NULL, itemDesc text NOT NULL, itemImg text DEFAULT 'none' NOT NULL, itemPrice decimal(19,4) DEFAULT 0 NOT NULL UNIQUE KEY itemID (itemID) ) " . $charset_collate . ";"; require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); dbDelta( $sql ); add_option( 'westpac_store_version', $westpac_store_version ); } register_activation_hook( __FILE__, 'westpac_store_install' ); //Adding Westpac Store Menu add_action('admin_menu', 'westpac_store'); function westpac_store(){ add_menu_page( 'Westpac Store', 'Westpac Store', 'manage_options', 'westpac-store', 'westpac_store_page', 'dashicons-cart', '4.1' ); } //Westpac Store Interface function westpac_store_page(){ ?> <div> <h2>Westpac Store</h2> View all product section </div> <?php } //Adding Westpac Store Add Sub-menu add_action('admin_menu', 'westpac_store_add'); function westpac_store_add(){ add_submenu_page( 'westpac-store', 'Westpac Store - Add Item', 'Add Item', 'manage_options', 'westpac-store-add', 'westpac_store_add_page' ); } //Westpac Store Add Interface function westpac_store_add_page(){ ?> <div> <h2>Westpac Store - Add Item</h2> Add item section </div> <?php } ?>
- The topic ‘creating table upon plugin activation doest work’ is closed to new replies.