Title: Alter users table
Last modified: August 22, 2016

---

# Alter users table

 *  [Harris Marfel](https://wordpress.org/support/users/hrace009/)
 * (@hrace009)
 * [11 years, 7 months ago](https://wordpress.org/support/topic/alter-users-table/)
 * Hello,
 * I have create plugin that if we activated it, it will add new column on users
   table.
 * the code :
 *     ```
       global $PWTW_db_version;
       $PWTW_db_version = '1.0';
   
       function PWTW_install() {
       	global $wpdb;
         global $PWTW_db_version;
   
       	$table_name = $wpdb->prefix . 'users';
   
       	$sql = "ALTER TABLE $table_name ADD COLUMN <code>user_credits</code>  int(20) NOT NULL AFTER <code>display_name</code>;";
   
       	require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
       	dbDelta( $sql );
   
       	add_option( 'PWTW_db_version', $PWTW_db_version );
       }
   
       $installed_ver = get_option( "PWTW_db_version" );
   
       if ( $installed_ver != $PWTW_db_version ) {
   
       	$table_name = $wpdb->prefix . 'users';
   
       	$sql = "ALTER TABLE $table_name ADD COLUMN <code>user_credits</code>  int(20) NOT NULL AFTER <code>display_name</code>;";
   
       	require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
       	dbDelta( $sql );
   
       	update_option( "PWTW_db_version", $PWTW_db_version );
       }
   
       function PWTW_update_db_check() {
         global $PWTW_db_version;
           if ( get_site_option( 'PWTW_db_version' ) != $PWTW_db_version ) {
               PWTW_install();
           }
       }
   
       register_activation_hook( __FILE__, 'PWTW_install' );
       add_action( 'plugins_loaded', 'PWTW_update_db_check' );
       ```
   
 * i try to Active the plugin, but it not create new column in users table.
 * does anyone can light me up?
 * thank you

The topic ‘Alter users table’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 0 replies
 * 1 participant
 * Last reply from: [Harris Marfel](https://wordpress.org/support/users/hrace009/)
 * Last activity: [11 years, 7 months ago](https://wordpress.org/support/topic/alter-users-table/)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
