Untitled

mail@pastecode.io avatar
unknown
php
2 years ago
1.2 kB
3
Indexable
Never
add_action( 'show_user_profile', 'extra_user_profile_fields2' );
add_action( 'edit_user_profile', 'extra_user_profile_fields2' );

function extra_user_profile_fields2( $user ) { ?>
    <h3><?php _e("Extra profile information", "blank"); ?></h3>

    <table class="form-table">
    <tr>
        <th><label for="vat_number"><?php _e("Address"); ?></label></th>
        <td>
            <input type="text" name="vat_number" id="vat_number" value="<?php echo esc_attr( get_the_author_meta( 'vat_number', $user->ID ) ); ?>" class="regular-text" /><br />
            <span class="description"><?php _e("Please enter your vat number."); ?></span>
        </td>
    </tr>

    </table>
<?php }
add_action( 'personal_options_update', 'save_extra_user_profile_fields2' );
add_action( 'edit_user_profile_update', 'save_extra_user_profile_fields2' );

function save_extra_user_profile_fields2( $user_id ) {
    if ( empty( $_POST['_wpnonce'] ) || ! wp_verify_nonce( $_POST['_wpnonce'], 'update-user_' . $user_id ) ) {
        return;
    }
    
    if ( !current_user_can( 'edit_user', $user_id ) ) { 
        return false; 
    }
    update_user_meta( $user_id, 'vat_number', $_POST['vat_number'] );
}