diff --git a/wp-admin/erase-personal-data.php b/wp-admin/erase-personal-data.php new file mode 100644 index 0000000000..cebe8a3042 --- /dev/null +++ b/wp-admin/erase-personal-data.php @@ -0,0 +1,96 @@ + 20, + 'option' => 'remove_personal_data_requests_per_page', + ) +); + +$_list_table_args = array( + 'plural' => 'privacy_requests', + 'singular' => 'privacy_request', +); + +$requests_table = _get_list_table( 'WP_Privacy_Data_Removal_Requests_List_Table', $_list_table_args ); + +$requests_table->screen->set_screen_reader_content( + array( + 'heading_views' => __( 'Filter erase personal data list' ), + 'heading_pagination' => __( 'Erase personal data list navigation' ), + 'heading_list' => __( 'Erase personal data list' ), + ) +); + +$requests_table->process_bulk_action(); +$requests_table->prepare_items(); + +require_once( ABSPATH . 'wp-admin/admin-header.php' ); +?> + +
+

+
+ + + +
+

+

+ +
+ + + +
+ + + +
+
+ + views(); ?> + +
+ search_box( __( 'Search Requests' ), 'requests' ); ?> + + + +
+ +
+ display(); + $requests_table->embed_scripts(); + ?> +
+
+ + 20, + 'option' => 'export_personal_data_requests_per_page', + ) +); + +$_list_table_args = array( + 'plural' => 'privacy_requests', + 'singular' => 'privacy_request', +); + +$requests_table = _get_list_table( 'WP_Privacy_Data_Export_Requests_List_Table', $_list_table_args ); + +$requests_table->screen->set_screen_reader_content( + array( + 'heading_views' => __( 'Filter export personal data list' ), + 'heading_pagination' => __( 'Export personal data list navigation' ), + 'heading_list' => __( 'Export personal data list' ), + ) +); + +$requests_table->process_bulk_action(); +$requests_table->prepare_items(); + +require_once( ABSPATH . 'wp-admin/admin-header.php' ); +?> + +
+

+
+ + + +
+

+

+ +
+ + + +
+ + + +
+
+ + views(); ?> + +
+ search_box( __( 'Search Requests' ), 'requests' ); ?> + + + +
+ +
+ display(); + $requests_table->embed_scripts(); + ?> +
+
+ +ID; + $nonce = wp_create_nonce( 'wp-privacy-export-personal-data-' . $request_id ); + + $download_data_markup = '
'; + + $download_data_markup .= '' . + '' . + '' . + ''; + + $download_data_markup .= '
'; + + $row_actions = array( + 'download-data' => $download_data_markup, + ); + + return sprintf( '%2$s %3$s', esc_url( 'mailto:' . $item->email ), $item->email, $this->row_actions( $row_actions ) ); + } + + /** + * Displays the next steps column. + * + * @since 4.9.6 + * + * @param WP_User_Request $item Item being shown. + */ + public function column_next_steps( $item ) { + $status = $item->status; + + switch ( $status ) { + case 'request-pending': + esc_html_e( 'Waiting for confirmation' ); + break; + case 'request-confirmed': + /** This filter is documented in wp-admin/includes/ajax-actions.php */ + $exporters = apply_filters( 'wp_privacy_personal_data_exporters', array() ); + $exporters_count = count( $exporters ); + $request_id = $item->ID; + $nonce = wp_create_nonce( 'wp-privacy-export-personal-data-' . $request_id ); + + echo '
'; + + ?> + + + + + '; + break; + case 'request-failed': + submit_button( __( 'Retry' ), 'secondary', 'privacy_action_email_retry[' . $item->ID . ']', false ); + break; + case 'request-completed': + echo '' . esc_html__( 'Remove request' ) . ''; + break; + } + } +} diff --git a/wp-admin/includes/class-wp-privacy-data-removal-requests-list-table.php b/wp-admin/includes/class-wp-privacy-data-removal-requests-list-table.php new file mode 100644 index 0000000000..04a4681bf1 --- /dev/null +++ b/wp-admin/includes/class-wp-privacy-data-removal-requests-list-table.php @@ -0,0 +1,135 @@ +status; + if ( 'request-confirmed' !== $status ) { + /** This filter is documented in wp-admin/includes/ajax-actions.php */ + $erasers = apply_filters( 'wp_privacy_personal_data_erasers', array() ); + $erasers_count = count( $erasers ); + $request_id = $item->ID; + $nonce = wp_create_nonce( 'wp-privacy-erase-personal-data-' . $request_id ); + + $remove_data_markup = '
'; + + $remove_data_markup .= '' . + '' . + ''; + + $remove_data_markup .= '
'; + + $row_actions = array( + 'remove-data' => $remove_data_markup, + ); + } + + return sprintf( '%2$s %3$s', esc_url( 'mailto:' . $item->email ), $item->email, $this->row_actions( $row_actions ) ); + } + + /** + * Next steps column. + * + * @since 4.9.6 + * + * @param WP_User_Request $item Item being shown. + */ + public function column_next_steps( $item ) { + $status = $item->status; + + switch ( $status ) { + case 'request-pending': + esc_html_e( 'Waiting for confirmation' ); + break; + case 'request-confirmed': + /** This filter is documented in wp-admin/includes/ajax-actions.php */ + $erasers = apply_filters( 'wp_privacy_personal_data_erasers', array() ); + $erasers_count = count( $erasers ); + $request_id = $item->ID; + $nonce = wp_create_nonce( 'wp-privacy-erase-personal-data-' . $request_id ); + + echo '
'; + + ?> + + + + '; + + break; + case 'request-failed': + submit_button( __( 'Retry' ), 'secondary', 'privacy_action_email_retry[' . $item->ID . ']', false ); + break; + case 'request-completed': + echo '' . esc_html__( 'Remove request' ) . ''; + break; + } + } + +} diff --git a/wp-admin/includes/class-wp-privacy-policy-content.php b/wp-admin/includes/class-wp-privacy-policy-content.php new file mode 100644 index 0000000000..0c3224870e --- /dev/null +++ b/wp-admin/includes/class-wp-privacy-policy-content.php @@ -0,0 +1,716 @@ + $plugin_name, + 'policy_text' => $policy_text, + ); + + if ( ! in_array( $data, self::$policy_content, true ) ) { + self::$policy_content[] = $data; + } + } + + /** + * Quick check if any privacy info has changed. + * + * @since 4.9.6 + */ + public static function text_change_check() { + + $policy_page_id = (int) get_option( 'wp_page_for_privacy_policy' ); + + // The site doesn't have a privacy policy. + if ( empty( $policy_page_id ) ) { + return false; + } + + if ( ! current_user_can( 'edit_post', $policy_page_id ) ) { + return false; + } + + $old = (array) get_post_meta( $policy_page_id, '_wp_suggested_privacy_policy_content' ); + + // Updates are not relevant if the user has not reviewed any suggestions yet. + if ( empty( $old ) ) { + return false; + } + + $cached = get_option( '_wp_suggested_policy_text_has_changed' ); + + /* + * When this function is called before `admin_init`, `self::$policy_content` + * has not been populated yet, so use the cached result from the last + * execution instead. + */ + if ( ! did_action( 'admin_init' ) ) { + return 'changed' === $cached; + } + + $new = self::$policy_content; + + // Remove the extra values added to the meta. + foreach ( $old as $key => $data ) { + if ( ! empty( $data['removed'] ) ) { + unset( $old[ $key ] ); + continue; + } + + $old[ $key ] = array( + 'plugin_name' => $data['plugin_name'], + 'policy_text' => $data['policy_text'], + ); + } + + // Normalize the order of texts, to facilitate comparison. + sort( $old ); + sort( $new ); + + // The == operator (equal, not identical) was used intentionally. + // See http://php.net/manual/en/language.operators.array.php + if ( $new != $old ) { + // A plugin was activated or deactivated, or some policy text has changed. + // Show a notice on the relevant screens to inform the admin. + add_action( 'admin_notices', array( 'WP_Privacy_Policy_Content', 'policy_text_changed_notice' ) ); + $state = 'changed'; + } else { + $state = 'not-changed'; + } + + // Cache the result for use before `admin_init` (see above). + if ( $cached !== $state ) { + update_option( '_wp_suggested_policy_text_has_changed', $state ); + } + + return 'changed' === $state; + } + + /** + * Output a warning when some privacy info has changed. + * + * @since 4.9.6 + */ + public static function policy_text_changed_notice() { + global $post; + + $screen = get_current_screen()->id; + + if ( 'privacy' !== $screen ) { + return; + } + + ?> +
+

+ review the guide and update your privacy policy.' ), + esc_url( admin_url( 'privacy-policy-guide.php' ) ) + ); + ?> +

+
+ $old_data ) { + if ( ! empty( $old_data['removed'] ) ) { + // Remove the old policy text. + $update_cache = true; + continue; + } + + if ( ! empty( $old_data['updated'] ) ) { + // 'updated' is now 'added'. + $done[] = array( + 'plugin_name' => $old_data['plugin_name'], + 'policy_text' => $old_data['policy_text'], + 'added' => $old_data['updated'], + ); + $update_cache = true; + } else { + $done[] = $old_data; + } + } + + if ( $update_cache ) { + delete_post_meta( $policy_page_id, '_wp_suggested_privacy_policy_content' ); + // Update the cache. + foreach ( $done as $data ) { + add_post_meta( $policy_page_id, '_wp_suggested_privacy_policy_content', $data ); + } + } + } + + /** + * Check for updated, added or removed privacy policy information from plugins. + * + * Caches the current info in post_meta of the policy page. + * + * @since 4.9.6 + * + * @return array The privacy policy text/informtion added by core and plugins. + */ + public static function get_suggested_policy_text() { + $policy_page_id = (int) get_option( 'wp_page_for_privacy_policy' ); + $checked = array(); + $time = time(); + $update_cache = false; + $new = self::$policy_content; + $old = array(); + + if ( $policy_page_id ) { + $old = (array) get_post_meta( $policy_page_id, '_wp_suggested_privacy_policy_content' ); + } + + // Check for no-changes and updates. + foreach ( $new as $new_key => $new_data ) { + foreach ( $old as $old_key => $old_data ) { + $found = false; + + if ( $new_data['policy_text'] === $old_data['policy_text'] ) { + // Use the new plugin name in case it was changed, translated, etc. + if ( $old_data['plugin_name'] !== $new_data['plugin_name'] ) { + $old_data['plugin_name'] = $new_data['plugin_name']; + $update_cache = true; + } + + // A plugin was re-activated. + if ( ! empty( $old_data['removed'] ) ) { + unset( $old_data['removed'] ); + $old_data['added'] = $time; + $update_cache = true; + } + + $checked[] = $old_data; + $found = true; + } elseif ( $new_data['plugin_name'] === $old_data['plugin_name'] ) { + // The info for the policy was updated. + $checked[] = array( + 'plugin_name' => $new_data['plugin_name'], + 'policy_text' => $new_data['policy_text'], + 'updated' => $time, + ); + $found = $update_cache = true; + } + + if ( $found ) { + unset( $new[ $new_key ], $old[ $old_key ] ); + continue 2; + } + } + } + + if ( ! empty( $new ) ) { + // A plugin was activated. + foreach ( $new as $new_data ) { + if ( ! empty( $new_data['plugin_name'] ) && ! empty( $new_data['policy_text'] ) ) { + $new_data['added'] = $time; + $checked[] = $new_data; + } + } + $update_cache = true; + } + + if ( ! empty( $old ) ) { + // A plugin was deactivated. + foreach ( $old as $old_data ) { + if ( ! empty( $old_data['plugin_name'] ) && ! empty( $old_data['policy_text'] ) ) { + $data = array( + 'plugin_name' => $old_data['plugin_name'], + 'policy_text' => $old_data['policy_text'], + 'removed' => $time, + ); + + $checked[] = $data; + } + } + $update_cache = true; + } + + if ( $update_cache && $policy_page_id ) { + delete_post_meta( $policy_page_id, '_wp_suggested_privacy_policy_content' ); + // Update the cache. + foreach ( $checked as $data ) { + add_post_meta( $policy_page_id, '_wp_suggested_privacy_policy_content', $data ); + } + } + + return $checked; + } + + /** + * Add a notice with a link to the guide when editing the privacy policy page. + * + * @since 4.9.6 + * @since 5.0.0 The $post parameter is now optional. + * + * @param WP_Post|null $post The currently edited post. Default null. + */ + public static function notice( $post = null ) { + if ( is_null( $post ) ) { + global $post; + } else { + $post = get_post( $post ); + } + + if ( ! ( $post instanceof WP_Post ) ) { + return; + } + + if ( ! current_user_can( 'manage_privacy_options' ) ) { + return; + } + + $policy_page_id = (int) get_option( 'wp_page_for_privacy_policy' ); + + if ( ! $policy_page_id || $policy_page_id !== $post->ID ) { + return; + } + + $message = __( 'Need help putting together your new Privacy Policy page? Check out our guide for recommendations on what content to include, along with policies suggested by your plugins and theme.' ); + $url = esc_url( admin_url( 'privacy-policy-guide.php' ) ); + $label = __( 'View Privacy Policy Guide.' ); + + if ( get_current_screen()->is_block_editor() ) { + wp_enqueue_script( 'wp-notices' ); + $action = array( + 'url' => $url, + 'label' => $label, + ); + wp_add_inline_script( + 'wp-notices', + sprintf( + 'wp.data.dispatch( "core/notices" ).createWarningNotice( "%s", { actions: [ %s ], isDismissible: false } )', + $message, + wp_json_encode( $action ) + ), + 'after' + ); + } else { + ?> +
+

+ %s %s', + $url, + $label, + /* translators: accessibility text */ + __( '(opens in a new tab)' ) + ); + ?> +

+
+ ' . __( 'Introduction' ) . '' ); + $date_format = __( 'F j, Y' ); + $copy = __( 'Copy this section to clipboard' ); + $return_to_top = '' . __( '↑ Return to Top' ) . ''; + + foreach ( $content_array as $section ) { + $class = $meta = $removed = ''; + + if ( ! empty( $section['removed'] ) ) { + $class = ' text-removed'; + $date = date_i18n( $date_format, $section['removed'] ); + $meta = sprintf( __( 'Removed %s.' ), $date ); + + $removed = __( 'You deactivated this plugin on %s and may no longer need this policy.' ); + $removed = '

' . sprintf( $removed, $date ) . '

'; + } elseif ( ! empty( $section['updated'] ) ) { + $class = ' text-updated'; + $date = date_i18n( $date_format, $section['updated'] ); + $meta = sprintf( __( 'Updated %s.' ), $date ); + } + + if ( $meta ) { + $meta = '
' . $meta . ''; + } + + $plugin_name = esc_html( $section['plugin_name'] ); + $toc_id = 'wp-privacy-policy-guide-' . sanitize_title( $plugin_name ); + $toc[] = sprintf( '
  • %2$s' . $meta . '
  • ', $toc_id, $plugin_name ); + + $content .= '
    '; + $content .= ' '; + /* translators: %s: plugin name */ + $content .= '

    ' . sprintf( __( 'Source: %s' ), $plugin_name ) . '

    '; + $content .= $removed; + + $content .= '
    ' . $section['policy_text'] . '
    '; + $content .= $return_to_top; + + if ( empty( $section['removed'] ) ) { + $content .= '
    '; + $content .= ''; + $content .= '
    '; + } + + $content .= "
    \n"; // End of .privacy-text-section. + } + + if ( count( $toc ) > 2 ) { + ?> +
    +

    +
      + +
    +
    + +
    +
    +   +

    +

    +

    +

    +

    +

    +
    + +
    + +
    +
    + ' . __( 'Suggested text:' ) . ' ' : ''; + $content = ''; + $strings = array(); + + // Start of the suggested privacy policy text. + if ( $description ) { + $strings[] = '
    '; + } + + /* translators: default privacy policy heading. */ + $strings[] = '

    ' . __( 'Who we are' ) . '

    '; + + if ( $description ) { + /* translators: privacy policy tutorial. */ + $strings[] = '

    ' . __( 'In this section you should note your site URL, as well as the name of the company, organization, or individual behind it, and some accurate contact information.' ) . '

    '; + /* translators: privacy policy tutorial. */ + $strings[] = '

    ' . __( 'The amount of information you may be required to show will vary depending on your local or national business regulations. You may, for example, be required to display a physical address, a registered address, or your company registration number.' ) . '

    '; + } + + /* translators: default privacy policy text, %s Site URL. */ + $strings[] = '

    ' . $suggested_text . sprintf( __( 'Our website address is: %s.' ), get_bloginfo( 'url', 'display' ) ) . '

    '; + + /* translators: default privacy policy heading. */ + $strings[] = '

    ' . __( 'What personal data we collect and why we collect it' ) . '

    '; + + if ( $description ) { + /* translators: privacy policy tutorial. */ + $strings[] = '

    ' . __( 'In this section you should note what personal data you collect from users and site visitors. This may include personal data, such as name, email address, personal account preferences; transactional data, such as purchase information; and technical data, such as information about cookies.' ) . '

    '; + /* translators: privacy policy tutorial. */ + $strings[] = '

    ' . __( 'You should also note any collection and retention of sensitive personal data, such as data concerning health.' ) . '

    '; + /* translators: privacy policy tutorial. */ + $strings[] = '

    ' . __( 'In addition to listing what personal data you collect, you need to note why you collect it. These explanations must note either the legal basis for your data collection and retention or the active consent the user has given.' ) . '

    '; + /* translators: privacy policy tutorial. */ + $strings[] = '

    ' . __( 'Personal data is not just created by a user’s interactions with your site. Personal data is also generated from technical processes such as contact forms, comments, cookies, analytics, and third party embeds.' ) . '

    '; + /* translators: privacy policy tutorial. */ + $strings[] = '

    ' . __( 'By default WordPress does not collect any personal data about visitors, and only collects the data shown on the User Profile screen from registered users. However some of your plugins may collect personal data. You should add the relevant information below.' ) . '

    '; + } + + /* translators: default privacy policy heading. */ + $strings[] = '

    ' . __( 'Comments' ) . '

    '; + + if ( $description ) { + /* translators: privacy policy tutorial. */ + $strings[] = '

    ' . __( 'In this subsection you should note what information is captured through comments. We have noted the data which WordPress collects by default.' ) . '

    '; + } + + /* translators: default privacy policy text. */ + $strings[] = '

    ' . $suggested_text . __( 'When visitors leave comments on the site we collect the data shown in the comments form, and also the visitor’s IP address and browser user agent string to help spam detection.' ) . '

    '; + /* translators: default privacy policy text. */ + $strings[] = '

    ' . __( 'An anonymized string created from your email address (also called a hash) may be provided to the Gravatar service to see if you are using it. The Gravatar service privacy policy is available here: https://automattic.com/privacy/. After approval of your comment, your profile picture is visible to the public in the context of your comment.' ) . '

    '; + + /* translators: default privacy policy heading. */ + $strings[] = '

    ' . __( 'Media' ) . '

    '; + + if ( $description ) { + /* translators: privacy policy tutorial. */ + $strings[] = '

    ' . __( 'In this subsection you should note what information may be disclosed by users who can upload media files. All uploaded files are usually publicly accessible.' ) . '

    '; + } + + /* translators: default privacy policy text. */ + $strings[] = '

    ' . $suggested_text . __( 'If you upload images to the website, you should avoid uploading images with embedded location data (EXIF GPS) included. Visitors to the website can download and extract any location data from images on the website.' ) . '

    '; + + /* translators: default privacy policy heading. */ + $strings[] = '

    ' . __( 'Contact forms' ) . '

    '; + + if ( $description ) { + /* translators: privacy policy tutorial. */ + $strings[] = '

    ' . __( 'By default, WordPress does not include a contact form. If you use a contact form plugin, use this subsection to note what personal data is captured when someone submits a contact form, and how long you keep it. For example, you may note that you keep contact form submissions for a certain period for customer service purposes, but you do not use the information submitted through them for marketing purposes.' ) . '

    '; + } + + /* translators: default privacy policy heading. */ + $strings[] = '

    ' . __( 'Cookies' ) . '

    '; + + if ( $description ) { + /* translators: privacy policy tutorial. */ + $strings[] = '

    ' . __( 'In this subsection you should list the cookies your web site uses, including those set by your plugins, social media, and analytics. We have provided the cookies which WordPress installs by default.' ) . '

    '; + } + + /* translators: default privacy policy text. */ + $strings[] = '

    ' . $suggested_text . __( 'If you leave a comment on our site you may opt-in to saving your name, email address and website in cookies. These are for your convenience so that you do not have to fill in your details again when you leave another comment. These cookies will last for one year.' ) . '

    '; + /* translators: default privacy policy text. */ + $strings[] = '

    ' . __( 'If you visit our login page, we will set a temporary cookie to determine if your browser accepts cookies. This cookie contains no personal data and is discarded when you close your browser.' ) . '

    '; + /* translators: default privacy policy text. */ + $strings[] = '

    ' . __( 'When you log in, we will also set up several cookies to save your login information and your screen display choices. Login cookies last for two days, and screen options cookies last for a year. If you select "Remember Me", your login will persist for two weeks. If you log out of your account, the login cookies will be removed.' ) . '

    '; + /* translators: default privacy policy text. */ + $strings[] = '

    ' . __( 'If you edit or publish an article, an additional cookie will be saved in your browser. This cookie includes no personal data and simply indicates the post ID of the article you just edited. It expires after 1 day.' ) . '

    '; + + /* translators: default privacy policy heading. */ + $strings[] = '

    ' . __( 'Embedded content from other websites' ) . '

    '; + /* translators: default privacy policy text. */ + $strings[] = '

    ' . $suggested_text . __( 'Articles on this site may include embedded content (e.g. videos, images, articles, etc.). Embedded content from other websites behaves in the exact same way as if the visitor has visited the other website.' ) . '

    '; + /* translators: default privacy policy text. */ + $strings[] = '

    ' . __( 'These websites may collect data about you, use cookies, embed additional third-party tracking, and monitor your interaction with that embedded content, including tracking your interaction with the embedded content if you have an account and are logged in to that website.' ) . '

    '; + + /* translators: default privacy policy heading. */ + $strings[] = '

    ' . __( 'Analytics' ) . '

    '; + + if ( $description ) { + /* translators: privacy policy tutorial. */ + $strings[] = '

    ' . __( 'In this subsection you should note what analytics package you use, how users can opt out of analytics tracking, and a link to your analytics provider’s privacy policy, if any.' ) . '

    '; + /* translators: privacy policy tutorial. */ + $strings[] = '

    ' . __( 'By default WordPress does not collect any analytics data. However, many web hosting accounts collect some anonymous analytics data. You may also have installed a WordPress plugin that provides analytics services. In that case, add information from that plugin here.' ) . '

    '; + } + + /* translators: default privacy policy heading. */ + $strings[] = '

    ' . __( 'Who we share your data with' ) . '

    '; + + if ( $description ) { + /* translators: privacy policy tutorial. */ + $strings[] = '

    ' . __( 'In this section you should name and list all third party providers with whom you share site data, including partners, cloud-based services, payment processors, and third party service providers, and note what data you share with them and why. Link to their own privacy policies if possible.' ) . '

    '; + /* translators: privacy policy tutorial. */ + $strings[] = '

    ' . __( 'By default WordPress does not share any personal data with anyone.' ) . '

    '; + } + + /* translators: default privacy policy heading. */ + $strings[] = '

    ' . __( 'How long we retain your data' ) . '

    '; + + if ( $description ) { + /* translators: privacy policy tutorial. */ + $strings[] = '

    ' . __( 'In this section you should explain how long you retain personal data collected or processed by the web site. While it is your responsibility to come up with the schedule of how long you keep each dataset for and why you keep it, that information does need to be listed here. For example, you may want to say that you keep contact form entries for six months, analytics records for a year, and customer purchase records for ten years.' ) . '

    '; + } + + /* translators: default privacy policy text. */ + $strings[] = '

    ' . $suggested_text . __( 'If you leave a comment, the comment and its metadata are retained indefinitely. This is so we can recognize and approve any follow-up comments automatically instead of holding them in a moderation queue.' ) . '

    '; + /* translators: default privacy policy text. */ + $strings[] = '

    ' . __( 'For users that register on our website (if any), we also store the personal information they provide in their user profile. All users can see, edit, or delete their personal information at any time (except they cannot change their username). Website administrators can also see and edit that information.' ) . '

    '; + + /* translators: default privacy policy heading. */ + $strings[] = '

    ' . __( 'What rights you have over your data' ) . '

    '; + + if ( $description ) { + /* translators: privacy policy tutorial. */ + $strings[] = '

    ' . __( 'In this section you should explain what rights your users have over their data and how they can invoke those rights.' ) . '

    '; + } + + /* translators: default privacy policy text. */ + $strings[] = '

    ' . $suggested_text . __( 'If you have an account on this site, or have left comments, you can request to receive an exported file of the personal data we hold about you, including any data you have provided to us. You can also request that we erase any personal data we hold about you. This does not include any data we are obliged to keep for administrative, legal, or security purposes.' ) . '

    '; + + /* translators: default privacy policy heading. */ + $strings[] = '

    ' . __( 'Where we send your data' ) . '

    '; + + if ( $description ) { + /* translators: privacy policy tutorial. */ + $strings[] = '

    ' . __( 'In this section you should list all transfers of your site data outside the European Union and describe the means by which that data is safeguarded to European data protection standards. This could include your web hosting, cloud storage, or other third party services.' ) . '

    '; + /* translators: privacy policy tutorial. */ + $strings[] = '

    ' . __( 'European data protection law requires data about European residents which is transferred outside the European Union to be safeguarded to the same standards as if the data was in Europe. So in addition to listing where data goes, you should describe how you ensure that these standards are met either by yourself or by your third party providers, whether that is through an agreement such as Privacy Shield, model clauses in your contracts, or binding corporate rules.' ) . '

    '; + } + + /* translators: default privacy policy text. */ + $strings[] = '

    ' . $suggested_text . __( 'Visitor comments may be checked through an automated spam detection service.' ) . '

    '; + + /* translators: default privacy policy heading. */ + $strings[] = '

    ' . __( 'Your contact information' ) . '

    '; + + if ( $description ) { + /* translators: privacy policy tutorial. */ + $strings[] = '

    ' . __( 'In this section you should provide a contact method for privacy-specific concerns. If you are required to have a Data Protection Officer, list their name and full contact details here as well.' ) . '

    '; + } + + /* translators: default privacy policy heading. */ + $strings[] = '

    ' . __( 'Additional information' ) . '

    '; + + if ( $description ) { + /* translators: privacy policy tutorial. */ + $strings[] = '

    ' . __( 'If you use your site for commercial purposes and you engage in more complex collection or processing of personal data, you should note the following information in your privacy policy in addition to the information we have already discussed.' ) . '

    '; + } + + /* translators: default privacy policy heading. */ + $strings[] = '

    ' . __( 'How we protect your data' ) . '

    '; + + if ( $description ) { + /* translators: privacy policy tutorial. */ + $strings[] = '

    ' . __( 'In this section you should explain what measures you have taken to protect your users’ data. This could include technical measures such as encryption; security measures such as two factor authentication; and measures such as staff training in data protection. If you have carried out a Privacy Impact Assessment, you can mention it here too.' ) . '

    '; + } + + /* translators: default privacy policy heading. */ + $strings[] = '

    ' . __( 'What data breach procedures we have in place' ) . '

    '; + + if ( $description ) { + /* translators: privacy policy tutorial. */ + $strings[] = '

    ' . __( 'In this section you should explain what procedures you have in place to deal with data breaches, either potential or real, such as internal reporting systems, contact mechanisms, or bug bounties.' ) . '

    '; + } + + /* translators: default privacy policy heading. */ + $strings[] = '

    ' . __( 'What third parties we receive data from' ) . '

    '; + + if ( $description ) { + /* translators: privacy policy tutorial. */ + $strings[] = '

    ' . __( 'If your web site receives data about users from third parties, including advertisers, this information must be included within the section of your privacy policy dealing with third party data.' ) . '

    '; + } + + /* translators: default privacy policy heading. */ + $strings[] = '

    ' . __( 'What automated decision making and/or profiling we do with user data' ) . '

    '; + + if ( $description ) { + /* translators: privacy policy tutorial. */ + $strings[] = '

    ' . __( 'If your web site provides a service which includes automated decision making - for example, allowing customers to apply for credit, or aggregating their data into an advertising profile - you must note that this is taking place, and include information about how that information is used, what decisions are made with that aggregated data, and what rights users have over decisions made without human intervention.' ) . '

    '; + } + + /* translators: default privacy policy heading. */ + $strings[] = '

    ' . __( 'Industry regulatory disclosure requirements' ) . '

    '; + + if ( $description ) { + /* translators: privacy policy tutorial. */ + $strings[] = '

    ' . __( 'If you are a member of a regulated industry, or if you are subject to additional privacy laws, you may be required to disclose that information here.' ) . '

    '; + $strings[] = '
    '; + } + + if ( $blocks ) { + foreach ( $strings as $key => $string ) { + if ( 0 === strpos( $string, '

    ' ) ) { + $strings[ $key ] = '' . $string . ''; + } + + if ( 0 === strpos( $string, '

    ' ) ) { + $strings[ $key ] = '' . $string . ''; + } + + if ( 0 === strpos( $string, '

    ' ) ) { + $strings[ $key ] = '' . $string . ''; + } + } + } + + $content = implode( '', $strings ); + // End of the suggested privacy policy text. + + /** + * Filters the default content suggested for inclusion in a privacy policy. + * + * @since 4.9.6 + * @since 5.0.0 Added the `$strings`, `$description`, and `$blocks` parameters. + * + * @param string $content The default policy content. + * @param array $strings An array of privacy policy content strings. + * @param bool $description Whether policy descriptions should be included. + * @param bool $blocks Whether the content should be formatted for the block editor. + */ + return apply_filters( 'wp_get_default_privacy_policy_content', $content, $strings, $description, $blocks ); + } + + /** + * Add the suggested privacy policy text to the policy postbox. + * + * @since 4.9.6 + */ + public static function add_suggested_content() { + $content = self::get_default_content( true, false ); + wp_add_privacy_policy_content( __( 'WordPress' ), $content ); + } +} diff --git a/wp-admin/includes/class-wp-privacy-requests-table.php b/wp-admin/includes/class-wp-privacy-requests-table.php new file mode 100644 index 0000000000..fe5a516431 --- /dev/null +++ b/wp-admin/includes/class-wp-privacy-requests-table.php @@ -0,0 +1,451 @@ + '', + 'email' => __( 'Requester' ), + 'status' => __( 'Status' ), + 'created_timestamp' => __( 'Requested' ), + 'next_steps' => __( 'Next Steps' ), + ); + return $columns; + } + + /** + * Normalize the admin URL to the current page (by request_type). + * + * @since 5.3.0 + * + * @return string URL to the current admin page. + */ + protected function get_admin_url() { + $pagenow = str_replace( '_', '-', $this->request_type ); + + if ( 'remove-personal-data' === $pagenow ) { + $pagenow = 'erase-personal-data'; + } + + return admin_url( $pagenow . '.php' ); + } + + /** + * Get a list of sortable columns. + * + * @since 4.9.6 + * + * @return array Default sortable columns. + */ + protected function get_sortable_columns() { + // The initial sorting is by 'Requested' (post_date) and descending. + // With initial sorting, the first click on 'Requested' should be ascending. + // With 'Requester' sorting active, the next click on 'Requested' should be descending. + $desc_first = isset( $_GET['orderby'] ); + + return array( + 'email' => 'requester', + 'created_timestamp' => array( 'requested', $desc_first ), + ); + } + + /** + * Default primary column. + * + * @since 4.9.6 + * + * @return string Default primary column name. + */ + protected function get_default_primary_column_name() { + return 'email'; + } + + /** + * Count number of requests for each status. + * + * @since 4.9.6 + * + * @return object Number of posts for each status. + */ + protected function get_request_counts() { + global $wpdb; + + $cache_key = $this->post_type . '-' . $this->request_type; + $counts = wp_cache_get( $cache_key, 'counts' ); + + if ( false !== $counts ) { + return $counts; + } + + $query = " + SELECT post_status, COUNT( * ) AS num_posts + FROM {$wpdb->posts} + WHERE post_type = %s + AND post_name = %s + GROUP BY post_status"; + + $results = (array) $wpdb->get_results( $wpdb->prepare( $query, $this->post_type, $this->request_type ), ARRAY_A ); + $counts = array_fill_keys( get_post_stati(), 0 ); + + foreach ( $results as $row ) { + $counts[ $row['post_status'] ] = $row['num_posts']; + } + + $counts = (object) $counts; + wp_cache_set( $cache_key, $counts, 'counts' ); + + return $counts; + } + + /** + * Get an associative array ( id => link ) with the list of views available on this table. + * + * @since 4.9.6 + * + * @return array Associative array of views in the format of $view_name => $view_markup. + */ + protected function get_views() { + $current_status = isset( $_REQUEST['filter-status'] ) ? sanitize_text_field( $_REQUEST['filter-status'] ) : ''; + $statuses = _wp_privacy_statuses(); + $views = array(); + $counts = $this->get_request_counts(); + $total_requests = absint( array_sum( (array) $counts ) ); + + // Normalized admin URL + $admin_url = $this->get_admin_url(); + + $current_link_attributes = empty( $current_status ) ? ' class="current" aria-current="page"' : ''; + $status_label = sprintf( + /* translators: %s: all requests count */ + _nx( + 'All (%s)', + 'All (%s)', + $total_requests, + 'requests' + ), + number_format_i18n( $total_requests ) + ); + + $views['all'] = sprintf( + '%s', + esc_url( $admin_url ), + $current_link_attributes, + $status_label + ); + + foreach ( $statuses as $status => $label ) { + $post_status = get_post_status_object( $status ); + if ( ! $post_status ) { + continue; + } + + $current_link_attributes = $status === $current_status ? ' class="current" aria-current="page"' : ''; + $total_status_requests = absint( $counts->{$status} ); + + $status_label = sprintf( + translate_nooped_plural( $post_status->label_count, $total_status_requests ), + number_format_i18n( $total_status_requests ) + ); + + $status_link = add_query_arg( 'filter-status', $status, $admin_url ); + + $views[ $status ] = sprintf( + '%s', + esc_url( $status_link ), + $current_link_attributes, + $status_label + ); + } + + return $views; + } + + /** + * Get bulk actions. + * + * @since 4.9.6 + * + * @return array List of bulk actions. + */ + protected function get_bulk_actions() { + return array( + 'delete' => __( 'Remove' ), + 'resend' => __( 'Resend email' ), + ); + } + + /** + * Process bulk actions. + * + * @since 4.9.6 + */ + public function process_bulk_action() { + $action = $this->current_action(); + $request_ids = isset( $_REQUEST['request_id'] ) ? wp_parse_id_list( wp_unslash( $_REQUEST['request_id'] ) ) : array(); + + $count = 0; + + if ( $request_ids ) { + check_admin_referer( 'bulk-privacy_requests' ); + } + + switch ( $action ) { + case 'delete': + foreach ( $request_ids as $request_id ) { + if ( wp_delete_post( $request_id, true ) ) { + $count ++; + } + } + + add_settings_error( + 'bulk_action', + 'bulk_action', + /* translators: %d: number of requests */ + sprintf( _n( 'Deleted %d request', 'Deleted %d requests', $count ), $count ), + 'updated' + ); + break; + case 'resend': + foreach ( $request_ids as $request_id ) { + $resend = _wp_privacy_resend_request( $request_id ); + + if ( $resend && ! is_wp_error( $resend ) ) { + $count++; + } + } + + add_settings_error( + 'bulk_action', + 'bulk_action', + /* translators: %d: number of requests */ + sprintf( _n( 'Re-sent %d request', 'Re-sent %d requests', $count ), $count ), + 'updated' + ); + break; + } + } + + /** + * Prepare items to output. + * + * @since 4.9.6 + * @since 5.1.0 Added support for column sorting. + */ + public function prepare_items() { + global $wpdb; + + $this->items = array(); + $posts_per_page = $this->get_items_per_page( $this->request_type . '_requests_per_page' ); + $args = array( + 'post_type' => $this->post_type, + 'post_name__in' => array( $this->request_type ), + 'posts_per_page' => $posts_per_page, + 'offset' => isset( $_REQUEST['paged'] ) ? max( 0, absint( $_REQUEST['paged'] ) - 1 ) * $posts_per_page : 0, + 'post_status' => 'any', + 's' => isset( $_REQUEST['s'] ) ? sanitize_text_field( $_REQUEST['s'] ) : '', + ); + + $orderby_mapping = array( + 'requester' => 'post_title', + 'requested' => 'post_date', + ); + + if ( isset( $_REQUEST['orderby'] ) && isset( $orderby_mapping[ $_REQUEST['orderby'] ] ) ) { + $args['orderby'] = $orderby_mapping[ $_REQUEST['orderby'] ]; + } + + if ( isset( $_REQUEST['order'] ) && in_array( strtoupper( $_REQUEST['order'] ), array( 'ASC', 'DESC' ), true ) ) { + $args['order'] = strtoupper( $_REQUEST['order'] ); + } + + if ( ! empty( $_REQUEST['filter-status'] ) ) { + $filter_status = isset( $_REQUEST['filter-status'] ) ? sanitize_text_field( $_REQUEST['filter-status'] ) : ''; + $args['post_status'] = $filter_status; + } + + $requests_query = new WP_Query( $args ); + $requests = $requests_query->posts; + + foreach ( $requests as $request ) { + $this->items[] = wp_get_user_request_data( $request->ID ); + } + + $this->items = array_filter( $this->items ); + + $this->set_pagination_args( + array( + 'total_items' => $requests_query->found_posts, + 'per_page' => $posts_per_page, + ) + ); + } + + /** + * Checkbox column. + * + * @since 4.9.6 + * + * @param WP_User_Request $item Item being shown. + * @return string Checkbox column markup. + */ + public function column_cb( $item ) { + return sprintf( '', esc_attr( $item->ID ) ); + } + + /** + * Status column. + * + * @since 4.9.6 + * + * @param WP_User_Request $item Item being shown. + * @return string Status column markup. + */ + public function column_status( $item ) { + $status = get_post_status( $item->ID ); + $status_object = get_post_status_object( $status ); + + if ( ! $status_object || empty( $status_object->label ) ) { + return '-'; + } + + $timestamp = false; + + switch ( $status ) { + case 'request-confirmed': + $timestamp = $item->confirmed_timestamp; + break; + case 'request-completed': + $timestamp = $item->completed_timestamp; + break; + } + + echo ''; + echo esc_html( $status_object->label ); + + if ( $timestamp ) { + echo ' (' . $this->get_timestamp_as_date( $timestamp ) . ')'; + } + + echo ''; + } + + /** + * Convert timestamp for display. + * + * @since 4.9.6 + * + * @param int $timestamp Event timestamp. + * @return string Human readable date. + */ + protected function get_timestamp_as_date( $timestamp ) { + if ( empty( $timestamp ) ) { + return ''; + } + + $time_diff = time() - $timestamp; + + if ( $time_diff >= 0 && $time_diff < DAY_IN_SECONDS ) { + /* translators: human readable timestamp */ + return sprintf( __( '%s ago' ), human_time_diff( $timestamp ) ); + } + + return date_i18n( get_option( 'date_format' ), $timestamp ); + } + + /** + * Default column handler. + * + * @since 4.9.6 + * + * @param WP_User_Request $item Item being shown. + * @param string $column_name Name of column being shown. + * @return string Default column output. + */ + public function column_default( $item, $column_name ) { + $cell_value = $item->$column_name; + + if ( in_array( $column_name, array( 'created_timestamp' ), true ) ) { + return $this->get_timestamp_as_date( $cell_value ); + } + + return $cell_value; + } + + /** + * Actions column. Overridden by children. + * + * @since 4.9.6 + * + * @param WP_User_Request $item Item being shown. + * @return string Email column markup. + */ + public function column_email( $item ) { + return sprintf( '%2$s %3$s', esc_url( 'mailto:' . $item->email ), $item->email, $this->row_actions( array() ) ); + } + + /** + * Next steps column. Overridden by children. + * + * @since 4.9.6 + * + * @param WP_User_Request $item Item being shown. + */ + public function column_next_steps( $item ) {} + + /** + * Generates content for a single row of the table, + * + * @since 4.9.6 + * + * @param WP_User_Request $item The current item. + */ + public function single_row( $item ) { + $status = $item->status; + + echo ''; + $this->single_row_columns( $item ); + echo ''; + } + + /** + * Embed scripts used to perform actions. Overridden by children. + * + * @since 4.9.6 + */ + public function embed_scripts() {} +} diff --git a/wp-admin/includes/deprecated.php b/wp-admin/includes/deprecated.php index e65fe5a79c..45583c102a 100644 --- a/wp-admin/includes/deprecated.php +++ b/wp-admin/includes/deprecated.php @@ -1514,3 +1514,50 @@ function options_permalink_add_js() { 'themes', 'WP_Theme_Install_List_Table' => array( 'themes', 'theme-install' ), 'WP_Plugins_List_Table' => 'plugins', + // Network Admin - 'WP_MS_Sites_List_Table' => 'ms-sites', - 'WP_MS_Users_List_Table' => 'ms-users', - 'WP_MS_Themes_List_Table' => 'ms-themes', + 'WP_MS_Sites_List_Table' => 'ms-sites', + 'WP_MS_Users_List_Table' => 'ms-users', + 'WP_MS_Themes_List_Table' => 'ms-themes', + + // Privacy requests tables + 'WP_Privacy_Data_Export_Requests_List_Table' => 'privacy-data-export-requests', + 'WP_Privacy_Data_Removal_Requests_List_Table' => 'privacy-data-removal-requests', ); if ( isset( $core_classes[ $class ] ) ) { diff --git a/wp-admin/includes/misc.php b/wp-admin/includes/misc.php index 0dcebdfedb..6b46f67037 100644 --- a/wp-admin/includes/misc.php +++ b/wp-admin/includes/misc.php @@ -1318,720 +1318,6 @@ function _wp_privacy_settings_filter_draft_page_titles( $title, $page ) { return $title; } -/** - * WP_Privacy_Policy_Content class. - * TODO: move this to a new file. - * - * @since 4.9.6 - */ -final class WP_Privacy_Policy_Content { - - private static $policy_content = array(); - - /** - * Constructor - * - * @since 4.9.6 - */ - private function __construct() {} - - /** - * Add content to the postbox shown when editing the privacy policy. - * - * Plugins and themes should suggest text for inclusion in the site's privacy policy. - * The suggested text should contain information about any functionality that affects user privacy, - * and will be shown in the Suggested Privacy Policy Content postbox. - * - * Intended for use from `wp_add_privacy_policy_content()`. - * - * @since 4.9.6 - * - * @param string $plugin_name The name of the plugin or theme that is suggesting content for the site's privacy policy. - * @param string $policy_text The suggested content for inclusion in the policy. - */ - public static function add( $plugin_name, $policy_text ) { - if ( empty( $plugin_name ) || empty( $policy_text ) ) { - return; - } - - $data = array( - 'plugin_name' => $plugin_name, - 'policy_text' => $policy_text, - ); - - if ( ! in_array( $data, self::$policy_content, true ) ) { - self::$policy_content[] = $data; - } - } - - /** - * Quick check if any privacy info has changed. - * - * @since 4.9.6 - */ - public static function text_change_check() { - - $policy_page_id = (int) get_option( 'wp_page_for_privacy_policy' ); - - // The site doesn't have a privacy policy. - if ( empty( $policy_page_id ) ) { - return false; - } - - if ( ! current_user_can( 'edit_post', $policy_page_id ) ) { - return false; - } - - $old = (array) get_post_meta( $policy_page_id, '_wp_suggested_privacy_policy_content' ); - - // Updates are not relevant if the user has not reviewed any suggestions yet. - if ( empty( $old ) ) { - return false; - } - - $cached = get_option( '_wp_suggested_policy_text_has_changed' ); - - /* - * When this function is called before `admin_init`, `self::$policy_content` - * has not been populated yet, so use the cached result from the last - * execution instead. - */ - if ( ! did_action( 'admin_init' ) ) { - return 'changed' === $cached; - } - - $new = self::$policy_content; - - // Remove the extra values added to the meta. - foreach ( $old as $key => $data ) { - if ( ! empty( $data['removed'] ) ) { - unset( $old[ $key ] ); - continue; - } - - $old[ $key ] = array( - 'plugin_name' => $data['plugin_name'], - 'policy_text' => $data['policy_text'], - ); - } - - // Normalize the order of texts, to facilitate comparison. - sort( $old ); - sort( $new ); - - // The == operator (equal, not identical) was used intentionally. - // See http://php.net/manual/en/language.operators.array.php - if ( $new != $old ) { - // A plugin was activated or deactivated, or some policy text has changed. - // Show a notice on the relevant screens to inform the admin. - add_action( 'admin_notices', array( 'WP_Privacy_Policy_Content', 'policy_text_changed_notice' ) ); - $state = 'changed'; - } else { - $state = 'not-changed'; - } - - // Cache the result for use before `admin_init` (see above). - if ( $cached !== $state ) { - update_option( '_wp_suggested_policy_text_has_changed', $state ); - } - - return 'changed' === $state; - } - - /** - * Output a warning when some privacy info has changed. - * - * @since 4.9.6 - */ - public static function policy_text_changed_notice() { - global $post; - - $screen = get_current_screen()->id; - - if ( 'privacy' !== $screen ) { - return; - } - - ?> -
    -

    - review the guide and update your privacy policy.' ), - esc_url( admin_url( 'tools.php?wp-privacy-policy-guide=1' ) ) - ); - ?> -

    -
    - $old_data ) { - if ( ! empty( $old_data['removed'] ) ) { - // Remove the old policy text. - $update_cache = true; - continue; - } - - if ( ! empty( $old_data['updated'] ) ) { - // 'updated' is now 'added'. - $done[] = array( - 'plugin_name' => $old_data['plugin_name'], - 'policy_text' => $old_data['policy_text'], - 'added' => $old_data['updated'], - ); - $update_cache = true; - } else { - $done[] = $old_data; - } - } - - if ( $update_cache ) { - delete_post_meta( $policy_page_id, '_wp_suggested_privacy_policy_content' ); - // Update the cache. - foreach ( $done as $data ) { - add_post_meta( $policy_page_id, '_wp_suggested_privacy_policy_content', $data ); - } - } - } - - /** - * Check for updated, added or removed privacy policy information from plugins. - * - * Caches the current info in post_meta of the policy page. - * - * @since 4.9.6 - * - * @return array The privacy policy text/informtion added by core and plugins. - */ - public static function get_suggested_policy_text() { - $policy_page_id = (int) get_option( 'wp_page_for_privacy_policy' ); - $checked = array(); - $time = time(); - $update_cache = false; - $new = self::$policy_content; - $old = array(); - - if ( $policy_page_id ) { - $old = (array) get_post_meta( $policy_page_id, '_wp_suggested_privacy_policy_content' ); - } - - // Check for no-changes and updates. - foreach ( $new as $new_key => $new_data ) { - foreach ( $old as $old_key => $old_data ) { - $found = false; - - if ( $new_data['policy_text'] === $old_data['policy_text'] ) { - // Use the new plugin name in case it was changed, translated, etc. - if ( $old_data['plugin_name'] !== $new_data['plugin_name'] ) { - $old_data['plugin_name'] = $new_data['plugin_name']; - $update_cache = true; - } - - // A plugin was re-activated. - if ( ! empty( $old_data['removed'] ) ) { - unset( $old_data['removed'] ); - $old_data['added'] = $time; - $update_cache = true; - } - - $checked[] = $old_data; - $found = true; - } elseif ( $new_data['plugin_name'] === $old_data['plugin_name'] ) { - // The info for the policy was updated. - $checked[] = array( - 'plugin_name' => $new_data['plugin_name'], - 'policy_text' => $new_data['policy_text'], - 'updated' => $time, - ); - $found = $update_cache = true; - } - - if ( $found ) { - unset( $new[ $new_key ], $old[ $old_key ] ); - continue 2; - } - } - } - - if ( ! empty( $new ) ) { - // A plugin was activated. - foreach ( $new as $new_data ) { - if ( ! empty( $new_data['plugin_name'] ) && ! empty( $new_data['policy_text'] ) ) { - $new_data['added'] = $time; - $checked[] = $new_data; - } - } - $update_cache = true; - } - - if ( ! empty( $old ) ) { - // A plugin was deactivated. - foreach ( $old as $old_data ) { - if ( ! empty( $old_data['plugin_name'] ) && ! empty( $old_data['policy_text'] ) ) { - $data = array( - 'plugin_name' => $old_data['plugin_name'], - 'policy_text' => $old_data['policy_text'], - 'removed' => $time, - ); - - $checked[] = $data; - } - } - $update_cache = true; - } - - if ( $update_cache && $policy_page_id ) { - delete_post_meta( $policy_page_id, '_wp_suggested_privacy_policy_content' ); - // Update the cache. - foreach ( $checked as $data ) { - add_post_meta( $policy_page_id, '_wp_suggested_privacy_policy_content', $data ); - } - } - - return $checked; - } - - /** - * Add a notice with a link to the guide when editing the privacy policy page. - * - * @since 4.9.6 - * @since 5.0.0 The $post parameter is now optional. - * - * @param WP_Post|null $post The currently edited post. Default null. - */ - public static function notice( $post = null ) { - if ( is_null( $post ) ) { - global $post; - } else { - $post = get_post( $post ); - } - - if ( ! ( $post instanceof WP_Post ) ) { - return; - } - - if ( ! current_user_can( 'manage_privacy_options' ) ) { - return; - } - - $policy_page_id = (int) get_option( 'wp_page_for_privacy_policy' ); - - if ( ! $policy_page_id || $policy_page_id !== $post->ID ) { - return; - } - - $message = __( 'Need help putting together your new Privacy Policy page? Check out our guide for recommendations on what content to include, along with policies suggested by your plugins and theme.' ); - $url = esc_url( admin_url( 'tools.php?wp-privacy-policy-guide=1' ) ); - $label = __( 'View Privacy Policy Guide.' ); - - if ( get_current_screen()->is_block_editor() ) { - wp_enqueue_script( 'wp-notices' ); - $action = array( - 'url' => $url, - 'label' => $label, - ); - wp_add_inline_script( - 'wp-notices', - sprintf( - 'wp.data.dispatch( "core/notices" ).createWarningNotice( "%s", { actions: [ %s ], isDismissible: false } )', - $message, - wp_json_encode( $action ) - ), - 'after' - ); - } else { - ?> -
    -

    - %s %s', - $url, - $label, - /* translators: accessibility text */ - __( '(opens in a new tab)' ) - ); - ?> -

    -
    - ' . __( 'Introduction' ) . '' ); - $date_format = __( 'F j, Y' ); - $copy = __( 'Copy this section to clipboard' ); - $return_to_top = '' . __( '↑ Return to Top' ) . ''; - - foreach ( $content_array as $section ) { - $class = $meta = $removed = ''; - - if ( ! empty( $section['removed'] ) ) { - $class = ' text-removed'; - $date = date_i18n( $date_format, $section['removed'] ); - $meta = sprintf( __( 'Removed %s.' ), $date ); - - $removed = __( 'You deactivated this plugin on %s and may no longer need this policy.' ); - $removed = '

    ' . sprintf( $removed, $date ) . '

    '; - } elseif ( ! empty( $section['updated'] ) ) { - $class = ' text-updated'; - $date = date_i18n( $date_format, $section['updated'] ); - $meta = sprintf( __( 'Updated %s.' ), $date ); - } - - if ( $meta ) { - $meta = '
    ' . $meta . ''; - } - - $plugin_name = esc_html( $section['plugin_name'] ); - $toc_id = 'wp-privacy-policy-guide-' . sanitize_title( $plugin_name ); - $toc[] = sprintf( '
  • %2$s' . $meta . '
  • ', $toc_id, $plugin_name ); - - $content .= '
    '; - $content .= ' '; - /* translators: %s: plugin name */ - $content .= '

    ' . sprintf( __( 'Source: %s' ), $plugin_name ) . '

    '; - $content .= $removed; - - $content .= '
    ' . $section['policy_text'] . '
    '; - $content .= $return_to_top; - - if ( empty( $section['removed'] ) ) { - $content .= '
    '; - $content .= ''; - $content .= '
    '; - } - - $content .= "
    \n"; // End of .privacy-text-section. - } - - if ( count( $toc ) > 2 ) { - ?> -
    -

    -
      - -
    -
    - -
    -
    -   -

    -

    -

    -

    -

    -

    -
    - -
    - -
    -
    - ' . __( 'Suggested text:' ) . ' ' : ''; - $content = ''; - $strings = array(); - - // Start of the suggested privacy policy text. - if ( $description ) { - $strings[] = '
    '; - } - - /* translators: default privacy policy heading. */ - $strings[] = '

    ' . __( 'Who we are' ) . '

    '; - - if ( $description ) { - /* translators: privacy policy tutorial. */ - $strings[] = '

    ' . __( 'In this section you should note your site URL, as well as the name of the company, organization, or individual behind it, and some accurate contact information.' ) . '

    '; - /* translators: privacy policy tutorial. */ - $strings[] = '

    ' . __( 'The amount of information you may be required to show will vary depending on your local or national business regulations. You may, for example, be required to display a physical address, a registered address, or your company registration number.' ) . '

    '; - } - - /* translators: default privacy policy text, %s Site URL. */ - $strings[] = '

    ' . $suggested_text . sprintf( __( 'Our website address is: %s.' ), get_bloginfo( 'url', 'display' ) ) . '

    '; - - /* translators: default privacy policy heading. */ - $strings[] = '

    ' . __( 'What personal data we collect and why we collect it' ) . '

    '; - - if ( $description ) { - /* translators: privacy policy tutorial. */ - $strings[] = '

    ' . __( 'In this section you should note what personal data you collect from users and site visitors. This may include personal data, such as name, email address, personal account preferences; transactional data, such as purchase information; and technical data, such as information about cookies.' ) . '

    '; - /* translators: privacy policy tutorial. */ - $strings[] = '

    ' . __( 'You should also note any collection and retention of sensitive personal data, such as data concerning health.' ) . '

    '; - /* translators: privacy policy tutorial. */ - $strings[] = '

    ' . __( 'In addition to listing what personal data you collect, you need to note why you collect it. These explanations must note either the legal basis for your data collection and retention or the active consent the user has given.' ) . '

    '; - /* translators: privacy policy tutorial. */ - $strings[] = '

    ' . __( 'Personal data is not just created by a user’s interactions with your site. Personal data is also generated from technical processes such as contact forms, comments, cookies, analytics, and third party embeds.' ) . '

    '; - /* translators: privacy policy tutorial. */ - $strings[] = '

    ' . __( 'By default WordPress does not collect any personal data about visitors, and only collects the data shown on the User Profile screen from registered users. However some of your plugins may collect personal data. You should add the relevant information below.' ) . '

    '; - } - - /* translators: default privacy policy heading. */ - $strings[] = '

    ' . __( 'Comments' ) . '

    '; - - if ( $description ) { - /* translators: privacy policy tutorial. */ - $strings[] = '

    ' . __( 'In this subsection you should note what information is captured through comments. We have noted the data which WordPress collects by default.' ) . '

    '; - } - - /* translators: default privacy policy text. */ - $strings[] = '

    ' . $suggested_text . __( 'When visitors leave comments on the site we collect the data shown in the comments form, and also the visitor’s IP address and browser user agent string to help spam detection.' ) . '

    '; - /* translators: default privacy policy text. */ - $strings[] = '

    ' . __( 'An anonymized string created from your email address (also called a hash) may be provided to the Gravatar service to see if you are using it. The Gravatar service privacy policy is available here: https://automattic.com/privacy/. After approval of your comment, your profile picture is visible to the public in the context of your comment.' ) . '

    '; - - /* translators: default privacy policy heading. */ - $strings[] = '

    ' . __( 'Media' ) . '

    '; - - if ( $description ) { - /* translators: privacy policy tutorial. */ - $strings[] = '

    ' . __( 'In this subsection you should note what information may be disclosed by users who can upload media files. All uploaded files are usually publicly accessible.' ) . '

    '; - } - - /* translators: default privacy policy text. */ - $strings[] = '

    ' . $suggested_text . __( 'If you upload images to the website, you should avoid uploading images with embedded location data (EXIF GPS) included. Visitors to the website can download and extract any location data from images on the website.' ) . '

    '; - - /* translators: default privacy policy heading. */ - $strings[] = '

    ' . __( 'Contact forms' ) . '

    '; - - if ( $description ) { - /* translators: privacy policy tutorial. */ - $strings[] = '

    ' . __( 'By default, WordPress does not include a contact form. If you use a contact form plugin, use this subsection to note what personal data is captured when someone submits a contact form, and how long you keep it. For example, you may note that you keep contact form submissions for a certain period for customer service purposes, but you do not use the information submitted through them for marketing purposes.' ) . '

    '; - } - - /* translators: default privacy policy heading. */ - $strings[] = '

    ' . __( 'Cookies' ) . '

    '; - - if ( $description ) { - /* translators: privacy policy tutorial. */ - $strings[] = '

    ' . __( 'In this subsection you should list the cookies your web site uses, including those set by your plugins, social media, and analytics. We have provided the cookies which WordPress installs by default.' ) . '

    '; - } - - /* translators: default privacy policy text. */ - $strings[] = '

    ' . $suggested_text . __( 'If you leave a comment on our site you may opt-in to saving your name, email address and website in cookies. These are for your convenience so that you do not have to fill in your details again when you leave another comment. These cookies will last for one year.' ) . '

    '; - /* translators: default privacy policy text. */ - $strings[] = '

    ' . __( 'If you visit our login page, we will set a temporary cookie to determine if your browser accepts cookies. This cookie contains no personal data and is discarded when you close your browser.' ) . '

    '; - /* translators: default privacy policy text. */ - $strings[] = '

    ' . __( 'When you log in, we will also set up several cookies to save your login information and your screen display choices. Login cookies last for two days, and screen options cookies last for a year. If you select "Remember Me", your login will persist for two weeks. If you log out of your account, the login cookies will be removed.' ) . '

    '; - /* translators: default privacy policy text. */ - $strings[] = '

    ' . __( 'If you edit or publish an article, an additional cookie will be saved in your browser. This cookie includes no personal data and simply indicates the post ID of the article you just edited. It expires after 1 day.' ) . '

    '; - - /* translators: default privacy policy heading. */ - $strings[] = '

    ' . __( 'Embedded content from other websites' ) . '

    '; - /* translators: default privacy policy text. */ - $strings[] = '

    ' . $suggested_text . __( 'Articles on this site may include embedded content (e.g. videos, images, articles, etc.). Embedded content from other websites behaves in the exact same way as if the visitor has visited the other website.' ) . '

    '; - /* translators: default privacy policy text. */ - $strings[] = '

    ' . __( 'These websites may collect data about you, use cookies, embed additional third-party tracking, and monitor your interaction with that embedded content, including tracking your interaction with the embedded content if you have an account and are logged in to that website.' ) . '

    '; - - /* translators: default privacy policy heading. */ - $strings[] = '

    ' . __( 'Analytics' ) . '

    '; - - if ( $description ) { - /* translators: privacy policy tutorial. */ - $strings[] = '

    ' . __( 'In this subsection you should note what analytics package you use, how users can opt out of analytics tracking, and a link to your analytics provider’s privacy policy, if any.' ) . '

    '; - /* translators: privacy policy tutorial. */ - $strings[] = '

    ' . __( 'By default WordPress does not collect any analytics data. However, many web hosting accounts collect some anonymous analytics data. You may also have installed a WordPress plugin that provides analytics services. In that case, add information from that plugin here.' ) . '

    '; - } - - /* translators: default privacy policy heading. */ - $strings[] = '

    ' . __( 'Who we share your data with' ) . '

    '; - - if ( $description ) { - /* translators: privacy policy tutorial. */ - $strings[] = '

    ' . __( 'In this section you should name and list all third party providers with whom you share site data, including partners, cloud-based services, payment processors, and third party service providers, and note what data you share with them and why. Link to their own privacy policies if possible.' ) . '

    '; - /* translators: privacy policy tutorial. */ - $strings[] = '

    ' . __( 'By default WordPress does not share any personal data with anyone.' ) . '

    '; - } - - /* translators: default privacy policy heading. */ - $strings[] = '

    ' . __( 'How long we retain your data' ) . '

    '; - - if ( $description ) { - /* translators: privacy policy tutorial. */ - $strings[] = '

    ' . __( 'In this section you should explain how long you retain personal data collected or processed by the web site. While it is your responsibility to come up with the schedule of how long you keep each dataset for and why you keep it, that information does need to be listed here. For example, you may want to say that you keep contact form entries for six months, analytics records for a year, and customer purchase records for ten years.' ) . '

    '; - } - - /* translators: default privacy policy text. */ - $strings[] = '

    ' . $suggested_text . __( 'If you leave a comment, the comment and its metadata are retained indefinitely. This is so we can recognize and approve any follow-up comments automatically instead of holding them in a moderation queue.' ) . '

    '; - /* translators: default privacy policy text. */ - $strings[] = '

    ' . __( 'For users that register on our website (if any), we also store the personal information they provide in their user profile. All users can see, edit, or delete their personal information at any time (except they cannot change their username). Website administrators can also see and edit that information.' ) . '

    '; - - /* translators: default privacy policy heading. */ - $strings[] = '

    ' . __( 'What rights you have over your data' ) . '

    '; - - if ( $description ) { - /* translators: privacy policy tutorial. */ - $strings[] = '

    ' . __( 'In this section you should explain what rights your users have over their data and how they can invoke those rights.' ) . '

    '; - } - - /* translators: default privacy policy text. */ - $strings[] = '

    ' . $suggested_text . __( 'If you have an account on this site, or have left comments, you can request to receive an exported file of the personal data we hold about you, including any data you have provided to us. You can also request that we erase any personal data we hold about you. This does not include any data we are obliged to keep for administrative, legal, or security purposes.' ) . '

    '; - - /* translators: default privacy policy heading. */ - $strings[] = '

    ' . __( 'Where we send your data' ) . '

    '; - - if ( $description ) { - /* translators: privacy policy tutorial. */ - $strings[] = '

    ' . __( 'In this section you should list all transfers of your site data outside the European Union and describe the means by which that data is safeguarded to European data protection standards. This could include your web hosting, cloud storage, or other third party services.' ) . '

    '; - /* translators: privacy policy tutorial. */ - $strings[] = '

    ' . __( 'European data protection law requires data about European residents which is transferred outside the European Union to be safeguarded to the same standards as if the data was in Europe. So in addition to listing where data goes, you should describe how you ensure that these standards are met either by yourself or by your third party providers, whether that is through an agreement such as Privacy Shield, model clauses in your contracts, or binding corporate rules.' ) . '

    '; - } - - /* translators: default privacy policy text. */ - $strings[] = '

    ' . $suggested_text . __( 'Visitor comments may be checked through an automated spam detection service.' ) . '

    '; - - /* translators: default privacy policy heading. */ - $strings[] = '

    ' . __( 'Your contact information' ) . '

    '; - - if ( $description ) { - /* translators: privacy policy tutorial. */ - $strings[] = '

    ' . __( 'In this section you should provide a contact method for privacy-specific concerns. If you are required to have a Data Protection Officer, list their name and full contact details here as well.' ) . '

    '; - } - - /* translators: default privacy policy heading. */ - $strings[] = '

    ' . __( 'Additional information' ) . '

    '; - - if ( $description ) { - /* translators: privacy policy tutorial. */ - $strings[] = '

    ' . __( 'If you use your site for commercial purposes and you engage in more complex collection or processing of personal data, you should note the following information in your privacy policy in addition to the information we have already discussed.' ) . '

    '; - } - - /* translators: default privacy policy heading. */ - $strings[] = '

    ' . __( 'How we protect your data' ) . '

    '; - - if ( $description ) { - /* translators: privacy policy tutorial. */ - $strings[] = '

    ' . __( 'In this section you should explain what measures you have taken to protect your users’ data. This could include technical measures such as encryption; security measures such as two factor authentication; and measures such as staff training in data protection. If you have carried out a Privacy Impact Assessment, you can mention it here too.' ) . '

    '; - } - - /* translators: default privacy policy heading. */ - $strings[] = '

    ' . __( 'What data breach procedures we have in place' ) . '

    '; - - if ( $description ) { - /* translators: privacy policy tutorial. */ - $strings[] = '

    ' . __( 'In this section you should explain what procedures you have in place to deal with data breaches, either potential or real, such as internal reporting systems, contact mechanisms, or bug bounties.' ) . '

    '; - } - - /* translators: default privacy policy heading. */ - $strings[] = '

    ' . __( 'What third parties we receive data from' ) . '

    '; - - if ( $description ) { - /* translators: privacy policy tutorial. */ - $strings[] = '

    ' . __( 'If your web site receives data about users from third parties, including advertisers, this information must be included within the section of your privacy policy dealing with third party data.' ) . '

    '; - } - - /* translators: default privacy policy heading. */ - $strings[] = '

    ' . __( 'What automated decision making and/or profiling we do with user data' ) . '

    '; - - if ( $description ) { - /* translators: privacy policy tutorial. */ - $strings[] = '

    ' . __( 'If your web site provides a service which includes automated decision making - for example, allowing customers to apply for credit, or aggregating their data into an advertising profile - you must note that this is taking place, and include information about how that information is used, what decisions are made with that aggregated data, and what rights users have over decisions made without human intervention.' ) . '

    '; - } - - /* translators: default privacy policy heading. */ - $strings[] = '

    ' . __( 'Industry regulatory disclosure requirements' ) . '

    '; - - if ( $description ) { - /* translators: privacy policy tutorial. */ - $strings[] = '

    ' . __( 'If you are a member of a regulated industry, or if you are subject to additional privacy laws, you may be required to disclose that information here.' ) . '

    '; - $strings[] = '
    '; - } - - if ( $blocks ) { - foreach ( $strings as $key => $string ) { - if ( 0 === strpos( $string, '

    ' ) ) { - $strings[ $key ] = '' . $string . ''; - } - - if ( 0 === strpos( $string, '

    ' ) ) { - $strings[ $key ] = '' . $string . ''; - } - - if ( 0 === strpos( $string, '

    ' ) ) { - $strings[ $key ] = '' . $string . ''; - } - } - } - - $content = implode( '', $strings ); - // End of the suggested privacy policy text. - - /** - * Filters the default content suggested for inclusion in a privacy policy. - * - * @since 4.9.6 - * @since 5.0.0 Added the `$strings`, `$description`, and `$blocks` parameters. - * - * @param string $content The default policy content. - * @param array $strings An array of privacy policy content strings. - * @param bool $description Whether policy descriptions should be included. - * @param bool $blocks Whether the content should be formatted for the block editor. - */ - return apply_filters( 'wp_get_default_privacy_policy_content', $content, $strings, $description, $blocks ); - } - - /** - * Add the suggested privacy policy text to the policy postbox. - * - * @since 4.9.6 - */ - public static function add_suggested_content() { - $content = self::get_default_content( true, false ); - wp_add_privacy_policy_content( __( 'WordPress' ), $content ); - } -} - /** * Checks if the user needs to update PHP. * diff --git a/wp-admin/includes/plugin.php b/wp-admin/includes/plugin.php index 7a1b038518..6244c3fd44 100644 --- a/wp-admin/includes/plugin.php +++ b/wp-admin/includes/plugin.php @@ -2187,7 +2187,7 @@ function wp_add_privacy_policy_content( $plugin_name, $policy_text ) { } if ( ! class_exists( 'WP_Privacy_Policy_Content' ) ) { - require_once( ABSPATH . 'wp-admin/includes/misc.php' ); + require_once( ABSPATH . 'wp-admin/includes/class-wp-privacy-policy-content.php' ); } WP_Privacy_Policy_Content::add( $plugin_name, $policy_text ); diff --git a/wp-admin/includes/privacy-tools.php b/wp-admin/includes/privacy-tools.php new file mode 100644 index 0000000000..67d8e43611 --- /dev/null +++ b/wp-admin/includes/privacy-tools.php @@ -0,0 +1,289 @@ +post_type ) { + return new WP_Error( 'privacy_request_error', __( 'Invalid request.' ) ); + } + + $result = wp_send_user_request( $request_id ); + + if ( is_wp_error( $result ) ) { + return $result; + } elseif ( ! $result ) { + return new WP_Error( 'privacy_request_error', __( 'Unable to initiate confirmation request.' ) ); + } + + return true; +} + +/** + * Marks a request as completed by the admin and logs the current timestamp. + * + * @since 4.9.6 + * @access private + * + * @param int $request_id Request ID. + * @return int|WP_Error $result Request ID on success or WP_Error. + */ +function _wp_privacy_completed_request( $request_id ) { + $request_id = absint( $request_id ); + $request = wp_get_user_request_data( $request_id ); + + if ( ! $request ) { + return new WP_Error( 'privacy_request_error', __( 'Invalid request.' ) ); + } + + update_post_meta( $request_id, '_wp_user_request_completed_timestamp', time() ); + + $result = wp_update_post( + array( + 'ID' => $request_id, + 'post_status' => 'request-completed', + ) + ); + + return $result; +} + +/** + * Handle list table actions. + * + * @since 4.9.6 + * @access private + */ +function _wp_personal_data_handle_actions() { + if ( isset( $_POST['privacy_action_email_retry'] ) ) { + check_admin_referer( 'bulk-privacy_requests' ); + + $request_id = absint( current( array_keys( (array) wp_unslash( $_POST['privacy_action_email_retry'] ) ) ) ); + $result = _wp_privacy_resend_request( $request_id ); + + if ( is_wp_error( $result ) ) { + add_settings_error( + 'privacy_action_email_retry', + 'privacy_action_email_retry', + $result->get_error_message(), + 'error' + ); + } else { + add_settings_error( + 'privacy_action_email_retry', + 'privacy_action_email_retry', + __( 'Confirmation request sent again successfully.' ), + 'updated' + ); + } + } elseif ( isset( $_POST['action'] ) ) { + $action = ! empty( $_POST['action'] ) ? sanitize_key( wp_unslash( $_POST['action'] ) ) : ''; + + switch ( $action ) { + case 'add_export_personal_data_request': + case 'add_remove_personal_data_request': + check_admin_referer( 'personal-data-request' ); + + if ( ! isset( $_POST['type_of_action'], $_POST['username_or_email_for_privacy_request'] ) ) { + add_settings_error( + 'action_type', + 'action_type', + __( 'Invalid action.' ), + 'error' + ); + } + $action_type = sanitize_text_field( wp_unslash( $_POST['type_of_action'] ) ); + $username_or_email_address = sanitize_text_field( wp_unslash( $_POST['username_or_email_for_privacy_request'] ) ); + $email_address = ''; + + if ( ! in_array( $action_type, _wp_privacy_action_request_types(), true ) ) { + add_settings_error( + 'action_type', + 'action_type', + __( 'Invalid action.' ), + 'error' + ); + } + + if ( ! is_email( $username_or_email_address ) ) { + $user = get_user_by( 'login', $username_or_email_address ); + if ( ! $user instanceof WP_User ) { + add_settings_error( + 'username_or_email_for_privacy_request', + 'username_or_email_for_privacy_request', + __( 'Unable to add this request. A valid email address or username must be supplied.' ), + 'error' + ); + } else { + $email_address = $user->user_email; + } + } else { + $email_address = $username_or_email_address; + } + + if ( empty( $email_address ) ) { + break; + } + + $request_id = wp_create_user_request( $email_address, $action_type ); + + if ( is_wp_error( $request_id ) ) { + add_settings_error( + 'username_or_email_for_privacy_request', + 'username_or_email_for_privacy_request', + $request_id->get_error_message(), + 'error' + ); + break; + } elseif ( ! $request_id ) { + add_settings_error( + 'username_or_email_for_privacy_request', + 'username_or_email_for_privacy_request', + __( 'Unable to initiate confirmation request.' ), + 'error' + ); + break; + } + + wp_send_user_request( $request_id ); + + add_settings_error( + 'username_or_email_for_privacy_request', + 'username_or_email_for_privacy_request', + __( 'Confirmation request initiated successfully.' ), + 'updated' + ); + break; + } + } +} + +/** + * Cleans up failed and expired requests before displaying the list table. + * + * @since 4.9.6 + * @access private + */ +function _wp_personal_data_cleanup_requests() { + /** This filter is documented in wp-includes/user.php */ + $expires = (int) apply_filters( 'user_request_key_expiration', DAY_IN_SECONDS ); + + $requests_query = new WP_Query( + array( + 'post_type' => 'user_request', + 'posts_per_page' => -1, + 'post_status' => 'request-pending', + 'fields' => 'ids', + 'date_query' => array( + array( + 'column' => 'post_modified_gmt', + 'before' => $expires . ' seconds ago', + ), + ), + ) + ); + + $request_ids = $requests_query->posts; + + foreach ( $request_ids as $request_id ) { + wp_update_post( + array( + 'ID' => $request_id, + 'post_status' => 'request-failed', + 'post_password' => '', + ) + ); + } +} + +/** + * Mark erasure requests as completed after processing is finished. + * + * This intercepts the Ajax responses to personal data eraser page requests, and + * monitors the status of a request. Once all of the processing has finished, the + * request is marked as completed. + * + * @since 4.9.6 + * + * @see wp_privacy_personal_data_erasure_page + * + * @param array $response The response from the personal data eraser for + * the given page. + * @param int $eraser_index The index of the personal data eraser. Begins + * at 1. + * @param string $email_address The email address of the user whose personal + * data this is. + * @param int $page The page of personal data for this eraser. + * Begins at 1. + * @param int $request_id The request ID for this personal data erasure. + * @return array The filtered response. + */ +function wp_privacy_process_personal_data_erasure_page( $response, $eraser_index, $email_address, $page, $request_id ) { + /* + * If the eraser response is malformed, don't attempt to consume it; let it + * pass through, so that the default Ajax processing will generate a warning + * to the user. + */ + if ( ! is_array( $response ) ) { + return $response; + } + + if ( ! array_key_exists( 'done', $response ) ) { + return $response; + } + + if ( ! array_key_exists( 'items_removed', $response ) ) { + return $response; + } + + if ( ! array_key_exists( 'items_retained', $response ) ) { + return $response; + } + + if ( ! array_key_exists( 'messages', $response ) ) { + return $response; + } + + $request = wp_get_user_request_data( $request_id ); + + if ( ! $request || 'remove_personal_data' !== $request->action_name ) { + wp_send_json_error( __( 'Invalid request ID when processing eraser data.' ) ); + } + + /** This filter is documented in wp-admin/includes/ajax-actions.php */ + $erasers = apply_filters( 'wp_privacy_personal_data_erasers', array() ); + $is_last_eraser = count( $erasers ) === $eraser_index; + $eraser_done = $response['done']; + + if ( ! $is_last_eraser || ! $eraser_done ) { + return $response; + } + + _wp_privacy_completed_request( $request_id ); + + /** + * Fires immediately after a personal data erasure request has been marked completed. + * + * @since 4.9.6 + * + * @param int $request_id The privacy request post ID associated with this request. + */ + do_action( 'wp_privacy_personal_data_erased', $request_id ); + + return $response; +} diff --git a/wp-admin/includes/upgrade.php b/wp-admin/includes/upgrade.php index 38fdb9b25c..03901109ad 100644 --- a/wp-admin/includes/upgrade.php +++ b/wp-admin/includes/upgrade.php @@ -342,7 +342,7 @@ Commenter avatars come from Gravatar.' $privacy_policy_content = get_site_option( 'default_privacy_policy_content' ); } else { if ( ! class_exists( 'WP_Privacy_Policy_Content' ) ) { - include_once( ABSPATH . 'wp-admin/includes/misc.php' ); + include_once( ABSPATH . 'wp-admin/includes/class-wp-privacy-policy-content.php' ); } $privacy_policy_content = WP_Privacy_Policy_Content::get_default_content(); diff --git a/wp-admin/includes/user.php b/wp-admin/includes/user.php index 558ff24970..e4b5534c3e 100644 --- a/wp-admin/includes/user.php +++ b/wp-admin/includes/user.php @@ -582,1142 +582,3 @@ Please click the following link to activate your user account: wp_specialchars_decode( translate_user_role( $role['name'] ) ) ); } - -/** - * Resend an existing request and return the result. - * - * @since 4.9.6 - * @access private - * - * @param int $request_id Request ID. - * @return bool|WP_Error Returns true/false based on the success of sending the email, or a WP_Error object. - */ -function _wp_privacy_resend_request( $request_id ) { - $request_id = absint( $request_id ); - $request = get_post( $request_id ); - - if ( ! $request || 'user_request' !== $request->post_type ) { - return new WP_Error( 'privacy_request_error', __( 'Invalid request.' ) ); - } - - $result = wp_send_user_request( $request_id ); - - if ( is_wp_error( $result ) ) { - return $result; - } elseif ( ! $result ) { - return new WP_Error( 'privacy_request_error', __( 'Unable to initiate confirmation request.' ) ); - } - - return true; -} - -/** - * Marks a request as completed by the admin and logs the current timestamp. - * - * @since 4.9.6 - * @access private - * - * @param int $request_id Request ID. - * @return int|WP_Error $result Request ID on success or WP_Error. - */ -function _wp_privacy_completed_request( $request_id ) { - $request_id = absint( $request_id ); - $request = wp_get_user_request_data( $request_id ); - - if ( ! $request ) { - return new WP_Error( 'privacy_request_error', __( 'Invalid request.' ) ); - } - - update_post_meta( $request_id, '_wp_user_request_completed_timestamp', time() ); - - $result = wp_update_post( - array( - 'ID' => $request_id, - 'post_status' => 'request-completed', - ) - ); - - return $result; -} - -/** - * Handle list table actions. - * - * @since 4.9.6 - * @access private - */ -function _wp_personal_data_handle_actions() { - if ( isset( $_POST['privacy_action_email_retry'] ) ) { - check_admin_referer( 'bulk-privacy_requests' ); - - $request_id = absint( current( array_keys( (array) wp_unslash( $_POST['privacy_action_email_retry'] ) ) ) ); - $result = _wp_privacy_resend_request( $request_id ); - - if ( is_wp_error( $result ) ) { - add_settings_error( - 'privacy_action_email_retry', - 'privacy_action_email_retry', - $result->get_error_message(), - 'error' - ); - } else { - add_settings_error( - 'privacy_action_email_retry', - 'privacy_action_email_retry', - __( 'Confirmation request sent again successfully.' ), - 'updated' - ); - } - } elseif ( isset( $_POST['action'] ) ) { - $action = isset( $_POST['action'] ) ? sanitize_key( wp_unslash( $_POST['action'] ) ) : ''; - - switch ( $action ) { - case 'add_export_personal_data_request': - case 'add_remove_personal_data_request': - check_admin_referer( 'personal-data-request' ); - - if ( ! isset( $_POST['type_of_action'], $_POST['username_or_email_for_privacy_request'] ) ) { - add_settings_error( - 'action_type', - 'action_type', - __( 'Invalid action.' ), - 'error' - ); - } - $action_type = sanitize_text_field( wp_unslash( $_POST['type_of_action'] ) ); - $username_or_email_address = sanitize_text_field( wp_unslash( $_POST['username_or_email_for_privacy_request'] ) ); - $email_address = ''; - - if ( ! in_array( $action_type, _wp_privacy_action_request_types(), true ) ) { - add_settings_error( - 'action_type', - 'action_type', - __( 'Invalid action.' ), - 'error' - ); - } - - if ( ! is_email( $username_or_email_address ) ) { - $user = get_user_by( 'login', $username_or_email_address ); - if ( ! $user instanceof WP_User ) { - add_settings_error( - 'username_or_email_for_privacy_request', - 'username_or_email_for_privacy_request', - __( 'Unable to add this request. A valid email address or username must be supplied.' ), - 'error' - ); - } else { - $email_address = $user->user_email; - } - } else { - $email_address = $username_or_email_address; - } - - if ( empty( $email_address ) ) { - break; - } - - $request_id = wp_create_user_request( $email_address, $action_type ); - - if ( is_wp_error( $request_id ) ) { - add_settings_error( - 'username_or_email_for_privacy_request', - 'username_or_email_for_privacy_request', - $request_id->get_error_message(), - 'error' - ); - break; - } elseif ( ! $request_id ) { - add_settings_error( - 'username_or_email_for_privacy_request', - 'username_or_email_for_privacy_request', - __( 'Unable to initiate confirmation request.' ), - 'error' - ); - break; - } - - wp_send_user_request( $request_id ); - - add_settings_error( - 'username_or_email_for_privacy_request', - 'username_or_email_for_privacy_request', - __( 'Confirmation request initiated successfully.' ), - 'updated' - ); - break; - } - } -} - -/** - * Cleans up failed and expired requests before displaying the list table. - * - * @since 4.9.6 - * @access private - */ -function _wp_personal_data_cleanup_requests() { - /** This filter is documented in wp-includes/user.php */ - $expires = (int) apply_filters( 'user_request_key_expiration', DAY_IN_SECONDS ); - - $requests_query = new WP_Query( - array( - 'post_type' => 'user_request', - 'posts_per_page' => -1, - 'post_status' => 'request-pending', - 'fields' => 'ids', - 'date_query' => array( - array( - 'column' => 'post_modified_gmt', - 'before' => $expires . ' seconds ago', - ), - ), - ) - ); - - $request_ids = $requests_query->posts; - - foreach ( $request_ids as $request_id ) { - wp_update_post( - array( - 'ID' => $request_id, - 'post_status' => 'request-failed', - 'post_password' => '', - ) - ); - } -} - -/** - * Personal data export. - * - * @since 4.9.6 - * @access private - */ -function _wp_personal_data_export_page() { - if ( ! current_user_can( 'export_others_personal_data' ) ) { - wp_die( __( 'Sorry, you are not allowed to export personal data on this site.' ) ); - } - - _wp_personal_data_handle_actions(); - _wp_personal_data_cleanup_requests(); - - // "Borrow" xfn.js for now so we don't have to create new files. - wp_enqueue_script( 'xfn' ); - - $requests_table = new WP_Privacy_Data_Export_Requests_Table( - array( - 'plural' => 'privacy_requests', - 'singular' => 'privacy_request', - 'screen' => 'export_personal_data', - ) - ); - - $requests_table->screen->set_screen_reader_content( - array( - 'heading_views' => __( 'Filter export personal data list' ), - 'heading_pagination' => __( 'Export personal data list navigation' ), - 'heading_list' => __( 'Export personal data list' ), - ) - ); - - $requests_table->process_bulk_action(); - $requests_table->prepare_items(); - ?> -
    -

    -
    - - - -
    -

    -

    - -
    - - - -
    - - - -
    -
    - - views(); ?> - -
    - search_box( __( 'Search Requests' ), 'requests' ); ?> - - - - -
    - -
    - display(); - $requests_table->embed_scripts(); - ?> -
    -
    - 'privacy_requests', - 'singular' => 'privacy_request', - 'screen' => 'remove_personal_data', - ) - ); - - $requests_table->screen->set_screen_reader_content( - array( - 'heading_views' => __( 'Filter erase personal data list' ), - 'heading_pagination' => __( 'Erase personal data list navigation' ), - 'heading_list' => __( 'Erase personal data list' ), - ) - ); - - $requests_table->process_bulk_action(); - $requests_table->prepare_items(); - - ?> -
    -

    -
    - - - -
    -

    -

    - -
    - - - -
    - - - -
    -
    - - views(); ?> - -
    - search_box( __( 'Search Requests' ), 'requests' ); ?> - - - - -
    - -
    - display(); - $requests_table->embed_scripts(); - ?> -
    -
    - action_name ) { - wp_send_json_error( __( 'Invalid request ID when processing eraser data.' ) ); - } - - /** This filter is documented in wp-admin/includes/ajax-actions.php */ - $erasers = apply_filters( 'wp_privacy_personal_data_erasers', array() ); - $is_last_eraser = count( $erasers ) === $eraser_index; - $eraser_done = $response['done']; - - if ( ! $is_last_eraser || ! $eraser_done ) { - return $response; - } - - _wp_privacy_completed_request( $request_id ); - - /** - * Fires immediately after a personal data erasure request has been marked completed. - * - * @since 4.9.6 - * - * @param int $request_id The privacy request post ID associated with this request. - */ - do_action( 'wp_privacy_personal_data_erased', $request_id ); - - return $response; -} - -/** - * Add requests pages. - * - * @since 4.9.6 - * @access private - */ -function _wp_privacy_hook_requests_page() { - add_submenu_page( 'tools.php', __( 'Export Personal Data' ), __( 'Export Personal Data' ), 'export_others_personal_data', 'export_personal_data', '_wp_personal_data_export_page' ); - add_submenu_page( 'tools.php', __( 'Erase Personal Data' ), __( 'Erase Personal Data' ), 'erase_others_personal_data', 'remove_personal_data', '_wp_personal_data_removal_page' ); -} - -/** - * Add options for the privacy requests screens. - * - * @since 4.9.8 - * @access private - */ -function _wp_privacy_requests_screen_options() { - $args = array( - 'option' => str_replace( 'tools_page_', '', get_current_screen()->id ) . '_requests_per_page', - ); - add_screen_option( 'per_page', $args ); -} - -// TODO: move the following classes in new files. -if ( ! class_exists( 'WP_List_Table' ) ) { - require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' ); -} - -/** - * WP_Privacy_Requests_Table class. - * - * @since 4.9.6 - */ -abstract class WP_Privacy_Requests_Table extends WP_List_Table { - - /** - * Action name for the requests this table will work with. Classes - * which inherit from WP_Privacy_Requests_Table should define this. - * - * Example: 'export_personal_data'. - * - * @since 4.9.6 - * - * @var string $request_type Name of action. - */ - protected $request_type = 'INVALID'; - - /** - * Post type to be used. - * - * @since 4.9.6 - * - * @var string $post_type The post type. - */ - protected $post_type = 'INVALID'; - - /** - * Get columns to show in the list table. - * - * @since 4.9.6 - * - * @return array Array of columns. - */ - public function get_columns() { - $columns = array( - 'cb' => '', - 'email' => __( 'Requester' ), - 'status' => __( 'Status' ), - 'created_timestamp' => __( 'Requested' ), - 'next_steps' => __( 'Next Steps' ), - ); - return $columns; - } - - /** - * Get a list of sortable columns. - * - * @since 4.9.6 - * - * @return array Default sortable columns. - */ - protected function get_sortable_columns() { - // The initial sorting is by 'Requested' (post_date) and descending. - // With initial sorting, the first click on 'Requested' should be ascending. - // With 'Requester' sorting active, the next click on 'Requested' should be descending. - $desc_first = isset( $_GET['orderby'] ); - - return array( - 'email' => 'requester', - 'created_timestamp' => array( 'requested', $desc_first ), - ); - } - - /** - * Default primary column. - * - * @since 4.9.6 - * - * @return string Default primary column name. - */ - protected function get_default_primary_column_name() { - return 'email'; - } - - /** - * Count number of requests for each status. - * - * @since 4.9.6 - * - * @return object Number of posts for each status. - */ - protected function get_request_counts() { - global $wpdb; - - $cache_key = $this->post_type . '-' . $this->request_type; - $counts = wp_cache_get( $cache_key, 'counts' ); - - if ( false !== $counts ) { - return $counts; - } - - $query = " - SELECT post_status, COUNT( * ) AS num_posts - FROM {$wpdb->posts} - WHERE post_type = %s - AND post_name = %s - GROUP BY post_status"; - - $results = (array) $wpdb->get_results( $wpdb->prepare( $query, $this->post_type, $this->request_type ), ARRAY_A ); - $counts = array_fill_keys( get_post_stati(), 0 ); - - foreach ( $results as $row ) { - $counts[ $row['post_status'] ] = $row['num_posts']; - } - - $counts = (object) $counts; - wp_cache_set( $cache_key, $counts, 'counts' ); - - return $counts; - } - - /** - * Get an associative array ( id => link ) with the list of views available on this table. - * - * @since 4.9.6 - * - * @return array Associative array of views in the format of $view_name => $view_markup. - */ - protected function get_views() { - $current_status = isset( $_REQUEST['filter-status'] ) ? sanitize_text_field( $_REQUEST['filter-status'] ) : ''; - $statuses = _wp_privacy_statuses(); - $views = array(); - $admin_url = admin_url( 'tools.php?page=' . $this->request_type ); - $counts = $this->get_request_counts(); - $total_requests = absint( array_sum( (array) $counts ) ); - - $current_link_attributes = empty( $current_status ) ? ' class="current" aria-current="page"' : ''; - $status_label = sprintf( - /* translators: %s: all requests count */ - _nx( - 'All (%s)', - 'All (%s)', - $total_requests, - 'requests' - ), - number_format_i18n( $total_requests ) - ); - - $views['all'] = sprintf( - '%s', - esc_url( $admin_url ), - $current_link_attributes, - $status_label - ); - - foreach ( $statuses as $status => $label ) { - $post_status = get_post_status_object( $status ); - if ( ! $post_status ) { - continue; - } - - $current_link_attributes = $status === $current_status ? ' class="current" aria-current="page"' : ''; - $total_status_requests = absint( $counts->{$status} ); - $status_label = sprintf( - translate_nooped_plural( $post_status->label_count, $total_status_requests ), - number_format_i18n( $total_status_requests ) - ); - $status_link = add_query_arg( 'filter-status', $status, $admin_url ); - - $views[ $status ] = sprintf( - '%s', - esc_url( $status_link ), - $current_link_attributes, - $status_label - ); - } - - return $views; - } - - /** - * Get bulk actions. - * - * @since 4.9.6 - * - * @return array List of bulk actions. - */ - protected function get_bulk_actions() { - return array( - 'delete' => __( 'Remove' ), - 'resend' => __( 'Resend email' ), - ); - } - - /** - * Process bulk actions. - * - * @since 4.9.6 - */ - public function process_bulk_action() { - $action = $this->current_action(); - $request_ids = isset( $_REQUEST['request_id'] ) ? wp_parse_id_list( wp_unslash( $_REQUEST['request_id'] ) ) : array(); - - $count = 0; - - if ( $request_ids ) { - check_admin_referer( 'bulk-privacy_requests' ); - } - - switch ( $action ) { - case 'delete': - foreach ( $request_ids as $request_id ) { - if ( wp_delete_post( $request_id, true ) ) { - $count ++; - } - } - - add_settings_error( - 'bulk_action', - 'bulk_action', - /* translators: %d: number of requests */ - sprintf( _n( 'Deleted %d request', 'Deleted %d requests', $count ), $count ), - 'updated' - ); - break; - case 'resend': - foreach ( $request_ids as $request_id ) { - $resend = _wp_privacy_resend_request( $request_id ); - - if ( $resend && ! is_wp_error( $resend ) ) { - $count++; - } - } - - add_settings_error( - 'bulk_action', - 'bulk_action', - /* translators: %d: number of requests */ - sprintf( _n( 'Re-sent %d request', 'Re-sent %d requests', $count ), $count ), - 'updated' - ); - break; - } - } - - /** - * Prepare items to output. - * - * @since 4.9.6 - * @since 5.1.0 Added support for column sorting. - */ - public function prepare_items() { - global $wpdb; - - $this->items = array(); - $posts_per_page = $this->get_items_per_page( $this->request_type . '_requests_per_page' ); - $args = array( - 'post_type' => $this->post_type, - 'post_name__in' => array( $this->request_type ), - 'posts_per_page' => $posts_per_page, - 'offset' => isset( $_REQUEST['paged'] ) ? max( 0, absint( $_REQUEST['paged'] ) - 1 ) * $posts_per_page : 0, - 'post_status' => 'any', - 's' => isset( $_REQUEST['s'] ) ? sanitize_text_field( $_REQUEST['s'] ) : '', - ); - - $orderby_mapping = array( - 'requester' => 'post_title', - 'requested' => 'post_date', - ); - - if ( isset( $_REQUEST['orderby'] ) && isset( $orderby_mapping[ $_REQUEST['orderby'] ] ) ) { - $args['orderby'] = $orderby_mapping[ $_REQUEST['orderby'] ]; - } - - if ( isset( $_REQUEST['order'] ) && in_array( strtoupper( $_REQUEST['order'] ), array( 'ASC', 'DESC' ), true ) ) { - $args['order'] = strtoupper( $_REQUEST['order'] ); - } - - if ( ! empty( $_REQUEST['filter-status'] ) ) { - $filter_status = isset( $_REQUEST['filter-status'] ) ? sanitize_text_field( $_REQUEST['filter-status'] ) : ''; - $args['post_status'] = $filter_status; - } - - $requests_query = new WP_Query( $args ); - $requests = $requests_query->posts; - - foreach ( $requests as $request ) { - $this->items[] = wp_get_user_request_data( $request->ID ); - } - - $this->items = array_filter( $this->items ); - - $this->set_pagination_args( - array( - 'total_items' => $requests_query->found_posts, - 'per_page' => $posts_per_page, - ) - ); - } - - /** - * Checkbox column. - * - * @since 4.9.6 - * - * @param WP_User_Request $item Item being shown. - * @return string Checkbox column markup. - */ - public function column_cb( $item ) { - return sprintf( '', esc_attr( $item->ID ) ); - } - - /** - * Status column. - * - * @since 4.9.6 - * - * @param WP_User_Request $item Item being shown. - * @return string Status column markup. - */ - public function column_status( $item ) { - $status = get_post_status( $item->ID ); - $status_object = get_post_status_object( $status ); - - if ( ! $status_object || empty( $status_object->label ) ) { - return '-'; - } - - $timestamp = false; - - switch ( $status ) { - case 'request-confirmed': - $timestamp = $item->confirmed_timestamp; - break; - case 'request-completed': - $timestamp = $item->completed_timestamp; - break; - } - - echo ''; - echo esc_html( $status_object->label ); - - if ( $timestamp ) { - echo ' (' . $this->get_timestamp_as_date( $timestamp ) . ')'; - } - - echo ''; - } - - /** - * Convert timestamp for display. - * - * @since 4.9.6 - * - * @param int $timestamp Event timestamp. - * @return string Human readable date. - */ - protected function get_timestamp_as_date( $timestamp ) { - if ( empty( $timestamp ) ) { - return ''; - } - - $time_diff = time() - $timestamp; - - if ( $time_diff >= 0 && $time_diff < DAY_IN_SECONDS ) { - /* translators: human readable timestamp */ - return sprintf( __( '%s ago' ), human_time_diff( $timestamp ) ); - } - - return date_i18n( get_option( 'date_format' ), $timestamp ); - } - - /** - * Default column handler. - * - * @since 4.9.6 - * - * @param WP_User_Request $item Item being shown. - * @param string $column_name Name of column being shown. - * @return string Default column output. - */ - public function column_default( $item, $column_name ) { - $cell_value = $item->$column_name; - - if ( in_array( $column_name, array( 'created_timestamp' ), true ) ) { - return $this->get_timestamp_as_date( $cell_value ); - } - - return $cell_value; - } - - /** - * Actions column. Overridden by children. - * - * @since 4.9.6 - * - * @param WP_User_Request $item Item being shown. - * @return string Email column markup. - */ - public function column_email( $item ) { - return sprintf( '%2$s %3$s', esc_url( 'mailto:' . $item->email ), $item->email, $this->row_actions( array() ) ); - } - - /** - * Next steps column. Overridden by children. - * - * @since 4.9.6 - * - * @param WP_User_Request $item Item being shown. - */ - public function column_next_steps( $item ) {} - - /** - * Generates content for a single row of the table, - * - * @since 4.9.6 - * - * @param WP_User_Request $item The current item. - */ - public function single_row( $item ) { - $status = $item->status; - - echo ''; - $this->single_row_columns( $item ); - echo ''; - } - - /** - * Embed scripts used to perform actions. Overridden by children. - * - * @since 4.9.6 - */ - public function embed_scripts() {} -} - -/** - * WP_Privacy_Data_Export_Requests_Table class. - * - * @since 4.9.6 - */ -class WP_Privacy_Data_Export_Requests_Table extends WP_Privacy_Requests_Table { - /** - * Action name for the requests this table will work with. - * - * @since 4.9.6 - * - * @var string $request_type Name of action. - */ - protected $request_type = 'export_personal_data'; - - /** - * Post type for the requests. - * - * @since 4.9.6 - * - * @var string $post_type The post type. - */ - protected $post_type = 'user_request'; - - /** - * Actions column. - * - * @since 4.9.6 - * - * @param WP_User_Request $item Item being shown. - * @return string Email column markup. - */ - public function column_email( $item ) { - /** This filter is documented in wp-admin/includes/ajax-actions.php */ - $exporters = apply_filters( 'wp_privacy_personal_data_exporters', array() ); - $exporters_count = count( $exporters ); - $request_id = $item->ID; - $nonce = wp_create_nonce( 'wp-privacy-export-personal-data-' . $request_id ); - - $download_data_markup = '
    '; - - $download_data_markup .= '' . - '' . - '' . - ''; - - $download_data_markup .= '
    '; - - $row_actions = array( - 'download-data' => $download_data_markup, - ); - - return sprintf( '%2$s %3$s', esc_url( 'mailto:' . $item->email ), $item->email, $this->row_actions( $row_actions ) ); - } - - /** - * Displays the next steps column. - * - * @since 4.9.6 - * - * @param WP_User_Request $item Item being shown. - */ - public function column_next_steps( $item ) { - $status = $item->status; - - switch ( $status ) { - case 'request-pending': - esc_html_e( 'Waiting for confirmation' ); - break; - case 'request-confirmed': - /** This filter is documented in wp-admin/includes/ajax-actions.php */ - $exporters = apply_filters( 'wp_privacy_personal_data_exporters', array() ); - $exporters_count = count( $exporters ); - $request_id = $item->ID; - $nonce = wp_create_nonce( 'wp-privacy-export-personal-data-' . $request_id ); - - echo '
    '; - - ?> - - - - - '; - break; - case 'request-failed': - submit_button( __( 'Retry' ), 'secondary', 'privacy_action_email_retry[' . $item->ID . ']', false ); - break; - case 'request-completed': - echo '' . esc_html__( 'Remove request' ) . ''; - break; - } - } -} - -/** - * WP_Privacy_Data_Removal_Requests_Table class. - * - * @since 4.9.6 - */ -class WP_Privacy_Data_Removal_Requests_Table extends WP_Privacy_Requests_Table { - /** - * Action name for the requests this table will work with. - * - * @since 4.9.6 - * - * @var string $request_type Name of action. - */ - protected $request_type = 'remove_personal_data'; - - /** - * Post type for the requests. - * - * @since 4.9.6 - * - * @var string $post_type The post type. - */ - protected $post_type = 'user_request'; - - /** - * Actions column. - * - * @since 4.9.6 - * - * @param WP_User_Request $item Item being shown. - * @return string Email column markup. - */ - public function column_email( $item ) { - $row_actions = array(); - - // Allow the administrator to "force remove" the personal data even if confirmation has not yet been received. - $status = $item->status; - if ( 'request-confirmed' !== $status ) { - /** This filter is documented in wp-admin/includes/ajax-actions.php */ - $erasers = apply_filters( 'wp_privacy_personal_data_erasers', array() ); - $erasers_count = count( $erasers ); - $request_id = $item->ID; - $nonce = wp_create_nonce( 'wp-privacy-erase-personal-data-' . $request_id ); - - $remove_data_markup = '
    '; - - $remove_data_markup .= '' . - '' . - ''; - - $remove_data_markup .= '
    '; - - $row_actions = array( - 'remove-data' => $remove_data_markup, - ); - } - - return sprintf( '%2$s %3$s', esc_url( 'mailto:' . $item->email ), $item->email, $this->row_actions( $row_actions ) ); - } - - /** - * Next steps column. - * - * @since 4.9.6 - * - * @param WP_User_Request $item Item being shown. - */ - public function column_next_steps( $item ) { - $status = $item->status; - - switch ( $status ) { - case 'request-pending': - esc_html_e( 'Waiting for confirmation' ); - break; - case 'request-confirmed': - /** This filter is documented in wp-admin/includes/ajax-actions.php */ - $erasers = apply_filters( 'wp_privacy_personal_data_erasers', array() ); - $erasers_count = count( $erasers ); - $request_id = $item->ID; - $nonce = wp_create_nonce( 'wp-privacy-erase-personal-data-' . $request_id ); - - echo '
    '; - - ?> - - - - '; - - break; - case 'request-failed': - submit_button( __( 'Retry' ), 'secondary', 'privacy_action_email_retry[' . $item->ID . ']', false ); - break; - case 'request-completed': - echo '' . esc_html__( 'Remove request' ) . ''; - break; - } - } - -} diff --git a/wp-admin/js/privacy-tools.js b/wp-admin/js/privacy-tools.js new file mode 100644 index 0000000000..39cc6b4120 --- /dev/null +++ b/wp-admin/js/privacy-tools.js @@ -0,0 +1,256 @@ +/** + * Interactions used by the User Privacy tools in WordPress. + * + * @output wp-admin/js/privacy-tools.js + */ + +// Privacy request action handling +jQuery( document ).ready( function( $ ) { + var strings = window.privacyToolsL10n || {}; + + function setActionState( $action, state ) { + $action.children().hide(); + $action.children( '.' + state ).show(); + } + + function clearResultsAfterRow( $requestRow ) { + $requestRow.removeClass( 'has-request-results' ); + + if ( $requestRow.next().hasClass( 'request-results' ) ) { + $requestRow.next().remove(); + } + } + + function appendResultsAfterRow( $requestRow, classes, summaryMessage, additionalMessages ) { + var itemList = '', + resultRowClasses = 'request-results'; + + clearResultsAfterRow( $requestRow ); + + if ( additionalMessages.length ) { + $.each( additionalMessages, function( index, value ) { + itemList = itemList + '
  • ' + value + '
  • '; + }); + itemList = '
      ' + itemList + '
    '; + } + + $requestRow.addClass( 'has-request-results' ); + + if ( $requestRow.hasClass( 'status-request-confirmed' ) ) { + resultRowClasses = resultRowClasses + ' status-request-confirmed'; + } + + if ( $requestRow.hasClass( 'status-request-failed' ) ) { + resultRowClasses = resultRowClasses + ' status-request-failed'; + } + + $requestRow.after( function() { + return '' + + '
    ' + + '

    ' + summaryMessage + '

    ' + + itemList + + '
    ' + + '' + + ''; + }); + } + + $( '.export-personal-data-handle' ).click( function( event ) { + var $this = $( this ), + $action = $this.parents( '.export-personal-data' ), + $requestRow = $this.parents( 'tr' ), + requestID = $action.data( 'request-id' ), + nonce = $action.data( 'nonce' ), + exportersCount = $action.data( 'exporters-count' ), + sendAsEmail = $action.data( 'send-as-email' ) ? true : false; + + event.preventDefault(); + event.stopPropagation(); + + $action.blur(); + clearResultsAfterRow( $requestRow ); + + function onExportDoneSuccess( zipUrl ) { + setActionState( $action, 'export-personal-data-success' ); + if ( 'undefined' !== typeof zipUrl ) { + window.location = zipUrl; + } else if ( ! sendAsEmail ) { + onExportFailure( strings.noExportFile ); + } + } + + function onExportFailure( errorMessage ) { + setActionState( $action, 'export-personal-data-failed' ); + if ( errorMessage ) { + appendResultsAfterRow( $requestRow, 'notice-error', strings.exportError, [ errorMessage ] ); + } + } + + function doNextExport( exporterIndex, pageIndex ) { + $.ajax( + { + url: window.ajaxurl, + data: { + action: 'wp-privacy-export-personal-data', + exporter: exporterIndex, + id: requestID, + page: pageIndex, + security: nonce, + sendAsEmail: sendAsEmail + }, + method: 'post' + } + ).done( function( response ) { + var responseData = response.data; + + if ( ! response.success ) { + + // e.g. invalid request ID + onExportFailure( response.data ); + return; + } + + if ( ! responseData.done ) { + setTimeout( doNextExport( exporterIndex, pageIndex + 1 ) ); + } else { + if ( exporterIndex < exportersCount ) { + setTimeout( doNextExport( exporterIndex + 1, 1 ) ); + } else { + onExportDoneSuccess( responseData.url ); + } + } + }).fail( function( jqxhr, textStatus, error ) { + + // e.g. Nonce failure + onExportFailure( error ); + }); + } + + // And now, let's begin + setActionState( $action, 'export-personal-data-processing' ); + doNextExport( 1, 1 ); + }); + + $( '.remove-personal-data-handle' ).click( function( event ) { + var $this = $( this ), + $action = $this.parents( '.remove-personal-data' ), + $requestRow = $this.parents( 'tr' ), + requestID = $action.data( 'request-id' ), + nonce = $action.data( 'nonce' ), + erasersCount = $action.data( 'erasers-count' ), + hasRemoved = false, + hasRetained = false, + messages = []; + + event.stopPropagation(); + + $action.blur(); + clearResultsAfterRow( $requestRow ); + + function onErasureDoneSuccess() { + var summaryMessage = strings.noDataFound; + var classes = 'notice-success'; + + setActionState( $action, 'remove-personal-data-idle' ); + + if ( false === hasRemoved ) { + if ( false === hasRetained ) { + summaryMessage = strings.noDataFound; + } else { + summaryMessage = strings.noneRemoved; + classes = 'notice-warning'; + } + } else { + if ( false === hasRetained ) { + summaryMessage = strings.foundAndRemoved; + } else { + summaryMessage = strings.someNotRemoved; + classes = 'notice-warning'; + } + } + appendResultsAfterRow( $requestRow, 'notice-success', summaryMessage, messages ); + } + + function onErasureFailure() { + setActionState( $action, 'remove-personal-data-failed' ); + appendResultsAfterRow( $requestRow, 'notice-error', strings.removalError, [] ); + } + + function doNextErasure( eraserIndex, pageIndex ) { + $.ajax({ + url: window.ajaxurl, + data: { + action: 'wp-privacy-erase-personal-data', + eraser: eraserIndex, + id: requestID, + page: pageIndex, + security: nonce + }, + method: 'post' + }).done( function( response ) { + var responseData = response.data; + + if ( ! response.success ) { + onErasureFailure(); + return; + } + if ( responseData.items_removed ) { + hasRemoved = hasRemoved || responseData.items_removed; + } + if ( responseData.items_retained ) { + hasRetained = hasRetained || responseData.items_retained; + } + if ( responseData.messages ) { + messages = messages.concat( responseData.messages ); + } + if ( ! responseData.done ) { + setTimeout( doNextErasure( eraserIndex, pageIndex + 1 ) ); + } else { + if ( eraserIndex < erasersCount ) { + setTimeout( doNextErasure( eraserIndex + 1, 1 ) ); + } else { + onErasureDoneSuccess(); + } + } + }).fail( function() { + onErasureFailure(); + }); + } + + // And now, let's begin + setActionState( $action, 'remove-personal-data-processing' ); + + doNextErasure( 1, 1 ); + }); + + // Privacy policy page, copy button. + $( document ).on( 'click', function( event ) { + var $target = $( event.target ); + var $parent, $container, range; + + if ( $target.is( 'button.privacy-text-copy' ) ) { + $parent = $target.parent().parent(); + $container = $parent.find( 'div.wp-suggested-text' ); + + if ( ! $container.length ) { + $container = $parent.find( 'div.policy-text' ); + } + + if ( $container.length ) { + try { + window.getSelection().removeAllRanges(); + range = document.createRange(); + $container.addClass( 'hide-privacy-policy-tutorial' ); + + range.selectNodeContents( $container[0] ); + window.getSelection().addRange( range ); + document.execCommand( 'copy' ); + + $container.removeClass( 'hide-privacy-policy-tutorial' ); + window.getSelection().removeAllRanges(); + } catch ( er ) {} + } + } + }); +}); + diff --git a/wp-admin/js/privacy-tools.min.js b/wp-admin/js/privacy-tools.min.js new file mode 100644 index 0000000000..662b97204a --- /dev/null +++ b/wp-admin/js/privacy-tools.min.js @@ -0,0 +1 @@ +jQuery(document).ready(function(a){function b(a,b){a.children().hide(),a.children("."+b).show()}function c(a){a.removeClass("has-request-results"),a.next().hasClass("request-results")&&a.next().remove()}function d(b,d,e,f){var g="",h="request-results";c(b),f.length&&(a.each(f,function(a,b){g=g+"
  • "+b+"
  • "}),g="
      "+g+"
    "),b.addClass("has-request-results"),b.hasClass("status-request-confirmed")&&(h+=" status-request-confirmed"),b.hasClass("status-request-failed")&&(h+=" status-request-failed"),b.after(function(){return'

    '+e+"

    "+g+"
    "})}var e=window.privacyToolsL10n||{};a(".export-personal-data-handle").click(function(f){function g(a){b(k,"export-personal-data-success"),"undefined"!=typeof a?window.location=a:p||h(e.noExportFile)}function h(a){b(k,"export-personal-data-failed"),a&&d(l,"notice-error",e.exportError,[a])}function i(b,c){a.ajax({url:window.ajaxurl,data:{action:"wp-privacy-export-personal-data",exporter:b,id:m,page:c,security:n,sendAsEmail:p},method:"post"}).done(function(a){var d=a.data;return a.success?void(d.done?b' + value + ''; - }); - itemList = '
      ' + itemList + '
    '; - } - - $requestRow.addClass( 'has-request-results' ); - - if ( $requestRow.hasClass( 'status-request-confirmed' ) ) { - resultRowClasses = resultRowClasses + ' status-request-confirmed'; - } - - if ( $requestRow.hasClass( 'status-request-failed' ) ) { - resultRowClasses = resultRowClasses + ' status-request-failed'; - } - - $requestRow.after( function() { - return '' + - '
    ' + - '

    ' + summaryMessage + '

    ' + - itemList + - '
    ' + - '' + - ''; - }); - } - - $( '.export-personal-data-handle' ).click( function( event ) { - - var $this = $( this ), - $action = $this.parents( '.export-personal-data' ), - $requestRow = $this.parents( 'tr' ), - requestID = $action.data( 'request-id' ), - nonce = $action.data( 'nonce' ), - exportersCount = $action.data( 'exporters-count' ), - sendAsEmail = $action.data( 'send-as-email' ) ? true : false; - - event.preventDefault(); - event.stopPropagation(); - - $action.blur(); - clearResultsAfterRow( $requestRow ); - - function onExportDoneSuccess( zipUrl ) { - setActionState( $action, 'export-personal-data-success' ); - if ( 'undefined' !== typeof zipUrl ) { - window.location = zipUrl; - } else if ( ! sendAsEmail ) { - onExportFailure( strings.noExportFile ); - } - } - - function onExportFailure( errorMessage ) { - setActionState( $action, 'export-personal-data-failed' ); - if ( errorMessage ) { - appendResultsAfterRow( $requestRow, 'notice-error', strings.exportError, [ errorMessage ] ); - } - } - - function doNextExport( exporterIndex, pageIndex ) { - $.ajax( - { - url: window.ajaxurl, - data: { - action: 'wp-privacy-export-personal-data', - exporter: exporterIndex, - id: requestID, - page: pageIndex, - security: nonce, - sendAsEmail: sendAsEmail - }, - method: 'post' - } - ).done( function( response ) { - var responseData = response.data; - - if ( ! response.success ) { - - // e.g. invalid request ID - onExportFailure( response.data ); - return; - } - - if ( ! responseData.done ) { - setTimeout( doNextExport( exporterIndex, pageIndex + 1 ) ); - } else { - if ( exporterIndex < exportersCount ) { - setTimeout( doNextExport( exporterIndex + 1, 1 ) ); - } else { - onExportDoneSuccess( responseData.url ); - } - } - }).fail( function( jqxhr, textStatus, error ) { - - // e.g. Nonce failure - onExportFailure( error ); - }); - } - - // And now, let's begin - setActionState( $action, 'export-personal-data-processing' ); - doNextExport( 1, 1 ); - }); - - $( '.remove-personal-data-handle' ).click( function( event ) { - - var $this = $( this ), - $action = $this.parents( '.remove-personal-data' ), - $requestRow = $this.parents( 'tr' ), - requestID = $action.data( 'request-id' ), - nonce = $action.data( 'nonce' ), - erasersCount = $action.data( 'erasers-count' ), - hasRemoved = false, - hasRetained = false, - messages = []; - - event.stopPropagation(); - - $action.blur(); - clearResultsAfterRow( $requestRow ); - - function onErasureDoneSuccess() { - var summaryMessage = strings.noDataFound; - var classes = 'notice-success'; - - setActionState( $action, 'remove-personal-data-idle' ); - - if ( false === hasRemoved ) { - if ( false === hasRetained ) { - summaryMessage = strings.noDataFound; - } else { - summaryMessage = strings.noneRemoved; - classes = 'notice-warning'; - } - } else { - if ( false === hasRetained ) { - summaryMessage = strings.foundAndRemoved; - } else { - summaryMessage = strings.someNotRemoved; - classes = 'notice-warning'; - } - } - appendResultsAfterRow( $requestRow, 'notice-success', summaryMessage, messages ); - } - - function onErasureFailure() { - setActionState( $action, 'remove-personal-data-failed' ); - appendResultsAfterRow( $requestRow, 'notice-error', strings.removalError, [] ); - } - - function doNextErasure( eraserIndex, pageIndex ) { - $.ajax({ - url: window.ajaxurl, - data: { - action: 'wp-privacy-erase-personal-data', - eraser: eraserIndex, - id: requestID, - page: pageIndex, - security: nonce - }, - method: 'post' - }).done( function( response ) { - var responseData = response.data; - - if ( ! response.success ) { - onErasureFailure(); - return; - } - if ( responseData.items_removed ) { - hasRemoved = hasRemoved || responseData.items_removed; - } - if ( responseData.items_retained ) { - hasRetained = hasRetained || responseData.items_retained; - } - if ( responseData.messages ) { - messages = messages.concat( responseData.messages ); - } - if ( ! responseData.done ) { - setTimeout( doNextErasure( eraserIndex, pageIndex + 1 ) ); - } else { - if ( eraserIndex < erasersCount ) { - setTimeout( doNextErasure( eraserIndex + 1, 1 ) ); - } else { - onErasureDoneSuccess(); - } - } - }).fail( function() { - onErasureFailure(); - }); - } - - // And now, let's begin - setActionState( $action, 'remove-personal-data-processing' ); - - doNextErasure( 1, 1 ); - }); -}); - -( function( $ ) { - - // Privacy policy page, copy button. - $( document ).on( 'click', function( event ) { - var $target = $( event.target ); - var $parent, $container, range; - - if ( $target.is( 'button.privacy-text-copy' ) ) { - $parent = $target.parent().parent(); - $container = $parent.find( 'div.wp-suggested-text' ); - - if ( ! $container.length ) { - $container = $parent.find( 'div.policy-text' ); - } - - if ( $container.length ) { - try { - window.getSelection().removeAllRanges(); - range = document.createRange(); - $container.addClass( 'hide-privacy-policy-tutorial' ); - - range.selectNodeContents( $container[0] ); - window.getSelection().addRange( range ); - document.execCommand( 'copy' ); - - $container.removeClass( 'hide-privacy-policy-tutorial' ); - window.getSelection().removeAllRanges(); - } catch ( er ) {} - } - } - }); - -} ( jQuery ) ); diff --git a/wp-admin/js/xfn.min.js b/wp-admin/js/xfn.min.js index 53250bb70a..1743f9dbdf 100644 --- a/wp-admin/js/xfn.min.js +++ b/wp-admin/js/xfn.min.js @@ -1 +1 @@ -jQuery(document).ready(function(a){a("#link_rel").prop("readonly",!0),a("#linkxfndiv input").bind("click keyup",function(){var b=a("#me").is(":checked"),c="";a("input.valinp").each(function(){b?a(this).prop("disabled",!0).parent().addClass("disabled"):(a(this).removeAttr("disabled").parent().removeClass("disabled"),a(this).is(":checked")&&""!==a(this).val()&&(c+=a(this).val()+" "))}),a("#link_rel").val(b?"me":c.substr(0,c.length-1))})}),jQuery(document).ready(function(a){function b(a,b){a.children().hide(),a.children("."+b).show()}function c(a){a.removeClass("has-request-results"),a.next().hasClass("request-results")&&a.next().remove()}function d(b,d,e,f){var g="",h="request-results";c(b),f.length&&(a.each(f,function(a,b){g=g+"
  • "+b+"
  • "}),g="
      "+g+"
    "),b.addClass("has-request-results"),b.hasClass("status-request-confirmed")&&(h+=" status-request-confirmed"),b.hasClass("status-request-failed")&&(h+=" status-request-failed"),b.after(function(){return'

    '+e+"

    "+g+"
    "})}var e=window.privacyToolsL10n||{};a(".export-personal-data-handle").click(function(f){function g(a){b(k,"export-personal-data-success"),"undefined"!=typeof a?window.location=a:p||h(e.noExportFile)}function h(a){b(k,"export-personal-data-failed"),a&&d(l,"notice-error",e.exportError,[a])}function i(b,c){a.ajax({url:window.ajaxurl,data:{action:"wp-privacy-export-personal-data",exporter:b,id:m,page:c,security:n,sendAsEmail:p},method:"post"}).done(function(a){var d=a.data;return a.success?void(d.done?bCheck out our guide%3$s for recommendations on what content to include, along with policies suggested by your plugins and theme.' ), - esc_url( admin_url( 'tools.php?wp-privacy-policy-guide=1' ) ), + esc_url( admin_url( 'privacy-policy-guide.php' ) ), '', '' ); @@ -193,17 +188,20 @@ require_once( ABSPATH . 'wp-admin/admin-header.php' );
    - +