/** * Fetch the post of the correct language. * * @since 2.1.0 * * @param $post_id Post ID */ function tptn_object_id_cur_lang($post_id) { $return_original_if_missing = false; /** * Filter to modify if the original language ID is returned. * * @since 2.2.3 * * @param bool $return_original_if_missing * @param int $post_id Post ID */ $return_original_if_missing = apply_filters('tptn_wpml_return_original', $return_original_if_missing, $post_id); if (function_exists('pll_get_post')) { $post_id = pll_get_post($post_id); } elseif (function_exists('wpml_object_id_filter')) { $post_id = wpml_object_id_filter($post_id, 'any', $return_original_if_missing); } elseif (function_exists('icl_object_id')) { $post_id = icl_object_id($post_id, 'any', $return_original_if_missing); } /** * Filters object ID for current language (WPML). * * @since 2.1.0 * * @param int $post_id Post ID */ return apply_filters('tptn_object_id_cur_lang', $post_id); }
function woocommerce_order_get_items($items) { if (isset($_GET['post']) && get_post_type($_GET['post']) == 'shop_order') { global $sitepress_settings; foreach ($items as $index => $item) { foreach ($item as $key => $item_data) { if ($key == 'product_id') { $tr_product_id = icl_object_id($item_data, 'product', false, $sitepress_settings['admin_default_language']); if (!is_null($tr_product_id)) { $items[$index][$key] = $tr_product_id; $items[$index]['name'] = get_the_title($tr_product_id); } } if ($key == 'variation_id') { $tr_variation_id = icl_object_id($item_data, 'product_variation', false, $sitepress_settings['admin_default_language']); if (!is_null($tr_variation_id)) { $items[$index][$key] = $tr_variation_id; } } if (substr($key, 0, 3) == 'pa_') { global $wpdb; //attr is taxonomy $default_term = get_term_by('slug', $item_data, $key); $tr_id = icl_object_id($default_term->term_id, $key, false, $sitepress_settings['admin_default_language']); if (!is_null($tr_id)) { $translated_slug = $wpdb->get_var($wpdb->prepare("\n SELECT t.slug FROM {$wpdb->terms} t JOIN {$wpdb->term_taxonomy} x ON x.term_id = t.term_id WHERE t.term_id = %d AND x.taxonomy = %s", $tr_id, $key)); $items[$index][$key] = $translated_slug; } } } } } return $items; }
/** * Get the id of the current translation of the post/custom type * * @since 2.0.0 * @author Andrea Frascaspata <*****@*****.**> */ function yit_wpml_get_translated_id($id, $post_type) { if (function_exists('icl_object_id')) { $id = icl_object_id($id, $post_type, true); } return $id; }
function merge_comment_count($count, $post_ID) { // get all the languages for which this post exists $languages = icl_get_languages('skip_missing=1'); $post = get_post($post_ID); $type = $post->post_type; foreach ($languages as $l) { // in $count is already the count from the current language if (!$l['active']) { $otherID = icl_object_id($post_ID, $type, false, $l['language_code']); if ($otherID) { // cannot use call_user_func due to php regressions if ($type == 'page') { $otherpost = get_page($otherID); } else { $otherpost = get_post($otherID); } if ($otherpost) { // increment comment count using translation post comment count. $count = $count + $otherpost->comment_count; } } } } return $count; }
/** * The Shortcode */ function ebor_portfolio_shortcode($atts) { extract(shortcode_atts(array('type' => 'grid', 'pppage' => '999', 'filter' => 'all', 'filters' => 'yes'), $atts)); /** * Initial query args */ $query_args = array('post_type' => 'portfolio', 'posts_per_page' => $pppage); if (!($filter == 'all')) { if (function_exists('icl_object_id')) { $filter = (int) icl_object_id($filter, 'portfolio_category', true); } $query_args['tax_query'] = array(array('taxonomy' => 'portfolio_category', 'field' => 'id', 'terms' => $filter)); } if ($filter == 'all') { $cats = get_categories('taxonomy=portfolio_category'); } else { $cats = get_categories('taxonomy=portfolio_category&exclude=' . $filter . '&child_of=' . $filter); } global $wp_query, $post; $old_post = $post; $wp_query = new WP_Query($query_args); ob_start(); get_template_part('loop/loop-portfolio', $type); $output = ob_get_contents(); ob_end_clean(); wp_reset_postdata(); $post = $old_post; return $output; }
/** * Returns correct ID for any object * Used to fix issues with translation plugins such as WPML * * @since 3.1.1 */ function wpex_parse_obj_id($id, $type = 'page') { if ($id && function_exists('icl_object_id')) { $id = icl_object_id($id, $type); } return $id; }
function filter_woocommerce_ajax_params($woocommerce_params) { global $sitepress, $post; $value = array(); $value = $woocommerce_params; if ($sitepress->get_current_language() !== $sitepress->get_default_language()) { $value['ajax_url'] = add_query_arg('lang', ICL_LANGUAGE_CODE, $woocommerce_params['ajax_url']); $value['checkout_url'] = add_query_arg('action', 'woocommerce-checkout', $value['ajax_url']); } if (!isset($post->ID)) { return $value; } $checkout_page_id = get_option('woocommerce_checkout_page_id'); $pay_page_id = get_option('woocommerce_pay_page_id'); $cart_page_id = get_option('woocommerce_cart_page_id'); $translated_checkout_page_id = icl_object_id($checkout_page_id, 'page', false); $translated_pay_page_id = icl_object_id($pay_page_id, 'page', false); $translated_cart_page_id = icl_object_id($cart_page_id, 'page', false); if ($translated_cart_page_id == $post->ID) { $value['is_cart'] = 1; $value['cart_url'] = get_permalink($translated_cart_page_id); } else { if ($translated_checkout_page_id == $post->ID || $checkout_page_id == $post->ID) { $value['is_checkout'] = 1; $_SESSION['wpml_globalcart_language'] = $sitepress->get_current_language(); } else { if ($translated_pay_page_id == $post->ID) { $value['is_pay_page'] = 1; } } } return $value; }
public function content($atts, $content = null) { $el_class = $width = $el_position = ''; extract(shortcode_atts(array('el_class' => '', 'el_position' => '', 'width' => '1/2'), $atts)); $output = $items_nav = $items = ''; // get all the categories from the database $cat_args = array('taxonomy' => 'faqs-category'); $cats = get_categories($cat_args); // FAQ NAVIGATION $items_nav .= '<h3>' . __("Browse F.A.Q. Topics", "swiftframework") . '</h3>'; $items_nav .= '<ul class="faqs-nav clearfix">'; foreach ($cats as $cat) { if (function_exists('icl_object_id')) { if ($cat->term_id != icl_object_id($cat->term_id, 'faqs-category', false, ICL_LANGUAGE_CODE)) { return; } } $items_nav .= '<li><a href="#' . $cat->slug . '"><i class="icon-list"></i>' . $cat->name . '<span class="count">' . $cat->count . '</span></a></li>'; } $items_nav .= '</ul>'; // FAQ LISTINGS foreach ($cats as $cat) { // setup the category ID $cat_id = $cat->term_id; if (function_exists('icl_object_id')) { if ($cat_id != icl_object_id($cat_id, 'faqs-category', false, ICL_LANGUAGE_CODE)) { return; } } // Make a header for the cateogry $items .= '<h3 class="faq-section-title" id="' . $cat->slug . '">' . $cat->name . '</h3>'; $faqs_args = array('post_type' => 'faqs', 'post_status' => 'publish', 'faqs-category' => $cat->slug, 'posts_per_page' => 100); $faqs = new WP_Query($faqs_args); $items .= '<ul class="faqs-section clearfix">'; // PORTFOLIO LOOP while ($faqs->have_posts()) { $faqs->the_post(); $faq_title = get_the_title(); $faq_text = get_the_content_with_formatting(); $items .= '<li class="faq-item">'; $items .= '<h6>' . $faq_title . '</h6>'; $items .= '<div class="faq-text">' . do_shortcode($faq_text) . '</div>'; $items .= '</li>'; } $items .= '<div class="wpb_divider go_to_top_icon1 wpb_content_element "><a class="animate-top" href="#"><i class="icon-arrow-up"></i></a></div>'; $items .= '</ul>'; wp_reset_postdata(); } $el_class = $this->getExtraClass($el_class); $width = wpb_translateColumnWidthToSpan($width); $output .= "\n\t" . '<div class="wpb_content_element ' . $width . $el_class . '">'; $output .= "\n\t\t" . '<div class="wpb_wrapper faqs-wrap">'; $output .= "\n\t\t\t" . $items_nav; $output .= "\n\t\t\t" . $items; $output .= "\n\t\t" . '</div> ' . $this->endBlockComment('.wpb_wrapper'); $output .= "\n\t" . '</div> ' . $this->endBlockComment($width); // $output = $this->startRow($el_position) . $output . $this->endRow($el_position); return $output; }
/** * The Shortcode */ function ebor_portfolio_shortcode($atts) { extract(shortcode_atts(array('type' => 'carousel', 'pppage' => '999', 'filter' => 'all', 'filters' => 'yes', 'more' => 'no'), $atts)); // Fix for pagination if (is_front_page()) { $paged = get_query_var('page') ? get_query_var('page') : 1; } else { $paged = get_query_var('paged') ? get_query_var('paged') : 1; } /** * Initial query args */ $query_args = array('post_type' => 'portfolio', 'posts_per_page' => $pppage, 'paged' => $paged); if (!($filter == 'all')) { if (function_exists('icl_object_id')) { $filter = (int) icl_object_id($filter, 'portfolio_category', true); } $query_args['tax_query'] = array(array('taxonomy' => 'portfolio_category', 'field' => 'id', 'terms' => $filter)); } if ($filter == 'all') { $cats = get_categories('taxonomy=portfolio_category'); } else { $cats = get_categories('taxonomy=portfolio_category&exclude=' . $filter . '&child_of=' . $filter); } global $wp_query; $wp_query = new WP_Query($query_args); $wp_query->filter_on_off = $filters; ob_start(); get_template_part('loop/loop-portfolio', $type); wp_reset_postdata(); $output = ob_get_contents(); ob_end_clean(); return $output; }
/** * Function: custom_get_wpml_language_link - custom code for getting wpml language toggle link * Author: JF * Date: May 29, 2014 */ function custom_get_wpml_language_link() { global $post, $current_child_site, $wp_query, $home_url; $wpml_post_name = ''; //get current inactive language code $get_inactive_language = custom_get_inactive_language(); // get the post ID in en $wpml_post_id = icl_object_id($post->ID, $post->post_type, true, $get_inactive_language['language_code']); // get the post object $wpml_post_obj = get_post($wpml_post_id); // get the name $wpml_post_name = $wpml_post_obj->post_name; if (is_archive()) { $wpml_post_name = $wp_query->query['post_type']; } if (is_singular('cpt')) { $wpml_post_name = 'cpt/' . $wpml_post_name; } if (is_front_page()) { $wpml_post_name = ''; } if (is_home()) { //check home blog listing //$wpml_post_name = 'blog'; } if (is_page()) { $translated_url = get_permalink($wpml_post_id); return '<a href="' . $translated_url . '">' . $get_inactive_language['native_name'] . '</a>'; } else { //output language switch link return '<a href="' . $home_url . '/' . $get_inactive_language['language_code'] . '/' . $wpml_post_name . '/">' . $get_inactive_language['native_name'] . '</a>'; } }
function TS_VCSC_Element_Widget_GetMeta($id, $key) { if (function_exists('icl_object_id')) { $id = icl_object_id($id, 'post', true, ICL_LANGUAGE_CODE); } return get_post_meta($id, $key, true); }
/** * The Shortcode */ function ebor_blog_shortcode($atts) { extract(shortcode_atts(array('type' => 'grid-3col', 'pppage' => '8', 'filter' => 'all'), $atts)); // Fix for pagination if (is_front_page()) { $paged = get_query_var('page') ? get_query_var('page') : 1; } else { $paged = get_query_var('paged') ? get_query_var('paged') : 1; } /** * Setup post query */ $query_args = array('post_type' => 'post', 'posts_per_page' => $pppage, 'paged' => $paged); if (!($filter == 'all')) { if (function_exists('icl_object_id')) { $filter = (int) icl_object_id($filter, 'category', true); } $query_args['tax_query'] = array(array('taxonomy' => 'category', 'field' => 'id', 'terms' => $filter)); } global $wp_query; $wp_query = new WP_Query($query_args); ob_start(); get_template_part('loop/loop-post', $type); wp_reset_postdata(); $output = ob_get_contents(); ob_end_clean(); return $output; }
/** * The Shortcode */ function ebor_testimonial_shortcode($atts) { extract(shortcode_atts(array('pppage' => '999', 'filter' => 'all', 'type' => 'carousel-3col'), $atts)); /** * Initial query args */ $query_args = array('post_type' => 'testimonial', 'posts_per_page' => $pppage); if (!($filter == 'all')) { if (function_exists('icl_object_id')) { $filter = (int) icl_object_id($filter, 'testimonial_category', true); } $query_args['tax_query'] = array(array('taxonomy' => 'testimonial_category', 'field' => 'id', 'terms' => $filter)); } /** * Finally, here's the query. */ global $wp_query; $wp_query = new WP_Query($query_args); ob_start(); get_template_part('loop/loop-testimonial', $type); wp_reset_postdata(); $output = ob_get_contents(); ob_end_clean(); return $output; }
/** * The Shortcode */ function ebor_client_shortcode($atts) { extract(shortcode_atts(array('pppage' => '8', 'filter' => 'all'), $atts)); /** * Setup post query */ $query_args = array('post_type' => 'client', 'posts_per_page' => $pppage); if (!($filter == 'all')) { if (function_exists('icl_object_id')) { $filter = (int) icl_object_id($filter, 'client_category', true); } $query_args['tax_query'] = array(array('taxonomy' => 'client_category', 'field' => 'id', 'terms' => $filter)); } global $wp_query, $post; $old_query = $wp_query; $old_post = $post; $wp_query = new WP_Query($query_args); ob_start(); get_template_part('loop/loop', 'client-carousel'); $output = ob_get_contents(); ob_end_clean(); wp_reset_postdata(); $wp_query = $old_query; $post = $old_post; return $output; }
function relevanssi_wpml_filter($data) { $use_filter = get_option('relevanssi_wpml_only_current'); if ('on' == $use_filter) { //save current blog language $lang = get_bloginfo('language'); $filtered_hits = array(); foreach ($data[0] as $hit) { if (isset($hit->blog_id)) { switch_to_blog($hit->blog_id); } global $sitepress; if (function_exists('icl_object_id') && $sitepress->is_translated_post_type($hit->post_type)) { if ($hit->ID == icl_object_id($hit->ID, $hit->post_type, false, ICL_LANGUAGE_CODE)) { $filtered_hits[] = $hit; } } elseif (function_exists('icl_object_id') && function_exists('pll_is_translated_post_type')) { if (pll_is_translated_post_type($hit->post_type)) { if ($hit->ID == icl_object_id($hit->ID, $hit->post_type, false, ICL_LANGUAGE_CODE)) { $filtered_hits[] = $hit; } } } elseif (get_bloginfo('language') == $lang) { $filtered_hits[] = $hit; } if (isset($hit->blog_id)) { restore_current_blog(); } } return array($filtered_hits, $data[1]); } return $data; }
function sync_variation_swatches_and_photos($original_product_id, $trnsl_product_id, $data = false) { global $sitepress, $wpdb; $atts = maybe_unserialize(get_post_meta($original_product_id, '_swatch_type_options', true)); $lang = $sitepress->get_language_for_element($trnsl_product_id, 'post_product'); $tr_atts = $atts; foreach ($atts as $att_name => $att_opts) { foreach ($att_opts['attributes'] as $slug => $options) { $o_term = get_term_by('slug', $slug, $att_name); $tr_term_id = icl_object_id($o_term->term_id, $att_name, false, $lang); if (!is_null($tr_term_id)) { $tr_term = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->terms} t JOIN {$wpdb->term_taxonomy} x ON x.term_id = t.term_id WHERE t.term_id = %d AND x.taxonomy = %s", $tr_term_id, $att_name)); $tr_slug = $tr_term->slug; if ($tr_slug != '') { $tr_atts[$att_name]['attributes'][$tr_term->slug] = $atts[$att_name]['attributes'][$slug]; if (isset($options['image'])) { $o_img_id = $options['image']; $tr_img_id = icl_object_id($o_img_id, 'image', false, $lang); } unset($tr_atts[$att_name]['attributes'][$slug]); } } } } update_post_meta($trnsl_product_id, '_swatch_type_options', $tr_atts); // Meta gets overwritten }
/** * Converts toggle page ID to WPML compatible ID * * @since 1.6.0 */ public function toggle_bar_content_id($id) { if (function_exists('icl_object_id') && defined('ICL_LANGUAGE_CODE')) { $id = icl_object_id($id, 'page', false, ICL_LANGUAGE_CODE); } return $id; }
function block($instance) { extract($instance); $query_args = array('post_type' => 'testimonial', 'posts_per_page' => $pppage); if (!($filter == 'all')) { if (function_exists('icl_object_id')) { $filter = (int) icl_object_id($filter, 'testimonial-category', true); } $query_args['tax_query'] = array(array('taxonomy' => 'testimonial-category', 'field' => 'id', 'terms' => $filter)); } $testimonial_query = new WP_Query($query_args); if ($testimonial_query->have_posts()) { while ($testimonial_query->have_posts()) { $testimonial_query->the_post(); ?> <div class="text-center services-1 col-md-3"> <div class="col-wrapper"> <?php the_title('<h5 class="upper">', '</h5>'); the_content(); ?> </div> </div> <?php } } else { /** * Display no posts message if none are found. */ get_template_part('loop/content', 'none'); } wp_reset_query(); }
/** * Front-end display of widget. * * @see WP_Widget::widget() * @since 1.0.0 * * @param array $args Widget arguments. * @param array $instance Saved values from database. */ function widget($args, $instance) { // Extract args extract($args, EXTR_SKIP); $title = apply_filters('widget_title', $instance['title']); $parent_page = icl_object_id($instance['parent_page'], true); $depth = $instance['depth']; $order_by = $instance['order_by']; $sort_by = $instance['sort_by']; echo $before_widget; if ($title) { echo $before_title . $title . $after_title; } if ($depth) { $args = array('sort_order' => $order_by, 'sort_column' => $sort_by, 'child_of' => $parent_page, 'parent' => $parent_page, 'hierarchical' => 0); } else { $args = array('child_of' => $parent_page); } $child_pages = get_pages($args); if ($child_pages) { $body_widget = '<ul>' . "\n"; foreach ($child_pages as $page) { $body_widget .= '<li><a href="' . get_page_link($page->ID) . '">' . $page->post_title . '</a></li>'; } $body_widget .= '</ul>' . "\n"; } echo $body_widget; echo $after_widget; return $instance; }
public static function get_id_by_slug($slug, $type) { if (!function_exists('icl_object_id')) { return; } $page = get_page_by_path($slug); return icl_object_id($page->ID, $type, true); }
function addons_product_terms($product_terms) { global $sitepress; foreach ($product_terms as $key => $product_term) { $product_terms[$key] = icl_object_id($product_term, 'product_cat', true, $sitepress->get_default_language()); } return $product_terms; }
public static function lang_category_id($id) { if (function_exists('icl_object_id')) { return icl_object_id($id, 'category', true); } else { return $id; } }
private function wpml_post() { global $post, $sitepress; if (!function_exists('icl_object_id') || !is_callable(array($sitepress, 'get_current_language'))) { return; } return get_post(icl_object_id($post->ID, 'post', false, $sitepress->get_current_language())); }
function translate_page($id) { global $pagenow; if (is_admin() && $pagenow == 'options-permalink.php') { return $id; } return icl_object_id($id, 'page', true); }
/** * Get the page ID of the add location page. * * @package Geodirectory * @since 1.4.6 * @return int|null Return the page ID if present or null if not. */ function geodir_location_page_id() { $gd_page_id = get_option('geodir_location_page'); if (function_exists('icl_object_id')) { $gd_page_id = icl_object_id($gd_page_id, 'page', true); } return $gd_page_id; }
function return_default_lan($id) { if (function_exists('icl_object_id')) { $id = icl_object_id($id, 'page', true, 'en'); } $post = get_post($id); return $post->post_name; }
private function modify_id($id) { // Check for WPML language posts if (function_exists('icl_object_id')) { $id = icl_object_id($id, 'ditty_news_ticker', true); } return $id; }
/** * Get WC shop page id * @return page id */ function st_get_shop_page() { $post_id = get_option('woocommerce_shop_page_id'); if (st_is_wpml()) { $post_id = icl_object_id($post_id, 'page', true); } return $post_id; }
/** * Render taxonomy term filter item content in the filters list */ function wpv_get_list_item_ui_taxonomy_term($selected, $view_settings = null) { if (isset($view_settings['taxonomy_type']) && is_array($view_settings['taxonomy_type'])) { $view_settings['taxonomy_type'] = $view_settings['taxonomy_type'][0]; } if (!isset($view_settings['taxonomy_terms_mode'])) { $view_settings['taxonomy_terms_mode'] = 'THESE'; } if (!isset($view_settings['taxonomy_terms'])) { $view_settings['taxonomy_terms'] = array(); } if (function_exists('icl_object_id') && !empty($view_settings['taxonomy_terms'])) { // Adjust for WPML support $trans_term_ids = array(); foreach ($view_settings['taxonomy_terms'] as $untrans_term_id) { $trans_term_ids[] = icl_object_id($untrans_term_id, $view_settings['taxonomy_type'], true); } $view_settings['taxonomy_terms'] = $trans_term_ids; } ob_start(); wpv_render_taxonomy_term_options(array('mode' => 'edit', 'view_settings' => $view_settings)); $data = ob_get_clean(); $td = "<p class='wpv-filter-taxonomy-term-summary js-wpv-filter-summary js-wpv-filter-taxonomy-term-summary'>\n"; $td .= wpv_get_filter_taxonomy_term_summary_txt($view_settings); $td .= "</p>\n<p class='edit-filter js-wpv-filter-edit-controls'>\n<button class='button-secondary js-wpv-filter-edit-open js-wpv-filter-taxonomy-term-edit-open'>" . __('Edit', 'wpv-views') . "</button>\n<i class='icon-remove-sign js-filter-remove' data-nonce='" . wp_create_nonce('wpv_view_filter_taxonomy_term_delete_nonce') . "'></i>\n</p>"; $td .= "<div id=\"wpv-filter-taxonomy-term-edit\" class=\"wpv-filter-edit js-wpv-filter-edit\">\n"; $td .= '<fieldset>'; $td .= '<legend><strong>' . __('Taxonomy term', 'wpv-views') . ':</strong></legend>'; $td .= '<div id="wpv-filter-taxonomy-term" class="js-filter-taxonomy-term-list">' . $data . '</div>'; $td .= '</fieldset>'; ob_start(); ?> <p> <input class="button-secondary js-wpv-filter-edit-ok js-wpv-filter-taxonomy-term-edit-ok" type="button" value="<?php echo htmlentities(__('Close', 'wpv-views'), ENT_QUOTES); ?> " data-save="<?php echo htmlentities(__('Save', 'wpv-views'), ENT_QUOTES); ?> " data-close="<?php echo htmlentities(__('Close', 'wpv-views'), ENT_QUOTES); ?> " data-success="<?php echo htmlentities(__('Updated', 'wpv-views'), ENT_QUOTES); ?> " data-unsaved="<?php echo htmlentities(__('Not saved', 'wpv-views'), ENT_QUOTES); ?> " data-nonce="<?php echo wp_create_nonce('wpv_view_filter_taxonomy_term_nonce'); ?> " /> </p> <?php $td .= ob_get_clean(); $td .= '</div>'; return $td; }
function translated_checkout_product_title($title, $product) { global $sitepress; if (isset($product->id)) { $tr_product_id = icl_object_id($product->id, 'product', true, $sitepress->get_current_language()); $title = get_the_title($tr_product_id); } return $title; }