Ticket #7826: 7826.01.patch
File 7826.01.patch, 14.6 KB (added by , 6 years ago) |
---|
-
new file src/bp-settings/actions/data.php
new file mode 100644
- + 1 <?php 2 /** 3 * Settings: Data management action handler 4 * 5 * @package BuddyPress 6 * @subpackage SettingsActions 7 * @since 3.1.0 8 */ 9 10 /** 11 * Data export request handler. 12 * 13 * @since 3.1.0 14 */ 15 add_action( 'bp_actions', function() { 16 if ( ! bp_is_post_request() || ! bp_displayed_user_id() || empty( $_POST['bp-data-export-nonce'] ) ) { 17 return; 18 } 19 20 // Nonce check. 21 check_admin_referer( 'bp-data-export', 'bp-data-export-nonce' ); 22 23 // Create the user request. 24 $request_id = wp_create_user_request( buddypress()->displayed_user->userdata->user_email, 'export_personal_data' ); 25 26 $success = true; 27 if ( is_wp_error( $request_id ) ) { 28 $success = false; 29 $message = $request_id->get_error_message(); 30 } elseif ( ! $request_id ) { 31 $success = false; 32 $message = __( 'We were unable to generate the data export request.', 'buddypress' ); 33 } 34 35 /* 36 * Auto-confirm the user request since the user already consented by 37 * submitting our form. 38 */ 39 if ( $success ) { 40 /** This hook is documented in /wp-login.php */ 41 do_action( 'user_request_action_confirmed', $request_id ); 42 43 $message = __( 'Data export request successfully created', 'buddypress' ); 44 } 45 46 bp_core_add_message( $message, $success ? 'success' : 'error' ); 47 bp_core_redirect( bp_get_requested_url() ); 48 } ); 49 No newline at end of file -
src/bp-settings/classes/class-bp-settings-component.php
65 65 return; 66 66 } 67 67 68 $actions = array( 'notifications', 'capabilities', 'd elete-account' );68 $actions = array( 'notifications', 'capabilities', 'data', 'delete-account' ); 69 69 70 70 // Authenticated actions. 71 71 if ( is_user_logged_in() ) { … … 182 182 ); 183 183 } 184 184 185 /** 186 * Filter whether the site should show the "Settings > Data" page. 187 * 188 * @since 3.1.0 189 * 190 * @param bool $show Defaults to true. 191 */ 192 $show_data_page = apply_filters( 'bp_settings_show_user_data_page', true ); 193 194 // Data Management - only available for WP 4.9.6+ 195 if ( true === $show_data_page && function_exists( 'wp_register_user_personal_data_exporter' ) ) { 196 $sub_nav[] = array( 197 'name' => __( 'Data Management', 'buddypress' ), 198 'slug' => 'data', 199 'parent_url' => $settings_link, 200 'parent_slug' => $slug, 201 'screen_function' => 'bp_settings_screen_data', 202 'position' => 89, 203 'user_has_access' => $access 204 ); 205 } 206 185 207 // Add Delete Account nav item. 186 208 if ( ( ! bp_disable_account_deletion() && bp_is_my_profile() ) || bp_current_user_can( 'delete_users' ) ) { 187 209 $sub_nav[] = array( … … 241 263 ); 242 264 } 243 265 266 /** This filter is documented in bp-settings/classes/class-bp-settings-component.php */ 267 $show_data_page = apply_filters( 'bp_settings_show_user_data_page', true ); 268 269 // Data Management. 270 if ( true === $show_data_page && function_exists( 'wp_register_user_personal_data_exporter' ) ) { 271 $wp_admin_nav[] = array( 272 'parent' => 'my-account-' . $this->id, 273 'id' => 'my-account-' . $this->id . '-data', 274 'title' => __( 'Data Management', 'buddypress' ), 275 'href' => trailingslashit( $settings_link . 'data' ), 276 'position' => 89 277 ); 278 } 279 244 280 // Delete Account 245 281 if ( !bp_current_user_can( 'bp_moderate' ) && ! bp_core_get_root_option( 'bp-disable-account-deletion' ) ) { 246 282 $wp_admin_nav[] = array( -
new file src/bp-settings/screens/data.php
new file mode 100644
- + 1 <?php 2 /** 3 * Settings: User's "Settings > Data Management" screen handler 4 * 5 * @package BuddyPress 6 * @subpackage SettingsScreens 7 * @since 3.1.0 8 */ 9 10 /** 11 * Show the data settings template. 12 * 13 * @since 3.1.0 14 */ 15 function bp_settings_screen_data() { 16 if ( bp_action_variables() ) { 17 bp_do_404(); 18 return; 19 } 20 21 /** 22 * Filters the template file path to use for the data settings screen. 23 * 24 * @since 3.1.0 25 * 26 * @param string $value Directory path to look in for the template file. 27 */ 28 bp_core_load_template( apply_filters( 'bp_settings_screen_data', 'members/single/settings/data' ) ); 29 } 30 31 /** 32 * Fetches a user's personal data request. 33 * 34 * @since 3.1.0 35 * 36 * @param int WP user ID. 37 * @return WP_User_Request|false WP_User_Request object on success, boolean false on failure. 38 */ 39 function bp_settings_get_personal_data_request( $user_id = 0 ) { 40 if ( empty( $user_id ) ) { 41 $user_id = bp_displayed_user_id(); 42 } 43 44 if ( empty( $user_id ) ) { 45 return false; 46 } 47 48 $user = get_userdata( $user_id ); 49 if ( empty( $user ) ) { 50 return false; 51 } 52 53 $query = new WP_Query( array( 54 'title' => $user->user_email, 55 'post_type' => 'user_request', 56 'post_status' => 'any', 57 'post_name__in' => array( 58 'export_personal_data' 59 ) 60 ) ); 61 62 if ( ! empty( $query->post ) ) { 63 return wp_get_user_request_data( $query->post->ID ); 64 } else { 65 return false; 66 } 67 } 68 69 /** 70 * Fetches the expiration date for when a user request expires. 71 * 72 * @since 3.1.0 73 * 74 * @param WP_User_Request $request User request object. 75 * @return string Formatted date. 76 */ 77 function bp_settings_get_personal_data_expiration_date( WP_User_Request $request ) { 78 /** This filter is documented in wp-admin/includes/file.php */ 79 $expiration = apply_filters( 'wp_privacy_export_expiration', 3 * DAY_IN_SECONDS ); 80 81 return bp_format_time( $request->completed_timestamp + $expiration, true ); 82 } 83 84 /** 85 * Fetches the confirmation date for a user request object. 86 * 87 * @since 3.1.0 88 * 89 * @param WP_User_Request $request User request object. 90 * @return string Formatted date for the confirmation date. 91 */ 92 function bp_settings_get_personal_data_confirmation_date( WP_User_Request $request ) { 93 return bp_format_time( $request->confirmed_timestamp, true ); 94 } 95 96 function bp_settings_get_personal_data_export_url( WP_User_Request $request ) { 97 return get_post_meta( $request->ID, '_export_file_url', true ); 98 } 99 100 /** 101 * Tempalte tag to output a list of data exporter items. 102 * 103 * Piggybacks off of the 'wp_privacy_personal_data_exporters' filter and the 104 * 'exporter_friendly_name' key, which is meant for the admin area. 105 * 106 * @todo We should look for a custom key like 'exporter_frontend_name' if available. 107 * 108 * @since 3.1.0 109 */ 110 function bp_settings_data_exporter_items() { 111 /** This filter is documented in /wp-admin/includes/ajax-actions.php */ 112 $exporters = apply_filters( 'wp_privacy_personal_data_exporters', array() ); 113 114 ?> 115 <ul> 116 <?php foreach ( $exporters as $exporter => $data ) : 117 /** 118 * Filters the data exporter name for display on the "Settings > Data" page. 119 * 120 * @since 3.1.0 121 * 122 * @param string $name Data exporter friendly name. 123 * @param string $exporter Internal exporter name. 124 */ 125 $item = apply_filters( 'bp_settings_data_exporter_name', esc_html( $data['exporter_friendly_name'] ), $exporter ); 126 ?> 127 128 <li><?php echo $item; ?></li> 129 130 <?php endforeach; ?> 131 </ul> 132 133 <?php 134 } 135 136 // This needs some polishing... 137 add_filter( 'bp_settings_data_exporter_name', function( $retval, $exporter ) { 138 if ( 'wordpress-user' === $exporter ) { 139 $retval = __( 'User profile', 'buddypress' ); 140 141 // Strip 'WordPress' string for whitelisting. 142 } elseif ( 0 === strpos( $exporter, 'wordpress-' ) ) { 143 $retval = str_replace( 'WordPress ', '', $retval ); 144 } 145 return $retval; 146 }, 10, 2 ); 147 No newline at end of file -
src/bp-templates/bp-legacy/buddypress/members/single/settings.php
37 37 case 'profile' : 38 38 bp_get_template_part( 'members/single/settings/profile' ); 39 39 break; 40 case 'data' : 41 bp_get_template_part( 'members/single/settings/data' ); 40 42 default: 41 43 bp_get_template_part( 'members/single/plugins' ); 42 44 break; -
new file src/bp-templates/bp-legacy/buddypress/members/single/settings/data.php
new file mode 100644
- + 1 <?php 2 /** 3 * BuddyPress - Members Settings Data 4 * 5 * @package BuddyPress 6 * @subpackage bp-legacy 7 * @version 3.1.0 8 */ 9 10 /** This action is documented in bp-templates/bp-legacy/buddypress/members/single/settings/profile.php */ 11 do_action( 'bp_before_member_settings_template' ); ?> 12 13 <h2><?php _e( 'Data Export', 'buddypress' );?></h2> 14 15 <?php $request = bp_settings_get_personal_data_request(); ?> 16 17 <?php if ( $request ) : ?> 18 19 <?php if ( 'request-completed' === $request->status ) : ?> 20 21 <p><?php esc_html_e( 'Your request for an export of personal data has been completed.', 'buddypress' ); ?></p> 22 <p><?php printf( esc_html__( 'You may download your personal data by clicking on the link below. For privacy and security, we will automatically delete the file on %s, so please download it before then.', 'buddypress' ), bp_settings_get_personal_data_expiration_date( $request ) ); ?></p> 23 24 <p><strong><?php printf( '<a href="%1$s">%2$s</a>', bp_settings_get_personal_data_export_url( $request ), esc_html__( 'Download personal data', 'buddypress' ) ); ?></strong></p> 25 26 <?php elseif ( 'request-confirmed' === $request->status ) : ?> 27 28 <p><?php printf( esc_html__( 'You previously requested an export of your personal data on %s.', 'buddypress' ), bp_settings_get_personal_data_confirmation_date( $request ) ); ?></p> 29 <p><?php esc_html_e( 'You will receive a link to download your export via email once we are able to fulfill your request.', 'buddypress' ); ?></p> 30 31 <?php endif; ?> 32 33 <?php else : ?> 34 35 <p><?php esc_html_e( 'You can request an export of your personal data, containing the following items if applicable:', 'buddypress' ); ?></p> 36 37 <?php bp_settings_data_exporter_items(); ?> 38 39 <p><?php esc_html_e( 'If you want to make a request, please click on the button below:', 'buddypress' ); ?></p> 40 41 <form id="bp-data-export" method="post"> 42 <button type="submit" name="bp-data-export-nonce" value="<?php echo wp_create_nonce( 'bp-data-export' ); ?>"><?php esc_html_e( 'Request personal data export', 'buddypress' ); ?></button> 43 </form> 44 45 <?php endif; ?> 46 47 <!-- 48 <h2 class="bp-screen-reader-text"><?php 49 /* translators: accessibility text */ 50 _e( 'Data Erase', 'buddypress' ); 51 ?></h2> 52 53 <p>You can make a request to erase the following type of data from the site:</p> 54 55 <p>If you want to make a request, please click on the button below:</p> 56 57 <form id="bp-data-erase" method="post"> 58 <button type="submit" name="bp-data-erase-nonce" value="<?php echo wp_create_nonce( 'bp-data-erase' ); ?>">Request data erasure</button> 59 </form> 60 --> 61 62 <?php 63 64 /** This action is documented in bp-templates/bp-legacy/buddypress/members/single/settings/profile.php */ 65 do_action( 'bp_after_member_settings_template' ); -
src/bp-templates/bp-nouveau/buddypress/members/single/settings.php
39 39 case 'invites': 40 40 bp_get_template_part( 'members/single/settings/group-invites' ); 41 41 break; 42 case 'data': 43 bp_get_template_part( 'members/single/settings/data' ); 44 break; 42 45 default: 43 46 bp_get_template_part( 'members/single/plugins' ); 44 47 break; -
new file src/bp-templates/bp-nouveau/buddypress/members/single/settings/data.php
new file mode 100644
- + 1 <?php 2 /** 3 * BuddyPress - Members Settings ( Data Management ) 4 * 5 * @since 3.1.0 6 * @version 3.1.0 7 */ 8 9 bp_nouveau_member_hook( 'before', 'settings_template' ); ?> 10 11 <h2 class="screen-heading data-settings-screen"> 12 <?php esc_html_e( 'Data Export', 'buddypress' ); ?> 13 </h2> 14 15 <?php $request = bp_settings_get_personal_data_request(); ?> 16 17 <?php if ( $request ) : ?> 18 19 <?php if ( 'request-completed' === $request->status ) : ?> 20 21 <p><?php esc_html_e( 'Your request for an export of personal data has been completed.', 'buddypress' ); ?></p> 22 <p><?php printf( esc_html__( 'You may download your personal data by clicking on the link below. For privacy and security, we will automatically delete the file on %s, so please download it before then.', 'buddypress' ), bp_settings_get_personal_data_expiration_date( $request ) ); ?></p> 23 24 <p><strong><?php printf( '<a href="%1$s">%2$s</a>', bp_settings_get_personal_data_export_url( $request ), esc_html__( 'Download personal data', 'buddypress' ) ); ?></strong></p> 25 26 <?php elseif ( 'request-confirmed' === $request->status ) : ?> 27 28 <p><?php printf( esc_html__( 'You previously requested an export of your personal data on %s.', 'buddypress' ), bp_settings_get_personal_data_confirmation_date( $request ) ); ?></p> 29 <p><?php esc_html_e( 'You will receive a link to download your export via email once we are able to fulfill your request.', 'buddypress' ); ?></p> 30 31 <?php endif; ?> 32 33 <?php else : ?> 34 35 <p><?php esc_html_e( 'You can request an export of your personal data, containing the following items if applicable:', 'buddypress' ); ?></p> 36 37 <?php bp_settings_data_exporter_items(); ?> 38 39 <p><?php esc_html_e( 'If you want to make a request, please click on the button below:', 'buddypress' ); ?></p> 40 41 <form id="bp-data-export" method="post"> 42 <button type="submit" name="bp-data-export-nonce" value="<?php echo wp_create_nonce( 'bp-data-export' ); ?>"><?php esc_html_e( 'Request personal data export', 'buddypress' ); ?></button> 43 </form> 44 45 <?php endif; ?> 46 47 <!-- 48 <h2 class="screen-heading data-settings-screen"> 49 <?php esc_html_e( 'Data Erase', 'buddypress' ); ?> 50 </h2> 51 52 <p>You can make a request to erase the following type of data from the site:</p> 53 54 <p>If you want to make a request, please click on the button below:</p> 55 56 <form id="bp-data-erase" method="post"> 57 <button type="submit" name="bp-data-erase-nonce" value="<?php echo wp_create_nonce( 'bp-data-erase' ); ?>">Request data erasure</button> 58 </form> 59 --> 60 61 <?php 62 bp_nouveau_member_hook( 'after', 'settings_template' );