link-manager.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <?php
  2. /**
  3. * Link Management Administration Screen.
  4. *
  5. * @package WordPress
  6. * @subpackage Administration
  7. */
  8. /** Load WordPress Administration Bootstrap */
  9. require_once( dirname( __FILE__ ) . '/admin.php' );
  10. if ( ! current_user_can( 'manage_links' ) ) {
  11. wp_die( __( 'Sorry, you are not allowed to edit the links for this site.' ) );
  12. }
  13. $wp_list_table = _get_list_table( 'WP_Links_List_Table' );
  14. // Handle bulk deletes
  15. $doaction = $wp_list_table->current_action();
  16. if ( $doaction && isset( $_REQUEST['linkcheck'] ) ) {
  17. check_admin_referer( 'bulk-bookmarks' );
  18. $redirect_to = admin_url( 'link-manager.php' );
  19. $bulklinks = (array) $_REQUEST['linkcheck'];
  20. if ( 'delete' == $doaction ) {
  21. foreach ( $bulklinks as $link_id ) {
  22. $link_id = (int) $link_id;
  23. wp_delete_link( $link_id );
  24. }
  25. $redirect_to = add_query_arg( 'deleted', count( $bulklinks ), $redirect_to );
  26. } else {
  27. /** This action is documented in wp-admin/edit-comments.php */
  28. $redirect_to = apply_filters( 'handle_bulk_actions-' . get_current_screen()->id, $redirect_to, $doaction, $bulklinks ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
  29. }
  30. wp_redirect( $redirect_to );
  31. exit;
  32. } elseif ( ! empty( $_GET['_wp_http_referer'] ) ) {
  33. wp_redirect( remove_query_arg( array( '_wp_http_referer', '_wpnonce' ), wp_unslash( $_SERVER['REQUEST_URI'] ) ) );
  34. exit;
  35. }
  36. $wp_list_table->prepare_items();
  37. $title = __( 'Links' );
  38. $this_file = 'link-manager.php';
  39. $parent_file = $this_file;
  40. get_current_screen()->add_help_tab(
  41. array(
  42. 'id' => 'overview',
  43. 'title' => __( 'Overview' ),
  44. 'content' =>
  45. '<p>' . sprintf(
  46. /* translators: %s: URL to Widgets screen. */
  47. __( 'You can add links here to be displayed on your site, usually using <a href="%s">Widgets</a>. By default, links to several sites in the WordPress community are included as examples.' ),
  48. 'widgets.php'
  49. ) . '</p>' .
  50. '<p>' . __( 'Links may be separated into Link Categories; these are different than the categories used on your posts.' ) . '</p>' .
  51. '<p>' . __( 'You can customize the display of this screen using the Screen Options tab and/or the dropdown filters above the links table.' ) . '</p>',
  52. )
  53. );
  54. get_current_screen()->add_help_tab(
  55. array(
  56. 'id' => 'deleting-links',
  57. 'title' => __( 'Deleting Links' ),
  58. 'content' =>
  59. '<p>' . __( 'If you delete a link, it will be removed permanently, as Links do not have a Trash function yet.' ) . '</p>',
  60. )
  61. );
  62. get_current_screen()->set_help_sidebar(
  63. '<p><strong>' . __( 'For more information:' ) . '</strong></p>' .
  64. '<p>' . __( '<a href="https://codex.wordpress.org/Links_Screen">Documentation on Managing Links</a>' ) . '</p>' .
  65. '<p>' . __( '<a href="https://wordpress.org/support/">Support</a>' ) . '</p>'
  66. );
  67. get_current_screen()->set_screen_reader_content(
  68. array(
  69. 'heading_list' => __( 'Links list' ),
  70. )
  71. );
  72. include_once( ABSPATH . 'wp-admin/admin-header.php' );
  73. if ( ! current_user_can( 'manage_links' ) ) {
  74. wp_die( __( 'Sorry, you are not allowed to edit the links for this site.' ) );
  75. }
  76. ?>
  77. <div class="wrap nosubsub">
  78. <h1 class="wp-heading-inline">
  79. <?php
  80. echo esc_html( $title );
  81. ?>
  82. </h1>
  83. <a href="link-add.php" class="page-title-action"><?php echo esc_html_x( 'Add New', 'link' ); ?></a>
  84. <?php
  85. if ( isset( $_REQUEST['s'] ) && strlen( $_REQUEST['s'] ) ) {
  86. /* translators: %s: Search query. */
  87. printf( '<span class="subtitle">' . __( 'Search results for &#8220;%s&#8221;' ) . '</span>', esc_html( wp_unslash( $_REQUEST['s'] ) ) );
  88. }
  89. ?>
  90. <hr class="wp-header-end">
  91. <?php
  92. if ( isset( $_REQUEST['deleted'] ) ) {
  93. echo '<div id="message" class="updated notice is-dismissible"><p>';
  94. $deleted = (int) $_REQUEST['deleted'];
  95. /* translators: %s: Number of links. */
  96. printf( _n( '%s link deleted.', '%s links deleted.', $deleted ), $deleted );
  97. echo '</p></div>';
  98. $_SERVER['REQUEST_URI'] = remove_query_arg( array( 'deleted' ), $_SERVER['REQUEST_URI'] );
  99. }
  100. ?>
  101. <form id="posts-filter" method="get">
  102. <?php $wp_list_table->search_box( __( 'Search Links' ), 'link' ); ?>
  103. <?php $wp_list_table->display(); ?>
  104. <div id="ajax-response"></div>
  105. </form>
  106. </div>
  107. <?php
  108. include( ABSPATH . 'wp-admin/admin-footer.php' );