diff --git a/uuid-file-renamer.php b/uuid-file-renamer.php index 46e9a3f..6295b91 100644 --- a/uuid-file-renamer.php +++ b/uuid-file-renamer.php @@ -4,7 +4,7 @@ * Plugin Name: UUID File Renamer * Description: Dieses Plugin benennt hochgeladene Dateien automatisch in eine UUID um und ermöglicht das Umbenennen bestehender Medien direkt in der Mediathek. * Plugin URI: https://gitea.gnilebein.de/gnilebein/wordpres-uuid-file-renamer - * Version: 1.4 + * Version: 1.5 * Author: Patrick Niebeling * Author URI: https://gnilebein.de * Text Domain: uuid-file-renamer @@ -34,6 +34,15 @@ function add_uuid_rename_button($form_fields, $post) { return $form_fields; } +// Link in der Mediathek hinzufügen +add_filter('media_row_actions', 'add_uuid_rename_link', 10, 2); +function add_uuid_rename_link($actions, $post) { + if ($post->post_type === 'attachment') { + $actions['rename_to_uuid'] = '' . __('In UUID umbenennen', 'uuid-file-renamer') . ''; + } + return $actions; +} + // AJAX-Handler für Einzel-Umbenennung add_action('wp_ajax_rename_media_to_uuid', 'rename_media_to_uuid_ajax'); function rename_media_to_uuid_ajax() { @@ -75,7 +84,7 @@ function rename_existing_media_to_uuid($attachment_id) { $file_info = pathinfo($file_path); $new_file_path = $file_info['dirname'] . '/' . $uuid . '.' . $file_info['extension']; - // Metadaten der Bilder abrufen + // Metadaten abrufen $metadata = wp_get_attachment_metadata($attachment_id); $upload_dir = wp_upload_dir(); @@ -87,13 +96,13 @@ function rename_existing_media_to_uuid($attachment_id) { 'post_name' => $uuid )); - // Thumbnails umbenennen + // Thumbnails umbenennen, falls vorhanden if (!empty($metadata['sizes'])) { foreach ($metadata['sizes'] as $size => $data) { $old_thumb_path = $upload_dir['basedir'] . '/' . dirname($metadata['file']) . '/' . $data['file']; - $thumb_info = pathinfo($old_thumb_path); - $new_thumb_path = $thumb_info['dirname'] . '/' . $uuid . '-' . $data['width'] . 'x' . $data['height'] . '.' . $thumb_info['extension']; if (file_exists($old_thumb_path)) { + $thumb_info = pathinfo($old_thumb_path); + $new_thumb_path = $thumb_info['dirname'] . '/' . $uuid . '-' . $data['width'] . 'x' . $data['height'] . '.' . $thumb_info['extension']; rename($old_thumb_path, $new_thumb_path); $metadata['sizes'][$size]['file'] = basename($new_thumb_path); } @@ -103,12 +112,13 @@ function rename_existing_media_to_uuid($attachment_id) { } } -// JS für Button hinzufügen +// JS für Buttons hinzufügen add_action('admin_footer', 'uuid_renamer_js'); function uuid_renamer_js() { echo '