]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-admin/edit-link-categories.php
Wordpress 2.6.2
[autoinstalls/wordpress.git] / wp-admin / edit-link-categories.php
1 <?php
2 require_once('admin.php');
3
4 // Handle bulk deletes
5 if ( isset($_GET['deleteit']) && isset($_GET['delete']) ) {
6         check_admin_referer('bulk-link-categories');
7
8         if ( !current_user_can('manage_categories') )
9                 wp_die(__('Cheatin&#8217; uh?'));
10
11         foreach( (array) $_GET['delete'] as $cat_ID ) {
12                 $cat_name = get_term_field('name', $cat_ID, 'link_category');
13                 $default_cat_id = get_option('default_link_category');
14                 
15                 // Don't delete the default cats.
16                 if ( $cat_ID == $default_cat_id )
17                         wp_die(sprintf(__("Can&#8217;t delete the <strong>%s</strong> category: this is the default one"), $cat_name));
18
19                 wp_delete_term($cat_ID, 'link_category', array('default' => $default_cat_id));
20         }
21
22         $location = 'edit-link-categories.php';
23         if ( $referer = wp_get_referer() ) {
24                 if ( false !== strpos($referer, 'edit-link-categories.php') )
25                         $location = $referer;
26         }
27
28         $location = add_query_arg('message', 6, $location);
29         wp_redirect($location);
30         exit();
31 } elseif ( !empty($_GET['_wp_http_referer']) ) {
32          wp_redirect(remove_query_arg(array('_wp_http_referer', '_wpnonce'), stripslashes($_SERVER['REQUEST_URI'])));
33          exit;
34 }
35
36 $title = __('Link Categories');
37 $parent_file = 'edit.php';
38
39 wp_enqueue_script( 'admin-categories' );
40 wp_enqueue_script('admin-forms');
41
42 require_once ('admin-header.php');
43
44 $messages[1] = __('Category added.');
45 $messages[2] = __('Category deleted.');
46 $messages[3] = __('Category updated.');
47 $messages[4] = __('Category not added.');
48 $messages[5] = __('Category not updated.');
49 $messages[6] = __('Categories deleted.');
50
51 if (isset($_GET['message'])) : ?>
52 <div id="message" class="updated fade"><p><?php echo $messages[$_GET['message']]; ?></p></div>
53 <?php $_SERVER['REQUEST_URI'] = remove_query_arg(array('message'), $_SERVER['REQUEST_URI']);
54 endif; ?>
55
56 <div class="wrap">
57
58 <form id="posts-filter" action="" method="get">
59 <?php if ( current_user_can('manage_categories') ) : ?>
60         <h2><?php printf(__('Manage Link Categories (<a href="%s">add new</a>)'), '#addcat') ?> </h2>
61 <?php else : ?>
62         <h2><?php _e('Manage Link Categories') ?> </h2>
63 <?php endif; ?>
64
65 <p id="post-search">
66         <label class="hidden" for="post-search-input"><?php _e( 'Search Categories' ); ?>:</label>
67         <input type="text" id="post-search-input" name="s" value="<?php echo attribute_escape(stripslashes($_GET['s'])); ?>" />
68         <input type="submit" value="<?php _e( 'Search Categories' ); ?>" class="button" />
69 </p>
70
71 <br class="clear" />
72
73 <div class="tablenav">
74
75 <?php
76 $pagenum = absint( $_GET['pagenum'] );
77 if ( empty($pagenum) )
78         $pagenum = 1;
79 if( !$catsperpage || $catsperpage < 0 )
80         $catsperpage = 20;
81
82 $page_links = paginate_links( array(
83         'base' => add_query_arg( 'pagenum', '%#%' ),
84         'format' => '',
85         'total' => ceil(wp_count_terms('link_category') / $catsperpage),
86         'current' => $pagenum
87 ));
88
89 if ( $page_links )
90         echo "<div class='tablenav-pages'>$page_links</div>";
91 ?>
92
93 <div class="alignleft">
94 <input type="submit" value="<?php _e('Delete'); ?>" name="deleteit" class="button-secondary delete" />
95 <?php wp_nonce_field('bulk-link-categories'); ?>
96 </div>
97
98 <br class="clear" />
99 </div>
100
101 <br class="clear" />
102
103 <table class="widefat">
104         <thead>
105         <tr>
106         <th scope="col" class="check-column"><input type="checkbox" /></th>
107         <th scope="col"><?php _e('Name') ?></th>
108         <th scope="col"><?php _e('Description') ?></th>
109         <th scope="col" class="num" style="width: 90px;"><?php _e('Links') ?></th>
110         </tr>
111         </thead>
112         <tbody id="the-list" class="list:link-cat">
113 <?php
114 $start = ($pagenum - 1) * $catsperpage;
115 $args = array('offset' => $start, 'number' => $catsperpage, 'hide_empty' => 0);
116 if ( !empty( $_GET['s'] ) )
117         $args['search'] = $_GET['s'];
118
119 $categories = get_terms( 'link_category', $args );
120 if ( $categories ) {
121         $output = '';
122         foreach ( $categories as $category ) {
123                 $category = sanitize_term($category, 'link_category', 'display');
124                 $output .= link_cat_row($category);
125         }
126         $output = apply_filters('cat_rows', $output);
127         echo $output;
128         unset($category);
129 }
130
131 ?>
132         </tbody>
133 </table>
134 </form>
135
136 <div class="tablenav">
137
138 <?php
139 if ( $page_links )
140         echo "<div class='tablenav-pages'>$page_links</div>";
141 ?>
142 <br class="clear" />
143 </div>
144 <br class="clear" />
145
146 </div>
147
148 <?php if ( current_user_can('manage_categories') ) : ?>
149 <div class="wrap">
150 <p><?php printf(__('<strong>Note:</strong><br />Deleting a category does not delete the links in that category. Instead, links that were only assigned to the deleted category are set to the category <strong>%s</strong>.'), get_term_field('name', get_option('default_link_category'), 'link_category')) ?></p>
151 </div>
152
153 <?php include('edit-link-category-form.php'); ?>
154
155 <?php endif; ?>
156
157 <?php include('admin-footer.php'); ?>