Custom Fields
Re-Envisioned
Support MB User Profile Display edit user form on front end

  • Creator
    Topic
  • #16401
    Resolved Eliodata
    Participant

    Hi,
    I pasted this code into my author.php file :

    <?php 
    $form = '[mb_user_profile_info id="untitled-field-group" user_id="36" submit_button="Submit" confirmation="Your information has been successfully submitted. Thank you."]';
    echo do_shortcode( $form );
    ?>

    It works displaying all the fields. But they are empty. I would like to be able to open each user profile and edit it front end. For example for the user “testuser” this page :
    https://mydomain.com/author/testuser
    should display the “testuser” datas, not an empty form.

    Can you help please ?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Author
    Replies
  • #16402
    Eliodata
    Participant

    I pasted you the bad code sorry. here is the one I use, without user id :

    <?php 
    $form = '[mb_user_profile_info id="untitled-field-group" submit_button="Submit" confirmation="Your information has been successfully submitted. Thank you."]';
    echo do_shortcode( $form );
    ?>
    #16410
    Anh Tran
    Keymaster

    Hi Eliodata,

    To edit default user fields, please create a meta box that has the same fields as WordPress’s. Then add it to the shortcode. For details, please see the docs:

    https://docs.metabox.io/extensions/mb-user-profile/#edit-default-fields

    #16416
    Eliodata
    Participant

    Hi Anh,

    My question was not clear, sorry for my poor english. My user form is ok and works fine on admin, I’m just trying to display it and edit content front end.

    The page “https://mydomain.com/author/testuser1&#8221; should display results for “testuser” and the page “https://mydomain.com/author/testuser2&#8221; sould display results for “testuser2”. But it only displays empty forms.

    How can I edit user forms front end please ? I mean choosing the profil I want and edit his content.

    Have a nice week !

    #16651
    Anh Tran
    Keymaster

    We have resolved this issue via email. Here is the solution in case anyone is interested in:

    The solution is using some hook to output the shortcode dynamically, like this:

    // We're adding a shortcode dynamically to a specific page
    add_filter( 'the_content', function( $content ) {
        if ( ! is_page() || 123 !== get_the_ID() ) {
            return $content;
        }
        
        // We pass user ID via URL
        $user_id = isset( $_GET['user_id'] ) ? $_GET['user_id'] : '';
        // Create shortcode dynamically
        $shortcode = '[mb_user_profile_info id="your-meta-box-id" user_id="' . $user_id . '"]';
    
        return $content . do_shortcode( $shortcode );
    } );

    So, you can create a page like /edit-user/ and pass user ID via URL like this: /edit-user/?user_id=123

Viewing 4 replies - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.