Advertisement
TouchWare

WPML Languages Fix

Jul 30th, 2014
35
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.18 KB | None | 0 0
  1. <?php
  2. /*
  3. Addon Name: WPML Languages
  4. Description: Fixes language insertion problem on WPML multilingual sites.
  5. Author: Arnold Bailey (Incsub)
  6. Author URI: http://premium.wpmudev.org
  7. Since version: 4.0.8
  8. */
  9.  
  10.  
  11. if(! class_exists('Autoblog_WPML_languages') ):
  12. class Autoblog_WPML_languages{
  13.  
  14.     function __construct(){
  15.         add_action( 'init', array(&$this,'on_init'), 10, 3 );
  16.         //TOUCHWARE
  17.         echo "<script type='text/javascript'>alert('I initiated');</script>";
  18.     }
  19.  
  20.     function on_init(){
  21.         if( ! defined('ICL_SITEPRESS_VERSION')) return; //no wpml
  22.         //TOUCHWARE
  23.         echo "<script type='text/javascript'>alert('I found WPML');</script>";
  24.  
  25.         add_action( 'autoblog_post_post_update', array(&$this,'notify_wpml'), 10, 3 );
  26.         add_action( 'autoblog_post_post_insert', array(&$this,'notify_wpml'), 10, 3 );
  27.  
  28.     }
  29.  
  30.     function get_feed_language( SimplePie_Item $item ){
  31.         global $wpdb;
  32.  
  33.         if( !defined('ICL_SITEPRESS_VERSION')) return; //no wpml
  34.  
  35.         if($feed = $item->get_feed()){
  36.             $language_code = $feed->get_language();
  37.             $language_code = empty($language_code) ? get_locale() : $language_code;
  38.         }
  39.  
  40.         if($language_code){
  41.             $language_code = $wpdb->get_var($wpdb->prepare("SELECT code FROM {$wpdb->prefix}icl_languages WHERE tag=%s", $language_code));
  42.             //TOUCHWARE
  43.             echo "<script type='text/javascript'>alert('$language_code');</script>";
  44.         }
  45.  
  46.         return $language_code;
  47.     }
  48.  
  49.     function notify_wpml( $post_id, array $details, SimplePie_Item $item) {
  50.         global $wpdb;
  51.  
  52.         if( !defined('ICL_SITEPRESS_VERSION')) return; //no wpml
  53.         if(empty($post_id) ) return $post_id; //No post id
  54.  
  55.         $language_code = $this->get_feed_language($item);
  56.  
  57.         global $sitepress;
  58.  
  59.         global $sitepress;
  60.  
  61.         $trid = (int)$wpdb->get_var(("SELECT MAX(trid) FROM {$wpdb->prefix}icl_translations"));
  62.         $sitepress->set_element_language_details($post_id, $el_type='post_post', null , $language_code, null);
  63.  
  64.         //update the cache
  65.         $languages = icl_cache_get('posts_per_language');
  66.         if($languages && array_key_exists($language_code, $languages)){
  67.             $languages[$language_code] += 1;
  68.             $languages['all'] += 1;
  69.             icl_cache_set('posts_per_language', $languages);
  70.         }
  71.  
  72.     }
  73. }
  74.  
  75. new Autoblog_WPML_languages;
  76.  
  77. endif;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement