Make WordPress Core

Ticket #44676: 44676.diff

File 44676.diff, 5.1 KB (added by garrett-eclipse, 7 years ago)

Adds support for multiple requests via comma-separated list.

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

     
    684684                                                'error'
    685685                                        );
    686686                                }
    687                                 $action_type               = sanitize_text_field( wp_unslash( $_POST['type_of_action'] ) );
    688                                 $username_or_email_address = sanitize_text_field( wp_unslash( $_POST['username_or_email_for_privacy_request'] ) );
    689                                 $email_address             = '';
    690687
     688                                $count                  = 0;
     689                                $failure_count  = 0;
     690
     691                                $action_type = sanitize_text_field( wp_unslash( $_POST['type_of_action'] ) );
     692                               
    691693                                if ( ! in_array( $action_type, _wp_privacy_action_request_types(), true ) ) {
    692694                                        add_settings_error(
    693695                                                'action_type',
     
    697699                                        );
    698700                                }
    699701
    700                                 if ( ! is_email( $username_or_email_address ) ) {
    701                                         $user = get_user_by( 'login', $username_or_email_address );
    702                                         if ( ! $user instanceof WP_User ) {
    703                                                 add_settings_error(
    704                                                         'username_or_email_for_privacy_request',
    705                                                         'username_or_email_for_privacy_request',
    706                                                         __( 'Unable to add this request. A valid email address or username must be supplied.' ),
    707                                                         'error'
    708                                                 );
     702                                $username_or_email_for_privacy_request  = sanitize_text_field( wp_unslash( $_POST['username_or_email_for_privacy_request'] ) );
     703                                $usernames_or_email_addresses                   = explode( ',', $username_or_email_for_privacy_request );
     704
     705                                foreach ( $usernames_or_email_addresses as $username_or_email_address ) {
     706                                        $email_address = '';
     707
     708                                        if ( ! is_email( $username_or_email_address ) ) {
     709                                                $user = get_user_by( 'login', $username_or_email_address );
     710                                                if ( ! $user instanceof WP_User ) {
     711                                                        $failure_count++;
     712                                                        break;
     713                                                } else {
     714                                                        $email_address = $user->user_email;
     715                                                }
    709716                                        } else {
    710                                                 $email_address = $user->user_email;
     717                                                $email_address = $username_or_email_address;
    711718                                        }
    712                                 } else {
    713                                         $email_address = $username_or_email_address;
    714                                 }
    715719
    716                                 if ( empty( $email_address ) ) {
     720                                        if ( empty( $email_address ) ) {
     721                                                $failure_count++;
     722                                                break;
     723                                        }
     724
     725                                        $request_id = wp_create_user_request( $email_address, $action_type );
     726
     727                                        if ( ! $request_id || is_wp_error( $request_id ) ) {
     728                                                $failure_count++;
     729                                                break;
     730                                        }
     731
     732                                        $result = wp_send_user_request( $request_id );
     733
     734                                        if ( ! $result || is_wp_error( $result ) ) {
     735                                                $failure_count++;
     736                                                break;
     737                                        }
     738
     739                                        $count++;
    717740                                        break;
    718741                                }
    719742
    720                                 $request_id = wp_create_user_request( $email_address, $action_type );
    721 
    722                                 if ( is_wp_error( $request_id ) ) {
     743                                if ( $count ) {
    723744                                        add_settings_error(
    724745                                                'username_or_email_for_privacy_request',
    725746                                                'username_or_email_for_privacy_request',
    726                                                 $request_id->get_error_message(),
    727                                                 'error'
     747                                                /* translators: %d: number of requests */
     748                                                sprintf( _n( '%d confirmation request initiated successfully.', '%d confirmation requests initiated successfully.', $count ), $count ),
     749                                                'updated'
    728750                                        );
    729                                         break;
    730                                 } elseif ( ! $request_id ) {
     751                                }
     752
     753                                if ( $failure_count ) {
    731754                                        add_settings_error(
    732755                                                'username_or_email_for_privacy_request',
    733756                                                'username_or_email_for_privacy_request',
    734                                                 __( 'Unable to initiate confirmation request.' ),
    735                                                 'error'
     757                                                /* translators: %d: number of requests */
     758                                                sprintf( _n( 'Unable to initiate %d confirmation request.', 'Unable to initiate %d confirmation requests.', $count ), $count ),
     759                                                'updated'
    736760                                        );
    737                                         break;
    738761                                }
    739 
    740                                 wp_send_user_request( $request_id );
    741 
    742                                 add_settings_error(
    743                                         'username_or_email_for_privacy_request',
    744                                         'username_or_email_for_privacy_request',
    745                                         __( 'Confirmation request initiated successfully.' ),
    746                                         'updated'
    747                                 );
    748762                                break;
    749763                }
    750764        }
     
    822836
    823837                <form method="post" class="wp-privacy-request-form">
    824838                        <h2><?php esc_html_e( 'Add Data Export Request' ); ?></h2>
    825                         <p><?php esc_html_e( 'An email will be sent to the user at this email address asking them to verify the request.' ); ?></p>
     839                        <p><?php esc_html_e( 'An email will be sent to the user asking them to verify the request.' ); ?></p>
     840                        <p><?php esc_html_e( 'To trigger multiple requests supply the usernames or email addresses in a comma deliminated list.' ); ?></p>
    826841
    827842                        <div class="wp-privacy-request-form-field">
    828843                                <label for="username_or_email_for_privacy_request"><?php esc_html_e( 'Username or email address' ); ?></label>
     
    897912
    898913                <form method="post" class="wp-privacy-request-form">
    899914                        <h2><?php esc_html_e( 'Add Data Erasure Request' ); ?></h2>
    900                         <p><?php esc_html_e( 'An email will be sent to the user at this email address asking them to verify the request.' ); ?></p>
     915                        <p><?php esc_html_e( 'An email will be sent to the user asking them to verify the request.' ); ?></p>
     916                        <p><?php esc_html_e( 'To trigger multiple requests supply the usernames or email addresses in a comma deliminated list.' ); ?></p>
    901917
    902918                        <div class="wp-privacy-request-form-field">
    903919                                <label for="username_or_email_for_privacy_request"><?php esc_html_e( 'Username or email address' ); ?></label>