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;
}
 /**
  * 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;
 }
示例#3
0
 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);
 }
示例#4
0
 /**
  * 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];
 }
示例#5
0
 /**
  * Yoast SEO
  * Modifies the sql request for posts sitemaps
  * Only when using multiple domains or subdomains
  *
  * @since 1.6.4
  *
  * @param string $sql       WHERE clause
  * @param string $post_type
  * @return string
  */
 public function wpseo_posts_where($sql, $post_type)
 {
     return pll_is_translated_post_type($post_type) ? $sql . PLL()->model->post->where_clause(PLL()->curlang) : $sql;
 }
 /**
  * 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;
 }
 /**
  * Retrieve the permalink for a post type object.
  *
  * @param string       $post_link  The post's permalink.
  * @param int|WP_Post  $post       The post in question.
  * @param bool         $leavename  Whether to keep the post name.
  * @param bool         $sample     Is it a sample permalink.
  */
 public function object_link($link, $post, $leavename = false, $sample = false)
 {
     global $polylang, $wp_rewrite;
     $key = $link . '|' . (int) $leavename . '|' . (int) $sample;
     /** Emulate Polylang's "cached" collection */
     if (isset($this->_links[$key])) {
         return $this->_links[$key];
     } else {
         // Manipulate a copy
         $post_link = $link;
         $permastruct = '';
         // This filter uses the ID instead of the post object
         if ('_get_page_link' == current_filter()) {
             $post = get_post($post);
         }
         if (!isset($wp_rewrite->extra_permastructs[$post->post_type])) {
             $post_language = $polylang->model->get_post_language($post->ID);
             if (is_object($post_language)) {
                 $post_language = $post_language->slug;
             }
             if (!$post_language && pll_is_translated_post_type($post->post_type)) {
                 $post_language = pll_current_language();
             }
             if ($post_language) {
                 $permastruct = $wp_rewrite->get_extra_permastruct($post->post_type . '_' . $post_language);
             }
             $post_type = get_post_type_object($post->post_type);
             $slug = $post->post_name;
             // If we aren't published, permalinks don't work
             $draft_or_pending = isset($post->post_status) && in_array($post->post_status, ['draft', 'pending', 'auto-draft']);
             if ((!empty($post_link) || !empty($permastruct)) && (!$draft_or_pending || $sample)) {
                 $filter_name = "parse_{$post->post_type}_link";
                 $filter_link = empty($permastruct) ? $post_link : $permastruct;
                 if (has_filter($filter_name)) {
                     // Don't bother filtering and parsing if no plugins are hooked in.
                     /**
                      * Filter the post link with the permastruct manually.
                      *
                      * @param string  $post_link  The post's permalink.
                      * @param WP_Post $post       The post in question.
                      * @param bool    $leavename  Whether to keep the post name.
                      */
                     $post_link = apply_filters($filter_name, $filter_link, $post, $leavename);
                 } else {
                     $post_link = parse_permalink_tags(empty($permastruct) ? $post_link : $permastruct, $post, $leavename);
                 }
             }
         }
         /**
          * Filter the permalink for a post with a custom post type.
          *
          * @param string  $post_link  The post's permalink.
          * @param WP_Post $post       The post in question.
          * @param bool    $leavename  Whether to keep the post name.
          * @param bool    $sample     Is it a sample permalink.
          */
         $post_link = apply_filters('pll_post_type_link', $post_link, $post, $leavename, $sample);
         $this->_links[$key] = $post_link;
     }
     return $post_link;
 }
示例#8
0
 public function wpseo_posts_where($sql, $post_type)
 {
     global $polylang;
     return pll_is_translated_post_type($post_type) ? $sql . $polylang->model->where_clause($polylang->curlang, 'post') : $sql;
 }
 public function parse_main_query($query)
 {
     if ($query !== $GLOBALS['wp_the_query']) {
         return;
     }
     $qv = $query->query_vars;
     // homepage is requested, let's set the language
     // take care to avoid posts page for which is_home = 1
     if (empty($query->query) && (is_home() || is_page() && $qv['page_id'] == $this->page_on_front)) {
         $this->home_language();
         $this->home_requested();
     }
     parent::parse_main_query($query);
     $is_archive = count($query->query) == 1 && !empty($qv['paged']) || $query->is_date || $query->is_author || !empty($qv['post_type']) && $query->is_post_type_archive && pll_is_translated_post_type($qv['post_type']);
     // sets the language in case we hide the default language
     // use $query->query['s'] as is_search is not set when search is empty
     // http://wordpress.org/support/topic/search-for-empty-string-in-default-language
     if ($this->options['hide_default'] && !isset($qv['lang']) && ($is_archive || isset($query->query['s']) || count($query->query) == 1 && !empty($qv['feed']))) {
         $this->set_language($this->model->get_language($this->options['default_lang']));
         $this->set_lang_query_var($query, $this->curlang);
     }
 }
示例#10
0
 /**
  * Yoast SEO
  * Modifies the sql request for posts sitemaps
  * Only when using multiple domains or subdomains or if some languages are not active
  *
  * @since 1.6.4
  *
  * @param string $sql       WHERE clause
  * @param string $post_type
  * @return string
  */
 public function wpseo_posts_where($sql, $post_type)
 {
     if (pll_is_translated_post_type($post_type)) {
         if (PLL()->options['force_lang'] > 1) {
             return $sql . PLL()->model->post->where_clause(PLL()->curlang);
         }
         if ($languages = $this->wpseo_get_active_languages()) {
             return $sql . PLL()->model->post->where_clause($languages);
         }
     }
     return $sql;
 }
