Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
1.3 kB
2
Indexable
Never
// Add additional email field to the user profile page in the backend
add_action('show_user_profile', 'add_additional_email_field');
add_action('edit_user_profile', 'add_additional_email_field');

function add_additional_email_field($user) {
    ?>
    <h3><?php _e('Additional Email', 'your_textdomain'); ?></h3>
    <table class="form-table">
        <tr>
            <th><label for="additional_email"><?php _e('Additional Email', 'your_textdomain'); ?></label></th>
            <td>
                <input type="email" name="additional_email" id="additional_email" value="<?php echo esc_attr(get_the_author_meta('additional_email', $user->ID)); ?>" class="regular-text" /><br />
                <span class="description"><?php _e('Please enter an additional email address.', 'your_textdomain'); ?></span>
            </td>
        </tr>
    </table>
    <?php
}

// Save the additional email field
add_action('personal_options_update', 'save_additional_email_field');
add_action('edit_user_profile_update', 'save_additional_email_field');

function save_additional_email_field($user_id) {
    if (!current_user_can('edit_user', $user_id)) {
        return false;
    }

    update_user_meta($user_id, 'additional_email', sanitize_email($_POST['additional_email']));
}
Leave a Comment