/** * Sync porduct meta * * @return false if the current post type is not "porduct" */ public function syncProductsMeta() { $currentScreen = get_current_screen(); if ($currentScreen->post_type !== 'product') { return false; } // sync product meta with polylang add_filter('pll_copy_post_metas', array(__CLASS__, 'getProductMetaToCopy')); $ID = false; $disable = false; /* * Disable editing product meta for translation * * if the "post" is defined in $_GET then we should check if the current * porduct has a translation and it is the same as the default translation * lang defined in polylang then porduct meta editing must by enabled * * if the "new_lang" is defined or if the current page is the "edit" * page then porduct meta editing must by disabled */ if (isset($_GET['post'])) { $ID = absint($_GET['post']); $disable = $ID && pll_get_post_language($ID) != pll_default_language(); } elseif (isset($_GET['new_lang']) || $currentScreen->base == 'edit') { $disable = isset($_GET['new_lang']) && esc_attr($_GET['new_lang']) != pll_default_language() ? true : false; $ID = isset($_GET['from_post']) ? absint($_GET['from_post']) : false; } // disable fields edit for translation if ($disable) { add_action('admin_print_scripts', array($this, 'addFieldsLocker'), 100); } /* sync selected prodcut type */ $this->syncSelectedProdcutType($ID); }
/** * Translate the rewrite rules. */ public function taxonomy_rewrite_rules_filter($rewrite_rules) { global $polylang, $wp_rewrite; $translated_rules = array(); // For each lang. foreach ($this->translated_slugs as $lang => $translated_slug) { // If "Hide URL language information for default language" option is // set to true the rules has to be different for the default language. if ($polylang->options['hide_default'] && $lang == pll_default_language()) { // For each rule. foreach ($rewrite_rules as $rule_key => $rule_value) { // Only translate the rewrite slug. $translated_rules[str_replace(trim($this->taxonomy_object->rewrite['slug'], '/'), $translated_slug, $rule_key)] = $rule_value; } } else { // For each rule. foreach ($rewrite_rules as $rule_key => $rule_value) { $taxonomy_rewrite_slug = $this->taxonomy_object->rewrite['slug']; // Replace the rewrite tags in slugs. foreach ($wp_rewrite->rewritecode as $position => $code) { $taxonomy_rewrite_slug = str_replace($code, $wp_rewrite->rewritereplace[$position], $taxonomy_rewrite_slug); $translated_slug = str_replace($code, $wp_rewrite->rewritereplace[$position], $translated_slug); } // Shift the matches up cause "lang" will be the first. $translated_rules['(' . $lang . ')/' . str_replace(trim($taxonomy_rewrite_slug, '/'), $translated_slug, $rule_key)] = str_replace(array('[8]', '[7]', '[6]', '[5]', '[4]', '[3]', '[2]', '[1]'), array('[9]', '[8]', '[7]', '[6]', '[5]', '[4]', '[3]', '[2]'), $rule_value); } } } return $translated_rules; }
/** * Get available languages. */ private function get_languages() { if ($this->plugin === 'Polylang') { global $polylang; // set default language $this->default_lang = pll_default_language(); // set languages $registered_languages = $polylang->model->get_languages_list(); if (!empty($registered_languages)) { foreach ($registered_languages as $language) { $this->languages[] = $language->slug; } } } elseif ($this->plugin === 'WPML') { global $sitepress; // set default language $this->default_lang = $sitepress->get_default_language(); // set languages $registered_languages = icl_get_languages(); if (!empty($registered_languages)) { foreach ($registered_languages as $language) { $this->languages[] = $language['language_code']; } } } // remove default language if (($key = array_search($this->default_lang, $this->languages)) !== false) { unset($this->languages[$key]); } }
/** * Action: Set Language * * @param string $lang_slug * @param object $current_lang Current language */ public function set_language($lang_slug, $current_lang) { $this->default_lang = pll_default_language(); $this->current_lang = pll_current_language(); acf_update_setting('default_language', $this->default_lang); acf_update_setting('current_language', $this->current_lang); }
public function create_nav_menu_locations() { static $once; global $_wp_registered_nav_menus; if (isset($_wp_registered_nav_menus) && !$once) { foreach ($_wp_registered_nav_menus as $loc => $name) { foreach ($this->model->get_languages_list() as $lang) { $arr[$loc . (pll_default_language() == $lang->slug ? '' : '___' . $lang->slug)] = $name . ' ' . $lang->name; } } $_wp_registered_nav_menus = $arr; $once = true; } }
/** * Prints the languages currently available * * ## EXAMPLES * * wp polylang languages * * @synopsis * @alias langs */ function languages($args, $assocArgs) { $languages = pll_get_languages_list(); if (!count($languages)) { WP_CLI::success("Less than two languages are currently configurated."); return; } $default = pll_default_language(); foreach ($languages as $language) { $line = "{$language->slug} — {$language->name}"; if ($language->slug == $default) { $line .= ' [DEFAULT]'; } WP_CLI::line($line); } }
/** * Sync product meta. * * @return false if the current post type is not "product" */ public function syncProductsMeta() { // sync product meta with polylang add_filter('pll_copy_post_metas', array(__CLASS__, 'getProductMetaToCopy')); // Shipping Class translation is not supported after WooCommerce 2.6 but it is // still implemented by WooCommerce as a taxonomy. Therefore Polylang will not // copy the Shipping Class meta. We need to take care of it. if (Utilities::woocommerceVersionCheck('2.6')) { add_action('wp_insert_post', array($this, 'syncShippingClass'), 10, 3); } $currentScreen = get_current_screen(); if ($currentScreen->post_type !== 'product') { return false; } $ID = false; $disable = false; /* * Disable editing product meta for translation * * if the "post" is defined in $_GET then we should check if the current * product has a translation and it is the same as the default translation * lang defined in polylang then product meta editing must by enabled * * if the "new_lang" is defined or if the current page is the "edit" * page then product meta editing must by disabled */ if (isset($_GET['post'])) { $ID = absint($_GET['post']); $disable = $ID && pll_get_post_language($ID) != pll_default_language(); } elseif (isset($_GET['new_lang']) || $currentScreen->base == 'edit') { $disable = isset($_GET['new_lang']) && esc_attr($_GET['new_lang']) != pll_default_language() ? true : false; $ID = isset($_GET['from_post']) ? absint($_GET['from_post']) : false; // Add the '_translation_porduct_type' meta, for the case where // the product was created before plugin acivation. $this->addProductTypeMeta($ID); } // disable fields edit for translation if ($disable) { add_action('admin_print_scripts', array($this, 'addFieldsLocker'), 100); } /* sync selected product type */ $this->syncSelectedproductType($ID); }
public function shim_untranslated($query_args, $args) { $def_lang = pll_default_language(); $cur_lang = pll_current_language(); $mixed = $cur_lang != $def_lang; if (apply_filters('listify_polylang_only_selected', false)) { return $query_args; } if (isset($query_args['tax_query']) && $mixed) { $taxes = $query_args['tax_query']; foreach ($taxes as $key => $tax) { $terms = $tax['terms']; $trans = array(); if (is_array($terms)) { foreach ($terms as $term) { // annoying since we have slugs but get an id but need back to slugs $obj = get_term_by('slug', $term, $tax['taxonomy']); $trans = pll_get_term($obj->term_id, $def_lang); $trans = get_term_by('id', $trans, $tax['taxonomy']); $query_args['tax_query'][$key]['terms'] = array_merge($terms, array($trans->slug)); } } } } $terms = get_terms('post_translations'); $exclude = array(); foreach ($terms as $translation) { $trans = unserialize($translation->description); if ($mixed) { $exclude[] = $trans[$def_lang]; } } if ($mixed) { if (isset($query_args['post__in'])) { $query_args['post__in'] = array_diff($query_args['post__in'], $exclude); unset($query_args['post__not_in']); } else { $query_args['post__not_in'] = $exclude; } } return $query_args; }
function optionsframework_option_name() { $themename = get_option('stylesheet'); $themename = preg_replace("/\\W/", "_", strtolower($themename)); if (is_child_theme()) { $themename = str_replace("_child", "", $themename); } $themename_lan = $themename; if (defined('ICL_LANGUAGE_CODE') && ICL_LANGUAGE_CODE != 'en') { $themename_lan = $themename . '_' . ICL_LANGUAGE_CODE; } if (function_exists('pll_current_language')) { $default_lan = pll_default_language('slug'); $current_lan = pll_current_language('slug'); if ($current_lan != '') { $themename_lan = $themename . '_' . $current_lan; } } return $themename_lan; }
/** * Sync porduct meta * * @return false if the current post type is not "product" */ public function syncProductsMeta() { // sync product meta with polylang add_filter('pll_copy_post_metas', array(__CLASS__, 'getProductMetaToCopy')); $currentScreen = get_current_screen(); if ($currentScreen->post_type !== 'product') { return false; } $ID = false; $disable = false; /* * Disable editing product meta for product translations * * In case of a "Add or update product" ($GET['post'] is set), and the * product language is different from the default, it is a product translation * and editing the product metadata should be disabled. * * In case of a "Add product translation" ($GET['new_lang'] is set), or the * 'edit' page, editing product metadata should be disabled. */ if (isset($_GET['post'])) { // Add or update product $ID = absint($_GET['post']); $disable = $ID && pll_get_post_language($ID) != pll_default_language(); } elseif (isset($_GET['new_lang']) || $currentScreen->base == 'edit') { // Add product translation $ID = isset($_GET['from_post']) ? absint($_GET['from_post']) : false; $disable = isset($_GET['new_lang']) && esc_attr($_GET['new_lang']) != pll_default_language() ? true : false; // Add the '_translation_porduct_type' meta,for the case the product // was created before plugin acivation. $this->add_product_type_meta($ID); } // disable fields edit for product translations if ($disable) { add_action('admin_print_scripts', array($this, 'addFieldsLocker'), 100); } // sync the product type selection in the product data settings box $this->sync_product_type_selection($ID); }
function real_site_url($path = '') { $site_url = get_site_url(); // check for multi-language-framework plugin if (is_plugin_active('multi-language-framework/multi-language-framework.php')) { global $mlf_config; $current_language = substr(strtolower(get_bloginfo('language')), 0, 2); if ($mlf_config['default_language'] != $current_language) { $site_url .= '/' . $current_language; } } elseif (is_plugin_active('polylang/polylang.php')) { $defLang = pll_default_language(); $curLang = pll_current_language(); if ($defLang != $curLang) { $site_url .= '/' . $curLang; } } if ($path != '') { $site_url .= '/' . $path; } $site_url .= '/'; return $site_url; }
<?php /** * Template Name: Related Resources */ global $post; $lang = ''; if (is_plugin_active('polylang/polylang.php')) { $defLang = pll_default_language(); $curLang = pll_current_language(); if ($defLang != $curLang) { $lang = $curLang; } } // get all the child categories of "Related resources" category $category = get_category_by_slug($post->post_name); $args = array('type' => 'post', 'child_of' => $category->term_id, 'orderby' => 'name', 'order' => 'ASC', 'hide_empty' => FALSE, 'hierarchical' => 1, 'taxonomy' => 'category'); $child_categories = get_categories($args); get_header(); ?> <?php $breadcrumb = '<div class="breadcrumb"><a href="' . esc_url(home_url("/" . $lang . "/")) . '" class="home">Home</a> > ' . $category->name . '</div>'; echo $breadcrumb; ?> <div id="primary" class="site-content"> <div id="content" role="main" <?php post_class('related-resources'); ?> >
/** * Action: Set Language * * @param string $lang_slug * @param object $current_lang Current language */ public function set_language($lang_slug, $current_lang) { $this->default_lang = pll_default_language(); $this->current_lang = pll_current_language(); }
/** * Jetpack * Adapted from the same function in jetpack-3.0.2/3rd-party/wpml.php * Keeps using 'icl_translate' as the function registers the string * * @since 1.5.4 */ public function grunion_contact_form_field_html_filter($r, $field_label, $id) { if (function_exists('icl_translate')) { if (pll_current_language() !== pll_default_language()) { $label_translation = icl_translate('jetpack ', $field_label . '_label', $field_label); $r = str_replace($field_label, $label_translation, $r); } } return $r; }
/** * Get all available pages with default admin language. */ private function dropdown_pages($args = array()) { $defaults = array('echo' => 0, 'post_type' => 'page', 'show_option_none' => __('None', 'events-maker'), 'option_none_value' => 0, 'suppress_filters' => false); $args = wp_parse_args($args, $defaults); if (class_exists('SitePress') && array_key_exists('sitepress', $GLOBALS)) { global $sitepress; $current_lang = $sitepress->get_current_language(); $default_lang = $sitepress->get_default_language(); // @TODO this only works if $_GET lang parameter is 'all' or equal to $default_lang // unfortunatelly WPML does not support any method to override that $sitepress->switch_lang($default_lang, true); } elseif (class_exists('Polylang') && function_exists('pll_default_language')) { $args['lang'] = pll_default_language('slug'); } $pages = wp_dropdown_pages($args); if (class_exists('SitePress') && array_key_exists('sitepress', $GLOBALS)) { $sitepress->switch_lang($current_lang); } return $pages; }
} elseif (ICL_LANGUAGE_CODE != 'en' && ICL_LANGUAGE_CODE != 'all' && function_exists('pll_default_language')) { if (in_array(ICL_LANGUAGE_CODE, $pll_languages)) { $lang = '_' . ICL_LANGUAGE_CODE; if (!get_option($theme_name . '_options' . $lang)) { update_option($theme_name . '_options' . $lang, get_option($theme_name . '_options')); } } } elseif (ICL_LANGUAGE_CODE == 'all') { if (defined('ICL_SITEPRESS_VERSION')) { $lang = '_' . $sitepress->get_default_language(); if ($sitepress->get_default_language() == 'en') { $lang = ''; } } elseif (function_exists('pll_default_language')) { $lang = '_' . pll_default_language('slug'); if (pll_default_language('slug') == 'en') { $lang = ''; } } } else { $lang = ''; } } else { $lang = ''; } } // End Avada Edit define('OPTIONS', $theme_name . '_options' . $lang); define('BACKUPS', $theme_name . '_backups' . $lang); /** * Required action filters
public function nav_menu_locations($menus) { if (is_array($menus)) { foreach ($menus as $loc => $menu) { foreach ($this->model->get_languages_list() as $lang) { if (pll_default_language() != $lang->slug && !empty($this->options['nav_menus'][$this->theme][$loc][$lang->slug])) { $menus[$loc . '___' . $lang->slug] = $this->options['nav_menus'][$this->theme][$loc][$lang->slug]; } } } } return $menus; }
/** * Get default language code * * @return string Default language code */ function get_default_language_code() { return pll_default_language('slug'); }
/** * Get the default language * * @return string */ public function getDefaultLanguage() { return pll_default_language(); }
/** * Fix "get_term_link" for this taxonomy. */ public function term_link_filter($termlink, $term, $taxonomy) { // Check if the post type is handle. if (isset($this->taxonomies[$taxonomy])) { global $wp_rewrite, $polylang; if (!is_object($term)) { if (is_int($term)) { $term = get_term($term, $taxonomy); } else { $term = get_term_by('slug', $term, $taxonomy); } } if (!is_object($term)) { $term = new WP_Error('invalid_term', __('Empty Term')); } if (is_wp_error($term)) { return $term; } // Get the term language. $term_language = PLL()->model->term->get_language($term->term_id); if ($term_language) { $lang = $term_language->slug; } else { $lang = pll_default_language(); } // Check if the language is handle. if (isset($this->taxonomies[$taxonomy]->translated_slugs[$lang])) { $taxonomy = $term->taxonomy; $termlink = $this->taxonomies[$taxonomy]->translated_struct[$lang]; $slug = $term->slug; $t = get_taxonomy($taxonomy); if (empty($termlink)) { if ('category' == $taxonomy) { $termlink = '?cat=' . $term->term_id; } elseif ($t->query_var) { $termlink = "?{$t->query_var}={$slug}"; } else { $termlink = "?taxonomy={$taxonomy}&term={$slug}"; } $termlink = home_url($termlink); } else { if ($t->rewrite['hierarchical']) { $hierarchical_slugs = array(); $ancestors = get_ancestors($term->term_id, $taxonomy); foreach ((array) $ancestors as $ancestor) { $ancestor_term = get_term($ancestor, $taxonomy); $hierarchical_slugs[] = $ancestor_term->slug; } $hierarchical_slugs = array_reverse($hierarchical_slugs); $hierarchical_slugs[] = $slug; $termlink = str_replace("%{$taxonomy}%", implode('/', $hierarchical_slugs), $termlink); } else { $termlink = str_replace("%{$taxonomy}%", $slug, $termlink); } $termlink = home_url(user_trailingslashit($termlink, 'category')); } // Back Compat filters. if ('post_tag' == $taxonomy) { $termlink = apply_filters('tag_link', $termlink, $term->term_id); } elseif ('category' == $taxonomy) { $termlink = apply_filters('category_link', $termlink, $term->term_id); } } } return $termlink; }
<img class="site_logo" alt="Site Logo" src="<?php echo get_stylesheet_directory_uri(); ?> /img/logo.png" /> </a></div> <!-- Navbar Collapse --> <div class="navbar-collapse collapse"> <!-- nav --> <ul class="nav navbar-nav" data-sm-skip-collapsible-behavior="true"> <!-- Home Mega Menu --> <li class=""> <a href="<?php echo site_url(); ?> /<?php echo LANG === pll_default_language('slug') ? '' : LANG; ?> "><?php echo pll__('Home'); ?> </a> </li> <!-- Mega Menu Ends --> <!-- Pages Mega Menu --> <li class=""> <a href="<?php echo site_url(); ?> /products<?php echo CAT_LANG_SUFFIX; ?>
/** * Display posts in the default language if the translation does not exist * * Modifies the taxonomy query set by PLL_Choose_Lang::set_lang_query_var() * * @todo This method is conceived to deal with bilingual posts only. * @link http://wordpress.syllogic.in/2014/08/going-multi-lingual-with-polylang/ */ public function pre_get_default_language_posts(&$query) { $dl = pll_default_language(); $cl = pll_current_language(); if ($dl !== $cl) { /** Polylang stores translated post IDs in a serialized array in the description field of this custom taxonomy */ $terms = get_terms('post_translations'); $exclude_posts = []; foreach ($terms as $translation) { $tp = unserialize($translation->description); /** If the current language is not the default, lets pick up the default language post */ if ($dl !== $cl && isset($tp[$dl])) { $exclude_posts[] = $tp[$dl]; } } $query->set('post__not_in', $exclude_posts); /** Remove the duplicate post in the default language */ $query->set('lang', "{$dl},{$cl}"); /** Select both default and current language post */ /** Remove any existing term-based language determiners to prevent conflicts */ if (!empty($query->query_vars['tax_query'])) { foreach ($query->query_vars['tax_query'] as $tax_key => $tax_query) { if ('term_taxonomy_id' === $tax_query['field'] && 'language' === $tax_query['taxonomy'] && 'IN' === $tax_query['operator']) { unset($query->query_vars['tax_query'][$tax_key]); break; } } } } }
/** * Build the $existing_terms array * * Takes each translatable taxonomy and builds an array of * language-specific term_id to term_id/term_name mappings * for terms already assigned to the item translation. * * @since 2.11 * @uses MLA_Polylang::$existing_terms * @uses MLA_Polylang::$relevant_terms * * @param integer $post_id ID of the current post * */ private static function _build_existing_terms($post_id) { global $polylang; if ($post_id == self::$existing_terms['element_id']) { return; } $language_details = $polylang->model->get_post_language($post_id); MLA::mla_debug_add("MLA_Polylang::_build_existing_terms( {$post_id} ) \$polylang->model->get_post_language = " . var_export($language_details, true), MLA::MLA_DEBUG_CATEGORY_AJAX); if (is_object($language_details)) { $language_details = (array) $language_details; } else { MLA::mla_debug_add("MLA_Polylang::_build_existing_terms( {$post_id} ) pll_default_language() = " . var_export(pll_default_language(), true), MLA::MLA_DEBUG_CATEGORY_AJAX); $language_details = (array) $polylang->model->get_language(pll_default_language()); MLA::mla_debug_add("MLA_Polylang::_build_existing_terms( {$post_id} ) \$polylang->model->get_language( pll_default_language() ) = " . var_export($language_details, true), MLA::MLA_DEBUG_CATEGORY_AJAX); } MLA::mla_debug_add("MLA_Polylang::_build_existing_terms( {$post_id} ) \$polylang->model->get_translations() = " . var_export($polylang->model->get_translations('post', $post_id), true), MLA::MLA_DEBUG_CATEGORY_AJAX); $translations = array(); foreach ($polylang->model->get_translations('post', $post_id) as $language_code => $translation) { $translations[$language_code] = array('element_id' => $translation); } if (empty($translations)) { $translations[$language_details['slug']] = array('element_id' => $post_id); } self::$existing_terms = array_merge(array('element_id' => $post_id, 'slug' => $language_details['slug']), $translations); $taxonomies = $polylang->model->get_translated_taxonomies(); /* * Find all assigned terms and build term_master array */ foreach ($translations as $language_code => $translation) { foreach ($taxonomies as $taxonomy_name) { if ($terms = get_the_terms($translation['element_id'], $taxonomy_name)) { foreach ($terms as $term) { self::_add_relevant_term($term); self::$existing_terms[$language_code][$taxonomy_name][$term->term_taxonomy_id] = $term; } // term } else { self::$existing_terms[$language_code][$taxonomy_name] = array(); } } // taxonomy } // translation /* * Add missing translated terms to the term_master array */ foreach (self::$relevant_terms as $term) { foreach ($term['translations'] as $translation) { if (get_term_by('id', $translation->element_id, $term['term']->taxonomy, NULL, true)) { continue; } $term_object = get_term_by('id', $translation->element_id, $term['term']->taxonomy); self::_add_relevant_term($term_object, $term['translations']); } // translation } // term MLA::mla_debug_add("MLA_Polylang::_build_existing_terms( {$post_id} ) self::\$existing_terms = " . var_export(self::$existing_terms, true), MLA::MLA_DEBUG_CATEGORY_AJAX); MLA::mla_debug_add("MLA_Polylang::_build_existing_terms( {$post_id} ) self::\$relevant_terms = " . var_export(self::$relevant_terms, true), MLA::MLA_DEBUG_CATEGORY_AJAX); return; }
/** * Handle variation limitation about default language * * @global string $pagenow current page name * * @return boolean false if this is not new variable product */ public function handleVariableLimitation() { global $pagenow; if ($pagenow !== 'post-new.php') { return false; } if (isset($_GET['from_post'])) { return false; } if (pll_current_language() === pll_default_language()) { return false; } add_action('admin_print_scripts', function () { $jsID = 'variables-data'; $code = sprintf('var HYYAN_WPI_VARIABLES = {' . ' title : "%s" ,' . ' content : "%s" ,' . ' defaultLang : "%s"' . '};', __('Wrong default language for Variable Products', 'woopoly'), __("Variable products must be created in the default language first due to a plugin design limitation. <br> <a href='https://github.com/decarvalhoaa/woopoly/tree/master#what-you-need-to-know-about-this-plugin' target='_blank'>Read more</a>", 'woopoly'), pll_default_language()); Utilities::jsScriptWrapper($jsID, $code, false); }); add_action('admin_enqueue_scripts', function () { wp_enqueue_script('jquery-ui-core'); wp_enqueue_script("jquery-effects-core"); wp_enqueue_script('jquery-ui-dialog'); wp_enqueue_script('woo-poly-variables', plugins_url('public/js/Variables.js', WOOPOLY_FILE), array('jquery', 'jquery-ui-core', 'jquery-ui-dialog'), \Hyyan\WPI\Plugin::getVersion(), true); }, 100); }
function wpml_get_default_language() { return pll_default_language(); }
/** * listing_images_default() * * Callback function to set the default * gallery with translated images if * these are available. * * @access public * @param array $field_args * @param object $field * @uses pll_get_post_language() * @uses pll_default_language() * @uses pll_get_post() * @uses get_post_meta() * @return array * * @since 1.0.0 */ public function listing_images_default($field_args, $field) { // Get post language $post_lang = pll_get_post_language($field->object_id); // Get from post early $from_post = isset($_REQUEST['from_post']) ? $_REQUEST['from_post'] : false; // If from_post is not available anymore, use current post ID if (!$from_post) { $from_post = $field->object_id; } // Get post ID of default language $origial = pll_get_post($from_post, pll_default_language()); // Get original gallery $gallery = get_post_meta($origial, '_gallery', true); if (empty($gallery)) { return; } // Set up translated gallery $gallery_lang = array(); foreach ($gallery as $id => $url) { // Get ID of image translation $id_lang = pll_get_post($id, $post_lang); if ($id_lang) { // When available, set new ID $gallery_lang[$id_lang] = $url; } } // If there are image translations, set new gallery default if (!empty($gallery_lang)) { return $gallery_lang; } }
/** * Updates views count. * * @since 1.4.0 * @global object $wpdb * @param int Post ID * @return bool|int FALSE if query failed, TRUE on success */ private function __update_views($id) { /* TODO: For WordPress Multisite, we must define the DIEONDBERROR constant for database errors to display like so: <?php define( 'DIEONDBERROR', true ); ?> */ global $wpdb; $table = $wpdb->prefix . "popularposts"; $wpdb->show_errors(); // WPML support, get original post/page ID if (defined('ICL_LANGUAGE_CODE') && function_exists('icl_object_id')) { global $sitepress; if (isset($sitepress)) { // avoids a fatal error with Polylang $id = icl_object_id($id, get_post_type($id), true, $sitepress->get_default_language()); } else { if (function_exists('pll_default_language')) { // adds Polylang support $id = icl_object_id($id, get_post_type($id), true, pll_default_language()); } } } $now = $this->__now(); $curdate = $this->__curdate(); $views = $this->user_settings['tools']['sampling']['active'] ? $this->user_settings['tools']['sampling']['rate'] : 1; // Allow WP themers / coders perform an action // before updating views count if (has_action('wpp_pre_update_views')) { do_action('wpp_pre_update_views', $id, $views); } // Update all-time table $result1 = $wpdb->query($wpdb->prepare("INSERT INTO {$table}data\n\t\t\t\t(postid, day, last_viewed, pageviews) VALUES (%d, %s, %s, %d)\n\t\t\t\tON DUPLICATE KEY UPDATE pageviews = pageviews + %4\$d, last_viewed = '%3\$s';", $id, $now, $now, $views)); // Update range (summary) table $result2 = $wpdb->query($wpdb->prepare("INSERT INTO {$table}summary\n\t\t\t\t(postid, pageviews, view_date, last_viewed) VALUES (%d, %d, %s, %s)\n\t\t\t\tON DUPLICATE KEY UPDATE pageviews = pageviews + %2\$d, last_viewed = '%4\$s';", $id, $views, $curdate, $now)); if (!$result1 || !$result2) { return false; } // Allow WP themers / coders perform an action // after updating views count if (has_action('wpp_post_update_views')) { do_action('wpp_post_update_views', $id); } return true; }
function cs_language_defaults() { $multilang = array(); if (cs_is_wpml_activated() || cs_is_qtranslate_activated() || cs_is_polylang_activated()) { if (cs_is_wpml_activated()) { global $sitepress; $multilang['default'] = $sitepress->get_default_language(); $multilang['current'] = $sitepress->get_current_language(); $multilang['languages'] = $sitepress->get_active_languages(); } else { if (cs_is_polylang_activated()) { global $polylang; $current = pll_current_language(); $default = pll_default_language(); $current = empty($current) ? $default : $current; $poly_langs = $polylang->model->get_languages_list(); $languages = array(); foreach ($poly_langs as $p_lang) { $languages[$p_lang->slug] = $p_lang->slug; } $multilang['default'] = $default; $multilang['current'] = $current; $multilang['languages'] = $languages; } else { if (cs_is_qtranslate_activated()) { global $q_config; $multilang['default'] = $q_config['default_language']; $multilang['current'] = $q_config['language']; $multilang['languages'] = array_flip(qtrans_getSortedLanguages()); } } } } $multilang = apply_filters('cs_language_defaults', $multilang); return !empty($multilang) ? $multilang : false; }
/** * Replace "permastruct", for single. * * This code simulate the code used in WordPress function "register_post_type" * and execute it for each language. */ private function replace_permastruct() { global $wp_rewrite; $post_type = $this->post_type_object->name; // remove the original permastructs unset($wp_rewrite->extra_permastructs[$post_type]); // add the translated permastructs for each languages foreach ($this->translated_slugs as $lang => $translated_slug) { $args = $translated_slug; if ($args->rewrite !== false && (is_admin() || get_option('permalink_structure') != '')) { $permastruct_args = $args->rewrite; $permastruct_args['feed'] = $permastruct_args['feeds']; // set the walk_dirs to false to avoid conflict with has_archive = false and the %language% // in the rewrite directive. Without it the archive page redirect to the frontpage if has_archive is false $permastruct_args['walk_dirs'] = false; // if "Hide URL language information for default language" option is // set to true the rules has to be different for the default language if ($this->plugin === 'Polylang') { global $polylang; // if "The language is set from content" is enabled if ((bool) $polylang->options['force_lang'] === false) { add_permastruct($post_type . '_' . $lang, "{$args->rewrite['slug']}/%{$post_type}%", $permastruct_args); } else { if ($polylang->options['hide_default'] && $lang == pll_default_language()) { add_permastruct($post_type . '_' . $lang, "{$args->rewrite['slug']}/%{$post_type}%", $permastruct_args); } else { // if "Keep /language/ in pretty permalinks" is enabled if ($polylang->options['rewrite'] == 0 && !($polylang->options['hide_default'] && $lang == pll_default_language())) { add_permastruct($post_type . '_' . $lang, 'language/' . "%language%/{$args->rewrite['slug']}/%{$post_type}%", $permastruct_args); } else { add_permastruct($post_type . '_' . $lang, "%language%/{$args->rewrite['slug']}/%{$post_type}%", $permastruct_args); } } } } elseif ($this->plugin === 'WPML') { add_permastruct($post_type . '_' . $lang, "{$args->rewrite['slug']}/%{$post_type}%", $permastruct_args); } do_action('wpml_translated_post_type_replace_permastruct', $post_type, $lang, $translated_slug); } } }
/** * Get the title of the post. * * @access public * @return string */ public function get_title() { global $sitepress; if (function_exists('icl_object_id') && function_exists('pll_default_language')) { // Polylang with use of WPML compatibility mode $id = icl_object_id($this->id, 'product', false, pll_default_language()); } elseif (function_exists('icl_object_id') && method_exists($sitepress, 'get_default_language')) { // WPML $id = icl_object_id($this->id, 'product', false, $sitepress->get_default_language()); } else { $id = $this->id; } return apply_filters('woocommerce_product_title', get_the_title($id), $this); }