/** * Save Category meta data */ function save_category_meta($term_id) { if (!get_term_meta($term_id, 'ac_category_featured_image')) { add_term_meta($term_id, 'ac_category_featured_image', '', true); } if (!get_term_meta($term_id, 'ac_category_color')) { add_term_meta($term_id, 'ac_category_color', '', true); } if (!get_term_meta($term_id, 'ac_category_icon')) { add_term_meta($term_id, 'ac_category_icon', '', true); } if (!get_term_meta($term_id, 'ac_category_icon_url')) { add_term_meta($term_id, 'ac_category_icon_url', '', true); } if (isset($_POST['ac_category_featured_image'])) { $ac_category_featured_image = esc_url($_POST['ac_category_featured_image']); update_term_meta($term_id, 'ac_category_featured_image', $ac_category_featured_image); } if (isset($_POST['ac_category_color'])) { $ac_category_color = esc_attr($_POST['ac_category_color']); update_term_meta($term_id, 'ac_category_color', $ac_category_color); } if (isset($_POST['ac_category_icon'])) { $ac_category_icon = $_POST['ac_category_icon']; update_term_meta($term_id, 'ac_category_icon', $ac_category_icon); } if (isset($_POST['ac_category_icon_url'])) { $ac_category_icon_url = esc_url($_POST['ac_category_icon_url']); update_term_meta($term_id, 'ac_category_icon_url', $ac_category_icon_url); } }
/** * Upgrades term metadata for version 2701. * * @since 2.7.0 */ function the_seo_framework_do_upgrade_2701() { $term_meta = get_option('autodescription-term-meta'); foreach ((array) $term_meta as $term_id => $meta) { add_term_meta($term_id, THE_SEO_FRAMEWORK_TERM_OPTIONS, $meta, true); } update_option('the_seo_framework_upgraded_db_version', '2701'); }
function thb_taxonomy_meta_field($term) { $t_id = $term->term_id; $term_meta = get_term_meta($t_id, 'cat_meta'); if (!$term_meta) { $term_meta = add_term_meta($t_id, 'cat_meta', ''); } ?> <tr> <th scope="row" valign="top"><label for="term_meta[cat_header]"><?php _e('Category Header', THB_THEME_NAME); ?> </label></th> <td> <?php $content = esc_attr($term_meta[0]['cat_header']) ? esc_attr($term_meta[0]['cat_header']) : ''; wp_editor($content, "term_meta[cat_header]", array('wpautop' => true, 'media_buttons' => true, 'textarea_name' => "term_meta[cat_header]", 'textarea_rows' => "6", 'tinymce' => true)); ?> <p class="description"><?php _e('This content will be displayed at the top of this category. You can use your shortcodes here. <small>You can create your content using visual composer and then copy its text here</small>', THB_THEME_NAME); ?> </p> </td> </tr> <?php }
function bottom_text_taxonomy_edit_meta_field($term) { // put the term ID into a variable $t_id = $term->term_id; // retrieve the existing value(s) for this meta field. This returns an array $term_meta = get_term_meta($t_id, 'cat_meta'); if (!$term_meta) { $term_meta = add_term_meta($t_id, 'cat_meta', ''); } ?> <tr class="form-field"> <th scope="row" valign="top"><label for="term_meta[cat_footer]"><?php _e('Bottom Content', 'flatsome'); ?> </label></th> <td> <?php $content = isset($term_meta[0]['cat_footer']) ? esc_attr($term_meta[0]['cat_footer']) : ''; echo '<textarea id="term_meta[cat_footer]" name="term_meta[cat_footer]">' . $content . '</textarea>'; ?> <p class="description"><?php _e('Enter a value for this field. Shortcodes are allowed. This will be displayed at bottom of the category.', 'flatsome'); ?> </p> </td> </tr> <?php }
function save_feature_category_meta($term_id, $tt_id) { if (isset($_POST['meta-keywords']) && '' !== $_POST['meta-keywords']) { $group = esc_attr($_POST['meta-keywords']); add_term_meta($term_id, 'meta-keywords', $group, true); } }
function hocwp_term_add_meta($term_id, $meta_key, $meta_value, $unique = false) { $version = hocwp_get_wp_version(); if (version_compare($version, '4.4', '>=')) { return add_term_meta($term_id, $meta_key, $meta_value, $unique); } return add_metadata('term', $term_id, $meta_key, $meta_value, $unique); }
function xmlrpc_add_term_meta($site, $term_id, $metadata) { foreach ($metadata as $meta_key => $meta_value) { if (array_key_exists(0, $meta_value) && count($meta_value) == 1) { $meta_value = $meta_value[0]; } add_term_meta($term_id, $meta_key, $meta_value); } }
/** * @ticket 37151 */ public function test_order_by_meta_value_num() { register_taxonomy('wptests_tax', 'post'); $terms = self::factory()->term->create_many(3, array('taxonomy' => 'wptests_tax')); add_term_meta($terms[0], 'foo', 10); add_term_meta($terms[1], 'foo', 1); add_term_meta($terms[2], 'foo', 100); $q = new WP_Term_Query(array('taxonomy' => array('wptests_tax'), 'fields' => 'ids', 'hide_empty' => false, 'meta_key' => 'foo', 'orderby' => 'meta_value_num')); $found = array_map('intval', $q->terms); $this->assertSame(array($terms[1], $terms[0], $terms[2]), $found); }
/** * Creates the individual test data object. * * Create individual posts for testing with. Gathers basic information such * as title, content, thumbnail, etc. and inserts them with the post. Also * adds metaboxes if applicable . * * @access private * * @see TestContent, wp_insert_post, add_post_meta, update_post_meta, $this->random_metabox_content * * @param string $slug a custom post type ID. */ private function create_test_object($slug) { // Get a random title $title = apply_filters("tc_{$slug}_term_title", TestContent::title()); $return = wp_insert_term($title, $slug, apply_filters("tc_{$slug}_term_arguments", array('description' => TestContent::title(), 'slug' => sanitize_title($title)))); // Then, set a test content flag on the new post for later deletion add_term_meta($return['term_id'], 'evans_test_content', '__test__', true); // Check if we have errors and return them or created message if (is_wp_error($return)) { error_log($return->get_error_message()); return $return; } else { return array('action' => 'created', 'object' => 'term', 'oid' => $return['term_id'], 'type' => $slug, 'link_edit' => admin_url('/edit-tags.php?action=edit&taxonomy=' . $slug . '&tag_ID=' . $return['term_id']), 'link_view' => get_term_link($return['term_id'])); } }
public function save_taxonomy($term_id) { if (wp_verify_nonce(cs_get_var('cs-taxonomy-nonce'), 'cs-taxonomy')) { $errors = array(); $taxonomy = cs_get_var('taxonomy'); foreach ($this->options as $request_value) { if ($taxonomy == $request_value['taxonomy']) { $request_key = $request_value['id']; $request = cs_get_var($request_key, array()); // ignore _nonce if (isset($request['_nonce'])) { unset($request['_nonce']); } if (isset($request_value['fields'])) { foreach ($request_value['fields'] as $field) { if (isset($field['type']) && isset($field['id'])) { $field_value = cs_get_vars($request_key, $field['id']); // sanitize options if (isset($field['sanitize']) && $field['sanitize'] !== false) { $sanitize_type = $field['sanitize']; } else { if (!isset($field['sanitize'])) { $sanitize_type = $field['type']; } } if (has_filter('cs_sanitize_' . $sanitize_type)) { $request[$field['id']] = apply_filters('cs_sanitize_' . $sanitize_type, $field_value, $field, $request_value['fields']); } // validate options if (isset($field['validate']) && has_filter('cs_validate_' . $field['validate'])) { $validate = apply_filters('cs_validate_' . $field['validate'], $field_value, $field, $request_value['fields']); if (!empty($validate)) { $meta_value = get_term_meta($term_id, $request_key, true); $errors[$field['id']] = array('code' => $field['id'], 'message' => $validate, 'type' => 'error'); $default_value = isset($field['default']) ? $field['default'] : ''; $request[$field['id']] = isset($meta_value[$field['id']]) ? $meta_value[$field['id']] : $default_value; } } } } } $request = apply_filters('cs_save_taxonomy', $request, $request_key, $term_id); if (empty($request)) { delete_term_meta($term_id, $request_key); } else { if (get_term_meta($term_id, $request_key, true)) { update_term_meta($term_id, $request_key, $request); } else { add_term_meta($term_id, $request_key, $request); } } } } set_transient('cs-taxonomy-transient', $errors, 10); } }
/** * 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 mixed $meta_key * @param mixed $meta_value * @param bool $unique (default: false) * @return bool */ function add_woocommerce_term_meta($term_id, $meta_key, $meta_value, $unique = false) { return function_exists('add_term_meta') ? add_term_meta($term_id, $meta_key, $meta_value, $unique) : add_metadata('woocommerce_term', $term_id, $meta_key, $meta_value, $unique); }
function save_neighborhood_meta($term_id) { global $neighborhood_terms; foreach ($neighborhood_terms as $t) { if (isset($_POST['tag-' . $t]) && '' !== $_POST['tag-' . $t]) { $group = $t == 'agent-email' ? sanitize_email($_POST['tag-' . $t]) : sanitize_title($_POST['tag-' . $t]); add_term_meta($term_id, 'neighborhood-' . $t, $group, true); } } }
/** * @param $id */ function save_category_metaboxes($id) { $awmp_edit = $nonce = null; if (isset($_POST['aiosp_edit'])) { $awmp_edit = $_POST['aiosp_edit']; } if (isset($_POST['nonce-aioseop-edit'])) { $nonce = $_POST['nonce-aioseop-edit']; } if (isset($awmp_edit) && !empty($awmp_edit) && wp_verify_nonce($nonce, 'edit-aioseop-nonce')) { $optlist = array('keywords', 'description', 'title', 'custom_link', 'sitemap_exclude', 'disable', 'disable_analytics', 'noindex', 'nofollow', 'noodp', 'noydir', 'titleatr', 'menulabel'); foreach ($optlist as $f) { $field = "aiosp_{$f}"; if (isset($_POST[$field])) { ${$field} = $_POST[$field]; } } $optlist = array('keywords', 'description', 'title', 'custom_link', 'noindex', 'nofollow', 'noodp', 'noydir', 'titleatr', 'menulabel'); if (!!empty($this->options['aiosp_can']) && !empty($this->options['aiosp_customize_canonical_links'])) { unset($optlist['custom_link']); } foreach ($optlist as $f) { delete_term_meta($id, "_aioseop_{$f}"); } if ($this->is_admin()) { delete_term_meta($id, '_aioseop_sitemap_exclude'); delete_term_meta($id, '_aioseop_disable'); delete_term_meta($id, '_aioseop_disable_analytics'); } foreach ($optlist as $f) { $var = "aiosp_{$f}"; $field = "_aioseop_{$f}"; if (isset(${$var}) && !empty(${$var})) { add_term_meta($id, $field, ${$var}); } } if (isset($aiosp_sitemap_exclude) && !empty($aiosp_sitemap_exclude) && $this->is_admin()) { add_term_meta($id, '_aioseop_sitemap_exclude', $aiosp_sitemap_exclude); } if (isset($aiosp_disable) && !empty($aiosp_disable) && $this->is_admin()) { add_term_meta($id, '_aioseop_disable', $aiosp_disable); if (isset($aiosp_disable_analytics) && !empty($aiosp_disable_analytics)) { add_term_meta($id, '_aioseop_disable_analytics', $aiosp_disable_analytics); } } } }
/** * Validates and saves all meta field values. * * It will only do that if all requirements are met. * * @since 0.6.0 * @param integer $term_id the current term ID * @param WP_Term $term the term object * @param bool $update whether the term is being updated (true) or generated (false) */ public function save_meta($term_id, $term, $update = false) { if (!$this->can_save_meta($term_id, $term)) { return; } $meta_values_validated = $this->validate_meta_values($_POST, $term_id); foreach ($meta_values_validated as $field_slug => $meta_value_validated) { if (is_array($meta_value_validated)) { delete_term_meta($term_id, $field_slug); foreach ($meta_value_validated as $mv) { add_term_meta($term_id, $field_slug, $mv); } } else { update_term_meta($term_id, $field_slug, $meta_value_validated); } } }
function handle($term_id, $tt_id, $taxonomy) { if (!isset($_POST[$this->nonce]) || !wp_verify_nonce($_POST[$this->nonce], $this->nonce_action)) { return $term_id; } $fields = $this->fields(); foreach (dp_field_options($fields) as $name => $field) { $meta_value = get_term_meta($term_id, $name, true); $new_meta_value = $_POST[$name]; if (is_array($new_meta_value)) { $new_meta_value = array_filter($new_meta_value); } elseif ($field['type'] == 'password') { $new_meta_value = md5($new_meta_vlue); } if ($new_meta_value && empty($meta_value)) { add_term_meta($term_id, $name, $new_meta_value, true); } elseif ($new_meta_value && $new_meta_value != $meta_value) { update_term_meta($term_id, $name, $new_meta_value); } elseif (empty($new_meta_value) && $meta_value) { delete_term_meta($term_id, $name, $meta_value); } } }
/** * save_category_fields function. * * @param mixed $term_id Term ID being saved */ public function save_category_fields($term_id, $tt_id = '') { update_term_meta($term_id, 'order', 0); if (isset($_POST['display_type']) && '' !== $_POST['display_type']) { $type = in_array($_POST['display_type'], array('documents', 'subcategory', 'both')) ? $_POST['display_type'] : ''; add_term_meta($term_id, 'display_type', $type); } if (isset($_POST['docu_cat_thumbnail_id']) && absint($_POST['docu_cat_thumbnail_id']) > 0) { add_term_meta($term_id, 'thumbnail_id', absint($_POST['docu_cat_thumbnail_id'])); } }
public function add_meta($key, $value) { return add_term_meta($this->get_id(), $key, $value); }
foreach ($this->ashu_feild as $ashu_feild) { delete_term_meta($term_id, $ashu_feild['id']); } } function save_taxonomy_metadata($term_id) { foreach ($this->ashu_feild as $ashu_feild) { if (isset($_POST[$ashu_feild['id']])) { if (!current_user_can('manage_categories')) { return $term_id; } if ($ashu_feild['type'] == 'tinymce') { $data = stripslashes($_POST[$ashu_feild['id']]); } elseif ($ashu_feild['type'] == 'checkbox') { $data = $_POST[$ashu_feild['id']]; } elseif ($ashu_feild['type'] == 'numbers_array') { $data = explode(',', $_POST[$ashu_feild['id']]); $data = array_filter($data); } elseif ($ashu_feild['type'] == 'gallery') { $data = explode(',', $_POST[$ashu_feild['id']]); $data = array_filter($data); } else { $data = htmlspecialchars($_POST[$ashu_feild['id']], ENT_QUOTES, "UTF-8"); } if (get_term_meta($term_id, $ashu_feild['id']) == "") { add_term_meta($term_id, $ashu_feild['id'], $data, true); } elseif ($data != get_term_meta($term_id, $ashu_feild['id'], true)) { update_term_meta($term_id, $ashu_feild['id'], $data); } elseif ($data == "") { delete_term_meta($term_id, $ashu_feild['id'], get_term_meta($term_id, $ashu_feild['id'], true));
/** * @ticket 21760 */ public function test_get_term_by_does_not_prime_term_meta_cache() { global $wpdb; $term_id = $this->factory->term->create(array('name' => 'Burrito', 'taxonomy' => 'post_tag')); add_term_meta($term_id, 'foo', 'bar'); clean_term_cache($term_id, 'post_tag'); $num_queries = $wpdb->num_queries; $term = get_term_by('name', 'Burrito', 'post_tag'); $num_queries++; $this->assertTrue($term instanceof WP_Term); $this->assertSame($term_id, $term->term_id); $this->assertEquals($num_queries, $wpdb->num_queries); $term_meta = get_term_meta($term_id, 'foo', true); $num_queries++; $this->assertSame($term_meta, 'bar'); $this->assertEquals($num_queries, $wpdb->num_queries); }
/** @issue #824 */ function testTermWithNativeMetaFalse() { $tid = $this->factory->term->create(array('name' => 'News', 'taxonomy' => 'category')); add_term_meta($tid, 'foo', false); $term = new TimberTerm($tid); $this->assertEquals('', $term->meta('foo')); }
/** * @ticket 35137 */ public function test_meta_query_should_not_return_duplicates() { register_taxonomy('wptests_tax', 'post'); $terms = self::factory()->term->create_many(1, array('taxonomy' => 'wptests_tax')); add_term_meta($terms[0], 'foo', 'bar'); add_term_meta($terms[0], 'foo', 'ber'); $found = get_terms('wptests_tax', array('hide_empty' => false, 'meta_query' => array(array('key' => 'foo', 'value' => 'bur', 'compare' => '!=')), 'fields' => 'ids')); $this->assertEqualSets(array($terms[0]), $found); }
/** * Save a term's meta * * @param int $id Term ID * @param array $term_meta All meta to be saved (set value to null to delete) * @param bool $strict Whether to delete previously saved meta not in $term_meta * @param array $fields (optional) The array of fields and their options, for further processing with * * @return int Id of the term with the meta * * @since 2.0 */ public function save_term_meta($id, $term_meta = null, $strict = false, $fields = array()) { if (!function_exists('get_term_meta')) { return $id; } $simple_tableless_objects = PodsForm::simple_tableless_objects(); $conflicted = pods_no_conflict_check('taxonomy'); if (!$conflicted) { pods_no_conflict_on('taxonomy'); } if (!is_array($term_meta)) { $term_meta = array(); } $id = (int) $id; $meta = get_term_meta($id); foreach ($meta as $k => $value) { if (is_array($value) && 1 == count($value)) { $meta[$k] = current($value); } } foreach ($term_meta as $meta_key => $meta_value) { if (null === $meta_value || $strict && '' === $term_meta[$meta_key]) { $old_meta_value = ''; if (isset($meta[$meta_key])) { $old_meta_value = $meta[$meta_key]; } delete_term_meta($id, $meta_key, $old_meta_value); } else { $simple = false; if (isset($fields[$meta_key])) { $field_data = $fields[$meta_key]; $simple = 'pick' == $field_data['type'] && in_array(pods_var('pick_object', $field_data), $simple_tableless_objects); } if ($simple) { delete_term_meta($id, $meta_key); update_term_meta($id, '_pods_' . $meta_key, $meta_value); if (!is_array($meta_value)) { $meta_value = array($meta_value); } foreach ($meta_value as $value) { add_term_meta($id, $meta_key, $value); } } else { update_term_meta($id, $meta_key, $meta_value); } } } if ($strict) { foreach ($meta as $meta_key => $meta_value) { if (!isset($term_meta[$meta_key])) { delete_term_meta($id, $meta_key, $meta_value); } } } if (!$conflicted) { pods_no_conflict_off('taxonomy'); } return $id; }
/** * Duplicate all meta from one term to the new one when it is split. * * For one reason or another, the initial design of this termmeta plugin stores * meta against a term ID, rather than term_taxonomy_id, this was an incorrect * design decision, however we now have to handle the backwards compatibility. * * If a shared term is split between two taxonomies, there is no way to determine what * meta entries in the meta table are tied to which taxonomy's term. So, the only * reliable solution is to duplicate all meta from the old term id to the new one, ensuring * the new term has any potential meta it owns. * * @param int $old_term_id * @param int $new_term_id */ function hm_duplicate_meta_on_split_term($old_term_id, $new_term_id) { $meta = get_metadata('term', $old_term_id); foreach ($meta as $meta_key => $values) { foreach ($values as $value) { $value = maybe_unserialize($value); add_term_meta($new_term_id, $meta_key, $value); } } }
public function create($tax_id, $meta_key, $value, $unique = false) { return add_term_meta($tax_id, $meta_key, $value, $unique); }
/** * @ticket 34626 */ public function test_term_meta_should_be_deleted_when_term_is_deleted() { $t = self::factory()->term->create(array('taxonomy' => 'wptests_tax')); add_term_meta($t, 'foo', 'bar'); add_term_meta($t, 'foo1', 'bar'); $this->assertSame('bar', get_term_meta($t, 'foo', true)); $this->assertSame('bar', get_term_meta($t, 'foo1', true)); $this->assertTrue(wp_delete_term($t, 'wptests_tax')); $this->assertSame('', get_term_meta($t, 'foo', true)); $this->assertSame('', get_term_meta($t, 'foo1', true)); }
/** * Callback to add term meta for the given term ID and current taxonomy. * * @see add_term_meta(). * @see Fieldmanager_Util_Term_Meta::add_term_meta() (Deprecated). */ protected function add_data($term_id, $meta_key, $meta_value, $unique = false) { if ($this->use_fm_meta) { return fm_add_term_meta($term_id, $this->current_taxonomy, $meta_key, $meta_value, $unique); } else { return add_term_meta($term_id, $meta_key, $meta_value, $unique); } }
/** * @ticket 10142 */ public function test_meta_query() { register_taxonomy('wptests_tax', 'post'); $terms = self::factory()->term->create_many(5, array('taxonomy' => 'wptests_tax')); add_term_meta($terms[0], 'foo', 'bar'); add_term_meta($terms[1], 'foo', 'bar'); add_term_meta($terms[2], 'foo', 'baz'); add_term_meta($terms[3], 'foob', 'ar'); $p = self::factory()->post->create(); wp_set_object_terms($p, $terms, 'wptests_tax'); $found = wp_get_object_terms($p, 'wptests_tax', array('meta_query' => array(array('key' => 'foo', 'value' => 'bar')))); $this->assertEqualSets(array($terms[0], $terms[1]), wp_list_pluck($found, 'term_id')); }
/** * Upgrade the database to version 2209. * * @since 2.2.6 * * @uses genesis_update_settings() Merges new settings with old settings and pushes them into the database. * @uses genesis_get_option() Get theme setting value. */ function genesis_upgrade_2209() { $term_meta = get_option('genesis-term-meta'); foreach ((array) $term_meta as $term_id => $meta) { foreach ((array) $meta as $key => $value) { add_term_meta($term_id, $key, $value); } } //* Update Settings genesis_update_settings(array('theme_version' => '2.2.6', 'db_version' => '2209')); }
/** * Add new metadata. * * @param mixed $value New value to be saved to the database * @return mixed */ public function add_raw_value($value) { return add_term_meta($this->object_id, $this->meta_key, $value, $this->is_single); }
public function save($term_id) { foreach ($this->fields as $id => $field) { if ($field) { add_term_meta($term_id, MI_PREFIX . $id, $_POST[$id], true) or update_term_meta($term_id, MI_PREFIX . $id, $_POST[$id], get_term_meta($term_id, MI_PREFIX . $id, true)); } } }