Wordpress's add_action for register_form not working

From what I read in the net, the following code should be adding a "City" field in the user registration form of Wordpress.

Thing is that, it seems to be not working - I don't see the additional "City" field in the user form.

Any help appreciated.

add_action( 'register_form', 'extended_register_form' );
add_filter('registration_errors', 'myplugin_registration_errors', 10, 3);
add_action('user_register', 'myplugin_user_register');

    function extended_register_form() {
$city = ( isset( $_POST['city'] ) ) ? $_POST['city']: '';
?>
<p>
    <label for="city">City<br />
    <input type="text" name="city" id="city" class="input" value="<?php echo esc_attr(stripslashes($city)); ?>" size="25" /></label>
</p>
<?
}
function myplugin_registration_errors ($errors, $sanitized_user_login, $user_email) {
    if ( empty( $_POST['city'] ) )
        $errors->add( 'city_error', __('<strong>ERROR</strong>: You must include a city.') );
    return $errors;
}
function myplugin_user_register ($user_id) {
    if ( isset( $_POST['city'] ) )
        update_user_meta($user_id, 'city', $_POST['city']);
}

Answers


I tried your code and it worked perfectly, perhaps it is because of the <? in line 12... Try <?php instead...

Where have you added the code? As a plugin or in the functions.php of your theme?


Since Wordpress 3.0.0, the action to call is "signup_extra_fields" instead of "register_form", so you should use:

add_action( 'signup_extra_fields', 'extended_register_form' );

Need Your Help

Receive XML Through HTTP POST In ASP.NET Web App

c# asp.net xml http

I have created an ASP.NET MVC 4 Web Application in Visual Studio and need to be able to receive XML through HTTP POST. What is the best way to go about this?

Automaticly send email after Paypal transaction

paypal

I need help on making a digital delivery system for my website.