Skip to content

Instantly share code, notes, and snippets.

@BhargavBhandari90
Created May 26, 2017 14:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BhargavBhandari90/936b6b0efd27bcb84868d79dc9bc971b to your computer and use it in GitHub Desktop.
Save BhargavBhandari90/936b6b0efd27bcb84868d79dc9bc971b to your computer and use it in GitHub Desktop.
Add currecnt languge slug of WPML to media url in activity stream.
<?php
/**
* Add this code snippet to theme's functions.php
*
* Add currecnt languge slug of WPML to media url in activity stream.
*
*/
if ( ! function_exists( 'rtmedia_wpml_activity_urls' ) ) {
function rtmedia_wpml_activity_urls( $permalink, $media, $id ) {
global $sitepress;
// Get media ids array.
$medias = ( isset( $_POST['rtMedia_attached_files'] ) && ! empty( $_POST['rtMedia_attached_files'] ) ) ? $_POST['rtMedia_attached_files'] : array();
// Get current language.
$lang_slug = ( isset( $_GET['lang'] ) && ! empty( $_GET['lang'] ) ) ? sanitize_text_field( wp_unslash( $_GET['lang'] ) ) : '';
if ( ! empty( $lang_slug ) && isset( $_POST['action'] ) && 'post_update' === $_POST['action'] && ! empty( $medias ) && $sitepress->get_default_language() !== $lang_slug ) {
$link = site_url();
// replace site url with current language slug.
$permalink = str_replace( $link, $link . '/' . $lang_slug, $permalink );
}
return $permalink;
}
}
add_filter( 'get_rtmedia_permalink', 'rtmedia_wpml_activity_urls', 99, 3 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment