Make WordPress Core


Ignore:
Timestamp:
05/02/2018 12:02:01 AM (7 years ago)
Author:
SergeyBiryukov
Message:

Privacy: add means to erase personal data by username or email address. First run.

Props allendav, coreymckrill, ericdaams, azaozz.
Merges [42986] to the 4.9 branch.
See #43637, #43602.

Location:
branches/4.9
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/4.9

  • branches/4.9/src/wp-admin/includes/user.php

    r43073 r43075  
    543543 * Get action description from the name.
    544544 *
    545  * @since 5.0.0
     545 * @since 4.9.6
    546546 * @access private
    547547 *
     
    560560 * Log a request and send to the user.
    561561 *
    562  * @since 5.0.0
     562 * @since 4.9.6
    563563 * @access private
    564564 *
     
    600600 * Resend an existing request and return the result.
    601601 *
    602  * @since 5.0.0
     602 * @since 4.9.6
    603603 * @access private
    604604 *
     
    640640 * Marks a request as completed by the admin and logs the datetime.
    641641 *
    642  * @since 5.0.0
     642 * @since 4.9.6
    643643 * @access private
    644644 *
     
    665665 * Handle list table actions.
    666666 *
    667  * @since 5.0.0
     667 * @since 4.9.6
    668668 * @access private
    669669 */
    670670function _wp_personal_data_handle_actions() {
    671     if ( isset( $_POST['export_personal_data_email_retry'] ) ) { // WPCS: input var ok.
     671    if ( isset( $_POST['privacy_action_email_retry'] ) ) { // WPCS: input var ok.
    672672        check_admin_referer( 'bulk-privacy_requests' );
    673673
    674         $request_id = absint( current( array_keys( (array) wp_unslash( $_POST['export_personal_data_email_retry'] ) ) ) ); // WPCS: input var ok, sanitization ok.
     674        $request_id = absint( current( array_keys( (array) wp_unslash( $_POST['privacy_action_email_retry'] ) ) ) ); // WPCS: input var ok, sanitization ok.
    675675        $result     = _wp_privacy_resend_request( $request_id );
    676676
    677677        if ( is_wp_error( $result ) ) {
    678678            add_settings_error(
    679                 'export_personal_data_email_retry',
    680                 'export_personal_data_email_retry',
     679                'privacy_action_email_retry',
     680                'privacy_action_email_retry',
    681681                $result->get_error_message(),
    682682                'error'
     
    684684        } else {
    685685            add_settings_error(
    686                 'export_personal_data_email_retry',
    687                 'export_personal_data_email_retry',
     686                'privacy_action_email_retry',
     687                'privacy_action_email_retry',
    688688                __( 'Confirmation request re-resent successfully.' ),
    689689                'updated'
     
    797797 * Personal data export.
    798798 *
    799  * @since 5.0.0
     799 * @since 4.9.6
    800800 * @access private
    801801 */
     
    858858 * Personal data anonymization.
    859859 *
    860  * @since 5.0.0
     860 * @since 4.9.6
    861861 * @access private
    862862 */
    863863function _wp_personal_data_removal_page() {
    864     if ( ! current_user_can( 'manage_options' ) ) {
     864    if ( ! current_user_can( 'delete_users' ) ) {
    865865        wp_die( esc_html__( 'Sorry, you are not allowed to manage privacy on this site.' ) );
    866866    }
    867867
    868868    _wp_personal_data_handle_actions();
     869
     870    // "Borrow" xfn.js for now so we don't have to create new files.
     871    wp_enqueue_script( 'xfn' );
    869872
    870873    $requests_table = new WP_Privacy_Data_Removal_Requests_Table( array(
     
    872875        'singular' => 'privacy_request',
    873876    ) );
     877
    874878    $requests_table->process_bulk_action();
    875879    $requests_table->prepare_items();
     880
    876881    ?>
    877882    <div class="wrap nosubsub">
     
    919924 * Add requests pages.
    920925 *
    921  * @since 5.0.0
     926 * @since 4.9.6
    922927 * @access private
    923928 */
     
    942947     * e.g. 'export_personal_data'
    943948     *
    944      * @since 5.0.0
     949     * @since 4.9.6
    945950     *
    946951     * @var string $request_type Name of action.
     
    951956     * Post type to be used.
    952957     *
    953      * @since 5.0.0
     958     * @since 4.9.6
    954959     *
    955960     * @var string $post_type The post type.
     
    960965     * Get columns to show in the list table.
    961966     *
    962      * @since 5.0.0
     967     * @since 4.9.6
    963968     *
    964969     * @param array Array of columns.
     
    978983     * Get a list of sortable columns.
    979984     *
    980      * @since 5.0.0
     985     * @since 4.9.6
    981986     *
    982987     * @return array
     
    989994     * Default primary column.
    990995     *
    991      * @since 5.0.0
     996     * @since 4.9.6
    992997     *
    993998     * @return string
     
    10011006     * of views available on this table.
    10021007     *
    1003      * @since 5.0.0
     1008     * @since 4.9.6
    10041009     *
    10051010     * @return array
     
    10261031     * Get bulk actions.
    10271032     *
    1028      * @since 5.0.0
     1033     * @since 4.9.6
    10291034     *
    10301035     * @return array
     
    10401045     * Process bulk actions.
    10411046     *
    1042      * @since 5.0.0
     1047     * @since 4.9.6
    10431048     */
    10441049    public function process_bulk_action() {
     
    10891094     * Prepare items to output.
    10901095     *
    1091      * @since 5.0.0
     1096     * @since 4.9.6
    10921097     */
    10931098    public function prepare_items() {
     
    11541159     * Checkbox column.
    11551160     *
    1156      * @since 5.0.0
     1161     * @since 4.9.6
    11571162     *
    11581163     * @param array $item Item being shown.
     
    11661171     * Status column.
    11671172     *
    1168      * @since 5.0.0
     1173     * @since 4.9.6
    11691174     *
    11701175     * @param array $item Item being shown.
     
    12031208     * Convert timestamp for display.
    12041209     *
    1205      * @since 5.0.0
     1210     * @since 4.9.6
    12061211     *
    12071212     * @param int $timestamp Event timestamp.
     
    12251230     * Default column handler.
    12261231     *
    1227      * @since 5.0.0
     1232     * @since 4.9.6
    12281233     *
    12291234     * @param array $item         Item being shown.
     
    12441249     * Actions column. Overriden by children.
    12451250     *
    1246      * @since 5.0.0
     1251     * @since 4.9.6
    12471252     *
    12481253     * @param array $item Item being shown.
     
    12561261     * Next steps column. Overriden by children.
    12571262     *
    1258      * @since 5.0.0
     1263     * @since 4.9.6
    12591264     *
    12601265     * @param array $item Item being shown.
     
    12651270     * Generates content for a single row of the table
    12661271     *
    1267      * @since 5.0.0
     1272     * @since 4.9.6
    12681273     *
    12691274     * @param object $item The current item
     
    12801285     * Embed scripts used to perform actions. Overriden by children.
    12811286     *
    1282      * @since 5.0.0
     1287     * @since 4.9.6
    12831288     */
    12841289    public function embed_scripts() {}
     
    12881293 * WP_Privacy_Data_Export_Requests_Table class.
    12891294 *
    1290  * @since 5.0.0
     1295 * @since 4.9.6
    12911296 */
    12921297class WP_Privacy_Data_Export_Requests_Table extends WP_Privacy_Requests_Table {
     
    12941299     * Action name for the requests this table will work with.
    12951300     *
    1296      * @since 5.0.0
     1301     * @since 4.9.6
    12971302     *
    12981303     * @var string $request_type Name of action.
     
    13031308     * Post type for the requests.
    13041309     *
    1305      * @since 5.0.0
     1310     * @since 4.9.6
    13061311     *
    13071312     * @var string $post_type The post type.
     
    13121317     * Actions column.
    13131318     *
    1314      * @since 5.0.0
     1319     * @since 4.9.6
    13151320     *
    13161321     * @param array $item Item being shown.
     
    13181323     */
    13191324    public function column_email( $item ) {
     1325        $exporters       = apply_filters( 'wp_privacy_personal_data_exporters', array() );
     1326        $exporters_count = count( $exporters );
     1327        $request_id      = $item['request_id'];
     1328        $nonce           = wp_create_nonce( 'wp-privacy-export-personal-data-' . $request_id );
     1329
     1330        $download_data_markup = '<div class="download_personal_data" ' .
     1331            'data-exporters-count="' . esc_attr( $exporters_count ) . '" ' .
     1332            'data-request-id="' . esc_attr( $request_id ) . '" ' .
     1333            'data-nonce="' . esc_attr( $nonce ) .
     1334            '">';
     1335
     1336        $download_data_markup .= '<span class="download_personal_data_idle"><a href="#" >' . __( 'Download Personal Data' ) . '</a></span>' .
     1337            '<span style="display:none" class="download_personal_data_processing" >' . __( 'Downloading Data...' ) . '</span>' .
     1338            '<span style="display:none" class="download_personal_data_failed">' . __( 'Download Failed!' ) . ' <a href="#" >' . __( 'Retry' ) . '</a></span>';
     1339
    13201340        $row_actions = array(
    1321             'download_data' => __( 'Download Personal Data' ),
     1341            'download_data' => $download_data_markup,
    13221342        );
    13231343
     
    13281348     * Next steps column.
    13291349     *
    1330      * @since 5.0.0
     1350     * @since 4.9.6
    13311351     *
    13321352     * @param array $item Item being shown.
     
    13431363                break;
    13441364            case 'request-failed':
    1345                 submit_button( __( 'Retry' ), 'secondary', 'export_personal_data_email_retry[' . $item['request_id'] . ']', false );
     1365                submit_button( __( 'Retry' ), 'secondary', 'privacy_action_email_retry[' . $item['request_id'] . ']', false );
    13461366                break;
    13471367            case 'request-completed':
     
    13581378 * WP_Privacy_Data_Removal_Requests_Table class.
    13591379 *
    1360      * @since 5.0.0
     1380     * @since 4.9.6
    13611381 */
    13621382class WP_Privacy_Data_Removal_Requests_Table extends WP_Privacy_Requests_Table {
     
    13641384     * Action name for the requests this table will work with.
    13651385     *
    1366      * @since 5.0.0
     1386     * @since 4.9.6
    13671387     *
    13681388     * @var string $request_type Name of action.
     
    13731393     * Post type for the requests.
    13741394     *
    1375      * @since 5.0.0
     1395     * @since 4.9.6
    13761396     *
    13771397     * @var string $post_type The post type.
     
    13821402     * Actions column.
    13831403     *
    1384      * @since 5.0.0
     1404     * @since 4.9.6
    13851405     *
    13861406     * @param array $item Item being shown.
     
    13881408     */
    13891409    public function column_email( $item ) {
    1390         $row_actions = array(
    1391             // TODO Complete in follow on patch.
    1392             'remove_data' => __( 'Remove Personal Data' ),
    1393         );
    1394 
    1395         // If we have a user ID, include a delete user action.
    1396         if ( ! empty( $item['user_id'] ) ) {
    1397             // TODO Complete in follow on patch.
    1398             $row_actions['delete_user'] = __( 'Delete User' );
     1410        $row_actions = array();
     1411
     1412        // Allow the administrator to "force remove" the personal data even if confirmation has not yet been received
     1413        $status = get_post_status( $item['request_id'] );
     1414        if ( 'request-confirmed' !== $status ) {
     1415            $erasers       = apply_filters( 'wp_privacy_personal_data_erasers', array() );
     1416            $erasers_count = count( $erasers );
     1417            $request_id    = $item['request_id'];
     1418            $nonce         = wp_create_nonce( 'wp-privacy-erase-personal-data-' . $request_id );
     1419
     1420            $remove_data_markup = '<div class="remove_personal_data force_remove_personal_data" ' .
     1421                'data-erasers-count="' . esc_attr( $erasers_count ) . '" ' .
     1422                'data-request-id="' . esc_attr( $request_id ) . '" ' .
     1423                'data-nonce="' . esc_attr( $nonce ) .
     1424                '">';
     1425
     1426            $remove_data_markup .= '<span class="remove_personal_data_idle"><a href="#" >' . __( 'Force Remove Personal Data' ) . '</a></span>' .
     1427                '<span style="display:none" class="remove_personal_data_processing" >' . __( 'Removing Data...' ) . '</span>' .
     1428                '<span style="display:none" class="remove_personal_data_failed">' . __( 'Force Remove Failed!' ) . ' <a href="#" >' . __( 'Retry' ) . '</a></span>';
     1429
     1430            $row_actions = array(
     1431                'remove_data' => $remove_data_markup,
     1432            );
    13991433        }
    14001434
     
    14051439     * Next steps column.
    14061440     *
    1407      * @since 5.0.0
     1441     * @since 4.9.6
    14081442     *
    14091443     * @param array $item Item being shown.
    14101444     */
    14111445    public function column_next_steps( $item ) {
    1412     }
    1413 
    1414 }
     1446        $status = get_post_status( $item['request_id'] );
     1447
     1448        switch ( $status ) {
     1449            case 'request-pending':
     1450                esc_html_e( 'Waiting for confirmation' );
     1451                break;
     1452            case 'request-confirmed':
     1453                $erasers       = apply_filters( 'wp_privacy_personal_data_erasers', array() );
     1454                $erasers_count = count( $erasers );
     1455                $request_id    = $item['request_id'];
     1456                $nonce         = wp_create_nonce( 'wp-privacy-erase-personal-data-' . $request_id );
     1457
     1458                echo '<div class="remove_personal_data" ' .
     1459                    'data-force-erase="1" ' .
     1460                    'data-erasers-count="' . esc_attr( $erasers_count ) . '" ' .
     1461                    'data-request-id="' . esc_attr( $request_id ) . '" ' .
     1462                    'data-nonce="' . esc_attr( $nonce ) .
     1463                    '">';
     1464
     1465                ?>
     1466                <span class="remove_personal_data_idle"><a class="button" href="#" ><?php _e( 'Remove Personal Data' ); ?></a></span>
     1467                <span style="display:none" class="remove_personal_data_processing button updating-message" ><?php _e( 'Removing Data...' ); ?></span>
     1468                <span style="display:none" class="remove_personal_data_failed"><?php _e( 'Removing Data Failed!' ); ?> <a class="button" href="#" ><?php _e( 'Retry' ); ?></a></span>
     1469                <?php
     1470
     1471                break;
     1472            case 'request-failed':
     1473                submit_button( __( 'Retry' ), 'secondary', 'privacy_action_email_retry[' . $item['request_id'] . ']', false );
     1474                break;
     1475            case 'request-completed':
     1476                echo '<a href="' . esc_url( wp_nonce_url( add_query_arg( array(
     1477                    'action' => 'delete',
     1478                    'request_id' => array( $item['request_id'] ),
     1479                ), admin_url( 'tools.php?page=remove_personal_data' ) ), 'bulk-privacy_requests' ) ) . '">' . esc_html__( 'Remove request' ) . '</a>';
     1480                break;
     1481        }
     1482    }
     1483
     1484}
Note: See TracChangeset for help on using the changeset viewer.