function bundled_themes_support_flag() { $current_parent_theme = get_option('template'); $current_theme = get_option('stylesheet'); if (in_array($current_parent_theme, array('twentyten', 'twentyeleven', 'twentytwelve', 'twentythirteen', 'twentyfifteen', 'twentysixteen'))) { add_theme_support('custom_xili_flag'); // same name as used in context of image } if (in_array($current_theme, array('twentyfourteen-xili', 'twentyfifteen-xili', 'twentysixteen-xili'))) { xili_xl_error_log('*********** bundled_themes_support_flag for ' . $current_theme); remove_theme_support('custom_xili_flag'); $args = array(); $listlanguages = $this->get_listlanguages(); foreach ($listlanguages as $one_language) { $path_root = get_stylesheet_directory(); $path = '%2$s/images/flags/' . $one_language->slug . '.png'; if (file_exists(sprintf($path, '', $path_root))) { $args[$one_language->slug] = array('path' => $path, 'height' => 16, 'width' => 11); } } // path and size - %2$s = child theme /* 'de_de' => array( 'path' => '%2$s/images/flags/de_de.png', 'height' => 16, 'width' => 11), */ add_theme_support('custom_xili_flag', $args); } }
/** * set language when post or page is saved or changed * * @since 0.9.0 * @completed 0.9.7.1 to record postmeta of linked posts in other languages * @updated 0.9.7.5 to delete relationship when undefined * @updated 0.9.9 to avoid delete relationship when in quick_edit * @updated 1.3.0 to avoid delete relationship when trashing - 1.4.1 - create post-meta xl-search-linked * @updated 1.8.9.3 for bulk edit... * @updated 2.5, 2.6 * @updated 2.9.10 bulk edit via ajax * * @param $post_ID */ function xili_language_add($post_ID, $post) { $posttypes = array_keys($this->xili_settings['multilingual_custom_post']); $posttypes[] = 'post'; $posttypes[] = 'page'; $thetype = $post->post_type; if (in_array($thetype, $posttypes)) { $listlanguages = $this->get_listlanguages(); $previous_lang = $this->get_post_language($post_ID); if (isset($_POST['_inline_edit'])) { /* when in quick_edit (edit.php) */ $sellang = $_POST['xlpop']; if ("" != $sellang) { if ($sellang != $previous_lang) { // move a language // clean linked targets foreach ($listlanguages as $language) { $target_id = get_post_meta($post_ID, QUETAG . '-' . $language->slug, true); if ($target_id != "") { if ($previous_lang != '') { delete_post_meta($target_id, QUETAG . '-' . $previous_lang); } update_post_meta($target_id, QUETAG . '-' . $sellang, $post_ID); } } wp_delete_object_term_relationships($post_ID, TAXONAME); } $return = wp_set_object_terms($post_ID, $sellang, TAXONAME); xili_xl_error_log('# ' . __LINE__ . ' ---- wp_set_object_terms --- ' . serialize($return)); } else { // undefined if (!isset($_GET['action'])) { // trash - edit // clean linked targets foreach ($listlanguages as $language) { //delete_post_meta( $post_ID, QUETAG.'-'.$language->slug ); // erase translated because undefined $target_id = get_post_meta($post_ID, QUETAG . '-' . $language->slug, true); if ($target_id != "") { delete_post_meta($target_id, QUETAG . '-' . $previous_lang); } } wp_delete_object_term_relationships($post_ID, TAXONAME); } } // bulk-edit via ajax 2.9.10 } else { if (isset($_GET['bulk_edit'])) { return; } else { // post-edit single $sellang = isset($_POST['xili_language_set']) ? $_POST['xili_language_set'] : ""; if ("" != $sellang && "undefined" != $sellang) { if ($sellang != $previous_lang && $previous_lang != '') { // move a language // clean linked targets foreach ($listlanguages as $language) { $target_id = get_post_meta($post_ID, QUETAG . '-' . $language->slug, true); if ($target_id != "") { delete_post_meta($target_id, QUETAG . '-' . $previous_lang); update_post_meta($target_id, QUETAG . '-' . $sellang, $post_ID); } } wp_delete_object_term_relationships($post_ID, TAXONAME); } $return = wp_set_object_terms($post_ID, $sellang, TAXONAME); xili_xl_error_log('# ' . __LINE__ . ' ---- wp_set_object_terms --- ' . serialize($return)); } elseif ("undefined" == $sellang) { // clean linked targets foreach ($listlanguages as $language) { $target_id = get_post_meta($post_ID, QUETAG . '-' . $language->slug, true); if ($target_id != "") { delete_post_meta($target_id, QUETAG . '-' . $previous_lang); } } // now undefined wp_delete_object_term_relationships($post_ID, TAXONAME); } $curlang = $this->get_cur_language($post_ID); // array /* the linked posts set by author in postmeta */ foreach ($listlanguages as $language) { $inputid = 'xili_language_' . QUETAG . '-' . $language->slug; $recinputid = 'xili_language_rec_' . QUETAG . '-' . $language->slug; $linkid = isset($_POST[$inputid]) ? $_POST[$inputid] : 0; $reclinkid = isset($_POST[$recinputid]) ? $_POST[$recinputid] : 0; /* hidden previous value */ $langslug = QUETAG . '-' . $language->slug; if ($reclinkid != $linkid) { /* only if changed value or created since 1.3.0 */ if (is_numeric($linkid) && $linkid == 0 || '' == $linkid) { delete_post_meta($post_ID, $langslug); } elseif (is_numeric($linkid) && $linkid > 0) { // test if possible 2.5.1 if ($this->is_post_free_for_link($post_ID, $curlang[QUETAG], $language->slug, $linkid)) { update_post_meta($post_ID, $langslug, $linkid); if ($reclinkid == "-1") { update_post_meta($linkid, QUETAG . '-' . $sellang, $post_ID); } // update target 2.5 foreach ($listlanguages as $metalanguage) { if ($metalanguage->slug != $language->slug && $metalanguage->slug != $curlang[QUETAG]) { $id = get_post_meta($post_ID, QUETAG . '-' . $metalanguage->slug, true); if ($id != "") { update_post_meta($linkid, QUETAG . '-' . $metalanguage->slug, $id); } } } update_post_meta($linkid, QUETAG . '-' . $curlang[QUETAG], $post_ID); // cur post $return = wp_set_object_terms($linkid, $language->slug, TAXONAME); xili_xl_error_log('# ' . __LINE__ . ' ---- wp_set_object_terms --- ' . serialize($return)); } } } } } } } }
/** * insert lang rewrite tag in $url of post, CPT, Category and Taxonomy links * * @updated 1.1.2 - short link of post * @updated 2.16.6 - add filter for json link */ function insert_lang_tag_root($url, $path, $orig_scheme, $blog_id) { // isset( $wp_query->query_vars['json_route']) if (true === apply_filters('xili_json_dont_insert_lang_tag_root', false, $url, $path, $orig_scheme, $blog_id)) { return $url; } // for JSON REST API 2.16.5 if (false !== strpos($url, $this->rew_reqtag)) { return $url; } // to avoid twice insertion global $xili_language; $enabled_custom_posts = $enabled_custom_post_types = array(); // fixes with only enabled 2.10.1 foreach ($xili_language->xili_settings['multilingual_custom_post'] as $post_type => $values) { if ($values['multilingual'] == 'enable') { $enabled_custom_posts[] = '\\/' . $post_type . '\\/'; $enabled_custom_post_types[] = $post_type; } } if ($enabled_custom_posts) { $pattern = '/(' . implode('|', $enabled_custom_posts) . ')/'; } else { $pattern = ''; } $tax_base = array(); $category_base_option = get_option('category_base'); $tax_base[] = $category_base_option ? $category_base_option : 'category'; // à centraliser si class - ajouter "date" if (class_exists('xili_tidy_tags')) { // now gives lang of tags $tag_base_option = get_option('tag_base'); $tax_base[] = $tag_base_option ? $tag_base_option : 'tag'; } $authorized_custom_taxonomies = $xili_language->authorized_custom_taxonomies($enabled_custom_post_types); $tax_base = array_merge($tax_base, $this->always_insert, $authorized_custom_taxonomies); $tax_base_slash = array(); foreach ($tax_base as $base) { $tax_base_slash[] = '\\/' . $base . '\\/'; } $pattern_tax = '/(' . implode('|', $tax_base_slash) . ')/'; // add / around if (class_exists('bbpress')) { if ($path == bbp_get_root_slug() . '/') { $replace = $xili_language->lang_slug_qv_trans($xili_language->default_slug); $url = str_replace($path, $replace . '/' . $path, $url); return $url; } else { if (false !== strpos($path, bbp_get_root_slug()) && preg_match($pattern, $path)) { $url = str_replace($path, $this->rew_reqtag . '/' . $path, $url); return $url; } } } if ($pattern && preg_match($pattern, $path)) { xili_xl_error_log(__CLASS__ . ' # ' . __LINE__ . ' ' . $path . ' ici 1 ' . $url); // CPT $path = substr($path, 0, 1) == '/' ? $path : '/' . $path; $url = str_replace($path, '/' . $this->rew_reqtag . $path, $url); } else { if (preg_match($pattern_tax, $path)) { $url = str_replace($path, '/' . $this->rew_reqtag . $path, $url); xili_xl_error_log(__CLASS__ . ' # ' . __LINE__ . ' ici 2 tax ' . $url); } else { if ('' != $path && '/' != substr($path, 0, 1) && false === strpos($path, $this->rew_reqtag)) { $url = str_replace($path, $this->rew_reqtag . '/' . $path, $url); xili_xl_error_log(__CLASS__ . ' # ' . __LINE__ . ' ici 3 ' . $url); // page } } } return $url; }