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

Revision 8682, 4.8 kB (checked in by ryan, 1 week ago)

Merge crazyhorse management pages. see #7552

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