/** * @ticket 34338 */ public function test_removal_should_delete_object_relationship_cache() { register_taxonomy('wptests_tax', 'post'); $p = self::factory()->post->create(); $t = self::factory()->term->create(array('taxonomy' => 'wptests_tax')); wp_set_object_terms($p, $t, 'wptests_tax'); // Pollute the cache. get_the_terms($p, 'wptests_tax'); wp_remove_object_terms($p, $t, 'wptests_tax'); $this->assertFalse(get_the_terms($p, 'wptests_tax')); }
public function test_deleted_terms_to_post_is_synced() { $anther_term = wp_insert_term('mouse', $this->taxonomy); wp_set_post_terms($this->post_id, array($anther_term['term_id']), $this->taxonomy, false); $anther_term_2 = wp_insert_term('cat', $this->taxonomy); wp_set_post_terms($this->post_id, array($anther_term_2['term_id']), $this->taxonomy, true); wp_remove_object_terms($this->post_id, array($anther_term_2['term_id']), $this->taxonomy); $this->client->do_sync(); $object_terms = get_the_terms($this->post_id, $this->taxonomy); $server_object_terms = $this->server_replica_storage->get_the_terms($this->post_id, $this->taxonomy); $server_object_terms = array_reverse($server_object_terms); $this->assertEquals($object_terms, $server_object_terms); }
function wp_update_nav_menu_item($menu_id, $menu_item_db_id, $args) { $menu_lang = $this->term_translations->lang_code_by_termid($menu_id); $trid = $this->post_translations->get_element_trid($menu_item_db_id); if (array_key_exists('menu-item-type', $args) && ($args['menu-item-type'] === 'post_type' || $args['menu-item-type'] === 'taxonomy') && array_key_exists('menu-item-object-id', $args) && $menu_id > 0) { $language_code_item = $args['menu-item-type'] === 'post_type' ? $this->post_translations->get_element_lang_code($args['menu-item-object-id']) : $this->term_translations->lang_code_by_termid($args['menu-item-object-id']); $language_code_item = $language_code_item ? $language_code_item : $this->sitepress->get_current_language(); if ($language_code_item !== $menu_lang) { wp_remove_object_terms((int) $menu_item_db_id, (int) $menu_id, 'nav_menu'); } } $language_code = isset($language_code_item) && $language_code_item ? $language_code_item : ($menu_lang ? $menu_lang : $this->sitepress->get_current_language()); $this->sitepress->set_element_language_details($menu_item_db_id, 'post_nav_menu_item', $trid, $language_code); }
public function force_change() { $productShelfs = wp_get_post_terms($_REQUEST['productid'], 'product_shelf'); if (!empty($productShelfs)) { foreach ($productShelfs as $productShelf) { wp_remove_object_terms($_REQUEST['productid'], $productShelf->term_id, 'product_shelf'); $subarray['shelf'][$productShelf->term_id]['name'] = $productShelf->name; $subarray['shelf'][$productShelf->term_id]['count'] = $productShelf->count; $subarray['shelf'][$productShelf->term_id]['id'] = $productShelf->term_id; } } wp_set_post_terms($_REQUEST['productid'], $_REQUEST['wcordersortupdateshelf'], 'product_shelf', false); echo '<h2>Shelf Updated. <small>Please Close This POPUP</small></h2>'; wp_die(); }
public function excludePreliminaryandMinorFromSearch($post_id) { // only do this for TOURS or CHAPTERS $post = get_post($post_id); $post_type = $post->post_type; if ($post_type == 'tours' or $post_type == 'chapters') { //nonce checks for the meta boxes have already occured... if (get_post_meta($post_id, 'mb_isPreliminaryTour', true) != 'ready_to_publish_tour' or get_post_meta($post_id, 'mb_isMajorMarket', true) != 'majorMarket' or get_post_meta($post_id, 'mb_isPartnerEvent', true) != true) { wp_set_object_terms($post_id, 'exclude-from-search', 'category', true); } if (get_post_meta($post_id, 'mb_isPreliminaryTour', true) == 'ready_to_publish_tour' or get_post_meta($post_id, 'mb_isMajorMarket', true) == 'majorMarket' or get_post_meta($post_id, 'mb_isPartnerEvent', true) == false) { wp_remove_object_terms($post_id, 'exclude-from-search', 'category', true); } } }
/** * Assign/unassign the sale category after post meta was updated. */ public function assign_sale_category($meta_id, $post_id, $meta_key, $meta_value) { if ($meta_key != '_price') { return; // do nothing, if the meta key is not _price } if (wp_get_post_parent_id($post_id)) { return; // bail if this is a variation } $product = wc_get_product($post_id); if ($product->is_on_sale()) { // product is on sale, let's assign the sale category wp_set_object_terms($post_id, $this->sale_category, 'product_cat', true); } else { // product is not on sale, let's remove the sale category wp_remove_object_terms($post_id, $this->sale_category, 'product_cat'); } }
/** * @ticket 15475 */ function test_wp_add_remove_object_terms() { $posts = self::$post_ids; $tags = self::factory()->tag->create_many(5); $tt = wp_add_object_terms($posts[0], $tags[1], 'post_tag'); $this->assertEquals(1, count($tt)); $this->assertEquals(array($tags[1]), wp_get_object_terms($posts[0], 'post_tag', array('fields' => 'ids'))); $three_tags = array($tags[0], $tags[1], $tags[2]); $tt = wp_add_object_terms($posts[1], $three_tags, 'post_tag'); $this->assertEquals(3, count($tt)); $this->assertEquals($three_tags, wp_get_object_terms($posts[1], 'post_tag', array('fields' => 'ids'))); $this->assertTrue(wp_remove_object_terms($posts[0], $tags[1], 'post_tag')); $this->assertFalse(wp_remove_object_terms($posts[0], $tags[0], 'post_tag')); $this->assertInstanceOf('WP_Error', wp_remove_object_terms($posts[0], $tags[1], 'non_existing_taxonomy')); $this->assertTrue(wp_remove_object_terms($posts[1], $three_tags, 'post_tag')); $this->assertEquals(0, count(wp_get_object_terms($posts[1], 'post_tag'))); foreach ($tags as $term_id) { $this->assertTrue(wp_delete_term($term_id, 'post_tag')); } foreach ($posts as $post_id) { $this->assertTrue((bool) wp_delete_post($post_id)); } }
function wpleads_remove_lead_from_list($list_id, $lead_id) { wp_remove_object_terms($lead_id, $list_id, 'wplead_list_category'); //build meta pair for list ids lead belongs to $wpleads_list_ids = get_post_meta($lead_id, 'wpleads_list_ids', true); if ($wpleads_list_ids) { //get array $wpleads_list_ids = json_decode($wpleads_list_ids, true); if (!is_array($wpleads_list_ids)) { $wpleads_list_ids = array(); } //clean delete_post_meta($lead_id, 'wpleads_list_ids'); //rebuild foreach ($wpleads_list_ids as $key => $value) { if ($value['ID'] == $list_id) { unset($wpleads_list_ids[$key]); } } //store $wpleads_list_ids = json_encode($wpleads_list_ids); $wpleads_list_ids = update_post_meta($lead_id, 'wpleads_list_ids', $wpleads_list_ids); } }
/** * Save module course on add/edit * * @since 1.8.0 * @param integer $module_id ID of module * @return void */ public function save_module_course($module_id) { // Get module's existing courses $args = array('post_type' => 'course', 'post_status' => array('publish', 'draft', 'future', 'private'), 'posts_per_page' => -1, 'tax_query' => array(array('taxonomy' => $this->taxonomy, 'field' => 'id', 'terms' => $module_id))); $courses = get_posts($args); // Remove module from existing courses if (isset($courses) && is_array($courses)) { foreach ($courses as $course) { wp_remove_object_terms($course->ID, $module_id, $this->taxonomy); } } // Add module to selected courses if (isset($_POST['module_courses']) && is_array($_POST['module_courses']) && count($_POST['module_courses']) > 0) { foreach ($_POST['module_courses'] as $k => $course_id) { wp_set_object_terms($course_id, $module_id, $this->taxonomy, true); } } }
/** * Save settings */ public function save() { global $current_section, $post; if ($current_section != '') { if (isset($_REQUEST['id'])) { $current_id = empty($_REQUEST['id']) ? '' : sanitize_title($_REQUEST['id']); switch ($current_section) { // With heirarchy case "property-type": case "commercial-property-type": case "location": // TODO: Validate (check for blank fields) if ($current_id == '') { // Adding new term // TODO: Check term doesn't exist already wp_insert_term($_POST[$_POST['taxonomy'] . '_name'], $_POST['taxonomy'], array('parent' => $_POST['parent_' . $_POST['taxonomy'] . '_id'])); // TODO: Check for errors returned from wp_insert_term() } else { // Editing term wp_update_term($current_id, $_POST['taxonomy'], array('name' => $_POST[$_POST['taxonomy'] . '_name'], 'parent' => $_POST['parent_' . $_POST['taxonomy'] . '_id'])); // TODO: Check for errors returned from wp_update_term() } break; // Without heirarchy // Without heirarchy case "availability": case "outside-space": case "parking": case "price-qualifier": case "sale-by": case "tenure": case "commercial-tenure": case "furnished": case "marketing-flag": // TODO: Validate (check for blank fields) if ($current_id == '') { // Adding new term // TODO: Check term doesn't exist already wp_insert_term($_POST[$_POST['taxonomy'] . '_name'], $_POST['taxonomy']); // TODO: Check for errors returned from wp_insert_term() } else { // Editing term wp_update_term($current_id, $_POST['taxonomy'], array('name' => $_POST[$_POST['taxonomy'] . '_name'])); // TODO: Check for errors returned from wp_update_term() } break; case "availability-delete": case "property-type-delete": case "commercial-property-type-delete": case "location-delete": case "parking-delete": case "price-qualifier-delete": case "sale-by-delete": case "tenure-delete": case "furnished-delete": case "marketing-flag-delete": if (isset($_POST['confirm_removal']) && $_POST['confirm_removal'] == '1') { $term_ids = explode("-", $current_id); foreach ($term_ids as $current_id) { // Update properties that have this taxonomy term set $query_args = array('post_type' => 'property', 'nopaging' => true, 'post_status' => array('pending', 'auto-draft', 'draft', 'private', 'publish', 'future', 'trash'), 'tax_query' => array(array('taxonomy' => $_POST['taxonomy'], 'field' => 'id', 'terms' => $current_id))); $property_query = new WP_Query($query_args); if ($property_query->have_posts()) { while ($property_query->have_posts()) { $property_query->the_post(); wp_remove_object_terms($post->ID, $current_id, $_POST['taxonomy']); // Re-assign to another term if (isset($_POST['reassign_to_' . $current_id]) && !empty($_POST['reassign_to_' . $current_id]) && $_POST['reassign_to_' . $current_id] != 'none') { $new_id = $_POST['reassign_to_' . $current_id]; wp_set_post_terms($post->ID, $new_id, $_POST['taxonomy'], TRUE); // TODO: Check for WP_ERROR } } } wp_reset_postdata(); if ($_POST['taxonomy'] == 'property_type' || $_POST['taxonomy'] == 'commercial_property_type' || $_POST['taxonomy'] == 'location') { $query_args = array('post_type' => 'contact', 'nopaging' => true, 'post_status' => array('pending', 'auto-draft', 'draft', 'private', 'publish', 'future', 'trash'), 'meta_query' => array(array('key' => '_contact_types', 'value' => 'applicant', 'compare' => 'LIKE'))); $applicant_query = new WP_Query($query_args); if ($applicant_query->have_posts()) { while ($applicant_query->have_posts()) { $applicant_query->the_post(); $num_applicant_profiles = get_post_meta(get_the_ID(), '_applicant_profiles', TRUE); if ($num_applicant_profiles == '') { $num_applicant_profiles = 0; } if ($num_applicant_profiles > 0) { for ($i = 0; $i < $num_applicant_profiles; ++$i) { $applicant_profile = get_post_meta(get_the_ID(), '_applicant_profile_' . $i, TRUE); if (isset($applicant_profile[$_POST['taxonomy'] . 's']) && is_array($applicant_profile[$_POST['taxonomy'] . 's']) && !empty($applicant_profile[$_POST['taxonomy'] . 's'])) { if (in_array($current_id, $applicant_profile[$_POST['taxonomy'] . 's'])) { // This profile has this term set unset($applicant_profile[$_POST['taxonomy'] . 's'][$current_id]); if (isset($_POST['reassign_to_' . $current_id]) && !empty($_POST['reassign_to_' . $current_id]) && $_POST['reassign_to_' . $current_id] != 'none') { $applicant_profile[$_POST['taxonomy'] . 's'][] = $_POST['reassign_to_' . $current_id]; $applicant_profile[$_POST['taxonomy'] . 's'] = array_unique($applicant_profile[$_POST['taxonomy'] . 's']); } $applicant_profile[$_POST['taxonomy'] . 's'] = array_values($applicant_profile[$_POST['taxonomy'] . 's']); update_post_meta(get_the_ID(), '_applicant_profile_' . $i, $applicant_profile); } } } } } } } wp_reset_postdata(); wp_delete_term($current_id, $_POST['taxonomy']); } } break; default: echo 'UNKNOWN CUSTOM FIELD'; } } else { // Nothing to save. Should always be an id set when editing custom fields. // Even blank ids dictate something is being added } } else { // Nothing to save. Should always be a section when editing custom fields } }
/** * Ajax handler allowing for the removal of a term from a post. * todo: handle the return of this in js. */ public static function wpml_remove_terms_from_post() { $translated_post_id = false; $terms = array(); $taxonomy = false; $arg_type = 'strings'; $result = false; if (isset($_POST['wpml_terms'])) { $terms = $_POST['wpml_terms']; } if (isset($_POST['wpml_arg_type'])) { $arg_type = $_POST['wpml_arg_type']; } if (isset($_POST['wpml_taxonomy'])) { $taxonomy = $_POST['wpml_taxonomy']; } if (isset($_POST['wpml_post_id'])) { $translated_post_id = $_POST['wpml_post_id']; } if ($arg_type == 'strings' && !empty($terms)) { $result = wp_remove_object_terms($translated_post_id, $terms, $taxonomy); } elseif ($arg_type == 'id' && !empty($terms)) { $result = wp_remove_object_terms($translated_post_id, array((int) $terms), $taxonomy); } wp_send_json_success($result); }
/** * Create Term and Taxonomy Relationships. * * Relates an object (post, link etc) to a term and taxonomy type. Creates the * term and taxonomy relationship if it doesn't already exist. Creates a term if * it doesn't exist (using the slug). * * A relationship means that the term is grouped in or belongs to the taxonomy. * A term has no meaning until it is given context by defining which taxonomy it * exists under. * * @since 2.3.0 * * @global wpdb $wpdb The WordPress database abstraction object. * * @param int $object_id The object to relate to. * @param array|int|string $terms A single term slug, single term id, or array of either term slugs or ids. * Will replace all existing related terms in this taxonomy. * @param string $taxonomy The context in which to relate the term to the object. * @param bool $append Optional. If false will delete difference of terms. Default false. * @return array|WP_Error Affected Term IDs. */ function wp_set_object_terms($object_id, $terms, $taxonomy, $append = false) { global $wpdb; $object_id = (int) $object_id; if (!taxonomy_exists($taxonomy)) { return new WP_Error('invalid_taxonomy', __('Invalid taxonomy')); } if (!is_array($terms)) { $terms = array($terms); } if (!$append) { $old_tt_ids = wp_get_object_terms($object_id, $taxonomy, array('fields' => 'tt_ids', 'orderby' => 'none')); } else { $old_tt_ids = array(); } $tt_ids = array(); $term_ids = array(); $new_tt_ids = array(); foreach ((array) $terms as $term) { if (!strlen(trim($term))) { continue; } if (!($term_info = term_exists($term, $taxonomy))) { // Skip if a non-existent term ID is passed. if (is_int($term)) { continue; } $term_info = wp_insert_term($term, $taxonomy); } if (is_wp_error($term_info)) { return $term_info; } $term_ids[] = $term_info['term_id']; $tt_id = $term_info['term_taxonomy_id']; $tt_ids[] = $tt_id; if ($wpdb->get_var($wpdb->prepare("SELECT term_taxonomy_id FROM {$wpdb->term_relationships} WHERE object_id = %d AND term_taxonomy_id = %d", $object_id, $tt_id))) { continue; } /** * Fires immediately before an object-term relationship is added. * * @since 2.9.0 * * @param int $object_id Object ID. * @param int $tt_id Term taxonomy ID. */ do_action('add_term_relationship', $object_id, $tt_id); $wpdb->insert($wpdb->term_relationships, array('object_id' => $object_id, 'term_taxonomy_id' => $tt_id)); /** * Fires immediately after an object-term relationship is added. * * @since 2.9.0 * * @param int $object_id Object ID. * @param int $tt_id Term taxonomy ID. */ do_action('added_term_relationship', $object_id, $tt_id); $new_tt_ids[] = $tt_id; } if ($new_tt_ids) { wp_update_term_count($new_tt_ids, $taxonomy); } if (!$append) { $delete_tt_ids = array_diff($old_tt_ids, $tt_ids); if ($delete_tt_ids) { $in_delete_tt_ids = "'" . implode("', '", $delete_tt_ids) . "'"; $delete_term_ids = $wpdb->get_col($wpdb->prepare("SELECT tt.term_id FROM {$wpdb->term_taxonomy} AS tt WHERE tt.taxonomy = %s AND tt.term_taxonomy_id IN ({$in_delete_tt_ids})", $taxonomy)); $delete_term_ids = array_map('intval', $delete_term_ids); $remove = wp_remove_object_terms($object_id, $delete_term_ids, $taxonomy); if (is_wp_error($remove)) { return $remove; } } } $t = get_taxonomy($taxonomy); if (!$append && isset($t->sort) && $t->sort) { $values = array(); $term_order = 0; $final_tt_ids = wp_get_object_terms($object_id, $taxonomy, array('fields' => 'tt_ids')); foreach ($tt_ids as $tt_id) { if (in_array($tt_id, $final_tt_ids)) { $values[] = $wpdb->prepare("(%d, %d, %d)", $object_id, $tt_id, ++$term_order); } } if ($values) { if (false === $wpdb->query("INSERT INTO {$wpdb->term_relationships} (object_id, term_taxonomy_id, term_order) VALUES " . join(',', $values) . " ON DUPLICATE KEY UPDATE term_order = VALUES(term_order)")) { return new WP_Error('db_insert_error', __('Could not insert term relationship into the database'), $wpdb->last_error); } } } wp_cache_delete($object_id, $taxonomy . '_relationships'); /** * Fires after an object's terms have been set. * * @since 2.8.0 * * @param int $object_id Object ID. * @param array $terms An array of object terms. * @param array $tt_ids An array of term taxonomy IDs. * @param string $taxonomy Taxonomy slug. * @param bool $append Whether to append new terms to the old terms. * @param array $old_tt_ids Old array of term taxonomy IDs. */ do_action('set_object_terms', $object_id, $terms, $tt_ids, $taxonomy, $append, $old_tt_ids); return $tt_ids; }
/** * Remove a term from a post. * * @param WP_REST_Request $request Full details about the request * @return WP_Error|null */ public function delete_item($request) { $post = get_post(absint($request['post_id'])); $term_id = absint($request['term_id']); $force = isset($request['force']) ? (bool) $request['force'] : false; // We don't support trashing for this type, error out if (!$force) { return new WP_Error('rest_trash_not_supported', __('Terms do not support trashing.'), array('status' => 501)); } $is_request_valid = $this->validate_request($request); if (is_wp_error($is_request_valid)) { return $is_request_valid; } $previous_item = $this->get_item($request); $remove = wp_remove_object_terms($post->ID, $term_id, $this->taxonomy); if (is_wp_error($remove)) { return $remove; } /** * Fires after a term is removed from a post via the REST API. * * @param array $previous_item The removed term data. * @param WP_Post $post The post the term was removed from. * @param WP_REST_Request $request The request sent to the API. */ do_action('rest_remove_term', $previous_item, $post, $request); return $previous_item; }
/** * Remove taxonomy terms on a BuddyPress object. * * @since BuddyPress (2.3.0) * * @see wp_remove_object_terms() for a full description of function and parameters. * * @param int $object_id Object ID. * @param string|array $terms Term or terms to remove. * @param string $taxonomy Taxonomy name. * * @return bool|WP_Error True on success, false or WP_Error on failure. */ function bp_remove_object_terms($object_id, $terms, $taxonomy) { $is_root_blog = bp_is_root_blog(); if (!$is_root_blog) { switch_to_blog(bp_get_root_blog_id()); } $retval = wp_remove_object_terms($object_id, $terms, $taxonomy); if (!$is_root_blog) { restore_current_blog(); } return $retval; }
public function removeFrom($bean) { $terms = $this->get(); if (!is_array($bean)) { $bean = array($bean); } foreach ($bean as $postID) { wp_remove_object_terms($postID, $terms, $this->name); } }
/** * Remove a post term. * * @param Term $term . * @return bool|WP_Error True on success, false or WP_Error on failure. */ public function remove_term($term) { return wp_remove_object_terms($this->get_id(), $term->get_id(), $term->get_taxonomy()); }
/** * Remove term(s) associated with a given object. * * * @global wpdb $wpdb WordPress database abstraction object. * * @param int $object_id The ID of the object from which the terms will be removed. * @param array|int|string $terms The slug(s) or ID(s) of the term(s) to remove. * @param array|string $taxonomy Taxonomy name. * @return bool|WP_Error True on success, false or WP_Error on failure. */ private static function wp_remove_object_terms($object_id, $terms, $taxonomy) { global $wpdb; // Remove notices in below 3.6 and support backwards compatibility if (function_exists('wp_remove_object_terms')) { return wp_remove_object_terms($object_id, $terms, $taxonomy); } $object_id = (int) $object_id; if (!taxonomy_exists($taxonomy)) { return new WP_Error('invalid_taxonomy', __('Invalid Taxonomy')); } if (!is_array($terms)) { $terms = array($terms); } $tt_ids = array(); foreach ((array) $terms as $term) { if (!strlen(trim($term))) { continue; } if (!($term_info = term_exists($term, $taxonomy))) { // Skip if a non-existent term ID is passed. if (is_int($term)) { continue; } } if (is_wp_error($term_info)) { return $term_info; } $tt_ids[] = $term_info['term_taxonomy_id']; } if ($tt_ids) { $in_tt_ids = "'" . implode("', '", $tt_ids) . "'"; /** * Fires immediately before an object-term relationship is deleted. * * @since 2.9.0 * * @param int $object_id Object ID. * @param array $tt_ids An array of term taxonomy IDs. */ do_action('delete_term_relationships', $object_id, $tt_ids); $deleted = $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->term_relationships} WHERE object_id = %d AND term_taxonomy_id IN ({$in_tt_ids})", $object_id)); /** * Fires immediately after an object-term relationship is deleted. * * @since 2.9.0 * * @param int $object_id Object ID. * @param array $tt_ids An array of term taxonomy IDs. */ do_action('deleted_term_relationships', $object_id, $tt_ids); wp_update_term_count($tt_ids, $taxonomy); return (bool) $deleted; } return false; }
public function remove_status($status_id = 0) { $update = wp_remove_object_terms($this->ID, (int) $status_id, self::STATUS_TAXONOMY); return $update; }
/** * @param $post_id * @param $taxonomy * @param bool $automatic_translation * Synchronizes a posts taxonomy term's languages with the posts language for all translations of the post. * */ public static function sync_post_and_taxonomy_terms_language($post_id, $taxonomy, $automatic_translation = false) { global $sitepress; $post = get_post($post_id); $post_type = $post->post_type; $post_trid = $sitepress->get_element_trid($post_id, 'post_' . $post_type); $post_translations = $sitepress->get_element_translations($post_trid, 'post_' . $post_type); $terms_from_original_post = wp_get_post_terms($post_id, $taxonomy); $is_original = true; if ($sitepress->get_original_element_id($post_id, 'post_' . $post_type) != $post_id) { $is_original = false; } foreach ($post_translations as $post_language => $translated_post) { $translated_post_id = $translated_post->element_id; $terms_from_translated_post = wp_get_post_terms($translated_post_id, $taxonomy); if ($is_original) { /** @var $iclTranslationManagement TranslationManagement */ global $iclTranslationManagement; $duplicates = $iclTranslationManagement->get_duplicates($post_id); if (in_array($translated_post_id, $duplicates)) { $terms = array_merge($terms_from_original_post, $terms_from_translated_post); } else { $terms = $terms_from_translated_post; } } else { $terms = $terms_from_translated_post; } foreach ((array) $terms as $term) { $term_original_tax_id = $term->term_taxonomy_id; $original_term_language_object = $sitepress->get_element_language_details($term_original_tax_id, 'tax_' . $term->taxonomy); if ($original_term_language_object && isset($original_term_language_object->language_code)) { $original_term_language = $original_term_language_object->language_code; } else { $original_term_language = $post_language; } if ($original_term_language != $post_language) { $term_trid = $sitepress->get_element_trid($term_original_tax_id, 'tax_' . $term->taxonomy); $translated_terms = $sitepress->get_element_translations($term_trid, 'tax_' . $term->taxonomy, false, false, true); $term_id = $term->term_id; wp_remove_object_terms($translated_post_id, (int) $term_id, $taxonomy); if (isset($translated_terms[$post_language])) { $term_in_correct_language = $translated_terms[$post_language]; } else { $term_in_correct_language = false; if ($automatic_translation) { $automatic_translation_args = array('lang_code' => $post_language, 'taxonomy' => $taxonomy, 'trid' => $term_trid, 'source_language' => $original_term_language); $term_in_correct_language = self::create_automatic_translation($automatic_translation_args); } if (!is_array($term_in_correct_language) || !isset($term_in_correct_language['term_id'])) { continue; } $term_in_correct_language = get_term($term_in_correct_language['term_id'], $taxonomy); } wp_set_post_terms($translated_post_id, array((int) $term_in_correct_language->term_id), $taxonomy, true); if (isset($term->term_taxonomy_id)) { wp_update_term_count($term->term_taxonomy_id, $taxonomy); } } wp_update_term_count($term_original_tax_id, $taxonomy); } self::sync_parent_child_relations($taxonomy, $post_language); } }
/** * @param $post_id * @param $taxonomy * Synchronizes a posts taxonomy term's languages with the posts language for all translations of the post. * */ public static function sync_post_and_taxonomy_terms_language($post_id, $taxonomy) { global $sitepress; $post = get_post($post_id); $post_type = $post->post_type; $post_trid = $sitepress->get_element_trid($post_id, 'post_' . $post_type); $post_translations = $sitepress->get_element_translations($post_trid, 'post_' . $post_type); $terms_from_original_post = wp_get_post_terms($post_id, $taxonomy); $is_original = true; if ($sitepress->get_original_element_id($post_id, 'post_' . $post_type) != $post_id) { $is_original = false; } foreach ($post_translations as $post_language => $translated_post) { $translated_post_id = $translated_post->element_id; if (!$translated_post_id) { continue; } $terms_from_translated_post = wp_get_post_terms($translated_post_id, $taxonomy); if ($is_original) { $duplicates = $sitepress->get_duplicates($post_id); if (in_array($translated_post_id, $duplicates)) { $terms = array_merge($terms_from_original_post, $terms_from_translated_post); } else { $terms = $terms_from_translated_post; } } else { $terms = $terms_from_translated_post; } foreach ((array) $terms as $term) { $term_original_tax_id = $term->term_taxonomy_id; $original_term_language_object = $sitepress->get_element_language_details($term_original_tax_id, 'tax_' . $term->taxonomy); if ($original_term_language_object && isset($original_term_language_object->language_code)) { $original_term_language = $original_term_language_object->language_code; } else { $original_term_language = $post_language; } if ($original_term_language != $post_language) { $term_trid = $sitepress->get_element_trid($term_original_tax_id, 'tax_' . $term->taxonomy); $translated_terms = $sitepress->get_element_translations($term_trid, 'tax_' . $term->taxonomy, false, false, true); $term_id = $term->term_id; wp_remove_object_terms($translated_post_id, (int) $term_id, $taxonomy); if (isset($translated_terms[$post_language])) { $term_in_correct_language = $translated_terms[$post_language]; wp_set_post_terms($translated_post_id, array((int) $term_in_correct_language->term_id), $taxonomy, true); } if (isset($term->term_taxonomy_id)) { wp_update_term_count($term->term_taxonomy_id, $taxonomy); } } wp_update_term_count($term_original_tax_id, $taxonomy); } } }
/** * Remove a term from a post. * * @param WP_REST_Request $request Full details about the request * @return WP_Error|null */ public function delete_item($request) { $post = get_post(absint($request['post_id'])); $term_id = absint($request['term_id']); $force = isset($request['force']) ? (bool) $request['force'] : false; // We don't support trashing for this type, error out if (!$force) { return new WP_Error('rest_trash_not_supported', __('Terms do not support trashing.'), array('status' => 501)); } $is_request_valid = $this->validate_request($request); if (is_wp_error($is_request_valid)) { return $is_request_valid; } $previous_item = $this->get_item($request); $remove = wp_remove_object_terms($post->ID, $term_id, $this->taxonomy); if (is_wp_error($remove)) { return $remove; } return $previous_item; }
private function delete_post_taxonomies($post) { $taxonomies = $this->getPostTaxonomies($post); foreach ($taxonomies as $taxonomy) { //Delete all terms only if taxonomy does exist on frontend //https://icanlocalize.basecamphq.com/projects/7393061-toolset/todo_items/187668009/comments $todelete = "new_tax_text_" . $taxonomy['name']; if (!isset($_POST[$todelete])) { continue; } //######################################################## if (count($taxonomy['terms']) > 0) { $delete = array(); foreach ($taxonomy['terms'] as $terms) { $delete[] = $terms['term_id']; } wp_remove_object_terms($post->ID, $delete, $taxonomy['name']); } } return $taxonomies; }
/** * Process group-doc unlinking requests. * Allows group mods & admins to remove docs from groups they moderate. * * @since 1.9.0 * * @param int $doc_id ID of the doc to remove from the group * @param int $group_id ID of the group the doc should be removed from * @return bool true if the term is removed */ function bp_docs_unlink_from_group($doc_id, $group_id = 0) { if ($group_id) { $term = bp_docs_get_group_term($group_id); } if (empty($doc_id) || empty($term)) { return false; } do_action('bp_docs_before_doc_unlink_from_group', $doc_id, $group_id, $term); $removed = wp_remove_object_terms($doc_id, $term, bp_docs_get_associated_item_tax_name()); // wp_remove_object_terms returns true on success, false or WP_Error on failure. $retval = $removed == true ? true : false; if ($removed) { do_action('bp_docs_doc_unlinked_from_group', $doc_id, $group_id, $term); } // If the doc is no longer associated with any group, make sure it doesn't become public. $assoc_group_id = bp_docs_get_associated_group_id($doc_id); if (empty($assoc_group_id)) { bp_docs_remove_group_related_doc_access_settings($doc_id); } // Recalculate the number of docs in the affected group. if ($retval) { bp_docs_update_doc_count($group_id, 'group'); } return $retval; }
/** * Remove a Doc from a Folder. * * @since 1.9 * * @param int $doc_id * @param int $folder_id * @return bool True on success, false on failure. */ function bp_docs_remove_doc_from_folder($doc_id, $folder_id) { $doc = get_post($doc_id); if (is_wp_error($doc) || empty($doc) || bp_docs_get_post_type_name() !== $doc->post_type) { return false; } $folder = get_post($folder_id); if (is_wp_error($folder) || empty($folder) || 'bp_docs_folder' !== $folder->post_type) { return false; } $term_id = bp_docs_get_folder_term($folder_id); // misc error if (!$term_id) { return false; } $existing_folders = wp_get_object_terms($doc_id, 'bp_docs_doc_in_folder'); // Return false if not in folder $in_folder = false; foreach ($existing_folders as $existing_folder) { if ($term_id === $existing_folder->term_id) { $in_folder = true; break; } } if (!$in_folder) { return false; } return (bool) wp_remove_object_terms($doc_id, $term_id, 'bp_docs_doc_in_folder'); }
/** * 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); }
/** * Testing Sensei_Teacher::update_course_modules_author * This test focus on changing module author * * @since 1.8.0 */ public function testUpdateCourseModulesAuthorChange() { // setup assertions $test_teacher_id = wp_create_user('teacherCourseModulesAuthor', 'teacherCourseModulesAuthor', '*****@*****.**'); // create test course with current admin as owner $test_course_id = $this->factory->get_random_course_id(); $administrator = get_user_by('email', get_bloginfo('admin_email')); wp_update_post(array('ID' => $test_course_id, 'post_author' => $administrator->ID)); //insert sample module terms $term_start = wp_insert_term('Sample Test Start', 'module'); $term_end = wp_insert_term('Sample Test End', 'module'); // assign sample terms to course wp_set_object_terms($test_course_id, array($term_start['term_id'], $term_end['term_id']), 'module', true); // run the function passing in new teacher Sensei_Teacher::update_course_modules_author($test_course_id, $test_teacher_id); // set the current active user to be the teacher so that get object terms // only return the teachers terms $current_user = get_current_user_id(); wp_set_current_user($test_teacher_id); // check the if the object terms have change to the new new user within the slug $updated_module_terms = wp_get_object_terms($test_course_id, 'module'); $assert_message = 'Course module term authors not updated.'; foreach ($updated_module_terms as $term) { // skip $term_start and $term_end if ($term_start['term_id'] == $term->term_id || $term_end['term_id'] == $term->term_id) { continue; } $updated_author = Sensei_Core_Modules::get_term_author($term->slug); $this->assertEquals($test_teacher_id, $updated_author->ID, $assert_message); } // modules should be removed from the course foreach ($updated_module_terms as $term) { // skip $term_start and $term_end $this->assertFalse($term_start['term_id'] == $term->term_id || $term_end['term_id'] == $term->term_id, 'The old modules should no longer be on the course'); } // reset current user for other tests wp_set_current_user($current_user); //when the lessons are moved back to admin they should be duplciated // first clear all the object term on the test course. $terms = wp_get_object_terms($test_course_id, 'module'); foreach ($terms as $term) { wp_remove_object_terms($test_course_id, array($term->term_id), 'module'); } $admin_module = wp_insert_term('Admin Test Module', 'module'); wp_set_object_terms($test_course_id, array($admin_module['term_id']), 'module', true); Sensei_Teacher::update_course_modules_author($test_course_id, $administrator->ID); // move to teacher and then back to admin Sensei_Teacher::update_course_modules_author($test_course_id, $test_teacher_id); Sensei_Teacher::update_course_modules_author($test_course_id, $administrator->ID); // after the update this course should still only have one module as course should not be duplicated for admin $admin_term_after_multiple_updates = wp_get_object_terms($test_course_id, 'module'); $message = 'A new admin term with slug {adminID}-slug should not have been created. The admin term should not be duplicated when passed back to admin'; $this->assertFalse(strpos($admin_term_after_multiple_updates[0]->slug, (string) $administrator->ID), $message); }
/** * Remove tag from lead * * @param lead_id INT * @param tag_id MIXED INT,STRING,ARRAY * */ public static function remove_tag_from_lead($lead_id, $list_id) { wp_remove_object_terms($lead_id, $list_id, 'lead-tags', true); }
/** * Update all the course terms set(selected) on the given course. Moving course term ownership to * the new author. Making sure the course terms are maintained. * * This function also checks if terms are shared, with other courses * * @param $course_id * @param $new_teacher_id * @return void */ public static function update_course_modules_author($course_id, $new_teacher_id) { if (empty($course_id) || empty($new_teacher_id)) { return false; } $terms_selected_on_course = wp_get_object_terms($course_id, 'module'); if (empty($terms_selected_on_course)) { return; } foreach ($terms_selected_on_course as $term) { $term_author = Sensei_Core_Modules::get_term_author($term->slug); if ($new_teacher_id != $term_author->ID) { $new_term = ''; //if the new teacher is admin first check to see if the term with this name already exists if (user_can($new_teacher_id, 'manage_options')) { $slug_without_teacher_id = str_ireplace(' ', '-', trim($term->name)); $term_args = array('slug' => $slug_without_teacher_id, 'hide_empty' => false); $existing_admin_terms = get_terms('module', $term_args); if (!empty($existing_admin_terms)) { // insert it even if it exists $new_term = get_term($existing_admin_terms[0]->term_id, 'module', ARRAY_A); } } if (empty($new_term)) { //setup the new slug $new_author_term_slug = $new_teacher_id . '-' . str_ireplace(' ', '-', trim($term->name)); // create new term and set it $new_term = wp_insert_term($term->name, 'module', array('slug' => $new_author_term_slug)); } // if term exists if (is_wp_error($new_term) && isset($new_term->errors['term_exists'])) { $existing_term = get_term_by('slug', $new_author_term_slug, 'module'); $term_id = $existing_term->term_id; } else { // for a new term simply get the term from the returned value $term_id = $new_term['term_id']; } // end if term exist // set the terms selected on the course wp_set_object_terms($course_id, $term_id, 'module', true); // remove old term wp_remove_object_terms($course_id, $term->term_id, 'module'); // update the lessons within the current module term $lessons = Sensei()->course->course_lessons($course_id); foreach ($lessons as $lesson) { if (has_term($term->slug, 'module', $lesson)) { // add the new term, the false at the end says to replace all terms on this module // with the new term. wp_set_object_terms($lesson->ID, $term_id, 'module', false); update_post_meta($lesson->ID, '_order_module_' . intval($term_id), 0); } } // end for each } } }
/** * Fires during init, looks for a semicolon_action. */ public static function inline_controls_handler() { if (empty($_GET['semicolon_action']) || !is_user_logged_in()) { return; } $action = strtolower($_GET['semicolon_action']); if (!in_array($action, array('toggle_featured'))) { return; } // Powered by Jetpack's Featured Content. if ('toggle_featured' == $action) { if (empty($_GET['semicolon_post_id'])) { return; } $post_id = absint($_GET['semicolon_post_id']); $post = get_post($post_id); if (!current_user_can('edit_post', $post->ID)) { return; } // Only if the featured content tag has been set. $term_id = self::get_jetpack_featured_content_term_id(); if (!$term_id) { return; } // Toggle the featured content tag. if (self::is_featured($post->ID)) { wp_remove_object_terms($post->ID, $term_id, 'post_tag'); } else { wp_set_object_terms($post->ID, $term_id, 'post_tag', true); } if (method_exists('Featured_Content', 'delete_transient')) { Featured_Content::delete_transient(); } $redirect_url = remove_query_arg(array('semicolon_action', 'semicolon_post_id')); $redirect_url .= sprintf('#semicolon-post-%d', $post->ID); wp_safe_redirect(esc_url_raw($redirect_url)); } }
/** * Remove taxonomy terms on a BuddyPress object. * * @since 2.3.0 * * @see wp_remove_object_terms() for a full description of function and parameters. * * @param int $object_id Object ID. * @param string|array $terms Term or terms to remove. * @param string $taxonomy Taxonomy name. * @return bool|WP_Error True on success, false or WP_Error on failure. */ function bp_remove_object_terms($object_id, $terms, $taxonomy) { $site_id = bp_get_taxonomy_term_site_id($taxonomy); $switched = false; if ($site_id !== get_current_blog_id()) { switch_to_blog($site_id); bp_register_taxonomies(); $switched = true; } $retval = wp_remove_object_terms($object_id, $terms, $taxonomy); if ($switched) { restore_current_blog(); } /** * Fires when taxonomy terms have been removed from BuddyPress objects. * * @since 2.7.0 * * @param int $object_id Object ID. * @param array $terms Term or terms to remove. * @param string $taxonomy Taxonomy name. */ do_action('bp_remove_object_terms', $object_id, $terms, $taxonomy); return $retval; }