Exemplo n.º 1
0
 /**
  * @param string $meta_type
  * @param int $object_id
  * @param string $multi_key 'abc' or 'ab/c/def'
  * @param array|string|int|bool $set_value
  */
 public static function set($meta_type, $object_id, $multi_key, $set_value)
 {
     if (empty($multi_key)) {
         trigger_error('Key not specified', E_USER_WARNING);
         return;
     }
     $multi_key = explode('/', $multi_key);
     $key = array_shift($multi_key);
     $multi_key = implode('/', $multi_key);
     // Make sure meta is added to the post, not a revision.
     if ($meta_type === 'post' && ($the_post = wp_is_post_revision($object_id))) {
         $object_id = $the_post;
     }
     $cache_key = self::$cache_key . '/' . $meta_type . '/' . $object_id . '/' . $key;
     if (empty($multi_key) && $multi_key !== '0') {
         /** Replace entire meta */
         fw_update_metadata($meta_type, $object_id, $key, $set_value);
         FW_Cache::del($cache_key);
     } else {
         /** Change only specified key */
         $values = array();
         $values['original'] = self::get($meta_type, $object_id, $key, true);
         $values['prepared'] = self::get($meta_type, $object_id, $key, false);
         fw_aks($multi_key, $set_value, $values['original']);
         fw_aks($multi_key, fw_prepare_option_value($set_value), $values['prepared']);
         FW_Cache::set($cache_key, $values);
         fw_update_metadata($meta_type, $object_id, $key, $values['original']);
     }
 }
 /**
  * @param int $post_id
  * @param string $multi_key 'abc' or 'ab/c/def'
  * @param array|string|int|bool $set_value
  */
 public static function set($post_id, $multi_key, $set_value)
 {
     if (empty($multi_key)) {
         trigger_error('Key not specified', E_USER_WARNING);
         return;
     }
     $multi_key = explode('/', $multi_key);
     $key = array_shift($multi_key);
     $multi_key = implode('/', $multi_key);
     $cache_key = self::$cache_key . '/' . $post_id . '/' . $key;
     if (empty($multi_key) && $multi_key !== '0') {
         /** Replace entire meta */
         fw_update_post_meta($post_id, $key, $set_value);
         FW_Cache::del($cache_key);
     } else {
         /** Change only specified key */
         $values = array();
         $values['original'] = self::get($post_id, $key, true);
         $values['prepared'] = self::get($post_id, $key, false);
         fw_aks($multi_key, $set_value, $values['original']);
         fw_aks($multi_key, fw_prepare_option_value($set_value), $values['prepared']);
         FW_Cache::set($cache_key, $values);
         fw_update_post_meta($post_id, $key, $values['original']);
     }
 }
Exemplo n.º 3
0
 protected static function get_set_key($multikey = null, $set_value = null, &$value)
 {
     $multikey = self::prepare_key($multikey);
     if ($set_value === null) {
         // get
         return fw_stripslashes_deep_keys($multikey === null ? $value : fw_akg($multikey, $value));
     } else {
         // set
         fw_aks($multikey, fw_addslashes_deep_keys($set_value), $value);
     }
 }
