diff options
author | donncha <donncha@7be80a69-a1ef-0310-a953-fb0f7c49ff36> | 2005-09-26 15:52:00 +0000 |
---|---|---|
committer | donncha <donncha@7be80a69-a1ef-0310-a953-fb0f7c49ff36> | 2005-09-26 15:52:00 +0000 |
commit | a6494ad1db59e9cc2d74e47cbb022b757b34345d (patch) | |
tree | 7ca015752831c2cb0122b242da7eb70fd6ec59da | |
parent | a6190921de18ef49d6329cd1fdd271a0fce0b771 (diff) | |
download | wordpress-mu-a6494ad1db59e9cc2d74e47cbb022b757b34345d.tar.gz wordpress-mu-a6494ad1db59e9cc2d74e47cbb022b757b34345d.tar.xz wordpress-mu-a6494ad1db59e9cc2d74e47cbb022b757b34345d.zip |
Categories: check for default category (not cat_ID == 1) when deleting.
Update default category option if cat_ID changes after edit.
git-svn-id: http://svn.automattic.com/wordpress-mu/trunk@372 7be80a69-a1ef-0310-a953-fb0f7c49ff36
-rw-r--r-- | wp-inst/wp-admin/categories.php | 21 | ||||
-rw-r--r-- | wp-inst/wp-content/mu-plugins/global-categories.php | 4 |
2 files changed, 17 insertions, 8 deletions
diff --git a/wp-inst/wp-admin/categories.php b/wp-inst/wp-admin/categories.php index 5641b6a..0cd64aa 100644 --- a/wp-inst/wp-admin/categories.php +++ b/wp-inst/wp-admin/categories.php @@ -42,9 +42,14 @@ case 'delete': $cat_ID = (int) $_GET['cat_ID']; $cat_name = get_catname($cat_ID); - if ( 1 == $cat_ID ) + $default_category = get_option( "default_category" ); + if ( $default_category == $cat_ID ) die(sprintf(__("Can't delete the <strong>%s</strong> category: this is the default one"), $cat_name)); + $categories = $wpdb->get_results("SELECT * FROM $wpdb->categories"); + if( count( $categories ) == 1 ) + die(sprintf(__("Can't delete the <strong>%s</strong> category: this is the only one"), $cat_name)); + wp_delete_category($cat_ID); header('Location: categories.php?message=2'); @@ -55,9 +60,6 @@ case 'edit': require_once ('admin-header.php'); $cat_ID = (int) $_GET['cat_ID']; - if( $cat_ID == 1 ) { - header( "Location: categories.php" ); - } $category = get_category_to_edit($cat_ID); ?> @@ -67,7 +69,9 @@ case 'edit': <table class="editform" width="100%" cellspacing="2" cellpadding="5"> <tr> <th width="33%" scope="row"><?php _e('Category name:') ?></th> - <td width="67%"><input name="cat_name" type="text" value="<?php echo wp_specialchars($category->cat_name); ?>" size="40" /> <input type="hidden" name="action" value="editedcat" /> + <td width="67%"><input name="cat_name" type="text" id='cat_name' value="<?php echo wp_specialchars($category->cat_name); ?>" size="40" /> <input type="hidden" name="action" value="editedcat" /> + <div style='display:none; height: 100px; width: 200px; overflow: auto; border: 1px solid #ccc; background: #eee; margin: 5px; padding: 5px;' id="searchresults"><?php _e( 'Search Results' ) ?></div> + <?php AJAX_search_box( "wpmu-edit.php?action=searchcategories&search=", "cat_name", "searchresults" ); ?> <input type="hidden" name="cat_ID" value="<?php echo $category->cat_ID ?>" /></td> </tr> <tr> @@ -99,7 +103,7 @@ case 'editedcat': if ( !current_user_can('manage_categories') ) die (__('Cheatin’ uh?')); - if( $_POST[ 'cat_ID' ] == 1 ) { + if( $_POST[ 'cat_ID' ] == get_option( 'default_category' ) ) { header( "Location: categories.php" ); } @@ -146,7 +150,8 @@ cat_rows(); <?php if ( current_user_can('manage_categories') ) : ?> <div class="wrap"> - <p><?php printf(__('<strong>Note:</strong><br />Deleting a category does not delete posts from that category, it will just set them back to the default category <strong>%s</strong>.'), get_catname(1)) ?> + <p><?php printf(__('<strong>Note:</strong><br />Deleting a category does not delete posts from that category, it will just set them back to the default category <strong>%s</strong>.'), get_catname( get_option( 'default_category' ) )) ?> + <br /><?php printf(__('You cannot delete the default category, <strong>%s</strong>, as a result. You must set another category as the default one by visiting the <a href="options-writing.php">Writing Options</a> page and changing it there.'), get_catname( get_option( 'default_category' ) )) ?> </p> </div> @@ -156,7 +161,7 @@ cat_rows(); <p><?php _e('Name:') ?><br /> <input type="text" name="cat_name" id='cat_name' value="" /></p> - <div style='display:none; height: 60px; width: 100px; overflow: auto; border: 1px solid #ccc; background: #eee; margin: 5px; padding: 5px;' id="searchresults"><?php _e( 'Search Results' ) ?></div> + <div style='display:none; height: 100px; width: 200px; overflow: auto; border: 1px solid #ccc; background: #eee; margin: 5px; padding: 5px;' id="searchresults"><?php _e( 'Search Results' ) ?></div> <?php AJAX_search_box( "wpmu-edit.php?action=searchcategories&search=", "cat_name", "searchresults" ); ?> <p><?php _e('Category parent:') ?><br /> <select name='category_parent' class='postform'> diff --git a/wp-inst/wp-content/mu-plugins/global-categories.php b/wp-inst/wp-content/mu-plugins/global-categories.php index 4b4a75d..b80b22d 100644 --- a/wp-inst/wp-content/mu-plugins/global-categories.php +++ b/wp-inst/wp-content/mu-plugins/global-categories.php @@ -10,9 +10,13 @@ function global_categories_filter( $update, $cat_ID, $category_nicename, $cat_na $wpdb->query( "UPDATE $wpdb->categories SET cat_ID = '$newcat_ID' WHERE cat_ID = '$cat_ID'" ); $wpdb->query( "UPDATE $wpdb->post2cat SET category_id = '$newcat_ID' WHERE category_id = '$cat_ID'" ); $cat_ID = $newcat_ID; + if( get_option( "default_category" ) == $cat_ID ) + update_option( "default_category", $newcat_ID ); } elseif( $details->cat_ID != $cat_ID ) { $wpdb->query( "UPDATE $wpdb->categories SET cat_ID = '$details->cat_ID' WHERE cat_ID = '$cat_ID'" ); $wpdb->query( "UPDATE $wpdb->post2cat SET category_id = '$details->cat_ID' WHERE category_id = '$cat_ID'" ); + if( get_option( "default_category" ) == $cat_ID ) + update_option( "default_category", $details->cat_ID ); $cat_ID = $details->cat_ID; } |