Skip to:
Content
Pages
Categories
Search
Top
Bottom

Re: Hide some fields in profile


Boris
Participant

@travel-junkie

Basically, you could extend the registration form by using one of the many hooks provided there. The data your user inputs there can then be saved as usermeta and it won’t show on their profile. Something like this:

/**
* Add xtra input field to registration form
* @since 4.0
*/
function tj_add_to_registration()
{
?>
<div id="tos" class="register-section">
<h3 class="transform"><?php _e( 'Don\'t forget...', 'traveljunkie' ) ?></h3>

<?php do_action( 'bp_accept_tos_errors' ) ?>
<label><input type="checkbox" name="accept_tos" id="accept_tos" value="agreed" /> <?php _e( 'Check this box to accept our <a href="/terms-of-service" target="_blank">Terms Of Service</a> (required)', 'traveljunkie' ) ?></label>
</div>
<?php
}
add_action( 'bp_before_registration_submit_buttons', 'tj_add_to_registration' );

/**
* Add custom userdata from register.php
* @since 4.0
*/
function tj_add_to_signup( $usermeta )
{
$usermeta['accept_tos'] = $_POST['accept_tos'];

return $usermeta;
}
add_filter( 'bp_signup_usermeta', 'tj_add_to_signup' );

/**
* Update usermeta with custom registration data
* @since 4.0
*/
function tj_user_activate_fields( $user )
{
update_usermeta( $user['user_id'], 'accept_tos', $user['meta']['accept_tos'] );

return $user;
}
add_filter( 'bp_core_activate_account', 'tj_user_activate_fields' );

/**
* Perform checks for custom registration data
* @since 4.0
*/
function tj_check_additional_signup()
{
global $bp;

if( $_POST['accept_tos'] != 'agreed' )
$bp->signup->errors['accept_tos'] = __( 'Please make sure to read our Terms of Service and then check this box!', 'traveljunkie' );

}
add_action( 'bp_signup_validate', 'tj_check_additional_signup' );

I haven’t tested the above code much so there might be some bugs…

Skip to toolbar