tool-bulk-editor.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <?php
  2. /**
  3. * WPSEO plugin file.
  4. *
  5. * @package WPSEO\Admin
  6. * @since 1.5.0
  7. */
  8. if ( ! defined( 'WPSEO_VERSION' ) ) {
  9. header( 'Status: 403 Forbidden' );
  10. header( 'HTTP/1.1 403 Forbidden' );
  11. exit();
  12. }
  13. /**
  14. * Sanitizes the parameters that have been sent.
  15. *
  16. * @return array The sanitized fields.
  17. */
  18. function yoast_free_bulk_sanitize_input_fields() {
  19. $possible_params = [
  20. 'type',
  21. 'paged',
  22. 'post_type_filter',
  23. 'post_status',
  24. 'order',
  25. 'orderby',
  26. ];
  27. $input_get = [];
  28. foreach ( $possible_params as $param_name ) {
  29. if ( isset( $_GET[ $param_name ] ) ) {
  30. $input_get[ $param_name ] = sanitize_text_field( wp_unslash( $_GET[ $param_name ] ) );
  31. }
  32. }
  33. return $input_get;
  34. }
  35. $yoast_free_input_fields = yoast_free_bulk_sanitize_input_fields();
  36. // Verifies the nonce.
  37. if ( ! empty( $yoast_free_input_fields ) ) {
  38. check_admin_referer( 'bulk-editor-table', 'nonce' );
  39. }
  40. // If type is empty, fill it with value of first tab (title).
  41. if ( ! isset( $yoast_free_input_fields['type'] ) ) {
  42. $yoast_free_input_fields['type'] = 'title';
  43. }
  44. $yoast_bulk_editor_arguments = [
  45. 'input_fields' => $yoast_free_input_fields,
  46. 'nonce' => wp_create_nonce( 'bulk-editor-table' ),
  47. ];
  48. $wpseo_bulk_titles_table = new WPSEO_Bulk_Title_Editor_List_Table( $yoast_bulk_editor_arguments );
  49. $wpseo_bulk_description_table = new WPSEO_Bulk_Description_List_Table( $yoast_bulk_editor_arguments );
  50. $yoast_free_screen_reader_content = [
  51. 'heading_views' => __( 'Filter posts list', 'wordpress-seo' ),
  52. 'heading_pagination' => __( 'Posts list navigation', 'wordpress-seo' ),
  53. 'heading_list' => __( 'Posts list', 'wordpress-seo' ),
  54. ];
  55. get_current_screen()->set_screen_reader_content( $yoast_free_screen_reader_content );
  56. if ( ! empty( $_REQUEST['_wp_http_referer'] ) && isset( $_SERVER['REQUEST_URI'] ) ) {
  57. $request_uri = sanitize_file_name( wp_unslash( $_SERVER['REQUEST_URI'] ) );
  58. wp_redirect(
  59. remove_query_arg(
  60. [ '_wp_http_referer', '_wpnonce' ],
  61. $request_uri
  62. )
  63. );
  64. exit;
  65. }
  66. /**
  67. * Renders a bulk editor tab.
  68. *
  69. * @param WPSEO_Bulk_List_Table $table The table to render.
  70. * @param string $id The id for the tab.
  71. */
  72. function wpseo_get_rendered_tab( $table, $id ) {
  73. ?>
  74. <div id="<?php echo esc_attr( $id ); ?>" class="wpseotab">
  75. <?php
  76. $table->show_page();
  77. ?>
  78. </div>
  79. <?php
  80. }
  81. ?>
  82. <script>
  83. // phpcs:ignore WordPress.Security.OutputEscaping -- WPSEO_Utils::format_json_encode is safe.
  84. var wpseoBulkEditorNonce = <?php echo WPSEO_Utils::format_json_encode( wp_create_nonce( 'wpseo-bulk-editor' ) ); ?>;
  85. // eslint-disable-next-line
  86. var wpseo_bulk_editor_nonce = wpseoBulkEditorNonce;
  87. </script>
  88. <br/><br/>
  89. <div class="wpseo_table_page">
  90. <h2 class="nav-tab-wrapper" id="wpseo-tabs">
  91. <a class="nav-tab" id="title-tab" href="#top#title"><?php esc_html_e( 'Title', 'wordpress-seo' ); ?></a>
  92. <a class="nav-tab" id="description-tab"
  93. href="#top#description"><?php esc_html_e( 'Description', 'wordpress-seo' ); ?></a>
  94. </h2>
  95. <div class="tabwrapper">
  96. <?php wpseo_get_rendered_tab( $wpseo_bulk_titles_table, 'title' ); ?>
  97. <?php wpseo_get_rendered_tab( $wpseo_bulk_description_table, 'description' ); ?>
  98. </div>
  99. </div>