function delete_terms($attribute_name, $term_taxonomy_id, $parent_id, $meta_data) { global $wpdb; $select_results = $wpdb->get_results("select p.ID as ID from {$wpdb->prefix}posts as p where p.post_parent = {$parent_id} "); $rows_child_ids = $wpdb->num_rows; $ids = array(); if ($rows_child_ids > 0) { foreach ($select_results as $select_result) { $ids[] = $select_result->ID; } $child_ids = implode(",", $ids); } $id = $term_taxonomy_id == 'all' ? implode(",", get_attribute_terms($attribute_name, $parent_id)) : $term_taxonomy_id; $delete_query = "DELETE FROM {$wpdb->prefix}term_relationships where object_id = {$parent_id} and term_taxonomy_id in ( {$id} )"; $delete_result = $wpdb->query($delete_query); if ($delete_result >= 1) { if ($term_taxonomy_id != 'all') { $taxonomy = "pa_" . $attribute_name; $meta_key = "attribute_" . $taxonomy; $select = "select t.slug from {$wpdb->prefix}terms as t join {$wpdb->prefix}term_taxonomy as tt on (t.term_id = tt.term_id) where tt.term_taxonomy_id = {$term_taxonomy_id} and tt.taxonomy = '{$taxonomy}' "; $select_output = $wpdb->get_row($select); $slug = $select_output->slug; if ($rows_child_ids > 0) { $update_query = "UPDATE {$wpdb->prefix}postmeta as pm SET pm.meta_value = '' where pm.meta_key = '{$meta_key}' and pm.meta_value = '{$slug}' and pm.post_id in ( {$child_ids} )"; $update_result = $wpdb->query($update_query); } $count_result = $wpdb->get_row("select count(*) as count from {$wpdb->prefix}term_relationships as tr join {$wpdb->prefix}term_taxonomy as tt on (tr.term_taxonomy_id = tt.term_taxonomy_id) where tt.taxonomy = '{$taxonomy}' and tr.object_id = {$parent_id} "); $count = $count_result->count; } // $count < 1 means not a single term exists for that attribute so it should be removed if ($count < 1 || $term_taxonomy_id == 'all') { remove_attribute($parent_id, $attribute_name, $child_ids, $meta_data); } } }
public function remove_attribute($tag = 'body', $attribute_name) { $this->set_attributes($tag, remove_attribute($this->get_attributes($tag), $attribute_name)); }
/** * Merges the existing attributes with the new ones * * @param array|string $attributes Array of attribute 'name' => 'value' pairs * or HTML attribute string * @param array|string $attributes Array of attribute 'name' => 'value' pairs * or HTML attribute string * * @return string A string containing merged attributes */ function merge_attributes_and_classes($attributes, $extra_attributes) { $attributes = prepare_attributes($attributes); $extra_attributes = prepare_attributes($extra_attributes); $class_extra = get_attribute($extra_attributes, 'class'); $attributes = add_class($attributes, get_attribute($extra_attributes, 'class')); $extra_attributes = remove_attribute($extra_attributes, 'class'); return merge_attributes($attributes, $extra_attributes); }