/** * Destroy the user we created and related posts. */ public static function wpTearDownAfterClass() { // Delete our user self::delete_user(self::$user_id); // Delete all of our posts foreach (self::$posts as $post) { wp_delete_post($post, true); } // Delete our taxonomy wp_delete_category(self::$category->term_id); }
function delete_categories($id) { $args = array('hide_empty' => 0, 'child_of' => $id); $child_categories = get_categories($args); if (!empty($child_categories)) { foreach ($child_categories as $child_category) { self::delete_categories($child_category->term_id); } } wp_delete_category($id); }
function testDeleteCategory() { update_option('default_category', 1); add_category(1, (object) array('slug' => 'test')); add_category(2, (object) array('slug' => 'test-2')); $this->assertFalse(wp_delete_category(1)); $this->assertTrue(wp_delete_category(2)); $result = get_category(1); $this->assertTrue(isset($result->term_id)); $result = get_category(2); $this->assertFalse(isset($result->term_id)); }
/** * @ticket 19205 */ function test_orphan_category() { $cat_id1 = $this->factory->category->create(); wp_delete_category( $cat_id1 ); $cat_id2 = $this->factory->category->create( array( 'parent' => $cat_id1 ) ); $this->assertWPError( $cat_id2 ); }
if ($r) { // Decide if we need to send back '1' or a more complicated response including page links and comment counts _wp_ajax_delete_comment_response($comment->comment_ID); } die('0'); break; case 'delete-cat': check_ajax_referer("delete-category_{$id}"); if (!current_user_can('manage_categories')) { die('-1'); } $cat = get_category($id); if (!$cat || is_wp_error($cat)) { die('1'); } if (wp_delete_category($id)) { die('1'); } else { die('0'); } break; case 'delete-tag': $tag_id = (int) $_POST['tag_ID']; check_ajax_referer("delete-tag_{$tag_id}"); if (!current_user_can('manage_categories')) { die('-1'); } $taxonomy = !empty($_POST['taxonomy']) ? $_POST['taxonomy'] : 'post_tag'; $tag = get_term($tag_id, $taxonomy); if (!$tag || is_wp_error($tag)) { die('1');
function cpm_action_build_storyline_schema() { global $cpm_config; update_option('comicpress-enable-storyline-support', isset($_POST['enable-storyline-support']) ? 1 : 0); update_option('comicpress-storyline-show-top-category', isset($_POST['show-top-category']) ? 1 : 0); if (isset($_POST['enable-storyline-support'])) { $cpm_config->is_cpm_modifying_categories = true; $categories_to_create = array(); $categories_to_rename = array(); $category_ids_to_clean = array(); extract(cpm_get_all_comic_categories()); $comic_posts = cpm_query_posts(); $comic_posts_by_category_id = array(); foreach ($comic_posts as $post) { foreach (wp_get_post_categories($post->ID) as $category) { if (!isset($comic_posts_by_category_id[$category])) { $comic_posts_by_category_id[$category] = array(); } $comic_posts_by_category_id[$category][] = $post->ID; } } foreach ($_POST as $field => $value) { $value = stripslashes($value); $parts = explode("/", $field); if ($parts[0] == "0" && count($parts) > 1) { $category_id = end($parts); $category = get_category($category_id); if (!empty($category)) { $category = (array) $category; if ($category['cat_name'] != $value) { $cpm_config->messages[] = sprintf(__('Category <strong>%1$s</strong> renamed to <strong>%2$s</strong>.', 'comicpress-manager'), $category['cat_name'], $value); $category['cat_name'] = $value; wp_update_category($category); $category_ids_to_clean[] = $category_id; } } else { $categories_to_create[$field] = $value; } if (($index = array_search($field, $category_tree)) !== false) { array_splice($category_tree, $index, 1); } } } if (isset($_POST['original-categories'])) { foreach (explode(",", $_POST['original-categories']) as $node) { if (!isset($_POST[$node])) { $category_id = end(explode("/", $node)); $category = get_category($category_id); $original_cat_name = $category->cat_name; // ensure that we're not deleting a ComicPress category $ok = true; foreach (array('comiccat', 'blogcat') as $type) { if ($category_id == $cpm_config->properties[$type]) { $ok = false; } } // ensure that the category truly is a child of the comic category if ($ok) { $category = get_category($category_id); $ok = false; if (!is_wp_error($category)) { while ($category->parent != 0 && $category->parent != $cpm_config->properties['comiccat']) { $category = get_category($category->parent); } if ($category->parent == $cpm_config->properties['comiccat']) { $ok = true; } } } if ($ok) { wp_delete_category($category_id); $category_ids_to_clean[] = $category_id; $cpm_config->messages[] = sprintf(__('Category <strong>%s</strong> deleted.', 'comicpress-manager'), $original_cat_name); } } } } uksort($categories_to_create, 'cpm_sort_category_keys_by_length'); $changed_field_ids = array(); $removed_field_ids = array(); $target_category_ids = array(); foreach ($categories_to_create as $field => $value) { $original_field = $field; foreach ($changed_field_ids as $changed_field => $new_field) { if (strpos($field, $changed_field) === 0 && strlen($field) > strlen($changed_field)) { $field = str_replace($changed_field, $new_field, $field); break; } } $parts = explode("/", $field); $target_id = array_pop($parts); $parent_id = array_pop($parts); if (!category_exists($value)) { $category_id = wp_create_category($value, $parent_id); $category_ids_to_clean[] = $category_id; array_push($parts, $parent_id); array_push($parts, $category_id); $changed_field_ids[$original_field] = implode("/", $parts); $cpm_config->messages[] = sprintf(__('Category <strong>%s</strong> created.', 'comicpress-manager'), $value); } else { $cpm_config->warnings[] = sprintf(__("The category %s already exists. Please enter a new name.", 'comicpress-manager'), $value); $removed_field_ids[] = $field; } } $order = array_diff(explode(",", $_POST['order']), $removed_field_ids); for ($i = 0; $i < count($order); ++$i) { if (isset($changed_field_ids[$order[$i]])) { $order[$i] = $changed_field_ids[$order[$i]]; } } // ensure we're writing sane data $new_order = array(); $valid_comic_categories = array(); foreach ($order as $node) { $parts = explode("/", $node); if ($parts[0] == "0" && count($parts) > 1) { $new_order[] = $node; $valid_comic_categories[] = end($parts); } } $comic_categories_preserved = array(); foreach ($comic_posts as $post) { $categories = wp_get_post_categories($post->ID); if (count(array_intersect($valid_comic_categories, $categories)) == 0) { $all_parent_categories = array(); foreach ($comic_posts_by_category_id as $category => $post_ids) { if (in_array($post->ID, $post_ids)) { foreach ($new_order as $node) { $parts = explode("/", $node); if ($category == end($parts)) { $parts = explode("/", $node); array_pop($parts); if (count($parts) > 1) { $all_parent_categories[] = implode("/", $parts); } } } } } if (count($all_parent_categories) > 0) { foreach ($all_parent_categories as $category_node) { if (in_array($category_node, $new_order)) { $categories[] = end(explode("/", $category_node)); } } } else { $categories[] = $cpm_config->properties['comiccat']; } wp_set_post_categories($post->ID, $categories); $comic_categories_preserved[] = $post->ID; } } if (count($comic_categories_preserved) > 0) { $cpm_config->messages[] = sprintf(__("The following orphaned comic posts were placed into their original category's parent: <strong>%s</strong>"), implode(", ", $comic_categories_preserved)); } $cpm_config->messages[] = __('Storyline structure saved.', 'comicpress-manager'); update_option("comicpress-storyline-category-order", implode(",", $new_order)); clean_term_cache($category_ids_to_clean, 'category'); wp_cache_flush(); } }
/** * Remove category. * * @since 2.5.0 * * @param array $args Method parameters. * @return mixed See {@link wp_delete_category()} for return info. */ function wp_deleteCategory($args) { $this->escape($args); $blog_id = (int) $args[0]; $username = $args[1]; $password = $args[2]; $category_id = (int) $args[3]; if (!$this->login_pass_ok($username, $password)) { return $this->error; } do_action('xmlrpc_call', 'wp.deleteCategory'); set_current_user(0, $username); if (!current_user_can("manage_categories")) { return new IXR_Error(401, __("Sorry, you do not have the right to delete a category.")); } return wp_delete_category($category_id); }
private function remove_category($params) { $inserted_install = get_theme_mod('exclusive_install_posts', ''); if (isset($inserted_install[$params['spec_id']])) { $sucsses = wp_delete_category($inserted_install[$params['spec_id']]); if ($sucsses) { unset($inserted_install[$params['spec_id']]); set_theme_mod('exclusive_install_posts', $inserted_install); return 1; } else { if (get_category($inserted_install[$params['spec_id']])) { return '<div class="error_text">Error Remove</div>'; } else { unset($inserted_install[$params['spec_id']]); set_theme_mod('exclusive_install_posts', $inserted_install); return '<div class="notification_text">Not Found</div>'; } } } else { return '<div class="notification_text">Not Found</div>'; } }
} else { $id = wpmu_create_blog($hostname, "/" . $site['slug'], $site['name'], 1, $options, 1); } $wpdb->show_errors(); if (!is_wp_error($id)) { //doing a normal flush rules will not work, just delete the rewrites switch_to_blog($id); // we delete the rewrites because flushing them does not work if the originally // loaded blog is the main one, deleteing them will force a propper flush on that site's first page. delete_option('rewrite_rules'); // Delete the first post wp_delete_post(1, true); // Delete the about page wp_delete_post(2, true); //Configure categories wp_delete_category(1); $inserted_cats = array(); foreach ($categories as $cat) { $cat_id = wp_insert_category($cat); $inserted_cats[$cat_id] = $cat; } // Create the Section Menu $menu_id = wp_create_nav_menu('Main', array('slug' => 'main')); // Assign it to the sections theme location $theme = get_current_theme(); $mods = get_option('mods_' . $theme); $mods['nav_menu_locations']['sections'] = $menu_id; update_option('mods_' . $theme, $mods); // Create the menu items foreach ($inserted_cats as $cat_id => $cat) { if (in_array($cat['cat_name'], $section_nav)) {
static function remove() { $td_stacks_demo_categories_id = get_option('td_demo_categories_id'); if (is_array($td_stacks_demo_categories_id)) { foreach ($td_stacks_demo_categories_id as $td_stacks_demo_category_id) { wp_delete_category($td_stacks_demo_category_id); } } }
/** * Test to see if a two facets can be selected with the AND operator. * Should yield zero results. * @group 37 */ function test_multi_facet_and() { $this->__change_option('s4wp_default_operator', 'AND'); $this->__change_option('s4wp_facet_on_custom_fields', array('my_field')); $this->__change_option('s4wp_index_custom_fields', array('my_field')); $cat_id_one = wp_create_category('new_cat'); $cat_id_two = wp_create_category('smelly_cat'); $p_id = $this->__create_test_post(); update_post_meta($p_id, 'my_field', 'my_value'); wp_set_object_terms($p_id, $cat_id_one, 'category', true); $p_id_two = $this->__create_test_post(); wp_set_object_terms($p_id_two, $cat_id_two, 'category', true); SolrPower_Sync::get_instance()->load_all_posts(0, 'post', 100, false); $query = $this->__facet_query(array('facet' => array('my_field_str' => array('my_value'), 'categories' => array('smelly_cat^^')))); // This should return zero results because the result cannot contain both the custom field and the category. $this->assertEquals(0, $query->post_count); $this->assertEquals(0, $query->found_posts); wp_delete_category($cat_id_one); wp_delete_category($cat_id_two); }
function test_wp_insert_delete_category() { $term = rand_str(); $this->assertNull( category_exists( $term ) ); $initial_count = wp_count_terms( 'category' ); $t = wp_insert_category( array( 'cat_name' => $term ) ); $this->assertTrue( is_numeric($t) ); $this->assertFalse( is_wp_error($t) ); $this->assertTrue( $t > 0 ); $this->assertEquals( $initial_count + 1, wp_count_terms( 'category' ) ); // make sure the term exists $this->assertTrue( term_exists($term) > 0 ); $this->assertTrue( term_exists($t) > 0 ); // now delete it $this->assertTrue( wp_delete_category($t) ); $this->assertNull( term_exists($term) ); $this->assertNull( term_exists($t) ); $this->assertEquals( $initial_count, wp_count_terms('category') ); }
function pp_delete_project($project_id) { if (true !== wp_delete_category($project_id)) { return false; } delete_option('pp_project_meta_' . $project_id); return true; }
function the_theme_setup() { require_once ABSPATH . 'wp-config.php'; require_once ABSPATH . 'wp-includes/wp-db.php'; require_once ABSPATH . 'wp-admin/includes/taxonomy.php'; include_once ABSPATH . 'wp-admin/includes/plugin.php'; // damn twenty twelve name had a space and is capitalized // i would use wp_current_theme, but twenty twelve screwed me $theme_name = get_option('template'); // First we check to see if our default theme settings have been applied. $the_theme_status = get_option("theme_setup_status_{$theme_name}"); if ($the_theme_status !== '1') { // value set to see if we include in the menu $categories = array('News' => 'true', 'Featured Media' => 'false', 'Gallery' => 'true', 'Spotlight' => 'false', 'Video' => 'false'); // make an array for list of category ids $created_categories = array(); foreach ($categories as $key => $value) { // this returns the cat id $term_id = term_exists($key, 'category'); if ($term_id !== 0 && $term_id !== null) { // just get the id $created_categories[$key] = $term_id; } else { // cat doesnt exist so we make it $created_categories[$key] = wp_create_category($key); } } // Category 2 update_option('default_category', $created_categories['News']); // delete the default category wp_delete_category(1); $pages = array('Bio', 'Contact', 'Tour'); // ids of the $page_ids = array(); foreach ($pages as $page) { // create new pages $post = array('comment_status' => 'closed', 'ping_status' => 'closed', 'post_content' => $page . ' page content goes here. Edit to make this go away', 'post_name' => $page, 'post_status' => 'publish', 'post_title' => $page, 'post_type' => 'page'); // check to see if page doesnt already exist so we don't keep adding junk. //worked fine in local, but sandbox was acting up. $page_check = get_page_by_title($page); if (is_null($page_check)) { $page_ids[$page] = wp_insert_post($post); } else { $page_ids[$page] = $page_check->ID; } } // create main menu if (!is_nav_menu('main')) { $main_menu_slug = 'main-menu'; $menu_title = 'main'; // just create one menu //register_nav_menu( $main_menu_slug, $menu_title ); if (!is_nav_menu($menu_title)) { $menu_id = wp_create_nav_menu($menu_title); $item = array('menu-item-type' => 'custom', 'menu-item-url' => site_url(), 'menu-item-title' => 'Home', 'menu-item-status' => 'publish'); wp_update_nav_menu_item($menu_id, 0, $item); foreach ($pages as $page) { $item = array('menu-item-object-id' => $page_ids[$page], 'menu-item-object' => 'page', 'menu-item-type' => 'post_type', 'menu-item-title' => $page, 'menu-item-status' => 'publish', 'menu-item-parent-id' => $menu_id); wp_update_nav_menu_item($menu_id, 0, $item); } foreach ($categories as $key => $value) { // do we include it in the menu? if ($value == 'true') { $item = array('menu-item-object-id' => $created_categories[$key], 'menu-item-object' => 'category', 'menu-item-type' => 'taxonomy', 'menu-item-title' => $key, 'menu-item-status' => 'publish', 'menu-item-parent-id' => $menu_id); wp_update_nav_menu_item($menu_id, 0, $item); } } $mods = get_option("theme_mods_{$theme_name}"); //update mods with menu id at theme location $menu_locations = get_nav_menu_locations(); foreach ($menu_locations as $menu_location => $description) { $mods['nav_menu_locations'][$menu_location] = $menu_id; } update_option("theme_mods_{$theme_name}", $mods); } } } elseif ($the_theme_status === '1' and isset($_GET['activated'])) { $msg = ' <div class="updated"> <p>The ' . get_option('current_theme') . ' theme was successfully re-activated.</p> </div>'; add_action('admin_notices', $c = create_function('', 'echo "' . addcslashes($msg, '"') . '";')); } update_option("theme_setup_status_{$theme_name}", '1'); }
/** * Undo demo setup and reverts back to state before importing the sample contents. * Does not remove post/pages that have been modified by the user. * * @since 1.7.6 */ function themify_undo_import_sample_content() { do_action('themify_before_demo_erase'); themify_import_sample_content_setup(); $import = new Themify_Import(); $data = $import->parse(themify_get_sample_content_file()); foreach ($data['categories'] as $cat) { $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'])) { wp_delete_category($term_id); } } } foreach ($data['tags'] as $tag) { $term_id = term_exists($tag['tag_slug'], 'post_tag'); if ($term_id) { if (is_array($term_id)) { $term_id = $term_id['term_id']; } if (isset($tag['term_id'])) { wp_delete_term($term_id, 'post_tag'); } } } foreach ($data['terms'] as $term) { $term_id = term_exists($term['slug'], $term['term_taxonomy']); if ($term_id) { if (is_array($term_id)) { $term_id = $term_id['term_id']; } if (isset($term['term_id'])) { wp_delete_term($term_id, $term['term_taxonomy']); } } } foreach ($data['posts'] as $post) { $post_exists = post_exists($post['post_title'], '', $post['post_date']); if ($post_exists && get_post_type($post_exists) == $post['post_type']) { /* check if the post has not been modified since it was created */ if ($post['post_date'] == get_post_field('post_modified', $post_exists)) { wp_delete_post($post_exists, true); // true: bypass trash } } } do_action('themify_after_demo_erase'); }
function dfll_custom_category_sanitize($value) { if (null == $value) { $cat = get_term_by('name', get_option('dfll_custom_category_name'), 'category'); if (false != $cat) { $d = wp_delete_category($cat->term_id); } } return $value; }
die(__('Cheatin’ uh?')); } wp_insert_category($_POST); header('Location: categories.php?message=1#addcat'); break; case 'delete': check_admin_referer(); if (!current_user_can('manage_categories')) { die(__('Cheatin’ uh?')); } $cat_ID = (int) $_GET['cat_ID']; $cat_name = get_catname($cat_ID); if (1 == $cat_ID) { die(sprintf(__("Can't delete the <strong>%s</strong> category: this is the default one"), $cat_name)); } wp_delete_category($cat_ID); header('Location: categories.php?message=2'); break; case 'edit': require_once 'admin-header.php'; $cat_ID = (int) $_GET['cat_ID']; $category = get_category_to_edit($cat_ID); ?> <div class="wrap"> <h2><?php _e('Edit Category'); ?> </h2> <form name="editcat" action="categories.php" method="post"> <table class="editform" width="100%" cellspacing="2" cellpadding="5">
private static function delete_empty_subcategories($mapping) { foreach (self::get_imported_sub_categories($mapping) as $category) { // XXX: the following should work, but does not! //if ($child->category_count == 0){ $objects = get_objects_in_term($category, 'category'); if (empty($objects)) { $cat = get_category($category); wp_delete_category($category); } } return true; }