hotec user fields

Home » Snippets » hotec user fields
0

Created with:

Visibility: 

public

Creator: info@codeagency.be

Customize with WPTurbo AI
X

Add Snippet To Project

New Project
Add To Existing Project
					<?php
/*
Plugin Name: Your WP Plugin
Description: Custom user fields for company information.
Version: 1.0
Author: Your Name
License: GPL2
*/

// Add custom fields to user profile
function wpturbo_add_custom_user_fields( $user ) {
    ?>
    <h3><?php _e( 'Company Information', 'wpturbo' ); ?></h3>

    <table class="form-table">
        <tr>
            <th><label for="company_name"><?php _e( 'Company Name', 'wpturbo' ); ?></label></th>
            <td>
                <input type="text" name="company_name" id="company_name" value="<?php echo esc_attr( get_the_author_meta( 'company_name', $user->ID ) ); ?>" class="regular-text" />
            </td>
        </tr>
        <tr>
            <th><label for="vat_id"><?php _e( 'VAT ID', 'wpturbo' ); ?></label></th>
            <td>
                <input type="text" name="vat_id" id="vat_id" value="<?php echo esc_attr( get_the_author_meta( 'vat_id', $user->ID ) ); ?>" class="regular-text" />
            </td>
        </tr>
        <tr>
            <th><label for="street"><?php _e( 'Street', 'wpturbo' ); ?></label></th>
            <td>
                <input type="text" name="street" id="street" value="<?php echo esc_attr( get_the_author_meta( 'street', $user->ID ) ); ?>" class="regular-text" />
            </td>
        </tr>
        <tr>
            <th><label for="housenumber"><?php _e( 'House Number', 'wpturbo' ); ?></label></th>
            <td>
                <input type="text" name="housenumber" id="housenumber" value="<?php echo esc_attr( get_the_author_meta( 'housenumber', $user->ID ) ); ?>" class="regular-text" />
            </td>
        </tr>
        <tr>
            <th><label for="bus"><?php _e( 'Bus', 'wpturbo' ); ?></label></th>
            <td>
                <input type="text" name="bus" id="bus" value="<?php echo esc_attr( get_the_author_meta( 'bus', $user->ID ) ); ?>" class="regular-text" />
            </td>
        </tr>
        <tr>
            <th><label for="zipcode"><?php _e( 'Zipcode', 'wpturbo' ); ?></label></th>
            <td>
                <input type="text" name="zipcode" id="zipcode" value="<?php echo esc_attr( get_the_author_meta( 'zipcode', $user->ID ) ); ?>" class="regular-text" />
            </td>
        </tr>
        <tr>
            <th><label for="city"><?php _e( 'City', 'wpturbo' ); ?></label></th>
            <td>
                <input type="text" name="city" id="city" value="<?php echo esc_attr( get_the_author_meta( 'city', $user->ID ) ); ?>" class="regular-text" />
            </td>
        </tr>
        <tr>
            <th><label for="country"><?php _e( 'Country', 'wpturbo' ); ?></label></th>
            <td>
                <input type="text" name="country" id="country" value="<?php echo esc_attr( get_the_author_meta( 'country', $user->ID ) ); ?>" class="regular-text" />
            </td>
        </tr>
        <tr>
            <th><label for="email_alternative"><?php _e( 'Alternative Email', 'wpturbo' ); ?></label></th>
            <td>
                <input type="email" name="email_alternative" id="email_alternative" value="<?php echo esc_attr( get_the_author_meta( 'email_alternative', $user->ID ) ); ?>" class="regular-text" />
            </td>
        </tr>
        <tr>
            <th><label for="phone"><?php _e( 'Phone', 'wpturbo' ); ?></label></th>
            <td>
                <input type="tel" name="phone" id="phone" value="<?php echo esc_attr( get_the_author_meta( 'phone', $user->ID ) ); ?>" class="regular-text" />
            </td>
        </tr>
        <tr>
            <th><label for="phone_alternative"><?php _e( 'Alternative Phone', 'wpturbo' ); ?></label></th>
            <td>
                <input type="tel" name="phone_alternative" id="phone_alternative" value="<?php echo esc_attr( get_the_author_meta( 'phone_alternative', $user->ID ) ); ?>" class="regular-text" />
            </td>
        </tr>
    </table>
    <?php
}
add_action( 'show_user_profile', 'wpturbo_add_custom_user_fields' );
add_action( 'edit_user_profile', 'wpturbo_add_custom_user_fields' );

// Save custom fields
function wpturbo_save_custom_user_fields( $user_id ) {
    if ( ! current_user_can( 'edit_user', $user_id ) ) {
        return false;
    }

    update_user_meta( $user_id, 'company_name', sanitize_text_field( $_POST['company_name'] ) );
    update_user_meta( $user_id, 'vat_id', sanitize_text_field( $_POST['vat_id'] ) );
    update_user_meta( $user_id, 'street', sanitize_text_field( $_POST['street'] ) );
    update_user_meta( $user
				

Register an account to save your snippets or go Pro to get more features.