public function edited_term($term_id, $tt_id, $taxonomy) { if (pll_is_translated_taxonomy($taxonomy)) { $document = $this->lgtm->get_group('term', $term_id); if ($document && $term_id == $document->source && md5(Lingotek_Group_Term::get_content(get_term($term_id, $taxonomy))) != $this->old_term) { $document->source_edited(); if ($document->is_automatic_upload()) { $this->lgtm->upload_term($term_id, $taxonomy); } } } }
/** * 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]; }
function icl_object_id($id, $type, $return_original_if_missing = false, $lang = false) { $pll_type = 'post' === $type || pll_is_translated_post_type($type) ? 'post' : ('term' === $type || pll_is_translated_taxonomy($type) ? 'term' : false); return $pll_type && ($lang = $lang ? $lang : pll_current_language()) && ($tr_id = PLL()->model->{$pll_type}->get_translation($id, $lang)) ? $tr_id : ($return_original_if_missing ? $id : null); }
/** * Get data from relationship objects * * @param array $object_params Object data parameters * * @return array|bool Object data */ public function get_object_data($object_params = null) { global $wpdb, $polylang, $sitepress, $icl_adjust_id_url_filter_off; $current_language = false; // WPML support if (is_object($sitepress) && !$icl_adjust_id_url_filter_off) { $current_language = pods_sanitize(ICL_LANGUAGE_CODE); } elseif (function_exists('pll_current_language')) { $current_language = pll_current_language('slug'); } $object_params = array_merge(array('name' => '', 'value' => '', 'options' => array(), 'pod' => '', 'id' => '', 'context' => '', 'data_params' => array('query' => ''), 'page' => 1, 'limit' => 0), $object_params); $name = $object_params['name']; $value = $object_params['value']; $options = $object_params['options'] = (array) $object_params['options']; $pod = $object_params['pod']; $id = $object_params['id']; $context = $object_params['context']; $data_params = $object_params['data_params'] = (array) $object_params['data_params']; $page = min(1, (int) $object_params['page']); $limit = (int) $object_params['limit']; if (isset($options['options'])) { $options = array_merge($options, $options['options']); unset($options['options']); } $data = apply_filters('pods_field_pick_object_data', null, $name, $value, $options, $pod, $id, $object_params); $items = array(); if (!isset($options[self::$type . '_object'])) { $data = pods_var_raw('data', $options, array(), null, true); } $simple = false; if (null === $data) { $data = array(); if ('custom-simple' == $options[self::$type . '_object']) { $custom = pods_var_raw(self::$type . '_custom', $options, ''); $custom = apply_filters('pods_form_ui_field_pick_custom_values', $custom, $name, $value, $options, $pod, $id, $object_params); if (!empty($custom)) { if (!is_array($custom)) { $data = array(); $custom = explode("\n", trim($custom)); foreach ($custom as $custom_value) { $custom_label = explode('|', $custom_value); if (empty($custom_label)) { continue; } if (1 == count($custom_label)) { $custom_label = $custom_value; } else { $custom_value = $custom_label[0]; $custom_label = $custom_label[1]; } $custom_value = trim((string) $custom_value); $custom_label = trim((string) $custom_label); $data[$custom_value] = $custom_label; } } else { $data = $custom; } $simple = true; } } elseif (isset(self::$related_objects[$options[self::$type . '_object']]) && isset(self::$related_objects[$options[self::$type . '_object']]['data']) && !empty(self::$related_objects[$options[self::$type . '_object']]['data'])) { $data = self::$related_objects[$options[self::$type . '_object']]['data']; $simple = true; } elseif (isset(self::$related_objects[$options[self::$type . '_object']]) && isset(self::$related_objects[$options[self::$type . '_object']]['data_callback']) && is_callable(self::$related_objects[$options[self::$type . '_object']]['data_callback'])) { $data = call_user_func_array(self::$related_objects[$options[self::$type . '_object']]['data_callback'], array($name, $value, $options, $pod, $id)); $simple = true; // Cache data from callback if (!empty($data)) { self::$related_objects[$options[self::$type . '_object']]['data'] = $data; } } elseif ('simple_value' != $context) { $pick_val = pods_var(self::$type . '_val', $options); if ('table' == pods_var(self::$type . '_object', $options)) { $pick_val = pods_var(self::$type . '_table', $options, $pick_val, null, true); } if ('__current__' == $pick_val) { if (is_object($pod)) { $pick_val = $pod->pod; } elseif (is_array($pod)) { $pick_val = $pod['name']; } elseif (0 < strlen($pod)) { $pick_val = $pod; } } $options['table_info'] = pods_api()->get_table_info(pods_var(self::$type . '_object', $options), $pick_val, null, null, $options); $search_data = pods_data(); $search_data->table($options['table_info']); if (isset($options['table_info']['pod']) && !empty($options['table_info']['pod']) && isset($options['table_info']['pod']['name'])) { $search_data->pod = $options['table_info']['pod']['name']; $search_data->fields = $options['table_info']['pod']['fields']; } $params = array('select' => "`t`.`{$search_data->field_id}`, `t`.`{$search_data->field_index}`", 'table' => $search_data->table, 'where' => pods_var_raw(self::$type . '_where', $options, (array) $options['table_info']['where_default'], null, true), 'orderby' => pods_var_raw(self::$type . '_orderby', $options, null, null, true), 'groupby' => pods_var_raw(self::$type . '_groupby', $options, null, null, true), 'pagination' => false, 'search' => false); if (in_array($options[self::$type . '_object'], array('site', 'network'))) { $params['select'] .= ', `t`.`path`'; } if (!empty($params['where']) && (array) $options['table_info']['where_default'] != $params['where']) { $params['where'] = pods_evaluate_tags($params['where'], true); } if (empty($params['where']) || !is_array($params['where']) && strlen(trim($params['where'])) < 1) { $params['where'] = array(); } elseif (!is_array($params['where'])) { $params['where'] = (array) $params['where']; } if ('value_to_label' == $context) { $params['where'][] = "`t`.`{$search_data->field_id}` = " . number_format($value, 0, '', ''); } /* not needed yet if ( !empty( $params[ 'orderby' ] ) ) $params[ 'orderby' ] = pods_evaluate_tags( $params[ 'orderby' ], true ); if ( !empty( $params[ 'groupby' ] ) ) $params[ 'groupby' ] = pods_evaluate_tags( $params[ 'groupby' ], true );*/ $display = trim(pods_var(self::$type . '_display', $options), ' {@}'); if (0 < strlen($display)) { if (isset($options['table_info']['pod']) && !empty($options['table_info']['pod'])) { if (isset($options['table_info']['pod']['object_fields']) && isset($options['table_info']['pod']['object_fields'][$display])) { $search_data->field_index = $display; $params['select'] = "`t`.`{$search_data->field_id}`, `t`.`{$search_data->field_index}`"; } elseif (isset($options['table_info']['pod']['fields'][$display])) { $search_data->field_index = $display; if ('table' == $options['table_info']['pod']['storage'] && !in_array($options['table_info']['pod']['type'], array('pod', 'table'))) { $params['select'] = "`t`.`{$search_data->field_id}`, `d`.`{$search_data->field_index}`"; } elseif ('meta' == $options['table_info']['pod']['storage']) { $params['select'] = "`t`.`{$search_data->field_id}`, `{$search_data->field_index}`.`meta_value` AS {$search_data->field_index}"; } else { $params['select'] = "`t`.`{$search_data->field_id}`, `t`.`{$search_data->field_index}`"; } } } elseif (isset($options['table_info']['object_fields']) && isset($options['table_info']['object_fields'][$display])) { $search_data->field_index = $display; $params['select'] = "`t`.`{$search_data->field_id}`, `t`.`{$search_data->field_index}`"; } } $autocomplete = false; if ('single' == pods_var(self::$type . '_format_type', $options, 'single') && 'autocomplete' == pods_var(self::$type . '_format_single', $options, 'dropdown')) { $autocomplete = true; } elseif ('multi' == pods_var(self::$type . '_format_type', $options, 'single') && 'autocomplete' == pods_var(self::$type . '_format_multi', $options, 'checkbox')) { $autocomplete = true; } $hierarchy = false; if ('data' == $context && !$autocomplete) { if ('single' == pods_var(self::$type . '_format_type', $options, 'single') && in_array(pods_var(self::$type . '_format_single', $options, 'dropdown'), array('dropdown', 'radio'))) { $hierarchy = true; } elseif ('multi' == pods_var(self::$type . '_format_type', $options, 'single') && in_array(pods_var(self::$type . '_format_multi', $options, 'checkbox'), array('multiselect', 'checkbox'))) { $hierarchy = true; } } if ($hierarchy && $options['table_info']['object_hierarchical'] && !empty($options['table_info']['field_parent'])) { $params['select'] .= ', ' . $options['table_info']['field_parent_select']; } if ($autocomplete) { if (0 == $limit) { $limit = 30; } $params['limit'] = apply_filters('pods_form_ui_field_pick_autocomplete_limit', $limit, $name, $value, $options, $pod, $id, $object_params); if (is_array($value) && $params['limit'] < count($value)) { $params['limit'] = count($value); } $params['page'] = $page; if ('admin_ajax_relationship' == $context) { $lookup_where = array($search_data->field_index => "`t`.`{$search_data->field_index}` LIKE '%" . pods_sanitize_like($data_params['query']) . "%'"); // @todo Hook into WPML for each table if ($wpdb->users == $search_data->table) { $lookup_where['display_name'] = "`t`.`display_name` LIKE '%" . pods_sanitize_like($data_params['query']) . "%'"; $lookup_where['user_login'] = "******" . pods_sanitize_like($data_params['query']) . "%'"; $lookup_where['user_email'] = "`t`.`user_email` LIKE '%" . pods_sanitize_like($data_params['query']) . "%'"; } elseif ($wpdb->posts == $search_data->table) { $lookup_where['post_title'] = "`t`.`post_title` LIKE '%" . pods_sanitize_like($data_params['query']) . "%'"; $lookup_where['post_name'] = "`t`.`post_name` LIKE '%" . pods_sanitize_like($data_params['query']) . "%'"; $lookup_where['post_content'] = "`t`.`post_content` LIKE '%" . pods_sanitize_like($data_params['query']) . "%'"; $lookup_where['post_excerpt'] = "`t`.`post_excerpt` LIKE '%" . pods_sanitize_like($data_params['query']) . "%'"; } elseif ($wpdb->terms == $search_data->table) { $lookup_where['name'] = "`t`.`name` LIKE '%" . pods_sanitize_like($data_params['query']) . "%'"; $lookup_where['slug'] = "`t`.`slug` LIKE '%" . pods_sanitize_like($data_params['query']) . "%'"; } elseif ($wpdb->comments == $search_data->table) { $lookup_where['comment_content'] = "`t`.`comment_content` LIKE '%" . pods_sanitize_like($data_params['query']) . "%'"; $lookup_where['comment_author'] = "`t`.`comment_author` LIKE '%" . pods_sanitize_like($data_params['query']) . "%'"; $lookup_where['comment_author_email'] = "`t`.`comment_author_email` LIKE '%" . pods_sanitize_like($data_params['query']) . "%'"; } $lookup_where = apply_filters('pods_form_ui_field_pick_autocomplete_lookup', $lookup_where, $data_params['query'], $name, $value, $options, $pod, $id, $object_params, $search_data); if (!empty($lookup_where)) { $params['where'][] = implode(' OR ', $lookup_where); } $orderby = array(); $orderby[] = "(`t`.`{$search_data->field_index}` LIKE '%" . pods_sanitize_like($data_params['query']) . "%' ) DESC"; $pick_orderby = pods_var_raw(self::$type . '_orderby', $options, null, null, true); if (0 < strlen($pick_orderby)) { $orderby[] = $pick_orderby; } $orderby[] = "`t`.`{$search_data->field_index}`"; $orderby[] = "`t`.`{$search_data->field_id}`"; $params['orderby'] = $orderby; } } elseif (0 < $limit) { $params['limit'] = $limit; $params['page'] = $page; } $extra = ''; if ($wpdb->posts == $search_data->table) { $extra = ', `t`.`post_type`'; } elseif ($wpdb->terms == $search_data->table) { $extra = ', `tt`.`taxonomy`'; } elseif ($wpdb->comments == $search_data->table) { $extra = ', `t`.`comment_type`'; } $params['select'] .= $extra; if ('user' == pods_var(self::$type . '_object', $options)) { $roles = pods_var(self::$type . '_user_role', $options); if (!empty($roles)) { $where = array(); foreach ((array) $roles as $role) { if (empty($role) || pods_clean_name($role) != $role && sanitize_title($role) != $role) { continue; } $where[] = $wpdb->base_prefix . (is_multisite() && !is_main_site() ? get_current_blog_id() . '_' : '') . 'capabilities.meta_value LIKE "%\\"' . pods_sanitize_like($role) . '\\"%"'; } if (!empty($where)) { $params['where'][] = implode(' OR ', $where); } } } $results = $search_data->select($params); if ($autocomplete && $params['limit'] < $search_data->total_found()) { if (!empty($value)) { $ids = $value; if (is_array($ids) && isset($ids[0]) && is_array($ids[0])) { $ids = wp_list_pluck($ids, $search_data->field_id); } if (is_array($ids)) { $ids = implode(', ', $ids); } if (is_array($params['where'])) { $params['where'] = implode(' AND ', $params['where']); } if (!empty($params['where'])) { $params['where'] .= ' AND '; } $params['where'] .= "`t`.`{$search_data->field_id}` IN ( " . $ids . " )"; $results = $search_data->select($params); } } else { $autocomplete = false; } if ('data' == $context) { self::$field_data = array('field' => $name, 'id' => $options['id'], 'autocomplete' => $autocomplete); } if ($hierarchy && !$autocomplete && !empty($results) && $options['table_info']['object_hierarchical'] && !empty($options['table_info']['field_parent'])) { $args = array('id' => $options['table_info']['field_id'], 'index' => $options['table_info']['field_index'], 'parent' => $options['table_info']['field_parent']); $results = pods_hierarchical_select($results, $args); } $ids = array(); if (!empty($results)) { $display_filter = pods_var('display_filter', pods_var_raw('options', pods_var_raw($search_data->field_index, $search_data->pod_data['object_fields']))); foreach ($results as $result) { $result = get_object_vars($result); if (!isset($result[$search_data->field_id]) || !isset($result[$search_data->field_index])) { continue; } $result[$search_data->field_index] = trim($result[$search_data->field_index]); $object = $object_type = ''; if ($wpdb->posts == $search_data->table && isset($result['post_type'])) { $object = $result['post_type']; $object_type = 'post_type'; } elseif ($wpdb->terms == $search_data->table && isset($result['taxonomy'])) { $object = $result['taxonomy']; $object_type = 'taxonomy'; } // WPML integration for Post Types and Taxonomies if (is_object($sitepress) && in_array($object_type, array('post_type', 'taxonomy'))) { $translated = false; if ('post_type' == $object_type && $sitepress->is_translated_post_type($object)) { $translated = true; } elseif ('taxonomy' == $object_type && $sitepress->is_translated_taxonomy($object)) { $translated = true; } if ($translated) { $object_id = icl_object_id($result[$search_data->field_id], $object, false, $current_language); if (0 < $object_id && !in_array($object_id, $ids)) { $text = $result[$search_data->field_index]; if ($result[$search_data->field_id] != $object_id) { if ($wpdb->posts == $search_data->table) { $text = trim(get_the_title($object_id)); } elseif ($wpdb->terms == $search_data->table) { $text = trim(get_term($object_id, $object)->name); } } $result[$search_data->field_id] = $object_id; $result[$search_data->field_index] = $text; } else { continue; } } } elseif (is_object($polylang) && in_array($object_type, array('post_type', 'taxonomy')) && method_exists($polylang, 'get_translation')) { $translated = false; if ('post_type' == $object_type && pll_is_translated_post_type($object)) { $translated = true; } elseif ('taxonomy' == $object_type && pll_is_translated_taxonomy($object)) { $translated = true; } if ($translated) { $object_id = $polylang->get_translation($object, $result[$search_data->field_id], $current_language); if (0 < $object_id && !in_array($object_id, $ids)) { $text = $result[$search_data->field_index]; if ($result[$search_data->field_id] != $object_id) { if ($wpdb->posts == $search_data->table) { $text = trim(get_the_title($object_id)); } elseif ($wpdb->terms == $search_data->table) { $text = trim(get_term($object_id, $object)->name); } } $result[$search_data->field_id] = $object_id; $result[$search_data->field_index] = $text; } else { continue; } } } if (0 < strlen($display_filter)) { $display_filter_args = pods_var('display_filter_args', pods_var_raw('options', pods_var_raw($search_data->field_index, $search_data->pod_data['object_fields']))); $args = array($display_filter, $result[$search_data->field_index]); if (!empty($display_filter_args)) { foreach ((array) $display_filter_args as $display_filter_arg) { if (isset($result[$display_filter_arg])) { $args[] = $result[$display_filter_arg]; } } } $result[$search_data->field_index] = call_user_func_array('apply_filters', $args); } if (in_array($options[self::$type . '_object'], array('site', 'network'))) { $result[$search_data->field_index] = $result[$search_data->field_index] . $result['path']; } elseif (strlen($result[$search_data->field_index]) < 1) { $result[$search_data->field_index] = '(No Title)'; } if ('admin_ajax_relationship' == $context) { $items[] = array('id' => $result[$search_data->field_id], 'text' => $result[$search_data->field_index], 'image' => ''); } else { $data[$result[$search_data->field_id]] = $result[$search_data->field_index]; } $ids[] = $result[$search_data->field_id]; } } } if ($simple && 'admin_ajax_relationship' == $context) { $found_data = array(); foreach ($data as $k => $v) { if (false !== stripos($v, $data_params['query']) || false !== stripos($k, $data_params['query'])) { $found_data[$k] = $v; } } $data = $found_data; } } if ('admin_ajax_relationship' == $context) { if (empty($items) && !empty($data)) { foreach ($data as $k => $v) { $items[] = array('id' => $k, 'text' => $v, 'image' => ''); } } return $items; } return $data; }
public function skip_default_attributes_meta($check, $object_id, $meta_key, $meta_value) { // Ignore if not default attribute if ('_default_attributes' === $meta_key) { $product = wc_get_product($object_id); // Don't let anyone delete the meta. NO ONE! if ($product && current_filter() === 'delete_post_metadata') { return false; } // _default_attributes meta should be unique if ($product && current_filter() === 'add_post_metadata') { $old_value = get_post_meta($product->id, '_default_attributes'); return empty($old_value) ? $check : false; } // Maybe is Variable Product // New translations of Variable Products are first created as simple if ($product && Utilities::maybe_variable_product($product)) { // Try Polylang first $lang = pll_get_post_language($product->id); if (!$lang) { // Must be a new translation and Polylang doesn't stored the language yet $lang = isset($_GET['new_lang']) ? $_GET['new_lang'] : ''; } foreach ($meta_value as $key => $value) { $term = get_term_by('slug', $value, $key); if ($term && pll_is_translated_taxonomy($term->taxonomy)) { $translated_term_id = pll_get_term($term->term_id, $lang); $translated_term = get_term_by('id', $translated_term_id, $term->taxonomy); // If meta is taxonomy managed by Polylang and is in the // correct language process, otherwise return false to // stop execution return $value === $translated_term->slug ? $check : false; } } } } return $check; }
/** * Yoast SEO * Translates strings for custom post types and custom taxonomies titles and meta descriptions * * @since 2.0 * * @param array $options * @return array */ function wpseo_translate_titles($options) { if (PLL() instanceof PLL_Frontend) { foreach (get_post_types(array('public' => true, '_builtin' => false)) as $t) { if (pll_is_translated_post_type($t) && !empty($options['title-' . $t])) { $options['title-' . $t] = pll__($options['title-' . $t]); $options['metadesc-' . $t] = pll__($options['metadesc-' . $t]); } } foreach (get_post_types(array('has_archive' => true, '_builtin' => false)) as $t) { if (pll_is_translated_post_type($t) && !empty($options['title-ptarchive-' . $t])) { $options['title-ptarchive-' . $t] = pll__($options['title-ptarchive-' . $t]); $options['metadesc-ptarchive-' . $t] = pll__($options['metadesc-ptarchive-' . $t]); } } foreach (get_taxonomies(array('public' => true, '_builtin' => false)) as $t) { if (pll_is_translated_taxonomy($t) && !empty($options['title-tax-' . $t])) { $options['title-tax-' . $t] = pll__($options['title-tax-' . $t]); $options['metadesc-tax-' . $t] = pll__($options['metadesc-tax-' . $t]); } } } return $options; }
/** * Get current language information from Multilingual plugins * * @since 2.6.6 * * @return array */ public static function get_current_language() { /** * @var $sitepress SitePress object * @var $polylang object */ /* * @todo wpml-comp Remove global object usage */ global $sitepress, $polylang; $lang_data = false; $translator = false; $current_language = false; // Multilingual support if (did_action('wpml_loaded') && apply_filters('wpml_setting', true, 'auto_adjust_ids')) { // WPML support $translator = 'WPML'; // Get the global current language (if set) $wpml_language = apply_filters('wpml_current_language', null); $current_language = $wpml_language != 'all' ? $wpml_language : ''; } elseif ((function_exists('PLL') || is_object($polylang)) && function_exists('pll_current_language')) { // Polylang support $translator = 'PLL'; // Get the global current language (if set) $current_language = pll_current_language('slug'); } /** * Admin functions that overwrite the current language * * @since 2.6.6 */ if (is_admin() && !empty($translator)) { if ($translator == 'PLL') { /** * Polylang support * Get the current user's perferred language. * This is a user meta setting that will overwrite the language returned from pll_current_language() * @see polylang/admin/admin-base.php -> init_user() */ $current_language = get_user_meta(get_current_user_id(), 'pll_filter_content', true); } // Get current language based on the object language if available if (function_exists('get_current_screen')) { $current_screen = get_current_screen(); /** * Overwrite the current language if needed for post types */ if (isset($current_screen->base) && ($current_screen->base == 'post' || $current_screen->base == 'edit')) { if (!empty($_GET['post'])) { /** * WPML support * In WPML the current language is always set to default on an edit screen * We need to overwrite this when the current object is not-translatable to enable relationships with different languages */ if ($translator == 'WPML' && !apply_filters('wpml_is_translated_post_type', false, get_post_type($_GET['post']))) { // Overwrite the current language to nothing if this is a NOT-translatable post_type $current_language = ''; } /** * Polylang support (1.5.4+) * In polylang the preferred language could be anything. * We only want the related objects if they are not translatable OR the same language as the current object */ if ($translator == 'PLL' && function_exists('pll_get_post_language') && pll_is_translated_post_type(get_post_type($_GET['post']))) { // Overwrite the current language if this is a translateable post_type $current_language = pll_get_post_language((int) $_GET['post']); } } /** * Polylang support (1.0.1+) * In polylang the preferred language could be anything. * When we're adding a new object and language is set we only want the related objects if they are not translatable OR the same language */ if ($translator == 'PLL' && !empty($_GET['new_lang']) && !empty($_GET['post_type']) && pll_is_translated_post_type(sanitize_text_field($_GET['post_type']))) { $current_language = $_GET['new_lang']; } /** * Overwrite the current language if needed for taxonomies */ } elseif (isset($current_screen->base) && ($current_screen->base == 'term' || $current_screen->base == 'edit-tags')) { // @todo MAYBE: Similar function like get_post_type for taxonomies so we don't need to check for $_GET['taxonomy'] if (!empty($_GET['taxonomy'])) { /* * @todo wpml-comp API call for taxonomy needed! * Suggested API call: * add_filter( 'wpml_is_translated_taxonomy', $_GET['taxonomy'], 10, 2 ); */ /** * WPML support * In WPML the current language is always set to default on an edit screen * We need to overwrite this when the current object is not-translatable to enable relationships with different languages */ if ($translator == 'WPML' && method_exists($sitepress, 'is_translated_taxonomy') && !$sitepress->is_translated_taxonomy($_GET['taxonomy'])) { // Overwrite the current language to nothing if this is a NOT-translatable taxonomy $current_language = ''; } /** * Polylang support (1.5.4+) * In polylang the preferred language could be anything. * We only want the related objects if they are not translatable OR the same language as the current object */ if ($translator == 'PLL' && !empty($_GET['tag_ID']) && function_exists('pll_get_term_language') && pll_is_translated_taxonomy(sanitize_text_field($_GET['taxonomy']))) { // Overwrite the current language if this is a translatable taxonomy $current_language = pll_get_term_language((int) $_GET['tag_ID']); } } /** * Polylang support (1.0.1+) * In polylang the preferred language could be anything. * When we're adding a new object and language is set we only want the related objects if they are not translatable OR the same language */ if ($translator == 'PLL' && !empty($_GET['new_lang']) && !empty($_GET['taxonomy']) && pll_is_translated_taxonomy(sanitize_text_field($_GET['taxonomy']))) { $current_language = $_GET['new_lang']; } } } } $current_language = pods_sanitize(sanitize_text_field($current_language)); if (!empty($current_language)) { // We need to return language data $lang_data = array('language' => $current_language, 't_id' => 0, 'tt_id' => 0, 'term' => null); /** * Polylang support * Get the language taxonomy object for the current language */ if ($translator == 'PLL') { $current_language_t = false; // Get the language term object if (function_exists('PLL') && isset(PLL()->model) && method_exists(PLL()->model, 'get_language')) { // Polylang 1.8 and newer $current_language_t = PLL()->model->get_language($current_language); } elseif (is_object($polylang) && isset($polylang->model) && method_exists($polylang->model, 'get_language')) { // Polylang 1.2 - 1.7.x $current_language_t = $polylang->model->get_language($current_language); } elseif (is_object($polylang) && method_exists($polylang, 'get_language')) { // Polylang 1.1.x and older $current_language_t = $polylang->get_language($current_language); } // If the language object exists, add it! if ($current_language_t && !empty($current_language_t->term_id)) { $lang_data['t_id'] = (int) $current_language_t->term_id; $lang_data['tt_id'] = (int) $current_language_t->term_taxonomy_id; $lang_data['term'] = $current_language_t; } } } /** * Override language data used by Pods. * * @since 2.6.6 * * @param array|false $lang_data { * Language data * * @type string $language Language slug * @type int $t_id Language term_id * @type int $tt_id Language term_taxonomy_id * @type WP_Term $term Language term object * } * @param string|boolean $translator Language plugin used */ $lang_data = apply_filters('pods_get_current_language', $lang_data, $translator); return $lang_data; }
/** * 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'; } $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); } $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_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_get_table_info_' . $current_language . '_' . md5($object_type . '_object_' . $object . '_name_' . $name . '_pod_' . $pod_name . '_field_' . $field_name); } $_info = false; if (pods_api_cache()) { $_info = pods_transient_get($transient); } if (pods_api_cache() && false === $_info && !did_action('init')) { $_info = pods_transient_get($transient . '_pre_init'); } if (false !== $_info) { $info = $_info; } else { if ('pod' == $object_type && null === $pod) { if (empty($name)) { $prefix = 'pod-'; // 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 (empty($name) && !empty($object)) { $name = $object; } $pod = $this->load_pod(array('name' => $name, 'table_info' => false), false); if (!empty($pod)) { $object_type = $pod['type']; $name = $pod['name']; $object = $pod['object']; $info['pod'] = $pod; } } elseif (null === $pod) { if (empty($name)) { $prefix = $object_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 (empty($name) && !empty($object)) { $name = $object; } if (!empty($name)) { $pod = $this->load_pod(array('name' => $name, 'table_info' => false), false); if (!empty($pod) && (null === $object_type || $object_type == $pod['type'])) { $object_type = $pod['type']; $name = $pod['name']; $object = $pod['object']; $info['pod'] = $pod; } } } elseif (!empty($pod)) { $info['pod'] = $pod; } if (0 === strpos($object_type, 'pod')) { if (empty($name)) { $prefix = 'pod-'; // 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)); } } $object_type = 'pod'; $info['table'] = $info['meta_table'] = $wpdb->prefix . 'pods_' . (empty($object) ? $name : $object); if (is_array($info['pod']) && 'pod' == pods_var('type', $info['pod'])) { $info['pod_field_index'] = $info['field_index'] = $info['meta_field_index'] = $info['meta_field_value'] = pods_var('pod_index', $info['pod']['options'], 'id', null, true); $slug_field = get_posts(array('post_type' => '_pods_field', 'posts_per_page' => 1, 'nopaging' => true, 'post_parent' => $info['pod']['id'], 'orderby' => 'menu_order', 'order' => 'ASC', 'meta_query' => array(array('key' => 'type', 'value' => 'slug')))); if (!empty($slug_field)) { $slug_field = $slug_field[0]; $info['field_slug'] = $info['pod_field_slug'] = $slug_field->post_name; } if (1 == pods_var('hierarchical', $info['pod']['options'], 0)) { $parent_field = pods_var('pod_parent', $info['pod']['options'], 'id', null, true); if (!empty($parent_field) && isset($info['pod']['fields'][$parent_field])) { $info['object_hierarchical'] = true; $info['pod_field_parent'] = $info['field_parent'] = $parent_field . '_select'; $info['field_parent_select'] = '`' . $parent_field . '`.`id` AS `' . $info['field_parent'] . '`'; } } } } 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; } $post_stati = $this->do_hook('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_stati) . '" )'; } $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')) { pods_transient_set($transient, $info); } else { pods_transient_set($transient . '_pre_init', $info); } } } $info = $this->do_hook('get_table_info', $info, $object_type, $object, $name, $pod, $field); return $info; }
/** * Find out whether a post type or a taxonomy term is translated * * @since 2.0 * * @param mixed $null * @param int $id post_id or term_id * @param string $type post type or taxonomy * @return bool */ public function wpml_element_has_translations($null, $id, $type) { $pll_type = 'post' == $type || pll_is_translated_post_type($type) ? 'post' : ('term' == $type || pll_is_translated_taxonomy($type) ? 'term' : false); return $pll_type && ($translations = call_user_func("pll_get_{$pll_type}_translations", $id)) ? count($translations) > 1 : false; }
/** * Get variations default attributes translation. * * Get the translation of the default attributes of product passed by id, in * a given language, if one is passed, otherwise in all available languages. * * @param int $product_id (required) Product id. * @param string $lang (optional) Language slug. * * @return array Indexed array, with language slug as key, of attributes * pairs [attribute] => attribute slug */ public static function getDefaultAttributesTranslation($product_id, $lang = '') { $product = wc_get_product($product_id); $translated_attributes = array(); if ($product && 'variable' === $product->product_type) { $default_attributes = $product->get_variation_default_attributes(); $terms = array(); // Array of terms: if the term is taxonomy each value is a term object, otherwise an array (term slug => term value) $langs = array(); foreach ($default_attributes as $key => $value) { $term = get_term_by('name', $value, $key); if ($term && pll_is_translated_taxonomy($term->taxonomy)) { $terms[] = $term; } else { $terms[] = array($key => $value); } } // For each product translation, get the translated default attributes if (empty($lang)) { $langs = pll_languages_list(); } else { $langs[] = $lang; // get translation for a specific language } foreach ($langs as $lang) { $translated_terms = array(); foreach ($terms as $term) { if (is_object($term)) { $translated_term_id = pll_get_term($term->term_id, $lang); $translated_term = get_term_by('id', $translated_term_id, $term->taxonomy); $translated_terms[$translated_term->taxonomy] = $translated_term->slug; } else { $translated_terms[key($term)] = $term[key($term)]; } } $translated_attributes[$lang] = $translated_terms; } } return $translated_attributes; }