function hocwp_term_delete_meta($term_id, $meta_key, $meta_value = '', $delete_all = false) { $version = hocwp_get_wp_version(); if (version_compare($version, '4.4', '>=')) { return delete_term_meta($term_id, $meta_key, $meta_value); } return delete_metadata('term', $term_id, $meta_value, $meta_value, $delete_all); }
function fsi_term_meta_replace($term_id, $data) { $meta_keys = array_keys(get_term_meta($term_id)); foreach ($meta_keys as $meta_key) { delete_term_meta($term_id, $meta_key); } fsi_term_meta_update($term_id, $data); }
public function delete_raw_value($value = '') { $action = $this->field->get_definition()->get_is_repetitive() ? 'delete_repetitive' : 'delete'; do_action("wpcf_termeta_before_{$action}", $this->field); $result = delete_term_meta($this->object_id, $this->meta_key, $value); do_action("wpcf_termmeta_after_{$action}", $this->field); return $result; }
function handle_delete_taxonomy_term($term, $tt_id) { require_once "taxonomy-metadata.php"; $meta_to_remove = get_term_meta($term, ''); if (is_array($meta_to_remove) && count($meta_to_remove) > 0) { foreach ($meta_to_remove as $meta_key => $meta) { delete_term_meta($term, $meta_key); } } }
/** * Delete all field values! * * @return bool */ public function delete_all_fields() { global $wpdb; $meta_key = $this->get_meta_key(); $termmeta_records = $wpdb->get_results($wpdb->prepare("SELECT term_id FROM {$wpdb->termmeta} WHERE meta_key = %s", $meta_key)); // Delete one by one because we (probably) want all the WP hooks to fire. foreach ($termmeta_records as $termmeta) { delete_term_meta($termmeta->term_id, $meta_key); } return true; }
public function tearDown() { if (_fm_phpunit_is_wp_at_least(4.4)) { $meta = get_term_meta($this->term_id); foreach ($meta as $key => $value) { delete_term_meta($this->term_id, $key); } } if (get_current_user_id() != $this->current_user) { wp_delete_user(get_current_user_id()); } wp_set_current_user($this->current_user); }
/** * Delete settings, data and metadata cache. * * ## OPTIONS * * <what> * : The type of data to be removed. Supported: all|settings|postdata|userdata|termdata|cache * * [--assume-yes] * : Run in non interactive mode. * * ## EXAMPLES * * wp amt clean all * wp amt clean settings * wp amt clean postdata * wp amt clean userdata * wp amt clean termdata * wp amt clean cache * wp amt clean cache --assume-yes * * @synopsis <all|settings|postdata|userdata|termdata|cache> [--assume-yes] */ function clean($args, $assoc_args) { list($what) = $args; if (!in_array($what, array('all', 'settings', 'postdata', 'userdata', 'termdata', 'cache'))) { WP_CLI::error('Invalid argument: ' . $what . ' (valid: all|settings|postdata|userdata|termdata|cache)'); } if ($assoc_args['assume-yes']) { WP_CLI::line(' '); WP_CLI::line('Running in non-interactive mode.'); WP_CLI::line('Proceeding with ' . $what . ' cleanup...'); } else { // Confirmation WP_CLI::line(' '); WP_CLI::line('This commands deletes Add-Meta-Tags data from the database.'); WP_CLI::line('This action is final and cannot be undone.'); WP_CLI::line(' '); echo 'Are you sure you want to do this? Type \'yes\' to continue: '; $handle = fopen('php://stdin', 'r'); $choice = fgets($handle); fclose($handle); if (trim($choice) != 'yes') { WP_CLI::line('Aborting...'); exit; } WP_CLI::line(' '); WP_CLI::line('Proceeding with ' . $what . ' cleanup...'); } // Delete AMT settings if ($what == 'settings' || $what == 'all') { delete_option('add_meta_tags_opts'); WP_CLI::line('Deleted settings.'); } elseif ($what == 'postdata' || $what == 'all') { $qr_args = array('numberposts' => -1, 'post_type' => 'any', 'post_status' => 'any', 'orderby' => 'id', 'order' => 'ASC', 'suppress_filters' => true); $posts_arr = get_posts($qr_args); $amt_post_fields = amt_get_post_custom_field_names(); foreach ($posts_arr as $post) { foreach ($amt_post_fields as $amt_post_field) { delete_post_meta($post->ID, $amt_post_field); } } WP_CLI::line('Deleted post custom fields.'); } elseif ($what == 'userdata' || $what == 'all') { $qr_args = array('orderby' => 'login', 'order' => 'ASC', 'fields' => 'all'); $users_arr = get_users($qr_args); $amt_user_fields = amt_get_user_custom_field_names(); foreach ($users_arr as $user) { foreach ($amt_user_fields as $amt_user_field) { delete_user_meta($user->ID, $amt_user_field); } } WP_CLI::line('Deleted user meta fields.'); } elseif ($what == 'termdata' || $what == 'all') { // Get taxonomies // Get the custom taxonomy names. // Arguments in order to retrieve all public custom taxonomies $tax_args = array('public' => true, '_builtin' => true); $tax_output = 'names'; // names or objects $tax_operator = 'and'; // 'and' or 'or' $taxonomies = get_taxonomies($tax_args, $tax_output, $tax_operator); // Get terms $qr_args = array('orderby' => 'id', 'order' => 'ASC', 'fields' => 'all'); $terms_arr = get_terms($taxonomies, $qr_args); // Iterate over our fields and export $amt_term_fields = amt_get_term_custom_field_names(); foreach ($terms_arr as $term) { foreach ($amt_term_fields as $amt_term_field) { delete_term_meta($term->term_id, $amt_term_field); } } WP_CLI::line('Deleted term meta fields.'); } elseif ($what == 'cache' || $what == 'all') { // Transients may not be cached in the database, but in a different storage backend. // So, here amt_delete_all_transient_metadata_cache() is not used. //$result = amt_delete_all_transient_metadata_cache(); //WP_CLI::line( sprintf('Deleted %d transient metadata cache entries.', $result) ); global $wpdb; // Get the current blog id. $blog_id = get_current_blog_id(); // Construct the options table name for the current blog $posts_table = $wpdb->get_blog_prefix($blog_id) . 'posts'; //var_dump($posts_table); // Construct SQL query that fetched the post IDs. $sql = "SELECT ID FROM {$posts_table} WHERE post_status = 'publish'"; // Get number of cache entries $results = $wpdb->get_results($sql); foreach ($results as $post) { // Delete the metadata cache for this post object amt_delete_transient_cache_for_post(absint($post->ID)); } WP_CLI::line(sprintf('Force purged cached metadata of %d published post objects.', count($results))); } WP_CLI::success('Data clean up complete.'); }
/** * Save the image uploaded * @param string $term_id term slug */ function impress_agents_save_term_image($term_id) { if (!isset($_POST['impa_term_image_nonce']) || !wp_verify_nonce($_POST['impa_term_image_nonce'], basename(__FILE__))) { return; } $old_image = $this->impress_agents_get_term_image($term_id); $new_image = isset($_POST['impa-term-image']) ? $_POST['impa-term-image'] : ''; if ($old_image && '' === $new_image) { delete_term_meta($term_id, 'impa_term_image'); } else { if ($old_image !== $new_image) { update_term_meta($term_id, 'impa_term_image', $new_image); } } return $term_id; }
public function test_deleting_term_meta_should_bust_get_terms_cache() { $terms = self::factory()->term->create_many(2, array('taxonomy' => 'wptests_tax')); add_term_meta($terms[0], 'foo', 'bar'); add_term_meta($terms[1], 'foo', 'bar'); // Prime cache. $found = get_terms('wptests_tax', array('hide_empty' => false, 'fields' => 'ids', 'meta_query' => array(array('key' => 'foo', 'value' => 'bar')))); $this->assertEqualSets(array($terms[0], $terms[1]), $found); delete_term_meta($terms[1], 'foo', 'bar'); $found = get_terms('wptests_tax', array('hide_empty' => false, 'fields' => 'ids', 'meta_query' => array(array('key' => 'foo', 'value' => 'bar')))); $this->assertEqualSets(array($terms[0]), $found); }
/** * 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 string $meta_value (default: '') * @param bool $deprecated (default: false) * @return bool */ function delete_woocommerce_term_meta($term_id, $meta_key, $meta_value = '', $deprecated = false) { return function_exists('delete_term_meta') ? delete_term_meta($term_id, $meta_key, $meta_value) : delete_metadata('woocommerce_term', $term_id, $meta_key, $meta_value); }
/** * @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); } } } }
/** * Display multiple input fields, one per language * * @param $term_id the term id * @param $tt_id the term taxonomy id * @param $taxonomy the term object * * @since 1.0 */ public function save_term($term_id, $tt_id, $taxonomy) { global $q_config; if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE || !current_user_can('edit_posts')) { // check permission return $term_id; } $term = get_term($term_id, $taxonomy); foreach ($q_config['enabled_languages'] as $lang) { $meta_name = $this->get_meta_key($lang); $meta_value = apply_filters('qts_validate_term_slug', $_POST["qts_{$lang}_slug"], $term, $lang); delete_term_meta($term_id, $meta_name); update_term_meta($term_id, $meta_name, $meta_value); } }
/** * Main Plugin Uninstall Handler * @since 0.1 * * Cleanup Tasks: * Delete our 'yikes_simple_taxonomy_ordering_options' stored options * Delete all 'tax_position' term meta created by this plugin */ // if uninstall not called from WordPress exit if (!defined('WP_UNINSTALL_PLUGIN')) { exit; } // Delete the taxonomy ordering options delete_option('yikes_simple_taxonomy_ordering_options'); // remove ALL 'tax_position' term meta created by this plugin $registered_taxonomies = get_taxonomies(); // loop over all registered taxonomies foreach ($registered_taxonomies as $taxonomy) { // get terms associated with this taxonomy $terms = get_terms($taxonomy, array('hide_empty' => false)); // if terms are set -- if ($terms) { // loop over site terms foreach ($terms as $term) { // delete 'tax_position' term meta delete_term_meta($term->term_id, 'tax_position'); } } } /* End Uninstall.php */
delete_term_meta($term_id, $ashu_feild['id']); } } } function save_taxonomy_metadata($term_id) { foreach ($this->ashu_feild as $ashu_feild) { if (isset($ashu_feild['id']) && $ashu_feild['id'] && isset($_POST[$ashu_feild['id']])) { if (!current_user_can('manage_categories')) { return; } $old_data = get_term_meta($term_id, $ashu_feild['id'], true); 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' || $ashu_feild['type'] == 'gallery') { $data = explode(',', $_POST[$ashu_feild['id']]); $data = array_filter($data); } elseif (in_array($ashu_feild['type'], array('open', 'close', 'title'))) { continue; } else { $data = htmlspecialchars($_POST[$ashu_feild['id']], ENT_QUOTES, "UTF-8"); } if ($data == "") { delete_term_meta($term_id, $ashu_feild['id'], $data); } else { update_term_meta($term_id, $ashu_feild['id'], $data);
function action_save_category_form_fields($term_id) { $old_usergroups = get_term_meta($term_id, 'usergroups', true); $new_usergroups = isset($_POST['category_usergroups']) ? $_POST['category_usergroups'] : ''; if ($new_usergroups === '') { delete_term_meta($term_id, 'usergroups'); } else { update_term_meta($term_id, 'usergroups', $new_usergroups); } }
/** * Display multiple input fields, one per language * * @param $term_id the term id * @param $tt_id the term taxonomy id * @param $taxonomy the term object * * @since 1.0 */ public function save_term($term_id, $tt_id, $taxonomy) { $cur_screen = get_current_screen(); if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE || !current_user_can('edit_posts') || isset($cur_screen) && $cur_screen->id === "nav-menus") { return $term_id; } $term = get_term($term_id, $taxonomy); foreach ($this->get_enabled_languages() as $lang) { $meta_name = $this->get_meta_key($lang); //43LC: when at the post edit screen and creating a new tag // the $slug comes from $_POST with the value of the post slug, // not with the term slug. if ($_POST['action'] == "editpost") { // so we use the slug wp gave it $term_slug = $term->slug; } else { // otherwise, its the edit term screen $term_slug = $_POST["qts_{$lang}_slug"]; } $meta_value = apply_filters('qts_validate_term_slug', $term_slug, $term, $lang); delete_term_meta($term_id, $meta_name); update_term_meta($term_id, $meta_name, $meta_value); } }
public function delete_taxonomy($term_id) { $taxonomy = cs_get_var('taxonomy'); if (!empty($taxonomy)) { foreach ($this->options as $request_value) { if ($taxonomy == $request_value['taxonomy']) { $request_key = $request_value['id']; delete_term_meta($term_id, $request_key); } } } }
/** * Updates meta value * * Note: If the key is private, an underscore "_" will be appended to the key before storing * * @see https://developer.wordpress.org/reference/functions/delete_term_meta/ * @see https://developer.wordpress.org/reference/functions/update_term_meta/ * @see https://developer.wordpress.org/reference/functions/clean_term_cache/ * * @uses WordPress delete_term_meta() * @uses WordPress update_term_meta() * @uses WordPress clean_term_cache() * * @access public * * @since 0.1.0 * * @param int $term_id Term ID. * @param string $taxonomy The taxonomy for the term. * @param mixed $meta_value The value to be updated. * @param bool $clean_cache Whether to clean the term cache. * * @return void|null If nonce isn't set. */ public function set_term_meta($term_id = 0, $taxonomy = '', $meta_value = '', $clean_cache = false) { if (empty($meta_value)) { delete_term_meta($term_id, $this->meta_key); } else { update_term_meta($term_id, $this->meta_key, $meta_value); } if (true === $clean_cache) { clean_term_cache($term_id, $taxonomy); } }
/** * Callback to delete term meta for the given term ID and current taxonomy. * * @see delete_term_meta(). * @see Fieldmanager_Util_Term_Meta::delete_term_meta() (Deprecated). */ protected function delete_data($term_id, $meta_key, $meta_value = '') { if ($this->use_fm_meta) { return fm_delete_term_meta($term_id, $this->current_taxonomy, $meta_key, $meta_value); } else { return delete_term_meta($term_id, $meta_key, $meta_value); } }
public function SetMultipleOfForCategory($category_id, $multiple_of) { $multiple_of = intval($multiple_of); if ($multiple_of) { update_term_meta($category_id, 'cat_multiple_of', $multiple_of); } else { delete_term_meta($category_id, 'cat_multiple_of'); } }
function save($term_id) { // Verify nonce if (!isset($_POST['termMetaBox_nonce']) || !wp_verify_nonce($_POST['termMetaBox_nonce'], basename(__FILE__))) { return; } // Check permissions if (!current_user_can('manage_categories')) { return; } // Validate fields before updating // If there is no validate in the array, nothing will save foreach ($this->_termMetaBox['fields'] as $field) { if (in_array($field['type'], ['multitext', 'multicheck'])) { foreach ($field['options'] as $option) { $old = get_term_meta($term_id, $option['id'], true); $new = isset($_POST[$option['id']]) ? $field['validate']($_POST[$option['id']]) : ''; if ($field['validate'] != '') { if ($new && $new != $old || $new === '0') { update_term_meta($term_id, $option['id'], $new); } elseif ('' == $new && $old || $old === '0') { delete_term_meta($term_id, $option['id'], $old); } } } } else { $old = get_term_meta($term_id, $field['id'], true); $new = isset($_POST[$field['id']]) ? $field['validate']($_POST[$field['id']]) : ''; if ($field['validate'] != '') { if ($new && $new != $old || $new === '0') { update_term_meta($term_id, $field['id'], $new); } elseif ('' == $new && $old || $old === '0') { delete_term_meta($term_id, $field['id'], $old); } } } } }
/** * 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); } } }
/** * Does the sweeping/cleaning up * * @since 1.0.0 * * @access public * @param string $name * @return string Processed message */ public function sweep($name) { global $wpdb; $message = ''; switch ($name) { case 'revisions': $query = $wpdb->get_col($wpdb->prepare("SELECT ID FROM {$wpdb->posts} WHERE post_type = %s", 'revision')); if ($query) { foreach ($query as $id) { wp_delete_post_revision(intval($id)); } $message = sprintf(__('%s Revisions Processed', 'wp-sweep'), number_format_i18n(sizeof($query))); } break; case 'auto_drafts': $query = $wpdb->get_col($wpdb->prepare("SELECT ID FROM {$wpdb->posts} WHERE post_status = %s", 'auto-draft')); if ($query) { foreach ($query as $id) { wp_delete_post(intval($id), true); } $message = sprintf(__('%s Auto Drafts Processed', 'wp-sweep'), number_format_i18n(sizeof($query))); } break; case 'deleted_posts': $query = $wpdb->get_col($wpdb->prepare("SELECT ID FROM {$wpdb->posts} WHERE post_status = %s", 'trash')); if ($query) { foreach ($query as $id) { wp_delete_post($id, true); } $message = sprintf(__('%s Deleted Posts Processed', 'wp-sweep'), number_format_i18n(sizeof($query))); } break; case 'unapproved_comments': $query = $wpdb->get_col($wpdb->prepare("SELECT comment_ID FROM {$wpdb->comments} WHERE comment_approved = %s", '0')); if ($query) { foreach ($query as $id) { wp_delete_comment(intval($id), true); } $message = sprintf(__('%s Unapproved Comments Processed', 'wp-sweep'), number_format_i18n(sizeof($query))); } break; case 'spam_comments': $query = $wpdb->get_col($wpdb->prepare("SELECT comment_ID FROM {$wpdb->comments} WHERE comment_approved = %s", 'spam')); if ($query) { foreach ($query as $id) { wp_delete_comment(intval($id), true); } $message = sprintf(__('%s Spam Comments Processed', 'wp-sweep'), number_format_i18n(sizeof($query))); } break; case 'deleted_comments': $query = $wpdb->get_col($wpdb->prepare("SELECT comment_ID FROM {$wpdb->comments} WHERE (comment_approved = %s OR comment_approved = %s)", 'trash', 'post-trashed')); if ($query) { foreach ($query as $id) { wp_delete_comment(intval($id), true); } $message = sprintf(__('%s Trash Comments Processed', 'wp-sweep'), number_format_i18n(sizeof($query))); } break; case 'transient_options': $query = $wpdb->get_col($wpdb->prepare("SELECT option_name FROM {$wpdb->options} WHERE option_name LIKE(%s)", '%_transient_%')); if ($query) { foreach ($query as $option_name) { if (strpos($option_name, '_site_transient_') !== false) { delete_site_transient(str_replace('_site_transient_', '', $option_name)); } else { delete_transient(str_replace('_transient_', '', $option_name)); } } $message = sprintf(__('%s Transient Options Processed', 'wp-sweep'), number_format_i18n(sizeof($query))); } break; case 'orphan_postmeta': $query = $wpdb->get_results("SELECT post_id, meta_key FROM {$wpdb->postmeta} WHERE post_id NOT IN (SELECT ID FROM {$wpdb->posts})"); if ($query) { foreach ($query as $meta) { $post_id = intval($meta->post_id); if ($post_id === 0) { $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->postmeta} WHERE post_id = %d AND meta_key = %s", $post_id, $meta->meta_key)); } else { delete_post_meta($post_id, $meta->meta_key); } } $message = sprintf(__('%s Orphaned Post Meta Processed', 'wp-sweep'), number_format_i18n(sizeof($query))); } break; case 'orphan_commentmeta': $query = $wpdb->get_results("SELECT comment_id, meta_key FROM {$wpdb->commentmeta} WHERE comment_id NOT IN (SELECT comment_ID FROM {$wpdb->comments})"); if ($query) { foreach ($query as $meta) { $comment_id = intval($meta->comment_id); if ($comment_id === 0) { $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->commentmeta} WHERE comment_id = %d AND meta_key = %s", $comment_id, $meta->meta_key)); } else { delete_comment_meta($comment_id, $meta->meta_key); } } $message = sprintf(__('%s Orphaned Comment Meta Processed', 'wp-sweep'), number_format_i18n(sizeof($query))); } break; case 'orphan_usermeta': $query = $wpdb->get_results("SELECT user_id, meta_key FROM {$wpdb->usermeta} WHERE user_id NOT IN (SELECT ID FROM {$wpdb->users})"); if ($query) { foreach ($query as $meta) { $user_id = intval($meta->user_id); if ($user_id === 0) { $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->usermeta} WHERE user_id = %d AND meta_key = %s", $user_id, $meta->meta_key)); } else { delete_user_meta($user_id, $meta->meta_key); } } $message = sprintf(__('%s Orphaned User Meta Processed', 'wp-sweep'), number_format_i18n(sizeof($query))); } break; case 'orphan_termmeta': $query = $wpdb->get_results("SELECT term_id, meta_key FROM {$wpdb->termmeta} WHERE term_id NOT IN (SELECT term_id FROM {$wpdb->terms})"); if ($query) { foreach ($query as $meta) { $term_id = intval($meta->term_id); if ($term_id === 0) { $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->termmeta} WHERE term_id = %d AND meta_key = %s", $term_id, $meta->meta_key)); } else { delete_term_meta($term_id, $meta->meta_key); } } $message = sprintf(__('%s Orphaned Term Meta Processed', 'wp-sweep'), number_format_i18n(sizeof($query))); } break; case 'orphan_term_relationships': $query = $wpdb->get_results("SELECT tr.object_id, tr.term_taxonomy_id, tt.term_id, tt.taxonomy FROM {$wpdb->term_relationships} AS tr INNER JOIN {$wpdb->term_taxonomy} AS tt ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE tt.taxonomy NOT IN ('" . implode('\',\'', $this->get_excluded_taxonomies()) . "') AND tr.object_id NOT IN (SELECT ID FROM {$wpdb->posts})"); if ($query) { foreach ($query as $tax) { $wp_remove_object_terms = wp_remove_object_terms(intval($tax->object_id), intval($tax->term_id), $tax->taxonomy); if ($wp_remove_object_terms !== true) { $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->term_relationships} WHERE object_id = %d AND term_taxonomy_id = %d", $tax->object_id, $tax->term_taxonomy_id)); } } $message = sprintf(__('%s Orphaned Term Relationships Processed', 'wp-sweep'), number_format_i18n(sizeof($query))); } break; case 'unused_terms': $query = $wpdb->get_results($wpdb->prepare("SELECT tt.term_taxonomy_id, t.term_id, tt.taxonomy FROM {$wpdb->terms} AS t INNER JOIN {$wpdb->term_taxonomy} AS tt ON t.term_id = tt.term_id WHERE tt.count = %d AND t.term_id NOT IN (" . implode(',', $this->get_excluded_termids()) . ")", 0)); if ($query) { $check_wp_terms = false; foreach ($query as $tax) { if (taxonomy_exists($tax->taxonomy)) { wp_delete_term(intval($tax->term_id), $tax->taxonomy); } else { $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->term_taxonomy} WHERE term_taxonomy_id = %d", intval($tax->term_taxonomy_id))); $check_wp_terms = true; } } // We need this for invalid taxonomies if ($check_wp_terms) { $wpdb->get_results("DELETE FROM {$wpdb->terms} WHERE term_id NOT IN (SELECT term_id FROM {$wpdb->term_taxonomy})"); } $message = sprintf(__('%s Unused Terms Processed', 'wp-sweep'), number_format_i18n(sizeof($query))); } break; case 'duplicated_postmeta': $query = $wpdb->get_results($wpdb->prepare("SELECT GROUP_CONCAT(meta_id ORDER BY meta_id DESC) AS ids, post_id, COUNT(*) AS count FROM {$wpdb->postmeta} GROUP BY post_id, meta_key, meta_value HAVING count > %d", 1)); if ($query) { foreach ($query as $meta) { $ids = array_map('intval', explode(',', $meta->ids)); array_pop($ids); $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->postmeta} WHERE meta_id IN (" . implode(',', $ids) . ") AND post_id = %d", intval($meta->post_id))); } $message = sprintf(__('%s Duplicated Post Meta Processed', 'wp-sweep'), number_format_i18n(sizeof($query))); } break; case 'duplicated_commentmeta': $query = $wpdb->get_results($wpdb->prepare("SELECT GROUP_CONCAT(meta_id ORDER BY meta_id DESC) AS ids, comment_id, COUNT(*) AS count FROM {$wpdb->commentmeta} GROUP BY comment_id, meta_key, meta_value HAVING count > %d", 1)); if ($query) { foreach ($query as $meta) { $ids = array_map('intval', explode(',', $meta->ids)); array_pop($ids); $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->commentmeta} WHERE meta_id IN (" . implode(',', $ids) . ") AND comment_id = %d", intval($meta->comment_id))); } $message = sprintf(__('%s Duplicated Comment Meta Processed', 'wp-sweep'), number_format_i18n(sizeof($query))); } break; case 'duplicated_usermeta': $query = $wpdb->get_results($wpdb->prepare("SELECT GROUP_CONCAT(umeta_id ORDER BY umeta_id DESC) AS ids, user_id, COUNT(*) AS count FROM {$wpdb->usermeta} GROUP BY user_id, meta_key, meta_value HAVING count > %d", 1)); if ($query) { foreach ($query as $meta) { $ids = array_map('intval', explode(',', $meta->ids)); array_pop($ids); $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->usermeta} WHERE umeta_id IN (" . implode(',', $ids) . ") AND user_id = %d", intval($meta->user_id))); } $message = sprintf(__('%s Duplicated User Meta Processed', 'wp-sweep'), number_format_i18n(sizeof($query))); } break; case 'duplicated_termmeta': $query = $wpdb->get_results($wpdb->prepare("SELECT GROUP_CONCAT(meta_id ORDER BY meta_id DESC) AS ids, term_id, COUNT(*) AS count FROM {$wpdb->termmeta} GROUP BY term_id, meta_key, meta_value HAVING count > %d", 1)); if ($query) { foreach ($query as $meta) { $ids = array_map('intval', explode(',', $meta->ids)); array_pop($ids); $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->termmeta} WHERE meta_id IN (" . implode(',', $ids) . ") AND term_id = %d", intval($meta->term_id))); } $message = sprintf(__('%s Duplicated Term Meta Processed', 'wp-sweep'), number_format_i18n(sizeof($query))); } break; case 'optimize_database': $query = $wpdb->get_col('SHOW TABLES'); if ($query) { $tables = implode(',', $query); $wpdb->query("OPTIMIZE TABLE {$tables}"); $message = sprintf(__('%s Tables Processed', 'wp-sweep'), number_format_i18n(sizeof($query))); } break; case 'oembed_postmeta': $query = $wpdb->get_results($wpdb->prepare("SELECT post_id, meta_key FROM {$wpdb->postmeta} WHERE meta_key LIKE(%s)", '%_oembed_%')); if ($query) { foreach ($query as $meta) { $post_id = intval($meta->post_id); if ($post_id === 0) { $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->postmeta} WHERE post_id = %d AND meta_key = %s", $post_id, $meta->meta_key)); } else { delete_post_meta($post_id, $meta->meta_key); } } $message = sprintf(__('%s oEmbed Caches In Post Meta Processed', 'wp-sweep'), number_format_i18n(sizeof($query))); } break; } return apply_filters('wp_sweep_sweep', $message, $name); }
/** * Delete term meta data. * * Fires when a user deletes a term. * * @since 1.2.0 * * @param integer $term_id Term ID. * @param integer $tt_id Taxonomy Term ID. */ function genesis_term_meta_delete($term_id, $tt_id) { foreach (genesis_term_meta_defaults() as $key => $value) { delete_term_meta($term_id, $key); } }
function amt_taxonomy_extra_fields_save($term_id, $taxonomy_id) { /* Verify the nonce before proceeding. */ // Verify this came from the our screen and with proper authorization, // because save_post can be triggered at other times if (!isset($_POST['amt_noncename']) || !wp_verify_nonce($_POST['amt_noncename'], plugin_basename(AMT_PLUGIN_FILE))) { return; } // Get the Metadata metabox permissions (filtered) $metabox_permissions = amt_get_metadata_metabox_permissions(); // Global Metadata metabox permission check (can be user customized via filter). if (!current_user_can($metabox_permissions['global_metabox_capability'])) { return; } // Get the Add-Meta-Tags options. $options = amt_get_options(); // Check if the current user has permission to edit the post. if (!current_user_can('edit_published_posts')) { return; } // OK, we're authenticated: we need to find and save the data // // Sanitize user input // // Full metatags - We allow only <meta> elements. if (isset($_POST['amt_custom_full_metatags'])) { $full_metatags_value = esc_textarea(wp_kses(stripslashes($_POST['amt_custom_full_metatags']), amt_get_allowed_html_kses())); } // Image URL if (isset($_POST['amt_custom_image_url'])) { $image_url_value = amt_esc_id_or_url_notation(stripslashes($_POST['amt_custom_image_url'])); } // If a value has not been entered we try to delete existing data from the database // If the user has entered data, store it in the database. // Add-Meta-Tags custom field names $amt_full_metatags_field_name = '_amt_term_full_metatags'; $amt_image_url_field_name = '_amt_term_image_url'; // As an extra security measure, here we also check the user-defined per box // permissions before we save any data in the database. // per term full meta tags if ($options['metabox_term_enable_full_metatags'] == '1' && current_user_can($metabox_permissions['term_full_metatags_box_capability'])) { if (empty($full_metatags_value)) { delete_term_meta($term_id, $amt_full_metatags_field_name); } else { update_term_meta($term_id, $amt_full_metatags_field_name, $full_metatags_value); } } // Image URL if ($options['metabox_term_enable_image_url'] == '1' && current_user_can($metabox_permissions['term_image_url_box_capability'])) { if (empty($image_url_value)) { delete_term_meta($term_id, $amt_image_url_field_name); } else { update_term_meta($term_id, $amt_image_url_field_name, $image_url_value); } } }
/** * Handle saving our custom taxonomy term meta * * @param $term_id * @param $taxonomy */ function taxonomy_term_form_save($term_id) { // our requirements for saving: if (isset($_POST['taxonomy-term-image-save-form-nonce']) && wp_verify_nonce($_POST['taxonomy-term-image-save-form-nonce'], 'taxonomy-term-image-form-save') && isset($_POST['taxonomy']) && isset($_POST['taxonomy_term_image']) && $_POST['taxonomy'] == $this->taxonomy) { // get the term_meta and assign it the old_image $old_image = get_term_meta($term_id, $this->term_meta_key, true); // see if image data was submitted: // sanitize the data and save it as the new_image $new_image = isset($_POST['taxonomy_term_image']) ? absint($_POST['taxonomy_term_image']) : ''; if ($old_image && '' === $new_image) { delete_term_meta($term_id, $this->term_meta_key); } else { if ($old_image !== $new_image) { // save the term image data update_term_meta($term_id, $this->term_meta_key, $new_image); } } } }
/** * Save usermeta field. * * * @param type $value */ function termmeta_save($value = null) { // If $value null, look for submitted data if (is_null($value)) { $value = $this->get_submitted_data(); } /* * * * Since Types 1.2 * We completely rewrite meta. * It has no impact on frontend and covers a lot of cases * (e.g. user change mode from single to repetitive) */ delete_term_meta($this->term_id, $this->slug); // Save if (!empty($value) || is_numeric($value)) { // Trim if (is_string($value)) { $value = trim($value); } // Apply filters $_value = $this->_filter_save_termmeta_value($value); $_value = $this->_filter_save_value($_value); if (!empty($_value) || is_numeric($_value)) { // Save field $mid = update_term_meta($this->term_id, $this->slug, $_value); $this->_action_save($this->cf, $_value, $mid, $value); } } }
function mbdb_save_taxonomy_book_grid_description($term_id, $taxonomy) { if (!isset($_POST['mbdb_' . $taxonomy . '_grid_description_nonce']) || !wp_verify_nonce($_POST['mbdb_' . $taxonomy . '_grid_description_nonce'], basename(__FILE__))) { return; } $old_description = get_term_meta($term_id, 'mbdb_' . $taxonomy . '_book_grid_description', true); $new_description = isset($_POST['mbdb_' . $taxonomy . '_book_grid_description']) ? $_POST['mbdb_' . $taxonomy . '_book_grid_description'] : ''; if ($old_description && '' === $new_description) { delete_term_meta($term_id, 'mbdb_' . $taxonomy . '_book_grid_description'); } else { if ($old_description !== $new_description) { update_term_meta($term_id, 'mbdb_' . $taxonomy . '_book_grid_description', $new_description); } } $old_description_bottom = get_term_meta($term_id, 'mbdb_' . $taxonomy . '_book_grid_description_bottom', true); $new_description_bottom = isset($_POST['mbdb_' . $taxonomy . '_book_grid_description_bottom']) ? $_POST['mbdb_' . $taxonomy . '_book_grid_description_bottom'] : ''; if ($old_description_bottom && '' === $new_description_bottom) { delete_term_meta($term_id, 'mbdb_' . $taxonomy . '_book_grid_description_bottom'); } else { if ($old_description_bottom !== $new_description_bottom) { update_term_meta($term_id, 'mbdb_' . $taxonomy . '_book_grid_description_bottom', $new_description_bottom); } } }
/** * Set `meta_key` of a specific term * * @since 0.1.0 * * @param int $term_id * @param string $taxonomy * @param string $meta * @param bool $clean_cache */ public function set_meta($term_id = 0, $taxonomy = '', $meta = '', $clean_cache = false) { // No meta_key, so delete if (empty($meta)) { delete_term_meta($term_id, $this->meta_key); // Update meta_key value } else { update_term_meta($term_id, $this->meta_key, $meta); } // Maybe clean the term cache if (true === $clean_cache) { clean_term_cache($term_id, $taxonomy); } }
public function delete_value($tax_id, $meta_key, $value = null) { return delete_term_meta($tax_id, $meta_key, $value); }