I’ve split the function as follows:
function xprofile_add_signup_fields() {
global $bp_xprofile_callback, $avatar_error, $avatar_error_msg;
/* Fetch the fields needed for the signup form */
$fields = BP_XProfile_Field::get_signup_fields();
if ( $fields ) {
?>
<div id="extra-form-fields">
<?php
for ( $i = 0; $i < count($fields); $i++ ) {
if ( $bp_xprofile_callback[$i]['field_id'] == $fields[$i]->id && isset($bp_xprofile_callback[$i]['error_msg']) ) {
$css_class = ' class="error"';
} else {
$css_class = '';
}
?>
<div class="extra-field">
<?php if ( $css_class != '' ) { echo '<div class="error">' . $bp_xprofile_callback[$i]['error_msg'] . '</div>'; } ?>
<?php echo $fields[$i]->get_edit_html($bp_xprofile_callback[$i]['value']); ?>
</div>
<?php
$field_ids .= $fields[$i]->id . ",";
}
?>
</div>
<input type="hidden" name="xprofile_ids" value="<?php echo attribute_escape( $field_ids ); ?>" />
<?php
}
}
add_action( 'signup_extra_fields', 'xprofile_add_signup_fields' );
function xprofile_avatar_field() {
global $bp_xprofile_callback, $avatar_error, $avatar_error_msg;
if ( !(int) get_site_option( 'bp-disable-avatar-uploads' ) ) {
?>
<div id="avatar-form-fields">
<h3><?php _e('Profile Picture (Avatar)', 'buddypress'); ?></h3>
<p id="avatar-help-text"><?php _e('You can upload an image from your computer to use as an avatar. This avatar will appear on your profile page.', 'buddypress'); ?></p>
<?php
if ( $avatar_error ) {
$css_class = ' error';
} else {
$css_class = '';
}
?>
<div class="avatar-field<?php echo $css_class; ?>">
<?php if ( $css_class != '' ) { echo '<div class="error">' . $avatar_error_msg . '</div>'; } ?>
<label for="file"><?php _e( 'Select a file:', 'buddypress' ) ?></label>
<input type="hidden" name="MAX_FILE_SIZE" value="<?php echo get_site_option('fileupload_maxk') * 1024; ?>" />
<input type="hidden" name="slick_avatars_action" value="upload" />
<input type="hidden" name="action" value="slick_avatars" />
<input type="file" name="file" id="file" />
</div>
<script type="text/javascript">
jQuery(document).ready( function() {
jQuery('form#setupform').attr( 'enctype', 'multipart/form-data' );
jQuery('form#setupform').attr( 'encoding', 'multipart/form-data' );
});
</script>
</div>
<?php
}
}
add_action( 'signup_avatar_field', 'xprofile_avatar_field' );
Unfortunately it doesn’t work 100%. I was able to register a test user, but first name, last name and avatar were not stored.
With the old combined function first name and last name were stored correctly, so I must have made a mistake in splitting them. Where?
Comments + suggestions appreciated!