jeudi 5 novembre 2015

add extra email field to wordpress registration with email confirmation

I am developing a WordPress Plugin and I want to add an extra email field to WordPress registration form. So that there are 2 emails field and I also want to send confirmation email to both the email accounts and only after both the emails are confirmed the users account is active. If only one email is confirmed users account wont be active. Is there a work around for this ? I have already added an email field with code below :

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">Paypal Id</label></th>
            <td>
                <input type="text" name="tac_paypal_id" id="tac_paypal_id" value="<?php echo esc_attr( get_the_author_meta( 'tac_paypal_id', $user->ID ) ); ?>" class="regular-text" /><br />
                <span class="description">Please enter your paypal id.</span>
            </td>
        </tr>
    </table>
<?php
}

add_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;

    update_usermeta( $user_id, 'tac_paypal_id', $_POST['tac_paypal_id'] );
}

/**
 * Add cutom field to registration form
 */

add_action('register_form','show_first_name_field');
add_action('register_post','check_fields',10,3);
add_action('user_register', 'register_extra_fields');

function show_first_name_field()
{
?>
    <p>
    <label>Paypal Id<br/>
    <input id="tac_paypal_id" type="text" tabindex="30" size="25" value="<?php echo $_POST['tac_paypal_id']; ?>" name="tac_paypal_id" />
    </label>
    </p>
<?php
}

function check_fields ( $login, $email, $errors )
{
    global $tac_paypal_id;
    if ( $_POST['tac_paypal_id'] == '' )
    {
        $errors->add( 'empty_realname', "<strong>ERROR</strong>: Please enter your paypal id" );
    }
    else
    {
        $tac_paypal_id = $_POST['tac_paypal_id'];
    }
}

function register_extra_fields ( $user_id, $password = "", $meta = array() )
{
    update_user_meta( $user_id, 'tac_paypal_id', $_POST['tac_paypal_id'] );
}



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire