Bug Report: Default Name Field Generation
-
Hello,
Just letting you know we’ve found some “sketchy” code in BP that could be improved. Probably won’t affect 80% of users, but here it is…
Version: 1.7.1
File: bp-core/admin/bp-core-schema.php
Lines: 308-309`
if ( !$wpdb->get_var( “SELECT id FROM {$bp_prefix}bp_xprofile_fields WHERE id = 1” ) )
$insert_sql[] = “INSERT INTO {$bp_prefix}bp_xprofile_fields ( group_id, parent_id, type, name, description, is_required, can_delete ) VALUES ( 1, 0, ‘textbox’, ” . $wpdb->prepare( ‘%s’, stripslashes( bp_get_option( ‘bp-xprofile-fullname-field-name’ ) ) ) . “, ”, 1, 0 );”;
`Symptoms:
When we first installed BuddyPress, we removed the “name” field in favour of using a combination of FirstName/LastName. Now, any time we do a major upgrade, BP creates a new required “Name” field in the database.The Problem:
You are searching for a field with “id=1” but when you create it, you don’t give it an ID of 1. This code makes the assumption that it is running on a new install, and therefore the database table must be empty. In our situation above, it is creating a new “Name” field but uses the auto-increment ID so the field never does have ID = 1. A similar problem appears to exist in the preceding lines as well when creating the group.The Solution:
Many possible solutions exist. One might be to create the field with an ID of 1 hardcoded. Another might be to test for the existence of a field where name = ‘Name’.Thanks,
JamesEDIT: typo.
- The topic ‘Bug Report: Default Name Field Generation’ is closed to new replies.