/** * Update link with the specified link categories. * * @since 2.1.0 * * @param int $link_id ID of link to update * @param array $link_categories Array of categories to */ function nxt_set_link_cats($link_id = 0, $link_categories = array()) { // If $link_categories isn't already an array, make it one: if (!is_array($link_categories) || 0 == count($link_categories)) { $link_categories = array(get_option('default_link_category')); } $link_categories = array_map('intval', $link_categories); $link_categories = array_unique($link_categories); nxt_set_object_terms($link_id, $link_categories, 'link_category'); clean_bookmark_cache($link_id); }
/** * {@internal Missing Short Description}} * * @since 2.5.0 * * @return unknown */ function media_upload_form_handler() { check_admin_referer('media-form'); $errors = null; if (isset($_POST['send'])) { $keys = array_keys($_POST['send']); $send_id = (int) array_shift($keys); } if (!empty($_POST['attachments'])) { foreach ($_POST['attachments'] as $attachment_id => $attachment) { $post = $_post = get_post($attachment_id, ARRAY_A); $post_type_object = get_post_type_object($post['post_type']); if (!current_user_can($post_type_object->cap->edit_post, $attachment_id)) { continue; } if (isset($attachment['post_content'])) { $post['post_content'] = $attachment['post_content']; } if (isset($attachment['post_title'])) { $post['post_title'] = $attachment['post_title']; } if (isset($attachment['post_excerpt'])) { $post['post_excerpt'] = $attachment['post_excerpt']; } if (isset($attachment['menu_order'])) { $post['menu_order'] = $attachment['menu_order']; } if (isset($send_id) && $attachment_id == $send_id) { if (isset($attachment['post_parent'])) { $post['post_parent'] = $attachment['post_parent']; } } $post = apply_filters('attachment_fields_to_save', $post, $attachment); if (isset($attachment['image_alt'])) { $image_alt = get_post_meta($attachment_id, '_nxt_attachment_image_alt', true); if ($image_alt != stripslashes($attachment['image_alt'])) { $image_alt = nxt_strip_all_tags(stripslashes($attachment['image_alt']), true); // update_meta expects slashed update_post_meta($attachment_id, '_nxt_attachment_image_alt', addslashes($image_alt)); } } if (isset($post['errors'])) { $errors[$attachment_id] = $post['errors']; unset($post['errors']); } if ($post != $_post) { nxt_update_post($post); } foreach (get_attachment_taxonomies($post) as $t) { if (isset($attachment[$t])) { nxt_set_object_terms($attachment_id, array_map('trim', preg_split('/,+/', $attachment[$t])), $t, false); } } } } if (isset($_POST['insert-gallery']) || isset($_POST['update-gallery'])) { ?> <script type="text/javascript"> /* <![CDATA[ */ var win = window.dialogArguments || opener || parent || top; win.tb_remove(); /* ]]> */ </script> <?php exit; } if (isset($send_id)) { $attachment = stripslashes_deep($_POST['attachments'][$send_id]); $html = $attachment['post_title']; if (!empty($attachment['url'])) { $rel = ''; if (strpos($attachment['url'], 'attachment_id') || get_attachment_link($send_id) == $attachment['url']) { $rel = " rel='attachment nxt-att-" . esc_attr($send_id) . "'"; } $html = "<a href='{$attachment['url']}'{$rel}>{$html}</a>"; } $html = apply_filters('media_send_to_editor', $html, $send_id, $attachment); return media_send_to_editor($html); } return $errors; }
/** * Set categories for a post. * * If the post categories parameter is not set, then the default category is * going used. * * @since 2.1.0 * * @param int $post_ID Post ID. * @param array $post_categories Optional. List of categories. * @return bool|mixed */ function nxt_set_post_categories($post_ID = 0, $post_categories = array()) { $post_ID = (int) $post_ID; $post_type = get_post_type($post_ID); $post_status = get_post_status($post_ID); // If $post_categories isn't already an array, make it one: if (!is_array($post_categories) || empty($post_categories)) { if ('post' == $post_type && 'auto-draft' != $post_status) { $post_categories = array(get_option('default_category')); } else { $post_categories = array(); } } else { if (1 == count($post_categories) && '' == reset($post_categories)) { return true; } } if (!empty($post_categories)) { $post_categories = array_map('intval', $post_categories); $post_categories = array_unique($post_categories); } return nxt_set_object_terms($post_ID, $post_categories, 'category'); }
/** * Removes a term from the database. * * If the term is a parent of other terms, then the children will be updated to * that term's parent. * * The $args 'default' will only override the terms found, if there is only one * term found. Any other and the found terms are used. * * The $args 'force_default' will force the term supplied as default to be * assigned even if the object was not going to be termless * @package NXTClass * @subpackage Taxonomy * @since 2.3.0 * * @uses $nxtdb * @uses do_action() Calls both 'delete_term' and 'delete_$taxonomy' action * hooks, passing term object, term id. 'delete_term' gets an additional * parameter with the $taxonomy parameter. * * @param int $term Term ID * @param string $taxonomy Taxonomy Name * @param array|string $args Optional. Change 'default' term id and override found term ids. * @return bool|nxt_Error Returns false if not term; true if completes delete action. */ function nxt_delete_term($term, $taxonomy, $args = array()) { global $nxtdb; $term = (int) $term; if (!($ids = term_exists($term, $taxonomy))) { return false; } if (is_nxt_error($ids)) { return $ids; } $tt_id = $ids['term_taxonomy_id']; $defaults = array(); if ('category' == $taxonomy) { $defaults['default'] = get_option('default_category'); if ($defaults['default'] == $term) { return 0; } // Don't delete the default category } $args = nxt_parse_args($args, $defaults); extract($args, EXTR_SKIP); if (isset($default)) { $default = (int) $default; if (!term_exists($default, $taxonomy)) { unset($default); } } // Update children to point to new parent if (is_taxonomy_hierarchical($taxonomy)) { $term_obj = get_term($term, $taxonomy); if (is_nxt_error($term_obj)) { return $term_obj; } $parent = $term_obj->parent; $edit_tt_ids = $nxtdb->get_col("SELECT `term_taxonomy_id` FROM {$nxtdb->term_taxonomy} WHERE `parent` = " . (int) $term_obj->term_id); do_action('edit_term_taxonomies', $edit_tt_ids); $nxtdb->update($nxtdb->term_taxonomy, compact('parent'), array('parent' => $term_obj->term_id) + compact('taxonomy')); do_action('edited_term_taxonomies', $edit_tt_ids); } $objects = $nxtdb->get_col($nxtdb->prepare("SELECT object_id FROM {$nxtdb->term_relationships} WHERE term_taxonomy_id = %d", $tt_id)); foreach ((array) $objects as $object) { $terms = nxt_get_object_terms($object, $taxonomy, array('fields' => 'ids', 'orderby' => 'none')); if (1 == count($terms) && isset($default)) { $terms = array($default); } else { $terms = array_diff($terms, array($term)); if (isset($default) && isset($force_default) && $force_default) { $terms = array_merge($terms, array($default)); } } $terms = array_map('intval', $terms); nxt_set_object_terms($object, $terms, $taxonomy); } // Clean the relationship caches for all object types using this term $tax_object = get_taxonomy($taxonomy); foreach ($tax_object->object_type as $object_type) { clean_object_term_cache($objects, $object_type); } do_action('delete_term_taxonomy', $tt_id); $nxtdb->query($nxtdb->prepare("DELETE FROM {$nxtdb->term_taxonomy} WHERE term_taxonomy_id = %d", $tt_id)); do_action('deleted_term_taxonomy', $tt_id); // Delete the term if no taxonomies use it. if (!$nxtdb->get_var($nxtdb->prepare("SELECT COUNT(*) FROM {$nxtdb->term_taxonomy} WHERE term_id = %d", $term))) { $nxtdb->query($nxtdb->prepare("DELETE FROM {$nxtdb->terms} WHERE term_id = %d", $term)); } clean_term_cache($term, $taxonomy); do_action('delete_term', $term, $tt_id, $taxonomy); do_action("delete_{$taxonomy}", $term, $tt_id); return true; }