PageRenderTime 47ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-admin/link-manager.php

https://github.com/markjaquith/WordPress
PHP | 143 lines | 102 code | 28 blank | 13 comment | 9 complexity | 42615bbf03fc25d9d771be7e7a451a84 MD5 | raw file
Possible License(s): GPL-2.0, AGPL-1.0, LGPL-2.1
  1. <?php
  2. /**
  3. * Link Management Administration Screen.
  4. *
  5. * @package WordPress
  6. * @subpackage Administration
  7. */
  8. /** Load WordPress Administration Bootstrap */
  9. require_once __DIR__ . '/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. $screen = get_current_screen()->id;
  28. /** This action is documented in wp-admin/edit.php */
  29. $redirect_to = apply_filters( "handle_bulk_actions-{$screen}", $redirect_to, $doaction, $bulklinks ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
  30. }
  31. wp_redirect( $redirect_to );
  32. exit;
  33. } elseif ( ! empty( $_GET['_wp_http_referer'] ) ) {
  34. wp_redirect( remove_query_arg( array( '_wp_http_referer', '_wpnonce' ), wp_unslash( $_SERVER['REQUEST_URI'] ) ) );
  35. exit;
  36. }
  37. $wp_list_table->prepare_items();
  38. // Used in the HTML title tag.
  39. $title = __( 'Links' );
  40. $this_file = 'link-manager.php';
  41. $parent_file = $this_file;
  42. get_current_screen()->add_help_tab(
  43. array(
  44. 'id' => 'overview',
  45. 'title' => __( 'Overview' ),
  46. 'content' =>
  47. '<p>' . sprintf(
  48. /* translators: %s: URL to Widgets screen. */
  49. __( '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.' ),
  50. 'widgets.php'
  51. ) . '</p>' .
  52. '<p>' . __( 'Links may be separated into Link Categories; these are different than the categories used on your posts.' ) . '</p>' .
  53. '<p>' . __( 'You can customize the display of this screen using the Screen Options tab and/or the dropdown filters above the links table.' ) . '</p>',
  54. )
  55. );
  56. get_current_screen()->add_help_tab(
  57. array(
  58. 'id' => 'deleting-links',
  59. 'title' => __( 'Deleting Links' ),
  60. 'content' =>
  61. '<p>' . __( 'If you delete a link, it will be removed permanently, as Links do not have a Trash function yet.' ) . '</p>',
  62. )
  63. );
  64. get_current_screen()->set_help_sidebar(
  65. '<p><strong>' . __( 'For more information:' ) . '</strong></p>' .
  66. '<p>' . __( '<a href="https://codex.wordpress.org/Links_Screen">Documentation on Managing Links</a>' ) . '</p>' .
  67. '<p>' . __( '<a href="https://wordpress.org/support/">Support</a>' ) . '</p>'
  68. );
  69. get_current_screen()->set_screen_reader_content(
  70. array(
  71. 'heading_list' => __( 'Links list' ),
  72. )
  73. );
  74. require_once ABSPATH . 'wp-admin/admin-header.php';
  75. if ( ! current_user_can( 'manage_links' ) ) {
  76. wp_die( __( 'Sorry, you are not allowed to edit the links for this site.' ) );
  77. }
  78. ?>
  79. <div class="wrap nosubsub">
  80. <h1 class="wp-heading-inline">
  81. <?php
  82. echo esc_html( $title );
  83. ?>
  84. </h1>
  85. <a href="link-add.php" class="page-title-action"><?php echo esc_html_x( 'Add New', 'link' ); ?></a>
  86. <?php
  87. if ( isset( $_REQUEST['s'] ) && strlen( $_REQUEST['s'] ) ) {
  88. echo '<span class="subtitle">';
  89. printf(
  90. /* translators: %s: Search query. */
  91. __( 'Search results for: %s' ),
  92. '<strong>' . esc_html( wp_unslash( $_REQUEST['s'] ) ) . '</strong>'
  93. );
  94. echo '</span>';
  95. }
  96. ?>
  97. <hr class="wp-header-end">
  98. <?php
  99. if ( isset( $_REQUEST['deleted'] ) ) {
  100. echo '<div id="message" class="updated notice is-dismissible"><p>';
  101. $deleted = (int) $_REQUEST['deleted'];
  102. /* translators: %s: Number of links. */
  103. printf( _n( '%s link deleted.', '%s links deleted.', $deleted ), $deleted );
  104. echo '</p></div>';
  105. $_SERVER['REQUEST_URI'] = remove_query_arg( array( 'deleted' ), $_SERVER['REQUEST_URI'] );
  106. }
  107. ?>
  108. <form id="posts-filter" method="get">
  109. <?php $wp_list_table->search_box( __( 'Search Links' ), 'link' ); ?>
  110. <?php $wp_list_table->display(); ?>
  111. <div id="ajax-response"></div>
  112. </form>
  113. </div>
  114. <?php
  115. require_once ABSPATH . 'wp-admin/admin-footer.php';