nxt_die(__('You attempted to edit an item that doesn’t exist. Perhaps it was deleted?')); } require_once 'admin-header.php'; include './edit-tag-form.php'; break; case 'editedtag': $tag_ID = (int) $_POST['tag_ID']; check_admin_referer('update-tag_' . $tag_ID); if (!current_user_can($tax->cap->edit_terms)) { nxt_die(__('Cheatin’ uh?')); } $tag = get_term($tag_ID, $taxonomy); if (!$tag) { nxt_die(__('You attempted to edit an item that doesn’t exist. Perhaps it was deleted?')); } $ret = nxt_update_term($tag_ID, $taxonomy, $_POST); $location = 'edit-tags.php?taxonomy=' . $taxonomy; if ('post' != $post_type) { $location .= '&post_type=' . $post_type; } if ($referer = nxt_get_original_referer()) { if (false !== strpos($referer, 'edit-tags.php')) { $location = $referer; } } if ($ret && !is_nxt_error($ret)) { $location = add_query_arg('message', 3, $location); } else { $location = add_query_arg('message', 5, $location); } nxt_redirect($location);
/** * Checks the given subset of the term hierarchy for hierarchy loops. * Prevents loops from forming and breaks those that it finds. * * Attached to the nxt_update_term_parent filter. * * @since 3.1.0 * @uses nxt_find_hierarchy_loop() * * @param int $parent term_id of the parent for the term we're checking. * @param int $term_id The term we're checking. * @param string $taxonomy The taxonomy of the term we're checking. * * @return int The new parent for the term. */ function nxt_check_term_hierarchy_for_loops($parent, $term_id, $taxonomy) { // Nothing fancy here - bail if (!$parent) { return 0; } // Can't be its own parent if ($parent == $term_id) { return 0; } // Now look for larger loops if (!($loop = nxt_find_hierarchy_loop('nxt_get_term_taxonomy_parent_id', $term_id, $parent, array($taxonomy)))) { return $parent; } // No loop // Setting $parent to the given value causes a loop if (isset($loop[$term_id])) { return 0; } // There's a loop, but it doesn't contain $term_id. Break the loop. foreach (array_keys($loop) as $loop_member) { nxt_update_term($loop_member, $taxonomy, array('parent' => 0)); } return $parent; }
$taxonomy = sanitize_key($_POST['taxonomy']); $tax = get_taxonomy($taxonomy); if (!$tax) { die('0'); } if (!current_user_can($tax->cap->edit_terms)) { die('-1'); } set_current_screen('edit-' . $taxonomy); $nxt_list_table = _get_list_table('nxt_Terms_List_Table'); if (!isset($_POST['tax_ID']) || !($id = (int) $_POST['tax_ID'])) { die(-1); } $tag = get_term($id, $taxonomy); $_POST['description'] = $tag->description; $updated = nxt_update_term($id, $taxonomy, $_POST); if ($updated && !is_nxt_error($updated)) { $tag = get_term($updated['term_id'], $taxonomy); if (!$tag || is_nxt_error($tag)) { if (is_nxt_error($tag) && $tag->get_error_message()) { die($tag->get_error_message()); } die(__('Item not updated.')); } echo $nxt_list_table->single_row($tag); } else { if (is_nxt_error($updated) && $updated->get_error_message()) { die($updated->get_error_message()); } die(__('Item not updated.')); }
/** * Updates an existing Category or creates a new Category. * * @since 2.0.0 * * @param mixed $catarr See defaults below. Set 'cat_ID' to a non-zero value to update an existing category. The 'taxonomy' key was added in 3.0.0. * @param bool $nxt_error Optional, since 2.5.0. Set this to true if the caller handles nxt_Error return values. * @return int|object The ID number of the new or updated Category on success. Zero or a nxt_Error on failure, depending on param $nxt_error. */ function nxt_insert_category($catarr, $nxt_error = false) { $cat_defaults = array('cat_ID' => 0, 'taxonomy' => 'category', 'cat_name' => '', 'category_description' => '', 'category_nicename' => '', 'category_parent' => ''); $catarr = nxt_parse_args($catarr, $cat_defaults); extract($catarr, EXTR_SKIP); if (trim($cat_name) == '') { if (!$nxt_error) { return 0; } else { return new nxt_Error('cat_name', __('You did not enter a category name.')); } } $cat_ID = (int) $cat_ID; // Are we updating or creating? if (!empty($cat_ID)) { $update = true; } else { $update = false; } $name = $cat_name; $description = $category_description; $slug = $category_nicename; $parent = $category_parent; $parent = (int) $parent; if ($parent < 0) { $parent = 0; } if (empty($parent) || !category_exists($parent) || $cat_ID && cat_is_ancestor_of($cat_ID, $parent)) { $parent = 0; } $args = compact('name', 'slug', 'parent', 'description'); if ($update) { $cat_ID = nxt_update_term($cat_ID, $taxonomy, $args); } else { $cat_ID = nxt_insert_term($cat_name, $taxonomy, $args); } if (is_nxt_error($cat_ID)) { if ($nxt_error) { return $cat_ID; } else { return 0; } } return $cat_ID['term_id']; }
/** * Save the properties of a menu or create a new menu with those properties. * * @since 3.0.0 * * @param int $menu_id The ID of the menu or "0" to create a new menu. * @param array $menu_data The array of menu data. * @return int|error object The menu's ID or nxt_Error object. */ function nxt_update_nav_menu_object($menu_id = 0, $menu_data = array()) { $menu_id = (int) $menu_id; $_menu = nxt_get_nav_menu_object($menu_id); $args = array('description' => isset($menu_data['description']) ? $menu_data['description'] : '', 'name' => isset($menu_data['menu-name']) ? $menu_data['menu-name'] : '', 'parent' => isset($menu_data['parent']) ? (int) $menu_data['parent'] : 0, 'slug' => null); // double-check that we're not going to have one menu take the name of another $_possible_existing = get_term_by('name', $menu_data['menu-name'], 'nav_menu'); if ($_possible_existing && !is_nxt_error($_possible_existing) && isset($_possible_existing->term_id) && $_possible_existing->term_id != $menu_id) { return new nxt_Error('menu_exists', sprintf(__('The menu name <strong>%s</strong> conflicts with another menu name. Please try another.'), esc_html($menu_data['menu-name']))); } // menu doesn't already exist, so create a new menu if (!$_menu || is_nxt_error($_menu)) { $menu_exists = get_term_by('name', $menu_data['menu-name'], 'nav_menu'); if ($menu_exists) { return new nxt_Error('menu_exists', sprintf(__('The menu name <strong>%s</strong> conflicts with another menu name. Please try another.'), esc_html($menu_data['menu-name']))); } $_menu = nxt_insert_term($menu_data['menu-name'], 'nav_menu', $args); if (is_nxt_error($_menu)) { return $_menu; } do_action('nxt_create_nav_menu', $_menu['term_id'], $menu_data); return (int) $_menu['term_id']; } if (!$_menu || !isset($_menu->term_id)) { return 0; } $menu_id = (int) $_menu->term_id; $update_response = nxt_update_term($menu_id, 'nav_menu', $args); if (is_nxt_error($update_response)) { return $update_response; } do_action('nxt_update_nav_menu', $menu_id, $menu_data); return $menu_id; }