Compare commits
4 Commits
v1.4
...
41bb7f855e
Author | SHA1 | Date | |
---|---|---|---|
41bb7f855e | |||
a30032f1ca | |||
0fbd2be3e6 | |||
af2e4cbdd6 |
@ -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 <patrick@niebel.ing>
|
||||
* 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'] = '<a href="#" class="rename-to-uuid" data-id="' . $post->ID . '">' . __('In UUID umbenennen', 'uuid-file-renamer') . '</a>';
|
||||
}
|
||||
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,17 +112,18 @@ 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 '<script>
|
||||
jQuery(document).ready(function($) {
|
||||
$(document).on("click", ".rename-to-uuid", function() {
|
||||
$(document).on("click", ".rename-to-uuid", function(event) {
|
||||
event.preventDefault();
|
||||
var button = $(this);
|
||||
var attachmentId = button.data("id");
|
||||
$.post(ajaxurl, { action: "rename_media_to_uuid", attachment_id: attachmentId }, function(response) {
|
||||
if (response.success) {
|
||||
alert(response.data);
|
||||
// alert(response.data);
|
||||
location.reload();
|
||||
} else {
|
||||
alert(response.data);
|
||||
|
Reference in New Issue
Block a user