Exemplo n.º 4
0
 /**
  * Alternative for update_option()
  * @param string $option_name
  * @param string|null $specific_multi_key
  * @param array|string|int|bool $set_value
  */
 public static function set($option_name, $specific_multi_key = null, $set_value)
 {
     if ($specific_multi_key === null) {
         // Replace entire option
         update_option($option_name, $set_value, false);
     } else {
         // Change only specified key
         $value = self::get($option_name, null, true);
         fw_aks($specific_multi_key, $set_value, $value);
         update_option($option_name, $value, false);
     }
 }
 public function sanitize($value)
 {
     $value = json_decode($value, true);
     if (is_null($value) || !is_array($value)) {
         return null;
     }
     $POST = array();
     foreach ($value as $var) {
         fw_aks(fw_html_attr_name_to_array_multi_key($var['name'], true), $var['value'], $POST);
     }
     $value = fw()->backend->option_type($this->fw_option['type'])->get_value_from_input($this->fw_option, fw_akg(fw_html_attr_name_to_array_multi_key($this->id), $POST));
     return $value;
 }
 public function setting_sanitize_callback($input)
 {
     $input = json_decode($input, true);
     if (is_null($input)) {
         return null;
     }
     $POST = array();
     foreach ($input as $var) {
         fw_aks(fw_html_attr_name_to_array_multi_key($var['name']), $var['value'], $POST);
     }
     $value = fw_get_options_values_from_input(array($this->id => $this->fw_option), fw_akg(FW_Option_Type::get_default_name_prefix(), $POST));
     $value = array_pop($value);
     return $value;
 }
 /**
  * {@inheritdoc}
  */
 protected function _save($id, array $option, $value, array $params)
 {
     if ($wp_option = $this->get_wp_option($option, $params)) {
         if (isset($option['fw-storage']['key'])) {
             $wp_option_value = get_option($wp_option, array());
             fw_aks($option['fw-storage']['key'], $value, $wp_option_value);
             update_option($wp_option, $wp_option_value, false);
             unset($wp_option_value);
         } else {
             update_option($wp_option, $value, false);
         }
         return fw()->backend->option_type($option['type'])->get_value_from_input(array('type' => $option['type']), null);
     } else {
         return $value;
     }
 }
 /**
  * {@inheritdoc}
  */
 protected function _save($id, array $option, $value, array $params)
 {
     if ($post_id = $this->get_post_id($option, $params)) {
         $meta_id = $this->get_meta_id($id, $option, $params);
         if (isset($option['fw-storage']['key'])) {
             $meta_value = get_post_meta($post_id, $meta_id, true);
             fw_aks($option['fw-storage']['key'], $value, $meta_value);
             fw_update_post_meta($post_id, $meta_id, $meta_value);
             unset($meta_value);
         } else {
             fw_update_post_meta($post_id, $meta_id, $value);
         }
         return fw()->backend->option_type($option['type'])->get_value_from_input(array('type' => $option['type']), null);
     } else {
         return $value;
     }
 }
Exemplo n.º 9
0
 /**
  * Alternative for update_option()
  * @param string $option_name
  * @param string|null $specific_multi_key
  * @param array|string|int|bool $set_value
  */
 public static function set($option_name, $specific_multi_key = null, $set_value)
 {
     $cache_key = self::$cache_key . '/' . $option_name;
     if ($specific_multi_key === null) {
         /** Replace entire option */
         update_option($option_name, $set_value, false);
         FW_Cache::del($cache_key);
     } else {
         /** Change only specified key */
         $values = array();
         $values['original'] = self::get($option_name, null, true);
         $values['prepared'] = self::get($option_name, null, false);
         fw_aks($specific_multi_key, $set_value, $values['original']);
         fw_aks($specific_multi_key, fw_prepare_option_value($set_value), $values['prepared']);
         FW_Cache::set($cache_key, $values);
         update_option($option_name, $values['original'], false);
     }
 }
Exemplo n.º 10
0
 /**
  * @param string $meta_type
  * @param int $object_id
  * @param string $multi_key 'abc' or 'ab/c/def'
  * @param array|string|int|bool $set_value
  */
 public static function set($meta_type, $object_id, $multi_key, $set_value)
 {
     if (empty($multi_key)) {
         trigger_error('Key not specified', E_USER_WARNING);
         return;
     }
     $multi_key = explode('/', $multi_key);
     $key = array_shift($multi_key);
     $multi_key = implode('/', $multi_key);
     if (empty($multi_key) && $multi_key !== '0') {
         // Replace entire meta
         fw_update_metadata($meta_type, $object_id, $key, $set_value);
     } else {
         // Change only specified key
         $value = self::get($meta_type, $object_id, $key, true);
         fw_aks($multi_key, $set_value, $value);
         fw_update_metadata($meta_type, $object_id, $key, $value);
     }
 }
Exemplo n.º 11
0
 /**
  * @param $keys
  * @param $value
  * @param $keys_delimiter
  */
 public static function set($keys, $value, $keys_delimiter = '/')
 {
     fw_aks($keys, $value, self::$cache, $keys_delimiter);
     self::free_memory();
     // call it every time to take care about memory
 }
