diff --git a/author.php b/author.php
index b666055..6d36a46 100644
--- a/author.php
+++ b/author.php
@@ -5,18 +5,16 @@
';
+ //$author_id = get_queried_object_id();
+ $author_id = get_the_author_meta('ID');
+ $avatar_id = get_user_meta($author_id, 'avatar_attachment_id', true);
+
+ if ($avatar_id) {
+ echo wp_get_attachment_image($avatar_id, 'medium', false, array('class' => 'author-avatar'));
} else {
+ // Fallback: Gravatar или дефолтное изображение
echo '' . get_avatar($author_id, 100, '', '', array('class' => 'avatar-round')) . '
';
- }
- ?>
+ }?>
= get_the_author(); ?>
diff --git a/inc/avatar.php b/inc/avatar.php
index ecc46c3..86b400b 100644
--- a/inc/avatar.php
+++ b/inc/avatar.php
@@ -6,27 +6,63 @@ function add_multipart_form_encoding() {
echo ' enctype="multipart/form-data"';
}
-// 2. Добавляем поле для загрузки аватара
+// 2. Добавляем поле для аватара + медиабиблиотеку
add_action('show_user_profile', 'extra_user_profile_fields');
add_action('edit_user_profile', 'extra_user_profile_fields');
function extra_user_profile_fields($user) {
+ wp_enqueue_media(); // Подключаем медиабиблиотеку
?>
+
+
false);
- $movefile = wp_handle_upload($uploadedfile, $upload_overrides);
+ $movefile = wp_handle_upload($uploadedfile, array('test_form' => false));
if ($movefile && !isset($movefile['error'])) {
- update_user_meta($user_id, 'avatar', $movefile['url']);
- } else {
- // Обработка ошибки (можно вывести сообщение)
- wp_die('Upload error: ' . $movefile['error']);
+ $attachment_id = wp_insert_attachment(array(
+ 'post_mime_type' => $movefile['type'],
+ 'post_title' => preg_replace('/\.[^.]+$/', '', basename($movefile['file'])),
+ 'post_status' => 'inherit'
+ ), $movefile['file']);
+
+ if (!is_wp_error($attachment_id)) {
+ require_once(ABSPATH . 'wp-admin/includes/image.php');
+ wp_update_attachment_metadata($attachment_id, wp_generate_attachment_metadata($attachment_id, $movefile['file']));
+ update_user_meta($user_id, 'avatar_attachment_id', $attachment_id);
+ }
}
}
+
+ // Сохранение выбранного изображения из медиатеки
+ if (!empty($_POST['avatar_attachment_id'])) {
+ update_user_meta($user_id, 'avatar_attachment_id', intval($_POST['avatar_attachment_id']));
+ }
}
\ No newline at end of file