Version Description
- Fix: Issue with rare characters used in the title.
- Fix: Issue with PDF thumbnails.
Download this release
Release Info
Developer | TigrouMeow |
Plugin | Media File Renamer |
Version | 4.7.0 |
Comparing to | |
See all releases |
Code changes from version 4.6.9 to 4.7.0
- common/img/kinsta.png +0 -0
- common/img/stackpath.png +0 -0
- core.php +30 -9
- helpers.php +4 -1
- media-file-renamer.php +2 -2
- readme.txt +5 -1
common/img/kinsta.png
CHANGED
Binary file
|
common/img/stackpath.png
CHANGED
Binary file
|
core.php
CHANGED
@@ -499,7 +499,14 @@ SQL;
|
|
499 |
'%c2%b4', '%cb%8a', '%cc%81', '%cd%81',
|
500 |
// grave accent, macron, caron
|
501 |
'%cc%80', '%cc%84', '%cc%8c',
|
|
|
|
|
502 |
);
|
|
|
|
|
|
|
|
|
|
|
503 |
$chars = array_map( 'urldecode', $chars );
|
504 |
|
505 |
// Combining Diacritical Marks (U+0300 - U+036F)
|
@@ -632,12 +639,16 @@ SQL;
|
|
632 |
|
633 |
// Convert all accent characters to ASCII characters
|
634 |
if ( apply_filters( 'mfrh_converts', false ) ) {
|
635 |
-
$new_filename = remove_accents( $new_filename );
|
636 |
$new_filename = $this->remove_special_chars( $new_filename );
|
|
|
637 |
$new_filename = $this->transliterate( $new_filename );
|
638 |
$new_filename = strtolower( $new_filename );
|
639 |
}
|
640 |
|
|
|
|
|
|
|
|
|
641 |
// If the resulting filename had no any valid character, return NULL
|
642 |
if ( empty( $new_filename ) ) return null;
|
643 |
|
@@ -739,6 +750,7 @@ SQL;
|
|
739 |
$this->log( "[!] File\t$old_filepath -> $new_filepath" );
|
740 |
return false;
|
741 |
}
|
|
|
742 |
$this->log( "File\t$old_filepath -> $new_filepath" );
|
743 |
do_action( 'mfrh_path_renamed', $post, $old_filepath, $new_filepath );
|
744 |
|
@@ -750,6 +762,7 @@ SQL;
|
|
750 |
$meta['file'] = $this->str_replace( $old_directory, $new_directory, $meta['file'] );
|
751 |
if ( isset( $meta['url'] ) && !empty( $meta['url'] ) && count( $meta['url'] ) > 4 )
|
752 |
$meta['url'] = $this->str_replace( $old_directory, $new_directory, $meta['url'] );
|
|
|
753 |
}
|
754 |
|
755 |
// Better to check like this rather than with wp_attachment_is_image
|
@@ -807,9 +820,9 @@ SQL;
|
|
807 |
}
|
808 |
|
809 |
// Update metadata
|
810 |
-
if ( $meta )
|
811 |
-
|
812 |
-
update_attached_file( $id, $new_filepath );
|
813 |
|
814 |
// I wonder about cleaning the cache for this media. It might have no impact, and will not reset the cache for the posts using this media anyway, and it adds processing time. I keep it for now, but there might be something better to do.
|
815 |
clean_post_cache( $id );
|
@@ -947,6 +960,7 @@ SQL;
|
|
947 |
$this->log( "[!] File $old_filepath -> $new_filepath" );
|
948 |
return $post;
|
949 |
}
|
|
|
950 |
$this->log( "File\t$old_filepath -> $new_filepath" );
|
951 |
do_action( 'mfrh_path_renamed', $post, $old_filepath, $new_filepath );
|
952 |
|
@@ -968,6 +982,7 @@ SQL;
|
|
968 |
$meta['url'] = $this->str_replace( $noext_old_filename, $noext_new_filename, $meta['url'] );
|
969 |
else
|
970 |
$meta['url'] = $noext_new_filename . '.' . $old_ext;
|
|
|
971 |
}
|
972 |
|
973 |
// Better to check like this rather than with wp_attachment_is_image
|
@@ -1032,9 +1047,8 @@ SQL;
|
|
1032 |
}
|
1033 |
|
1034 |
$meta['sizes'][$size]['file'] = $meta_new_filename;
|
1035 |
-
|
1036 |
-
// Detect if another size has exactly the same filename
|
1037 |
foreach ( $meta['sizes'] as $s => $m ) {
|
|
|
1038 |
if ( !isset( $meta['sizes'][$s]['file'] ) )
|
1039 |
continue;
|
1040 |
if ( $meta['sizes'][$s]['file'] == $meta_old_filename ) {
|
@@ -1042,6 +1056,7 @@ SQL;
|
|
1042 |
$meta['sizes'][$s]['file'] = $meta_new_filename;
|
1043 |
}
|
1044 |
}
|
|
|
1045 |
|
1046 |
// Success, call other plugins
|
1047 |
$this->log( "File\t$meta_old_filepath -> $meta_new_filepath" );
|
@@ -1062,9 +1077,9 @@ SQL;
|
|
1062 |
add_post_meta( $id, '_manual_file_renaming', true, true );
|
1063 |
|
1064 |
// Update metadata
|
1065 |
-
if ( $meta )
|
1066 |
-
|
1067 |
-
update_attached_file( $id, $new_filepath );
|
1068 |
|
1069 |
// I wonder about cleaning the cache for this media. It might have no impact, and will not reset the cache for the posts using this media anyway, and it adds processing time. I keep it for now, but there might be something better to do.
|
1070 |
clean_post_cache( $id );
|
@@ -1121,6 +1136,12 @@ SQL;
|
|
1121 |
$force_rename,
|
1122 |
$post
|
1123 |
) {
|
|
|
|
|
|
|
|
|
|
|
|
|
1124 |
// 2 patterns exist.
|
1125 |
// - filename.webp
|
1126 |
// - filename.ext.webp
|
499 |
'%c2%b4', '%cb%8a', '%cc%81', '%cd%81',
|
500 |
// grave accent, macron, caron
|
501 |
'%cc%80', '%cc%84', '%cc%8c',
|
502 |
+
// quotation marks
|
503 |
+
chr(194), chr(171)
|
504 |
);
|
505 |
+
|
506 |
+
// error_log( print_r( $new_filename, 1 ));
|
507 |
+
// error_log( print_r( $new_filename[20], 1 ));
|
508 |
+
// error_log( print_r( ord( $new_filename[20] ), 1 ));
|
509 |
+
|
510 |
$chars = array_map( 'urldecode', $chars );
|
511 |
|
512 |
// Combining Diacritical Marks (U+0300 - U+036F)
|
639 |
|
640 |
// Convert all accent characters to ASCII characters
|
641 |
if ( apply_filters( 'mfrh_converts', false ) ) {
|
|
|
642 |
$new_filename = $this->remove_special_chars( $new_filename );
|
643 |
+
$new_filename = remove_accents( $new_filename );
|
644 |
$new_filename = $this->transliterate( $new_filename );
|
645 |
$new_filename = strtolower( $new_filename );
|
646 |
}
|
647 |
|
648 |
+
if ( empty( $manual_filename ) ) {
|
649 |
+
$new_filename = $this->format_hyphens( $new_filename );
|
650 |
+
}
|
651 |
+
|
652 |
// If the resulting filename had no any valid character, return NULL
|
653 |
if ( empty( $new_filename ) ) return null;
|
654 |
|
750 |
$this->log( "[!] File\t$old_filepath -> $new_filepath" );
|
751 |
return false;
|
752 |
}
|
753 |
+
update_attached_file( $id, $new_filepath );
|
754 |
$this->log( "File\t$old_filepath -> $new_filepath" );
|
755 |
do_action( 'mfrh_path_renamed', $post, $old_filepath, $new_filepath );
|
756 |
|
762 |
$meta['file'] = $this->str_replace( $old_directory, $new_directory, $meta['file'] );
|
763 |
if ( isset( $meta['url'] ) && !empty( $meta['url'] ) && count( $meta['url'] ) > 4 )
|
764 |
$meta['url'] = $this->str_replace( $old_directory, $new_directory, $meta['url'] );
|
765 |
+
wp_update_attachment_metadata( $id, $meta );
|
766 |
}
|
767 |
|
768 |
// Better to check like this rather than with wp_attachment_is_image
|
820 |
}
|
821 |
|
822 |
// Update metadata
|
823 |
+
//if ( $meta )
|
824 |
+
// wp_update_attachment_metadata( $id, $meta );
|
825 |
+
//update_attached_file( $id, $new_filepath );
|
826 |
|
827 |
// I wonder about cleaning the cache for this media. It might have no impact, and will not reset the cache for the posts using this media anyway, and it adds processing time. I keep it for now, but there might be something better to do.
|
828 |
clean_post_cache( $id );
|
960 |
$this->log( "[!] File $old_filepath -> $new_filepath" );
|
961 |
return $post;
|
962 |
}
|
963 |
+
update_attached_file( $id, $new_filepath );
|
964 |
$this->log( "File\t$old_filepath -> $new_filepath" );
|
965 |
do_action( 'mfrh_path_renamed', $post, $old_filepath, $new_filepath );
|
966 |
|
982 |
$meta['url'] = $this->str_replace( $noext_old_filename, $noext_new_filename, $meta['url'] );
|
983 |
else
|
984 |
$meta['url'] = $noext_new_filename . '.' . $old_ext;
|
985 |
+
wp_update_attachment_metadata( $id, $meta );
|
986 |
}
|
987 |
|
988 |
// Better to check like this rather than with wp_attachment_is_image
|
1047 |
}
|
1048 |
|
1049 |
$meta['sizes'][$size]['file'] = $meta_new_filename;
|
|
|
|
|
1050 |
foreach ( $meta['sizes'] as $s => $m ) {
|
1051 |
+
// Detect if another size has exactly the same filename
|
1052 |
if ( !isset( $meta['sizes'][$s]['file'] ) )
|
1053 |
continue;
|
1054 |
if ( $meta['sizes'][$s]['file'] == $meta_old_filename ) {
|
1056 |
$meta['sizes'][$s]['file'] = $meta_new_filename;
|
1057 |
}
|
1058 |
}
|
1059 |
+
wp_update_attachment_metadata( $id, $meta );
|
1060 |
|
1061 |
// Success, call other plugins
|
1062 |
$this->log( "File\t$meta_old_filepath -> $meta_new_filepath" );
|
1077 |
add_post_meta( $id, '_manual_file_renaming', true, true );
|
1078 |
|
1079 |
// Update metadata
|
1080 |
+
// if ( $meta )
|
1081 |
+
// wp_update_attachment_metadata( $id, $meta );
|
1082 |
+
//update_attached_file( $id, $new_filepath );
|
1083 |
|
1084 |
// I wonder about cleaning the cache for this media. It might have no impact, and will not reset the cache for the posts using this media anyway, and it adds processing time. I keep it for now, but there might be something better to do.
|
1085 |
clean_post_cache( $id );
|
1136 |
$force_rename,
|
1137 |
$post
|
1138 |
) {
|
1139 |
+
|
1140 |
+
// TODO: Without this check, the code following actually doesn't work with PDF Thumbnails (because the old_ext and new_ext doesn't correspond to jpg, which is used for the thumbnails in the PDF case, and not .pdf). In fact, the code after that should be rewritten.
|
1141 |
+
if ( !preg_match( '/\.webp$/', $old_filepath ) ) {
|
1142 |
+
return;
|
1143 |
+
}
|
1144 |
+
|
1145 |
// 2 patterns exist.
|
1146 |
// - filename.webp
|
1147 |
// - filename.ext.webp
|
helpers.php
CHANGED
@@ -29,7 +29,10 @@ if ( !function_exists( 'is_rest' ) ) {
|
|
29 |
$current_url = wp_parse_url( add_query_arg( array( ) ) );
|
30 |
if ( !$rest_url || !$current_url )
|
31 |
return false;
|
32 |
-
|
|
|
|
|
|
|
33 |
}
|
34 |
}
|
35 |
|
29 |
$current_url = wp_parse_url( add_query_arg( array( ) ) );
|
30 |
if ( !$rest_url || !$current_url )
|
31 |
return false;
|
32 |
+
if ( !empty( $current_url['path'] ) && !empty( $rest_url['path'] ) ) {
|
33 |
+
return strpos( $current_url['path'], $rest_url['path'], 0 ) === 0;
|
34 |
+
}
|
35 |
+
return false;
|
36 |
}
|
37 |
}
|
38 |
|
media-file-renamer.php
CHANGED
@@ -3,7 +3,7 @@
|
|
3 |
Plugin Name: Media File Renamer (Auto Rename)
|
4 |
Plugin URI: https://meowapps.com
|
5 |
Description: Renames automatically the files depending on Media titles and updates the links.
|
6 |
-
Version: 4.
|
7 |
Author: Jordy Meow
|
8 |
Author URI: https://jordymeow.com
|
9 |
Text Domain: media-file-renamer
|
@@ -32,7 +32,7 @@ require( 'helpers.php');
|
|
32 |
if ( is_admin() || is_rest() ) {
|
33 |
|
34 |
global $mfrh_version, $mfrh_core;
|
35 |
-
$mfrh_version = '4.
|
36 |
|
37 |
// Admin
|
38 |
require( 'mfrh_admin.php');
|
3 |
Plugin Name: Media File Renamer (Auto Rename)
|
4 |
Plugin URI: https://meowapps.com
|
5 |
Description: Renames automatically the files depending on Media titles and updates the links.
|
6 |
+
Version: 4.7.0
|
7 |
Author: Jordy Meow
|
8 |
Author URI: https://jordymeow.com
|
9 |
Text Domain: media-file-renamer
|
32 |
if ( is_admin() || is_rest() ) {
|
33 |
|
34 |
global $mfrh_version, $mfrh_core;
|
35 |
+
$mfrh_version = '4.7.0';
|
36 |
|
37 |
// Admin
|
38 |
require( 'mfrh_admin.php');
|
readme.txt
CHANGED
@@ -5,7 +5,7 @@ Donate link: https://commerce.coinbase.com/checkout/d047546a-77a8-41c8-9ea9-4a95
|
|
5 |
Requires at least: 4.8
|
6 |
Tested up to: 5.4
|
7 |
Requires PHP: 7.0
|
8 |
-
Stable tag: 4.
|
9 |
|
10 |
Physically renames your files nicely for a cleaner system and for a better SEO. Please read the description.
|
11 |
|
@@ -57,6 +57,10 @@ Check the FAQ on the official website, [here](https://meowapps.com/media-file-re
|
|
57 |
|
58 |
== Changelog ==
|
59 |
|
|
|
|
|
|
|
|
|
60 |
= 4.6.9 =
|
61 |
* Add: There was an issue with Auto-Rename sometimes not appearing when the Sensitive Files Check was disabled.
|
62 |
* Note: If you like it, please review the plugin [by clicking here](https://wordpress.org/support/plugin/media-file-renamer/reviews/?rate=5#new-post). It's important for us - we need motivation for all the work we want to put in the next version :)
|
5 |
Requires at least: 4.8
|
6 |
Tested up to: 5.4
|
7 |
Requires PHP: 7.0
|
8 |
+
Stable tag: 4.7.0
|
9 |
|
10 |
Physically renames your files nicely for a cleaner system and for a better SEO. Please read the description.
|
11 |
|
57 |
|
58 |
== Changelog ==
|
59 |
|
60 |
+
= 4.7.0 =
|
61 |
+
* Fix: Issue with rare characters used in the title.
|
62 |
+
* Fix: Issue with PDF thumbnails.
|
63 |
+
|
64 |
= 4.6.9 =
|
65 |
* Add: There was an issue with Auto-Rename sometimes not appearing when the Sensitive Files Check was disabled.
|
66 |
* Note: If you like it, please review the plugin [by clicking here](https://wordpress.org/support/plugin/media-file-renamer/reviews/?rate=5#new-post). It's important for us - we need motivation for all the work we want to put in the next version :)
|