/** * 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); }
/** * Save an item by giving an array of field data or set a specific field to a specific value. * * Though this function has the capacity to add new items, best practice should direct you * to use add() for that instead. * * @see PodsAPI::save_pod_item * * @param array|string $data Either an associative array of field information or a field name * @param mixed $value (optional) Value of the field, if $data is a field name * @param int $id (optional) ID of the pod item to update * @param array $params (optional) Additional params to send to save_pod_item * * @return int The item ID * * @since 2.0 * @link http://pods.io/docs/save/ */ public function save($data = null, $value = null, $id = null, $params = null) { if (null !== $value) { $data = array($data => $value); } $fetch = false; if (null === $id) { $fetch = true; $id = $this->id(); } $data = (array) $this->do_hook('save', $data, $id); if (empty($data)) { return $id; } $default = array(); if (!empty($params) && is_array($params)) { $default = $params; } $params = array('pod' => $this->pod, 'id' => $id, 'data' => $data, 'allow_custom_fields' => true, 'clear_slug_cache' => false); if (!empty($default)) { $params = array_merge($params, $default); } $id = $this->api->save_pod_item($params); if (0 < $id && $fetch) { $this->fetch($id, false); } if (!empty($this->pod_data['field_slug'])) { if (0 < $id && $fetch) { $slug = $this->field($this->pod_data['field_slug']); } else { $slug = pods($this->pod, $id)->field($this->pod_data['field_slug']); } if (0 < strlen($slug)) { pods_cache_clear($slug, 'pods_items_' . $this->pod); } } return $id; }
/** * Clear cache on save * * @since 2.0 */ public function clear_cache($data, $pod = null, $id = null, $groups = null, $post = null) { $old_post = $id; if (!is_object($id)) { $old_post = null; } if (is_object($post) && $this->object_type != $post->post_type) { return; } if (!is_array($data) && 0 < $data) { $post = $data; $post = get_post($post); } if ($this->object_type == $post->post_type) { pods_transient_clear('pods_object_pages'); if (is_object($old_post) && $this->object_type == $old_post->post_type) { pods_cache_clear($old_post->post_title, 'pods_object_page_wildcard'); } pods_cache_clear($post->post_title, 'pods_object_page_wildcard'); self::flush_rewrites(); } }
/** * Clear cache * * @param string $key Cache key * @param string $group Cache group */ public function cache_clear($key, $group) { if (function_exists('pods_cache_clear')) { pods_cache_clear($key, $group); } else { wp_cache_delete($key, $group); } }