/** * 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); }
/** * Save the order language with every checkout * * @param integer $order the order object */ public function saveOrderLanguage($order) { $current = pll_current_language(); if ($current) { pll_set_post_language($order, $current); } }
function footsy() { global $popupBoxen; echo $popupBoxen; if (class_exists('PLL_Base')) { echo '<span id="pylangswitcher">'; // echo '<li><a id="notice-trans" href="#">notice! (08-30)</a></li>'; // these are the publicly-available languages foreach (unserialize(PRODUCTION_LANGUAGES) as $lang) { if ($lang != pll_current_language()) { echo '<li><a href="' . get_permalink(pll_get_post(get_the_ID(), $lang)) . '">' . $lang . '</a></li>'; } } // these are the ones in development if (userIsAdmin() || userIsTranslator() || userIsAssistant()) { foreach (unserialize(DEVELOPMENT_LANGUAGES) as $lang) { if ($lang != pll_current_language()) { echo '<li><a href="' . get_permalink(pll_get_post(get_the_ID(), $lang)) . '">' . $lang . '</a></li>'; } } } // old method: echo pll_the_languages(array('echo'=>0,'display_names_as' => 'slug','hide_current' => 1)); if (userIsAdmin() || userIsTranslator() || userIsAssistant()) { echo '<li><a href="' . admin_url('edit.php?post_type=page') . '">' . __t('Editor') . '</a></li>'; } echo '</span>'; } }
function wp_new_user_notification($user_id, $plaintext_pass = '') { //pyboxlog('called wp_n_u_n', 1); $user = new WP_User($user_id); $body = __t('An account has been created for you on the Computer Science Circles website, with a randomly generated password. User name: %username% Current random password: %password% Please visit %loginurl% and change your password to something you will remember. Press "%upprof%" once you are done. Thanks from the Computer Science Circles team! %siteurl%'); //pyboxlog('locale:' . pll_current_language('locale'), 1); if (class_exists('PLL_Base')) { update_user_meta($user_id, 'user_lang', pll_current_language('locale')); } $subject = __t('Computer Science Circles: New account'); $user_login = stripslashes($user->user_login); $user_email = stripslashes($user->user_email); $find = array('/%username%/i', '/%password%/i', '/%blogname%/i', '/%siteurl%/i', '/%loginurl%/i', '/%useremail%/i', '/%upprof%/i'); $replace = array($user_login, $plaintext_pass, get_option('blogname'), get_option('siteurl'), get_option('siteurl') . '/wp-login.php', $user_email, __t('Update Profile')); $body = preg_replace($find, $replace, $body); $body = preg_replace("/%.*%/", "", $body); pb_mail('"' . get_option('blogname') . '" <' . CSCIRCLES_BOUNCE_EMAIL . '>', '<' . $user_email . '>', $subject, $body); }
function nav_menu_add_classes2($items, $args) { //print_r($items); global $post; $i = 0; $j = false; $a = false; foreach ($items as $item) { $i++; if (is_single() && get_post_type() == 'interesting-fact') { //get parent page ID by checking which page uses interesting fatcs page template $pages = get_pages(array('meta_key' => '_wp_page_template', 'meta_value' => 'page-templates/interesting_facts.php', 'lang' => pll_current_language('slug'))); $parent_page_id = $pages[0]->ID; if ($item->object_id == $parent_page_id) { // $item->classes[] = 'current_page_parent'; $item->classes[] = 'current_menu_item'; $j = $i - 1; $a = $item->ID; } } } if ($j) { // $items[$j]->classes[] = 'current_page_parent'; $items[1]->classes[] = 'current_page_ancestor'; } if ($a) { echo $a; } return $items; }
public static function get_slug_pll($slug, $type) { $id = self::get_id_by_slug($slug, $type); $id = pll_get_post($id, pll_current_language()); $data = get_post($id, ARRAY_A); return $data['post_name']; }
/** * Get data from context * @author Joachim Jensen <*****@*****.**> * @since 2.0 * @return array */ public function get_context_data() { $data = array($this->id); if (function_exists('pll_current_language')) { $data[] = pll_current_language(); } return $data; }
/** * Filter WordPress current locale with Polylang's current locale. * * @used-by Filters\"locale" * @param string $locale The locale ID. */ public function pll_get_locale($locale) { $pll_locale = pll_current_language('locale'); if ($locale !== $pll_locale) { $locale = $pll_locale; } return $locale; }
function dbProblemSummary($limit, $sortname, $sortorder, $req = NULL) { global $db_query_info; $db_query_info = array(); if ($req == NULL) { $req = $_REQUEST; } $db_query_info['type'] = 'problem-summary'; if (!is_user_logged_in()) { return __t("You must log in to view past submissions."); } $problemslug = getSoft($req, "p", ""); //which problem? if ($problemslug == "") { return __t("You must enter a non-empty problem name."); } global $wpdb; $problem_table = $wpdb->prefix . "pb_problems"; $problemname = $wpdb->get_var($wpdb->prepare("SELECT publicname FROM {$problem_table} WHERE lang = '%s' AND slug = '%s'", pll_current_language(), $problemslug)); if ($problemname == null) { return sprintf(__t("Problem %s not found (at least in current language)"), $problemslug); } $db_query_info['problem'] = $problemslug; $u = wp_get_current_user(); $uid = $u->ID; $db_query_info['viewuser'] = $uid; $ulogin = $u->user_login; $submit_table = $wpdb->prefix . "pb_submissions"; $usermeta_table = $wpdb->prefix . "usermeta"; $user_table = $wpdb->prefix . "users"; $complete_table = $wpdb->prefix . "pb_completed"; $count = $wpdb->get_var(userIsAdmin() ? "SELECT count(1) FROM {$user_table}" : $wpdb->prepare("SELECT count(1) FROM {$usermeta_table} WHERE meta_key=%s AND meta_value=%s", 'pbguru', $ulogin)); $students = $wpdb->get_results(userIsAdmin() ? "SELECT ID FROM {$user_table} {$limit}" : $wpdb->prepare("SELECT user_id AS ID FROM {$usermeta_table} WHERE meta_key=%s AND meta_value=%s {$limit}", 'pbguru', $ulogin)); // no sorting allowed due to weird nature of query $flexirows = array(); foreach ($students as $r) { $sid = $r->ID; $sdata = $wpdb->get_row($wpdb->prepare("SELECT usercode, beginstamp FROM {$submit_table} \n WHERE userid={$sid} and problem='%s' and result='Y'\n ORDER BY beginstamp DESC limit 1", $problemslug)); $s = get_userdata($sid); $cell = array(); $cell['ID'] = $sid; $cell['info'] = userString($sid); if ($sdata != null) { $cell[__t('latest correct')] = prebox($sdata->usercode); $cell[__t('last time')] = $sdata->beginstamp; $cell[__t('first time')] = $wpdb->get_var($wpdb->prepare("SELECT time FROM {$complete_table} WHERE userid={$sid} and problem='%s'", $problemslug)); } else { $cell[__t('latest correct')] = '<i>n/a</i>'; $cell[__t('last time')] = '<i>n/a</i>'; $cell[__t('first time')] = '<i>n/a</i>'; } $flexirows[] = array('id' => $sid, 'cell' => $cell); } return array('total' => $count, 'rows' => $flexirows); }
function nueva_url() { if (pll_current_language('slug') == "fr") { $url = home_url(); } elseif (pll_current_language('slug') == "es") { $url = home_url(); } else { $url = home_url(); } echo $url; }
/** * Add things to the context for every twig template * @param $context * @return mixed */ function addToContext($context) { $context['menu'] = new TimberMenu(); $context['site'] = $this; $context['is_home'] = is_front_page() ? "true" : "false"; $context['home_url'] = get_home_url(); if (function_exists("pll_current_language")) { $context['current_lang'] = pll_current_language(); } return $context; }
/** * Return the language 2-4 letters code * * @since 1.0.0 * * @return string 4 letters cod of the locale */ function get_language() { if (defined('ICL_LANGUAGE_CODE')) { return ICL_LANGUAGE_CODE; } elseif (function_exists('cml_get_browser_lang')) { return cml_get_browser_lang(); } elseif (function_exists('pll_current_language')) { return pll_current_language(); } else { // Return a 2-4 letters code return get_locale(); } }
/** * Get the current language. * * Uses the WordPress locale setting, but also checks for WPML and Polylang. * * @return string */ protected function get_site_language() { $language = get_bloginfo('language'); if (defined('ICL_LANGUAGE_CODE')) { $language = ICL_LANGUAGE_CODE; } if (function_exists('pll_current_language')) { $language = pll_current_language('slug'); } /** * Filters the displayed site language. * * @param string $language Site language. */ return apply_filters('user_feedback_site_language', $language); }
public function add_to_context($context) { /* Menu */ $context['menu'] = new TimberMenu('primary_navigation'); /* Site info */ $context['site'] = $this; /* Boolean if is homepage */ $context['is_home'] = is_front_page() ? "true" : "false"; /* homepage url */ $context['home_url'] = get_home_url(); /* if multilang is enabled return current language */ if (function_exists("pll_current_language")) { $context['current_lang'] = pll_current_language(); } return $context; }
/** * Retrieve permalink for search. * * @param string $query Optional. The query string to use. If empty the current query is used. * @return string */ function search_link($link, $search) { $lang = pll_current_language(); $slug = pll_translations_x('search', 'URI slug', 'boilerplate', $lang); //$link = "/$slug/$search"; $link = "/{$search}"; $link = home_url(user_trailingslashit($link, 'search')); /** * Filter the search permalink. * * @param string $link Search permalink. * @param string $search The URL-encoded search term. */ var_dump($link); var_dump($search); return apply_filters('pll_search_link', $link, $search); }
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; }
/** * Translates _page for posts_ and _page on front_ * * @used-by Filters\"option_{$option}" * @param int $value The page ID for 'page_for_posts' and 'page_on_front' * @return int $value The translated page ID or the original ID. */ public static function pll_translate_page($value) { if (class_exists('Polylang')) { global $polylang; /** This hook may be often called so let's store the result */ static $posts = []; $blog_id = get_current_blog_id(); $lang = pll_current_language(); if ($lang) { if (!isset($posts[$blog_id][$value])) { $_value = $polylang->model->get_post($value, $lang); $posts[$blog_id][$value] = $_value ? $_value : null; } if (!is_null($posts[$blog_id][$value])) { return $posts[$blog_id][$value]; } } } return $value; }
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; }
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; }
function get_network_wide_posts($args = '') { require_once plugin_dir_path(dirname(__FILE__)) . 'public/class-network-wide-posts-public.php'; if (!isset($args['lang']) && function_exists('pll_current_language')) { $args['lang'] = pll_current_language(); } $results = Network_Wide_Posts_Public::get_network_wide_posts($args); $posts = array(); $current_blog_id = get_current_blog_id(); foreach ($results as $result) { $blog_id = $result->blog_id; switch_to_blog($blog_id); $post_id = $result->nwp_id; $post_id = substr($post_id, strlen($blog_id)); $permalink = get_permalink($post_id); $thumb_url = $result->nwp_thumb_url; if (isset($args['thumbnail'])) { $arr = wp_get_attachment_image_src($result->nwp_thumb_id, $args['thumbnail']); $thumb_url = $arr[0]; } $posts[] = array("post_id" => $result->nwp_id, "post_title" => $result->nwp_title, "post_excerpt" => $result->nwp_excerpt, "post_url" => $permalink, "thumb_url" => $thumb_url, "blog_id" => $result->blog_id); } return $posts; }
/** * Is combine * * Check if combine mode is requested * * @return boolean true if combine mode , false otherwise */ public static function isCombine() { return !pll_current_language() || isset($_GET['lang']) && esc_attr($_GET['lang']) === 'all'; }
function eme_detect_lang() { $language=""; if (function_exists('qtrans_getLanguage')) { // if permalinks are on, $_GET doesn't contain lang as a parameter // so we get it like this to be sure $language=qtrans_getLanguage(); } elseif (function_exists('ppqtrans_getLanguage')) { $language=ppqtrans_getLanguage(); } elseif (function_exists('qtranxf_getLanguage')) { $language=qtranxf_getLanguage(); } elseif (function_exists('pll_current_language') && function_exists('pll_languages_list')) { $languages=pll_languages_list(); if (is_array($languages)) { foreach ($languages as $tmp_lang) { if (preg_match("/^$tmp_lang\/|\/$tmp_lang\//",$_SERVER['REQUEST_URI'])) $language=$tmp_lang; } } if (empty($language)) $language=pll_current_language('slug'); } elseif (defined('ICL_LANGUAGE_CODE')) { // Both polylang and wpml define this constant, so check polylang first (above) // if permalinks are on, $_GET doesn't contain lang as a parameter // so we get it like this to be sure $language=ICL_LANGUAGE_CODE; } elseif (isset($_GET['lang'])) { $language=eme_strip_tags($_GET['lang']); } else { $language=""; } return $language; }
$custom = get_post_custom($my_query->ID); $terms = get_the_terms($post->ID, 'project_location'); // echo $terms{0}->slug; ?> <div class="item g1 <?php echo $terms[0]->slug; ?> "> <a href="<?php echo get_permalink(); ?> " class="whole-div"> <div class="blurb gradient"> <h6><?php echo $custom["sq_ft"][0]; echo pll_current_language() == "en" ? ' sq-ft' : ''; ?> </h6> <h4><?php echo $custom["subtitle"][0]; ?> </h4> <!--<h6><?php //echo $custom["sq_ft"][0] . ' sq-ft'; ?> </h6>--> <h5><?php echo the_title(); ?> </h5>
static function get_blog_language() { $language = ''; //check if WPML is active if (defined('ICL_LANGUAGE_CODE') && defined('ICL_SITEPRESS_VERSION')) { //do not rely on ICL_LANGUAGE_CODE as main language can switch durring the code execution //$language = ICL_LANGUAGE_CODE; global $sitepress; if (is_object($sitepress)) { $language = $sitepress->get_current_language(); } //polylang global $polylang; if (is_object($polylang)) { $language = $polylang->curlang->slug; } } //check Polylang if (function_exists('pll_current_language')) { $language = pll_current_language(); } $wp_locale = get_locale(); if ($language == '' && $wp_locale != '' && !defined('TRANSPOSH_PLUGIN_VER')) { $locale_data = explode("_", $wp_locale); $language = $locale_data[0]; } if ($language == '') { $language = 'en'; } return $language; }
/** * Get information about an objects MySQL table * * @param string $object_type * @param string $object The object to look for * @param null $name (optional) Name of the pod to load * @param array $pod (optional) Array with pod information * @param array $field (optional) Array with field information * * @return array|bool * * @since 2.0 */ public function get_table_info($object_type, $object, $name = null, $pod = null, $field = null) { /** * @var $wpdb wpdb * @var $sitepress SitePress * @var $icl_adjust_id_url_filter_off boolean */ global $wpdb, $sitepress, $icl_adjust_id_url_filter_off, $polylang; // @todo Handle $object arrays for Post Types, Taxonomies, Comments (table pulled from first object in array) $info = array('object_type' => $object_type, 'type' => null, 'object_name' => $object, 'object_hierarchical' => false, 'table' => $object, 'meta_table' => $object, 'pod_table' => $wpdb->prefix . 'pods_' . (empty($object) ? $name : $object), 'field_id' => 'id', 'field_index' => 'name', 'field_slug' => null, 'field_type' => null, 'field_parent' => null, 'field_parent_select' => null, 'meta_field_id' => 'id', 'meta_field_index' => 'name', 'meta_field_value' => 'name', 'pod_field_id' => 'id', 'pod_field_index' => 'name', 'pod_field_slug' => null, 'pod_field_parent' => null, 'join' => array(), 'where' => null, 'where_default' => null, 'orderby' => null, 'pod' => null, 'recurse' => false); if (empty($object_type)) { $object_type = 'post_type'; $object = 'post'; } elseif (empty($object) && in_array($object_type, array('user', 'media', 'comment'))) { $object = $object_type; } $pod_name = $pod; if (is_array($pod_name)) { $pod_name = pods_var_raw('name', $pod_name, version_compare(PHP_VERSION, '5.4.0', '>=') ? json_encode($pod_name, JSON_UNESCAPED_UNICODE) : json_encode($pod_name), null, true); } else { $pod_name = $object; } $field_name = $field; if (is_array($field_name)) { $field_name = pods_var_raw('name', $field_name, version_compare(PHP_VERSION, '5.4.0', '>=') ? json_encode($pod_name, JSON_UNESCAPED_UNICODE) : json_encode($field_name), null, true); } $transient = 'pods_' . $wpdb->prefix . '_get_table_info_' . md5($object_type . '_object_' . $object . '_name_' . $name . '_pod_' . $pod_name . '_field_' . $field_name); $current_language = false; $current_language_t_id = $current_language_tt_id = 0; // WPML support if (is_object($sitepress) && !$icl_adjust_id_url_filter_off) { $current_language = pods_sanitize(ICL_LANGUAGE_CODE); } elseif (is_object($polylang) && function_exists('pll_current_language')) { $current_language = pods_sanitize(pll_current_language('slug')); if (!empty($current_language)) { $current_language_t_id = (int) $polylang->get_language($current_language)->term_id; $current_language_tt_id = (int) $polylang->get_language($current_language)->term_taxonomy_id; } } if (!empty($current_language)) { $transient = 'pods_' . $wpdb->prefix . '_get_table_info_' . $current_language . '_' . md5($object_type . '_object_' . $object . '_name_' . $name . '_pod_' . $pod_name . '_field_' . $field_name); } $_info = false; if (isset(self::$table_info_cache[$transient])) { // Prefer info from the object internal cache $_info = self::$table_info_cache[$transient]; } elseif (pods_api_cache()) { $_info = pods_transient_get($transient); if (false === $_info && !did_action('init')) { $_info = pods_transient_get($transient . '_pre_init'); } } if (false !== $_info) { // Data was cached, use that $info = $_info; } else { // Data not cached, load it up $_info = $this->get_table_info_load($object_type, $object, $name, $pod); if (isset($_info['type'])) { // Allow function to override $object_type $object_type = $_info['type']; } $info = array_merge($info, $_info); } if (0 === strpos($object_type, 'post_type') || 'media' == $object_type || in_array(pods_var_raw('type', $info['pod']), array('post_type', 'media'))) { $info['table'] = $wpdb->posts; $info['meta_table'] = $wpdb->postmeta; $info['field_id'] = 'ID'; $info['field_index'] = 'post_title'; $info['field_slug'] = 'post_name'; $info['field_type'] = 'post_type'; $info['field_parent'] = 'post_parent'; $info['field_parent_select'] = '`t`.`' . $info['field_parent'] . '`'; $info['meta_field_id'] = 'post_id'; $info['meta_field_index'] = 'meta_key'; $info['meta_field_value'] = 'meta_value'; if ('media' == $object_type) { $object = 'attachment'; } if (empty($name)) { $prefix = 'post_type-'; // Make sure we actually have the prefix before trying anything with the name if (0 === strpos($object_type, $prefix)) { $name = substr($object_type, strlen($prefix), strlen($object_type)); } } if ('media' != $object_type) { $object_type = 'post_type'; } $post_type = pods_sanitize(empty($object) ? $name : $object); if ('attachment' == $post_type || 'media' == $object_type) { $info['pod_table'] = $wpdb->prefix . 'pods_media'; } else { $info['pod_table'] = $wpdb->prefix . 'pods_' . pods_clean_name($post_type, true, false); } $post_type_object = get_post_type_object($post_type); if (is_object($post_type_object) && $post_type_object->hierarchical) { $info['object_hierarchical'] = true; } /** * Default Post Status to query for. * * Use to change "default" post status from publish to any other status or statuses. * * @param array $post_status List of post statuses. Default is 'publish' * @param string $post_type Post type of current object * @param array $info Array of information about the object. * @param string $object Type of object * @param string $name Name of pod to load * @param array $pod Array with Pod information. Result of PodsAPI::load_pod() * @param array $field Array with field information * * @since unknown */ $post_status = apply_filters('pods_api_get_table_info_default_post_status', array('publish'), $post_type, $info, $object_type, $object, $name, $pod, $field); $info['where'] = array('post_type' => '`t`.`' . $info['field_type'] . '` = "' . $post_type . '"'); if ('post_type' == $object_type) { $info['where_default'] = '`t`.`post_status` IN ( "' . implode('", "', $post_status) . '" )'; } $info['orderby'] = '`t`.`menu_order`, `t`.`' . $info['field_index'] . '`, `t`.`post_date`'; // WPML support if (is_object($sitepress) && $sitepress->is_translated_post_type($post_type) && !$icl_adjust_id_url_filter_off) { $info['join']['wpml_translations'] = "\n LEFT JOIN `{$wpdb->prefix}icl_translations` AS `wpml_translations`\n ON `wpml_translations`.`element_id` = `t`.`ID`\n AND `wpml_translations`.`element_type` = 'post_{$post_type}'\n AND `wpml_translations`.`language_code` = '{$current_language}'\n "; $info['join']['wpml_languages'] = "\n LEFT JOIN `{$wpdb->prefix}icl_languages` AS `wpml_languages`\n ON `wpml_languages`.`code` = `wpml_translations`.`language_code` AND `wpml_languages`.`active` = 1\n "; $info['where']['wpml_languages'] = "`wpml_languages`.`code` IS NOT NULL"; } elseif (is_object($polylang) && !empty($current_language) && function_exists('pll_is_translated_post_type') && pll_is_translated_post_type($post_type)) { $info['join']['polylang_languages'] = "\n LEFT JOIN `{$wpdb->term_relationships}` AS `polylang_languages`\n ON `polylang_languages`.`object_id` = `t`.`ID`\n AND `polylang_languages`.`term_taxonomy_id` = {$current_language_tt_id}\n "; $info['where']['polylang_languages'] = "`polylang_languages`.`object_id` IS NOT NULL"; } $info['object_fields'] = $this->get_wp_object_fields($object_type, $info['pod']); } elseif (0 === strpos($object_type, 'taxonomy') || in_array($object_type, array('nav_menu', 'post_format')) || 'taxonomy' == pods_var_raw('type', $info['pod'])) { $info['table'] = $info['meta_table'] = $wpdb->terms; $info['join']['tt'] = "LEFT JOIN `{$wpdb->term_taxonomy}` AS `tt` ON `tt`.`term_id` = `t`.`term_id`"; $info['field_id'] = $info['meta_field_id'] = 'term_id'; $info['field_index'] = $info['meta_field_index'] = $info['meta_field_value'] = 'name'; $info['field_slug'] = 'slug'; $info['field_type'] = 'taxonomy'; $info['field_parent'] = 'parent'; $info['field_parent_select'] = '`tt`.`' . $info['field_parent'] . '`'; if ('nav_menu' == $object_type) { $object = 'nav_menu'; } elseif ('post_format' == $object_type) { $object = 'post_format'; } if (empty($name)) { $prefix = 'taxonomy-'; // Make sure we actually have the prefix before trying anything with the name if (0 === strpos($object_type, $prefix)) { $name = substr($object_type, strlen($prefix), strlen($object_type)); } } if (!in_array($object_type, array('nav_menu', 'post_format'))) { $object_type = 'taxonomy'; } $taxonomy = pods_sanitize(empty($object) ? $name : $object); $info['pod_table'] = $wpdb->prefix . 'pods_' . pods_clean_name($taxonomy, true, false); $taxonomy_object = get_taxonomy($taxonomy); if (is_object($taxonomy_object) && $taxonomy_object->hierarchical) { $info['object_hierarchical'] = true; } $info['where'] = array('tt.taxonomy' => '`tt`.`' . $info['field_type'] . '` = "' . $taxonomy . '"'); // WPML Support if (is_object($sitepress) && $sitepress->is_translated_taxonomy($taxonomy) && !$icl_adjust_id_url_filter_off) { $info['join']['wpml_translations'] = "\n LEFT JOIN `{$wpdb->prefix}icl_translations` AS `wpml_translations`\n ON `wpml_translations`.`element_id` = `tt`.`term_taxonomy_id`\n AND `wpml_translations`.`element_type` = 'tax_{$taxonomy}'\n AND `wpml_translations`.`language_code` = '{$current_language}'\n "; $info['join']['wpml_languages'] = "\n LEFT JOIN `{$wpdb->prefix}icl_languages` AS `wpml_languages`\n ON `wpml_languages`.`code` = `wpml_translations`.`language_code` AND `wpml_languages`.`active` = 1\n "; $info['where']['wpml_languages'] = "`wpml_languages`.`code` IS NOT NULL"; } elseif (is_object($polylang) && !empty($current_language) && function_exists('pll_is_translated_taxonomy') && pll_is_translated_taxonomy($taxonomy)) { $info['join']['polylang_languages'] = "\n LEFT JOIN `{$wpdb->termmeta}` AS `polylang_languages`\n ON `polylang_languages`.`term_id` = `t`.`term_id`\n AND `polylang_languages`.`meta_value` = {$current_language_t_id}\n "; $info['where']['polylang_languages'] = "`polylang_languages`.`term_id` IS NOT NULL"; } $info['object_fields'] = $this->get_wp_object_fields($object_type, $info['pod']); } elseif ('user' == $object_type || 'user' == pods_var_raw('type', $info['pod'])) { $info['table'] = $wpdb->users; $info['meta_table'] = $wpdb->usermeta; $info['pod_table'] = $wpdb->prefix . 'pods_user'; $info['field_id'] = 'ID'; $info['field_index'] = 'display_name'; $info['field_slug'] = 'user_nicename'; $info['meta_field_id'] = 'user_id'; $info['meta_field_index'] = 'meta_key'; $info['meta_field_value'] = 'meta_value'; $info['where'] = array('user_status' => '`t`.`user_status` = 0'); $info['object_fields'] = $this->get_wp_object_fields($object_type, $info['pod']); } elseif ('comment' == $object_type || 'comment' == pods_var_raw('type', $info['pod'])) { //$info[ 'object_hierarchical' ] = true; $info['table'] = $wpdb->comments; $info['meta_table'] = $wpdb->commentmeta; $info['pod_table'] = $wpdb->prefix . 'pods_comment'; $info['field_id'] = 'comment_ID'; $info['field_index'] = 'comment_date'; $info['field_type'] = 'comment_type'; $info['field_parent'] = 'comment_parent'; $info['field_parent_select'] = '`t`.`' . $info['field_parent'] . '`'; $info['meta_field_id'] = 'comment_id'; $info['meta_field_index'] = 'meta_key'; $info['meta_field_value'] = 'meta_value'; $object = 'comment'; $comment_type = empty($object) ? $name : $object; $comment_type_clause = '`t`.`' . $info['field_type'] . '` = "' . $comment_type . '"'; if ('comment' == $comment_type) { $comment_type_clause = '( ' . $comment_type_clause . ' OR `t`.`' . $info['field_type'] . '` = "" )'; } $info['where'] = array('comment_approved' => '`t`.`comment_approved` = 1', 'comment_type' => $comment_type_clause); $info['orderby'] = '`t`.`' . $info['field_index'] . '` DESC, `t`.`' . $info['field_id'] . '`'; } elseif (in_array($object_type, array('option', 'settings')) || 'settings' == pods_var_raw('type', $info['pod'])) { $info['table'] = $wpdb->options; $info['meta_table'] = $wpdb->options; $info['field_id'] = 'option_id'; $info['field_index'] = 'option_name'; $info['meta_field_id'] = 'option_id'; $info['meta_field_index'] = 'option_name'; $info['meta_field_value'] = 'option_value'; $info['orderby'] = '`t`.`' . $info['field_index'] . '` ASC'; } elseif (is_multisite() && (in_array($object_type, array('site_option', 'site_settings')) || 'site_settings' == pods_var_raw('type', $info['pod']))) { $info['table'] = $wpdb->sitemeta; $info['meta_table'] = $wpdb->sitemeta; $info['field_id'] = 'site_id'; $info['field_index'] = 'meta_key'; $info['meta_field_id'] = 'site_id'; $info['meta_field_index'] = 'meta_key'; $info['meta_field_value'] = 'meta_value'; $info['orderby'] = '`t`.`' . $info['field_index'] . '` ASC'; } elseif (is_multisite() && 'network' == $object_type) { // Network = Site $info['table'] = $wpdb->site; $info['meta_table'] = $wpdb->sitemeta; $info['field_id'] = 'id'; $info['field_index'] = 'domain'; $info['meta_field_id'] = 'site_id'; $info['meta_field_index'] = 'meta_key'; $info['meta_field_value'] = 'meta_value'; $info['orderby'] = '`t`.`' . $info['field_index'] . '` ASC, `t`.`path` ASC, `t`.`' . $info['field_id'] . '`'; } elseif (is_multisite() && 'site' == $object_type) { // Site = Blog $info['table'] = $wpdb->blogs; $info['field_id'] = 'blog_id'; $info['field_index'] = 'domain'; $info['field_type'] = 'site_id'; $info['where'] = array('archived' => '`t`.`archived` = 0', 'spam' => '`t`.`spam` = 0', 'deleted' => '`t`.`deleted` = 0', 'site_id' => '`t`.`' . $info['field_type'] . '` = ' . (int) get_current_site()->id); $info['orderby'] = '`t`.`' . $info['field_index'] . '` ASC, `t`.`path` ASC, `t`.`' . $info['field_id'] . '`'; } elseif ('table' == $object_type || 'table' == pods_var_raw('type', $info['pod'])) { $info['table'] = empty($object) ? $name : $object; $info['pod_table'] = $wpdb->prefix . 'pods_' . $info['table']; if (!empty($field) && is_array($field)) { $info['table'] = pods_var_raw('pick_table', pods_var_raw('options', $field, $field)); $info['field_id'] = pods_var_raw('pick_table_id', pods_var_raw('options', $field, $field)); $info['field_index'] = $info['meta_field_index'] = $info['meta_field_value'] = pods_var_raw('pick_table_index', pods_var_raw('options', $field, $field)); } } $info['table'] = pods_clean_name($info['table'], false, false); $info['meta_table'] = pods_clean_name($info['meta_table'], false, false); $info['pod_table'] = pods_clean_name($info['pod_table'], false, false); $info['field_id'] = pods_clean_name($info['field_id'], false, false); $info['field_index'] = pods_clean_name($info['field_index'], false, false); $info['field_slug'] = pods_clean_name($info['field_slug'], false, false); $info['meta_field_id'] = pods_clean_name($info['meta_field_id'], false, false); $info['meta_field_index'] = pods_clean_name($info['meta_field_index'], false, false); $info['meta_field_value'] = pods_clean_name($info['meta_field_value'], false, false); if (empty($info['orderby'])) { $info['orderby'] = '`t`.`' . $info['field_index'] . '`, `t`.`' . $info['field_id'] . '`'; } if ('table' == pods_var_raw('storage', $info['pod']) && !in_array($object_type, array('pod', 'table'))) { $info['join']['d'] = 'LEFT JOIN `' . $info['pod_table'] . '` AS `d` ON `d`.`id` = `t`.`' . $info['field_id'] . '`'; //$info[ 'select' ] .= ', `d`.*'; } if (!empty($info['pod']) && is_array($info['pod'])) { $info['recurse'] = true; } $info['type'] = $object_type; $info['object_name'] = $object; if (pods_api_cache()) { if (!did_action('init')) { $transient .= '_pre_init'; } pods_transient_set($transient, $info); } self::$table_info_cache[$transient] = apply_filters('pods_api_get_table_info', $info, $object_type, $object, $name, $pod, $field, $this); return self::$table_info_cache[$transient]; }
/** * Set the PayPal checkout locale code. * * @param array $args the current paypal request args array */ public function setPaypalLocalCode($args) { $lang = pll_current_language('locale'); $args['locale.x'] = $lang; return $args; }
/** * Get current language code * * @return string Current language code */ function get_current_language_code() { return pll_current_language('slug'); }
function widget($args, $instance) { global $comments, $comment; $cache = array(); if (!$this->is_preview()) { $cache = wp_cache_get('widget_recent_comments', 'widget'); } if (!is_array($cache)) { $cache = array(); } if (!isset($args['widget_id'])) { $args['widget_id'] = $this->id; } $lang = pll_current_language(); #added if (isset($cache[$args['widget_id']][$lang])) { #modified# echo $cache[$args['widget_id']][$lang]; #modified# return; } extract($args, EXTR_SKIP); $output = ''; $title = !empty($instance['title']) ? $instance['title'] : __('Recent Comments'); /** This filter is documented in wp-includes/default-widgets.php */ $title = apply_filters('widget_title', $title, $instance, $this->id_base); $number = !empty($instance['number']) ? absint($instance['number']) : 5; if (!$number) { $number = 5; } /** * Filter the arguments for the Recent Comments widget. * * @since 3.4.0 * * @see get_comments() * * @param array $comment_args An array of arguments used to retrieve the recent comments. */ $comments = get_comments(apply_filters('widget_comments_args', array('number' => $number, 'status' => 'approve', 'post_status' => 'publish'))); $output .= $before_widget; if ($title) { $output .= $before_title . $title . $after_title; } $output .= '<ul id="recentcomments">'; if ($comments) { // Prime cache for associated posts. (Prime post term cache if we need it for permalinks.) $post_ids = array_unique(wp_list_pluck($comments, 'comment_post_ID')); _prime_post_caches($post_ids, strpos(get_option('permalink_structure'), '%category%'), false); foreach ((array) $comments as $comment) { $output .= '<li class="recentcomments">' . sprintf(_x('%1$s on %2$s', 'widgets'), get_comment_author_link(), '<a href="' . esc_url(get_comment_link($comment->comment_ID)) . '">' . get_the_title($comment->comment_post_ID) . '</a>') . '</li>'; } } $output .= '</ul>'; $output .= $after_widget; echo $output; if (!$this->is_preview()) { $cache[$args['widget_id']][$lang] = $output; #modified# wp_cache_set('widget_recent_comments', $cache, 'widget'); } }
/** * Runs on template_include filter. Check for $POST values coming from the filter and add them to the url * Also check for custom GET parameters and reattach them to the url to support combination with other functionalities * @since 1.0.0 */ public function catch_filter_values() { //Nope, this pageload was not due to our filter! if (!isset($_POST['btf_do_filtering_nonce']) || !wp_verify_nonce($_POST['btf_do_filtering_nonce'], "Beutiful-taxonomy-filters-do-filter")) { return; } //If we don't have an url, this wont work! $referer = isset($_POST['site-url']) ? $_POST['site-url'] : false; if (!$referer) { return; } //get current post type archive rewrite slug if (isset($_POST['post_type_rewrite']) && $_POST['post_type_rewrite'] != '') { $current_post_type_rewrite = $_POST['post_type_rewrite']; } else { //If there was no post type from the form (for some reason), try to get it anyway! $current_post_type_rewrite = self::get_current_posttype(); } //get current post type archive if (isset($_POST['post_type']) && $_POST['post_type'] != '') { $current_post_type = $_POST['post_type']; } else { //If there was no post type from the form (for some reason), try to get it anyway! $current_post_type = self::get_current_posttype(false); } //post type validation if (!post_type_exists($current_post_type)) { return; } //Polylang support if (function_exists('pll_current_language')) { $language_slug = pll_current_language('slug'); //If the post type is translated… if (pll_is_translated_post_type($current_post_type)) { $new_url = pll_home_url($language_slug); } else { //base url $new_url = $referer . '/'; } } else { //base url $new_url = $referer . '/'; } $new_url .= $current_post_type_rewrite . '/'; //Get the taxonomies of the current post type $current_taxonomies = get_object_taxonomies($current_post_type, 'objects'); if ($current_taxonomies) { foreach ($current_taxonomies as $key => $value) { //check for each taxonomy as a $_POST variable. //If it exists we want to append it along with the value (term) it has. $term = isset($_POST['select-' . $key]) ? $_POST['select-' . $key] : false; if ($term) { //If the taxonomy has a rewrite slug we need to use that instead! if (is_array($value->rewrite) && array_key_exists('slug', $value->rewrite)) { $new_url .= $value->rewrite['slug'] . '/' . $term . '/'; } else { $new_url .= $key . '/' . $term . '/'; } } } } //Perform actions before the redirect to the filtered page do_action('beautiful_actions_before_redirection', $current_post_type); //keep GET parameters $new_url = $this->append_get_parameters($new_url); //sanitize URL $new_url = esc_url_raw($new_url); //perform a redirect to the new filtered url wp_redirect(apply_filters('beautiful_filters_new_url', $new_url, $current_post_type)); exit; }
/** * Translates Woocommerce email subjects and headings content to the order language. * * @param string $string Subject or heading not translated * @param WC_Order $order Order object * @param string $string_type Type of string to translate <subject | heading> * @param string $email_type Email template * * @return string Translated string, returns the original $string on error */ public function translateEmailStringToOrderLanguage($string, $order, $string_type, $email_type) { if (empty($order)) { return $string; // Returns the original $string on error (no order to get language from) } // Get order language $order_language = pll_get_post_language($order->id, 'locale'); if ($order_language == '') { $order_language = pll_current_language('locale'); } // Get setting used to register string in the Polylang strings translation table $_string = $string; // Store original string to return in case of error if (false == ($string = $this->getEmailSetting($string_type, $email_type)) && !isset($this->default_settings[$email_type . '_' . $string_type])) { return $_string; // No setting in Polylang strings translations table nor default string found to translate } // Switch language $this->switchLanguage($order_language); if ($string) { // Retrieve translation from Polylang Strings Translations table $string = pll__($string); } else { // If no user translation found in Polylang Strings Translations table, use WooCommerce default translation $string = __($this->default_settings[$email_type . '_' . $string_type], 'woocommerce'); } $find = array(); $replace = array(); $find['order-date'] = '{order_date}'; $find['order-number'] = '{order_number}'; $find['site_title'] = '{site_title}'; $replace['order-date'] = date_i18n(wc_date_format(), strtotime($order->order_date)); $replace['order-number'] = $order->get_order_number(); $replace['site_title'] = get_bloginfo('name'); $string = str_replace($find, $replace, $string); return $string; }