/**
 * Function, with caching, to export all items of a Pod as a serialized php array or JSON object
 *
 * @param string     $pod_name
 * @param bool 		$json
 *
 * @return bool|mixed|null|string|void
 */
function export_pod($pod_name, $json = true)
{
    //be sure to set your Pod's name here
    //name the transient we are caching in for the Pod.
    $transient_name = "all_{$pod_name}_export";
    //check if we already have this data cached, if not continue
    if (false === ($export = pods_transient_get($transient_name))) {
        //build Pods object, get all items
        $pods = pods($pod_name, array('limit' => -1), true);
        //if we have items, loop through them, adding each item's complete row to the array
        if ($pods && $pods->total() > 0) {
            while ($pods->fetch()) {
                $export[$pods->id()] = $pods->row();
            }
        }
        if ($json) {
            $export = json_encode($export);
        } else {
            $export = serialize($export);
        }
        //cache for next time
        pods_transient_set($transient_name, $export);
    }
    return $export;
}
Пример #2
0
$field_defaults = array('name' => 'new_field', 'label' => 'New Field', 'description' => '', 'type' => 'text', 'pick_object' => '', 'sister_id' => '', 'required' => 0, 'unique' => 0);
$pick_object = PodsForm::field_method('pick', 'related_objects', true);
$tableless_field_types = PodsForm::tableless_field_types();
$simple_tableless_objects = PodsForm::field_method('pick', 'simple_objects');
$bidirectional_objects = PodsForm::field_method('pick', 'bidirectional_objects');
foreach ($pod['options'] as $_option => $_value) {
    $pod[$_option] = $_value;
}
foreach ($pod['fields'] as $_field => $_data) {
    $_data['options'] = (array) $_data['options'];
    foreach ($_data['options'] as $_option => $_value) {
        $pod['fields'][$_field][$_option] = $_value;
    }
}
$field_defaults = apply_filters('pods_field_defaults', apply_filters('pods_field_defaults_' . $pod['name'], $field_defaults, $pod));
$pick_table = pods_transient_get('pods_tables');
if (empty($pick_table)) {
    $pick_table = array('' => __('-- Select Table --', 'pods'));
    global $wpdb;
    $tables = $wpdb->get_results("SHOW TABLES", ARRAY_N);
    if (!empty($tables)) {
        foreach ($tables as $table) {
            $pick_table[$table[0]] = $table[0];
        }
    }
    pods_transient_set('pods_tables', $pick_table);
}
$field_settings = array('field_types_select' => $field_types_select, 'field_defaults' => $field_defaults, 'pick_object' => $pick_object, 'pick_table' => $pick_table, 'sister_id' => array('' => __('No Related Fields Found', 'pods')));
$field_settings = apply_filters('pods_field_settings', apply_filters('pods_field_settings_' . $pod['name'], $field_settings, $pod));
$pod['fields'] = apply_filters('pods_fields_edit', apply_filters('pods_fields_edit_' . $pod['name'], $pod['fields'], $pod));
global $wpdb;
Пример #3
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];
 }
 /**
  * Setup related objects
  *
  * @param boolean $force Whether to force refresh of related objects
  * @return bool True when data has been loaded
  * @since 2.3
  */
 public function setup_related_objects($force = false)
 {
     $new_data_loaded = false;
     if (!$force && empty(self::$related_objects)) {
         // Only load transient if we aren't forcing a refresh
         self::$related_objects = pods_transient_get('pods_related_objects');
         if (false !== self::$related_objects) {
             $new_data_loaded = true;
         }
     } elseif ($force) {
         // If we are rebuilding, make sure we start with a clean slate
         self::$related_objects = array();
     }
     if (empty(self::$related_objects)) {
         // Do a complete build of related_objects
         $new_data_loaded = true;
         // Custom
         self::$related_objects['custom-simple'] = array('label' => __('Simple (custom defined list)', 'pods'), 'group' => __('Custom', 'pods'), 'simple' => true);
         // Pods
         $pod_options = array();
         // Include PodsMeta if not already included
         pods_meta();
         // Advanced Content Types
         $_pods = PodsMeta::$advanced_content_types;
         foreach ($_pods as $pod) {
             $pod_options[$pod['name']] = $pod['label'] . ' (' . $pod['name'] . ')';
         }
         // Settings
         $_pods = PodsMeta::$settings;
         foreach ($_pods as $pod) {
             $pod_options[$pod['name']] = $pod['label'] . ' (' . $pod['name'] . ')';
         }
         asort($pod_options);
         foreach ($pod_options as $pod => $label) {
             self::$related_objects['pod-' . $pod] = array('label' => $label, 'group' => __('Pods', 'pods'), 'bidirectional' => true);
         }
         // Post Types
         $post_types = get_post_types();
         asort($post_types);
         $ignore = array('attachment', 'revision', 'nav_menu_item');
         foreach ($post_types as $post_type => $label) {
             if (in_array($post_type, $ignore) || empty($post_type)) {
                 unset($post_types[$post_type]);
                 continue;
             } elseif (0 === strpos($post_type, '_pods_') && apply_filters('pods_pick_ignore_internal', true)) {
                 unset($post_types[$post_type]);
                 continue;
             }
             $post_type = get_post_type_object($post_type);
             self::$related_objects['post_type-' . $post_type->name] = array('label' => $post_type->label . ' (' . $post_type->name . ')', 'group' => __('Post Types', 'pods'), 'bidirectional' => true);
         }
         // Taxonomies
         $taxonomies = get_taxonomies();
         asort($taxonomies);
         $ignore = array('nav_menu', 'post_format');
         foreach ($taxonomies as $taxonomy => $label) {
             if (in_array($taxonomy, $ignore) || empty($taxonomy)) {
                 unset($taxonomies[$taxonomy]);
                 continue;
             } elseif (0 === strpos($taxonomy, '_pods_') && apply_filters('pods_pick_ignore_internal', true)) {
                 unset($taxonomies[$taxonomy]);
                 continue;
             }
             $taxonomy = get_taxonomy($taxonomy);
             self::$related_objects['taxonomy-' . $taxonomy->name] = array('label' => $taxonomy->label . ' (' . $taxonomy->name . ')', 'group' => __('Taxonomies', 'pods'), 'bidirectional' => true);
         }
         // Other WP Objects
         self::$related_objects['user'] = array('label' => __('Users', 'pods'), 'group' => __('Other WP Objects', 'pods'), 'bidirectional' => true);
         self::$related_objects['role'] = array('label' => __('User Roles', 'pods'), 'group' => __('Other WP Objects', 'pods'), 'simple' => true, 'data_callback' => array($this, 'data_roles'));
         self::$related_objects['capability'] = array('label' => __('User Capabilities', 'pods'), 'group' => __('Other WP Objects', 'pods'), 'simple' => true, 'data_callback' => array($this, 'data_capabilities'));
         self::$related_objects['media'] = array('label' => __('Media', 'pods'), 'group' => __('Other WP Objects', 'pods'), 'bidirectional' => true);
         self::$related_objects['comment'] = array('label' => __('Comments', 'pods'), 'group' => __('Other WP Objects', 'pods'), 'bidirectional' => true);
         self::$related_objects['image-size'] = array('label' => __('Image Sizes', 'pods'), 'group' => __('Other WP Objects', 'pods'), 'simple' => true, 'data_callback' => array($this, 'data_image_sizes'));
         self::$related_objects['nav_menu'] = array('label' => __('Navigation Menus', 'pods'), 'group' => __('Other WP Objects', 'pods'));
         self::$related_objects['post_format'] = array('label' => __('Post Formats', 'pods'), 'group' => __('Other WP Objects', 'pods'));
         self::$related_objects['post-status'] = array('label' => __('Post Status', 'pods'), 'group' => __('Other WP Objects', 'pods'), 'simple' => true, 'data_callback' => array($this, 'data_post_stati'));
         do_action('pods_form_ui_field_pick_related_objects_other');
         self::$related_objects['country'] = array('label' => __('Countries', 'pods'), 'group' => __('Predefined Lists', 'pods'), 'simple' => true, 'data_callback' => array($this, 'data_countries'));
         self::$related_objects['us_state'] = array('label' => __('US States', 'pods'), 'group' => __('Predefined Lists', 'pods'), 'simple' => true, 'data_callback' => array($this, 'data_us_states'));
         self::$related_objects['days_of_week'] = array('label' => __('Calendar - Days of Week', 'pods'), 'group' => __('Predefined Lists', 'pods'), 'simple' => true, 'data_callback' => array($this, 'data_days_of_week'));
         self::$related_objects['months_of_year'] = array('label' => __('Calendar - Months of Year', 'pods'), 'group' => __('Predefined Lists', 'pods'), 'simple' => true, 'data_callback' => array($this, 'data_months_of_year'));
         do_action('pods_form_ui_field_pick_related_objects_predefined');
         if (did_action('init')) {
             pods_transient_set('pods_related_objects', self::$related_objects);
         }
     }
     foreach (self::$custom_related_objects as $object => $related_object) {
         if (!isset(self::$related_objects[$object])) {
             $new_data_loaded = true;
             self::$related_objects[$object] = $related_object;
         }
     }
     return $new_data_loaded;
 }
Пример #5
0
 /**
  * Check to see if Pod Page exists and return data
  *
  * $uri not required, if NULL then returns REQUEST_URI matching Pod Page
  *
  * @param string $uri The Pod Page URI to check if exists
  *
  * @return array|bool
  */
 public static function exists($uri = null)
 {
     if (null === $uri) {
         $uri = parse_url(pods_current_url());
         $uri = $uri['path'];
     } else {
         $uri = explode('?', $uri);
         $uri = explode('#', $uri[0]);
         $uri = $uri[0];
     }
     $home = parse_url(get_home_url());
     if (!empty($home) && isset($home['path']) && '/' != $home['path']) {
         $uri = substr($uri, strlen($home['path']));
     }
     $uri = trim($uri, '/');
     $uri_depth = count(array_filter(explode('/', $uri))) - 1;
     $pods_page_exclusions = array('wp-admin', 'wp-content', 'wp-includes', 'index.php', 'wp-login.php', 'wp-signup.php');
     $pods_page_exclusions = apply_filters('pods_page_exclusions', $pods_page_exclusions);
     if (is_admin() || empty($uri)) {
         return false;
     }
     foreach ($pods_page_exclusions as $exclusion) {
         if (0 === strpos($uri, $exclusion)) {
             return false;
         }
     }
     $object = false;
     if (false === strpos($uri, '*') && !apply_filters('pods_page_regex_matching', false)) {
         $object = pods_by_title($uri, ARRAY_A, '_pods_page', 'publish');
     }
     $wildcard = false;
     if (empty($object)) {
         if (false === strpos($uri, '*')) {
             $object = pods_cache_get($uri, 'pods_object_page_wildcard');
             if (!empty($object)) {
                 return $object;
             }
         }
         $pod_page_rewrites = pods_transient_get('pods_object_page_rewrites');
         if (empty($pod_page_rewrites)) {
             $pod_page_rewrites = self::flush_rewrites();
         } else {
             $pod_page_rewrites = array_flip($pod_page_rewrites);
         }
         $found_rewrite_page_id = 0;
         if (!empty($pod_page_rewrites)) {
             foreach ($pod_page_rewrites as $pod_page => $pod_page_id) {
                 if (!apply_filters('pods_page_regex_matching', false)) {
                     if (false === strpos($pod_page, '*')) {
                         continue;
                     }
                     $depth_check = strlen($pod_page) - strlen(str_replace('/', '', $pod_page));
                     $pod_page = preg_quote($pod_page, '/');
                     $pod_page = str_replace('\\*', '(.*)', $pod_page);
                     if ($uri_depth == $depth_check && preg_match('/^' . $pod_page . '$/', $uri)) {
                         $found_rewrite_page_id = $pod_page_id;
                         break;
                     }
                 } elseif (preg_match('/^' . str_replace('/', '\\/', $pod_page) . '$/', $uri)) {
                     $found_rewrite_page_id = $pod_page_id;
                     break;
                 }
             }
             if (!empty($found_rewrite_page_id)) {
                 $object = get_post($found_rewrite_page_id, ARRAY_A);
                 if (empty($object) || '_pods_page' != $object['post_type']) {
                     $object = false;
                 }
             }
         }
         $wildcard = true;
     }
     if (!empty($object)) {
         $object = array('id' => $object['ID'], 'uri' => $object['post_title'], 'code' => $object['post_content'], 'phpcode' => $object['post_content'], 'precode' => get_post_meta($object['ID'], 'precode', true), 'page_template' => get_post_meta($object['ID'], 'page_template', true), 'title' => get_post_meta($object['ID'], 'page_title', true), 'options' => array('admin_only' => (bool) get_post_meta($object['ID'], 'admin_only', true), 'restrict_role' => (bool) get_post_meta($object['ID'], 'restrict_role', true), 'restrict_capability' => (bool) get_post_meta($object['ID'], 'restrict_capability', true), 'roles_allowed' => get_post_meta($object['ID'], 'roles_allowed', true), 'capability_allowed' => get_post_meta($object['ID'], 'capability_allowed', true), 'restrict_redirect' => (bool) get_post_meta($object['ID'], 'restrict_redirect', true), 'restrict_redirect_login' => (bool) get_post_meta($object['ID'], 'restrict_redirect_login', true), 'restrict_redirect_url' => get_post_meta($object['ID'], 'restrict_redirect_url', true), 'pod' => get_post_meta($object['ID'], 'pod', true), 'pod_slug' => get_post_meta($object['ID'], 'pod_slug', true)));
         if ($wildcard) {
             pods_cache_set($uri, $object, 'pods_object_page_wildcard', 3600);
         }
         return $object;
     }
     return false;
 }
/**
 * Return a variable (if exists)
 *
 * @param mixed $var The variable name, can also be a modifier for specific types
 * @param string|array|object $type (optional) Super globals, url/url-relative, constants, globals, options, transients, cache, user data, Pod field values, dates
 * @param mixed $default (optional) The default value to set if variable doesn't exist
 * @param bool $strict (optional) Only allow values (must not be empty)
 * @param array $params (optional) Set 'casting'=>true to cast value from $default, 'allowed'=>$allowed to restrict a value to what's allowed
 *
 * @return mixed The variable (if exists), or default value
 * @since 2.3.10
 */
function pods_v($var = null, $type = 'get', $default = null, $strict = false, $params = array())
{
    $defaults = array('casting' => false, 'allowed' => null);
    $params = (object) array_merge($defaults, (array) $params);
    $output = null;
    if (null === $type || '' === $type) {
        // Invalid $type
    } elseif (is_array($type)) {
        if (isset($type[$var])) {
            $output = $type[$var];
        }
    } elseif (is_object($type)) {
        if (isset($type->{$var})) {
            $output = $type->{$var};
        }
    } else {
        $type = strtolower((string) $type);
        switch ($type) {
            case 'get':
                if (isset($_GET[$var])) {
                    $output = pods_unslash($_GET[$var]);
                }
                break;
            case 'post':
                if (isset($_POST[$var])) {
                    $output = pods_unslash($_POST[$var]);
                }
                break;
            case 'request':
                if (isset($_REQUEST[$var])) {
                    $output = pods_unslash($_REQUEST[$var]);
                }
                break;
            case 'url':
            case 'uri':
                $url = parse_url(pods_current_url());
                $uri = trim($url['path'], '/');
                $uri = array_filter(explode('/', $uri));
                if ('first' == $var) {
                    $var = 0;
                } elseif ('last' == $var) {
                    $var = -1;
                }
                if (is_numeric($var)) {
                    $output = $var < 0 ? pods_v(count($uri) + $var, $uri) : pods_v($var, $uri);
                }
                break;
            case 'url-relative':
                $url_raw = pods_current_url();
                $prefix = get_site_url();
                if (substr($url_raw, 0, strlen($prefix)) == $prefix) {
                    $url_raw = substr($url_raw, strlen($prefix) + 1, strlen($url_raw));
                }
                $url = parse_url($url_raw);
                $uri = trim($url['path'], '/');
                $uri = array_filter(explode('/', $uri));
                if ('first' == $var) {
                    $var = 0;
                } elseif ('last' == $var) {
                    $var = -1;
                }
                if (is_numeric($var)) {
                    $output = $var < 0 ? pods_v(count($uri) + $var, $uri) : pods_v($var, $uri);
                }
                break;
            case 'template-url':
                $output = get_template_directory_uri();
                break;
            case 'stylesheet-url':
                $output = get_stylesheet_directory_uri();
                break;
            case 'site-url':
                $blog_id = $scheme = null;
                $path = '';
                if (is_array($var)) {
                    if (isset($var[0])) {
                        $blog_id = $var[0];
                    } elseif (isset($var[1])) {
                        $path = $var[1];
                    } elseif (isset($var[2])) {
                        $scheme = $var[2];
                    }
                } else {
                    $blog_id = $var;
                }
                $output = get_site_url($blog_id, $path, $scheme);
                break;
            case 'home-url':
                $blog_id = $scheme = null;
                $path = '';
                if (is_array($var)) {
                    if (isset($var[0])) {
                        $blog_id = $var[0];
                    } elseif (isset($var[1])) {
                        $path = $var[1];
                    } elseif (isset($var[2])) {
                        $scheme = $var[2];
                    }
                } else {
                    $blog_id = $var;
                }
                $output = get_home_url($blog_id, $path, $scheme);
                break;
            case 'admin-url':
                $blog_id = $scheme = null;
                $path = '';
                if (is_array($var)) {
                    if (isset($var[0])) {
                        $blog_id = $var[0];
                    } elseif (isset($var[1])) {
                        $path = $var[1];
                    } elseif (isset($var[2])) {
                        $scheme = $var[2];
                    }
                } else {
                    $blog_id = $var;
                }
                $output = get_admin_url($blog_id, $path, $scheme);
                break;
            case 'includes-url':
                $output = includes_url($var);
                break;
            case 'content-url':
                $output = content_url($var);
                break;
            case 'plugins-url':
                $path = $plugin = '';
                if (is_array($var)) {
                    if (isset($var[0])) {
                        $path = $var[0];
                    } elseif (isset($var[1])) {
                        $plugin = $var[1];
                    }
                } else {
                    $path = $var;
                }
                $output = plugins_url($path, $plugin);
                break;
            case 'network-site-url':
                $path = '';
                $scheme = null;
                if (is_array($var)) {
                    if (isset($var[0])) {
                        $path = $var[0];
                    } elseif (isset($var[1])) {
                        $scheme = $var[1];
                    }
                } else {
                    $path = $var;
                }
                $output = network_site_url($path, $scheme);
                break;
            case 'network-home-url':
                $path = '';
                $scheme = null;
                if (is_array($var)) {
                    if (isset($var[0])) {
                        $path = $var[0];
                    } elseif (isset($var[1])) {
                        $scheme = $var[1];
                    }
                } else {
                    $path = $var;
                }
                $output = network_home_url($path, $scheme);
                break;
            case 'network-admin-url':
                $path = '';
                $scheme = null;
                if (is_array($var)) {
                    if (isset($var[0])) {
                        $path = $var[0];
                    } elseif (isset($var[1])) {
                        $scheme = $var[1];
                    }
                } else {
                    $path = $var;
                }
                $output = network_admin_url($path, $scheme);
                break;
            case 'user-admin-url':
                $path = '';
                $scheme = null;
                if (is_array($var)) {
                    if (isset($var[0])) {
                        $path = $var[0];
                    } elseif (isset($var[1])) {
                        $scheme = $var[1];
                    }
                } else {
                    $path = $var;
                }
                $output = user_admin_url($path, $scheme);
                break;
            case 'prefix':
                global $wpdb;
                $output = $wpdb->prefix;
                break;
            case 'server':
                if (!pods_strict()) {
                    if (isset($_SERVER[$var])) {
                        $output = pods_unslash($_SERVER[$var]);
                    } elseif (isset($_SERVER[strtoupper($var)])) {
                        $output = pods_unslash($_SERVER[strtoupper($var)]);
                    }
                }
                break;
            case 'session':
                if (isset($_SESSION[$var])) {
                    $output = $_SESSION[$var];
                }
                break;
            case 'global':
            case 'globals':
                if (isset($GLOBALS[$var])) {
                    $output = $GLOBALS[$var];
                }
                break;
            case 'cookie':
                if (isset($_COOKIE[$var])) {
                    $output = pods_unslash($_COOKIE[$var]);
                }
                break;
            case 'constant':
                if (defined($var)) {
                    $output = constant($var);
                }
                break;
            case 'user':
                if (is_user_logged_in()) {
                    $user = get_userdata(get_current_user_id());
                    if (isset($user->{$var})) {
                        $value = $user->{$var};
                    } elseif ('role' == $var) {
                        $value = '';
                        if (!empty($user->roles)) {
                            $value = array_shift($user->roles);
                        }
                    } else {
                        $value = get_user_meta($user->ID, $var);
                    }
                    if (is_array($value) && !empty($value)) {
                        $output = $value;
                    } elseif (!is_array($value) && 0 < strlen($value)) {
                        $output = $value;
                    }
                }
                break;
            case 'option':
                $output = get_option($var, $default);
                break;
            case 'site-option':
                $output = get_site_option($var, $default);
                break;
            case 'transient':
                $output = get_transient($var);
                break;
            case 'site-transient':
                $output = get_site_transient($var);
                break;
            case 'cache':
                if (isset($GLOBALS['wp_object_cache']) && is_object($GLOBALS['wp_object_cache'])) {
                    $group = 'default';
                    $force = false;
                    if (!is_array($var)) {
                        $var = explode('|', $var);
                    }
                    if (isset($var[0])) {
                        if (isset($var[1])) {
                            $group = $var[1];
                        }
                        if (isset($var[2])) {
                            $force = $var[2];
                        }
                        $var = $var[0];
                        $output = wp_cache_get($var, $group, $force);
                    }
                }
                break;
            case 'pods-transient':
                $callback = null;
                if (!is_array($var)) {
                    $var = explode('|', $var);
                }
                if (isset($var[0])) {
                    if (isset($var[1])) {
                        $callback = $var[1];
                    }
                    $var = $var[0];
                    $output = pods_transient_get($var, $callback);
                }
                break;
            case 'pods-site-transient':
                $callback = null;
                if (!is_array($var)) {
                    $var = explode('|', $var);
                }
                if (isset($var[0])) {
                    if (isset($var[1])) {
                        $callback = $var[1];
                    }
                    $var = $var[0];
                    $output = pods_site_transient_get($var, $callback);
                }
                break;
            case 'pods-cache':
                if (isset($GLOBALS['wp_object_cache']) && is_object($GLOBALS['wp_object_cache'])) {
                    $group = 'default';
                    $callback = null;
                    if (!is_array($var)) {
                        $var = explode('|', $var);
                    }
                    if (isset($var[0])) {
                        if (isset($var[1])) {
                            $group = $var[1];
                        }
                        if (isset($var[2])) {
                            $callback = $var[2];
                        }
                        $var = $var[0];
                        $output = pods_cache_get($var, $group, $callback);
                    }
                }
                break;
            case 'pods-option-cache':
                $group = 'default';
                $callback = null;
                if (!is_array($var)) {
                    $var = explode('|', $var);
                }
                if (isset($var[0])) {
                    if (isset($var[1])) {
                        $group = $var[1];
                    }
                    if (isset($var[2])) {
                        $callback = $var[2];
                    }
                    $var = $var[0];
                    $output = pods_option_cache_get($var, $group, $callback);
                }
                break;
            case 'date':
                $var = explode('|', $var);
                if (!empty($var)) {
                    $output = date_i18n($var[0], isset($var[1]) ? strtotime($var[1]) : false);
                }
                break;
            case 'pods':
            case 'pods_display':
                /**
                 * @var $pods Pods
                 */
                global $pods;
                if (is_object($pods) && 'Pods' == get_class($pods)) {
                    if ('pods' === $type) {
                        $output = $pods->field($var);
                        if (is_array($output)) {
                            $options = array('field' => $var, 'fields' => $pods->fields);
                            $output = pods_serial_comma($output, $options);
                        }
                    } elseif ('pods_display' === $type) {
                        $output = $pods->display($var);
                    }
                }
                break;
            default:
                $output = apply_filters('pods_var_' . $type, $default, $var, $strict, $params);
        }
    }
    if (null !== $default) {
        // Set default
        if (null === $output) {
            $output = $default;
        }
        // Casting
        if (true === $params->casting) {
            $output = pods_cast($output, $default);
        }
    }
    // Strict defaults for empty values
    if (true === $strict) {
        if (empty($output)) {
            $output = $default;
        }
    }
    // Allowed values
    if (null !== $params->allowed) {
        if (is_array($params->allowed)) {
            // Not in array and is not the same array
            if (!in_array($output, $params->allowed) && (!is_array($output) || $output !== $params->allowed)) {
                $output = $default;
            }
        } elseif ($output !== $params->allowed) {
            // Value doesn't match
            $output = $default;
        }
    }
    return $output;
}
Пример #7
0
 /**
  * Update Post Type messages
  *
  * @param array $messages
  *
  * @return array
  * @since 2.0.2
  */
 public function setup_updated_messages($messages)
 {
     global $post, $post_ID;
     $post_types = PodsMeta::$post_types;
     $existing_post_types = get_post_types();
     $pods_cpt_ct = pods_transient_get('pods_wp_cpt_ct');
     if (empty($pods_cpt_ct) || empty($post_types)) {
         return $messages;
     }
     foreach ($post_types as $post_type) {
         if (!isset($pods_cpt_ct['post_types'][$post_type['name']])) {
             continue;
         }
         $labels = self::object_label_fix($pods_cpt_ct['post_types'][$post_type['name']], 'post_type');
         $labels = $labels['labels'];
         $messages[$post_type['name']] = array(1 => sprintf(__('%s updated. <a href="%s">%s</a>', 'pods'), $labels['singular_name'], esc_url(get_permalink($post_ID)), $labels['view_item']), 2 => __('Custom field updated.', 'pods'), 3 => __('Custom field deleted.', 'pods'), 4 => sprintf(__('%s updated.', 'pods'), $labels['singular_name']), 5 => isset($_GET['revision']) ? sprintf(__('%s restored to revision from %s', 'pods'), $labels['singular_name'], wp_post_revision_title((int) $_GET['revision'], false)) : false, 6 => sprintf(__('%s published. <a href="%s">%s</a>', 'pods'), $labels['singular_name'], esc_url(get_permalink($post_ID)), $labels['view_item']), 7 => sprintf(__('%s saved.', 'pods'), $labels['singular_name']), 8 => sprintf(__('%s submitted. <a target="_blank" href="%s">Preview %s</a>', 'pods'), $labels['singular_name'], esc_url(add_query_arg('preview', 'true', get_permalink($post_ID))), $labels['singular_name']), 9 => sprintf(__('%s scheduled for: <strong>%1$s</strong>. <a target="_blank" href="%2$s">Preview %s</a>', 'pods'), $labels['singular_name'], date_i18n(__('M j, Y @ G:i'), strtotime($post->post_date)), esc_url(get_permalink($post_ID)), $labels['singular_name']), 10 => sprintf(__('%s draft updated. <a target="_blank" href="%s">Preview %s</a>', 'pods'), $labels['singular_name'], esc_url(add_query_arg('preview', 'true', get_permalink($post_ID))), $labels['singular_name']));
         if (false === (bool) $pods_cpt_ct['post_types'][$post_type['name']]['public']) {
             $messages[$post_type['name']][1] = sprintf(__('%s updated.', 'pods'), $labels['singular_name']);
             $messages[$post_type['name']][6] = sprintf(__('%s published.', 'pods'), $labels['singular_name']);
             $messages[$post_type['name']][8] = sprintf(__('%s submitted.', 'pods'), $labels['singular_name']);
             $messages[$post_type['name']][9] = sprintf(__('%s scheduled for: <strong>%1$s</strong>.', 'pods'), $labels['singular_name'], date_i18n(__('M j, Y @ G:i'), strtotime($post->post_date)));
             $messages[$post_type['name']][10] = sprintf(__('%s draft updated.', 'pods'), $labels['singular_name']);
         }
     }
     return $messages;
 }
Пример #8
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;
 }
Пример #9
0
 /**
  * Add REST API support to post type and taxonomy objects.
  *
  * @uses "init"
  *
  * @since 2.5.6
  */
 public function add_rest_support()
 {
     static $rest_support_added;
     if (!function_exists('register_rest_field')) {
         return;
     }
     include_once PODS_DIR . 'classes/PodsRESTFields.php';
     include_once PODS_DIR . 'classes/PodsRESTHandlers.php';
     $rest_bases = pods_transient_get('pods_rest_bases');
     if (empty($rest_bases)) {
         $pods = pods_api()->load_pods();
         $rest_bases = array();
         if (!empty($pods) && is_array($pods)) {
             foreach ($pods as $pod) {
                 $type = $pod['type'];
                 if (in_array($type, array('post_type', 'taxonomy'))) {
                     if ($pod && PodsRESTHandlers::pod_extends_core_route($pod)) {
                         $rest_bases[$pod['name']] = array('type' => $type, 'base' => sanitize_title(pods_v('rest_base', $pod['options'], $pod['name'])));
                     }
                 }
             }
         }
         if (empty($rest_bases)) {
             $rest_bases = 'none';
         }
         pods_transient_set('pods_rest_bases', $rest_bases);
     }
     if (empty($rest_support_added) && !empty($rest_bases) && 'none' !== $rest_bases) {
         foreach ($rest_bases as $pod_name => $pod_info) {
             $pod_type = $pod_info['type'];
             $rest_base = $pod_info['base'];
             if ('post_type' == $pod_type) {
                 PodsRESTHandlers::post_type_rest_support($pod_name, $rest_base);
             } elseif ('taxonomy' == $pod_type) {
                 PodsRESTHandlers::taxonomy_rest_support($pod_name, $rest_base);
             }
             new PodsRESTFields($pod_name);
         }
         $rest_support_added = true;
     }
 }
 /**
  * Test if archive is set for post types that don't have archives.
  *
  * @return bool|mixed|null|void
  *
  * @since 2.4.5
  */
 function archive_test()
 {
     //try to get cached results of this method
     $key = 'pods_pfat_archive_test';
     $archive_test = pods_transient_get($key);
     if ($archive_test === false) {
         $front = $this->front_end(true);
         $auto_pods = $front->auto_pods();
         foreach ($auto_pods as $name => $pod) {
             if (!$pod['has_archive'] && $pod['archive'] && $pod['type'] !== 'taxonomy' && !in_array($name, array('post', 'page', 'attachment'))) {
                 $archive_test[$pod['label']] = 'fail';
             }
         }
         pods_transient_set($key, $archive_test);
     }
     return $archive_test;
 }
Пример #11
0
/**
 * Return a variable (if exists)
 *
 * @param mixed $var The variable name, can also be a modifier for specific types
 * @param string|array|object $type (optional) Super globals, url/url-relative, constants, globals, options, transients, cache, user data, Pod field values, dates
 * @param mixed $default (optional) The default value to set if variable doesn't exist
 * @param bool $strict (optional) Only allow values (must not be empty)
 * @param array $params (optional) Set 'casting'=>true to cast value from $default, 'allowed'=>$allowed to restrict a value to what's allowed
 *
 * @return mixed The variable (if exists), or default value
 * @since 2.3.10
 */
function pods_v($var = null, $type = 'get', $default = null, $strict = false, $params = array())
{
    $defaults = array('casting' => false, 'allowed' => null);
    $params = (object) array_merge($defaults, (array) $params);
    $output = null;
    if (null === $type || '' === $type) {
        // Invalid $type
    } elseif (is_array($type)) {
        if (isset($type[$var])) {
            $output = $type[$var];
        }
    } elseif (is_object($type)) {
        if (isset($type->{$var})) {
            $output = $type->{$var};
        }
    } else {
        $type = strtolower((string) $type);
        switch ($type) {
            case 'get':
                if (isset($_GET[$var])) {
                    $output = pods_unslash($_GET[$var]);
                }
                break;
            case 'post':
                if (isset($_POST[$var])) {
                    $output = pods_unslash($_POST[$var]);
                }
                break;
            case 'request':
                if (isset($_REQUEST[$var])) {
                    $output = pods_unslash($_REQUEST[$var]);
                }
                break;
            case 'url':
            case 'uri':
                $url = parse_url(pods_current_url());
                $uri = trim($url['path'], '/');
                $uri = array_filter(explode('/', $uri));
                if ('first' == $var) {
                    $var = 0;
                } elseif ('last' == $var) {
                    $var = -1;
                }
                if (is_numeric($var)) {
                    $output = $var < 0 ? pods_v(count($uri) + $var, $uri) : pods_v($var, $uri);
                }
                break;
            case 'url-relative':
                $url_raw = pods_current_url();
                $prefix = get_site_url();
                if (substr($url_raw, 0, strlen($prefix)) == $prefix) {
                    $url_raw = substr($url_raw, strlen($prefix) + 1, strlen($url_raw));
                }
                $url = parse_url($url_raw);
                $uri = trim($url['path'], '/');
                $uri = array_filter(explode('/', $uri));
                if ('first' == $var) {
                    $var = 0;
                } elseif ('last' == $var) {
                    $var = -1;
                }
                if (is_numeric($var)) {
                    $output = $var < 0 ? pods_v(count($uri) + $var, $uri) : pods_v($var, $uri);
                }
                break;
            case 'template-url':
                $output = get_template_directory_uri();
                break;
            case 'stylesheet-url':
                $output = get_stylesheet_directory_uri();
                break;
            case 'site-url':
                $blog_id = $scheme = null;
                $path = '';
                if (is_array($var)) {
                    if (isset($var[0])) {
                        $blog_id = $var[0];
                    } elseif (isset($var[1])) {
                        $path = $var[1];
                    } elseif (isset($var[2])) {
                        $scheme = $var[2];
                    }
                } else {
                    $blog_id = $var;
                }
                $output = get_site_url($blog_id, $path, $scheme);
                break;
            case 'home-url':
                $blog_id = $scheme = null;
                $path = '';
                if (is_array($var)) {
                    if (isset($var[0])) {
                        $blog_id = $var[0];
                    } elseif (isset($var[1])) {
                        $path = $var[1];
                    } elseif (isset($var[2])) {
                        $scheme = $var[2];
                    }
                } else {
                    $blog_id = $var;
                }
                $output = get_home_url($blog_id, $path, $scheme);
                break;
            case 'admin-url':
                $blog_id = $scheme = null;
                $path = '';
                if (is_array($var)) {
                    if (isset($var[0])) {
                        $blog_id = $var[0];
                    } elseif (isset($var[1])) {
                        $path = $var[1];
                    } elseif (isset($var[2])) {
                        $scheme = $var[2];
                    }
                } else {
                    $blog_id = $var;
                }
                $output = get_admin_url($blog_id, $path, $scheme);
                break;
            case 'includes-url':
                $output = includes_url($var);
                break;
            case 'content-url':
                $output = content_url($var);
                break;
            case 'plugins-url':
                $path = $plugin = '';
                if (is_array($var)) {
                    if (isset($var[0])) {
                        $path = $var[0];
                    } elseif (isset($var[1])) {
                        $plugin = $var[1];
                    }
                } else {
                    $path = $var;
                }
                $output = plugins_url($path, $plugin);
                break;
            case 'network-site-url':
                $path = '';
                $scheme = null;
                if (is_array($var)) {
                    if (isset($var[0])) {
                        $path = $var[0];
                    } elseif (isset($var[1])) {
                        $scheme = $var[1];
                    }
                } else {
                    $path = $var;
                }
                $output = network_site_url($path, $scheme);
                break;
            case 'network-home-url':
                $path = '';
                $scheme = null;
                if (is_array($var)) {
                    if (isset($var[0])) {
                        $path = $var[0];
                    } elseif (isset($var[1])) {
                        $scheme = $var[1];
                    }
                } else {
                    $path = $var;
                }
                $output = network_home_url($path, $scheme);
                break;
            case 'network-admin-url':
                $path = '';
                $scheme = null;
                if (is_array($var)) {
                    if (isset($var[0])) {
                        $path = $var[0];
                    } elseif (isset($var[1])) {
                        $scheme = $var[1];
                    }
                } else {
                    $path = $var;
                }
                $output = network_admin_url($path, $scheme);
                break;
            case 'user-admin-url':
                $path = '';
                $scheme = null;
                if (is_array($var)) {
                    if (isset($var[0])) {
                        $path = $var[0];
                    } elseif (isset($var[1])) {
                        $scheme = $var[1];
                    }
                } else {
                    $path = $var;
                }
                $output = user_admin_url($path, $scheme);
                break;
            case 'prefix':
                global $wpdb;
                $output = $wpdb->prefix;
                break;
            case 'server':
                if (!pods_strict()) {
                    if (isset($_SERVER[$var])) {
                        $output = pods_unslash($_SERVER[$var]);
                    } elseif (isset($_SERVER[strtoupper($var)])) {
                        $output = pods_unslash($_SERVER[strtoupper($var)]);
                    }
                }
                break;
            case 'session':
                if (isset($_SESSION[$var])) {
                    $output = $_SESSION[$var];
                }
                break;
            case 'global':
            case 'globals':
                if (isset($GLOBALS[$var])) {
                    $output = $GLOBALS[$var];
                }
                break;
            case 'cookie':
                if (isset($_COOKIE[$var])) {
                    $output = pods_unslash($_COOKIE[$var]);
                }
                break;
            case 'constant':
                if (defined($var)) {
                    $output = constant($var);
                }
                break;
            case 'user':
                if (is_user_logged_in()) {
                    $user = get_userdata(get_current_user_id());
                    if (isset($user->{$var})) {
                        $value = $user->{$var};
                    } elseif ('role' == $var) {
                        $value = '';
                        if (!empty($user->roles)) {
                            $value = array_shift($user->roles);
                        }
                    } else {
                        $value = get_user_meta($user->ID, $var);
                    }
                    if (is_array($value) && !empty($value)) {
                        $output = $value;
                    } elseif (!is_array($value) && 0 < strlen($value)) {
                        $output = $value;
                    }
                }
                break;
            case 'option':
                $output = get_option($var, $default);
                break;
            case 'site-option':
                $output = get_site_option($var, $default);
                break;
            case 'transient':
                $output = get_transient($var);
                break;
            case 'site-transient':
                $output = get_site_transient($var);
                break;
            case 'cache':
                if (isset($GLOBALS['wp_object_cache']) && is_object($GLOBALS['wp_object_cache'])) {
                    $group = 'default';
                    $force = false;
                    if (!is_array($var)) {
                        $var = explode('|', $var);
                    }
                    if (isset($var[0])) {
                        if (isset($var[1])) {
                            $group = $var[1];
                        }
                        if (isset($var[2])) {
                            $force = $var[2];
                        }
                        $var = $var[0];
                        $output = wp_cache_get($var, $group, $force);
                    }
                }
                break;
            case 'pods-transient':
                $callback = null;
                if (!is_array($var)) {
                    $var = explode('|', $var);
                }
                if (isset($var[0])) {
                    if (isset($var[1])) {
                        $callback = $var[1];
                    }
                    $var = $var[0];
                    $output = pods_transient_get($var, $callback);
                }
                break;
            case 'pods-site-transient':
                $callback = null;
                if (!is_array($var)) {
                    $var = explode('|', $var);
                }
                if (isset($var[0])) {
                    if (isset($var[1])) {
                        $callback = $var[1];
                    }
                    $var = $var[0];
                    $output = pods_site_transient_get($var, $callback);
                }
                break;
            case 'pods-cache':
                if (isset($GLOBALS['wp_object_cache']) && is_object($GLOBALS['wp_object_cache'])) {
                    $group = 'default';
                    $callback = null;
                    if (!is_array($var)) {
                        $var = explode('|', $var);
                    }
                    if (isset($var[0])) {
                        if (isset($var[1])) {
                            $group = $var[1];
                        }
                        if (isset($var[2])) {
                            $callback = $var[2];
                        }
                        $var = $var[0];
                        $output = pods_cache_get($var, $group, $callback);
                    }
                }
                break;
            case 'pods-option-cache':
                $group = 'default';
                $callback = null;
                if (!is_array($var)) {
                    $var = explode('|', $var);
                }
                if (isset($var[0])) {
                    if (isset($var[1])) {
                        $group = $var[1];
                    }
                    if (isset($var[2])) {
                        $callback = $var[2];
                    }
                    $var = $var[0];
                    $output = pods_option_cache_get($var, $group, $callback);
                }
                break;
            case 'date':
                $var = explode('|', $var);
                if (!empty($var)) {
                    $output = date_i18n($var[0], isset($var[1]) ? strtotime($var[1]) : false);
                }
                break;
            case 'pods':
            case 'pods_display':
                /**
                 * @var $pods Pods
                 */
                global $pods;
                if (is_object($pods) && 'Pods' == get_class($pods)) {
                    if ('pods' === $type) {
                        $output = $pods->field($var);
                        if (is_array($output)) {
                            $options = array('field' => $var, 'fields' => $pods->fields);
                            $output = pods_serial_comma($output, $options);
                        }
                    } elseif ('pods_display' === $type) {
                        $output = $pods->display($var);
                    }
                }
                break;
            case 'post_id':
                if (empty($var)) {
                    if (!empty($default)) {
                        $post_id = $default;
                    } else {
                        // If no $var and no $default then use current post ID
                        $post_id = get_the_ID();
                    }
                } else {
                    $post_id = $var;
                }
                if (did_action('wpml_loaded')) {
                    /* Only call filter if WPML is installed */
                    $post_type = get_post_type($post_id);
                    $post_id = apply_filters('wpml_object_id', $post_id, $post_type, true);
                } elseif (function_exists('pll_get_post')) {
                    $polylang_id = pll_get_post($post_id);
                    if (!empty($polylang_id)) {
                        $post_id = $polylang_id;
                    }
                }
                // Add other translation plugin specific code here
                /**
                 * Filter to override post_id
                 *
                 * Generally used with language translation plugins in order to return the post id of a
                 * translated post
                 *
                 * @param  int $post_id The post ID of current post
                 * @param  mixed $default The default value to set if variable doesn't exist
                 * @param  mixed $var The variable name, can also be a modifier for specific types
                 * @param  bool $strict Only allow values (must not be empty)
                 * @param  array $params Set 'casting'=>true to cast value from $default, 'allowed'=>$allowed to restrict a value to what's allowed
                 *
                 * @since 2.6.6
                 */
                $output = apply_filters('pods_var_post_id', $post_id, $default, $var, $strict, $params);
                break;
            default:
                $output = apply_filters('pods_var_' . $type, $default, $var, $strict, $params);
        }
    }
    if (null !== $default) {
        // Set default
        if (null === $output) {
            $output = $default;
        }
        // Casting
        if (true === $params->casting) {
            $output = pods_cast($output, $default);
        }
    }
    // Strict defaults for empty values
    if (true === $strict) {
        if (empty($output)) {
            $output = $default;
        }
    }
    // Allowed values
    if (null !== $params->allowed) {
        if (is_array($params->allowed)) {
            // Not in array and is not the same array
            if (!in_array($output, $params->allowed) && (!is_array($output) || $output !== $params->allowed)) {
                $output = $default;
            }
        } elseif ($output !== $params->allowed) {
            // Value doesn't match
            $output = $default;
        }
    }
    return $output;
}
Пример #12
0
 /**
  * Take over the avatar served from WordPress
  *
  * @param string $avatar Default Avatar Image output from WordPress
  * @param int|string|object $id_or_email A user ID, email address, or comment object
  * @param int $size Size of the avatar image
  * @param string $default URL to a default image to use if no avatar is available
  * @param string $alt Alternate text to use in image tag. Defaults to blank
  * @return string <img> tag for the user's avatar
  */
 public function get_avatar($avatar, $id_or_email, $size, $default = '', $alt = '')
 {
     $_user_ID = 0;
     if (is_numeric($id_or_email) && 0 < $id_or_email) {
         $_user_ID = (int) $id_or_email;
     } elseif (is_object($id_or_email) && isset($id_or_email->user_id) && 0 < $id_or_email->user_id) {
         $_user_ID = (int) $id_or_email->user_id;
     } elseif (is_object($id_or_email) && isset($id_or_email->ID) && isset($id_or_email->user_login) && 0 < $id_or_email->ID) {
         $_user_ID = (int) $id_or_email->ID;
     } elseif (!is_object($id_or_email) && false !== strpos($id_or_email, '@')) {
         $_user = get_user_by('email', $id_or_email);
         if (!empty($_user)) {
             $_user_ID = (int) $_user->ID;
         }
     }
     if (0 < $_user_ID && !empty(PodsMeta::$user)) {
         $avatar_cached = pods_cache_get($_user_ID . '-' . $size, 'pods_avatars');
         if (!empty($avatar_cached)) {
             $avatar = $avatar_cached;
         } else {
             $avatar_field = pods_transient_get('pods_avatar_field');
             $user = current(PodsMeta::$user);
             if (empty($avatar_field)) {
                 foreach ($user['fields'] as $field) {
                     if ('avatar' == $field['type']) {
                         $avatar_field = $field['name'];
                         pods_transient_set('pods_avatar_field', $avatar_field);
                         break;
                     }
                 }
             } elseif (!isset($user['fields'][$avatar_field])) {
                 $avatar_field = false;
             }
             if (!empty($avatar_field)) {
                 $user_avatar = get_user_meta($_user_ID, $avatar_field . '.ID', true);
                 if (!empty($user_avatar)) {
                     $attributes = array('alt' => '', 'class' => 'avatar avatar-' . $size . ' photo');
                     if (!empty($alt)) {
                         $attributes['alt'] = $alt;
                     }
                     $user_avatar = pods_image($user_avatar, array($size, $size), 0, $attributes);
                     if (!empty($user_avatar)) {
                         $avatar = $user_avatar;
                         pods_cache_set($_user_ID . '-' . $size, $avatar, 'pods_avatars');
                     }
                 }
             }
         }
     }
     return $avatar;
 }
Пример #13
0
 /**
  * Setup related objects
  *
  * @param boolean $force Whether to force refresh of related objects
  *
  * @since 2.3
  */
 public function setup_related_objects($force = false)
 {
     $related_objects = pods_transient_get('pods_related_objects');
     if (!$force && !empty($related_objects)) {
         self::$related_objects = $related_objects;
     } else {
         // Custom
         self::$related_objects['custom-simple'] = array('label' => __('Simple (custom defined list)', 'pods'), 'group' => __('Custom', 'pods'), 'simple' => true);
         // Pods
         $pod_options = array();
         // Advanced Content Types
         $_pods = PodsMeta::$advanced_content_types;
         foreach ($_pods as $pod) {
             $pod_options[$pod['name']] = $pod['label'] . ' (' . $pod['name'] . ')';
         }
         // Settings
         $_pods = PodsMeta::$settings;
         foreach ($_pods as $pod) {
             $pod_options[$pod['name']] = $pod['label'] . ' (' . $pod['name'] . ')';
         }
         asort($pod_options);
         foreach ($pod_options as $pod => $label) {
             self::$related_objects['pod-' . $pod] = array('label' => $label, 'group' => __('Pods', 'pods'), 'bidirectional' => true);
         }
         // Post Types
         $post_types = get_post_types();
         asort($post_types);
         $ignore = array('attachment', 'revision', 'nav_menu_item');
         foreach ($post_types as $post_type => $label) {
             if (in_array($post_type, $ignore) || empty($post_type)) {
                 unset($post_types[$post_type]);
                 continue;
             } elseif (0 === strpos($post_type, '_pods_')) {
                 unset($post_types[$post_type]);
                 continue;
             }
             $post_type = get_post_type_object($post_type);
             self::$related_objects['post_type-' . $post_type->name] = array('label' => $post_type->label . ' (' . $post_type->name . ')', 'group' => __('Post Types', 'pods'), 'bidirectional' => true);
         }
         // Taxonomies
         $taxonomies = get_taxonomies();
         asort($taxonomies);
         $ignore = array('nav_menu', 'post_format');
         foreach ($taxonomies as $taxonomy => $label) {
             if (in_array($taxonomy, $ignore) || empty($taxonomy)) {
                 continue;
             }
             $taxonomy = get_taxonomy($taxonomy);
             self::$related_objects['taxonomy-' . $taxonomy->name] = array('label' => $taxonomy->label . ' (' . $taxonomy->name . ')', 'group' => __('Taxonomies', 'pods'), 'bidirectional' => true);
         }
         // Other WP Objects
         self::$related_objects['user'] = array('label' => __('Users', 'pods'), 'group' => __('Other WP Objects', 'pods'), 'bidirectional' => true);
         self::$related_objects['role'] = array('label' => __('User Roles', 'pods'), 'group' => __('Other WP Objects', 'pods'), 'simple' => true, 'data_callback' => array($this, 'data_roles'));
         self::$related_objects['capability'] = array('label' => __('User Capabilities', 'pods'), 'group' => __('Other WP Objects', 'pods'), 'simple' => true, 'data_callback' => array($this, 'data_capabilities'));
         self::$related_objects['media'] = array('label' => __('Media', 'pods'), 'group' => __('Other WP Objects', 'pods'), 'bidirectional' => true);
         self::$related_objects['comment'] = array('label' => __('Comments', 'pods'), 'group' => __('Other WP Objects', 'pods'), 'bidirectional' => true);
         self::$related_objects['image-size'] = array('label' => __('Image Sizes', 'pods'), 'group' => __('Other WP Objects', 'pods'), 'simple' => true, 'data_callback' => array($this, 'data_image_sizes'));
         self::$related_objects['nav_menu'] = array('label' => __('Navigation Menus', 'pods'), 'group' => __('Other WP Objects', 'pods'));
         self::$related_objects['post_format'] = array('label' => __('Post Formats', 'pods'), 'group' => __('Other WP Objects', 'pods'));
         self::$related_objects['post-status'] = array('label' => __('Post Status', 'pods'), 'group' => __('Other WP Objects', 'pods'), 'simple' => true, 'data_callback' => array($this, 'data_post_stati'));
         do_action('pods_form_ui_field_pick_related_objects_other');
         self::$related_objects['country'] = array('label' => __('Countries', 'pods'), 'group' => __('Predefined Lists', 'pods'), 'simple' => true, 'data_callback' => array($this, 'data_countries'));
         self::$related_objects['us_state'] = array('label' => __('US States', 'pods'), 'group' => __('Predefined Lists', 'pods'), 'simple' => true, 'data_callback' => array($this, 'data_us_states'));
         do_action('pods_form_ui_field_pick_related_objects_predefined');
         if (did_action('init')) {
             pods_transient_set('pods_related_objects', self::$related_objects);
         }
     }
     foreach (self::$custom_related_objects as $object => $related_object) {
         self::$related_objects[$object] = $related_object;
     }
 }
Пример #14
0
 /**
  * Get list of components available
  *
  * @since 2.0
  */
 public function get_components()
 {
     $components = pods_transient_get('pods_components');
     if (1 == pods_var('pods_debug_components', 'get', 0) && pods_is_admin(array('pods'))) {
         $components = array();
     }
     if (PodsInit::$version != PODS_VERSION || !is_array($components) || empty($components) || is_admin() && isset($_GET['page']) && 'pods-components' == $_GET['page'] && 1 !== pods_transient_get('pods_components_refresh')) {
         do_action('pods_components_get');
         $component_dir = @opendir(untrailingslashit($this->components_dir));
         $component_files = array();
         if (false !== $component_dir) {
             while (false !== ($file = readdir($component_dir))) {
                 if ('.' == substr($file, 0, 1)) {
                     continue;
                 } elseif (is_dir($this->components_dir . $file)) {
                     $component_subdir = @opendir($this->components_dir . $file);
                     if ($component_subdir) {
                         while (false !== ($subfile = readdir($component_subdir))) {
                             if ('.' == substr($subfile, 0, 1)) {
                                 continue;
                             } elseif ('.php' == substr($subfile, -4)) {
                                 $component_files[] = str_replace('\\', '/', $file . '/' . $subfile);
                             }
                         }
                         closedir($component_subdir);
                     }
                 } elseif ('.php' == substr($file, -4)) {
                     $component_files[] = $file;
                 }
             }
             closedir($component_dir);
         }
         $default_headers = array('ID' => 'ID', 'Name' => 'Name', 'ShortName' => 'Short Name', 'PluginName' => 'Plugin Name', 'ComponentName' => 'Component Name', 'URI' => 'URI', 'MenuName' => 'Menu Name', 'MenuPage' => 'Menu Page', 'MenuAddPage' => 'Menu Add Page', 'MustUse' => 'Must Use', 'Description' => 'Description', 'Version' => 'Version', 'Category' => 'Category', 'Author' => 'Author', 'AuthorURI' => 'Author URI', 'Class' => 'Class', 'Hide' => 'Hide', 'PluginDependency' => 'Plugin Dependency', 'ThemeDependency' => 'Theme Dependency', 'DeveloperMode' => 'Developer Mode', 'TablelessMode' => 'Tableless Mode', 'Capability' => 'Capability', 'Plugin' => 'Plugin');
         $component_files = apply_filters('pods_components_register', $component_files);
         $components = array();
         foreach ($component_files as $component_file) {
             $external = false;
             if (is_array($component_file) && isset($component_file['File'])) {
                 $component = $component_file = $component_file['File'];
                 $external = true;
             } else {
                 $component = $this->components_dir . $component_file;
             }
             if (!is_readable($component)) {
                 continue;
             }
             $component_data = get_file_data($component, $default_headers, 'pods_component');
             if (empty($component_data['Name']) && empty($component_data['ComponentName']) && empty($component_data['PluginName']) || 'yes' == $component_data['Hide']) {
                 continue;
             }
             if (isset($component_data['Plugin']) && pods_is_plugin_active($component_data['Plugin'])) {
                 continue;
             }
             if (empty($component_data['Name'])) {
                 if (!empty($component_data['ComponentName'])) {
                     $component_data['Name'] = $component_data['ComponentName'];
                 } elseif (!empty($component_data['PluginName'])) {
                     $component_data['Name'] = $component_data['PluginName'];
                 }
             }
             if (empty($component_data['ShortName'])) {
                 $component_data['ShortName'] = $component_data['Name'];
             }
             if (empty($component_data['MenuName'])) {
                 $component_data['MenuName'] = $component_data['Name'];
             }
             if (empty($component_data['Class'])) {
                 $component_data['Class'] = 'Pods_' . pods_clean_name(basename($component, '.php'), false);
             }
             if (empty($component_data['ID'])) {
                 $component_data['ID'] = $component_data['Name'];
             }
             $component_data['ID'] = sanitize_title($component_data['ID']);
             if ('on' == strtolower($component_data['DeveloperMode']) || 1 == $component_data['DeveloperMode']) {
                 $component_data['DeveloperMode'] = true;
             } else {
                 $component_data['DeveloperMode'] = false;
             }
             if ('on' == strtolower($component_data['TablelessMode']) || 1 == $component_data['TablelessMode']) {
                 $component_data['TablelessMode'] = true;
             } else {
                 $component_data['TablelessMode'] = false;
             }
             $component_data['External'] = (bool) $external;
             if ('on' == strtolower($component_data['MustUse']) || '1' == $component_data['MustUse']) {
                 $component_data['MustUse'] = true;
             } elseif ('off' == strtolower($component_data['MustUse']) || '0' == $component_data['MustUse']) {
                 $component_data['MustUse'] = false;
             } else {
                 $component_data['MustUse'] = $component_data['External'];
             }
             $component_data['File'] = $component_file;
             $components[$component_data['ID']] = $component_data;
         }
         ksort($components);
         pods_transient_set('pods_components_refresh', 1, 60 * 60 * 12);
         pods_transient_set('pods_components', $components);
     }
     if (1 == pods_var('pods_debug_components', 'get', 0) && pods_is_admin(array('pods'))) {
         pods_debug($components);
     }
     $this->components = $components;
     return $this->components;
 }
 /**
  * Get all Pods with auto template enable and its settings
  *
  * @return array With info about auto template settings per post type
  *
  * @since 2.4.5
  */
 function auto_pods()
 {
     /**
      * Filter to override all settings for which templates are used.
      *
      * Note: If this filter does not return null, all back-end settings are ignored. To add to settings with a filter, use 'pods_pfat_auto_pods';
      *
      * @param array $auto_pods Array of parameters to use instead of those from settings.
      *
      * @return array Settings arrays for each post type.
      *
      * @since 2.4.5
      */
     $auto_pods = apply_filters('pods_pfat_auto_pods_override', null);
     if (!is_null($auto_pods)) {
         return $auto_pods;
     }
     //try to get cached results of this method
     $key = '_pods_pfat_auto_pods';
     $auto_pods = pods_transient_get($key);
     //check if we already have the results cached & use it if we can.
     if ($auto_pods === false) {
         //get possible pods
         $the_pods = $this->the_pods();
         //start output array empty
         $auto_pods = array();
         //get pods api class
         $api = pods_api();
         //loop through each to see if auto templates is enabled
         foreach ($the_pods as $the_pod => $the_pod_label) {
             //get this Pods' data.
             $pod_data = $api->load_pod(array('name' => $the_pod));
             //if auto template is enabled add info about Pod to array
             if (1 == pods_v('pfat_enable', $pod_data['options'])) {
                 //check if pfat_single and pfat_archive are set
                 $single = pods_v('pfat_single', $pod_data['options'], false, true);
                 $archive = pods_v('pfat_archive', $pod_data['options'], false, true);
                 $single_append = pods_v('pfat_append_single', $pod_data['options'], true, true);
                 $archive_append = pods_v('pfat_append_archive', $pod_data['options'], true, true);
                 $single_filter = pods_v('pfat_filter_single', $pod_data['options'], 'the_content', true);
                 $archive_filter = pods_v('pfat_filter_archive', $pod_data['options'], 'the_content', true);
                 $type = pods_v('type', $pod_data, false, true);
                 //check if it's a post type that has an arhive
                 if ($type === 'post_type' && $the_pod !== 'post' || $the_pod !== 'page') {
                     $has_archive = pods_v('has_archive', $pod_data['options'], false, true);
                 } else {
                     $has_archive = true;
                 }
                 if (empty($single_filter)) {
                     $single_filter = 'the_content';
                 }
                 if (empty($archive_filter)) {
                     $archive_filter = 'the_content';
                 }
                 //build output array
                 $auto_pods[$the_pod] = array('name' => $the_pod, 'label' => $the_pod_label, 'single' => $single, 'archive' => $archive, 'single_append' => $single_append, 'archive_append' => $archive_append, 'has_archive' => $has_archive, 'single_filter' => $single_filter, 'archive_filter' => $archive_filter, 'type' => $type);
             }
         }
         //endforeach
         //cache the results
         pods_transient_set($key, $auto_pods);
     }
     /**
      * Add to or change settings.
      *
      * Use this filter to change or add to the settings set in the back-end for this plugin. Has no effect if 'pods_pfat_auto_pods_override' filter is being used.
      *
      * @param array $auto_pods Array of parameters to use instead of those from settings.
      *
      * @return array Settings arrays for each post type.
      *
      * @since 2.4.5
      */
     $auto_pods = apply_filters('pods_pfat_auto_pods', $auto_pods);
     return $auto_pods;
 }
Пример #16
0
 /**
  * Get a list of all available field types and include
  *
  * @return array Registered Field Types data
  *
  * @since 2.3
  */
 public static function field_types()
 {
     $field_types = array('text', 'website', 'phone', 'email', 'password', 'paragraph', 'wysiwyg', 'code', 'datetime', 'date', 'time', 'number', 'currency', 'file', 'avatar', 'pick', 'boolean', 'color', 'slug');
     $field_types = array_merge($field_types, array_keys(self::$field_types));
     $field_types = array_filter(array_unique($field_types));
     $types = apply_filters('pods_api_field_types', $field_types);
     $field_types = pods_transient_get('pods_field_types');
     if (empty($field_types) || count($types) != count($field_types)) {
         $field_types = array();
         foreach ($types as $field_type) {
             $file = null;
             if (isset(self::$field_types[$field_type])) {
                 $file = self::$field_types[$field_type]['file'];
             }
             self::field_loader($field_type, $file);
             if (!isset(self::$loaded[$field_type]) || !is_object(self::$loaded[$field_type])) {
                 continue;
             }
             $class_vars = get_class_vars(get_class(self::$loaded[$field_type]));
             // PHP 5.2.x workaround
             $field_types[$field_type] = $class_vars;
             $field_types[$field_type]['file'] = $file;
         }
         self::$field_types = $field_types;
         pods_transient_set('pods_field_types', self::$field_types);
     } else {
         self::$field_types = array_merge($field_types, self::$field_types);
     }
     return self::$field_types;
 }
 /**
  * Take over the avatar served from WordPress
  *
  * @param string $avatar Default Avatar Image output from WordPress
  * @param int|string|object $id_or_email A user ID, email address, or comment object
  * @param int $size Size of the avatar image
  * @param string $default URL to a default image to use if no avatar is available
  * @param string $alt Alternate text to use in image tag. Defaults to blank
  * @return string <img> tag for the user's avatar
  */
 public function get_avatar($avatar, $id_or_email, $size, $default = '', $alt = '')
 {
     // Don't replace for the Avatars section of the Discussion settings page
     if (is_admin()) {
         $current_screen = get_current_screen();
         if (!is_null($current_screen) && 'options-discussion' == $current_screen->id && 32 == $size) {
             return $avatar;
         }
     }
     $_user_ID = 0;
     if (is_numeric($id_or_email) && 0 < $id_or_email) {
         $_user_ID = (int) $id_or_email;
     } elseif (is_object($id_or_email) && isset($id_or_email->user_id) && 0 < $id_or_email->user_id) {
         $_user_ID = (int) $id_or_email->user_id;
     } elseif (is_object($id_or_email) && isset($id_or_email->ID) && isset($id_or_email->user_login) && 0 < $id_or_email->ID) {
         $_user_ID = (int) $id_or_email->ID;
     } elseif (!is_object($id_or_email) && false !== strpos($id_or_email, '@')) {
         $_user = get_user_by('email', $id_or_email);
         if (!empty($_user)) {
             $_user_ID = (int) $_user->ID;
         }
     }
     // Include PodsMeta if not already included
     pods_meta();
     if (0 < $_user_ID && !empty(PodsMeta::$user)) {
         $avatar_cached = pods_cache_get($_user_ID . '-' . $size, 'pods_avatars');
         if (!empty($avatar_cached)) {
             $avatar = $avatar_cached;
         } else {
             $avatar_field = pods_transient_get('pods_avatar_field');
             $user = current(PodsMeta::$user);
             if (empty($avatar_field)) {
                 foreach ($user['fields'] as $field) {
                     if ('avatar' == $field['type']) {
                         $avatar_field = $field['name'];
                         pods_transient_set('pods_avatar_field', $avatar_field);
                         break;
                     }
                 }
             } elseif (!isset($user['fields'][$avatar_field])) {
                 $avatar_field = false;
             }
             if (!empty($avatar_field)) {
                 $user_avatar = get_user_meta($_user_ID, $avatar_field . '.ID', true);
                 if (!empty($user_avatar)) {
                     $attributes = array('alt' => '', 'class' => 'avatar avatar-' . $size . ' photo');
                     if (!empty($alt)) {
                         $attributes['alt'] = $alt;
                     }
                     $user_avatar = pods_image($user_avatar, array($size, $size), 0, $attributes);
                     if (!empty($user_avatar)) {
                         $avatar = $user_avatar;
                         pods_cache_set($_user_ID . '-' . $size, $avatar, 'pods_avatars');
                     }
                 }
             }
         }
     }
     return $avatar;
 }