2007-06-05 07:08:27 +02:00
|
|
|
<?php
|
2008-08-14 08:30:38 +02:00
|
|
|
/**
|
|
|
|
* Manage link category administration actions.
|
|
|
|
*
|
|
|
|
* This page is accessed by the link management pages and handles the forms and
|
|
|
|
* AJAX processes for category actions.
|
|
|
|
*
|
|
|
|
* @package WordPress
|
|
|
|
* @subpackage Administration
|
|
|
|
*/
|
|
|
|
|
|
|
|
/** Load WordPress Administration Bootstrap */
|
2007-06-05 07:08:27 +02:00
|
|
|
require_once('admin.php');
|
|
|
|
|
|
|
|
wp_reset_vars(array('action', 'cat'));
|
|
|
|
|
|
|
|
switch($action) {
|
|
|
|
|
|
|
|
case 'addcat':
|
|
|
|
|
|
|
|
check_admin_referer('add-link-category');
|
|
|
|
|
|
|
|
if ( !current_user_can('manage_categories') )
|
|
|
|
wp_die(__('Cheatin’ uh?'));
|
|
|
|
|
|
|
|
if ( wp_insert_term($_POST['name'], 'link_category', $_POST ) ) {
|
|
|
|
wp_redirect('edit-link-categories.php?message=1#addcat');
|
|
|
|
} else {
|
|
|
|
wp_redirect('edit-link-categories.php?message=4#addcat');
|
|
|
|
}
|
|
|
|
exit;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'delete':
|
|
|
|
$cat_ID = (int) $_GET['cat_ID'];
|
|
|
|
check_admin_referer('delete-link-category_' . $cat_ID);
|
|
|
|
|
|
|
|
if ( !current_user_can('manage_categories') )
|
|
|
|
wp_die(__('Cheatin’ uh?'));
|
|
|
|
|
|
|
|
$cat_name = get_term_field('name', $cat_ID, 'link_category');
|
2008-07-21 18:13:23 +02:00
|
|
|
$default_cat_id = get_option('default_link_category');
|
2007-06-05 07:08:27 +02:00
|
|
|
|
|
|
|
// Don't delete the default cats.
|
2008-08-14 08:30:38 +02:00
|
|
|
if ( $cat_ID == $default_cat_id )
|
2007-06-05 07:08:27 +02:00
|
|
|
wp_die(sprintf(__("Can’t delete the <strong>%s</strong> category: this is the default one"), $cat_name));
|
|
|
|
|
2008-07-21 18:13:23 +02:00
|
|
|
wp_delete_term($cat_ID, 'link_category', array('default' => $default_cat_id));
|
2007-06-05 07:08:27 +02:00
|
|
|
|
2008-03-26 23:21:01 +01:00
|
|
|
$location = 'edit-link-categories.php';
|
|
|
|
if ( $referer = wp_get_original_referer() ) {
|
|
|
|
if ( false !== strpos($referer, 'edit-link-categories.php') )
|
|
|
|
$location = $referer;
|
|
|
|
}
|
|
|
|
|
|
|
|
$location = add_query_arg('message', 2, $location);
|
|
|
|
|
|
|
|
wp_redirect($location);
|
2007-06-05 07:08:27 +02:00
|
|
|
exit;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'edit':
|
|
|
|
$title = __('Categories');
|
2008-03-19 00:49:42 +01:00
|
|
|
$parent_file = 'edit.php';
|
2007-06-05 07:08:27 +02:00
|
|
|
$submenu_file = 'edit-link-categories.php';
|
|
|
|
require_once ('admin-header.php');
|
|
|
|
$cat_ID = (int) $_GET['cat_ID'];
|
|
|
|
$category = get_term_to_edit($cat_ID, 'link_category');
|
|
|
|
include('edit-link-category-form.php');
|
|
|
|
include('admin-footer.php');
|
|
|
|
exit;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'editedcat':
|
|
|
|
$cat_ID = (int) $_POST['cat_ID'];
|
|
|
|
check_admin_referer('update-link-category_' . $cat_ID);
|
|
|
|
|
|
|
|
if ( !current_user_can('manage_categories') )
|
|
|
|
wp_die(__('Cheatin’ uh?'));
|
|
|
|
|
2008-03-26 23:21:01 +01:00
|
|
|
$location = 'edit-link-categories.php';
|
|
|
|
if ( $referer = wp_get_original_referer() ) {
|
|
|
|
if ( false !== strpos($referer, 'edit-link-categories.php') )
|
|
|
|
$location = $referer;
|
|
|
|
}
|
|
|
|
|
2008-07-21 19:52:19 +02:00
|
|
|
$update = wp_update_term($cat_ID, 'link_category', $_POST);
|
|
|
|
|
|
|
|
if ( $update && !is_wp_error($update) )
|
2008-03-26 23:21:01 +01:00
|
|
|
$location = add_query_arg('message', 3, $location);
|
2007-06-05 07:08:27 +02:00
|
|
|
else
|
2008-03-26 23:21:01 +01:00
|
|
|
$location = add_query_arg('message', 5, $location);
|
2007-06-05 07:08:27 +02:00
|
|
|
|
2008-03-26 23:21:01 +01:00
|
|
|
wp_redirect($location);
|
2007-06-05 07:08:27 +02:00
|
|
|
exit;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
?>
|