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']);
     }
 }
Exemplo n.º 2
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.º 3
0
/**
 * Update term meta field based on term ID.
 *
 * Use the $prev_value parameter to differentiate between meta fields with the
 * same key and term ID.
 *
 * If the meta field for the term does not exist, it will be added.
 *
 * @param int $term_id Term ID.
 * @param string $key Metadata key.
 * @param mixed $value Metadata value.
 * @param mixed $prev_value Optional. Previous value to check before removing.
 *
 * @return bool False on failure, true if success.
 */
function fw_update_term_meta($term_id, $meta_key, $meta_value, $prev_value = '')
{
    return fw_update_metadata('fw_term', $term_id, $meta_key, $meta_value, $prev_value);
}
Exemplo n.º 4
0
/**
 * Update comment meta field based on comment ID.
 *
 * Use the $prev_value parameter to differentiate between meta fields with the
 * same key and comment ID.
 *
 * If the meta field for the comment does not exist, it will be added.
 *
 * @param int $comment_id Comment ID.
 * @param string $meta_key Metadata key.
 * @param mixed $meta_value Metadata value.
 * @param mixed $prev_value Optional. Previous value to check before removing.
 *
 * @return int|bool Meta ID if the key didn't exist, true on successful update, false on failure.
 */
function fw_update_comment_meta($comment_id, $meta_key, $meta_value, $prev_value = '')
{
    return fw_update_metadata('comment', $comment_id, $meta_key, $meta_value, $prev_value);
}