Archives

Require Additional Profile Fields at Registration

<?php

add_action( 'register_form', 'additional_profile_fields' );
function additional_profile_fields() { ?>
    <p>
        <label><?php _e('First Name') ?><br />
        <input type="text" name="first_name" id="first_name" class="input" size="25" tabindex="20" /></label>
    </p>
    <p>
        <label><?php _e('Last Name') ?><br />
        <input type="text" name="last_name" id="last_name" class="input" size="25" tabindex="20" /></label>
    </p>
<?php }
 
add_action( 'register_post', 'add_register_field_validate_first_name', 10, 3 );
function add_register_field_validate_first_name( $sanitized_user_login, $user_email, $errors) {
    if (!isset($_POST[ 'first_name' ]) || empty($_POST[ 'first_name' ])) {
    	return $errors->add( 'firstnameempty', '<strong>ERROR</strong>: Please provide a first name.' );
    }    
}
add_action( 'register_post', 'add_register_field_validate_last_name', 10, 3 );
function add_register_field_validate_last_name( $sanitized_user_login, $user_email, $errors) {
    if (!isset($_POST[ 'last_name' ]) || empty($_POST[ 'last_name' ])) {
    	return $errors->add( 'lastnameempty', '<strong>ERROR</strong>: Please provide a last name.' );
    }    
}

add_action( 'user_register', 'insert_register_fields' );
function insert_register_fields( $user_id ) {
	
	$first_name = apply_filters('pre_user_first_name', $_POST['first_name']);
	$last_name = apply_filters('pre_user_last_name', $_POST['last_name']);
	
	update_user_meta( $user_id, 'first_name', $first_name );
	update_user_meta( $user_id, 'last_name', $last_name );
}

Move Privacy Notice in 3.2

If you’ve already started poking around in WordPress 3.2, you may have noticed that the privacy notice that used to appear in the WordPress header has been moved to the Right Now box on the dashboard.

And if you’re like me, you probably wish it was back at the top. Fortunately, with just a few lines, we can do that:

add_action('in_admin_header', 'privacy_notice_in_header');
function privacy_notice_in_header() {
    if (1 != get_option('blog_public')) {
        $title = apply_filters('privacy_on_link_title', __('Your site is asking search engines not to index its content') );
        $content = apply_filters('privacy_on_link_text', __('Search Engines Blocked') );
        echo "<p class='alignleft' style='padding:9px 0 0;margin:0;'><a href='options-privacy.php' title='$title'>$content</a></p>";
    }
}