Compare commits
11 Commits
5368937ba0
...
v1.5.1
Author | SHA1 | Date | |
---|---|---|---|
5614f47939 | |||
41bb7f855e | |||
a30032f1ca | |||
0fbd2be3e6 | |||
af2e4cbdd6 | |||
bbdd20c0f5 | |||
2c9040fa81 | |||
111b72ee1c | |||
8a814cbafa | |||
5d429a890e | |||
2bc2ce43ba |
296
.gitignore
vendored
Normal file
296
.gitignore
vendored
Normal file
@ -0,0 +1,296 @@
|
||||
### Ansible ###
|
||||
*.retry
|
||||
|
||||
### Intellij+all ###
|
||||
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
|
||||
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
|
||||
|
||||
# User-specific stuff
|
||||
.idea/**/workspace.xml
|
||||
.idea/**/tasks.xml
|
||||
.idea/**/usage.statistics.xml
|
||||
.idea/**/dictionaries
|
||||
.idea/**/shelf
|
||||
|
||||
# Generated files
|
||||
.idea/**/contentModel.xml
|
||||
|
||||
# Sensitive or high-churn files
|
||||
.idea/**/dataSources/
|
||||
.idea/**/dataSources.ids
|
||||
.idea/**/dataSources.local.xml
|
||||
.idea/**/sqlDataSources.xml
|
||||
.idea/**/dynamic.xml
|
||||
.idea/**/uiDesigner.xml
|
||||
.idea/**/dbnavigator.xml
|
||||
|
||||
# Gradle
|
||||
.idea/**/gradle.xml
|
||||
.idea/**/libraries
|
||||
|
||||
# Gradle and Maven with auto-import
|
||||
# When using Gradle or Maven with auto-import, you should exclude module files,
|
||||
# since they will be recreated, and may cause churn. Uncomment if using
|
||||
# auto-import.
|
||||
# .idea/artifacts
|
||||
# .idea/compiler.xml
|
||||
# .idea/jarRepositories.xml
|
||||
# .idea/modules.xml
|
||||
# .idea/*.iml
|
||||
# .idea/modules
|
||||
# *.iml
|
||||
# *.ipr
|
||||
|
||||
# CMake
|
||||
cmake-build-*/
|
||||
|
||||
# Mongo Explorer plugin
|
||||
.idea/**/mongoSettings.xml
|
||||
|
||||
# File-based project format
|
||||
*.iws
|
||||
|
||||
# IntelliJ
|
||||
out/
|
||||
|
||||
# mpeltonen/sbt-idea plugin
|
||||
.idea_modules/
|
||||
|
||||
# JIRA plugin
|
||||
atlassian-ide-plugin.xml
|
||||
|
||||
# Cursive Clojure plugin
|
||||
.idea/replstate.xml
|
||||
|
||||
# Crashlytics plugin (for Android Studio and IntelliJ)
|
||||
com_crashlytics_export_strings.xml
|
||||
crashlytics.properties
|
||||
crashlytics-build.properties
|
||||
fabric.properties
|
||||
|
||||
# Editor-based Rest Client
|
||||
.idea/httpRequests
|
||||
|
||||
# Android studio 3.1+ serialized cache file
|
||||
.idea/caches/build_file_checksums.ser
|
||||
|
||||
### Intellij+all Patch ###
|
||||
# Ignores the whole .idea folder and all .iml files
|
||||
# See https://github.com/joeblau/gitignore.io/issues/186 and https://github.com/joeblau/gitignore.io/issues/360
|
||||
|
||||
.idea/
|
||||
|
||||
# Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-249601023
|
||||
|
||||
*.iml
|
||||
modules.xml
|
||||
.idea/misc.xml
|
||||
*.ipr
|
||||
|
||||
# Sonarlint plugin
|
||||
.idea/sonarlint
|
||||
|
||||
### Linux ###
|
||||
*~
|
||||
|
||||
# temporary files which can be created if a process still has a handle open of a deleted file
|
||||
.fuse_hidden*
|
||||
|
||||
# KDE directory preferences
|
||||
.directory
|
||||
|
||||
# Linux trash folder which might appear on any partition or disk
|
||||
.Trash-*
|
||||
|
||||
# .nfs files are created when an open file is removed but is still being accessed
|
||||
.nfs*
|
||||
|
||||
### Python ###
|
||||
# Byte-compiled / optimized / DLL files
|
||||
__pycache__/
|
||||
*.py[cod]
|
||||
*$py.class
|
||||
|
||||
# C extensions
|
||||
*.so
|
||||
|
||||
# Distribution / packaging
|
||||
.Python
|
||||
build/
|
||||
develop-eggs/
|
||||
dist/
|
||||
downloads/
|
||||
eggs/
|
||||
.eggs/
|
||||
lib/
|
||||
lib64/
|
||||
parts/
|
||||
sdist/
|
||||
var/
|
||||
wheels/
|
||||
pip-wheel-metadata/
|
||||
share/python-wheels/
|
||||
*.egg-info/
|
||||
.installed.cfg
|
||||
*.egg
|
||||
MANIFEST
|
||||
|
||||
# PyInstaller
|
||||
# Usually these files are written by a python script from a template
|
||||
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
||||
*.manifest
|
||||
*.spec
|
||||
|
||||
# Installer logs
|
||||
pip-log.txt
|
||||
pip-delete-this-directory.txt
|
||||
|
||||
# Unit test / coverage reports
|
||||
htmlcov/
|
||||
.tox/
|
||||
.nox/
|
||||
.coverage
|
||||
.coverage.*
|
||||
.cache
|
||||
nosetests.xml
|
||||
coverage.xml
|
||||
*.cover
|
||||
*.py,cover
|
||||
.hypothesis/
|
||||
.pytest_cache/
|
||||
pytestdebug.log
|
||||
|
||||
# Translations
|
||||
*.mo
|
||||
*.pot
|
||||
|
||||
# Django stuff:
|
||||
*.log
|
||||
local_settings.py
|
||||
db.sqlite3
|
||||
db.sqlite3-journal
|
||||
|
||||
# Flask stuff:
|
||||
instance/
|
||||
.webassets-cache
|
||||
|
||||
# Scrapy stuff:
|
||||
.scrapy
|
||||
|
||||
# Sphinx documentation
|
||||
docs/_build/
|
||||
doc/_build/
|
||||
|
||||
# PyBuilder
|
||||
target/
|
||||
|
||||
# Jupyter Notebook
|
||||
.ipynb_checkpoints
|
||||
|
||||
# IPython
|
||||
profile_default/
|
||||
ipython_config.py
|
||||
|
||||
# pyenv
|
||||
.python-version
|
||||
|
||||
# pipenv
|
||||
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
||||
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
||||
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
||||
# install all needed dependencies.
|
||||
#Pipfile.lock
|
||||
|
||||
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
|
||||
__pypackages__/
|
||||
|
||||
# Celery stuff
|
||||
celerybeat-schedule
|
||||
celerybeat.pid
|
||||
|
||||
# SageMath parsed files
|
||||
*.sage.py
|
||||
|
||||
# Environments
|
||||
.env
|
||||
.venv
|
||||
env/
|
||||
venv/
|
||||
ENV/
|
||||
env.bak/
|
||||
venv.bak/
|
||||
|
||||
# Spyder project settings
|
||||
.spyderproject
|
||||
.spyproject
|
||||
|
||||
# Rope project settings
|
||||
.ropeproject
|
||||
|
||||
# mkdocs documentation
|
||||
/site
|
||||
|
||||
# mypy
|
||||
.mypy_cache/
|
||||
.dmypy.json
|
||||
dmypy.json
|
||||
|
||||
# Pyre type checker
|
||||
.pyre/
|
||||
|
||||
# pytype static type analyzer
|
||||
.pytype/
|
||||
|
||||
### Terraform ###
|
||||
# Local .terraform directories
|
||||
**/.terraform/*
|
||||
|
||||
# .tfstate files
|
||||
*.tfstate
|
||||
*.tfstate.*
|
||||
*.terraform.lock.hcl
|
||||
|
||||
# Crash log files
|
||||
crash.log
|
||||
|
||||
# Ignore any .tfvars files that are generated automatically for each Terraform run. Most
|
||||
# .tfvars files are managed as part of configuration and so should be included in
|
||||
# version control.
|
||||
#
|
||||
# example.tfvars
|
||||
|
||||
# Ignore override files as they are usually used to override resources locally and so
|
||||
# are not checked in
|
||||
override.tf
|
||||
override.tf.json
|
||||
*_override.tf
|
||||
*_override.tf.json
|
||||
|
||||
# Include override files you do wish to add to version control using negated pattern
|
||||
# !example_override.tf
|
||||
|
||||
# Include tfplan files to ignore the plan output of command: terraform plan -out=tfplan
|
||||
# example: *tfplan*
|
||||
|
||||
### Vim ###
|
||||
# Swap
|
||||
[._]*.s[a-v][a-z]
|
||||
!*.svg # comment out if you don't need vector files
|
||||
[._]*.sw[a-p]
|
||||
[._]s[a-rt-v][a-z]
|
||||
[._]ss[a-gi-z]
|
||||
[._]sw[a-p]
|
||||
|
||||
# Session
|
||||
Session.vim
|
||||
Sessionx.vim
|
||||
|
||||
# Temporary
|
||||
.netrwhist
|
||||
# Auto-generated tag files
|
||||
tags
|
||||
# Persistent undo
|
||||
[._]*.un~
|
||||
|
||||
#VSCode
|
||||
.vscode
|
14
README.md
14
README.md
@ -1,3 +1,15 @@
|
||||
# wordpres-uuid-file-renamer
|
||||
# Description
|
||||
|
||||
Dieses Plugin benennt hochgeladene Dateien automatisch in eine UUID um.
|
||||
|
||||
# Installation
|
||||
Go to your Wordpress plugin directory and run the following command.
|
||||
```
|
||||
git clone https://gitea.gnilebein.de/gnilebein/wordpres-uuid-file-renamer.git uuid-file-renamer
|
||||
```
|
||||
|
||||
# Update
|
||||
Go to plungin directory directory and run the following command.
|
||||
```
|
||||
git pull
|
||||
```
|
135
uuid-file-renamer.php
Normal file
135
uuid-file-renamer.php
Normal file
@ -0,0 +1,135 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* 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.5
|
||||
* Author: Patrick Niebeling <patrick@niebel.ing>
|
||||
* Author URI: https://gnilebein.de
|
||||
* Text Domain: uuid-file-renamer
|
||||
* License: GPL2
|
||||
*/
|
||||
|
||||
// Hook in den Upload-Prozess
|
||||
add_filter('wp_handle_upload_prefilter', 'rename_file_to_uuid');
|
||||
|
||||
function rename_file_to_uuid($file)
|
||||
{
|
||||
$uuid = wp_generate_uuid4();
|
||||
$file_info = pathinfo($file['name']);
|
||||
$extension = isset($file_info['extension']) ? '.' . $file_info['extension'] : '';
|
||||
$file['name'] = $uuid . $extension;
|
||||
return $file;
|
||||
}
|
||||
|
||||
// Medienbearbeitungsseite erweitern
|
||||
add_filter('attachment_fields_to_edit', 'add_uuid_rename_button', 10, 2);
|
||||
function add_uuid_rename_button($form_fields, $post) {
|
||||
$form_fields['uuid_rename'] = array(
|
||||
'label' => __('UUID umbenennen', 'uuid-file-renamer'),
|
||||
'input' => 'html',
|
||||
'html' => '<button type="button" class="button rename-to-uuid" data-id="' . $post->ID . '">' . __('In UUID umbenennen', 'uuid-file-renamer') . '</button>'
|
||||
);
|
||||
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() {
|
||||
if (!current_user_can('manage_options')) {
|
||||
wp_send_json_error(__('Keine Berechtigung.', 'uuid-file-renamer'));
|
||||
}
|
||||
if (!isset($_POST['attachment_id'])) {
|
||||
wp_send_json_error(__('Fehlende Anhangs-ID.', 'uuid-file-renamer'));
|
||||
}
|
||||
$attachment_id = intval($_POST['attachment_id']);
|
||||
rename_existing_media_to_uuid($attachment_id);
|
||||
wp_send_json_success(__('Datei erfolgreich umbenannt.', 'uuid-file-renamer'));
|
||||
}
|
||||
|
||||
// Medienübersicht erweitern
|
||||
add_filter('bulk_actions-upload', 'register_bulk_uuid_rename');
|
||||
function register_bulk_uuid_rename($bulk_actions) {
|
||||
$bulk_actions['rename_to_uuid'] = __('In UUID umbenennen', 'uuid-file-renamer');
|
||||
return $bulk_actions;
|
||||
}
|
||||
|
||||
// Batch-Umbenennung verarbeiten
|
||||
add_filter('handle_bulk_actions-upload', 'handle_bulk_uuid_rename', 10, 3);
|
||||
function handle_bulk_uuid_rename($redirect_to, $doaction, $attachment_ids) {
|
||||
if ($doaction !== 'rename_to_uuid') {
|
||||
return $redirect_to;
|
||||
}
|
||||
foreach ($attachment_ids as $attachment_id) {
|
||||
rename_existing_media_to_uuid($attachment_id);
|
||||
}
|
||||
$redirect_to = add_query_arg('bulk_uuid_renamed', count($attachment_ids), $redirect_to);
|
||||
return $redirect_to;
|
||||
}
|
||||
|
||||
// Funktion zum Umbenennen bestehender Medien inkl. Thumbnails
|
||||
function rename_existing_media_to_uuid($attachment_id) {
|
||||
$uuid = wp_generate_uuid4();
|
||||
$file_path = get_attached_file($attachment_id);
|
||||
$file_info = pathinfo($file_path);
|
||||
$new_file_path = $file_info['dirname'] . '/' . $uuid . '.' . $file_info['extension'];
|
||||
|
||||
// Metadaten abrufen
|
||||
$metadata = wp_get_attachment_metadata($attachment_id);
|
||||
$upload_dir = wp_upload_dir();
|
||||
|
||||
if (rename($file_path, $new_file_path)) {
|
||||
update_attached_file($attachment_id, $new_file_path);
|
||||
wp_update_post(array(
|
||||
'ID' => $attachment_id,
|
||||
'post_title' => $uuid,
|
||||
'post_name' => $uuid
|
||||
));
|
||||
|
||||
// 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'];
|
||||
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);
|
||||
}
|
||||
}
|
||||
wp_update_attachment_metadata($attachment_id, $metadata);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 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(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);
|
||||
location.reload();
|
||||
} else {
|
||||
alert(response.data);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
</script>';
|
||||
}
|
Reference in New Issue
Block a user