/** * Load a Pods Object * * $params['id'] int The Object ID * $params['name'] string The Object name * $params['type'] string The Object type * * @param array|object $params An associative array of parameters * @param bool $strict * * @return array|bool * @since 2.0 */ public function load_object($params, $strict = false) { if (is_object($params) && isset($params->post_title)) { $_object = get_object_vars($params); } else { $params = (object) pods_sanitize($params); if (!isset($params->type) || empty($params->type)) { return pods_error(__('Object type is required', 'pods'), $this); } if ((!isset($params->id) || empty($params->id)) && (!isset($params->name) || empty($params->name))) { return pods_error(__('Either Object ID or Name are required', 'pods'), $this); } /** * @var $wpdb wpdb */ global $wpdb; if (isset($params->name)) { $_object = pods_by_title($params->name, ARRAY_A, '_pods_' . $params->type, 'publish'); } else { $object = $params->id; $_object = get_post($object, ARRAY_A); } if (empty($_object)) { if ($strict) { return pods_error(__('Object not found', 'pods'), $this); } return false; } } $object = array('id' => $_object['ID'], 'name' => $_object['post_title'], 'code' => $_object['post_content'], 'type' => str_replace('_pods_', '', $_object['post_type']), 'slug' => $_object['post_name']); $object['options'] = get_post_meta($object['id']); foreach ($object['options'] as $option => &$value) { if (is_array($value) && 1 == count($value)) { $value = current($value); } } return $object; }
/** * 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; }