/** * Aliases nxt_insert_category() with minimal args. * * If you want to update only some fields of an existing category, call this * function with only the new values set inside $catarr. * * @since 2.0.0 * * @param array $catarr The 'cat_ID' value is required. All other keys are optional. * @return int|bool The ID number of the new or updated Category on success. Zero or FALSE on failure. */ function nxt_update_category($catarr) { $cat_ID = (int) $catarr['cat_ID']; if (isset($catarr['category_parent']) && $cat_ID == $catarr['category_parent']) { return false; } // First, get all of the original fields $category = get_category($cat_ID, ARRAY_A); // Escape data pulled from DB. $category = add_magic_quotes($category); // Merge old and new fields with new fields overwriting old ones. $catarr = array_merge($category, $catarr); return nxt_insert_category($catarr); }
/** * Create new category. * * @since 2.2.0 * * @param array $args Method parameters. * @return int Category ID. */ function nxt_newCategory($args) { $this->escape($args); $blog_id = (int) $args[0]; $username = $args[1]; $password = $args[2]; $category = $args[3]; if (!($user = $this->login($username, $password))) { return $this->error; } do_action('xmlrpc_call', 'nxt.newCategory'); // Make sure the user is allowed to add a category. if (!current_user_can('manage_categories')) { return new IXR_Error(401, __('Sorry, you do not have the right to add a category.')); } // If no slug was provided make it empty so that // NXTClass will generate one. if (empty($category['slug'])) { $category['slug'] = ''; } // If no parent_id was provided make it empty // so that it will be a top level page (no parent). if (!isset($category['parent_id'])) { $category['parent_id'] = ''; } // If no description was provided make it empty. if (empty($category["description"])) { $category["description"] = ""; } $new_category = array('cat_name' => $category['name'], 'category_nicename' => $category['slug'], 'category_parent' => $category['parent_id'], 'category_description' => $category['description']); $cat_id = nxt_insert_category($new_category, true); if (is_nxt_error($cat_id)) { if ('term_exists' == $cat_id->get_error_code()) { return (int) $cat_id->get_error_data(); } else { return new IXR_Error(500, __('Sorry, the new category failed.')); } } elseif (!$cat_id) { return new IXR_Error(500, __('Sorry, the new category failed.')); } return $cat_id; }
/** * Create new categories based on import information * * Doesn't create a new category if its slug already exists */ function process_categories() { if (empty($this->categories)) { return; } foreach ($this->categories as $cat) { // if the category already exists leave it alone $term_id = term_exists($cat['category_nicename'], 'category'); if ($term_id) { if (is_array($term_id)) { $term_id = $term_id['term_id']; } if (isset($cat['term_id'])) { $this->processed_terms[intval($cat['term_id'])] = (int) $term_id; } continue; } $category_parent = empty($cat['category_parent']) ? 0 : category_exists($cat['category_parent']); $category_description = isset($cat['category_description']) ? $cat['category_description'] : ''; $catarr = array('category_nicename' => $cat['category_nicename'], 'category_parent' => $category_parent, 'cat_name' => $cat['cat_name'], 'category_description' => $category_description); $id = nxt_insert_category($catarr); if (!is_nxt_error($id)) { if (isset($cat['term_id'])) { $this->processed_terms[intval($cat['term_id'])] = $id; } } else { printf(__('Failed to import category %s', 'nxtclass-importer'), esc_html($cat['category_nicename'])); if (defined('IMPORT_DEBUG') && IMPORT_DEBUG) { echo ': ' . $id->get_error_message(); } echo '<br />'; continue; } } unset($this->categories); }