WordPress.org

Support

Support » Plugins and Hacks » Hacks » Custom profile fields validator

Custom profile fields validator

  • Hi.

    I made a plugin for custom profile fields. How can I display errors, if name is not inserted?

    add_action( 'show_user_profile', 'extra_user_profile_fields' );
    add_action( 'edit_user_profile', 'extra_user_profile_fields' );
    
    function extra_user_profile_fields() { ?>
    <table class="form-table">
    <tr>
    <th><label for="field_name"><?php _e("Name*"); ?></label></th>
    <td>
    <input type="text" name="field_name" id="field_name" value="<?php
    echo get_user_meta( current_user_id(), 'field_name', true);
    ?>" class="regular-text" /><br />
    <span class="description"><?php _e("Insert name."); ?></span>
    </td>
    </tr>
    </table>
    
    add_action( 'personal_options_update', 'save_extra_user_profile_fields' );
    add_action( 'edit_user_profile_update', 'save_extra_user_profile_fields' );
    
    function save_extra_user_profile_fields( $user_id ) {
    if ( !current_user_can( 'edit_user', $user_id ) ) { return false; }
    update_usermeta( user_id(), 'field name', $_POST['field_name'] );
    }
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘Custom profile fields validator’ is closed to new replies.
Skip to toolbar