get_base_name(); } /** * Load the field value(s) with caching * * @param Field $field The field to load value(s) in. * @return array */ public function load(Field $field) { $cache_key = $this->get_key_for_field($field); $cached_value = wp_cache_get($cache_key, $this->cache_group); if ($cached_value !== false) { return $cached_value; } $key = $this->get_key_for_field($field); $value = get_option($key, null); // Cache the retrieved value wp_cache_set($cache_key, $value, $this->cache_group); return $value; } /** * Save the field value(s) and update cache * * @param Field $field The field to save. */ public function save(Field $field) { if (!empty($field->get_hierarchy())) { return; // only applicable to root fields } $key = $this->get_key_for_field($field); $value = $field->get_full_value(); if (is_a($field, '\\Carbon_Fields\\Field\\Complex_Field')) { $value = $field->get_value_tree(); } $this->save_key_value_pair_with_autoload($key, $value, $field->get_autoload()); // Update cache wp_cache_set($key, $value, $this->cache_group); } /** * Delete the field value(s) and remove from cache * * @param Field $field The field to delete. */ public function delete(Field $field) { if (!empty($field->get_hierarchy())) { return; // only applicable to root fields } $key = $this->get_key_for_field($field); delete_option($key); // Remove from cache wp_cache_delete($key, $this->cache_group); } /** * Save a single key-value pair to the database with autoload * * @param string $key * @param string $value * @param bool $autoload */ protected function save_key_value_pair_with_autoload($key, $value, $autoload) { $notoptions = wp_cache_get('notoptions', 'options'); $notoptions[$key] = ''; wp_cache_set('notoptions', $notoptions, 'options'); $autoload = $autoload ? 'yes' : 'no'; if (!add_option($key, $value, "", $autoload)) { update_option($key, $value, $autoload); } } }