/**
 * If WPML is used: Try to create automatically a Newsletter subscription page 
 * for each language, when language list is changed
 */
function alo_em_create_wpml_subscrpage_translations($settings)
{
    if (!function_exists('wpml_get_active_languages')) {
        return;
    }
    // if runs before WPML is completely loaded
    $langs = wpml_get_active_languages();
    if (is_array($langs)) {
        foreach ($langs as $lang) {
            // Original page ID
            $original_page_id = get_option('alo_em_subsc_page');
            // If the translated page doesn't exist, now create it
            if (icl_object_id($original_page_id, 'page', false, $lang['code']) == null) {
                // Found at: http://wordpress.stackexchange.com/questions/20143/plugin-wpml-how-to-create-a-translation-of-a-post-using-the-wpml-api
                $post_translated_title = get_post($original_page_id)->post_title . ' (' . $lang['code'] . ')';
                // All page stuff
                $my_page = array();
                $my_page['post_title'] = $post_translated_title;
                $my_page['post_content'] = '[ALO-EASYMAIL-PAGE]';
                $my_page['post_status'] = 'publish';
                $my_page['post_author'] = 1;
                $my_page['comment_status'] = 'closed';
                $my_page['post_type'] = 'page';
                // Insert translated post
                $post_translated_id = wp_insert_post($my_page);
                // Get trid of original post
                $trid = wpml_get_content_trid('post_' . 'page', $original_page_id);
                // Get default language
                $default_lang = wpml_get_default_language();
                // Associate original post and translated post
                global $wpdb;
                $wpdb->update($wpdb->prefix . 'icl_translations', array('trid' => $trid, 'language_code' => $lang['code'], 'source_language_code' => $default_lang), array('element_id' => $post_translated_id));
            }
        }
    }
}
Example #2
0
function motopressCEWPMLFix($post_id, $tmp_post_id, $post_type)
{
    if (defined('ICL_SITEPRESS_VERSION')) {
        global $wpdb, $sitepress;
        $content_type = 'post_' . $post_type;
        // fix #169
        if ($sitepress->is_translated_post_type($post_type) && is_file(WP_PLUGIN_DIR . '/sitepress-multilingual-cms/inc/wpml-api.php')) {
            require_once WP_PLUGIN_DIR . '/sitepress-multilingual-cms/inc/wpml-api.php';
            if (!wpml_get_content_trid($content_type, $tmp_post_id)) {
                $content_type_pattern = 'post_%';
                $translation_id = $wpdb->get_var($wpdb->prepare("SELECT translation_id FROM {$wpdb->prefix}icl_translations WHERE element_id=%d AND element_type LIKE %s", array($tmp_post_id, $content_type_pattern)));
                if ($translation_id) {
                    $wpdb->update($wpdb->prefix . 'icl_translations', array('element_type' => $content_type), array('translation_id' => $translation_id));
                }
            }
        }
        $language_code = $wpdb->get_var($wpdb->prepare('SELECT language_code FROM ' . $wpdb->prefix . 'icl_translations WHERE element_id = %d', $post_id));
        if (!is_null($language_code) && is_file(WP_PLUGIN_DIR . '/sitepress-multilingual-cms/inc/wpml-api.php')) {
            require_once WP_PLUGIN_DIR . '/sitepress-multilingual-cms/inc/wpml-api.php';
            if (wpml_get_content_trid($content_type, $tmp_post_id)) {
                wpml_update_translatable_content($content_type, $tmp_post_id, $language_code);
            } else {
                wpml_add_translatable_content($content_type, $tmp_post_id, $language_code);
            }
        }
    }
}
Example #3
0
 public function updateInsertWPMLconnection($offer_pos, $wp_post, $lang, $casawp_id)
 {
     if ($this->hasWPML()) {
         if ($this->getMainLang() == $lang) {
             $this->curtrid = wpml_get_content_trid('post_casawp_property', $wp_post->ID);
         }
         $_POST['icl_post_language'] = $lang;
         global $sitepress;
         if ($this->getMainLang() != $lang) {
             $sitepress->set_element_language_details($wp_post->ID, 'post_casawp_property', $this->curtrid, $lang, $sitepress->get_default_language(), true);
         } else {
             $sitepress->set_element_language_details($wp_post->ID, 'post_casawp_property', $this->curtrid, $lang, NULL, true);
         }
     }
 }