Make WordPress Core


Ignore:
Timestamp:
04/18/2018 10:29:59 PM (8 years ago)
Author:
azaozz
Message:

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

Props allendav, coreymckrill, ericdaams, azaozz.
See #43637, #43602.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/user.php

    r42977 r42986  
    584584 * Get action description from the name.
    585585 *
    586  * @since 5.0.0
     586 * @since 4.9.6
    587587 * @access private
    588588 *
     
    601601 * Log a request and send to the user.
    602602 *
    603  * @since 5.0.0
     603 * @since 4.9.6
    604604 * @access private
    605605 *
     
    641641 * Resend an existing request and return the result.
    642642 *
    643  * @since 5.0.0
     643 * @since 4.9.6
    644644 * @access private
    645645 *
     
    681681 * Marks a request as completed by the admin and logs the datetime.
    682682 *
    683  * @since 5.0.0
     683 * @since 4.9.6
    684684 * @access private
    685685 *
     
    706706 * Handle list table actions.
    707707 *
    708  * @since 5.0.0
     708 * @since 4.9.6
    709709 * @access private
    710710 */
    711711function _wp_personal_data_handle_actions() {
    712         if ( isset( $_POST['export_personal_data_email_retry'] ) ) { // WPCS: input var ok.
     712        if ( isset( $_POST['privacy_action_email_retry'] ) ) { // WPCS: input var ok.
    713713                check_admin_referer( 'bulk-privacy_requests' );
    714714
    715                 $request_id = absint( current( array_keys( (array) wp_unslash( $_POST['export_personal_data_email_retry'] ) ) ) ); // WPCS: input var ok, sanitization ok.
     715                $request_id = absint( current( array_keys( (array) wp_unslash( $_POST['privacy_action_email_retry'] ) ) ) ); // WPCS: input var ok, sanitization ok.
    716716                $result     = _wp_privacy_resend_request( $request_id );
    717717
    718718                if ( is_wp_error( $result ) ) {
    719719                        add_settings_error(
    720                                 'export_personal_data_email_retry',
    721                                 'export_personal_data_email_retry',
     720                                'privacy_action_email_retry',
     721                                'privacy_action_email_retry',
    722722                                $result->get_error_message(),
    723723                                'error'
     
    725725                } else {
    726726                        add_settings_error(
    727                                 'export_personal_data_email_retry',
    728                                 'export_personal_data_email_retry',
     727                                'privacy_action_email_retry',
     728                                'privacy_action_email_retry',
    729729                                __( 'Confirmation request re-resent successfully.' ),
    730730                                'updated'
     
    838838 * Personal data export.
    839839 *
    840  * @since 5.0.0
     840 * @since 4.9.6
    841841 * @access private
    842842 */
     
    899899 * Personal data anonymization.
    900900 *
    901  * @since 5.0.0
     901 * @since 4.9.6
    902902 * @access private
    903903 */
    904904function _wp_personal_data_removal_page() {
    905         if ( ! current_user_can( 'manage_options' ) ) {
     905        if ( ! current_user_can( 'delete_users' ) ) {
    906906                wp_die( esc_html__( 'Sorry, you are not allowed to manage privacy on this site.' ) );
    907907        }
    908908
    909909        _wp_personal_data_handle_actions();
     910
     911        // "Borrow" xfn.js for now so we don't have to create new files.
     912        wp_enqueue_script( 'xfn' );
    910913
    911914        $requests_table = new WP_Privacy_Data_Removal_Requests_Table( array(
     
    913916                'singular' => 'privacy_request',
    914917        ) );
     918
    915919        $requests_table->process_bulk_action();
    916920        $requests_table->prepare_items();
     921
    917922        ?>
    918923        <div class="wrap nosubsub">
     
    960965 * Add requests pages.
    961966 *
    962  * @since 5.0.0
     967 * @since 4.9.6
    963968 * @access private
    964969 */
     
    983988         * e.g. 'export_personal_data'
    984989         *
    985          * @since 5.0.0
     990         * @since 4.9.6
    986991         *
    987992         * @var string $request_type Name of action.
     
    992997         * Post type to be used.
    993998         *
    994          * @since 5.0.0
     999         * @since 4.9.6
    9951000         *
    9961001         * @var string $post_type The post type.
     
    10011006         * Get columns to show in the list table.
    10021007         *
    1003          * @since 5.0.0
     1008         * @since 4.9.6
    10041009         *
    10051010         * @param array Array of columns.
     
    10191024         * Get a list of sortable columns.
    10201025         *
    1021          * @since 5.0.0
     1026         * @since 4.9.6
    10221027         *
    10231028         * @return array
     
    10301035         * Default primary column.
    10311036         *
    1032          * @since 5.0.0
     1037         * @since 4.9.6
    10331038         *
    10341039         * @return string
     
    10421047         * of views available on this table.
    10431048         *
    1044          * @since 5.0.0
     1049         * @since 4.9.6
    10451050         *
    10461051         * @return array
     
    10671072         * Get bulk actions.
    10681073         *
    1069          * @since 5.0.0
     1074         * @since 4.9.6
    10701075         *
    10711076         * @return array
     
    10811086         * Process bulk actions.
    10821087         *
    1083          * @since 5.0.0
     1088         * @since 4.9.6
    10841089         */
    10851090        public function process_bulk_action() {
     
    11301135         * Prepare items to output.
    11311136         *
    1132          * @since 5.0.0
     1137         * @since 4.9.6
    11331138         */
    11341139        public function prepare_items() {
     
    11951200         * Checkbox column.
    11961201         *
    1197          * @since 5.0.0
     1202         * @since 4.9.6
    11981203         *
    11991204         * @param array $item Item being shown.
     
    12071212         * Status column.
    12081213         *
    1209          * @since 5.0.0
     1214         * @since 4.9.6
    12101215         *
    12111216         * @param array $item Item being shown.
     
    12441249         * Convert timestamp for display.
    12451250         *
    1246          * @since 5.0.0
     1251         * @since 4.9.6
    12471252         *
    12481253         * @param int $timestamp Event timestamp.
     
    12661271         * Default column handler.
    12671272         *
    1268          * @since 5.0.0
     1273         * @since 4.9.6
    12691274         *
    12701275         * @param array $item         Item being shown.
     
    12851290         * Actions column. Overriden by children.
    12861291         *
    1287          * @since 5.0.0
     1292         * @since 4.9.6
    12881293         *
    12891294         * @param array $item Item being shown.
     
    12971302         * Next steps column. Overriden by children.
    12981303         *
    1299          * @since 5.0.0
     1304         * @since 4.9.6
    13001305         *
    13011306         * @param array $item Item being shown.
     
    13061311         * Generates content for a single row of the table
    13071312         *
    1308          * @since 5.0.0
     1313         * @since 4.9.6
    13091314         *
    13101315         * @param object $item The current item
     
    13211326         * Embed scripts used to perform actions. Overriden by children.
    13221327         *
    1323          * @since 5.0.0
     1328         * @since 4.9.6
    13241329         */
    13251330        public function embed_scripts() {}
     
    13291334 * WP_Privacy_Data_Export_Requests_Table class.
    13301335 *
    1331  * @since 5.0.0
     1336 * @since 4.9.6
    13321337 */
    13331338class WP_Privacy_Data_Export_Requests_Table extends WP_Privacy_Requests_Table {
     
    13351340         * Action name for the requests this table will work with.
    13361341         *
    1337          * @since 5.0.0
     1342         * @since 4.9.6
    13381343         *
    13391344         * @var string $request_type Name of action.
     
    13441349         * Post type for the requests.
    13451350         *
    1346          * @since 5.0.0
     1351         * @since 4.9.6
    13471352         *
    13481353         * @var string $post_type The post type.
     
    13531358         * Actions column.
    13541359         *
    1355          * @since 5.0.0
     1360         * @since 4.9.6
    13561361         *
    13571362         * @param array $item Item being shown.
     
    13591364         */
    13601365        public function column_email( $item ) {
     1366                $exporters       = apply_filters( 'wp_privacy_personal_data_exporters', array() );
     1367                $exporters_count = count( $exporters );
     1368                $request_id      = $item['request_id'];
     1369                $nonce           = wp_create_nonce( 'wp-privacy-export-personal-data-' . $request_id );
     1370
     1371                $download_data_markup = '<div class="download_personal_data" ' .
     1372                        'data-exporters-count="' . esc_attr( $exporters_count ) . '" ' .
     1373                        'data-request-id="' . esc_attr( $request_id ) . '" ' .
     1374                        'data-nonce="' . esc_attr( $nonce ) .
     1375                        '">';
     1376
     1377                $download_data_markup .= '<span class="download_personal_data_idle"><a href="#" >' . __( 'Download Personal Data' ) . '</a></span>' .
     1378                        '<span style="display:none" class="download_personal_data_processing" >' . __( 'Downloading Data...' ) . '</span>' .
     1379                        '<span style="display:none" class="download_personal_data_failed">' . __( 'Download Failed!' ) . ' <a href="#" >' . __( 'Retry' ) . '</a></span>';
     1380
    13611381                $row_actions = array(
    1362                         'download_data' => __( 'Download Personal Data' ),
     1382                        'download_data' => $download_data_markup,
    13631383                );
    13641384
     
    13691389         * Next steps column.
    13701390         *
    1371          * @since 5.0.0
     1391         * @since 4.9.6
    13721392         *
    13731393         * @param array $item Item being shown.
     
    13841404                                break;
    13851405                        case 'request-failed':
    1386                                 submit_button( __( 'Retry' ), 'secondary', 'export_personal_data_email_retry[' . $item['request_id'] . ']', false );
     1406                                submit_button( __( 'Retry' ), 'secondary', 'privacy_action_email_retry[' . $item['request_id'] . ']', false );
    13871407                                break;
    13881408                        case 'request-completed':
     
    13991419 * WP_Privacy_Data_Removal_Requests_Table class.
    14001420 *
    1401          * @since 5.0.0
     1421         * @since 4.9.6
    14021422 */
    14031423class WP_Privacy_Data_Removal_Requests_Table extends WP_Privacy_Requests_Table {
     
    14051425         * Action name for the requests this table will work with.
    14061426         *
    1407          * @since 5.0.0
     1427         * @since 4.9.6
    14081428         *
    14091429         * @var string $request_type Name of action.
     
    14141434         * Post type for the requests.
    14151435         *
    1416          * @since 5.0.0
     1436         * @since 4.9.6
    14171437         *
    14181438         * @var string $post_type The post type.
     
    14231443         * Actions column.
    14241444         *
    1425          * @since 5.0.0
     1445         * @since 4.9.6
    14261446         *
    14271447         * @param array $item Item being shown.
     
    14291449         */
    14301450        public function column_email( $item ) {
    1431                 $row_actions = array(
    1432                         // TODO Complete in follow on patch.
    1433                         'remove_data' => __( 'Remove Personal Data' ),
    1434                 );
    1435 
    1436                 // If we have a user ID, include a delete user action.
    1437                 if ( ! empty( $item['user_id'] ) ) {
    1438                         // TODO Complete in follow on patch.
    1439                         $row_actions['delete_user'] = __( 'Delete User' );
     1451                $row_actions = array();
     1452
     1453                // Allow the administrator to "force remove" the personal data even if confirmation has not yet been received
     1454                $status = get_post_status( $item['request_id'] );
     1455                if ( 'request-confirmed' !== $status ) {
     1456                        $erasers       = apply_filters( 'wp_privacy_personal_data_erasers', array() );
     1457                        $erasers_count = count( $erasers );
     1458                        $request_id    = $item['request_id'];
     1459                        $nonce         = wp_create_nonce( 'wp-privacy-erase-personal-data-' . $request_id );
     1460
     1461                        $remove_data_markup = '<div class="remove_personal_data force_remove_personal_data" ' .
     1462                                'data-erasers-count="' . esc_attr( $erasers_count ) . '" ' .
     1463                                'data-request-id="' . esc_attr( $request_id ) . '" ' .
     1464                                'data-nonce="' . esc_attr( $nonce ) .
     1465                                '">';
     1466
     1467                        $remove_data_markup .= '<span class="remove_personal_data_idle"><a href="#" >' . __( 'Force Remove Personal Data' ) . '</a></span>' .
     1468                                '<span style="display:none" class="remove_personal_data_processing" >' . __( 'Removing Data...' ) . '</span>' .
     1469                                '<span style="display:none" class="remove_personal_data_failed">' . __( 'Force Remove Failed!' ) . ' <a href="#" >' . __( 'Retry' ) . '</a></span>';
     1470
     1471                        $row_actions = array(
     1472                                'remove_data' => $remove_data_markup,
     1473                        );
    14401474                }
    14411475
     
    14461480         * Next steps column.
    14471481         *
    1448          * @since 5.0.0
     1482         * @since 4.9.6
    14491483         *
    14501484         * @param array $item Item being shown.
    14511485         */
    14521486        public function column_next_steps( $item ) {
    1453         }
    1454 
    1455 }
     1487                $status = get_post_status( $item['request_id'] );
     1488
     1489                switch ( $status ) {
     1490                        case 'request-pending':
     1491                                esc_html_e( 'Waiting for confirmation' );
     1492                                break;
     1493                        case 'request-confirmed':
     1494                                $erasers       = apply_filters( 'wp_privacy_personal_data_erasers', array() );
     1495                                $erasers_count = count( $erasers );
     1496                                $request_id    = $item['request_id'];
     1497                                $nonce         = wp_create_nonce( 'wp-privacy-erase-personal-data-' . $request_id );
     1498
     1499                                echo '<div class="remove_personal_data" ' .
     1500                                        'data-force-erase="1" ' .
     1501                                        'data-erasers-count="' . esc_attr( $erasers_count ) . '" ' .
     1502                                        'data-request-id="' . esc_attr( $request_id ) . '" ' .
     1503                                        'data-nonce="' . esc_attr( $nonce ) .
     1504                                        '">';
     1505
     1506                                ?>
     1507                                <span class="remove_personal_data_idle"><a class="button" href="#" ><?php _e( 'Remove Personal Data' ); ?></a></span>
     1508                                <span style="display:none" class="remove_personal_data_processing button updating-message" ><?php _e( 'Removing Data...' ); ?></span>
     1509                                <span style="display:none" class="remove_personal_data_failed"><?php _e( 'Removing Data Failed!' ); ?> <a class="button" href="#" ><?php _e( 'Retry' ); ?></a></span>
     1510                                <?php
     1511
     1512                                break;
     1513                        case 'request-failed':
     1514                                submit_button( __( 'Retry' ), 'secondary', 'privacy_action_email_retry[' . $item['request_id'] . ']', false );
     1515                                break;
     1516                        case 'request-completed':
     1517                                echo '<a href="' . esc_url( wp_nonce_url( add_query_arg( array(
     1518                                        'action' => 'delete',
     1519                                        'request_id' => array( $item['request_id'] ),
     1520                                ), admin_url( 'tools.php?page=remove_personal_data' ) ), 'bulk-privacy_requests' ) ) . '">' . esc_html__( 'Remove request' ) . '</a>';
     1521                                break;
     1522                }
     1523        }
     1524
     1525}
Note: See TracChangeset for help on using the changeset viewer.