Version Description
- Update: Now uploading Media into Post rename the filename accordingly.
Download this release
Release Info
Developer | TigrouMeow |
Plugin | Media File Renamer |
Version | 3.7.2 |
Comparing to | |
See all releases |
Code changes from version 3.7.1 to 3.7.2
- core.php +35 -8
- media-file-renamer.php +2 -2
- readme.txt +4 -1
core.php
CHANGED
@@ -396,27 +396,54 @@ class Meow_MFRH_Core {
|
|
396 |
return get_post( $postid, OBJECT );
|
397 |
}
|
398 |
|
|
|
|
|
|
|
|
|
399 |
function wp_handle_upload_prefilter( $file ) {
|
400 |
|
|
|
|
|
401 |
// If everything's fine, renames in based on the Title in the EXIF
|
402 |
$method = apply_filters( 'mfrh_method', 'media_title' );
|
403 |
if ( $method == 'media_title' ) {
|
404 |
$exif = wp_read_image_metadata( $file['tmp_name'] );
|
405 |
if ( !empty( $exif ) && isset( $exif[ 'title' ] ) && !empty( $exif[ 'title' ] ) ) {
|
406 |
-
$
|
407 |
-
$file
|
|
|
|
|
|
|
|
|
|
|
|
|
408 |
return $file;
|
409 |
}
|
410 |
}
|
411 |
|
412 |
// Otherwise, let's do the basics based on the filename
|
413 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
414 |
$pp = pathinfo( $file['name'] );
|
415 |
$file['name'] = $this->new_filename( null, $pp['basename'] );
|
416 |
-
error_log( "AFTER: " . $file['name'] );
|
417 |
return $file;
|
418 |
}
|
419 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
420 |
// Return false if everything is fine, otherwise return true with an output.
|
421 |
function check_attachment( $id, &$output = array() ) {
|
422 |
$method = apply_filters( 'mfrh_method', 'media_title' );
|
@@ -816,8 +843,8 @@ class Meow_MFRH_Core {
|
|
816 |
function log_sql( $data, $antidata ) {
|
817 |
if ( !get_option( 'mfrh_logsql' ) || !$this->mfrh_admin->is_registered() )
|
818 |
return;
|
819 |
-
$fh = fopen( trailingslashit( dirname(__FILE__) ) . '
|
820 |
-
$fh_anti = fopen( trailingslashit( dirname(__FILE__) ) . '
|
821 |
$date = date( "Y-m-d H:i:s" );
|
822 |
fwrite( $fh, "{$data}\n" );
|
823 |
fwrite( $fh_anti, "{$antidata}\n" );
|
@@ -875,13 +902,13 @@ class Meow_MFRH_Core {
|
|
875 |
// Media already exists (not a fresh upload). Gets filename and ext.
|
876 |
$old_filepath = get_attached_file( $media['ID'] );
|
877 |
$pp = pathinfo( $old_filepath );
|
878 |
-
$new_ext = $pp['extension'];
|
879 |
$old_filename = $pp['basename'];
|
880 |
}
|
881 |
else {
|
882 |
// It's an upload, let's check if the extension is provided in the text
|
883 |
$pp = pathinfo( $text );
|
884 |
-
$new_ext = $pp['extension'];
|
885 |
$text = $pp['filename'];
|
886 |
}
|
887 |
|
396 |
return get_post( $postid, OBJECT );
|
397 |
}
|
398 |
|
399 |
+
/*****************************************************************************
|
400 |
+
RENAME ON UPLOAD
|
401 |
+
*****************************************************************************/
|
402 |
+
|
403 |
function wp_handle_upload_prefilter( $file ) {
|
404 |
|
405 |
+
$pp = pathinfo( $file['name'] );
|
406 |
+
|
407 |
// If everything's fine, renames in based on the Title in the EXIF
|
408 |
$method = apply_filters( 'mfrh_method', 'media_title' );
|
409 |
if ( $method == 'media_title' ) {
|
410 |
$exif = wp_read_image_metadata( $file['tmp_name'] );
|
411 |
if ( !empty( $exif ) && isset( $exif[ 'title' ] ) && !empty( $exif[ 'title' ] ) ) {
|
412 |
+
$file['name'] = $this->new_filename( null, $exif[ 'title' ] ) . '.' . $pp['extension'];
|
413 |
+
return $file;
|
414 |
+
}
|
415 |
+
}
|
416 |
+
else if ( $method == 'post_title' && isset( $_POST['post_id'] ) && $_POST['post_id'] > 0 ) {
|
417 |
+
$post = get_post( $_POST['post_id'] );
|
418 |
+
if ( !empty( $post ) && !empty( $post->post_title ) ) {
|
419 |
+
$file['name'] = $this->new_filename( null, $post->post_title ) . '.' . $pp['extension'];
|
420 |
return $file;
|
421 |
}
|
422 |
}
|
423 |
|
424 |
// Otherwise, let's do the basics based on the filename
|
425 |
+
|
426 |
+
// The name will be modified at this point so let's keep it in a global
|
427 |
+
// and re-inject it later
|
428 |
+
global $mfrh_title_override;
|
429 |
+
$mfrh_title_override = $pp['filename'];
|
430 |
+
add_filter( 'wp_read_image_metadata', array( $this, 'wp_read_image_metadata' ), 10, 2 );
|
431 |
+
|
432 |
+
// Modify the filename
|
433 |
$pp = pathinfo( $file['name'] );
|
434 |
$file['name'] = $this->new_filename( null, $pp['basename'] );
|
|
|
435 |
return $file;
|
436 |
}
|
437 |
|
438 |
+
function wp_read_image_metadata( $meta, $file ) {
|
439 |
+
// Override the title, without this it is using the new filename
|
440 |
+
global $mfrh_title_override;
|
441 |
+
$meta['title'] = $mfrh_title_override;
|
442 |
+
return $meta;
|
443 |
+
}
|
444 |
+
|
445 |
+
/****************************************************************************/
|
446 |
+
|
447 |
// Return false if everything is fine, otherwise return true with an output.
|
448 |
function check_attachment( $id, &$output = array() ) {
|
449 |
$method = apply_filters( 'mfrh_method', 'media_title' );
|
843 |
function log_sql( $data, $antidata ) {
|
844 |
if ( !get_option( 'mfrh_logsql' ) || !$this->mfrh_admin->is_registered() )
|
845 |
return;
|
846 |
+
$fh = fopen( trailingslashit( dirname(__FILE__) ) . 'mfrh_sql.log', 'a' );
|
847 |
+
$fh_anti = fopen( trailingslashit( dirname(__FILE__) ) . 'mfrh_sql_revert.log', 'a' );
|
848 |
$date = date( "Y-m-d H:i:s" );
|
849 |
fwrite( $fh, "{$data}\n" );
|
850 |
fwrite( $fh_anti, "{$antidata}\n" );
|
902 |
// Media already exists (not a fresh upload). Gets filename and ext.
|
903 |
$old_filepath = get_attached_file( $media['ID'] );
|
904 |
$pp = pathinfo( $old_filepath );
|
905 |
+
$new_ext = empty( $pp['extension'] ) ? "" : $pp['extension'];
|
906 |
$old_filename = $pp['basename'];
|
907 |
}
|
908 |
else {
|
909 |
// It's an upload, let's check if the extension is provided in the text
|
910 |
$pp = pathinfo( $text );
|
911 |
+
$new_ext = empty( $pp['extension'] ) ? "" : $pp['extension'];
|
912 |
$text = $pp['filename'];
|
913 |
}
|
914 |
|
media-file-renamer.php
CHANGED
@@ -3,7 +3,7 @@
|
|
3 |
Plugin Name: Media File Renamer
|
4 |
Plugin URI: http://meowapps.com
|
5 |
Description: Auto-rename the files when titles are modified and update and the references (links). Manual Rename is a Pro option. Please read the description.
|
6 |
-
Version: 3.7.
|
7 |
Author: Jordy Meow
|
8 |
Author URI: http://meowapps.com
|
9 |
Text Domain: media-file-renamer
|
@@ -29,7 +29,7 @@ if ( class_exists( 'Meow_MFRH_Core' ) ) {
|
|
29 |
if ( is_admin() ) {
|
30 |
|
31 |
global $mfrh_version, $mfrh_core;
|
32 |
-
$mfrh_version = '3.7.
|
33 |
|
34 |
// Admin
|
35 |
require( 'mfrh_admin.php');
|
3 |
Plugin Name: Media File Renamer
|
4 |
Plugin URI: http://meowapps.com
|
5 |
Description: Auto-rename the files when titles are modified and update and the references (links). Manual Rename is a Pro option. Please read the description.
|
6 |
+
Version: 3.7.2
|
7 |
Author: Jordy Meow
|
8 |
Author URI: http://meowapps.com
|
9 |
Text Domain: media-file-renamer
|
29 |
if ( is_admin() ) {
|
30 |
|
31 |
global $mfrh_version, $mfrh_core;
|
32 |
+
$mfrh_version = '3.7.2';
|
33 |
|
34 |
// Admin
|
35 |
require( 'mfrh_admin.php');
|
readme.txt
CHANGED
@@ -3,7 +3,7 @@ Contributors: TigrouMeow
|
|
3 |
Tags: rename, file, media, management, image, renamer, wpml, wp-retina-2x
|
4 |
Requires at least: 4.2
|
5 |
Tested up to: 4.8
|
6 |
-
Stable tag: 3.7.
|
7 |
|
8 |
Automatically rename files depending on Media titles dynamically + update links. Pro version has many more options. Check the description :)
|
9 |
|
@@ -100,6 +100,9 @@ You are welcome to create plugins using Media File Renamer using special rules f
|
|
100 |
|
101 |
== Changelog ==
|
102 |
|
|
|
|
|
|
|
103 |
= 3.7.1 =
|
104 |
* Fix: Rename on Upload issue in a few cases.
|
105 |
|
3 |
Tags: rename, file, media, management, image, renamer, wpml, wp-retina-2x
|
4 |
Requires at least: 4.2
|
5 |
Tested up to: 4.8
|
6 |
+
Stable tag: 3.7.2
|
7 |
|
8 |
Automatically rename files depending on Media titles dynamically + update links. Pro version has many more options. Check the description :)
|
9 |
|
100 |
|
101 |
== Changelog ==
|
102 |
|
103 |
+
= 3.7.2 =
|
104 |
+
* Update: Now uploading Media into Post rename the filename accordingly.
|
105 |
+
|
106 |
= 3.7.1 =
|
107 |
* Fix: Rename on Upload issue in a few cases.
|
108 |
|