Exemplo n.º 12
0
/**
 * Set a theme customizer option value in database
 *
 * @param null $option_id Specific option id (accepts multikey). null - all options
 * @param mixed $value
 */
function fw_set_db_customizer_option($option_id = null, $value)
{
    $db_value = get_theme_mod(FW_Option_Type::get_default_name_prefix(), array());
    if (is_null($option_id)) {
        $db_value = $value;
    } else {
        fw_aks($option_id, $value, $db_value);
    }
    set_theme_mod(FW_Option_Type::get_default_name_prefix(), $db_value);
}
 public final function set($item_id = null, $option_id = null, $value, array $extra_data = array())
 {
     FW_Cache::del($cache_key_values = $this->get_cache_key('values', $item_id, $extra_data));
     FW_Cache::del($cache_key_values_processed = $this->get_cache_key('values:processed', $item_id, $extra_data));
     try {
         $options = FW_Cache::get($cache_key = $this->get_cache_key('options', $item_id, $extra_data));
     } catch (FW_Cache_Not_Found_Exception $e) {
         FW_Cache::set($cache_key, array());
         // prevent recursion
         FW_Cache::set($cache_key, $options = fw_extract_only_options($this->get_options($item_id, $extra_data)));
     }
     $sub_keys = null;
     if ($option_id) {
         $option_id = explode('/', $option_id);
         // 'option_id/sub/keys'
         $_option_id = array_shift($option_id);
         // 'option_id'
         $sub_keys = empty($option_id) ? null : implode('/', $option_id);
         // 'sub/keys'
         $option_id = $_option_id;
         unset($_option_id);
         $old_values = is_array($old_values = $this->get_values($item_id, $extra_data)) ? $old_values : array();
         $old_value = isset($old_values[$option_id]) ? $old_values[$option_id] : null;
         if ($sub_keys) {
             // update sub_key in old_value and use the entire value
             $new_value = $old_value;
             fw_aks($sub_keys, $value, $new_value);
             $value = $new_value;
             unset($new_value);
             $old_value = fw_akg($sub_keys, $old_value);
         }
         if (isset($options[$option_id])) {
             $value = fw()->backend->option_type($options[$option_id]['type'])->storage_save($option_id, $options[$option_id], $value, $this->get_fw_storage_params($item_id, $extra_data));
         }
         $old_values[$option_id] = $value;
         $this->set_values($item_id, $old_values, $extra_data);
         unset($old_values);
     } else {
         $old_value = is_array($old_values = $this->get_values($item_id, $extra_data)) ? $old_values : array();
         if (!is_array($value)) {
             $value = array();
         }
         foreach ($value as $_option_id => $_option_value) {
             if (isset($options[$_option_id])) {
                 $value[$_option_id] = fw()->backend->option_type($options[$_option_id]['type'])->storage_save($_option_id, $options[$_option_id], $_option_value, $this->get_fw_storage_params($item_id, $extra_data));
             }
         }
         $this->set_values($item_id, $value, $extra_data);
     }
     FW_Cache::del($cache_key_values);
     // fixes https://github.com/ThemeFuse/Unyson/issues/1538
     FW_Cache::del($cache_key_values_processed);
     $this->_after_set($item_id, $option_id, $sub_keys, $old_value, $extra_data);
 }
 private function _fw_update_adapter($allowed_places)
 {
     $db = $this->get_db();
     fw_aks('allowed_places', $allowed_places, $db);
     update_option($this->wp_option_sidebar_settings, $db, false);
 }
Exemplo n.º 15
0
/**
 * @param int $user_id
 * @param string $extension_name
 * @param mixed $value
 * @param string $keys
 *
 * In case the extension doesn't exist or is disabled, or the value is equal to previous, returns false
 *
 * @return bool|int
 */
function fw_set_db_extension_user_data($user_id, $extension_name, $value, $keys = null)
{
    if (!fw()->extensions->get($extension_name)) {
        trigger_error('Invalid extension: ' . $extension_name, E_USER_WARNING);
        return false;
    }
    $data = get_user_meta($user_id, 'fw_data', true);
    if ($keys == null) {
        fw_aks($extension_name, $value, $data);
    } else {
        fw_aks($extension_name . '/' . $keys, $value, $data);
    }
    return fw_update_user_meta($user_id, 'fw_data', $data);
}
Exemplo n.º 16
0
 /**
  * @param $keys
  * @param $value
  * @param $keys_delimiter
  */
 public static function set($keys, $value, $keys_delimiter = '/')
 {
     if (!self::is_enabled()) {
         return;
     }
     self::free_memory();
     fw_aks($keys, $value, self::$cache, $keys_delimiter);
     self::free_memory();
 }
Exemplo n.º 17
0
 public static function set($key, $value)
 {
     self::start_session();
     fw_aks($key, $value, $_SESSION);
 }
Exemplo n.º 18
0
/**
 * Set (or create if not exists) value for specified key in some array level
 *
 * @param string $keys 'a/b/c', or 'a/b/c/' equivalent to: $arr['a']['b']['c'][] = $val;
 * @param mixed $value
 * @param array|object $array_or_object
 * @param string $keys_delimiter
 */
function fw_aks($keys, $value, &$array_or_object, $keys_delimiter = '/')
{
    if (!is_array($keys)) {
        $keys = explode($keys_delimiter, (string) $keys);
    }
    $key_or_property = array_shift($keys);
    if ($key_or_property === null) {
        return;
    }
    $is_object = is_object($array_or_object);
    if ($is_object) {
        if (!property_exists($array_or_object, $key_or_property) || !(is_array($array_or_object->{$key_or_property}) || is_object($array_or_object->{$key_or_property}))) {
            if ($key_or_property === '') {
                // this happens when use 'empty keys' like: abc/d/e////i/j//foo/
                trigger_error('Cannot push value to object like in array ($arr[] = $val)', E_USER_WARNING);
            } else {
                $array_or_object->{$key_or_property} = array();
            }
        }
    } else {
        if (!is_array($array_or_object)) {
            $array_or_object = array();
        }
        if (!array_key_exists($key_or_property, $array_or_object) || !is_array($array_or_object[$key_or_property])) {
            if ($key_or_property === '') {
                // this happens when use 'empty keys' like: abc.d.e....i.j..foo.
                $array_or_object[] = array();
                // get auto created key (last)
                end($array_or_object);
                $key_or_property = key($array_or_object);
            } else {
                $array_or_object[$key_or_property] = array();
            }
        }
    }
    if (isset($keys[0])) {
        // not used count() for performance reasons
        if ($is_object) {
            fw_aks($keys, $value, $array_or_object->{$key_or_property});
        } else {
            fw_aks($keys, $value, $array_or_object[$key_or_property]);
        }
    } else {
        if ($is_object) {
            $array_or_object->{$key_or_property} = $value;
        } else {
            $array_or_object[$key_or_property] = $value;
        }
    }
}
 /**
  * Save settings for specific pages/grouped pages/conditional tags
  */
 public function update_preset($preset)
 {
     $db = $this->get_db();
     $path = 'settings/' . $preset['type'] . '/' . $preset['sub_type'];
     $value['position'] = $preset['position'];
     $value['sidebars'] = $preset['sidebars'];
     $value['timestamp'] = time();
     if (is_array($preset['ids']) and !empty($preset['ids'])) {
         $value['ids'] = $preset['ids'];
     }
     if (is_array($preset['ids'])) {
         $path .= '/by_ids/' . $preset['preset'];
     } else {
         $path .= '/common';
     }
     fw_aks($path, $value, $db);
     if (is_array($preset['ids'])) {
         $this->recalculate_saved_ids($db, $preset['type'], $preset['sub_type']);
         $this->clean_unused_arrays($db, $preset['type'], $preset['sub_type']);
         $saved_presets = fw_akg('settings/saved_presets', $db, array());
         if (!in_array($preset['preset'], $saved_presets)) {
             $saved_presets[] = $preset['preset'];
             fw_aks('settings/saved_presets', $saved_presets, $db);
         }
     }
     update_option($this->wp_option_sidebar_settings, $db);
     return true;
 }