Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //=========================================================================================================
- // Create Table after activating theme
- //=========================================================================================================
- global $cb_db_version;
- $cb_db_version = '1.1';
- $prefix = $wpdb->prefix;
- $table_name1 = $prefix . 'table_one';
- $table_name2 = $prefix . 'table_two';
- $table_name3 = $prefix . 'table_three';
- function cb_create_table() {
- global $wpdb;
- global $jal_db_version;
- $charset_collate = $wpdb->get_charset_collate();
- global $table_name1, $table_name2, $table_name3;
- $sql = "CREATE TABLE $table_name1 (
- `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
- `description` varchar(255) COLLATE utf8_unicode_ci NOT NULL DEFAULT '',
- `rotator_type` varchar(255) COLLATE utf8_unicode_ci NOT NULL DEFAULT 'Series',
- PRIMARY KEY (`id`)
- ) $charset_collate;";
- $sql .= "CREATE TABLE $table_name2 (
- `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
- `click_rotators_id` int(10) unsigned NOT NULL DEFAULT '0',
- `series_position` int(10) unsigned NOT NULL DEFAULT '0',
- PRIMARY KEY (`id`)
- ) $charset_collate;";
- $sql .= "CREATE TABLE $table_name3 (
- `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
- `click_rotators_id` int(10) unsigned NOT NULL DEFAULT '0',
- `click_rotator_links_id` int(10) unsigned NOT NULL DEFAULT '0',
- PRIMARY KEY (`id`)
- ) $charset_collate;";
- require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
- dbDelta( $sql );
- add_option( 'cb_db_version', $jal_db_version );
- }
- // Add table after Installing and Activating theme
- function cb_update_table() {
- global $cb_db_version;
- if ( get_site_option( 'cb_db_version' ) != $cb_db_version ) {
- cb_create_table();
- }
- }
- add_action( 'after_switch_theme', 'cb_update_table' );
- //=========================================================================================================
- // Delete Table after deactivating theme
- //=========================================================================================================
- function theme_deactivation_function(){
- global $wpdb;
- global $cb_db_version;
- global $table_name1, $table_name2, $table_name3;
- $sql = "DROP TABLE $table_name1, $table_name2, $table_name3;";
- $wpdb->query($sql);
- delete_option($cb_db_version);
- }
- add_action('switch_theme', 'theme_deactivation_function');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement