web/wp-admin/link-category.php
branchwordpress
changeset 109 03b0d1493584
child 132 4d4862461b8d
equal deleted inserted replaced
-1:000000000000 109:03b0d1493584
       
     1 <?php
       
     2 /**
       
     3  * Manage link category administration actions.
       
     4  *
       
     5  * This page is accessed by the link management pages and handles the forms and
       
     6  * AJAX processes for category actions.
       
     7  *
       
     8  * @package WordPress
       
     9  * @subpackage Administration
       
    10  */
       
    11 
       
    12 /** Load WordPress Administration Bootstrap */
       
    13 require_once('admin.php');
       
    14 
       
    15 wp_reset_vars(array('action', 'cat'));
       
    16 
       
    17 switch($action) {
       
    18 
       
    19 case 'addcat':
       
    20 
       
    21 	check_admin_referer('add-link-category');
       
    22 
       
    23 	if ( !current_user_can('manage_categories') )
       
    24 		wp_die(__('Cheatin&#8217; uh?'));
       
    25 
       
    26 	if ( wp_insert_term($_POST['name'], 'link_category', $_POST ) ) {
       
    27 		wp_redirect('edit-link-categories.php?message=1#addcat');
       
    28 	} else {
       
    29 		wp_redirect('edit-link-categories.php?message=4#addcat');
       
    30 	}
       
    31 	exit;
       
    32 break;
       
    33 
       
    34 case 'delete':
       
    35 	$cat_ID = (int) $_GET['cat_ID'];
       
    36 	check_admin_referer('delete-link-category_' .  $cat_ID);
       
    37 
       
    38 	if ( !current_user_can('manage_categories') )
       
    39 		wp_die(__('Cheatin&#8217; uh?'));
       
    40 
       
    41 	$cat_name = get_term_field('name', $cat_ID, 'link_category');
       
    42 	$default_cat_id = get_option('default_link_category');
       
    43 
       
    44 	// Don't delete the default cats.
       
    45 	if ( $cat_ID == $default_cat_id )
       
    46 		wp_die(sprintf(__("Can&#8217;t delete the <strong>%s</strong> category: this is the default one"), $cat_name));
       
    47 
       
    48 	wp_delete_term($cat_ID, 'link_category', array('default' => $default_cat_id));
       
    49 
       
    50 	$location = 'edit-link-categories.php';
       
    51 	if ( $referer = wp_get_original_referer() ) {
       
    52 		if ( false !== strpos($referer, 'edit-link-categories.php') )
       
    53 			$location = $referer;
       
    54 	}
       
    55 
       
    56 	$location = add_query_arg('message', 2, $location);
       
    57 
       
    58 	wp_redirect($location);
       
    59 	exit;
       
    60 
       
    61 break;
       
    62 
       
    63 case 'edit':
       
    64 	$title = __('Edit Category');
       
    65 	$parent_file = 'link-manager.php';
       
    66 	$submenu_file = 'edit-link-categories.php';
       
    67 	require_once ('admin-header.php');
       
    68 	$cat_ID = (int) $_GET['cat_ID'];
       
    69 	$category = get_term_to_edit($cat_ID, 'link_category');
       
    70 	include('edit-link-category-form.php');
       
    71 	include('admin-footer.php');
       
    72 	exit;
       
    73 break;
       
    74 
       
    75 case 'editedcat':
       
    76 	$cat_ID = (int) $_POST['cat_ID'];
       
    77 	check_admin_referer('update-link-category_' . $cat_ID);
       
    78 
       
    79 	if ( !current_user_can('manage_categories') )
       
    80 		wp_die(__('Cheatin&#8217; uh?'));
       
    81 
       
    82 	$location = 'edit-link-categories.php';
       
    83 	if ( $referer = wp_get_original_referer() ) {
       
    84 		if ( false !== strpos($referer, 'edit-link-categories.php') )
       
    85 			$location = $referer;
       
    86 	}
       
    87 
       
    88 	$update =  wp_update_term($cat_ID, 'link_category', $_POST);
       
    89 
       
    90 	if ( $update && !is_wp_error($update) )
       
    91 		$location = add_query_arg('message', 3, $location);
       
    92 	else
       
    93 		$location = add_query_arg('message', 5, $location);
       
    94 
       
    95 	wp_redirect($location);
       
    96 	exit;
       
    97 break;
       
    98 }
       
    99 
       
   100 ?>