/**
 * 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;
}
Example #2
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;
 }
Example #3
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;
 }
    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;
$max_length_name = 64;
$max_length_name -= 10;
// Allow for WP Multisite or prefix changes in the future
$max_length_name -= strlen($wpdb->prefix . 'pods_');
$tabs = PodsInit::$admin->admin_setup_edit_tabs($pod);
$tab_options = PodsInit::$admin->admin_setup_edit_options($pod);
$field_tabs = PodsInit::$admin->admin_setup_edit_field_tabs($pod);
$field_tab_options = PodsInit::$admin->admin_setup_edit_field_options($pod);
$no_additional = array();
foreach ($field_tab_options['additional-field'] as $field_type => $field_type_fields) {
Example #5
0
 /**
  * Clear Pod-related cache
  *
  * @param array $pod
  *
  * @return void
  *
  * @since 2.0
  */
 public function cache_flush_pods($pod = null)
 {
     /**
      * @var $wpdb wpdb
      */
     global $wpdb;
     pods_transient_clear('pods');
     pods_transient_clear('pods_components');
     if (null !== $pod && is_array($pod)) {
         pods_transient_clear('pods_pod_' . $pod['name']);
         pods_cache_clear($pod['name'], 'pods-class');
         foreach ($pod['fields'] as $field) {
             pods_transient_clear('pods_field_' . $pod['name'] . '_' . $field['name']);
         }
         if (in_array($pod['type'], array('post_type', 'taxonomy'))) {
             pods_transient_clear('pods_wp_cpt_ct');
         }
     } else {
         pods_transient_clear('pods_wp_cpt_ct');
     }
     $wpdb->query("DELETE FROM `{$wpdb->options}` WHERE `option_name` LIKE '_transient_pods%'");
     $wpdb->query("DELETE FROM `{$wpdb->options}` WHERE `option_name` LIKE '_transient_timeout_pods%'");
     pods_cache_clear(true);
     pods_transient_set('pods_flush_rewrites', 1);
 }
 /**
  * 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;
 }
Example #7
0
 /**
  * Flush Pod Page Rewrite cache
  *
  * @return array Pod Page Rewrites
  *
  * @since 2.3.4
  */
 public static function flush_rewrites()
 {
     $args = array('post_type' => '_pods_page', 'nopaging' => true, 'posts_per_page' => -1, 'post_status' => 'publish', 'order' => 'ASC', 'orderby' => 'title');
     $pod_pages = get_posts($args);
     $pod_page_rewrites = array();
     foreach ($pod_pages as $pod_page) {
         $pod_page_rewrites[$pod_page->ID] = $pod_page->post_title;
     }
     uksort($pod_page_rewrites, 'pods_page_length_sort');
     pods_transient_set('pods_object_page_rewrites', $pod_page_rewrites);
     $pod_page_rewrites = array_flip($pod_page_rewrites);
     return $pod_page_rewrites;
 }
Example #8
0
 public static function enqueue()
 {
     foreach (self::$queue as $type => $objects) {
         foreach ($objects as $pod_name => $pod) {
             pods_transient_set('pods_pod_' . $pod_name, $pod);
         }
         self::${$type} = array_merge(self::${$type}, $objects);
     }
 }
Example #9
0
 /**
  * Register Post Types and Taxonomies
  */
 public function setup_content_types($force = false)
 {
     $post_types = PodsMeta::$post_types;
     $taxonomies = PodsMeta::$taxonomies;
     $existing_post_types = get_post_types();
     $existing_taxonomies = get_taxonomies();
     $pods_cpt_ct = pods_transient_get('pods_wp_cpt_ct');
     $cpt_positions = array();
     if (empty($pods_cpt_ct) && (!empty($post_types) || !empty($taxonomies))) {
         $force = true;
     } elseif (!empty($pods_cpt_ct) && empty($pods_cpt_ct['post_types']) && !empty($post_types)) {
         $force = true;
     } elseif (!empty($pods_cpt_ct) && empty($pods_cpt_ct['taxonomies']) && !empty($taxonomies)) {
         $force = true;
     }
     if (false === $pods_cpt_ct || $force) {
         $pods_cpt_ct = array('post_types' => array(), 'taxonomies' => array());
         $pods_post_types = $pods_taxonomies = array();
         $supported_post_types = $supported_taxonomies = array();
         foreach ($post_types as $post_type) {
             // Post Type exists already
             if (isset($pods_cpt_ct['post_types'][$post_type['name']])) {
                 continue;
             } elseif (!empty($post_type['object']) && isset($existing_post_types[$post_type['object']])) {
                 continue;
             } elseif (!$force && isset($existing_post_types[$post_type['name']])) {
                 continue;
             }
             $post_type['options']['name'] = $post_type['name'];
             $post_type = array_merge($post_type, (array) $post_type['options']);
             // Labels
             $cpt_label = esc_html(pods_var_raw('label', $post_type, ucwords(str_replace('_', ' ', pods_var_raw('name', $post_type))), null, true));
             $cpt_singular = esc_html(pods_var_raw('label_singular', $post_type, ucwords(str_replace('_', ' ', pods_var_raw('label', $post_type, pods_var('name', $post_type), null, true))), null, true));
             $cpt_labels = array();
             $cpt_labels['name'] = $cpt_label;
             $cpt_labels['singular_name'] = $cpt_singular;
             $cpt_labels['menu_name'] = pods_var_raw('menu_name', $post_type, '', null, true);
             $cpt_labels['add_new'] = pods_var_raw('label_add_new', $post_type, '', null, true);
             $cpt_labels['add_new_item'] = pods_var_raw('label_add_new_item', $post_type, '', null, true);
             $cpt_labels['new_item'] = pods_var_raw('label_new_item', $post_type, '', null, true);
             $cpt_labels['edit'] = pods_var_raw('label_edit', $post_type, '', null, true);
             $cpt_labels['edit_item'] = pods_var_raw('label_edit_item', $post_type, '', null, true);
             $cpt_labels['view'] = pods_var_raw('label_view', $post_type, '', null, true);
             $cpt_labels['view_item'] = pods_var_raw('label_view_item', $post_type, '', null, true);
             $cpt_labels['all_items'] = pods_var_raw('label_all_items', $post_type, '', null, true);
             $cpt_labels['search_items'] = pods_var_raw('label_search_items', $post_type, '', null, true);
             $cpt_labels['not_found'] = pods_var_raw('label_not_found', $post_type, '', null, true);
             $cpt_labels['not_found_in_trash'] = pods_var_raw('label_not_found_in_trash', $post_type, '', null, true);
             $cpt_labels['parent'] = pods_var_raw('label_parent', $post_type, '', null, true);
             $cpt_labels['parent_item_colon'] = pods_var_raw('label_parent_item_colon', $post_type, '', null, true);
             // Supported
             $cpt_supported = array('title' => (bool) pods_var('supports_title', $post_type, false), 'editor' => (bool) pods_var('supports_editor', $post_type, false), 'author' => (bool) pods_var('supports_author', $post_type, false), 'thumbnail' => (bool) pods_var('supports_thumbnail', $post_type, false), 'excerpt' => (bool) pods_var('supports_excerpt', $post_type, false), 'trackbacks' => (bool) pods_var('supports_trackbacks', $post_type, false), 'custom-fields' => (bool) pods_var('supports_custom_fields', $post_type, false), 'comments' => (bool) pods_var('supports_comments', $post_type, false), 'revisions' => (bool) pods_var('supports_revisions', $post_type, false), 'page-attributes' => (bool) pods_var('supports_page_attributes', $post_type, false), 'post-formats' => (bool) pods_var('supports_post_formats', $post_type, false));
             // Custom Supported
             $cpt_supported_custom = pods_var('supports_custom', $post_type, '');
             if (!empty($cpt_supported_custom)) {
                 $cpt_supported_custom = explode(',', $cpt_supported_custom);
                 $cpt_supported_custom = array_filter(array_unique($cpt_supported_custom));
                 foreach ($cpt_supported_custom as $cpt_support) {
                     $cpt_supported[$cpt_support] = true;
                 }
             }
             // Genesis Support
             if (function_exists('genesis')) {
                 $cpt_supported['genesis-seo'] = (bool) pods_var('supports_genesis_seo', $post_type, false);
                 $cpt_supported['genesis-layouts'] = (bool) pods_var('supports_genesis_layouts', $post_type, false);
                 $cpt_supported['genesis-simple-sidebars'] = (bool) pods_var('supports_genesis_simple_sidebars', $post_type, false);
             }
             // WP needs something, if this was empty and none were enabled, it would show title+editor pre 3.5 :(
             $cpt_supports = array();
             if (!pods_version_check('wp', '3.5')) {
                 $cpt_supports = array('_bug_fix_pre_35');
             }
             foreach ($cpt_supported as $cpt_support => $supported) {
                 if (true === $supported) {
                     $cpt_supports[] = $cpt_support;
                 }
             }
             if (empty($cpt_supports) && pods_version_check('wp', '3.5')) {
                 $cpt_supports = false;
             }
             // Rewrite
             $cpt_rewrite = (bool) pods_var('rewrite', $post_type, true);
             $cpt_rewrite_array = array('slug' => pods_var('rewrite_custom_slug', $post_type, str_replace('_', '-', pods_var('name', $post_type)), null, true), 'with_front' => (bool) pods_var('rewrite_with_front', $post_type, true), 'feeds' => (bool) pods_var('rewrite_feeds', $post_type, (bool) pods_var('has_archive', $post_type, false)), 'pages' => (bool) pods_var('rewrite_pages', $post_type, true));
             if (false !== $cpt_rewrite) {
                 $cpt_rewrite = $cpt_rewrite_array;
             }
             $capability_type = pods_var('capability_type', $post_type, 'post');
             if ('custom' == $capability_type) {
                 $capability_type = pods_var('capability_type_custom', $post_type, 'post');
             }
             $show_in_menu = (bool) pods_var('show_in_menu', $post_type, true);
             if ($show_in_menu && 0 < strlen(pods_var_raw('menu_location_custom', $post_type))) {
                 $show_in_menu = pods_var_raw('menu_location_custom', $post_type);
             }
             // Register Post Type
             $pods_post_types[pods_var('name', $post_type)] = array('label' => $cpt_label, 'labels' => $cpt_labels, 'description' => esc_html(pods_var_raw('description', $post_type)), 'public' => (bool) pods_var('public', $post_type, true), 'publicly_queryable' => (bool) pods_var('publicly_queryable', $post_type, (bool) pods_var('public', $post_type, true)), 'exclude_from_search' => (bool) pods_var('exclude_from_search', $post_type, (bool) pods_var('public', $post_type, true) ? false : true), 'show_ui' => (bool) pods_var('show_ui', $post_type, (bool) pods_var('public', $post_type, true)), 'show_in_menu' => $show_in_menu, 'show_in_admin_bar' => (bool) pods_var('show_in_admin_bar', $post_type, (bool) pods_var('show_in_menu', $post_type, true)), 'menu_position' => (int) pods_var('menu_position', $post_type, 0, null, true), 'menu_icon' => pods_var('menu_icon', $post_type, null, null, true), 'capability_type' => $capability_type, 'map_meta_cap' => (bool) pods_var('capability_type_extra', $post_type, true), 'hierarchical' => (bool) pods_var('hierarchical', $post_type, false), 'supports' => $cpt_supports, 'has_archive' => (bool) pods_var('has_archive', $post_type, false), 'rewrite' => $cpt_rewrite, 'query_var' => false !== (bool) pods_var('query_var', $post_type, true) ? pods_var('query_var_string', $post_type, pods_var('name', $post_type), null, true) : false, 'can_export' => (bool) pods_var('can_export', $post_type, true), 'show_in_nav_menus' => (bool) pods_var('show_in_nav_menus', $post_type, (bool) pods_var('public', $post_type, true)));
             if (25 == $pods_post_types[pods_var('name', $post_type)]['menu_position']) {
                 $pods_post_types[pods_var('name', $post_type)]['menu_position']++;
             }
             if ($pods_post_types[pods_var('name', $post_type)]['menu_position'] < 1 || in_array($pods_post_types[pods_var('name', $post_type)]['menu_position'], $cpt_positions)) {
                 unset($pods_post_types[pods_var('name', $post_type)]['menu_position']);
             } else {
                 $cpt_positions[] = $pods_post_types[pods_var('name', $post_type)]['menu_position'];
                 // This would be nice if WP supported floats in menu_position
                 // $pods_post_types[ pods_var( 'name', $post_type ) ][ 'menu_position' ] = $pods_post_types[ pods_var( 'name', $post_type ) ][ 'menu_position' ] . '.1';
             }
             // Taxonomies
             $cpt_taxonomies = array();
             $_taxonomies = get_taxonomies();
             $_taxonomies = array_merge_recursive($_taxonomies, $pods_taxonomies);
             $ignore = array('nav_menu', 'link_category', 'post_format');
             foreach ($_taxonomies as $taxonomy => $label) {
                 if (in_array($taxonomy, $ignore)) {
                     continue;
                 }
                 if (false !== (bool) pods_var('built_in_taxonomies_' . $taxonomy, $post_type, false)) {
                     $cpt_taxonomies[] = $taxonomy;
                     if (isset($supported_post_types[$taxonomy]) && !in_array(pods_var('name', $post_type), $supported_post_types[$taxonomy])) {
                         $supported_post_types[$taxonomy][] = pods_var('name', $post_type);
                     }
                 }
             }
             if (isset($supported_taxonomies[pods_var('name', $post_type)])) {
                 $supported_taxonomies[pods_var('name', $post_type)] = array_merge((array) $supported_taxonomies[pods_var('name', $post_type)], $cpt_taxonomies);
             } else {
                 $supported_taxonomies[pods_var('name', $post_type)] = $cpt_taxonomies;
             }
         }
         foreach ($taxonomies as $taxonomy) {
             // Taxonomy Type exists already
             if (isset($pods_cpt_ct['taxonomies'][$taxonomy['name']])) {
                 continue;
             } elseif (!empty($taxonomy['object']) && isset($existing_taxonomies[$taxonomy['object']])) {
                 continue;
             } elseif (!$force && isset($existing_taxonomies[$taxonomy['name']])) {
                 continue;
             }
             $taxonomy['options']['name'] = $taxonomy['name'];
             $taxonomy = array_merge($taxonomy, (array) $taxonomy['options']);
             // Labels
             $ct_label = esc_html(pods_var_raw('label', $taxonomy, ucwords(str_replace('_', ' ', pods_var_raw('name', $taxonomy))), null, true));
             $ct_singular = esc_html(pods_var_raw('label_singular', $taxonomy, ucwords(str_replace('_', ' ', pods_var_raw('label', $taxonomy, pods_var_raw('name', $taxonomy), null, true))), null, true));
             $ct_labels = array();
             $ct_labels['name'] = $ct_label;
             $ct_labels['singular_name'] = $ct_singular;
             $ct_labels['menu_name'] = pods_var_raw('menu_name', $taxonomy, '', null, true);
             $ct_labels['search_items'] = pods_var_raw('label_search_items', $taxonomy, '', null, true);
             $ct_labels['popular_items'] = pods_var_raw('label_popular_items', $taxonomy, '', null, true);
             $ct_labels['all_items'] = pods_var_raw('label_all_items', $taxonomy, '', null, true);
             $ct_labels['parent_item'] = pods_var_raw('label_parent_item', $taxonomy, '', null, true);
             $ct_labels['parent_item_colon'] = pods_var_raw('label_parent_item_colon', $taxonomy, '', null, true);
             $ct_labels['edit_item'] = pods_var_raw('label_edit_item', $taxonomy, '', null, true);
             $ct_labels['update_item'] = pods_var_raw('label_update_item', $taxonomy, '', null, true);
             $ct_labels['add_new_item'] = pods_var_raw('label_add_new_item', $taxonomy, '', null, true);
             $ct_labels['new_item_name'] = pods_var_raw('label_new_item_name', $taxonomy, '', null, true);
             $ct_labels['separate_items_with_commas'] = pods_var_raw('label_separate_items_with_commas', $taxonomy, '', null, true);
             $ct_labels['add_or_remove_items'] = pods_var_raw('label_add_or_remove_items', $taxonomy, '', null, true);
             $ct_labels['choose_from_most_used'] = pods_var_raw('label_choose_from_the_most_used', $taxonomy, '', null, true);
             // Rewrite
             $ct_rewrite = (bool) pods_var('rewrite', $taxonomy, true);
             $ct_rewrite_array = array('slug' => pods_var('rewrite_custom_slug', $taxonomy, str_replace('_', '-', pods_var('name', $taxonomy)), null, true), 'with_front' => (bool) pods_var('rewrite_with_front', $taxonomy, true), 'hierarchical' => (bool) pods_var('rewrite_hierarchical', $taxonomy, (bool) pods_var('hierarchical', $taxonomy, false)));
             if (false !== $ct_rewrite) {
                 $ct_rewrite = $ct_rewrite_array;
             }
             // Register Taxonomy
             $pods_taxonomies[pods_var('name', $taxonomy)] = array('label' => $ct_label, 'labels' => $ct_labels, 'public' => (bool) pods_var('public', $taxonomy, true), 'show_in_nav_menus' => (bool) pods_var('show_in_nav_menus', $taxonomy, (bool) pods_var('public', $taxonomy, true)), 'show_ui' => (bool) pods_var('show_ui', $taxonomy, (bool) pods_var('public', $taxonomy, true)), 'show_tagcloud' => (bool) pods_var('show_tagcloud', $taxonomy, (bool) pods_var('show_ui', $taxonomy, (bool) pods_var('public', $taxonomy, true))), 'hierarchical' => (bool) pods_var('hierarchical', $taxonomy, false), 'update_count_callback' => pods_var('update_count_callback', $taxonomy, null, null, true), 'query_var' => false !== (bool) pods_var('query_var', $taxonomy, true) ? pods_var('query_var_string', $taxonomy, pods_var('name', $taxonomy), null, true) : false, 'rewrite' => $ct_rewrite, 'show_admin_column' => (bool) pods_var('show_admin_column', $taxonomy, false), 'sort' => (bool) pods_var('sort', $taxonomy, false));
             if (is_array($ct_rewrite) && !$pods_taxonomies[pods_var('name', $taxonomy)]['query_var']) {
                 $pods_taxonomies[pods_var('name', $taxonomy)]['query_var'] = pods_var('query_var_string', $taxonomy, pods_var('name', $taxonomy), null, true);
             }
             // Post Types
             $ct_post_types = array();
             $_post_types = get_post_types();
             $_post_types = array_merge_recursive($_post_types, $pods_post_types);
             $ignore = array('revision', 'nav_menu_item');
             foreach ($_post_types as $post_type => $options) {
                 if (in_array($post_type, $ignore)) {
                     continue;
                 }
                 if (false !== (bool) pods_var('built_in_post_types_' . $post_type, $taxonomy, false)) {
                     $ct_post_types[] = $post_type;
                     if (isset($supported_taxonomies[$post_type]) && !in_array(pods_var('name', $taxonomy), $supported_taxonomies[$post_type])) {
                         $supported_taxonomies[$post_type][] = pods_var('name', $taxonomy);
                     }
                 }
             }
             if (isset($supported_post_types[pods_var('name', $taxonomy)])) {
                 $supported_post_types[pods_var('name', $taxonomy)] = array_merge($supported_post_types[pods_var('name', $taxonomy)], $ct_post_types);
             } else {
                 $supported_post_types[pods_var('name', $taxonomy)] = $ct_post_types;
             }
         }
         $pods_post_types = apply_filters('pods_wp_post_types', $pods_post_types);
         $pods_taxonomies = apply_filters('pods_wp_taxonomies', $pods_taxonomies);
         $supported_post_types = apply_filters('pods_wp_supported_post_types', $supported_post_types);
         $supported_taxonomies = apply_filters('pods_wp_supported_taxonomies', $supported_taxonomies);
         foreach ($pods_taxonomies as $taxonomy => $options) {
             $ct_post_types = null;
             if (isset($supported_post_types[$taxonomy]) && !empty($supported_post_types[$taxonomy])) {
                 $ct_post_types = $supported_post_types[$taxonomy];
             }
             $pods_cpt_ct['taxonomies'][$taxonomy] = array('post_types' => $ct_post_types, 'options' => $options);
         }
         foreach ($pods_post_types as $post_type => $options) {
             if (isset($supported_taxonomies[$post_type]) && !empty($supported_taxonomies[$post_type])) {
                 $options['taxonomies'] = $supported_taxonomies[$post_type];
             }
             $pods_cpt_ct['post_types'][$post_type] = $options;
         }
         pods_transient_set('pods_wp_cpt_ct', $pods_cpt_ct);
     }
     foreach ($pods_cpt_ct['taxonomies'] as $taxonomy => $options) {
         if (isset(self::$content_types_registered['taxonomies']) && in_array($taxonomy, self::$content_types_registered['taxonomies'])) {
             continue;
         }
         $ct_post_types = $options['post_types'];
         $options = $options['options'];
         $options = apply_filters('pods_register_taxonomy_' . $taxonomy, $options);
         $options = self::object_label_fix($options, 'taxonomy');
         // Max length for taxonomies are 32 characters
         $taxonomy = substr($taxonomy, 0, 32);
         // i18n compatibility for plugins that override it
         if (is_array($options['rewrite']) && isset($options['rewrite']['slug']) && !empty($options['rewrite']['slug'])) {
             $options['rewrite']['slug'] = _x($options['rewrite']['slug'], 'URL taxonomy slug', 'pods');
         }
         if (1 == pods_var('pods_debug_register', 'get', 0) && pods_is_admin(array('pods'))) {
             pods_debug(array($taxonomy, $ct_post_types, $options));
         }
         register_taxonomy($taxonomy, $ct_post_types, $options);
         if (!isset(self::$content_types_registered['taxonomies'])) {
             self::$content_types_registered['taxonomies'] = array();
         }
         self::$content_types_registered['taxonomies'][] = $taxonomy;
     }
     foreach ($pods_cpt_ct['post_types'] as $post_type => $options) {
         if (isset(self::$content_types_registered['post_types']) && in_array($post_type, self::$content_types_registered['post_types'])) {
             continue;
         }
         $options = apply_filters('pods_register_post_type_' . $post_type, $options);
         $options = self::object_label_fix($options, 'post_type');
         // Max length for post types are 20 characters
         $post_type = substr($post_type, 0, 20);
         // i18n compatibility for plugins that override it
         if (is_array($options['rewrite']) && isset($options['rewrite']['slug']) && !empty($options['rewrite']['slug'])) {
             $options['rewrite']['slug'] = _x($options['rewrite']['slug'], 'URL slug', 'pods');
         }
         if (1 == pods_var('pods_debug_register', 'get', 0) && pods_is_admin(array('pods'))) {
             pods_debug(array($post_type, $options));
         }
         register_post_type($post_type, $options);
         if (!isset(self::$content_types_registered['post_types'])) {
             self::$content_types_registered['post_types'] = array();
         }
         self::$content_types_registered['post_types'][] = $post_type;
     }
     $flush = pods_transient_get('pods_flush_rewrites');
     if (1 == $flush) {
         global $wp_rewrite;
         $wp_rewrite->flush_rules();
         $wp_rewrite->init();
         pods_transient_set('pods_flush_rewrites', 0);
     }
 }
 /**
  * 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;
 }
Example #11
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;
 }
Example #13
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;
 }
Example #14
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;
     }
 }
Example #15
0
 /**
  * Check if we need to flush WordPress rewrite rules
  * This gets run during 'init' action late in the game to give other plugins time to register their rewrite rules
  *
  */
 public function flush_rewrite_rules()
 {
     $flush = pods_transient_get('pods_flush_rewrites');
     if (1 == $flush) {
         global $wp_rewrite;
         $wp_rewrite->flush_rules();
         $wp_rewrite->init();
         pods_transient_set('pods_flush_rewrites', 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 = '')
 {
     // 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;
 }