Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Show Database Errors
- // Comment this line out when going live :)
- $wpdb->show_errors();
- // 99 times out of 100 this is overkill
- // I'm just being on the safe side
- //
- // It checks what the current user ID is
- if ( !$user_id ) {
- $current_user = wp_get_current_user();
- $user_id = $current_user->ID;
- } else {
- $user_id = (int) $user_id;
- }
- // Connects to the database
- // Retrieves the value for this user for wp_capabilities
- $user_cap = $wpdb->get_row( "SELECT meta_value FROM wp_usermeta WHERE user_id=$user_id AND meta_key='wp_capabilities' LIMIT 1" );
- // Checks to see if the user already has a bb_capabilities
- // If it does we'll overwrite it
- // If it doesn't we'll add a new one.
- $user_cap_in_bb_meta = $wpdb->get_row( "SELECT meta_value FROM bb_usermeta WHERE user_id=$user_id AND meta_key='bb_capabilities' LIMIT 1" );
- if ($user_cap_in_bb_meta)
- {
- // update bbPress database
- $wpdb->query("UPDATE bb_usermeta SET meta_value='". $user_cap->meta_value ."' WHERE user_id=". $user_id ." AND meta_key= 'bb_capabilities' ");
- } else {
- // Add a new row to the bbPress database
- $wpdb->query("INSERT INTO bb_usermeta (user_id, meta_key, meta_value) VALUES (". $user_id .", bb_capabilities, '". $user_cap->meta_value ."') ");
- }
- // Print all Database errors
- // Comment this line out when going live :)
- $wpdb->print_error();
- // Hide Database Errors
- // Comment this line out when going live :)
- $wpdb->hide_errors();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement