Metabox, which displays user data, you can update and overwrite. After clicking on the refresh button, the data is displayed as before, and changes do not occur in the database.

add_action('add_meta_boxes', 'metatest_init'); function metatest_init() { add_meta_box('metatest', 'MetaTest-параметры поста', 'metatest_showup', 'post', 'side', 'high', 'default'); } function metatest_showup($user, $box) { // получение существующих метаданных $data = get_post_meta($user->ID, '_metatest_data', true); // скрытое поле с одноразовым кодом wp_nonce_field('metatest_action', 'metatest_nonce'); $user_info = get_userdata(1); // поле с метаданными echo '<p>Введите ID пользователя: <input type="text" name="metadata_field" value="' . $user_info->ID . '"/></p>'; echo '<p> Login: <input type="text" name="metadata_field" value="' . $user_info->user_login . '"/></p>'; echo '<p>Имя:<br> <input type="text" name="metadata_field" value="' . $user_info->user_firstname . '"/></p>'; echo '<p>Фамилия: <input type="text" name="metadata_field" value="' . $user_info->user_lastname . '"/></p>'; echo '<p>E-mail : <input type="text" name="metadata_field" value="' . $user_info->user_email . '"/></p>'; } add_action('save_post', 'metatest_save'); function metatest_save($userID) { // пришло ли поле наших данных? if (!isset($_POST['metadata_field'])) return; // не происходит ли автосохранение? if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) return; // не ревизию ли сохраняем? if (wp_is_post_revision($userID)) return; // проверка достоверности запроса check_admin_referer('metatest_action', 'metatest_nonce'); // коррекция данных $data = sanitize_text_field($_POST['metadata_field']); update_user_meta($userID, '_metatest_data', $data); } 
  • one
    You have just been explained today that the user_firstname and user_lastname fields do not exist. How so? - KAGG Design
  • @KAGG Design, yes, I remember, but I found in my inaccuracy, where I was mistaken in the last question. I fixed this in my code. And in this case, the user_email field is not even overwritten! - Alexander
  • one
    And then, what do you want to see? After receiving the existing metadata in the $ data variable, it is not used at all. - KAGG Design
  • one
    You put the ruble in your left pocket, and then you try to pull it out of the right one. - KAGG Design
  • one
    The left pocket is called _metatest_data, and the right one is get_userdata. I really do not know how to explain more clearly. You write one into the database, and display another. What's so incomprehensible? - KAGG Design

0