Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

User profile fields are pre populated with current user data #427

Closed
avoinicu opened this issue Aug 11, 2015 · 5 comments
Closed

User profile fields are pre populated with current user data #427

avoinicu opened this issue Aug 11, 2015 · 5 comments

Comments

@avoinicu
Copy link

Whenever I am adding a new user, the custom fields come pre populated with the current user's data. I am using CMB2 2.1.0 with WordPress 2.4.2

Tested field types: text and file (with and without default values).

@avoinicu
Copy link
Author

I've managed to solve this problem by updating the IF statement at line 228 in CMB2_Field.php with the following:

// If no override, get value normally
if ( 'cmb2_field_no_override_val' === $data ) {
    switch (true) {
        case ($a['type'] === 'options-page'):
            $data = cmb2_options( $a['id'] )->get( $a['field_id'] );
            break;
        case ($a['type'] === 'user' && get_current_screen()->action === 'add'):
            $data = cmb2_options( $a['id'] )->get( $a['field_id'] );
            break;
        default:
            $data = get_metadata( $a['type'], $a['id'], $a['field_id'], ( $a['single'] || $a['repeat'] ) );
    }
}

@jtsternberg
Copy link
Member

This has been addressed in the trunk branch, thank you for reporting! Please please please don't modify CMB2 core as there may be other plugins depending on your copy of CMB2 (because of the way CMB2 loading works) and while your edits may work for your use-case, it's alway possible that they could break somebody else's.

@avoinicu
Copy link
Author

Thank you for the quick reply!

The only reason I posted my solution is because I need a temporary fix until a new version of CMB2 is released and I thought this might help somebody else, but you are right.

Thank you again for the great work you do!

@jtsternberg
Copy link
Member

Understood. Did you happen to test trunk? It should be good (it worked for me), but want to verify.

@avoinicu
Copy link
Author

Yes, it worked as expected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants