/**
  * @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']);
     }
 }
 /**
  * {@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);
         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;
     }
 }
 /**
  * {@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.º 4
0
/**
 * @internal
 */
function _mega_menu_meta($post, $key, $default = null, $write = false)
{
    static $meta = array();
    $post_id = is_object($post) ? $post->ID : $post;
    if (!isset($meta[$post_id])) {
        $meta[$post_id] = (array) get_post_meta($post_id, 'mega-menu', true);
    }
    if ($write) {
        if (is_array($key)) {
            $meta[$post_id] = array_filter(array_merge($meta[$post_id], $key));
        } else {
            $meta[$post_id][$key] = $default;
            $meta[$post_id][$key] = array_filter($meta[$post_id][$key]);
        }
        fw_update_post_meta($post_id, 'mega-menu', $meta[$post_id]);
        return null;
    }
    return isset($meta[$post_id][$key]) ? $meta[$post_id][$key] : $default;
}
Exemplo n.º 5
0
 /**
  * Update all post meta `fw_option:<option-id>` with values from post options that has the 'save-in-separate-meta' parameter
  *
  * @param int $post_id
  *
  * @return bool
  * @deprecated since 2.5.0
  */
 public function _sync_post_separate_meta($post_id)
 {
     $post_type = get_post_type($post_id);
     if (!$post_type) {
         return false;
     }
     $meta_prefix = 'fw_option:';
     $options_values = fw_get_db_post_option($post_id);
     $separate_meta_options = array();
     foreach (fw_extract_only_options(fw()->theme->get_post_options($post_type)) as $option_id => $option) {
         if (isset($option['save-in-separate-meta']) && $option['save-in-separate-meta'] && array_key_exists($option_id, $options_values)) {
             $separate_meta_options[$meta_prefix . $option_id] = $options_values[$option_id];
         }
     }
     unset($options_values);
     /** @var wpdb $wpdb */
     global $wpdb;
     foreach ($wpdb->get_results($wpdb->prepare("SELECT meta_key " . "FROM {$wpdb->postmeta} " . "WHERE meta_key LIKE %s AND post_id = %d", $wpdb->esc_like($meta_prefix) . '%', $post_id)) as $row) {
         if (array_key_exists($row->meta_key, $separate_meta_options)) {
             /**
              * This meta exists and will be updated below.
              * Do not delete for performance reasons, instead of delete->insert will be performed only update
              */
             continue;
         } else {
             // this option does not exist anymore
             delete_post_meta($post_id, $row->meta_key);
         }
     }
     foreach ($separate_meta_options as $meta_key => $option_value) {
         fw_update_post_meta($post_id, $meta_key, $option_value);
     }
     return true;
 }
Exemplo n.º 6
0
 /**
  * @param int  $post_id
  * @param WP_Post $post
  */
 public function _action_save_post($post_id, $post)
 {
     if (!fw_is_real_post_save($post_id)) {
         return;
     }
     $options_values = array_merge((array) fw_get_db_post_option($post_id), fw_get_options_values_from_input(fw()->theme->get_post_options($post->post_type)));
     fw_set_db_post_option($post_id, null, $options_values);
     // find options that requested to be saved in separate meta
     foreach (fw_extract_only_options(fw()->theme->get_post_options($post->post_type)) as $option_id => $option) {
         if (isset($option['save-to-separate-meta']) && $option['save-to-separate-meta']) {
             // think of a better key name
             fw_update_post_meta($post_id, 'fw_option_' . $option_id, $options_values[$option_id]);
         }
     }
     do_action('fw_save_post_options', $post_id, $post, $options_values);
 }
 private function update($key, $value)
 {
     $this->check();
     fw_update_post_meta($this->post_id, $key, $value);
 }