Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Matthew Muro

    (@mmuro)

    This is possible with the vfb_field_default hook in VFB Pro.

    Thread Starter jabad

    (@jabad)

    Sorry I’m trying without exit

    I have the form nº 27 and a Advanced Field name
    I insert the following code in the visual-form-builder-pro.php

    function vfb_filter_field_default( $default, $field_type, $field_id, $form_id ){
        $first = $last = '';
    
        switch ( $field_type ) :
    
            case 'name' :
               if ( 114 == $form_id && is_user_logged_in() ) :
                   $current_user = wp_get_current_user();
    
                    if ( !empty( $current_user->user_firstname ) && empty( $current_user->user_lastname ) )
                        $first = $current_user->user_firstname;
                    else if ( empty( $current_user->user_firstname ) && !empty( $current_user->user_lastname ) )
                       $last = $current_user->user_lastname;
                    else if ( !empty( $current_user->user_firstname ) && !empty( $current_user->user_lastname ) ) {
                        $first = $current_user->user_firstname;
                        $last = $current_user->user_lastname;
    
                    return "$first $last";
                endif;
            break;
    
            case 'email' :
                if ( 114 == $form_id && is_user_logged_in() ) :
                    $current_user = wp_get_current_user();
    
                    if ( !empty( $current_user->user_email ) )
                        $default = $current_user->user_email;
    
                    return $default;
                endif;
            break;
    
        endswitch;
        return $default;
    }

    and then I call the filter from the form-output.php

    add_filter( 'vfb_field_default', 'vfb_filter_field_default', 10, 4 );

    And when I try to actívate the pluging I received the following error

    Parse error: syntax error, unexpected T_ENDIF in C:\Llocs Web\onomricat\www\wp-content\plugins\visual-form-builder-pro\visual-form-builder-pro.php on line 4127

    Plugin Author Matthew Muro

    (@mmuro)

    I insert the following code in the visual-form-builder-pro.php

    No, you should never edit the source code! That’s why I have hooks.

    Any code should either go in the functions.php file of your theme or a custom plugin. Here is documentation on the add_filter function. If you need further help with this, I suggest asking a question on the WordPress StackExchange.

    Thread Starter jabad

    (@jabad)

    Thks
    Now I have a plugin that I can activate without error but I’m not able to get it work it will be great for a future update to have the username as possibility in the hidden field.

    Thanks for your great plugin

    cloc562oc

    (@cloc562oc)

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Username’ is closed to new replies.