Adding security on post2cat table
-
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
- The topic ‘Adding security on post2cat table’ is closed to new replies.