Wordpress Multisite Add custom fields on registrat

2019-08-31 04:33发布

问题:

I am searching all over the internet but can't find how to add or update meta data after the user has activated their blog/site.

I want to add those one so that the user can see their additional meta/custom field in their profile page.

I have this code on my wp-signup.php file:

    $signup_meta = array(
        'organization_address'=>$_POST['organization_address'],
        'organization_name'=>$_POST['organization_name'],
        'organization_number'=>$_POST['organization_number'],
        'organization_address'=>$_POST['organization_address'],
        'organization_zip'=>$_POST['organization_zip'],
        'organization_city'=>$_POST['organization_city'],
        'organization_country'=>$_POST['organization_country'],
        'first_name'=>$_POST['first_name'],
        'last_name'=>$_POST['last_name'],
        'phone'=>$_POST['phone'],
        'lang_id' => 1, 
        'public' => $public
    );
wpmu_signup_blog($domain, $path, $blog_title,  $email, $email, $signup_meta);
add_action('user_register', 'custom_register_extra_fields');
add_action('wpmu_activate_user', 'stjert_register_user_meta', 10, 3);

$meta_defaults = apply_filters( 'signup_create_blog_meta', $signup_meta );
confirm_blog_signup($domain, $path, $blog_title, $email, $email, $signup_meta);

Then on my functions.php file , I have this code:

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>Kontaktinformasjon</h3>
    <table class="form-table">
        <tr>
            <th><label for="first_name">Fornavn:</label></th>
            <td>
                <input type="text" name="first_name" id="first_name" value="<?php echo esc_attr( get_the_author_meta( 'first_name', $user->ID ) ); ?>" class="regular-text" />
            </td>
        </tr>
        <tr>
            <th><label>Etternavn:</label></th>
            <td>
                <input type="text" name="last_name" id="last_name" value="<?php echo esc_attr( get_the_author_meta( 'last_name', $user->ID ) ); ?>" class="regular-text" />
            </td>
        </tr>
        <tr>
            <th><label>Telefon:</label></th>
            <td>
                <input type="text" name="phone" id="phone" value="<?php echo esc_attr( get_the_author_meta( 'phone', $user->ID ) ); ?>" class="regular-text" />
            </td>
        </tr>
    </table>

I cut down the code because its too long.

When I go to the Profile Page(wp-admin), I don't see those custom fields/meta values that I had during registration, I was thinking that maybe it was not saved or whatever?

Any help on this? Please. I am really new to wordpress and the 'Wordpress way' is very difficult for me. Feels like very different from MVC frameworks.

Your help will be greatly appreciated!

Thanks!

PS: Here's my entire code of wp-signup.php http://pastebin.com/YcvHeHkC

回答1:

I don't think I have fully understood the question here...But what I see, is that you're trying to do a registration form, with non-regular fields and save those as metadata. Your way of thinking is correct, but the functions I'm not pretty sure...

It was not clear either if you want to do this inside or outside the admin panel, so, what i suggest is

Create the user retriving it's Username, Password and Email, using

wp_create_user( $username, $password, $email ); // Go to codex 

http://codex.wordpress.org/Function_Reference/wp_create_user

This function will return the ID of the given user created, than you get all this posts and in a foreach or something use this other function

add_user_meta( $user_id, $meta_key, $meta_value, $unique ); // Go to codex 

http://codex.wordpress.org/Function_Reference/add_user_meta

And finally, on the edit page, or where you want to show it, you're able to show it by using

get_user_meta($user_id, $key, $single); // Go to codex

http://codex.wordpress.org/Function_Reference/get_user_meta



标签: php wordpress