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

/wp-admin/link.php

http://github.com/markjaquith/WordPress
PHP | 126 lines | 81 code | 29 blank | 16 comment | 13 complexity | 3bf7e705390ef312d9a88de4dfd431a8 MD5 | raw file
Possible License(s): 0BSD
  1. <?php
  2. /**
  3. * Manage link administration actions.
  4. *
  5. * This page is accessed by the link management pages and handles the forms and
  6. * Ajax processes for link actions.
  7. *
  8. * @package WordPress
  9. * @subpackage Administration
  10. */
  11. /** Load WordPress Administration Bootstrap */
  12. require_once __DIR__ . '/admin.php';
  13. wp_reset_vars( array( 'action', 'cat_id', 'link_id' ) );
  14. if ( ! current_user_can( 'manage_links' ) ) {
  15. wp_link_manager_disabled_message();
  16. }
  17. if ( ! empty( $_POST['deletebookmarks'] ) ) {
  18. $action = 'deletebookmarks';
  19. }
  20. if ( ! empty( $_POST['move'] ) ) {
  21. $action = 'move';
  22. }
  23. if ( ! empty( $_POST['linkcheck'] ) ) {
  24. $linkcheck = $_POST['linkcheck'];
  25. }
  26. $this_file = admin_url( 'link-manager.php' );
  27. switch ( $action ) {
  28. case 'deletebookmarks':
  29. check_admin_referer( 'bulk-bookmarks' );
  30. // For each link id (in $linkcheck[]) change category to selected value.
  31. if ( count( $linkcheck ) == 0 ) {
  32. wp_redirect( $this_file );
  33. exit;
  34. }
  35. $deleted = 0;
  36. foreach ( $linkcheck as $link_id ) {
  37. $link_id = (int) $link_id;
  38. if ( wp_delete_link( $link_id ) ) {
  39. $deleted++;
  40. }
  41. }
  42. wp_redirect( "$this_file?deleted=$deleted" );
  43. exit;
  44. case 'move':
  45. check_admin_referer( 'bulk-bookmarks' );
  46. // For each link id (in $linkcheck[]) change category to selected value.
  47. if ( count( $linkcheck ) == 0 ) {
  48. wp_redirect( $this_file );
  49. exit;
  50. }
  51. $all_links = join( ',', $linkcheck );
  52. /*
  53. * Should now have an array of links we can change:
  54. * $q = $wpdb->query("update $wpdb->links SET link_category='$category' WHERE link_id IN ($all_links)");
  55. */
  56. wp_redirect( $this_file );
  57. exit;
  58. case 'add':
  59. check_admin_referer( 'add-bookmark' );
  60. $redir = wp_get_referer();
  61. if ( add_link() ) {
  62. $redir = add_query_arg( 'added', 'true', $redir );
  63. }
  64. wp_redirect( $redir );
  65. exit;
  66. case 'save':
  67. $link_id = (int) $_POST['link_id'];
  68. check_admin_referer( 'update-bookmark_' . $link_id );
  69. edit_link( $link_id );
  70. wp_redirect( $this_file );
  71. exit;
  72. case 'delete':
  73. $link_id = (int) $_GET['link_id'];
  74. check_admin_referer( 'delete-bookmark_' . $link_id );
  75. wp_delete_link( $link_id );
  76. wp_redirect( $this_file );
  77. exit;
  78. case 'edit':
  79. wp_enqueue_script( 'link' );
  80. wp_enqueue_script( 'xfn' );
  81. if ( wp_is_mobile() ) {
  82. wp_enqueue_script( 'jquery-touch-punch' );
  83. }
  84. $parent_file = 'link-manager.php';
  85. $submenu_file = 'link-manager.php';
  86. $title = __( 'Edit Link' );
  87. $link_id = (int) $_GET['link_id'];
  88. $link = get_link_to_edit( $link_id );
  89. if ( ! $link ) {
  90. wp_die( __( 'Link not found.' ) );
  91. }
  92. require ABSPATH . 'wp-admin/edit-link-form.php';
  93. require_once ABSPATH . 'wp-admin/admin-footer.php';
  94. break;
  95. default:
  96. break;
  97. }