示例#11
0
/**
 * Check if the query needs to be adapted.
 *
 * @since 0.2.0
 *
 * @param  WP_Query $query The WP_Query instance (passed by reference).
 *
 * @return bool
 */
function polylang_slug_should_run($query = '')
{
    /**
     * Disable front end query modification.
     *
     * Allows disabling front end query modification if not needed.
     *
     * @since 0.2.0
     *
     * @param bool     false  Not disabling run.
     * @param WP_Query $query The WP_Query instance (passed by reference).
     */
    $disable = apply_filters('polylang_slug_disable', false, $query);
    // The lang query should be defined if the URL contains the language
    $lang = empty($query->query['lang']) ? pll_current_language() : $query->query['lang'];
    // Checks if the post type is translated when doing a custom query with the post type defined
    $is_translated = !empty($query->query['post_type']) && !pll_is_translated_post_type($query->query['post_type']);
    if (is_admin() || !$lang || $is_translated || $disable) {
        return false;
    } else {
        return true;
    }
}
 /**
  * Parse permalink rewrite tags
  *
  * Replicates the operations performed in {@see get_permalink()}
  * to build a valid URL from a permastruct.
  *
  * This offers a more flexible solution for custom permalinks.
  *
  * @global  Polylang     $polylang   If Polylang is available, translations will be considered.
  *
  * @param   string       $post_link  The permalink building blocks.
  * @param   int|WP_Post  $id         Optional. Post ID or post object. Default current post.
  * @param   bool         $leavename  Optional. Whether to keep post name or page name. Default false.
  * @return  string|bool  $post_link  The permalink URL or false if post does not exist.
  */
 function parse_permastruct_tags($post_link, $id = 0, $leavename = false)
 {
     $rewritecode = ['%year%', '%monthnum%', '%day%', '%hour%', '%minute%', '%second%', $leavename ? '' : '%postname%', '%post_id%', '%category%', '%author%', $leavename ? '' : '%pagename%'];
     if (is_object($id) && isset($id->filter) && 'sample' == $id->filter) {
         $post = $id;
         $sample = true;
     } else {
         $post = get_post($id);
         $sample = false;
     }
     if (empty($post->ID)) {
         return false;
     }
     // If we aren't published, permalinks don't work
     $draft_or_pending = isset($post->post_status) && in_array($post->post_status, ['draft', 'pending', 'auto-draft']);
     if (!empty($post_link) && !$draft_or_pending) {
         $post_type = get_post_type_object($post->post_type);
         /**
          * Filter the post name to use as a slug.
          *
          * @param string  $post_name  The post's name.
          * @param WP_Post $post       The post in question.
          * @param bool    $leavename  Whether to keep the post name.
          */
         $slug = apply_filters("parse_{$post->post_type}_link/postname", $post->post_name, $post, $leavename);
         if (!$leavename) {
             if ($post_type->hierarchical) {
                 $slug = get_page_uri($id);
             }
             $post_link = str_replace("%{$post->post_type}%", $slug, $post_link);
         }
         if (class_exists('Polylang')) {
             global $polylang;
             if (is_object($polylang) && $polylang->options['force_lang']) {
                 $post_language = $polylang->model->get_post_language($post->ID);
                 if (is_object($post_language)) {
                     $post_language = $post_language->slug;
                 }
                 if (!$post_language && pll_is_translated_post_type($post->post_type)) {
                     $post_language = pll_current_language();
                 }
                 if ($post_language) {
                     // $post_link = $polylang->links_model->add_language_to_link( $post_link, $post_language );
                     $lang = $polylang->options['default_lang'] == $post_language && $polylang->options['hide_default'] ? '' : ($polylang->options['rewrite'] ? '' : 'language/') . $post_language;
                     $post_link = str_replace('%language%', $lang, $post_link);
                 }
             }
         }
         $unixtime = strtotime($post->post_date);
         $category = '';
         if (strpos($post_link, '%category%') !== false) {
             $cats = get_the_category($post->ID);
             if ($cats) {
                 usort($cats, '_usort_terms_by_ID');
                 // order by ID
                 /**
                  * Filter the category that gets used in the %category% permalink token.
                  *
                  * @param stdClass $cat  The category to use in the permalink.
                  * @param array    $cats Array of all categories associated with the post.
                  * @param WP_Post  $post The post in question.
                  */
                 $category_object = apply_filters('post_link_category', $cats[0], $cats, $post);
                 $category_object = get_term($category_object, 'category');
                 $category = $category_object->slug;
                 if ($parent = $category_object->parent) {
                     $category = get_category_parents($parent, false, '/', true) . $category;
                 }
             }
             // show default category in permalinks, without
             // having to assign it explicitly
             if (empty($category)) {
                 $default_category = get_term(get_option('default_category'), 'category');
                 $category = is_wp_error($default_category) ? '' : $default_category->slug;
             }
         }
         $author = '';
         if (strpos($post_link, '%author%') !== false) {
             $authordata = get_userdata($post->post_author);
             $author = $authordata->user_nicename;
         }
         $date = explode(' ', date('Y m d H i s', $unixtime));
         $rewritereplace = [$date[0], $date[1], $date[2], $date[3], $date[4], $date[5], $post->post_name, $post->ID, $category, $author, $post->post_name];
         $post_link = home_url(str_replace($rewritecode, $rewritereplace, $post_link));
         $post_link = user_trailingslashit($post_link, 'single');
     }
     return $post_link;
 }
示例#13
0
 /**
  * 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;
 }
示例#14
0
 /**
  * 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;
 }
示例#15
0
 /**
  * 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;
 }