Last active
September 25, 2018 13:13
-
-
Save srdjan-jcc/5c47685cda4da471dff5757ba3ce5ab1 to your computer and use it in GitHub Desktop.
Compress JPEG & PNG images and WPML
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Plugin Name: Compress JPEG & PNG images and WPML | |
Description: Synchronizes localized images | |
Version: 0.0.2 | |
*/ | |
add_action( 'updated_tiny_postmeta', 'wpml_updated_tiny_postmeta', 10, 3 ); | |
function wpml_updated_tiny_postmeta( $post_id, $meta_key, $meta_value ) { | |
$trid = apply_filters( 'wpml_element_trid', null, $post_id, 'post_attachment' ); | |
if ( $trid ) { | |
$attachments = apply_filters( 'wpml_get_element_translations', array(), $trid, 'post_attachment' ); | |
$attached_file = get_attached_file( $post_id ); | |
foreach ( $attachments as $language_code => $attachment ) { | |
// Check if file is different for localized image | |
$localized_file = get_attached_file( $attachment->element_id ); | |
if ( $attachment->element_id != $post_id | |
&& $localized_file == $attached_file ) { | |
update_post_meta( $attachment->element_id, $meta_key, $meta_value ); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment