PageRenderTime 46ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

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

https://github.com/schr/wordpress
PHP | 228 lines | 174 code | 45 blank | 9 comment | 23 complexity | 5fd97d175ec1a8d4c599a0ba739f79f6 MD5 | raw file
  1. <?php
  2. /**
  3. * Edit Link Categories Administration Panel.
  4. *
  5. * @package WordPress
  6. * @subpackage Administration
  7. */
  8. /** WordPress Administration Bootstrap */
  9. require_once('admin.php');
  10. // Handle bulk actions
  11. if ( isset($_GET['action']) && isset($_GET['delete']) ) {
  12. check_admin_referer('bulk-link-categories');
  13. $doaction = $_GET['action'] ? $_GET['action'] : $_GET['action2'];
  14. if ( !current_user_can('manage_categories') )
  15. wp_die(__('Cheatin&#8217; uh?'));
  16. if ( 'delete' == $doaction ) {
  17. foreach( (array) $_GET['delete'] as $cat_ID ) {
  18. $cat_name = get_term_field('name', $cat_ID, 'link_category');
  19. $default_cat_id = get_option('default_link_category');
  20. // Don't delete the default cats.
  21. if ( $cat_ID == $default_cat_id )
  22. wp_die(sprintf(__("Can&#8217;t delete the <strong>%s</strong> category: this is the default one"), $cat_name));
  23. wp_delete_term($cat_ID, 'link_category', array('default' => $default_cat_id));
  24. }
  25. $location = 'edit-link-categories.php';
  26. if ( $referer = wp_get_referer() ) {
  27. if ( false !== strpos($referer, 'edit-link-categories.php') )
  28. $location = $referer;
  29. }
  30. $location = add_query_arg('message', 6, $location);
  31. wp_redirect($location);
  32. exit();
  33. }
  34. } elseif ( isset($_GET['_wp_http_referer']) && ! empty($_GET['_wp_http_referer']) ) {
  35. wp_redirect( remove_query_arg( array('_wp_http_referer', '_wpnonce'), stripslashes($_SERVER['REQUEST_URI']) ) );
  36. exit;
  37. }
  38. $title = __('Link Categories');
  39. wp_enqueue_script('admin-categories');
  40. if ( current_user_can('manage_categories') )
  41. wp_enqueue_script('inline-edit-tax');
  42. require_once ('admin-header.php');
  43. $messages[1] = __('Category added.');
  44. $messages[2] = __('Category deleted.');
  45. $messages[3] = __('Category updated.');
  46. $messages[4] = __('Category not added.');
  47. $messages[5] = __('Category not updated.');
  48. $messages[6] = __('Categories deleted.'); ?>
  49. <div class="wrap nosubsub">
  50. <?php screen_icon(); ?>
  51. <h2><?php echo wp_specialchars( $title );
  52. if ( isset($_GET['s']) && $_GET['s'] )
  53. printf( '<span class="subtitle">' . __('Search results for &#8220;%s&#8221;') . '</span>', wp_specialchars( stripslashes($_GET['s']) ) ); ?>
  54. </h2>
  55. <?php if ( isset($_GET['message']) && ( $msg = (int) $_GET['message'] ) ) : ?>
  56. <div id="message" class="updated fade"><p><?php echo $messages[$msg]; ?></p></div>
  57. <?php $_SERVER['REQUEST_URI'] = remove_query_arg(array('message'), $_SERVER['REQUEST_URI']);
  58. endif; ?>
  59. <form class="search-form" action="" method="get">
  60. <p class="search-box">
  61. <label class="hidden" for="link-category-search-input"><?php _e( 'Search Categories' ); ?>:</label>
  62. <input type="text" class="search-input" id="link-category-search-input" name="s" value="<?php _admin_search_query(); ?>" />
  63. <input type="submit" value="<?php _e( 'Search Categories' ); ?>" class="button" />
  64. </p>
  65. </form>
  66. <br class="clear" />
  67. <div id="col-container">
  68. <div id="col-right">
  69. <div class="col-wrap">
  70. <form id="posts-filter" action="" method="get">
  71. <div class="tablenav">
  72. <?php
  73. $pagenum = isset( $_GET['pagenum'] ) ? absint( $_GET['pagenum'] ) : 0;
  74. if ( empty($pagenum) )
  75. $pagenum = 1;
  76. if( ! isset( $catsperpage ) || $catsperpage < 0 )
  77. $catsperpage = 20;
  78. $page_links = paginate_links( array(
  79. 'base' => add_query_arg( 'pagenum', '%#%' ),
  80. 'format' => '',
  81. 'prev_text' => __('&laquo;'),
  82. 'next_text' => __('&raquo;'),
  83. 'total' => ceil(wp_count_terms('link_category') / $catsperpage),
  84. 'current' => $pagenum
  85. ));
  86. if ( $page_links )
  87. echo "<div class='tablenav-pages'>$page_links</div>";
  88. ?>
  89. <div class="alignleft actions">
  90. <select name="action">
  91. <option value="" selected="selected"><?php _e('Bulk Actions'); ?></option>
  92. <option value="delete"><?php _e('Delete'); ?></option>
  93. </select>
  94. <input type="submit" value="<?php _e('Apply'); ?>" name="doaction" id="doaction" class="button-secondary action" />
  95. <?php wp_nonce_field('bulk-link-categories'); ?>
  96. </div>
  97. <br class="clear" />
  98. </div>
  99. <div class="clear"></div>
  100. <table class="widefat fixed" cellspacing="0">
  101. <thead>
  102. <tr>
  103. <?php print_column_headers('edit-link-categories'); ?>
  104. </tr>
  105. </thead>
  106. <tfoot>
  107. <tr>
  108. <?php print_column_headers('edit-link-categories', false); ?>
  109. </tr>
  110. </tfoot>
  111. <tbody id="the-list" class="list:link-cat">
  112. <?php
  113. $start = ($pagenum - 1) * $catsperpage;
  114. $args = array('offset' => $start, 'number' => $catsperpage, 'hide_empty' => 0);
  115. if ( !empty( $_GET['s'] ) )
  116. $args['search'] = $_GET['s'];
  117. $categories = get_terms( 'link_category', $args );
  118. if ( $categories ) {
  119. $output = '';
  120. foreach ( $categories as $category ) {
  121. $output .= link_cat_row($category);
  122. }
  123. echo $output;
  124. unset($category);
  125. }
  126. ?>
  127. </tbody>
  128. </table>
  129. <div class="tablenav">
  130. <?php
  131. if ( $page_links )
  132. echo "<div class='tablenav-pages'>$page_links</div>";
  133. ?>
  134. <div class="alignleft actions">
  135. <select name="action2">
  136. <option value="" selected="selected"><?php _e('Bulk Actions'); ?></option>
  137. <option value="delete"><?php _e('Delete'); ?></option>
  138. </select>
  139. <input type="submit" value="<?php _e('Apply'); ?>" name="doaction2" id="doaction2" class="button-secondary action" />
  140. </div>
  141. <br class="clear" />
  142. </div>
  143. <br class="clear" />
  144. </form>
  145. <div class="form-wrap">
  146. <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>
  147. </div>
  148. </div>
  149. </div><!-- /col-right -->
  150. <div id="col-left">
  151. <div class="col-wrap">
  152. <?php if ( current_user_can('manage_categories') ) {
  153. $category = (object) array(); $category->parent = 0; do_action('add_link_category_form_pre', $category); ?>
  154. <div class="form-wrap">
  155. <h3><?php _e('Add Category'); ?></h3>
  156. <div id="ajax-response"></div>
  157. <form name="addcat" id="addcat" class="add:the-list: validate" method="post" action="link-category.php">
  158. <input type="hidden" name="action" value="addcat" />
  159. <?php wp_original_referer_field(true, 'previous'); wp_nonce_field('add-link-category'); ?>
  160. <div class="form-field form-required">
  161. <label for="name"><?php _e('Category name') ?></label>
  162. <input name="name" id="name" type="text" value="" size="40" aria-required="true" />
  163. </div>
  164. <div class="form-field">
  165. <label for="slug"><?php _e('Category slug') ?></label>
  166. <input name="slug" id="slug" type="text" value="" size="40" />
  167. <p><?php _e('The &#8220;slug&#8221; is the URL-friendly version of the name. It is usually all lowercase and contains only letters, numbers, and hyphens.'); ?></p>
  168. </div>
  169. <div class="form-field">
  170. <label for="description"><?php _e('Description (optional)') ?></label>
  171. <textarea name="description" id="description" rows="5" cols="40"></textarea>
  172. </div>
  173. <p class="submit"><input type="submit" class="button" name="submit" value="<?php _e('Add Category'); ?>" /></p>
  174. <?php do_action('edit_link_category_form', $category); ?>
  175. </form>
  176. </div>
  177. <?php } ?>
  178. </div>
  179. </div><!-- /col-left -->
  180. </div><!-- /col-container -->
  181. </div><!-- /wrap -->
  182. <?php inline_edit_term_row('edit-link-categories'); ?>
  183. <?php include('admin-footer.php'); ?>