• Hi,
    Here is my version of delete category (from wp-admin/categories.php)
    it add more consistency in the post2cat table, before you had the possibility to get duplicate row and incorrect #post.
    I don’t know the way to report bug correction (is there a bug list somewhere to track and correct bug ?)
    case ‘Delete’:
    $standalone = 1;
    require_once(‘admin-header.php’);
    $cat_ID = intval($HTTP_GET_VARS[“cat_ID”]);
    $cat_name = get_catname($cat_ID);
    $cat_name = addslashes($cat_name);
    if (1 == $cat_ID)
    die(“Can’t delete the $cat_name category: this is the default one”);
    if ($user_level < 3)
    die (‘Cheatin’ uh?’);
    // Do we have posts with this category ?
    $posts = $wpdb->get_results(“SELECT * FROM $tablepost2cat WHERE category_id=$cat_ID”);
    if($posts != null)
    foreach ($posts as $post) { // for each post in this category
    $count = $wpdb->get_var(“SELECT COUNT(rel_id) FROM $tablepost2cat WHERE post_id = $post->post_id”);
    if($count == 1) // is this post only in this category ?
    // yes, relink this post to ‘General’
    $wpdb->query(“UPDATE $tablepost2cat SET category_id=’1′ WHERE category_id=$cat_ID AND post_id=$post->post_id”);
    else
    // no, just remove this link
    $wpdb->query(“DELETE FROM $tablepost2cat WHERE category_id=$cat_ID AND post_id=$post->post_id”);
    }
    // Remove the category from the categories’ table
    $wpdb->query(“DELETE FROM $tablecategories WHERE cat_ID = $cat_ID”);
    header(‘Location: categories.php’);
    break;
    Cyril
    Montreal

Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter Cyril

    (@cyril)

    I read that the new beta has cat and subcat,
    I think if we remove a cat, post without cat must be link to the parent of the removed cat and if no parent to the General.
    Just my idea, I don’t have that new version.
    Cyril
    Montreal

    Cyril: We’re doing something like that, except if the deleted category had no parent then it’s children will have no parent.

    When you delete a category, I don’t see why we can’t prompt you for what category to you want to re-assign the posts to.

    Seems I misread what Cyril said.
    I think prompting for where they should go is a good idea.

    Thread Starter Cyril

    (@cyril)

    Hi Alex, Jason,
    any way is a good way, we just need to put a category (or general) on each post.
    I would like to do that modification and other to add more security in the code, but since the new WP deal with cat and subcat, I would like to work directly on it.
    The new WP with cat and subcat is the nightly build version ?
    How can I report modification in the cvs tree ?
    Do you have a bug-database to know where work is needed ?
    Thanks.
    Cyril

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Adding security on post2cat table’ is closed to new replies.