• Resolved vince123

    (@vince123)


    Hi,

    Thanks for this amazing plugin,
    I have a small concern which is regarding the visibility of the custom user profile fields that are not visible on the Edit profile page.
    I used the following code for addition of a custom field to the user profile,

    add_action( ‘show_user_profile’, ‘my_show_extra_profile_fields’ );
    add_action( ‘edit_user_profile’, ‘my_show_extra_profile_fields’ );

    function my_show_extra_profile_fields( $user ) { ?>

    <h3>Extra profile information</h3>

    <table class=”form-table”>

    <tr>
    <th><label for=”twitter”>Twitter</label></th>

    <td>
    <input type=”text” name=”twitter” id=”twitter” value=”<?php echo esc_attr( get_the_author_meta( ‘twitter’, $user->ID ) ); ?>” class=”regular-text” /><br />
    <span class=”description”>Please enter your Twitter username.</span>
    </td>
    </tr>

    </table>
    dd_action( ‘personal_options_update’, ‘my_save_extra_profile_fields’ );
    add_action( ‘edit_user_profile_update’, ‘my_save_extra_profile_fields’ );

    function my_save_extra_profile_fields( $user_id ) {

    if ( !current_user_can( ‘edit_user’, $user_id ) )
    return false;

    /* Copy and paste this line for additional fields. Make sure to change ‘twitter’ to the field ID. */
    update_usermeta( $user_id, ‘twitter’, $_POST[‘twitter’] );
    }
    <?php }

    the addition of the new field was successful but I could not find the newly added field on the Edit profile page. I checked the profile builder > manage field, option but could not find the new field.

    Thanks!

    • This topic was modified 6 years, 8 months ago by vince123.
Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Georgian Cocora

    (@raster02)

    Hello @vince123,

    We don’t mimic the hooks that WordPress uses for their forms so your code is triggered only for the default forms.

    To save the data you can use this hook: https://www.cozmoslabs.com/docs/profile-builder-2/developers-knowledge-base/useful-profile-builder-hooks/#Edit_Profile

    And for display, there is a hook: wppb_after_form_fields, you can use it like this:

    add_filter('wppb_after_form_fields', 'wppbc_add_something_after_form_fields', 20, 3);
    function wppbc_add_something_after_form_fields($content, $form_type, $args_id) {
        if ($form_type != 'edit_profile') return;
        
        $your_custom_content = '<a href="https://google.com">Go to GOOGLE</a>';
        
        return $your_custom_content . $content;
    }

    At the end I’m concatenating my custom content with the $content variable that is made available to the function. This is because we use this to return the closing </ul> tag of our form and if you don’t put it at the end, the HTML of the form will be broken.

    Regards.

    Thread Starter vince123

    (@vince123)

    Hi Georgian Cocora (@raster02)

    Thanks for the support, the code I added will add new fields to the user profile page visible only on the backend of the WordPress.I need the extra fields also to be visible on the Edit Profile Page that was created by adding the corresponding shortcode to the page. The code you shared created a hyperlink to the Google on Edit profile Page, It seems your intention was to take the user to the custom content (in my code it is a separate section labelled as Extra profile information).So In order to take him to that part what URL will I use. Sorry, I am not an expert, Please correct me If I am wrong.what If I don’t want a hyperlink to navigate to the extra fields I added, I may want to view the full user profile with all fields on the same page itself.Please guide me to achieve this

    Please share How can we make the Log-out link into a button on the front end of the site also.

    Kind Regards,
    Vince

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘custom field for user not visible on Edit profile’ is closed to new replies.