Skip to:
Content
Pages
Categories
Search
Top
Bottom

Hide some fields in profile


  • lukabernardi
    Participant

    @lukabernardi

    When you sign I need to prompt the user for sensitive information like his phone or his address, but I do not want to be then displayed on their profile for obvious reasons of privacy.

    How can I do?

Viewing 2 replies - 1 through 2 (of 2 total)

  • Anonymous User 96400
    Inactive

    @anonymized-96400

    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…


    lukabernardi
    Participant

    @lukabernardi

    This seems like a solution that can fit only in certain cases.

    I would also like to filter-before-output …

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Hide some fields in profile’ is closed to new replies.
Skip to toolbar