/** * Update term meta field based on term ID. * */ public static function update_meta($term_id, $meta_key, $meta_value, $prev_value = '') { if (current_theme_supports('extended-taxonomies')) { return update_post_meta(self::get_post_for_extended_term($term_id)->ID, $meta_key, $meta_value, $prev_value); } return update_metadata('taxonomy', $term_id, $meta_key, $meta_value, $prev_value); }
public static function restore_revision($post_id, $revision_id) { $meta = piklist('post_custom', $revision->ID); foreach ($meta as $key => $value) { update_metadata('post', $post_id, $key, $value); } }
/** * @ticket 35795 */ public function test_slashed_key_for_existing_metadata() { global $wpdb; add_metadata('post', 123, wp_slash('foo\\foo'), 'bar'); update_metadata('post', 123, wp_slash('foo\\foo'), 'baz'); $found = get_metadata('post', 123, 'foo\\foo', true); $this->assertSame('baz', $found); }
/** * @param WP_Post $post * @param WP_Post $revision */ public function persist(WP_Post $post, WP_Post $revision) { $value = $_REQUEST[$this->getKey()]; $format = 'Y-m-d H:i:s'; if (isset($this->options['config']['timepicker']) && $this->options['config']['timepicker'] == false) { $format = 'Y-m-d'; } update_metadata('post', $revision->ID, $this->getKey(), date_i18n($format, strtotime($value))); }
function save_item_category($term_id, $tt_id) { if (!$term_id) { return; } if (isset($_POST['ait_item_category_thumbnail'])) { update_metadata(str_replace("-", "_", $_POST['taxonomy']), $term_id, 'ait_item_category_thumbnail', $_POST['ait_item_category_thumbnail']); } }
/** * Update the value of the specified metadata field of the object wrapped by this container. * * @access protected * * @param string $field Meta name. * @param string $new_value New meta value. * @param string $old_value old meta value. * @return bool|WP_Error True on success, an error object if something went wrong. */ function update_field($field, $new_value, $old_value = '') { $rez = update_metadata($this->meta_type, $this->container_id, $field, $new_value, $old_value); if ($rez) { return true; } else { return new WP_Error('metadata_update_failed', sprintf(__("Failed to update the meta field '%s' on %s [%d]", 'broken-link-checker'), $field, $this->meta_type, $this->container_id)); } }
/** * Update a meta field. * * @alias set * @synopsis <id> <key> <value> */ public function update($args, $assoc_args) { list($object_id, $meta_key, $meta_value) = $args; $success = update_metadata($this->meta_type, $object_id, $meta_key, $meta_value); if ($success) { WP_CLI::success("Updated custom field."); } else { WP_CLI::error("Failed to update custom field."); } }
public function saveThumbnail($termId, $ttId, $taxonomy) { if ($taxonomy != Types::PRODUCT_CATEGORY) { return; } $thumbnail = isset($_POST[Types::PRODUCT_CATEGORY . '_thumbnail_id']) ? $_POST[Types::PRODUCT_CATEGORY . '_thumbnail_id'] : false; if (!is_numeric($thumbnail)) { return; } update_metadata(Core::TERMS, $termId, 'thumbnail_id', (int) $thumbnail); }
public function update_data($new_value, $single = true) { extract($this->data_args(array('new_value' => $new_value, 'single' => $single))); if ('options-page' === $type) { return rrze_Meta_Box::update_option($id, $field_id, $new_value, $single); } if (!$single) { return add_metadata($type, $id, $field_id, $new_value, false); } return update_metadata($type, $id, $field_id, $new_value); }
function easy_ads_update_section_meta($post_id, $field_name, $value = '') { if (empty($value) or !$value) { $doo = delete_metadata('easy_ads_taxnomy_sections_', $post_id, $field_name, $value); } elseif (!get_metadata('easy_ads_taxnomy_sections_', $post_id, $field_name)) { $doo = add_metadata('easy_ads_taxnomy_sections_', $post_id, $field_name, $value); } else { $doo = update_metadata('easy_ads_taxnomy_sections_', $post_id, $field_name, $value); } return $doo; }
/** * Save matadata object * * @return int the metadata object id */ function save() { if ($this->id > 0) { return update_metadata($this->id, $this->name, $this->value, $this->value_type, $this->owner_guid, $this->access_id); } else { $this->id = create_metadata($this->entity_guid, $this->name, $this->value, $this->value_type, $this->owner_guid, $this->access_id); if (!$this->id) { throw new IOException(elgg_echo('IOException:UnableToSaveNew', array(get_class()))); } return $this->id; } }
/** * Update meta field for a user * * @param array $args * @param array $assoc_args **/ public function update($args, $assoc_args) { $object_id = WP_CLI::get_numeric_arg($args, 0, "{$this->meta_type} ID"); $meta_key = self::get_arg_or_error($args, 1, "meta_key"); $meta_value = self::get_arg_or_error($args, 2, "meta_value"); $success = update_metadata($this->meta_type, $object_id, $meta_key, $meta_value); if ($success) { WP_CLI::success("Updated custom field."); } else { WP_CLI::error("Failed to update custom field."); } }
/** * Save metadata object * * @return int|bool the metadata object id or true if updated * * @throws IOException */ public function save() { if ($this->id > 0) { return update_metadata($this->id, $this->name, $this->value, $this->value_type, $this->owner_guid, $this->access_id); } else { $this->id = create_metadata($this->entity_guid, $this->name, $this->value, $this->value_type, $this->owner_guid, $this->access_id); if (!$this->id) { throw new \IOException("Unable to save new " . get_class()); } return $this->id; } }
public function do_save($return_val, $params, $metas, $module) { $status = false; if (!isset($params['meta_value'])) { return false; } if (empty($params['meta_key'])) { return false; } if (!is_null($params['meta_value'])) { $status = update_metadata($this->object_name, $this->object_id, $params['meta_key'], $params['meta_value']); } return $status; }
public function unsubscribe($user_id) { $subscriber_ids = $this->subscriber_ids(); if (in_array($user_id, $subscriber_ids)) { $subscriber_ids = array_diff($subscriber_ids, array($user_id)); update_metadata($this->meta_type, $this->id, self::SUBSCRIBED_META_KEY, $subscriber_ids); /** * A post subscription has been removed. * * @param int $subscriber_id * @param Prompt_Interface_Subscribable $object The thing subscribed to. */ do_action('prompt/unsubscribed', $user_id, $this, $this->meta_type); } return $this; }
/** * Pre save page template and page type. * * @param int $id */ protected function pre_save($id) { if (empty($id)) { return; } $data = $this->get_pre_data(); foreach ($data as $key => $value) { if (empty($value)) { continue; } if (is_array($value)) { list($keys, $value) = $this->get_pre_deep_keys_value($value); $key = sprintf('%s_%s', $key, implode('_', $keys)); } update_metadata($this->get_meta_type(), $id, $key, $value); } }
/** * @param WP_Post $post * @param WP_Post $revision */ public function persist(WP_Post $post, WP_Post $revision) { $key = $this->getKey(); $values = $_POST[$key]; if (is_array($values)) { delete_metadata('post', $revision->ID, $key); foreach ($values as $value) { add_metadata('post', $revision->ID, $key, $value); } } else { if (empty($values)) { delete_post_meta($revision->ID, $key); } else { update_metadata('post', $revision->ID, $key, $values); } } }
function save_ctax_meta($term_id, $tt_id) { if (!$term_id) { return; } global $wpdb; foreach ($this->args as $fields) { if (isset($_POST[$fields['name']])) { //print_r('<hr />'); //print_r($_POST['taxonomy']); //print_r($term_id); //print_r($fields['name']); //print_r($_POST[ $fields['name'] ] ); $update = update_metadata($_POST['taxonomy'], $term_id, $fields['name'], $_POST[$fields['name']]); } } }
/** * Hijacks saving of cached oEmbed. * Saves cached data to relevant object metadata (vs postmeta) * * @since 0.9.5 * @param boolean $check Whether to continue setting postmeta * @param int $object_id Object ID to get postmeta from * @param string $meta_key Postmeta's key * @param mixed $meta_value Value of the postmeta to be saved * @return boolean Whether to continue setting */ public static function hijack_oembed_cache_set($check, $object_id, $meta_key, $meta_value) { if (!self::$hijack || self::$object_id != $object_id && 1987645321 !== $object_id) { return $check; } // Cache the result to our metadata if ('options-page' === self::$object_type) { // Set the option cmb_Meta_Box::update_option(self::$object_id, self::$embed_args['cache_key'], $meta_value, array('type' => 'oembed')); // Save the option cmb_Meta_Box::save_option(self::$object_id); } else { update_metadata(self::$object_type, self::$object_id, $meta_key, $meta_value); } // Anything other than `null` to cancel saving to postmeta return true; }
function elggpg_import_key($public_key, $user) { $gpg = new gnupg(); $info = $gpg->import($public_key); $new_fp = $info['fingerprint']; $user_fp = current(elgg_get_metadata(array('guid' => $user->guid, 'metadata_name' => 'openpgp_publickey'))); $access_id = ACCESS_LOGGED_IN; if ($user_fp && $user_fp->value != $new_fp) { update_metadata($user_fp->id, $user_fp->name, $new_fp, 'text', $user->guid, $access_id); $info['imported'] = 1; } elseif (!$user_fp) { create_metadata($user->guid, "openpgp_publickey", $new_fp, 'text', $user->guid, $access_id); $info['imported'] = 1; } $info['key_id'] = elggpg_fp2keyid($new_fp); return $info; }
function acf_update_metadata($post_id = 0, $name = '', $value = '', $hidden = false) { // vars $return = false; $prefix = $hidden ? '_' : ''; // get post_id info $info = acf_get_post_id_info($post_id); // bail early if no $post_id (acf_form - new_post) if (!$info['id']) { return $return; } // option if ($info['type'] === 'option') { $name = $prefix . $post_id . '_' . $name; $return = acf_update_option($name, $value); // meta } else { $name = $prefix . $name; $return = update_metadata($info['type'], $info['id'], $name, $value); } // return return $return; }
/** * Update post meta field based on post ID. * * Use the $prev_value parameter to differentiate between meta fields with the * same key and post ID. * * If the meta field for the post does not exist, it will be added. * * @since 1.5.0 * @uses $wpdb * @link http://codex.wordpress.org/Function_Reference/update_post_meta * * @param int $post_id Post 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 bool False on failure, true if success. */ function update_post_meta($post_id, $meta_key, $meta_value, $prev_value = '') { // make sure meta is added to the post, not a revision if ($the_post = wp_is_post_revision($post_id)) { $post_id = $the_post; } return update_metadata('post', $post_id, $meta_key, $meta_value, $prev_value); }
/** * Update user meta field based on user ID. * * Use the $prev_value parameter to differentiate between meta fields with the * same key and user ID. * * If the meta field for the user does not exist, it will be added. * * @since 3.0.0 * @uses update_metadata * @link http://codex.wordpress.org/Function_Reference/update_user_meta * * @param int $user_id Post 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 update_user_meta($user_id, $meta_key, $meta_value, $prev_value = '') { return update_metadata('user', $user_id, $meta_key, $meta_value, $prev_value); }
/** * Update a piece of group metadata. * * @param int $group_id ID of the group. * @param string $meta_key Metadata key. * @param mixed $meta_value Value to store. * @param mixed $prev_value Optional. If specified, only update existing * metadata entries with the specified value. * Otherwise, update all entries. * * @return bool|int $retval Returns false on failure. On successful update of existing * metadata, returns true. On successful creation of new metadata, * returns the integer ID of the new metadata row. */ function groups_update_groupmeta($group_id, $meta_key, $meta_value, $prev_value = '') { add_filter('query', 'bp_filter_metaid_column_name'); $retval = update_metadata('group', $group_id, $meta_key, $meta_value, $prev_value); remove_filter('query', 'bp_filter_metaid_column_name'); return $retval; }
/** * Save the field value(s) into the database. * * @param Field $field The field to save. */ public function save(Field $field) { if (!update_metadata($this->get_meta_type(), $this->get_id(), $this->get_field_name($field), $field->get_value())) { add_metadata($this->get_meta_type(), $this->get_id(), $this->get_field_name($field), $field->get_value(), true); } }
/** * Store the export record. * * @param array $export * @return bool */ function set_exported_menu($export) { //Caution: update_metadata expects slashed data. $export = wp_slash($export); $user = wp_get_current_user(); return update_metadata('user', $user->ID, 'custom_menu_export', $export); }
/** * WooCommerce Term Meta API * * WC tables for storing term meta are @deprecated from WordPress 4.4 since 4.4 has its own table. * This function serves as a wrapper, using the new table if present, or falling back to the WC table. * * @todo These functions should be deprecated with notices in a future WC version, allowing users a chance to upgrade WordPress. * * @param mixed $term_id * @param string $meta_key * @param mixed $meta_value * @param string $prev_value (default: '') * @return bool */ function update_woocommerce_term_meta($term_id, $meta_key, $meta_value, $prev_value = '') { return function_exists('update_term_meta') ? update_term_meta($term_id, $meta_key, $meta_value, $prev_value) : update_metadata('woocommerce_term', $term_id, $meta_key, $meta_value, $prev_value); }
/** * メタデータを更新。そのメタデータが存在しない場合は追加。 * * @param string $key メタキー * @param mixed $value 保存する値 * @param mixed $prev_value 指定された場合、この値のものだけを上書き * @return int|false Meta ID */ public function update($key, $value, $prev_value = '') { $return = false; do_action(SCF_Config::PREFIX . '-before-save-' . $this->meta_type, $this->id, $key, $value); $is_valid = apply_filters(SCF_Config::PREFIX . '-validate-save-' . $this->meta_type, $this->id, $key, $value); if ($is_valid) { if (_get_meta_table($this->meta_type)) { $return = update_metadata($this->meta_type, $this->id, $key, $value, $prev_value); } else { $option_name = $this->get_option_name(); $option = get_option($option_name); if (isset($option[$key])) { if ($prev_value !== '') { foreach ($option[$key] as $option_key => $option_value) { if ($prev_value === $option_value) { $option[$key][$option_key] = $value; break; } } } else { foreach ($option[$key] as $option_key => $option_value) { $option[$key][$option_key] = $value; } } } else { $option[$key][] = $value; } $option = stripslashes_deep($option); $return = update_option($option_name, $option, false); } } do_action(SCF_Config::PREFIX . '-after-save-' . $this->meta_type, $this->id, $key, $value); return $return; }
/** * This is for the Wordpress settings page. */ function update_facebook_settings() { foreach ($_POST['coda_slider_post_id'] as $meta_id => $post_id) { update_metadata('post', (int) $post_id, 'coda_slider_wt', (int) $_POST['coda_slider_wt'][$meta_id]); } print '<div id="message" class="updated below-h2"><p>Your slider was updated successfully.</p></div>'; }
function hocwp_term_update_meta($term_id, $meta_key, $meta_value) { $version = hocwp_get_wp_version(); if (version_compare($version, '4.4', '>=')) { return update_term_meta($term_id, $meta_key, $meta_value); } hocwp_term_register_termmeta_table(); return update_metadata('term', $term_id, $meta_key, $meta_value); }