PageRenderTime 59ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

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

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