Compare commits
5 Commits
bbdd20c0f5
...
v1.5.1
Author | SHA1 | Date | |
---|---|---|---|
5614f47939 | |||
41bb7f855e | |||
a30032f1ca | |||
0fbd2be3e6 | |||
af2e4cbdd6 |
@ -4,7 +4,7 @@
|
|||||||
* Plugin Name: UUID File Renamer
|
* 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.
|
* 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
|
* Plugin URI: https://gitea.gnilebein.de/gnilebein/wordpres-uuid-file-renamer
|
||||||
* Version: 1.4
|
* Version: 1.5
|
||||||
* Author: Patrick Niebeling <patrick@niebel.ing>
|
* Author: Patrick Niebeling <patrick@niebel.ing>
|
||||||
* Author URI: https://gnilebein.de
|
* Author URI: https://gnilebein.de
|
||||||
* Text Domain: uuid-file-renamer
|
* Text Domain: uuid-file-renamer
|
||||||
@ -34,6 +34,15 @@ function add_uuid_rename_button($form_fields, $post) {
|
|||||||
return $form_fields;
|
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
|
// AJAX-Handler für Einzel-Umbenennung
|
||||||
add_action('wp_ajax_rename_media_to_uuid', 'rename_media_to_uuid_ajax');
|
add_action('wp_ajax_rename_media_to_uuid', 'rename_media_to_uuid_ajax');
|
||||||
function 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);
|
$file_info = pathinfo($file_path);
|
||||||
$new_file_path = $file_info['dirname'] . '/' . $uuid . '.' . $file_info['extension'];
|
$new_file_path = $file_info['dirname'] . '/' . $uuid . '.' . $file_info['extension'];
|
||||||
|
|
||||||
// Metadaten der Bilder abrufen
|
// Metadaten abrufen
|
||||||
$metadata = wp_get_attachment_metadata($attachment_id);
|
$metadata = wp_get_attachment_metadata($attachment_id);
|
||||||
$upload_dir = wp_upload_dir();
|
$upload_dir = wp_upload_dir();
|
||||||
|
|
||||||
@ -87,13 +96,13 @@ function rename_existing_media_to_uuid($attachment_id) {
|
|||||||
'post_name' => $uuid
|
'post_name' => $uuid
|
||||||
));
|
));
|
||||||
|
|
||||||
// Thumbnails umbenennen
|
// Thumbnails umbenennen, falls vorhanden
|
||||||
if (!empty($metadata['sizes'])) {
|
if (!empty($metadata['sizes'])) {
|
||||||
foreach ($metadata['sizes'] as $size => $data) {
|
foreach ($metadata['sizes'] as $size => $data) {
|
||||||
$old_thumb_path = $upload_dir['basedir'] . '/' . dirname($metadata['file']) . '/' . $data['file'];
|
$old_thumb_path = $upload_dir['basedir'] . '/' . dirname($metadata['file']) . '/' . $data['file'];
|
||||||
|
if (file_exists($old_thumb_path)) {
|
||||||
$thumb_info = pathinfo($old_thumb_path);
|
$thumb_info = pathinfo($old_thumb_path);
|
||||||
$new_thumb_path = $thumb_info['dirname'] . '/' . $uuid . '-' . $data['width'] . 'x' . $data['height'] . '.' . $thumb_info['extension'];
|
$new_thumb_path = $thumb_info['dirname'] . '/' . $uuid . '-' . $data['width'] . 'x' . $data['height'] . '.' . $thumb_info['extension'];
|
||||||
if (file_exists($old_thumb_path)) {
|
|
||||||
rename($old_thumb_path, $new_thumb_path);
|
rename($old_thumb_path, $new_thumb_path);
|
||||||
$metadata['sizes'][$size]['file'] = basename($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');
|
add_action('admin_footer', 'uuid_renamer_js');
|
||||||
function uuid_renamer_js() {
|
function uuid_renamer_js() {
|
||||||
echo '<script>
|
echo '<script>
|
||||||
jQuery(document).ready(function($) {
|
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 button = $(this);
|
||||||
var attachmentId = button.data("id");
|
var attachmentId = button.data("id");
|
||||||
$.post(ajaxurl, { action: "rename_media_to_uuid", attachment_id: attachmentId }, function(response) {
|
$.post(ajaxurl, { action: "rename_media_to_uuid", attachment_id: attachmentId }, function(response) {
|
||||||
if (response.success) {
|
if (response.success) {
|
||||||
alert(response.data);
|
// alert(response.data);
|
||||||
location.reload();
|
location.reload();
|
||||||
} else {
|
} else {
|
||||||
alert(response.data);
|
alert(response.data);
|
||||||
|
Reference in New Issue
Block a user