root/trunk/wp-admin/edit-link-categories.php

Revision 1525, 6.8 kB (checked in by donncha, 2 days ago)

WP merge with revision 9756

Line 
1 <?php
2 /**
3  * Edit Link Categories Administration Panel.
4  *
5  * @package WordPress
6  * @subpackage Administration
7  */
8
9 /** WordPress Administration Bootstrap */
10 require_once('admin.php');
11
12 // Handle bulk actions
13 if ( isset($_GET['action']) && isset($_GET['delete']) ) {
14     check_admin_referer('bulk-link-categories');
15     $doaction = $_GET['action'] ? $_GET['action'] : $_GET['action2'];
16
17     if ( !current_user_can('manage_categories') )
18         wp_die(__('Cheatin&#8217; uh?'));
19
20     if ( 'delete' == $doaction ) {
21         foreach( (array) $_GET['delete'] as $cat_ID ) {
22             $cat_name = get_term_field('name', $cat_ID, 'link_category');
23             $default_cat_id = get_option('default_link_category');
24
25             // Don't delete the default cats.
26             if ( $cat_ID == $default_cat_id )
27                 wp_die(sprintf(__("Can&#8217;t delete the <strong>%s</strong> category: this is the default one"), $cat_name));
28
29             wp_delete_term($cat_ID, 'link_category', array('default' => $default_cat_id));
30         }
31
32         $location = 'edit-link-categories.php';
33         if ( $referer = wp_get_referer() ) {
34             if ( false !== strpos($referer, 'edit-link-categories.php') )
35                 $location = $referer;
36         }
37
38         $location = add_query_arg('message', 6, $location);
39         wp_redirect($location);
40         exit();
41     }
42 } elseif ( isset($_GET['_wp_http_referer']) && ! empty($_GET['_wp_http_referer']) ) {
43      wp_redirect( remove_query_arg( array('_wp_http_referer', '_wpnonce'), stripslashes($_SERVER['REQUEST_URI']) ) );
44      exit;
45 }
46
47 $title = __('Link Categories');
48
49 wp_enqueue_script('admin-categories');
50 if ( current_user_can('manage_categories') )
51     wp_enqueue_script('inline-edit-tax');
52
53 require_once ('admin-header.php');
54
55 $messages[1] = __('Category added.');
56 $messages[2] = __('Category deleted.');
57 $messages[3] = __('Category updated.');
58 $messages[4] = __('Category not added.');
59 $messages[5] = __('Category not updated.');
60 $messages[6] = __('Categories deleted.'); ?>
61
62 <div class="wrap nosubsub">
63 <h2><?php echo wp_specialchars( $title ); ?></h2>
64
65 <?php if ( isset($_GET['message']) && ( $msg = (int) $_GET['message'] ) ) : ?>
66 <div id="message" class="updated fade"><p><?php echo $messages[$msg]; ?></p></div>
67 <?php $_SERVER['REQUEST_URI'] = remove_query_arg(array('message'), $_SERVER['REQUEST_URI']);
68 endif; ?>
69
70 <form class="search-form" action="" method="get">
71 <p class="search-box">
72     <label class="hidden" for="link-category-search-input"><?php _e( 'Search Categories' ); ?>:</label>
73     <input type="text" class="search-input" id="link-category-search-input" name="s" value="<?php _admin_search_query(); ?>" />
74     <input type="submit" value="<?php _e( 'Search Categories' ); ?>" class="button" />
75 </p>
76 </form>
77 <br class="clear" />
78
79 <div id="col-container">
80
81 <div id="col-right">
82 <div class="col-wrap">
83 <form id="posts-filter" action="" method="get">
84 <div class="tablenav">
85
86 <?php
87 $pagenum = isset( $_GET['pagenum'] ) ? absint( $_GET['pagenum'] ) : 0;
88 if ( empty($pagenum) )
89     $pagenum = 1;
90 if( ! isset( $catsperpage ) || $catsperpage < 0 )
91     $catsperpage = 20;
92
93 $page_links = paginate_links( array(
94     'base' => add_query_arg( 'pagenum', '%#%' ),
95     'format' => '',
96     'prev_text' => __('&larr;'),
97     'next_text' => __('&rarr;'),
98     'total' => ceil(wp_count_terms('link_category') / $catsperpage),
99     'current' => $pagenum
100 ));
101
102 if ( $page_links )
103     echo "<div class='tablenav-pages'>$page_links</div>";
104 ?>
105
106 <div class="alignleft actions">
107 <select name="action">
108 <option value="" selected="selected"><?php _e('Actions'); ?></option>
109 <option value="delete"><?php _e('Delete'); ?></option>
110 </select>
111 <input type="submit" value="<?php _e('Apply'); ?>" name="doaction" id="doaction" class="button-secondary action" />
112 <?php wp_nonce_field('bulk-link-categories'); ?>
113 </div>
114
115 <br class="clear" />
116 </div>
117
118 <div class="clear"></div>
119
120 <table class="widefat fixed" cellspacing="0">
121     <thead>
122     <tr>
123 <?php print_column_headers('edit-link-categories'); ?>
124     </tr>
125     </thead>
126
127     <tfoot>
128     <tr>
129 <?php print_column_headers('edit-link-categories', false); ?>
130     </tr>
131     </tfoot>
132
133     <tbody id="the-list" class="list:link-cat">
134 <?php
135 $start = ($pagenum - 1) * $catsperpage;
136 $args = array('offset' => $start, 'number' => $catsperpage, 'hide_empty' => 0);
137 if ( !empty( $_GET['s'] ) )
138     $args['search'] = $_GET['s'];
139
140 $categories = get_terms( 'link_category', $args );
141 if ( $categories ) {
142     $output = '';
143     foreach ( $categories as $category ) {
144         $output .= link_cat_row($category);
145     }
146     $output = apply_filters('cat_rows', $output);
147     echo $output;
148     unset($category);
149 }
150
151 ?>
152     </tbody>
153 </table>
154
155 <div class="tablenav">
156 <?php
157 if ( $page_links )
158     echo "<div class='tablenav-pages'>$page_links</div>";
159 ?>
160
161 <div class="alignleft actions">
162 <select name="action2">
163 <option value="" selected="selected"><?php _e('Actions'); ?></option>
164 <option value="delete"><?php _e('Delete'); ?></option>
165 </select>
166 <input type="submit" value="<?php _e('Apply'); ?>" name="doaction2" id="doaction2" class="button-secondary action" />
167 </div>
168
169 <br class="clear" />
170 </div>
171 <br class="clear" />
172 </form>
173 </div>
174 </div><!-- /col-right -->
175
176 <div id="col-left">
177 <div class="col-wrap">
178
179 <?php if ( current_user_can('manage_categories') ) {
180     $category = (object) array(); $category->parent = 0; do_action('add_link_category_form_pre', $category); ?>
181
182 <div class="form-wrap">
183 <h3><?php _e('Add Category'); ?></h3>
184 <div id="ajax-response"></div>
185 <form name="addcat" id="addcat" class="add:the-list: validate" method="post" action="link-category.php">
186 <input type="hidden" name="action" value="addcat" />
187 <?php wp_original_referer_field(true, 'previous'); wp_nonce_field('add-link-category'); ?>
188
189 <div class="form-field form-required">
190     <label for="name"><?php _e('Category name') ?></label>
191     <input name="name" id="name" type="text" value="" size="40" aria-required="true" />
192 </div>
193
194 <div class="form-field">
195     <label for="description"><?php _e('Description (optional)') ?></label>
196     <textarea name="description" id="description" rows="5" cols="40"></textarea>
197 </div>
198
199 <p class="submit"><input type="submit" class="button" name="submit" value="<?php _e('Add Category'); ?>" /></p>
200 <?php do_action('edit_link_category_form', $category); ?>
201 </form>
202 </div>
203
204 <?php } ?>
205
206 <div class="form-wrap">
207 <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>
208 </div>
209
210 </div>
211 </div><!-- /col-left -->
212
213 </div><!-- /col-container -->
214 </div><!-- /wrap -->
215
216 <script type="text/javascript">
217 /* <![CDATA[ */
218 (function($){
219     $(document).ready(function(){
220         $('#doaction, #doaction2').click(function(){
221             if ( $('select[name^="action"]').val() == 'delete' ) {
222                 var m = '<?php echo js_escape(__("You are about to delete the selected link categories.\n  'Cancel' to stop, 'OK' to delete.")); ?>';
223                 return showNotice.warn(m);
224             }
225         });
226     });
227 })(jQuery);
228 /* ]]> */
229 </script>
230
231 <?php inline_edit_term_row('link-category'); ?>
232 <?php include('admin-footer.php'); ?>
233
Note: See TracBrowser for help on using the browser.