WordPress.org

Ready to get started?Download WordPress

Forums

Media File Renamer
[resolved] WPML compatibility (0.34, patch) (14 posts)

  1. lkraav
    Member
    Posted 2 years ago #

    So with WPML and Media Translator plugin you run into a situation where if you modify meta of different languages, MFR will kill the correct filenames for other languages. There's probably no totally trivial solution to this, although I guess I would suggest creating symlinks to get_default_language()-associated filenames. But in the meanwhile, I'm suggesting something like this:

    25 function mfrh_attachment_fields_to_save( $post, $attachment ) {
     26     // Make sure we only operate on filenames of default language
     27     // Symlinking to other languages could be an option                                                               28     global $sitepress;
     29     if ( $sitepress && $sitepress->get_current_language() != $sitepress->get_default_language() )
     30         return $post;

    http://wordpress.org/extend/plugins/media-file-renamer/

  2. Jordy Meow
    Member
    Plugin Author

    Posted 2 years ago #

    Hey Ikraav, thank you a lot for finding this. I use WPML but I didn't even knew there was a Media Translator plugin. Symlinking would be a bit difficult, as it depends of the system / partition used... So I'd rather use your code instead to avoid that issue. What is $sitepress though?

  3. lkraav
    Member
    Posted 2 years ago #

    Right, symlinking is indeed x-platform problematic and would require respective handling. OTOH it would be nice to be able to provide effective multi-language file names as well..

    Re Media Translator, I also didn't pay attention to it at first sight until customer asked about translatable image meta.

    $sitepress is the gateway variable to the WPML instance. WPML's real name is actually "SitePress Multi-Lingual CMS Thingamathingiemegasuper Something".

  4. Jordy Meow
    Member
    Plugin Author

    Posted 2 years ago #

    Oh okay :) I'd prefer to use is_function with one of the function used by the Media Translator plugin.

    Though I don't see a huge advantage to use that plugin, I get most of my google results thanks to my "renamed" media file, and not really from the name/alt of the media. But yeah, I will add this code to MFR, to avoid any issue while using it. Time for an update!

  5. lkraav
    Member
    Posted 2 years ago #

    My patch doesn't actually seem to work, those functions don't return the correct language information. Must look through Media Translator source to see how they process media language info.

  6. lkraav
    Member
    Posted 2 years ago #

    OK so this would be a start to protect translations, but it's more complicated than that:

    25 function mfrh_attachment_notice() {
     26     echo "<div class=\"updated\">Media File Renamer: File was not renamed, because it was not in the default language</div>";
     27 }
     28
     29 function mfrh_attachment_fields_to_save( $post, $attachment ) {
     30     // Make sure we only operate on filenames of default language
     31     // Symlinking to other languages could be an option, but requires platform specific handling
     32     global $sitepress, $WPML_media;
     33
     34     if ( $WPML_media ) {
     35         $translations = $WPML_media->_get_translations( $post[ "ID" ] );
     36         if ( $sitepress && ! empty( $translations ) && $post[ "ID" ] != $translations[ $sitepress->get_default_language() ] ) {
     37             # admin_notices doesn't work here for some reason
     38             add_action( "admin_notices", "mfrh_attachment_notice" );
     39             return $post;
     40         }
     41     }

    Problem is the "Duplicate uploaded media to translations" checkbox. If this is on for a post, it will fire immediately for all attachments if you edit any original language attachments.

    This means MFR will have to the a thorough

    $translations = $WPML_media->_get_translations( $post[ "ID" ] );

    type thing lower in the code as well, probably somewhere at, looping through all the translations and saving the new filename into all translations:

    85     // Update the attachment meta
     86     $meta = wp_get_attachment_metadata( $post['ID'] );

    Right now, one would have to make sure no posts have automatic duplication checked, then process all filenames in default language, and then enable automatic duplication to translations.

  7. Jordy Meow
    Member
    Plugin Author

    Posted 1 year ago #

    I will come back to you on this soon, I'm about to restart my work on this plugin and I want it to work perfectly with WPML and the Media Translator.

  8. lkraav
    Member
    Posted 1 year ago #

    (y) as you probably know, WPML just relased 2.5.0, WPML Media was also bumped to 1.3.0 I believe.

  9. Jordy Meow
    Member
    Plugin Author

    Posted 1 year ago #

    Yes but it still work the same with MFR it seems :)

  10. lkraav
    Member
    Posted 1 year ago #

    Yeah, the diff wasn't anything significant. Anyway, write here if you get stuck anywhere, I can probably help.

  11. Jordy Meow
    Member
    Plugin Author

    Posted 1 year ago #

    Okay super, I think I will use you soon, Thanks a lot for your help :)

  12. Jordy Meow
    Member
    Plugin Author

    Posted 1 year ago #

    I did a bunch of changes and released a new version of Media File Renamer. The plugin is way safer now + it works with WPML. I didn't try it with your plugin though, you could give it another try and see how well it play together? Thanks a lot. Let's start another thread if there are issues.

  13. lkraav
    Member
    Posted 1 year ago #

    Wdym "my plugin"? WPML Media Translator is another official WPML plugin. Check their download section.

  14. Jordy Meow
    Member
    Plugin Author

    Posted 1 year ago #

    Haha, sorry, I meant the plugin YOU are using :) Okay I am going to try today, and will try to work on the issue if I find any.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic