/** * Include and Init the Pods class * * @see Pods * * @param string $type The pod name * @param mixed $id (optional) The ID or slug, to load a single record; Provide array of $params to run 'find' * @param bool $strict (optional) If set to true, return false instead of an object if the Pod doesn't exist * * @return bool|\Pods * @since 2.0 * @link http://pods.io/docs/pods/ */ function pods($type = null, $id = null, $strict = null) { require_once PODS_DIR . 'classes/Pods.php'; $pod = new Pods($type, $id); if (null === $strict) { $strict = pods_strict(); } if (true === $strict && null !== $type && !$pod->valid()) { return false; } return $pod; }
/** * Determine if Deprecated Mode is enabled * * @param bool $include_debug Whether to include strict mode * * @return bool Whether Deprecated Mode is enabled * * @since 2.3.10 */ function pods_allow_deprecated($strict = true) { if ($strict && pods_strict()) { return false; } elseif (!defined('PODS_DEPRECATED') || PODS_DEPRECATED) { return true; } 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; }
/** * 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; }
/** * Constructor - Pods Framework core * * @param string $pod The pod name * @param mixed $id (optional) The ID or slug, to load a single record; Provide array of $params to run 'find' * * @return \Pods * * @license http://www.gnu.org/licenses/gpl-2.0.html * @since 1.0.0 * @link http://pods.io/docs/pods/ */ public function __construct($pod = null, $id = null) { if (null === $pod) { $queried_object = get_queried_object(); if ($queried_object) { $id_lookup = true; // Post Type Singular if (isset($queried_object->post_type)) { $pod = $queried_object->post_type; } elseif (isset($queried_object->taxonomy)) { $pod = $queried_object->taxonomy; } elseif (isset($queried_object->user_login)) { $pod = 'user'; } elseif (isset($queried_object->public) && isset($queried_object->name)) { $pod = $queried_object->name; $id_lookup = false; } if (null === $id && $id_lookup) { $id = get_queried_object_id(); } } } $this->api = pods_api($pod); $this->api->display_errors =& $this->display_errors; $this->data = pods_data($this->api, $id, false); PodsData::$display_errors =& $this->display_errors; // Set up page variable if (pods_strict(false)) { $this->page = 1; $this->pagination = false; $this->search = false; } else { // Get the page variable $this->page = pods_var($this->page_var, 'get'); $this->page = empty($this->page) ? 1 : max(pods_absint($this->page), 1); } // Set default pagination handling to on/off if (defined('PODS_GLOBAL_POD_PAGINATION')) { if (!PODS_GLOBAL_POD_PAGINATION) { $this->page = 1; $this->pagination = false; } else { $this->pagination = true; } } // Set default search to on/off if (defined('PODS_GLOBAL_POD_SEARCH')) { if (PODS_GLOBAL_POD_SEARCH) { $this->search = true; } else { $this->search = false; } } // Set default search mode $allowed_search_modes = array('int', 'text', 'text_like'); if (defined('PODS_GLOBAL_POD_SEARCH_MODE') && in_array(PODS_GLOBAL_POD_SEARCH_MODE, $allowed_search_modes)) { $this->search_mode = PODS_GLOBAL_POD_SEARCH_MODE; } // Sync Settings $this->data->page =& $this->page; $this->data->limit =& $this->limit; $this->data->pagination =& $this->pagination; $this->data->search =& $this->search; $this->data->search_mode =& $this->search_mode; // Sync Pod Data $this->api->pod_data =& $this->data->pod_data; $this->pod_data =& $this->api->pod_data; $this->api->pod_id =& $this->data->pod_id; $this->pod_id =& $this->api->pod_id; $this->datatype_id =& $this->pod_id; $this->api->pod =& $this->data->pod; $this->pod =& $this->api->pod; $this->datatype =& $this->pod; $this->api->fields =& $this->data->fields; $this->fields =& $this->api->fields; $this->detail_page =& $this->data->detail_page; $this->id =& $this->data->id; $this->row =& $this->data->row; $this->rows =& $this->data->data; $this->row_number =& $this->data->row_number; $this->sql =& $this->data->sql; if (is_array($id) || is_object($id)) { $this->find($id); } }