class-wp-privacy-data-export-requests-list-table.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <?php
  2. /**
  3. * List Table API: WP_Privacy_Data_Export_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_Export_Requests_Table class.
  14. *
  15. * @since 4.9.6
  16. */
  17. class WP_Privacy_Data_Export_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 = 'export_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. /** This filter is documented in wp-admin/includes/ajax-actions.php */
  44. $exporters = apply_filters( 'wp_privacy_personal_data_exporters', array() );
  45. $exporters_count = count( $exporters );
  46. $request_id = $item->ID;
  47. $nonce = wp_create_nonce( 'wp-privacy-export-personal-data-' . $request_id );
  48. $download_data_markup = '<div class="export-personal-data" ' .
  49. 'data-exporters-count="' . esc_attr( $exporters_count ) . '" ' .
  50. 'data-request-id="' . esc_attr( $request_id ) . '" ' .
  51. 'data-nonce="' . esc_attr( $nonce ) .
  52. '">';
  53. $download_data_markup .= '<span class="export-personal-data-idle"><button type="button" class="button-link export-personal-data-handle">' . __( 'Download Personal Data' ) . '</button></span>' .
  54. '<span class="export-personal-data-processing hidden">' . __( 'Downloading Data...' ) . '</span>' .
  55. '<span class="export-personal-data-success hidden"><button type="button" class="button-link export-personal-data-handle">' . __( 'Download Personal Data Again' ) . '</button></span>' .
  56. '<span class="export-personal-data-failed hidden">' . __( 'Download failed.' ) . ' <button type="button" class="button-link">' . __( 'Retry' ) . '</button></span>';
  57. $download_data_markup .= '</div>';
  58. $row_actions = array(
  59. 'download-data' => $download_data_markup,
  60. );
  61. return sprintf( '<a href="%1$s">%2$s</a> %3$s', esc_url( 'mailto:' . $item->email ), $item->email, $this->row_actions( $row_actions ) );
  62. }
  63. /**
  64. * Displays the next steps column.
  65. *
  66. * @since 4.9.6
  67. *
  68. * @param WP_User_Request $item Item being shown.
  69. */
  70. public function column_next_steps( $item ) {
  71. $status = $item->status;
  72. switch ( $status ) {
  73. case 'request-pending':
  74. esc_html_e( 'Waiting for confirmation' );
  75. break;
  76. case 'request-confirmed':
  77. /** This filter is documented in wp-admin/includes/ajax-actions.php */
  78. $exporters = apply_filters( 'wp_privacy_personal_data_exporters', array() );
  79. $exporters_count = count( $exporters );
  80. $request_id = $item->ID;
  81. $nonce = wp_create_nonce( 'wp-privacy-export-personal-data-' . $request_id );
  82. echo '<div class="export-personal-data" ' .
  83. 'data-send-as-email="1" ' .
  84. 'data-exporters-count="' . esc_attr( $exporters_count ) . '" ' .
  85. 'data-request-id="' . esc_attr( $request_id ) . '" ' .
  86. 'data-nonce="' . esc_attr( $nonce ) .
  87. '">';
  88. ?>
  89. <span class="export-personal-data-idle"><button type="button" class="button export-personal-data-handle"><?php _e( 'Send Export Link' ); ?></button></span>
  90. <span class="export-personal-data-processing button updating-message hidden"><?php _e( 'Sending Email...' ); ?></span>
  91. <span class="export-personal-data-success success-message hidden"><?php _e( 'Email sent.' ); ?></span>
  92. <span class="export-personal-data-failed hidden"><?php _e( 'Email could not be sent.' ); ?> <button type="button" class="button export-personal-data-handle"><?php _e( 'Retry' ); ?></button></span>
  93. <?php
  94. echo '</div>';
  95. break;
  96. case 'request-failed':
  97. submit_button( __( 'Retry' ), 'secondary', 'privacy_action_email_retry[' . $item->ID . ']', false );
  98. break;
  99. case 'request-completed':
  100. echo '<a href="' . esc_url(
  101. wp_nonce_url(
  102. add_query_arg(
  103. array(
  104. 'action' => 'delete',
  105. 'request_id' => array( $item->ID ),
  106. ),
  107. admin_url( 'export-personal-data.php' )
  108. ),
  109. 'bulk-privacy_requests'
  110. )
  111. ) . '" class="button">' . esc_html__( 'Remove request' ) . '</a>';
  112. break;
  113. }
  114. }
  115. }