class-wp-privacy-data-removal-requests-list-table.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. <?php
  2. /**
  3. * List Table API: WP_Privacy_Data_Removal_Requests_List_Table class
  4. *
  5. * @package WordPress
  6. * @subpackage Administration
  7. * @since 4.9.6
  8. */
  9. if ( ! class_exists( 'WP_Privacy_Requests_Table' ) ) {
  10. require_once( ABSPATH . 'wp-admin/includes/class-wp-privacy-requests-table.php' );
  11. }
  12. /**
  13. * WP_Privacy_Data_Removal_Requests_List_Table class.
  14. *
  15. * @since 4.9.6
  16. */
  17. class WP_Privacy_Data_Removal_Requests_List_Table extends WP_Privacy_Requests_Table {
  18. /**
  19. * Action name for the requests this table will work with.
  20. *
  21. * @since 4.9.6
  22. *
  23. * @var string $request_type Name of action.
  24. */
  25. protected $request_type = 'remove_personal_data';
  26. /**
  27. * Post type for the requests.
  28. *
  29. * @since 4.9.6
  30. *
  31. * @var string $post_type The post type.
  32. */
  33. protected $post_type = 'user_request';
  34. /**
  35. * Actions column.
  36. *
  37. * @since 4.9.6
  38. *
  39. * @param WP_User_Request $item Item being shown.
  40. * @return string Email column markup.
  41. */
  42. public function column_email( $item ) {
  43. $row_actions = array();
  44. // Allow the administrator to "force remove" the personal data even if confirmation has not yet been received.
  45. $status = $item->status;
  46. if ( 'request-confirmed' !== $status ) {
  47. /** This filter is documented in wp-admin/includes/ajax-actions.php */
  48. $erasers = apply_filters( 'wp_privacy_personal_data_erasers', array() );
  49. $erasers_count = count( $erasers );
  50. $request_id = $item->ID;
  51. $nonce = wp_create_nonce( 'wp-privacy-erase-personal-data-' . $request_id );
  52. $remove_data_markup = '<div class="remove-personal-data force-remove-personal-data" ' .
  53. 'data-erasers-count="' . esc_attr( $erasers_count ) . '" ' .
  54. 'data-request-id="' . esc_attr( $request_id ) . '" ' .
  55. 'data-nonce="' . esc_attr( $nonce ) .
  56. '">';
  57. $remove_data_markup .= '<span class="remove-personal-data-idle"><button type="button" class="button-link remove-personal-data-handle">' . __( 'Force Erase Personal Data' ) . '</button></span>' .
  58. '<span class="remove-personal-data-processing hidden">' . __( 'Erasing Data...' ) . '</span>' .
  59. '<span class="remove-personal-data-success hidden">' . __( 'Erasure completed.' ) . '</span>' .
  60. '<span class="remove-personal-data-failed hidden">' . __( 'Force Erasure has failed.' ) . ' <button type="button" class="button-link remove-personal-data-handle">' . __( 'Retry' ) . '</button></span>';
  61. $remove_data_markup .= '</div>';
  62. $row_actions = array(
  63. 'remove-data' => $remove_data_markup,
  64. );
  65. }
  66. return sprintf( '<a href="%1$s">%2$s</a> %3$s', esc_url( 'mailto:' . $item->email ), $item->email, $this->row_actions( $row_actions ) );
  67. }
  68. /**
  69. * Next steps column.
  70. *
  71. * @since 4.9.6
  72. *
  73. * @param WP_User_Request $item Item being shown.
  74. */
  75. public function column_next_steps( $item ) {
  76. $status = $item->status;
  77. switch ( $status ) {
  78. case 'request-pending':
  79. esc_html_e( 'Waiting for confirmation' );
  80. break;
  81. case 'request-confirmed':
  82. /** This filter is documented in wp-admin/includes/ajax-actions.php */
  83. $erasers = apply_filters( 'wp_privacy_personal_data_erasers', array() );
  84. $erasers_count = count( $erasers );
  85. $request_id = $item->ID;
  86. $nonce = wp_create_nonce( 'wp-privacy-erase-personal-data-' . $request_id );
  87. echo '<div class="remove-personal-data" ' .
  88. 'data-force-erase="1" ' .
  89. 'data-erasers-count="' . esc_attr( $erasers_count ) . '" ' .
  90. 'data-request-id="' . esc_attr( $request_id ) . '" ' .
  91. 'data-nonce="' . esc_attr( $nonce ) .
  92. '">';
  93. ?>
  94. <span class="remove-personal-data-idle"><button type="button" class="button remove-personal-data-handle"><?php _e( 'Erase Personal Data' ); ?></button></span>
  95. <span class="remove-personal-data-processing button updating-message hidden"><?php _e( 'Erasing Data...' ); ?></span>
  96. <span class="remove-personal-data-success success-message hidden" ><?php _e( 'Erasure completed.' ); ?></span>
  97. <span class="remove-personal-data-failed hidden"><?php _e( 'Data Erasure has failed.' ); ?> <button type="button" class="button remove-personal-data-handle"><?php _e( 'Retry' ); ?></button></span>
  98. <?php
  99. echo '</div>';
  100. break;
  101. case 'request-failed':
  102. submit_button( __( 'Retry' ), 'secondary', 'privacy_action_email_retry[' . $item->ID . ']', false );
  103. break;
  104. case 'request-completed':
  105. echo '<a href="' . esc_url(
  106. wp_nonce_url(
  107. add_query_arg(
  108. array(
  109. 'action' => 'delete',
  110. 'request_id' => array( $item->ID ),
  111. ),
  112. admin_url( 'erase-personal-data.php' )
  113. ),
  114. 'bulk-privacy_requests'
  115. )
  116. ) . '" class="button">' . esc_html__( 'Remove request' ) . '</a>';
  117. break;
  118. }
  119. }
  120. }