PageRenderTime 38ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-admin/link-category.php

https://github.com/gplsek/competitor-mu
PHP | 100 lines | 65 code | 24 blank | 11 comment | 13 complexity | 699855b991c70d1af8545bbea7cf4a9f MD5 | raw file
Possible License(s): LGPL-3.0
  1. <?php
  2. /**
  3. * Manage link category administration actions.
  4. *
  5. * This page is accessed by the link management pages and handles the forms and
  6. * AJAX processes for category actions.
  7. *
  8. * @package WordPress
  9. * @subpackage Administration
  10. */
  11. /** Load WordPress Administration Bootstrap */
  12. require_once('admin.php');
  13. wp_reset_vars(array('action', 'cat'));
  14. switch($action) {
  15. case 'addcat':
  16. check_admin_referer('add-link-category');
  17. if ( !current_user_can('manage_categories') )
  18. wp_die(__('Cheatin&#8217; uh?'));
  19. if ( wp_insert_term($_POST['name'], 'link_category', $_POST ) ) {
  20. wp_redirect('edit-link-categories.php?message=1#addcat');
  21. } else {
  22. wp_redirect('edit-link-categories.php?message=4#addcat');
  23. }
  24. exit;
  25. break;
  26. case 'delete':
  27. $cat_ID = (int) $_GET['cat_ID'];
  28. check_admin_referer('delete-link-category_' . $cat_ID);
  29. if ( !current_user_can('manage_categories') )
  30. wp_die(__('Cheatin&#8217; uh?'));
  31. $cat_name = get_term_field('name', $cat_ID, 'link_category');
  32. $default_cat_id = get_option('default_link_category');
  33. // Don't delete the default cats.
  34. if ( $cat_ID == $default_cat_id )
  35. wp_die(sprintf(__("Can&#8217;t delete the <strong>%s</strong> category: this is the default one"), $cat_name));
  36. wp_delete_term($cat_ID, 'link_category', array('default' => $default_cat_id));
  37. $location = 'edit-link-categories.php';
  38. if ( $referer = wp_get_original_referer() ) {
  39. if ( false !== strpos($referer, 'edit-link-categories.php') )
  40. $location = $referer;
  41. }
  42. $location = add_query_arg('message', 2, $location);
  43. wp_redirect($location);
  44. exit;
  45. break;
  46. case 'edit':
  47. $title = __('Edit Category');
  48. $parent_file = 'link-manager.php';
  49. $submenu_file = 'edit-link-categories.php';
  50. require_once ('admin-header.php');
  51. $cat_ID = (int) $_GET['cat_ID'];
  52. $category = get_term_to_edit($cat_ID, 'link_category');
  53. include('edit-link-category-form.php');
  54. include('admin-footer.php');
  55. exit;
  56. break;
  57. case 'editedcat':
  58. $cat_ID = (int) $_POST['cat_ID'];
  59. check_admin_referer('update-link-category_' . $cat_ID);
  60. if ( !current_user_can('manage_categories') )
  61. wp_die(__('Cheatin&#8217; uh?'));
  62. $location = 'edit-link-categories.php';
  63. if ( $referer = wp_get_original_referer() ) {
  64. if ( false !== strpos($referer, 'edit-link-categories.php') )
  65. $location = $referer;
  66. }
  67. $update = wp_update_term($cat_ID, 'link_category', $_POST);
  68. if ( $update && !is_wp_error($update) )
  69. $location = add_query_arg('message', 3, $location);
  70. else
  71. $location = add_query_arg('message', 5, $location);
  72. wp_redirect($location);
  73. exit;
  74. break;
  75. }
  76. ?>