Make WordPress Core

Changeset 45448


Ignore:
Timestamp:
05/26/2019 08:49:04 PM (6 years ago)
Author:
azaozz
Message:

Privacy tools: Organize privacy functions into logical files and classes.

Props xkon, birgire, desrosj, garrett-eclipse, azaozz.
See #43895.

Location:
trunk
Files:
9 added
13 edited
1 moved

Legend:

Unmodified
Added
Removed
  • trunk/Gruntfile.js

    r45342 r45448  
    265265                    [ WORKING_DIR + 'wp-admin/js/tags.js' ]: [ './src/js/_enqueues/admin/tags.js' ],
    266266                    [ WORKING_DIR + 'wp-admin/js/site-health.js' ]: [ './src/js/_enqueues/admin/site-health.js' ],
     267                    [ WORKING_DIR + 'wp-admin/js/privacy-tools.js' ]: [ './src/js/_enqueues/admin/privacy-tools.js' ],
    267268                    [ WORKING_DIR + 'wp-admin/js/theme-plugin-editor.js' ]: [ './src/js/_enqueues/wp/theme-plugin-editor.js' ],
    268269                    [ WORKING_DIR + 'wp-admin/js/theme.js' ]: [ './src/js/_enqueues/wp/theme.js' ],
  • trunk/src/js/_enqueues/admin/xfn.js

    r43347 r45448  
    2222    });
    2323});
    24 
    25 // Privacy request action handling
    26 jQuery( document ).ready( function( $ ) {
    27     var strings = window.privacyToolsL10n || {};
    28 
    29     function setActionState( $action, state ) {
    30         $action.children().hide();
    31         $action.children( '.' + state ).show();
    32     }
    33 
    34     function clearResultsAfterRow( $requestRow ) {
    35         $requestRow.removeClass( 'has-request-results' );
    36 
    37         if ( $requestRow.next().hasClass( 'request-results' ) ) {
    38             $requestRow.next().remove();
    39         }
    40     }
    41 
    42     function appendResultsAfterRow( $requestRow, classes, summaryMessage, additionalMessages ) {
    43         var itemList = '',
    44             resultRowClasses = 'request-results';
    45 
    46         clearResultsAfterRow( $requestRow );
    47 
    48         if ( additionalMessages.length ) {
    49             $.each( additionalMessages, function( index, value ) {
    50                 itemList = itemList + '<li>' + value + '</li>';
    51             });
    52             itemList = '<ul>' + itemList + '</ul>';
    53         }
    54 
    55         $requestRow.addClass( 'has-request-results' );
    56 
    57         if ( $requestRow.hasClass( 'status-request-confirmed' ) ) {
    58             resultRowClasses = resultRowClasses + ' status-request-confirmed';
    59         }
    60 
    61         if ( $requestRow.hasClass( 'status-request-failed' ) ) {
    62             resultRowClasses = resultRowClasses + ' status-request-failed';
    63         }
    64 
    65         $requestRow.after( function() {
    66             return '<tr class="' + resultRowClasses + '"><th colspan="5">' +
    67                 '<div class="notice inline notice-alt ' + classes + '">' +
    68                 '<p>' + summaryMessage + '</p>' +
    69                 itemList +
    70                 '</div>' +
    71                 '</td>' +
    72                 '</tr>';
    73         });
    74     }
    75 
    76     $( '.export-personal-data-handle' ).click( function( event ) {
    77 
    78         var $this          = $( this ),
    79             $action        = $this.parents( '.export-personal-data' ),
    80             $requestRow    = $this.parents( 'tr' ),
    81             requestID      = $action.data( 'request-id' ),
    82             nonce          = $action.data( 'nonce' ),
    83             exportersCount = $action.data( 'exporters-count' ),
    84             sendAsEmail    = $action.data( 'send-as-email' ) ? true : false;
    85 
    86         event.preventDefault();
    87         event.stopPropagation();
    88 
    89         $action.blur();
    90         clearResultsAfterRow( $requestRow );
    91 
    92         function onExportDoneSuccess( zipUrl ) {
    93             setActionState( $action, 'export-personal-data-success' );
    94             if ( 'undefined' !== typeof zipUrl ) {
    95                 window.location = zipUrl;
    96             } else if ( ! sendAsEmail ) {
    97                 onExportFailure( strings.noExportFile );
    98             }
    99         }
    100 
    101         function onExportFailure( errorMessage ) {
    102             setActionState( $action, 'export-personal-data-failed' );
    103             if ( errorMessage ) {
    104                 appendResultsAfterRow( $requestRow, 'notice-error', strings.exportError, [ errorMessage ] );
    105             }
    106         }
    107 
    108         function doNextExport( exporterIndex, pageIndex ) {
    109             $.ajax(
    110                 {
    111                     url: window.ajaxurl,
    112                     data: {
    113                         action: 'wp-privacy-export-personal-data',
    114                         exporter: exporterIndex,
    115                         id: requestID,
    116                         page: pageIndex,
    117                         security: nonce,
    118                         sendAsEmail: sendAsEmail
    119                     },
    120                     method: 'post'
    121                 }
    122             ).done( function( response ) {
    123                 var responseData = response.data;
    124 
    125                 if ( ! response.success ) {
    126 
    127                     // e.g. invalid request ID
    128                     onExportFailure( response.data );
    129                     return;
    130                 }
    131 
    132                 if ( ! responseData.done ) {
    133                     setTimeout( doNextExport( exporterIndex, pageIndex + 1 ) );
    134                 } else {
    135                     if ( exporterIndex < exportersCount ) {
    136                         setTimeout( doNextExport( exporterIndex + 1, 1 ) );
    137                     } else {
    138                         onExportDoneSuccess( responseData.url );
    139                     }
    140                 }
    141             }).fail( function( jqxhr, textStatus, error ) {
    142 
    143                 // e.g. Nonce failure
    144                 onExportFailure( error );
    145             });
    146         }
    147 
    148         // And now, let's begin
    149         setActionState( $action, 'export-personal-data-processing' );
    150         doNextExport( 1, 1 );
    151     });
    152 
    153     $( '.remove-personal-data-handle' ).click( function( event ) {
    154 
    155         var $this         = $( this ),
    156             $action       = $this.parents( '.remove-personal-data' ),
    157             $requestRow   = $this.parents( 'tr' ),
    158             requestID     = $action.data( 'request-id' ),
    159             nonce         = $action.data( 'nonce' ),
    160             erasersCount  = $action.data( 'erasers-count' ),
    161             hasRemoved    = false,
    162             hasRetained   = false,
    163             messages      = [];
    164 
    165         event.stopPropagation();
    166 
    167         $action.blur();
    168         clearResultsAfterRow( $requestRow );
    169 
    170         function onErasureDoneSuccess() {
    171             var summaryMessage = strings.noDataFound;
    172             var classes = 'notice-success';
    173 
    174             setActionState( $action, 'remove-personal-data-idle' );
    175 
    176             if ( false === hasRemoved ) {
    177                 if ( false === hasRetained ) {
    178                     summaryMessage = strings.noDataFound;
    179                 } else {
    180                     summaryMessage = strings.noneRemoved;
    181                     classes = 'notice-warning';
    182                 }
    183             } else {
    184                 if ( false === hasRetained ) {
    185                     summaryMessage = strings.foundAndRemoved;
    186                 } else {
    187                     summaryMessage = strings.someNotRemoved;
    188                     classes = 'notice-warning';
    189                 }
    190             }
    191             appendResultsAfterRow( $requestRow, 'notice-success', summaryMessage, messages );
    192         }
    193 
    194         function onErasureFailure() {
    195             setActionState( $action, 'remove-personal-data-failed' );
    196             appendResultsAfterRow( $requestRow, 'notice-error', strings.removalError, [] );
    197         }
    198 
    199         function doNextErasure( eraserIndex, pageIndex ) {
    200             $.ajax({
    201                 url: window.ajaxurl,
    202                 data: {
    203                     action: 'wp-privacy-erase-personal-data',
    204                     eraser: eraserIndex,
    205                     id: requestID,
    206                     page: pageIndex,
    207                     security: nonce
    208                 },
    209                 method: 'post'
    210             }).done( function( response ) {
    211                 var responseData = response.data;
    212 
    213                 if ( ! response.success ) {
    214                     onErasureFailure();
    215                     return;
    216                 }
    217                 if ( responseData.items_removed ) {
    218                     hasRemoved = hasRemoved || responseData.items_removed;
    219                 }
    220                 if ( responseData.items_retained ) {
    221                     hasRetained = hasRetained || responseData.items_retained;
    222                 }
    223                 if ( responseData.messages ) {
    224                     messages = messages.concat( responseData.messages );
    225                 }
    226                 if ( ! responseData.done ) {
    227                     setTimeout( doNextErasure( eraserIndex, pageIndex + 1 ) );
    228                 } else {
    229                     if ( eraserIndex < erasersCount ) {
    230                         setTimeout( doNextErasure( eraserIndex + 1, 1 ) );
    231                     } else {
    232                         onErasureDoneSuccess();
    233                     }
    234                 }
    235             }).fail( function() {
    236                 onErasureFailure();
    237             });
    238         }
    239 
    240         // And now, let's begin
    241         setActionState( $action, 'remove-personal-data-processing' );
    242 
    243         doNextErasure( 1, 1 );
    244     });
    245 });
    246 
    247 ( function( $ ) {
    248 
    249     // Privacy policy page, copy button.
    250     $( document ).on( 'click', function( event ) {
    251         var $target = $( event.target );
    252         var $parent, $container, range;
    253 
    254         if ( $target.is( 'button.privacy-text-copy' ) ) {
    255             $parent = $target.parent().parent();
    256             $container = $parent.find( 'div.wp-suggested-text' );
    257 
    258             if ( ! $container.length ) {
    259                 $container = $parent.find( 'div.policy-text' );
    260             }
    261 
    262             if ( $container.length ) {
    263                 try {
    264                     window.getSelection().removeAllRanges();
    265                     range = document.createRange();
    266                     $container.addClass( 'hide-privacy-policy-tutorial' );
    267 
    268                     range.selectNodeContents( $container[0] );
    269                     window.getSelection().addRange( range );
    270                     document.execCommand( 'copy' );
    271 
    272                     $container.removeClass( 'hide-privacy-policy-tutorial' );
    273                     window.getSelection().removeAllRanges();
    274                 } catch ( er ) {}
    275             }
    276         }
    277     });
    278 
    279 } ( jQuery ) );
  • trunk/src/wp-admin/includes/admin-filters.php

    r45117 r45448  
    4545add_action( 'admin_head', 'wp_site_icon' );
    4646add_action( 'admin_head', '_ipad_meta' );
    47 
    48 // Privacy tools
    49 add_action( 'admin_menu', '_wp_privacy_hook_requests_page' );
    50 add_action( 'load-tools_page_export_personal_data', '_wp_privacy_requests_screen_options' );
    51 add_action( 'load-tools_page_remove_personal_data', '_wp_privacy_requests_screen_options' );
    5247
    5348// Prerendering.
  • trunk/src/wp-admin/includes/admin.php

    r42343 r45448  
    4141require_once( ABSPATH . 'wp-admin/includes/misc.php' );
    4242
     43/** WordPress Misc Administration API */
     44require_once( ABSPATH . 'wp-admin/includes/class-wp-privacy-policy-content.php' );
     45
    4346/** WordPress Options Administration API */
    4447require_once( ABSPATH . 'wp-admin/includes/options.php' );
     
    6871require_once( ABSPATH . 'wp-admin/includes/theme.php' );
    6972
     73/** WordPress Privacy Functions */
     74require_once( ABSPATH . 'wp-admin/includes/privacy-tools.php' );
     75
     76/** WordPress Privacy List Table classes. */
     77// Previously in wp-admin/includes/user.php. Need to be loaded for backwards compatibility.
     78require_once( ABSPATH . 'wp-admin/includes/class-wp-privacy-requests-table.php' );
     79require_once( ABSPATH . 'wp-admin/includes/class-wp-privacy-data-export-requests-list-table.php' );
     80require_once( ABSPATH . 'wp-admin/includes/class-wp-privacy-data-removal-requests-list-table.php' );
     81
    7082/** WordPress User Administration API */
    7183require_once( ABSPATH . 'wp-admin/includes/user.php' );
  • trunk/src/wp-admin/includes/deprecated.php

    r44537 r45448  
    15151515    <?php
    15161516}
     1517
     1518/**
     1519 * Previous class for list table for privacy data export requests.
     1520 *
     1521 * @since 4.9.6
     1522 * @deprecated 5.3.0
     1523 */
     1524class WP_Privacy_Data_Export_Requests_Table extends WP_Privacy_Data_Export_Requests_List_Table {
     1525    function __construct( $args ) {
     1526        _deprecated_function( __CLASS__, '5.3.0', 'WP_Privacy_Data_Export_Requests_List_Table' );
     1527
     1528        if ( ! isset( $args['screen'] ) || $args['screen'] === 'export_personal_data' ) {
     1529            $args['screen'] = 'export-personal-data';
     1530        }
     1531
     1532        parent::__construct( $args );   
     1533    }
     1534}
     1535
     1536/**
     1537 * Previous class for list table for privacy data erasure requests.
     1538 *
     1539 * @since 4.9.6
     1540 * @deprecated 5.3.0
     1541 */
     1542class WP_Privacy_Data_Removal_Requests_Table extends WP_Privacy_Data_Removal_Requests_List_Table {
     1543    function __construct( $args ) {
     1544        _deprecated_function( __CLASS__, '5.3.0', 'WP_Privacy_Data_Removal_Requests_List_Table' );
     1545
     1546        if ( ! isset( $args['screen'] ) || $args['screen'] === 'remove_personal_data' ) {
     1547            $args['screen'] = 'erase-personal-data';
     1548        }
     1549
     1550        parent::__construct( $args );
     1551    }
     1552}
     1553
     1554/**
     1555 * Was used to add options for the privacy requests screens before they were separate files.
     1556 *
     1557 * @since 4.9.8
     1558 * @access private
     1559 * @deprecated 5.3.0
     1560 */
     1561function _wp_privacy_requests_screen_options() {
     1562    _deprecated_function( __FUNCTION__, '5.3.0' );
     1563}
  • trunk/src/wp-admin/includes/list-table.php

    r43177 r45448  
    3434        'WP_Theme_Install_List_Table'  => array( 'themes', 'theme-install' ),
    3535        'WP_Plugins_List_Table'        => 'plugins',
     36
    3637        // Network Admin
    37         'WP_MS_Sites_List_Table'       => 'ms-sites',
    38         'WP_MS_Users_List_Table'       => 'ms-users',
    39         'WP_MS_Themes_List_Table'      => 'ms-themes',
     38        'WP_MS_Sites_List_Table'  => 'ms-sites',
     39        'WP_MS_Users_List_Table'  => 'ms-users',
     40        'WP_MS_Themes_List_Table' => 'ms-themes',
     41
     42        // Privacy requests tables
     43        'WP_Privacy_Data_Export_Requests_List_Table'  => 'privacy-data-export-requests',
     44        'WP_Privacy_Data_Removal_Requests_List_Table' => 'privacy-data-removal-requests',
    4045    );
    4146
  • trunk/src/wp-admin/includes/misc.php

    r45204 r45448  
    13201320
    13211321/**
    1322  * WP_Privacy_Policy_Content class.
    1323  * TODO: move this to a new file.
    1324  *
    1325  * @since 4.9.6
    1326  */
    1327 final class WP_Privacy_Policy_Content {
    1328 
    1329     private static $policy_content = array();
    1330 
    1331     /**
    1332      * Constructor
    1333      *
    1334      * @since 4.9.6
    1335      */
    1336     private function __construct() {}
    1337 
    1338     /**
    1339      * Add content to the postbox shown when editing the privacy policy.
    1340      *
    1341      * Plugins and themes should suggest text for inclusion in the site's privacy policy.
    1342      * The suggested text should contain information about any functionality that affects user privacy,
    1343      * and will be shown in the Suggested Privacy Policy Content postbox.
    1344      *
    1345      * Intended for use from `wp_add_privacy_policy_content()`.
    1346      *
    1347      * @since 4.9.6
    1348      *
    1349      * @param string $plugin_name The name of the plugin or theme that is suggesting content for the site's privacy policy.
    1350      * @param string $policy_text The suggested content for inclusion in the policy.
    1351      */
    1352     public static function add( $plugin_name, $policy_text ) {
    1353         if ( empty( $plugin_name ) || empty( $policy_text ) ) {
    1354             return;
    1355         }
    1356 
    1357         $data = array(
    1358             'plugin_name' => $plugin_name,
    1359             'policy_text' => $policy_text,
    1360         );
    1361 
    1362         if ( ! in_array( $data, self::$policy_content, true ) ) {
    1363             self::$policy_content[] = $data;
    1364         }
    1365     }
    1366 
    1367     /**
    1368      * Quick check if any privacy info has changed.
    1369      *
    1370      * @since 4.9.6
    1371      */
    1372     public static function text_change_check() {
    1373 
    1374         $policy_page_id = (int) get_option( 'wp_page_for_privacy_policy' );
    1375 
    1376         // The site doesn't have a privacy policy.
    1377         if ( empty( $policy_page_id ) ) {
    1378             return false;
    1379         }
    1380 
    1381         if ( ! current_user_can( 'edit_post', $policy_page_id ) ) {
    1382             return false;
    1383         }
    1384 
    1385         $old = (array) get_post_meta( $policy_page_id, '_wp_suggested_privacy_policy_content' );
    1386 
    1387         // Updates are not relevant if the user has not reviewed any suggestions yet.
    1388         if ( empty( $old ) ) {
    1389             return false;
    1390         }
    1391 
    1392         $cached = get_option( '_wp_suggested_policy_text_has_changed' );
    1393 
    1394         /*
    1395          * When this function is called before `admin_init`, `self::$policy_content`
    1396          * has not been populated yet, so use the cached result from the last
    1397          * execution instead.
    1398          */
    1399         if ( ! did_action( 'admin_init' ) ) {
    1400             return 'changed' === $cached;
    1401         }
    1402 
    1403         $new = self::$policy_content;
    1404 
    1405         // Remove the extra values added to the meta.
    1406         foreach ( $old as $key => $data ) {
    1407             if ( ! empty( $data['removed'] ) ) {
    1408                 unset( $old[ $key ] );
    1409                 continue;
    1410             }
    1411 
    1412             $old[ $key ] = array(
    1413                 'plugin_name' => $data['plugin_name'],
    1414                 'policy_text' => $data['policy_text'],
    1415             );
    1416         }
    1417 
    1418         // Normalize the order of texts, to facilitate comparison.
    1419         sort( $old );
    1420         sort( $new );
    1421 
    1422         // The == operator (equal, not identical) was used intentionally.
    1423         // See http://php.net/manual/en/language.operators.array.php
    1424         if ( $new != $old ) {
    1425             // A plugin was activated or deactivated, or some policy text has changed.
    1426             // Show a notice on the relevant screens to inform the admin.
    1427             add_action( 'admin_notices', array( 'WP_Privacy_Policy_Content', 'policy_text_changed_notice' ) );
    1428             $state = 'changed';
    1429         } else {
    1430             $state = 'not-changed';
    1431         }
    1432 
    1433         // Cache the result for use before `admin_init` (see above).
    1434         if ( $cached !== $state ) {
    1435             update_option( '_wp_suggested_policy_text_has_changed', $state );
    1436         }
    1437 
    1438         return 'changed' === $state;
    1439     }
    1440 
    1441     /**
    1442      * Output a warning when some privacy info has changed.
    1443      *
    1444      * @since 4.9.6
    1445      */
    1446     public static function policy_text_changed_notice() {
    1447         global $post;
    1448 
    1449         $screen = get_current_screen()->id;
    1450 
    1451         if ( 'privacy' !== $screen ) {
    1452             return;
    1453         }
    1454 
    1455         ?>
    1456         <div class="policy-text-updated notice notice-warning is-dismissible">
    1457             <p>
    1458             <?php
    1459                 printf(
    1460                     /* translators: %s: Privacy Policy Guide URL */
    1461                     __( 'The suggested privacy policy text has changed. Please <a href="%s">review the guide</a> and update your privacy policy.' ),
    1462                     esc_url( admin_url( 'tools.php?wp-privacy-policy-guide=1' ) )
    1463                 );
    1464             ?>
    1465             </p>
    1466         </div>
    1467         <?php
    1468     }
    1469 
    1470     /**
    1471      * Update the cached policy info when the policy page is updated.
    1472      *
    1473      * @since 4.9.6
    1474      * @access private
    1475      */
    1476     public static function _policy_page_updated( $post_id ) {
    1477         $policy_page_id = (int) get_option( 'wp_page_for_privacy_policy' );
    1478 
    1479         if ( ! $policy_page_id || $policy_page_id !== (int) $post_id ) {
    1480             return;
    1481         }
    1482 
    1483         // Remove updated|removed status.
    1484         $old          = (array) get_post_meta( $policy_page_id, '_wp_suggested_privacy_policy_content' );
    1485         $done         = array();
    1486         $update_cache = false;
    1487 
    1488         foreach ( $old as $old_key => $old_data ) {
    1489             if ( ! empty( $old_data['removed'] ) ) {
    1490                 // Remove the old policy text.
    1491                 $update_cache = true;
    1492                 continue;
    1493             }
    1494 
    1495             if ( ! empty( $old_data['updated'] ) ) {
    1496                 // 'updated' is now 'added'.
    1497                 $done[]       = array(
    1498                     'plugin_name' => $old_data['plugin_name'],
    1499                     'policy_text' => $old_data['policy_text'],
    1500                     'added'       => $old_data['updated'],
    1501                 );
    1502                 $update_cache = true;
    1503             } else {
    1504                 $done[] = $old_data;
    1505             }
    1506         }
    1507 
    1508         if ( $update_cache ) {
    1509             delete_post_meta( $policy_page_id, '_wp_suggested_privacy_policy_content' );
    1510             // Update the cache.
    1511             foreach ( $done as $data ) {
    1512                 add_post_meta( $policy_page_id, '_wp_suggested_privacy_policy_content', $data );
    1513             }
    1514         }
    1515     }
    1516 
    1517     /**
    1518      * Check for updated, added or removed privacy policy information from plugins.
    1519      *
    1520      * Caches the current info in post_meta of the policy page.
    1521      *
    1522      * @since 4.9.6
    1523      *
    1524      * @return array The privacy policy text/informtion added by core and plugins.
    1525      */
    1526     public static function get_suggested_policy_text() {
    1527         $policy_page_id = (int) get_option( 'wp_page_for_privacy_policy' );
    1528         $checked        = array();
    1529         $time           = time();
    1530         $update_cache   = false;
    1531         $new            = self::$policy_content;
    1532         $old            = array();
    1533 
    1534         if ( $policy_page_id ) {
    1535             $old = (array) get_post_meta( $policy_page_id, '_wp_suggested_privacy_policy_content' );
    1536         }
    1537 
    1538         // Check for no-changes and updates.
    1539         foreach ( $new as $new_key => $new_data ) {
    1540             foreach ( $old as $old_key => $old_data ) {
    1541                 $found = false;
    1542 
    1543                 if ( $new_data['policy_text'] === $old_data['policy_text'] ) {
    1544                     // Use the new plugin name in case it was changed, translated, etc.
    1545                     if ( $old_data['plugin_name'] !== $new_data['plugin_name'] ) {
    1546                         $old_data['plugin_name'] = $new_data['plugin_name'];
    1547                         $update_cache            = true;
    1548                     }
    1549 
    1550                     // A plugin was re-activated.
    1551                     if ( ! empty( $old_data['removed'] ) ) {
    1552                         unset( $old_data['removed'] );
    1553                         $old_data['added'] = $time;
    1554                         $update_cache      = true;
    1555                     }
    1556 
    1557                     $checked[] = $old_data;
    1558                     $found     = true;
    1559                 } elseif ( $new_data['plugin_name'] === $old_data['plugin_name'] ) {
    1560                     // The info for the policy was updated.
    1561                     $checked[] = array(
    1562                         'plugin_name' => $new_data['plugin_name'],
    1563                         'policy_text' => $new_data['policy_text'],
    1564                         'updated'     => $time,
    1565                     );
    1566                     $found     = $update_cache = true;
    1567                 }
    1568 
    1569                 if ( $found ) {
    1570                     unset( $new[ $new_key ], $old[ $old_key ] );
    1571                     continue 2;
    1572                 }
    1573             }
    1574         }
    1575 
    1576         if ( ! empty( $new ) ) {
    1577             // A plugin was activated.
    1578             foreach ( $new as $new_data ) {
    1579                 if ( ! empty( $new_data['plugin_name'] ) && ! empty( $new_data['policy_text'] ) ) {
    1580                     $new_data['added'] = $time;
    1581                     $checked[]         = $new_data;
    1582                 }
    1583             }
    1584             $update_cache = true;
    1585         }
    1586 
    1587         if ( ! empty( $old ) ) {
    1588             // A plugin was deactivated.
    1589             foreach ( $old as $old_data ) {
    1590                 if ( ! empty( $old_data['plugin_name'] ) && ! empty( $old_data['policy_text'] ) ) {
    1591                     $data = array(
    1592                         'plugin_name' => $old_data['plugin_name'],
    1593                         'policy_text' => $old_data['policy_text'],
    1594                         'removed'     => $time,
    1595                     );
    1596 
    1597                     $checked[] = $data;
    1598                 }
    1599             }
    1600             $update_cache = true;
    1601         }
    1602 
    1603         if ( $update_cache && $policy_page_id ) {
    1604             delete_post_meta( $policy_page_id, '_wp_suggested_privacy_policy_content' );
    1605             // Update the cache.
    1606             foreach ( $checked as $data ) {
    1607                 add_post_meta( $policy_page_id, '_wp_suggested_privacy_policy_content', $data );
    1608             }
    1609         }
    1610 
    1611         return $checked;
    1612     }
    1613 
    1614     /**
    1615      * Add a notice with a link to the guide when editing the privacy policy page.
    1616      *
    1617      * @since 4.9.6
    1618      * @since 5.0.0 The $post parameter is now optional.
    1619      *
    1620      * @param WP_Post|null $post The currently edited post. Default null.
    1621      */
    1622     public static function notice( $post = null ) {
    1623         if ( is_null( $post ) ) {
    1624             global $post;
    1625         } else {
    1626             $post = get_post( $post );
    1627         }
    1628 
    1629         if ( ! ( $post instanceof WP_Post ) ) {
    1630             return;
    1631         }
    1632 
    1633         if ( ! current_user_can( 'manage_privacy_options' ) ) {
    1634             return;
    1635         }
    1636 
    1637         $policy_page_id = (int) get_option( 'wp_page_for_privacy_policy' );
    1638 
    1639         if ( ! $policy_page_id || $policy_page_id !== $post->ID ) {
    1640             return;
    1641         }
    1642 
    1643         $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.' );
    1644         $url     = esc_url( admin_url( 'tools.php?wp-privacy-policy-guide=1' ) );
    1645         $label   = __( 'View Privacy Policy Guide.' );
    1646 
    1647         if ( get_current_screen()->is_block_editor() ) {
    1648             wp_enqueue_script( 'wp-notices' );
    1649             $action = array(
    1650                 'url'   => $url,
    1651                 'label' => $label,
    1652             );
    1653             wp_add_inline_script(
    1654                 'wp-notices',
    1655                 sprintf(
    1656                     'wp.data.dispatch( "core/notices" ).createWarningNotice( "%s", { actions: [ %s ], isDismissible: false } )',
    1657                     $message,
    1658                     wp_json_encode( $action )
    1659                 ),
    1660                 'after'
    1661             );
    1662         } else {
    1663             ?>
    1664             <div class="notice notice-warning inline wp-pp-notice">
    1665                 <p>
    1666                 <?php
    1667                 echo $message;
    1668                 printf(
    1669                     ' <a href="%s" target="_blank">%s <span class="screen-reader-text">%s</span></a>',
    1670                     $url,
    1671                     $label,
    1672                     /* translators: accessibility text */
    1673                     __( '(opens in a new tab)' )
    1674                 );
    1675                 ?>
    1676                 </p>
    1677             </div>
    1678             <?php
    1679         }
    1680     }
    1681 
    1682     /**
    1683      * Output the privacy policy guide together with content from the theme and plugins.
    1684      *
    1685      * @since 4.9.6
    1686      */
    1687     public static function privacy_policy_guide() {
    1688 
    1689         $content_array = self::get_suggested_policy_text();
    1690 
    1691         $content       = '';
    1692         $toc           = array( '<li><a href="#wp-privacy-policy-guide-introduction">' . __( 'Introduction' ) . '</a></li>' );
    1693         $date_format   = __( 'F j, Y' );
    1694         $copy          = __( 'Copy this section to clipboard' );
    1695         $return_to_top = '<a href="#" class="return-to-top">' . __( '&uarr; Return to Top' ) . '</a>';
    1696 
    1697         foreach ( $content_array as $section ) {
    1698             $class = $meta = $removed = '';
    1699 
    1700             if ( ! empty( $section['removed'] ) ) {
    1701                 $class = ' text-removed';
    1702                 $date  = date_i18n( $date_format, $section['removed'] );
    1703                 $meta  = sprintf( __( 'Removed %s.' ), $date );
    1704 
    1705                 $removed = __( 'You deactivated this plugin on %s and may no longer need this policy.' );
    1706                 $removed = '<div class="error inline"><p>' . sprintf( $removed, $date ) . '</p></div>';
    1707             } elseif ( ! empty( $section['updated'] ) ) {
    1708                 $class = ' text-updated';
    1709                 $date  = date_i18n( $date_format, $section['updated'] );
    1710                 $meta  = sprintf( __( 'Updated %s.' ), $date );
    1711             }
    1712 
    1713             if ( $meta ) {
    1714                 $meta = '<br><span class="privacy-text-meta">' . $meta . '</span>';
    1715             }
    1716 
    1717             $plugin_name = esc_html( $section['plugin_name'] );
    1718             $toc_id      = 'wp-privacy-policy-guide-' . sanitize_title( $plugin_name );
    1719             $toc[]       = sprintf( '<li><a href="#%1$s">%2$s</a>' . $meta . '</li>', $toc_id, $plugin_name );
    1720 
    1721             $content .= '<div class="privacy-text-section' . $class . '">';
    1722             $content .= '<a id="' . $toc_id . '">&nbsp;</a>';
    1723             /* translators: %s: plugin name */
    1724             $content .= '<h2>' . sprintf( __( 'Source: %s' ), $plugin_name ) . '</h2>';
    1725             $content .= $removed;
    1726 
    1727             $content .= '<div class="policy-text">' . $section['policy_text'] . '</div>';
    1728             $content .= $return_to_top;
    1729 
    1730             if ( empty( $section['removed'] ) ) {
    1731                 $content         .= '<div class="privacy-text-actions">';
    1732                     $content     .= '<button type="button" class="privacy-text-copy button">';
    1733                         $content .= $copy;
    1734                         $content .= '<span class="screen-reader-text">' . sprintf( __( 'Copy suggested policy text from %s.' ), $plugin_name ) . '</span>';
    1735                     $content     .= '</button>';
    1736                 $content         .= '</div>';
    1737             }
    1738 
    1739             $content .= "</div>\n"; // End of .privacy-text-section.
    1740         }
    1741 
    1742         if ( count( $toc ) > 2 ) {
    1743             ?>
    1744             <div  class="privacy-text-box-toc">
    1745                 <p><?php _e( 'Table of Contents' ); ?></p>
    1746                 <ol>
    1747                     <?php echo implode( "\n", $toc ); ?>
    1748                 </ol>
    1749             </div>
    1750             <?php
    1751         }
    1752 
    1753         ?>
    1754         <div class="privacy-text-box">
    1755             <div class="privacy-text-box-head">
    1756                 <a id="wp-privacy-policy-guide-introduction">&nbsp;</a>
    1757                 <h2><?php _e( 'Introduction' ); ?></h2>
    1758                 <p><?php _e( 'Hello,' ); ?></p>
    1759                 <p><?php _e( 'This text template will help you to create your web site&#8217;s privacy policy.' ); ?></p>
    1760                 <p><?php _e( 'We have suggested the sections you will need. Under each section heading you will find a short summary of what information you should provide, which will help you to get started. Some sections include suggested policy content, others will have to be completed with information from your theme and plugins.' ); ?></p>
    1761                 <p><?php _e( 'Please edit your privacy policy content, making sure to delete the summaries, and adding any information from your theme and plugins. Once you publish your policy page, remember to add it to your navigation menu.' ); ?></p>
    1762                 <p><?php _e( 'It is your responsibility to write a comprehensive privacy policy, to make sure it reflects all national and international legal requirements on privacy, and to keep your policy current and accurate.' ); ?></p>
    1763             </div>
    1764 
    1765             <div class="privacy-text-box-body">
    1766                 <?php echo $content; ?>
    1767             </div>
    1768         </div>
    1769         <?php
    1770     }
    1771 
    1772     /**
    1773      * Return the default suggested privacy policy content.
    1774      *
    1775      * @since 4.9.6
    1776      * @since 5.0.0 Added the `$blocks` parameter.
    1777      *
    1778      * @param bool $description Whether to include the descriptions under the section headings. Default false.
    1779      * @param bool $blocks      Whether to format the content for the block editor. Default true.
    1780      * @return string The default policy content.
    1781      */
    1782     public static function get_default_content( $description = false, $blocks = true ) {
    1783         $suggested_text = $description ? '<strong class="privacy-policy-tutorial">' . __( 'Suggested text:' ) . ' </strong>' : '';
    1784         $content        = '';
    1785         $strings        = array();
    1786 
    1787         // Start of the suggested privacy policy text.
    1788         if ( $description ) {
    1789             $strings[] = '<div class="wp-suggested-text">';
    1790         }
    1791 
    1792         /* translators: default privacy policy heading. */
    1793         $strings[] = '<h2>' . __( 'Who we are' ) . '</h2>';
    1794 
    1795         if ( $description ) {
    1796             /* translators: privacy policy tutorial. */
    1797             $strings[] = '<p class="privacy-policy-tutorial">' . __( '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.' ) . '</p>';
    1798             /* translators: privacy policy tutorial. */
    1799             $strings[] = '<p class="privacy-policy-tutorial">' . __( '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.' ) . '</p>';
    1800         }
    1801 
    1802         /* translators: default privacy policy text, %s Site URL. */
    1803         $strings[] = '<p>' . $suggested_text . sprintf( __( 'Our website address is: %s.' ), get_bloginfo( 'url', 'display' ) ) . '</p>';
    1804 
    1805         /* translators: default privacy policy heading. */
    1806         $strings[] = '<h2>' . __( 'What personal data we collect and why we collect it' ) . '</h2>';
    1807 
    1808         if ( $description ) {
    1809             /* translators: privacy policy tutorial. */
    1810             $strings[] = '<p class="privacy-policy-tutorial">' . __( '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.' ) . '</p>';
    1811             /* translators: privacy policy tutorial. */
    1812             $strings[] = '<p class="privacy-policy-tutorial">' . __( 'You should also note any collection and retention of sensitive personal data, such as data concerning health.' ) . '</p>';
    1813             /* translators: privacy policy tutorial. */
    1814             $strings[] = '<p class="privacy-policy-tutorial">' . __( '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.' ) . '</p>';
    1815             /* translators: privacy policy tutorial. */
    1816             $strings[] = '<p class="privacy-policy-tutorial">' . __( 'Personal data is not just created by a user&#8217;s interactions with your site. Personal data is also generated from technical processes such as contact forms, comments, cookies, analytics, and third party embeds.' ) . '</p>';
    1817             /* translators: privacy policy tutorial. */
    1818             $strings[] = '<p class="privacy-policy-tutorial">' . __( '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.' ) . '</p>';
    1819         }
    1820 
    1821         /* translators: default privacy policy heading. */
    1822         $strings[] = '<h3>' . __( 'Comments' ) . '</h3>';
    1823 
    1824         if ( $description ) {
    1825             /* translators: privacy policy tutorial. */
    1826             $strings[] = '<p class="privacy-policy-tutorial">' . __( 'In this subsection you should note what information is captured through comments. We have noted the data which WordPress collects by default.' ) . '</p>';
    1827         }
    1828 
    1829         /* translators: default privacy policy text. */
    1830         $strings[] = '<p>' . $suggested_text . __( 'When visitors leave comments on the site we collect the data shown in the comments form, and also the visitor&#8217;s IP address and browser user agent string to help spam detection.' ) . '</p>';
    1831         /* translators: default privacy policy text. */
    1832         $strings[] = '<p>' . __( '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.' ) . '</p>';
    1833 
    1834         /* translators: default privacy policy heading. */
    1835         $strings[] = '<h3>' . __( 'Media' ) . '</h3>';
    1836 
    1837         if ( $description ) {
    1838             /* translators: privacy policy tutorial. */
    1839             $strings[] = '<p class="privacy-policy-tutorial">' . __( '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.' ) . '</p>';
    1840         }
    1841 
    1842         /* translators: default privacy policy text. */
    1843         $strings[] = '<p>' . $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.' ) . '</p>';
    1844 
    1845         /* translators: default privacy policy heading. */
    1846         $strings[] = '<h3>' . __( 'Contact forms' ) . '</h3>';
    1847 
    1848         if ( $description ) {
    1849             /* translators: privacy policy tutorial. */
    1850             $strings[] = '<p class="privacy-policy-tutorial">' . __( '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.' ) . '</p>';
    1851         }
    1852 
    1853         /* translators: default privacy policy heading. */
    1854         $strings[] = '<h3>' . __( 'Cookies' ) . '</h3>';
    1855 
    1856         if ( $description ) {
    1857             /* translators: privacy policy tutorial. */
    1858             $strings[] = '<p class="privacy-policy-tutorial">' . __( '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.' ) . '</p>';
    1859         }
    1860 
    1861         /* translators: default privacy policy text. */
    1862         $strings[] = '<p>' . $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.' ) . '</p>';
    1863         /* translators: default privacy policy text. */
    1864         $strings[] = '<p>' . __( '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.' ) . '</p>';
    1865         /* translators: default privacy policy text. */
    1866         $strings[] = '<p>' . __( '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 &quot;Remember Me&quot;, your login will persist for two weeks. If you log out of your account, the login cookies will be removed.' ) . '</p>';
    1867         /* translators: default privacy policy text. */
    1868         $strings[] = '<p>' . __( '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.' ) . '</p>';
    1869 
    1870         /* translators: default privacy policy heading. */
    1871         $strings[] = '<h3>' . __( 'Embedded content from other websites' ) . '</h3>';
    1872         /* translators: default privacy policy text. */
    1873         $strings[] = '<p>' . $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.' ) . '</p>';
    1874         /* translators: default privacy policy text. */
    1875         $strings[] = '<p>' . __( '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.' ) . '</p>';
    1876 
    1877         /* translators: default privacy policy heading. */
    1878         $strings[] = '<h3>' . __( 'Analytics' ) . '</h3>';
    1879 
    1880         if ( $description ) {
    1881             /* translators: privacy policy tutorial. */
    1882             $strings[] = '<p class="privacy-policy-tutorial">' . __( '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&#8217;s privacy policy, if any.' ) . '</p>';
    1883             /* translators: privacy policy tutorial. */
    1884             $strings[] = '<p class="privacy-policy-tutorial">' . __( '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.' ) . '</p>';
    1885         }
    1886 
    1887         /* translators: default privacy policy heading. */
    1888         $strings[] = '<h2>' . __( 'Who we share your data with' ) . '</h2>';
    1889 
    1890         if ( $description ) {
    1891             /* translators: privacy policy tutorial. */
    1892             $strings[] = '<p class="privacy-policy-tutorial">' . __( '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.' ) . '</p>';
    1893             /* translators: privacy policy tutorial. */
    1894             $strings[] = '<p class="privacy-policy-tutorial">' . __( 'By default WordPress does not share any personal data with anyone.' ) . '</p>';
    1895         }
    1896 
    1897         /* translators: default privacy policy heading. */
    1898         $strings[] = '<h2>' . __( 'How long we retain your data' ) . '</h2>';
    1899 
    1900         if ( $description ) {
    1901             /* translators: privacy policy tutorial. */
    1902             $strings[] = '<p class="privacy-policy-tutorial">' . __( '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.' ) . '</p>';
    1903         }
    1904 
    1905         /* translators: default privacy policy text. */
    1906         $strings[] = '<p>' . $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.' ) . '</p>';
    1907         /* translators: default privacy policy text. */
    1908         $strings[] = '<p>' . __( '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.' ) . '</p>';
    1909 
    1910         /* translators: default privacy policy heading. */
    1911         $strings[] = '<h2>' . __( 'What rights you have over your data' ) . '</h2>';
    1912 
    1913         if ( $description ) {
    1914             /* translators: privacy policy tutorial. */
    1915             $strings[] = '<p class="privacy-policy-tutorial">' . __( 'In this section you should explain what rights your users have over their data and how they can invoke those rights.' ) . '</p>';
    1916         }
    1917 
    1918         /* translators: default privacy policy text. */
    1919         $strings[] = '<p>' . $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.' ) . '</p>';
    1920 
    1921         /* translators: default privacy policy heading. */
    1922         $strings[] = '<h2>' . __( 'Where we send your data' ) . '</h2>';
    1923 
    1924         if ( $description ) {
    1925             /* translators: privacy policy tutorial. */
    1926             $strings[] = '<p class="privacy-policy-tutorial">' . __( '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.' ) . '</p>';
    1927             /* translators: privacy policy tutorial. */
    1928             $strings[] = '<p class="privacy-policy-tutorial">' . __( '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.' ) . '</p>';
    1929         }
    1930 
    1931         /* translators: default privacy policy text. */
    1932         $strings[] = '<p>' . $suggested_text . __( 'Visitor comments may be checked through an automated spam detection service.' ) . '</p>';
    1933 
    1934         /* translators: default privacy policy heading. */
    1935         $strings[] = '<h2>' . __( 'Your contact information' ) . '</h2>';
    1936 
    1937         if ( $description ) {
    1938             /* translators: privacy policy tutorial. */
    1939             $strings[] = '<p class="privacy-policy-tutorial">' . __( '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.' ) . '</p>';
    1940         }
    1941 
    1942         /* translators: default privacy policy heading. */
    1943         $strings[] = '<h2>' . __( 'Additional information' ) . '</h2>';
    1944 
    1945         if ( $description ) {
    1946             /* translators: privacy policy tutorial. */
    1947             $strings[] = '<p class="privacy-policy-tutorial">' . __( '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.' ) . '</p>';
    1948         }
    1949 
    1950         /* translators: default privacy policy heading. */
    1951         $strings[] = '<h3>' . __( 'How we protect your data' ) . '</h3>';
    1952 
    1953         if ( $description ) {
    1954             /* translators: privacy policy tutorial. */
    1955             $strings[] = '<p class="privacy-policy-tutorial">' . __( 'In this section you should explain what measures you have taken to protect your users&#8217; 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.' ) . '</p>';
    1956         }
    1957 
    1958         /* translators: default privacy policy heading. */
    1959         $strings[] = '<h3>' . __( 'What data breach procedures we have in place' ) . '</h3>';
    1960 
    1961         if ( $description ) {
    1962             /* translators: privacy policy tutorial. */
    1963             $strings[] = '<p class="privacy-policy-tutorial">' . __( '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.' ) . '</p>';
    1964         }
    1965 
    1966         /* translators: default privacy policy heading. */
    1967         $strings[] = '<h3>' . __( 'What third parties we receive data from' ) . '</h3>';
    1968 
    1969         if ( $description ) {
    1970             /* translators: privacy policy tutorial. */
    1971             $strings[] = '<p class="privacy-policy-tutorial">' . __( '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.' ) . '</p>';
    1972         }
    1973 
    1974         /* translators: default privacy policy heading. */
    1975         $strings[] = '<h3>' . __( 'What automated decision making and/or profiling we do with user data' ) . '</h3>';
    1976 
    1977         if ( $description ) {
    1978             /* translators: privacy policy tutorial. */
    1979             $strings[] = '<p class="privacy-policy-tutorial">' . __( '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.' ) . '</p>';
    1980         }
    1981 
    1982         /* translators: default privacy policy heading. */
    1983         $strings[] = '<h3>' . __( 'Industry regulatory disclosure requirements' ) . '</h3>';
    1984 
    1985         if ( $description ) {
    1986             /* translators: privacy policy tutorial. */
    1987             $strings[] = '<p class="privacy-policy-tutorial">' . __( '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.' ) . '</p>';
    1988             $strings[] = '</div>';
    1989         }
    1990 
    1991         if ( $blocks ) {
    1992             foreach ( $strings as $key => $string ) {
    1993                 if ( 0 === strpos( $string, '<p>' ) ) {
    1994                     $strings[ $key ] = '<!-- wp:paragraph -->' . $string . '<!-- /wp:paragraph -->';
    1995                 }
    1996 
    1997                 if ( 0 === strpos( $string, '<h2>' ) ) {
    1998                     $strings[ $key ] = '<!-- wp:heading -->' . $string . '<!-- /wp:heading -->';
    1999                 }
    2000 
    2001                 if ( 0 === strpos( $string, '<h3>' ) ) {
    2002                     $strings[ $key ] = '<!-- wp:heading {"level":3} -->' . $string . '<!-- /wp:heading -->';
    2003                 }
    2004             }
    2005         }
    2006 
    2007         $content = implode( '', $strings );
    2008         // End of the suggested privacy policy text.
    2009 
    2010         /**
    2011          * Filters the default content suggested for inclusion in a privacy policy.
    2012          *
    2013          * @since 4.9.6
    2014          * @since 5.0.0 Added the `$strings`, `$description`, and `$blocks` parameters.
    2015          *
    2016          * @param string $content     The default policy content.
    2017          * @param array  $strings     An array of privacy policy content strings.
    2018          * @param bool   $description Whether policy descriptions should be included.
    2019          * @param bool   $blocks      Whether the content should be formatted for the block editor.
    2020          */
    2021         return apply_filters( 'wp_get_default_privacy_policy_content', $content, $strings, $description, $blocks );
    2022     }
    2023 
    2024     /**
    2025      * Add the suggested privacy policy text to the policy postbox.
    2026      *
    2027      * @since 4.9.6
    2028      */
    2029     public static function add_suggested_content() {
    2030         $content = self::get_default_content( true, false );
    2031         wp_add_privacy_policy_content( __( 'WordPress' ), $content );
    2032     }
    2033 }
    2034 
    2035 /**
    20361322 * Checks if the user needs to update PHP.
    20371323 *
  • trunk/src/wp-admin/includes/plugin.php

    r45185 r45448  
    21882188
    21892189    if ( ! class_exists( 'WP_Privacy_Policy_Content' ) ) {
    2190         require_once( ABSPATH . 'wp-admin/includes/misc.php' );
     2190        require_once( ABSPATH . 'wp-admin/includes/class-wp-privacy-policy-content.php' );
    21912191    }
    21922192
  • trunk/src/wp-admin/includes/upgrade.php

    r45424 r45448  
    343343        } else {
    344344            if ( ! class_exists( 'WP_Privacy_Policy_Content' ) ) {
    345                 include_once( ABSPATH . 'wp-admin/includes/misc.php' );
     345                include_once( ABSPATH . 'wp-admin/includes/class-wp-privacy-policy-content.php' );
    346346            }
    347347
  • trunk/src/wp-admin/includes/user.php

    r45194 r45448  
    583583    );
    584584}
    585 
    586 /**
    587  * Resend an existing request and return the result.
    588  *
    589  * @since 4.9.6
    590  * @access private
    591  *
    592  * @param int $request_id Request ID.
    593  * @return bool|WP_Error Returns true/false based on the success of sending the email, or a WP_Error object.
    594  */
    595 function _wp_privacy_resend_request( $request_id ) {
    596     $request_id = absint( $request_id );
    597     $request    = get_post( $request_id );
    598 
    599     if ( ! $request || 'user_request' !== $request->post_type ) {
    600         return new WP_Error( 'privacy_request_error', __( 'Invalid request.' ) );
    601     }
    602 
    603     $result = wp_send_user_request( $request_id );
    604 
    605     if ( is_wp_error( $result ) ) {
    606         return $result;
    607     } elseif ( ! $result ) {
    608         return new WP_Error( 'privacy_request_error', __( 'Unable to initiate confirmation request.' ) );
    609     }
    610 
    611     return true;
    612 }
    613 
    614 /**
    615  * Marks a request as completed by the admin and logs the current timestamp.
    616  *
    617  * @since 4.9.6
    618  * @access private
    619  *
    620  * @param  int          $request_id Request ID.
    621  * @return int|WP_Error $result Request ID on success or WP_Error.
    622  */
    623 function _wp_privacy_completed_request( $request_id ) {
    624     $request_id = absint( $request_id );
    625     $request    = wp_get_user_request_data( $request_id );
    626 
    627     if ( ! $request ) {
    628         return new WP_Error( 'privacy_request_error', __( 'Invalid request.' ) );
    629     }
    630 
    631     update_post_meta( $request_id, '_wp_user_request_completed_timestamp', time() );
    632 
    633     $result = wp_update_post(
    634         array(
    635             'ID'          => $request_id,
    636             'post_status' => 'request-completed',
    637         )
    638     );
    639 
    640     return $result;
    641 }
    642 
    643 /**
    644  * Handle list table actions.
    645  *
    646  * @since 4.9.6
    647  * @access private
    648  */
    649 function _wp_personal_data_handle_actions() {
    650     if ( isset( $_POST['privacy_action_email_retry'] ) ) {
    651         check_admin_referer( 'bulk-privacy_requests' );
    652 
    653         $request_id = absint( current( array_keys( (array) wp_unslash( $_POST['privacy_action_email_retry'] ) ) ) );
    654         $result     = _wp_privacy_resend_request( $request_id );
    655 
    656         if ( is_wp_error( $result ) ) {
    657             add_settings_error(
    658                 'privacy_action_email_retry',
    659                 'privacy_action_email_retry',
    660                 $result->get_error_message(),
    661                 'error'
    662             );
    663         } else {
    664             add_settings_error(
    665                 'privacy_action_email_retry',
    666                 'privacy_action_email_retry',
    667                 __( 'Confirmation request sent again successfully.' ),
    668                 'updated'
    669             );
    670         }
    671     } elseif ( isset( $_POST['action'] ) ) {
    672         $action = isset( $_POST['action'] ) ? sanitize_key( wp_unslash( $_POST['action'] ) ) : '';
    673 
    674         switch ( $action ) {
    675             case 'add_export_personal_data_request':
    676             case 'add_remove_personal_data_request':
    677                 check_admin_referer( 'personal-data-request' );
    678 
    679                 if ( ! isset( $_POST['type_of_action'], $_POST['username_or_email_for_privacy_request'] ) ) {
    680                     add_settings_error(
    681                         'action_type',
    682                         'action_type',
    683                         __( 'Invalid action.' ),
    684                         'error'
    685                     );
    686                 }
    687                 $action_type               = sanitize_text_field( wp_unslash( $_POST['type_of_action'] ) );
    688                 $username_or_email_address = sanitize_text_field( wp_unslash( $_POST['username_or_email_for_privacy_request'] ) );
    689                 $email_address             = '';
    690 
    691                 if ( ! in_array( $action_type, _wp_privacy_action_request_types(), true ) ) {
    692                     add_settings_error(
    693                         'action_type',
    694                         'action_type',
    695                         __( 'Invalid action.' ),
    696                         'error'
    697                     );
    698                 }
    699 
    700                 if ( ! is_email( $username_or_email_address ) ) {
    701                     $user = get_user_by( 'login', $username_or_email_address );
    702                     if ( ! $user instanceof WP_User ) {
    703                         add_settings_error(
    704                             'username_or_email_for_privacy_request',
    705                             'username_or_email_for_privacy_request',
    706                             __( 'Unable to add this request. A valid email address or username must be supplied.' ),
    707                             'error'
    708                         );
    709                     } else {
    710                         $email_address = $user->user_email;
    711                     }
    712                 } else {
    713                     $email_address = $username_or_email_address;
    714                 }
    715 
    716                 if ( empty( $email_address ) ) {
    717                     break;
    718                 }
    719 
    720                 $request_id = wp_create_user_request( $email_address, $action_type );
    721 
    722                 if ( is_wp_error( $request_id ) ) {
    723                     add_settings_error(
    724                         'username_or_email_for_privacy_request',
    725                         'username_or_email_for_privacy_request',
    726                         $request_id->get_error_message(),
    727                         'error'
    728                     );
    729                     break;
    730                 } elseif ( ! $request_id ) {
    731                     add_settings_error(
    732                         'username_or_email_for_privacy_request',
    733                         'username_or_email_for_privacy_request',
    734                         __( 'Unable to initiate confirmation request.' ),
    735                         'error'
    736                     );
    737                     break;
    738                 }
    739 
    740                 wp_send_user_request( $request_id );
    741 
    742                 add_settings_error(
    743                     'username_or_email_for_privacy_request',
    744                     'username_or_email_for_privacy_request',
    745                     __( 'Confirmation request initiated successfully.' ),
    746                     'updated'
    747                 );
    748                 break;
    749         }
    750     }
    751 }
    752 
    753 /**
    754  * Cleans up failed and expired requests before displaying the list table.
    755  *
    756  * @since 4.9.6
    757  * @access private
    758  */
    759 function _wp_personal_data_cleanup_requests() {
    760     /** This filter is documented in wp-includes/user.php */
    761     $expires = (int) apply_filters( 'user_request_key_expiration', DAY_IN_SECONDS );
    762 
    763     $requests_query = new WP_Query(
    764         array(
    765             'post_type'      => 'user_request',
    766             'posts_per_page' => -1,
    767             'post_status'    => 'request-pending',
    768             'fields'         => 'ids',
    769             'date_query'     => array(
    770                 array(
    771                     'column' => 'post_modified_gmt',
    772                     'before' => $expires . ' seconds ago',
    773                 ),
    774             ),
    775         )
    776     );
    777 
    778     $request_ids = $requests_query->posts;
    779 
    780     foreach ( $request_ids as $request_id ) {
    781         wp_update_post(
    782             array(
    783                 'ID'            => $request_id,
    784                 'post_status'   => 'request-failed',
    785                 'post_password' => '',
    786             )
    787         );
    788     }
    789 }
    790 
    791 /**
    792  * Personal data export.
    793  *
    794  * @since 4.9.6
    795  * @access private
    796  */
    797 function _wp_personal_data_export_page() {
    798     if ( ! current_user_can( 'export_others_personal_data' ) ) {
    799         wp_die( __( 'Sorry, you are not allowed to export personal data on this site.' ) );
    800     }
    801 
    802     _wp_personal_data_handle_actions();
    803     _wp_personal_data_cleanup_requests();
    804 
    805     // "Borrow" xfn.js for now so we don't have to create new files.
    806     wp_enqueue_script( 'xfn' );
    807 
    808     $requests_table = new WP_Privacy_Data_Export_Requests_Table(
    809         array(
    810             'plural'   => 'privacy_requests',
    811             'singular' => 'privacy_request',
    812             'screen'   => 'export_personal_data',
    813         )
    814     );
    815 
    816     $requests_table->screen->set_screen_reader_content(
    817         array(
    818             'heading_views'      => __( 'Filter export personal data list' ),
    819             'heading_pagination' => __( 'Export personal data list navigation' ),
    820             'heading_list'       => __( 'Export personal data list' ),
    821         )
    822     );
    823 
    824     $requests_table->process_bulk_action();
    825     $requests_table->prepare_items();
    826     ?>
    827     <div class="wrap nosubsub">
    828         <h1><?php esc_html_e( 'Export Personal Data' ); ?></h1>
    829         <hr class="wp-header-end" />
    830 
    831         <?php settings_errors(); ?>
    832 
    833         <form action="<?php echo esc_url( admin_url( 'tools.php?page=export_personal_data' ) ); ?>" method="post" class="wp-privacy-request-form">
    834             <h2><?php esc_html_e( 'Add Data Export Request' ); ?></h2>
    835             <p><?php esc_html_e( 'An email will be sent to the user at this email address asking them to verify the request.' ); ?></p>
    836 
    837             <div class="wp-privacy-request-form-field">
    838                 <label for="username_or_email_for_privacy_request"><?php esc_html_e( 'Username or email address' ); ?></label>
    839                 <input type="text" required class="regular-text" id="username_or_email_for_privacy_request" name="username_or_email_for_privacy_request" />
    840                 <?php submit_button( __( 'Send Request' ), 'secondary', 'submit', false ); ?>
    841             </div>
    842             <?php wp_nonce_field( 'personal-data-request' ); ?>
    843             <input type="hidden" name="action" value="add_export_personal_data_request" />
    844             <input type="hidden" name="type_of_action" value="export_personal_data" />
    845         </form>
    846         <hr />
    847 
    848         <?php $requests_table->views(); ?>
    849 
    850         <form class="search-form wp-clearfix">
    851             <?php $requests_table->search_box( __( 'Search Requests' ), 'requests' ); ?>
    852             <input type="hidden" name="page" value="export_personal_data" />
    853             <input type="hidden" name="filter-status" value="<?php echo isset( $_REQUEST['filter-status'] ) ? esc_attr( sanitize_text_field( $_REQUEST['filter-status'] ) ) : ''; ?>" />
    854             <input type="hidden" name="orderby" value="<?php echo isset( $_REQUEST['orderby'] ) ? esc_attr( sanitize_text_field( $_REQUEST['orderby'] ) ) : ''; ?>" />
    855             <input type="hidden" name="order" value="<?php echo isset( $_REQUEST['order'] ) ? esc_attr( sanitize_text_field( $_REQUEST['order'] ) ) : ''; ?>" />
    856         </form>
    857 
    858         <form method="post">
    859             <?php
    860             $requests_table->display();
    861             $requests_table->embed_scripts();
    862             ?>
    863         </form>
    864     </div>
    865     <?php
    866 }
    867 
    868 /**
    869  * Personal data anonymization.
    870  *
    871  * @since 4.9.6
    872  * @access private
    873  */
    874 function _wp_personal_data_removal_page() {
    875     /*
    876      * Require both caps in order to make it explicitly clear that delegating
    877      * erasure from network admins to single-site admins will give them the
    878      * ability to affect global users, rather than being limited to the site
    879      * that they administer.
    880      */
    881     if ( ! current_user_can( 'erase_others_personal_data' ) || ! current_user_can( 'delete_users' ) ) {
    882         wp_die( __( 'Sorry, you are not allowed to erase data on this site.' ) );
    883     }
    884 
    885     _wp_personal_data_handle_actions();
    886     _wp_personal_data_cleanup_requests();
    887 
    888     // "Borrow" xfn.js for now so we don't have to create new files.
    889     wp_enqueue_script( 'xfn' );
    890 
    891     $requests_table = new WP_Privacy_Data_Removal_Requests_Table(
    892         array(
    893             'plural'   => 'privacy_requests',
    894             'singular' => 'privacy_request',
    895             'screen'   => 'remove_personal_data',
    896         )
    897     );
    898 
    899     $requests_table->screen->set_screen_reader_content(
    900         array(
    901             'heading_views'      => __( 'Filter erase personal data list' ),
    902             'heading_pagination' => __( 'Erase personal data list navigation' ),
    903             'heading_list'       => __( 'Erase personal data list' ),
    904         )
    905     );
    906 
    907     $requests_table->process_bulk_action();
    908     $requests_table->prepare_items();
    909 
    910     ?>
    911     <div class="wrap nosubsub">
    912         <h1><?php esc_html_e( 'Erase Personal Data' ); ?></h1>
    913         <hr class="wp-header-end" />
    914 
    915         <?php settings_errors(); ?>
    916 
    917         <form action="<?php echo esc_url( admin_url( 'tools.php?page=remove_personal_data' ) ); ?>" method="post" class="wp-privacy-request-form">
    918             <h2><?php esc_html_e( 'Add Data Erasure Request' ); ?></h2>
    919             <p><?php esc_html_e( 'An email will be sent to the user at this email address asking them to verify the request.' ); ?></p>
    920 
    921             <div class="wp-privacy-request-form-field">
    922                 <label for="username_or_email_for_privacy_request"><?php esc_html_e( 'Username or email address' ); ?></label>
    923                 <input type="text" required class="regular-text" id="username_or_email_for_privacy_request" name="username_or_email_for_privacy_request" />
    924                 <?php submit_button( __( 'Send Request' ), 'secondary', 'submit', false ); ?>
    925             </div>
    926             <?php wp_nonce_field( 'personal-data-request' ); ?>
    927             <input type="hidden" name="action" value="add_remove_personal_data_request" />
    928             <input type="hidden" name="type_of_action" value="remove_personal_data" />
    929         </form>
    930         <hr />
    931 
    932         <?php $requests_table->views(); ?>
    933 
    934         <form class="search-form wp-clearfix">
    935             <?php $requests_table->search_box( __( 'Search Requests' ), 'requests' ); ?>
    936             <input type="hidden" name="page" value="remove_personal_data" />
    937             <input type="hidden" name="filter-status" value="<?php echo isset( $_REQUEST['filter-status'] ) ? esc_attr( sanitize_text_field( $_REQUEST['filter-status'] ) ) : ''; ?>" />
    938             <input type="hidden" name="orderby" value="<?php echo isset( $_REQUEST['orderby'] ) ? esc_attr( sanitize_text_field( $_REQUEST['orderby'] ) ) : ''; ?>" />
    939             <input type="hidden" name="order" value="<?php echo isset( $_REQUEST['order'] ) ? esc_attr( sanitize_text_field( $_REQUEST['order'] ) ) : ''; ?>" />
    940         </form>
    941 
    942         <form method="post">
    943             <?php
    944             $requests_table->display();
    945             $requests_table->embed_scripts();
    946             ?>
    947         </form>
    948     </div>
    949     <?php
    950 }
    951 
    952 /**
    953  * Mark erasure requests as completed after processing is finished.
    954  *
    955  * This intercepts the Ajax responses to personal data eraser page requests, and
    956  * monitors the status of a request. Once all of the processing has finished, the
    957  * request is marked as completed.
    958  *
    959  * @since 4.9.6
    960  *
    961  * @see wp_privacy_personal_data_erasure_page
    962  *
    963  * @param array  $response      The response from the personal data eraser for
    964  *                              the given page.
    965  * @param int    $eraser_index  The index of the personal data eraser. Begins
    966  *                              at 1.
    967  * @param string $email_address The email address of the user whose personal
    968  *                              data this is.
    969  * @param int    $page          The page of personal data for this eraser.
    970  *                              Begins at 1.
    971  * @param int    $request_id    The request ID for this personal data erasure.
    972  * @return array The filtered response.
    973  */
    974 function wp_privacy_process_personal_data_erasure_page( $response, $eraser_index, $email_address, $page, $request_id ) {
    975     /*
    976      * If the eraser response is malformed, don't attempt to consume it; let it
    977      * pass through, so that the default Ajax processing will generate a warning
    978      * to the user.
    979      */
    980     if ( ! is_array( $response ) ) {
    981         return $response;
    982     }
    983 
    984     if ( ! array_key_exists( 'done', $response ) ) {
    985         return $response;
    986     }
    987 
    988     if ( ! array_key_exists( 'items_removed', $response ) ) {
    989         return $response;
    990     }
    991 
    992     if ( ! array_key_exists( 'items_retained', $response ) ) {
    993         return $response;
    994     }
    995 
    996     if ( ! array_key_exists( 'messages', $response ) ) {
    997         return $response;
    998     }
    999 
    1000     $request = wp_get_user_request_data( $request_id );
    1001 
    1002     if ( ! $request || 'remove_personal_data' !== $request->action_name ) {
    1003         wp_send_json_error( __( 'Invalid request ID when processing eraser data.' ) );
    1004     }
    1005 
    1006     /** This filter is documented in wp-admin/includes/ajax-actions.php */
    1007     $erasers        = apply_filters( 'wp_privacy_personal_data_erasers', array() );
    1008     $is_last_eraser = count( $erasers ) === $eraser_index;
    1009     $eraser_done    = $response['done'];
    1010 
    1011     if ( ! $is_last_eraser || ! $eraser_done ) {
    1012         return $response;
    1013     }
    1014 
    1015     _wp_privacy_completed_request( $request_id );
    1016 
    1017     /**
    1018      * Fires immediately after a personal data erasure request has been marked completed.
    1019      *
    1020      * @since 4.9.6
    1021      *
    1022      * @param int $request_id The privacy request post ID associated with this request.
    1023      */
    1024     do_action( 'wp_privacy_personal_data_erased', $request_id );
    1025 
    1026     return $response;
    1027 }
    1028 
    1029 /**
    1030  * Add requests pages.
    1031  *
    1032  * @since 4.9.6
    1033  * @access private
    1034  */
    1035 function _wp_privacy_hook_requests_page() {
    1036     add_submenu_page( 'tools.php', __( 'Export Personal Data' ), __( 'Export Personal Data' ), 'export_others_personal_data', 'export_personal_data', '_wp_personal_data_export_page' );
    1037     add_submenu_page( 'tools.php', __( 'Erase Personal Data' ), __( 'Erase Personal Data' ), 'erase_others_personal_data', 'remove_personal_data', '_wp_personal_data_removal_page' );
    1038 }
    1039 
    1040 /**
    1041  * Add options for the privacy requests screens.
    1042  *
    1043  * @since 4.9.8
    1044  * @access private
    1045  */
    1046 function _wp_privacy_requests_screen_options() {
    1047     $args = array(
    1048         'option' => str_replace( 'tools_page_', '', get_current_screen()->id ) . '_requests_per_page',
    1049     );
    1050     add_screen_option( 'per_page', $args );
    1051 }
    1052 
    1053 // TODO: move the following classes in new files.
    1054 if ( ! class_exists( 'WP_List_Table' ) ) {
    1055     require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
    1056 }
    1057 
    1058 /**
    1059  * WP_Privacy_Requests_Table class.
    1060  *
    1061  * @since 4.9.6
    1062  */
    1063 abstract class WP_Privacy_Requests_Table extends WP_List_Table {
    1064 
    1065     /**
    1066      * Action name for the requests this table will work with. Classes
    1067      * which inherit from WP_Privacy_Requests_Table should define this.
    1068      *
    1069      * Example: 'export_personal_data'.
    1070      *
    1071      * @since 4.9.6
    1072      *
    1073      * @var string $request_type Name of action.
    1074      */
    1075     protected $request_type = 'INVALID';
    1076 
    1077     /**
    1078      * Post type to be used.
    1079      *
    1080      * @since 4.9.6
    1081      *
    1082      * @var string $post_type The post type.
    1083      */
    1084     protected $post_type = 'INVALID';
    1085 
    1086     /**
    1087      * Get columns to show in the list table.
    1088      *
    1089      * @since 4.9.6
    1090      *
    1091      * @return array Array of columns.
    1092      */
    1093     public function get_columns() {
    1094         $columns = array(
    1095             'cb'                => '<input type="checkbox" />',
    1096             'email'             => __( 'Requester' ),
    1097             'status'            => __( 'Status' ),
    1098             'created_timestamp' => __( 'Requested' ),
    1099             'next_steps'        => __( 'Next Steps' ),
    1100         );
    1101         return $columns;
    1102     }
    1103 
    1104     /**
    1105      * Get a list of sortable columns.
    1106      *
    1107      * @since 4.9.6
    1108      *
    1109      * @return array Default sortable columns.
    1110      */
    1111     protected function get_sortable_columns() {
    1112         // The initial sorting is by 'Requested' (post_date) and descending.
    1113         // With initial sorting, the first click on 'Requested' should be ascending.
    1114         // With 'Requester' sorting active, the next click on 'Requested' should be descending.
    1115         $desc_first = isset( $_GET['orderby'] );
    1116 
    1117         return array(
    1118             'email'             => 'requester',
    1119             'created_timestamp' => array( 'requested', $desc_first ),
    1120         );
    1121     }
    1122 
    1123     /**
    1124      * Default primary column.
    1125      *
    1126      * @since 4.9.6
    1127      *
    1128      * @return string Default primary column name.
    1129      */
    1130     protected function get_default_primary_column_name() {
    1131         return 'email';
    1132     }
    1133 
    1134     /**
    1135      * Count number of requests for each status.
    1136      *
    1137      * @since 4.9.6
    1138      *
    1139      * @return object Number of posts for each status.
    1140      */
    1141     protected function get_request_counts() {
    1142         global $wpdb;
    1143 
    1144         $cache_key = $this->post_type . '-' . $this->request_type;
    1145         $counts    = wp_cache_get( $cache_key, 'counts' );
    1146 
    1147         if ( false !== $counts ) {
    1148             return $counts;
    1149         }
    1150 
    1151         $query = "
    1152             SELECT post_status, COUNT( * ) AS num_posts
    1153             FROM {$wpdb->posts}
    1154             WHERE post_type = %s
    1155             AND post_name = %s
    1156             GROUP BY post_status";
    1157 
    1158         $results = (array) $wpdb->get_results( $wpdb->prepare( $query, $this->post_type, $this->request_type ), ARRAY_A );
    1159         $counts  = array_fill_keys( get_post_stati(), 0 );
    1160 
    1161         foreach ( $results as $row ) {
    1162             $counts[ $row['post_status'] ] = $row['num_posts'];
    1163         }
    1164 
    1165         $counts = (object) $counts;
    1166         wp_cache_set( $cache_key, $counts, 'counts' );
    1167 
    1168         return $counts;
    1169     }
    1170 
    1171     /**
    1172      * Get an associative array ( id => link ) with the list of views available on this table.
    1173      *
    1174      * @since 4.9.6
    1175      *
    1176      * @return array Associative array of views in the format of $view_name => $view_markup.
    1177      */
    1178     protected function get_views() {
    1179         $current_status = isset( $_REQUEST['filter-status'] ) ? sanitize_text_field( $_REQUEST['filter-status'] ) : '';
    1180         $statuses       = _wp_privacy_statuses();
    1181         $views          = array();
    1182         $admin_url      = admin_url( 'tools.php?page=' . $this->request_type );
    1183         $counts         = $this->get_request_counts();
    1184         $total_requests = absint( array_sum( (array) $counts ) );
    1185 
    1186         $current_link_attributes = empty( $current_status ) ? ' class="current" aria-current="page"' : '';
    1187         $status_label            = sprintf(
    1188             /* translators: %s: all requests count */
    1189             _nx(
    1190                 'All <span class="count">(%s)</span>',
    1191                 'All <span class="count">(%s)</span>',
    1192                 $total_requests,
    1193                 'requests'
    1194             ),
    1195             number_format_i18n( $total_requests )
    1196         );
    1197 
    1198         $views['all'] = sprintf(
    1199             '<a href="%s"%s>%s</a>',
    1200             esc_url( $admin_url ),
    1201             $current_link_attributes,
    1202             $status_label
    1203         );
    1204 
    1205         foreach ( $statuses as $status => $label ) {
    1206             $post_status = get_post_status_object( $status );
    1207             if ( ! $post_status ) {
    1208                 continue;
    1209             }
    1210 
    1211             $current_link_attributes = $status === $current_status ? ' class="current" aria-current="page"' : '';
    1212             $total_status_requests   = absint( $counts->{$status} );
    1213             $status_label            = sprintf(
    1214                 translate_nooped_plural( $post_status->label_count, $total_status_requests ),
    1215                 number_format_i18n( $total_status_requests )
    1216             );
    1217             $status_link             = add_query_arg( 'filter-status', $status, $admin_url );
    1218 
    1219             $views[ $status ] = sprintf(
    1220                 '<a href="%s"%s>%s</a>',
    1221                 esc_url( $status_link ),
    1222                 $current_link_attributes,
    1223                 $status_label
    1224             );
    1225         }
    1226 
    1227         return $views;
    1228     }
    1229 
    1230     /**
    1231      * Get bulk actions.
    1232      *
    1233      * @since 4.9.6
    1234      *
    1235      * @return array List of bulk actions.
    1236      */
    1237     protected function get_bulk_actions() {
    1238         return array(
    1239             'delete' => __( 'Remove' ),
    1240             'resend' => __( 'Resend email' ),
    1241         );
    1242     }
    1243 
    1244     /**
    1245      * Process bulk actions.
    1246      *
    1247      * @since 4.9.6
    1248      */
    1249     public function process_bulk_action() {
    1250         $action      = $this->current_action();
    1251         $request_ids = isset( $_REQUEST['request_id'] ) ? wp_parse_id_list( wp_unslash( $_REQUEST['request_id'] ) ) : array();
    1252 
    1253         $count = 0;
    1254 
    1255         if ( $request_ids ) {
    1256             check_admin_referer( 'bulk-privacy_requests' );
    1257         }
    1258 
    1259         switch ( $action ) {
    1260             case 'delete':
    1261                 foreach ( $request_ids as $request_id ) {
    1262                     if ( wp_delete_post( $request_id, true ) ) {
    1263                         $count ++;
    1264                     }
    1265                 }
    1266 
    1267                 add_settings_error(
    1268                     'bulk_action',
    1269                     'bulk_action',
    1270                     /* translators: %d: number of requests */
    1271                     sprintf( _n( 'Deleted %d request', 'Deleted %d requests', $count ), $count ),
    1272                     'updated'
    1273                 );
    1274                 break;
    1275             case 'resend':
    1276                 foreach ( $request_ids as $request_id ) {
    1277                     $resend = _wp_privacy_resend_request( $request_id );
    1278 
    1279                     if ( $resend && ! is_wp_error( $resend ) ) {
    1280                         $count++;
    1281                     }
    1282                 }
    1283 
    1284                 add_settings_error(
    1285                     'bulk_action',
    1286                     'bulk_action',
    1287                     /* translators: %d: number of requests */
    1288                     sprintf( _n( 'Re-sent %d request', 'Re-sent %d requests', $count ), $count ),
    1289                     'updated'
    1290                 );
    1291                 break;
    1292         }
    1293     }
    1294 
    1295     /**
    1296      * Prepare items to output.
    1297      *
    1298      * @since 4.9.6
    1299      * @since 5.1.0 Added support for column sorting.
    1300      */
    1301     public function prepare_items() {
    1302         global $wpdb;
    1303 
    1304         $this->items    = array();
    1305         $posts_per_page = $this->get_items_per_page( $this->request_type . '_requests_per_page' );
    1306         $args           = array(
    1307             'post_type'      => $this->post_type,
    1308             'post_name__in'  => array( $this->request_type ),
    1309             'posts_per_page' => $posts_per_page,
    1310             'offset'         => isset( $_REQUEST['paged'] ) ? max( 0, absint( $_REQUEST['paged'] ) - 1 ) * $posts_per_page : 0,
    1311             'post_status'    => 'any',
    1312             's'              => isset( $_REQUEST['s'] ) ? sanitize_text_field( $_REQUEST['s'] ) : '',
    1313         );
    1314 
    1315         $orderby_mapping = array(
    1316             'requester' => 'post_title',
    1317             'requested' => 'post_date',
    1318         );
    1319 
    1320         if ( isset( $_REQUEST['orderby'] ) && isset( $orderby_mapping[ $_REQUEST['orderby'] ] ) ) {
    1321             $args['orderby'] = $orderby_mapping[ $_REQUEST['orderby'] ];
    1322         }
    1323 
    1324         if ( isset( $_REQUEST['order'] ) && in_array( strtoupper( $_REQUEST['order'] ), array( 'ASC', 'DESC' ), true ) ) {
    1325             $args['order'] = strtoupper( $_REQUEST['order'] );
    1326         }
    1327 
    1328         if ( ! empty( $_REQUEST['filter-status'] ) ) {
    1329             $filter_status       = isset( $_REQUEST['filter-status'] ) ? sanitize_text_field( $_REQUEST['filter-status'] ) : '';
    1330             $args['post_status'] = $filter_status;
    1331         }
    1332 
    1333         $requests_query = new WP_Query( $args );
    1334         $requests       = $requests_query->posts;
    1335 
    1336         foreach ( $requests as $request ) {
    1337             $this->items[] = wp_get_user_request_data( $request->ID );
    1338         }
    1339 
    1340         $this->items = array_filter( $this->items );
    1341 
    1342         $this->set_pagination_args(
    1343             array(
    1344                 'total_items' => $requests_query->found_posts,
    1345                 'per_page'    => $posts_per_page,
    1346             )
    1347         );
    1348     }
    1349 
    1350     /**
    1351      * Checkbox column.
    1352      *
    1353      * @since 4.9.6
    1354      *
    1355      * @param WP_User_Request $item Item being shown.
    1356      * @return string Checkbox column markup.
    1357      */
    1358     public function column_cb( $item ) {
    1359         return sprintf( '<input type="checkbox" name="request_id[]" value="%1$s" /><span class="spinner"></span>', esc_attr( $item->ID ) );
    1360     }
    1361 
    1362     /**
    1363      * Status column.
    1364      *
    1365      * @since 4.9.6
    1366      *
    1367      * @param WP_User_Request $item Item being shown.
    1368      * @return string Status column markup.
    1369      */
    1370     public function column_status( $item ) {
    1371         $status        = get_post_status( $item->ID );
    1372         $status_object = get_post_status_object( $status );
    1373 
    1374         if ( ! $status_object || empty( $status_object->label ) ) {
    1375             return '-';
    1376         }
    1377 
    1378         $timestamp = false;
    1379 
    1380         switch ( $status ) {
    1381             case 'request-confirmed':
    1382                 $timestamp = $item->confirmed_timestamp;
    1383                 break;
    1384             case 'request-completed':
    1385                 $timestamp = $item->completed_timestamp;
    1386                 break;
    1387         }
    1388 
    1389         echo '<span class="status-label status-' . esc_attr( $status ) . '">';
    1390         echo esc_html( $status_object->label );
    1391 
    1392         if ( $timestamp ) {
    1393             echo ' (' . $this->get_timestamp_as_date( $timestamp ) . ')';
    1394         }
    1395 
    1396         echo '</span>';
    1397     }
    1398 
    1399     /**
    1400      * Convert timestamp for display.
    1401      *
    1402      * @since 4.9.6
    1403      *
    1404      * @param int $timestamp Event timestamp.
    1405      * @return string Human readable date.
    1406      */
    1407     protected function get_timestamp_as_date( $timestamp ) {
    1408         if ( empty( $timestamp ) ) {
    1409             return '';
    1410         }
    1411 
    1412         $time_diff = time() - $timestamp;
    1413 
    1414         if ( $time_diff >= 0 && $time_diff < DAY_IN_SECONDS ) {
    1415             /* translators: human readable timestamp */
    1416             return sprintf( __( '%s ago' ), human_time_diff( $timestamp ) );
    1417         }
    1418 
    1419         return date_i18n( get_option( 'date_format' ), $timestamp );
    1420     }
    1421 
    1422     /**
    1423      * Default column handler.
    1424      *
    1425      * @since 4.9.6
    1426      *
    1427      * @param WP_User_Request $item        Item being shown.
    1428      * @param string          $column_name Name of column being shown.
    1429      * @return string Default column output.
    1430      */
    1431     public function column_default( $item, $column_name ) {
    1432         $cell_value = $item->$column_name;
    1433 
    1434         if ( in_array( $column_name, array( 'created_timestamp' ), true ) ) {
    1435             return $this->get_timestamp_as_date( $cell_value );
    1436         }
    1437 
    1438         return $cell_value;
    1439     }
    1440 
    1441     /**
    1442      * Actions column. Overridden by children.
    1443      *
    1444      * @since 4.9.6
    1445      *
    1446      * @param WP_User_Request $item Item being shown.
    1447      * @return string Email column markup.
    1448      */
    1449     public function column_email( $item ) {
    1450         return sprintf( '<a href="%1$s">%2$s</a> %3$s', esc_url( 'mailto:' . $item->email ), $item->email, $this->row_actions( array() ) );
    1451     }
    1452 
    1453     /**
    1454      * Next steps column. Overridden by children.
    1455      *
    1456      * @since 4.9.6
    1457      *
    1458      * @param WP_User_Request $item Item being shown.
    1459      */
    1460     public function column_next_steps( $item ) {}
    1461 
    1462     /**
    1463      * Generates content for a single row of the table,
    1464      *
    1465      * @since 4.9.6
    1466      *
    1467      * @param WP_User_Request $item The current item.
    1468      */
    1469     public function single_row( $item ) {
    1470         $status = $item->status;
    1471 
    1472         echo '<tr id="request-' . esc_attr( $item->ID ) . '" class="status-' . esc_attr( $status ) . '">';
    1473         $this->single_row_columns( $item );
    1474         echo '</tr>';
    1475     }
    1476 
    1477     /**
    1478      * Embed scripts used to perform actions. Overridden by children.
    1479      *
    1480      * @since 4.9.6
    1481      */
    1482     public function embed_scripts() {}
    1483 }
    1484 
    1485 /**
    1486  * WP_Privacy_Data_Export_Requests_Table class.
    1487  *
    1488  * @since 4.9.6
    1489  */
    1490 class WP_Privacy_Data_Export_Requests_Table extends WP_Privacy_Requests_Table {
    1491     /**
    1492      * Action name for the requests this table will work with.
    1493      *
    1494      * @since 4.9.6
    1495      *
    1496      * @var string $request_type Name of action.
    1497      */
    1498     protected $request_type = 'export_personal_data';
    1499 
    1500     /**
    1501      * Post type for the requests.
    1502      *
    1503      * @since 4.9.6
    1504      *
    1505      * @var string $post_type The post type.
    1506      */
    1507     protected $post_type = 'user_request';
    1508 
    1509     /**
    1510      * Actions column.
    1511      *
    1512      * @since 4.9.6
    1513      *
    1514      * @param WP_User_Request $item Item being shown.
    1515      * @return string Email column markup.
    1516      */
    1517     public function column_email( $item ) {
    1518         /** This filter is documented in wp-admin/includes/ajax-actions.php */
    1519         $exporters       = apply_filters( 'wp_privacy_personal_data_exporters', array() );
    1520         $exporters_count = count( $exporters );
    1521         $request_id      = $item->ID;
    1522         $nonce           = wp_create_nonce( 'wp-privacy-export-personal-data-' . $request_id );
    1523 
    1524         $download_data_markup = '<div class="export-personal-data" ' .
    1525             'data-exporters-count="' . esc_attr( $exporters_count ) . '" ' .
    1526             'data-request-id="' . esc_attr( $request_id ) . '" ' .
    1527             'data-nonce="' . esc_attr( $nonce ) .
    1528             '">';
    1529 
    1530         $download_data_markup .= '<span class="export-personal-data-idle"><button type="button" class="button-link export-personal-data-handle">' . __( 'Download Personal Data' ) . '</button></span>' .
    1531             '<span style="display:none" class="export-personal-data-processing" >' . __( 'Downloading Data...' ) . '</span>' .
    1532             '<span style="display:none" class="export-personal-data-success"><button type="button" class="button-link export-personal-data-handle">' . __( 'Download Personal Data Again' ) . '</button></span>' .
    1533             '<span style="display:none" class="export-personal-data-failed">' . __( 'Download failed.' ) . ' <button type="button" class="button-link">' . __( 'Retry' ) . '</button></span>';
    1534 
    1535         $download_data_markup .= '</div>';
    1536 
    1537         $row_actions = array(
    1538             'download-data' => $download_data_markup,
    1539         );
    1540 
    1541         return sprintf( '<a href="%1$s">%2$s</a> %3$s', esc_url( 'mailto:' . $item->email ), $item->email, $this->row_actions( $row_actions ) );
    1542     }
    1543 
    1544     /**
    1545      * Displays the next steps column.
    1546      *
    1547      * @since 4.9.6
    1548      *
    1549      * @param WP_User_Request $item Item being shown.
    1550      */
    1551     public function column_next_steps( $item ) {
    1552         $status = $item->status;
    1553 
    1554         switch ( $status ) {
    1555             case 'request-pending':
    1556                 esc_html_e( 'Waiting for confirmation' );
    1557                 break;
    1558             case 'request-confirmed':
    1559                 /** This filter is documented in wp-admin/includes/ajax-actions.php */
    1560                 $exporters       = apply_filters( 'wp_privacy_personal_data_exporters', array() );
    1561                 $exporters_count = count( $exporters );
    1562                 $request_id      = $item->ID;
    1563                 $nonce           = wp_create_nonce( 'wp-privacy-export-personal-data-' . $request_id );
    1564 
    1565                 echo '<div class="export-personal-data" ' .
    1566                     'data-send-as-email="1" ' .
    1567                     'data-exporters-count="' . esc_attr( $exporters_count ) . '" ' .
    1568                     'data-request-id="' . esc_attr( $request_id ) . '" ' .
    1569                     'data-nonce="' . esc_attr( $nonce ) .
    1570                     '">';
    1571 
    1572                 ?>
    1573                 <span class="export-personal-data-idle"><button type="button" class="button export-personal-data-handle"><?php _e( 'Send Export Link' ); ?></button></span>
    1574                 <span style="display:none" class="export-personal-data-processing button updating-message" ><?php _e( 'Sending Email...' ); ?></span>
    1575                 <span style="display:none" class="export-personal-data-success success-message" ><?php _e( 'Email sent.' ); ?></span>
    1576                 <span style="display:none" class="export-personal-data-failed"><?php _e( 'Email could not be sent.' ); ?> <button type="button" class="button export-personal-data-handle"><?php _e( 'Retry' ); ?></button></span>
    1577                 <?php
    1578 
    1579                 echo '</div>';
    1580                 break;
    1581             case 'request-failed':
    1582                 submit_button( __( 'Retry' ), 'secondary', 'privacy_action_email_retry[' . $item->ID . ']', false );
    1583                 break;
    1584             case 'request-completed':
    1585                 echo '<a href="' . esc_url(
    1586                     wp_nonce_url(
    1587                         add_query_arg(
    1588                             array(
    1589                                 'action'     => 'delete',
    1590                                 'request_id' => array( $item->ID ),
    1591                             ),
    1592                             admin_url( 'tools.php?page=export_personal_data' )
    1593                         ),
    1594                         'bulk-privacy_requests'
    1595                     )
    1596                 ) . '" class="button">' . esc_html__( 'Remove request' ) . '</a>';
    1597                 break;
    1598         }
    1599     }
    1600 }
    1601 
    1602 /**
    1603  * WP_Privacy_Data_Removal_Requests_Table class.
    1604  *
    1605  * @since 4.9.6
    1606  */
    1607 class WP_Privacy_Data_Removal_Requests_Table extends WP_Privacy_Requests_Table {
    1608     /**
    1609      * Action name for the requests this table will work with.
    1610      *
    1611      * @since 4.9.6
    1612      *
    1613      * @var string $request_type Name of action.
    1614      */
    1615     protected $request_type = 'remove_personal_data';
    1616 
    1617     /**
    1618      * Post type for the requests.
    1619      *
    1620      * @since 4.9.6
    1621      *
    1622      * @var string $post_type The post type.
    1623      */
    1624     protected $post_type = 'user_request';
    1625 
    1626     /**
    1627      * Actions column.
    1628      *
    1629      * @since 4.9.6
    1630      *
    1631      * @param WP_User_Request $item Item being shown.
    1632      * @return string Email column markup.
    1633      */
    1634     public function column_email( $item ) {
    1635         $row_actions = array();
    1636 
    1637         // Allow the administrator to "force remove" the personal data even if confirmation has not yet been received.
    1638         $status = $item->status;
    1639         if ( 'request-confirmed' !== $status ) {
    1640             /** This filter is documented in wp-admin/includes/ajax-actions.php */
    1641             $erasers       = apply_filters( 'wp_privacy_personal_data_erasers', array() );
    1642             $erasers_count = count( $erasers );
    1643             $request_id    = $item->ID;
    1644             $nonce         = wp_create_nonce( 'wp-privacy-erase-personal-data-' . $request_id );
    1645 
    1646             $remove_data_markup = '<div class="remove-personal-data force-remove-personal-data" ' .
    1647                 'data-erasers-count="' . esc_attr( $erasers_count ) . '" ' .
    1648                 'data-request-id="' . esc_attr( $request_id ) . '" ' .
    1649                 'data-nonce="' . esc_attr( $nonce ) .
    1650                 '">';
    1651 
    1652             $remove_data_markup .= '<span class="remove-personal-data-idle"><button type="button" class="button-link remove-personal-data-handle">' . __( 'Force Erase Personal Data' ) . '</button></span>' .
    1653                 '<span style="display:none" class="remove-personal-data-processing" >' . __( 'Erasing Data...' ) . '</span>' .
    1654                 '<span style="display:none" class="remove-personal-data-failed">' . __( 'Force Erase has failed.' ) . ' <button type="button" class="button-link remove-personal-data-handle">' . __( 'Retry' ) . '</button></span>';
    1655 
    1656             $remove_data_markup .= '</div>';
    1657 
    1658             $row_actions = array(
    1659                 'remove-data' => $remove_data_markup,
    1660             );
    1661         }
    1662 
    1663         return sprintf( '<a href="%1$s">%2$s</a> %3$s', esc_url( 'mailto:' . $item->email ), $item->email, $this->row_actions( $row_actions ) );
    1664     }
    1665 
    1666     /**
    1667      * Next steps column.
    1668      *
    1669      * @since 4.9.6
    1670      *
    1671      * @param WP_User_Request $item Item being shown.
    1672      */
    1673     public function column_next_steps( $item ) {
    1674         $status = $item->status;
    1675 
    1676         switch ( $status ) {
    1677             case 'request-pending':
    1678                 esc_html_e( 'Waiting for confirmation' );
    1679                 break;
    1680             case 'request-confirmed':
    1681                 /** This filter is documented in wp-admin/includes/ajax-actions.php */
    1682                 $erasers       = apply_filters( 'wp_privacy_personal_data_erasers', array() );
    1683                 $erasers_count = count( $erasers );
    1684                 $request_id    = $item->ID;
    1685                 $nonce         = wp_create_nonce( 'wp-privacy-erase-personal-data-' . $request_id );
    1686 
    1687                 echo '<div class="remove-personal-data" ' .
    1688                     'data-force-erase="1" ' .
    1689                     'data-erasers-count="' . esc_attr( $erasers_count ) . '" ' .
    1690                     'data-request-id="' . esc_attr( $request_id ) . '" ' .
    1691                     'data-nonce="' . esc_attr( $nonce ) .
    1692                     '">';
    1693 
    1694                 ?>
    1695                 <span class="remove-personal-data-idle"><button type="button" class="button remove-personal-data-handle"><?php _e( 'Erase Personal Data' ); ?></button></span>
    1696                 <span style="display:none" class="remove-personal-data-processing button updating-message" ><?php _e( 'Erasing Data...' ); ?></span>
    1697                 <span style="display:none" class="remove-personal-data-failed"><?php _e( 'Erasing Data has failed.' ); ?> <button type="button" class="button remove-personal-data-handle"><?php _e( 'Retry' ); ?></button></span>
    1698                 <?php
    1699 
    1700                 echo '</div>';
    1701 
    1702                 break;
    1703             case 'request-failed':
    1704                 submit_button( __( 'Retry' ), 'secondary', 'privacy_action_email_retry[' . $item->ID . ']', false );
    1705                 break;
    1706             case 'request-completed':
    1707                 echo '<a href="' . esc_url(
    1708                     wp_nonce_url(
    1709                         add_query_arg(
    1710                             array(
    1711                                 'action'     => 'delete',
    1712                                 'request_id' => array( $item->ID ),
    1713                             ),
    1714                             admin_url( 'tools.php?page=remove_personal_data' )
    1715                         ),
    1716                         'bulk-privacy_requests'
    1717                     )
    1718                 ) . '" class="button">' . esc_html__( 'Remove request' ) . '</a>';
    1719                 break;
    1720         }
    1721     }
    1722 
    1723 }
  • trunk/src/wp-admin/menu.php

    r45142 r45448  
    265265    $submenu['tools.php'][15] = array( __( 'Export' ), 'export', 'export.php' );
    266266    $submenu['tools.php'][20] = array( __( 'Site Health' ), 'install_plugins', 'site-health.php' );
     267    $submenu['tools.php'][25] = array( __( 'Export Personal Data' ), 'export_others_personal_data', 'export-personal-data.php' );
     268    $submenu['tools.php'][30] = array( __( 'Erase Personal Data' ), 'erase_others_personal_data', 'erase-personal-data.php' );
    267269if ( is_multisite() && ! is_main_site() ) {
    268     $submenu['tools.php'][25] = array( __( 'Delete Site' ), 'delete_site', 'ms-delete-site.php' );
     270    $submenu['tools.php'][35] = array( __( 'Delete Site' ), 'delete_site', 'ms-delete-site.php' );
    269271}
    270272if ( ! is_multisite() && defined( 'WP_ALLOW_MULTISITE' ) && WP_ALLOW_MULTISITE ) {
     
    279281    $submenu['options-general.php'][30] = array( __( 'Media' ), 'manage_options', 'options-media.php' );
    280282    $submenu['options-general.php'][40] = array( __( 'Permalinks' ), 'manage_options', 'options-permalink.php' );
    281     $submenu['options-general.php'][45] = array( __( 'Privacy' ), 'manage_privacy_options', 'privacy.php' );
     283    $submenu['options-general.php'][45] = array( __( 'Privacy' ), 'manage_privacy_options', 'options-privacy.php' );
    282284
    283285$_wp_last_utility_menu = 80; // The index of the last top-level menu in the utility menu group
  • trunk/src/wp-admin/options-privacy.php

    r45407 r45448  
    4646        }
    4747
    48         add_settings_error(
    49             'page_for_privacy_policy',
    50             'page_for_privacy_policy',
    51             $privacy_page_updated_message,
    52             'updated'
    53         );
     48        add_settings_error( 'page_for_privacy_policy', 'page_for_privacy_policy', $privacy_page_updated_message, 'updated' );
    5449    } elseif ( 'create-privacy-page' === $action ) {
    5550
    5651        if ( ! class_exists( 'WP_Privacy_Policy_Content' ) ) {
    57             require_once( ABSPATH . 'wp-admin/includes/misc.php' );
     52            require_once( ABSPATH . 'wp-admin/includes/class-wp-privacy-policy-content.php' );
    5853        }
    5954
     
    183178            /* translators: 1: Privacy Policy guide URL, 2: additional link attributes, 3: accessibility text */
    184179            __( 'Need help putting together your new Privacy Policy page? <a href="%1$s" %2$s>Check out our guide%3$s</a> for recommendations on what content to include, along with policies suggested by your plugins and theme.' ),
    185             esc_url( admin_url( 'tools.php?wp-privacy-policy-guide=1' ) ),
     180            esc_url( admin_url( 'privacy-policy-guide.php' ) ),
    186181            '',
    187182            ''
     
    192187
    193188    <hr>
    194     <table class="form-table tools-privacy-policy-page">
     189    <table class="form-table tools-privacy-policy-page" role="presentation">
    195190        <tr>
    196191            <th scope="row">
    197                 <?php
    198                 if ( $privacy_policy_page_exists ) {
    199                     _e( 'Change your Privacy Policy page' );
    200                 } else {
    201                     _e( 'Select a Privacy Policy page' );
    202                 }
    203                 ?>
     192                <label for="page_for_privacy_policy">
     193                    <?php
     194                    if ( $privacy_policy_page_exists ) {
     195                        _e( 'Change your Privacy Policy page' );
     196                    } else {
     197                        _e( 'Select a Privacy Policy page' );
     198                    }
     199                    ?>
     200                </label>
    204201            </th>
    205202            <td>
    206203                <?php
     204               
    207205                $has_pages = (bool) get_posts(
    208206                    array(
     
    219217                    ?>
    220218                    <form method="post" action="">
    221                         <label for="page_for_privacy_policy">
    222                             <?php _e( 'Select an existing page:' ); ?>
    223                         </label>
    224219                        <input type="hidden" name="action" value="set-privacy-page" />
    225220                        <?php
     221                       
    226222                        wp_dropdown_pages(
    227223                            array(
  • trunk/src/wp-admin/tools.php

    r45140 r45448  
    77 */
    88
     9if ( isset( $_GET['page'] ) && ! empty( $_POST ) ) {
     10    // Ensure POST-ing to `tools.php?page=export_personal_data` and `tools.php?page=remove_personal_data`
     11    // continues to work after creating the new files for exporting and erasing of personal data.
     12    if ( $_GET['page'] === 'export_personal_data' ) {
     13        require_once( ABSPATH . 'wp-admin/export-personal-data.php' );
     14        return;
     15    } elseif ( $_GET['page'] === 'remove_personal_data' ) {
     16        require_once( ABSPATH . 'wp-admin/erase-personal-data.php' );
     17        return;
     18    }
     19}
     20
    921/** WordPress Administration Bootstrap */
    1022require_once( dirname( __FILE__ ) . '/admin.php' );
    1123
    12 $is_privacy_guide = ( isset( $_GET['wp-privacy-policy-guide'] ) && current_user_can( 'manage_privacy_options' ) );
     24// The privacy policy guide used to be outputted from here. Since WP 5.3 it is in wp-admin/privacy-policy-guide.php.
     25if ( isset( $_GET['wp-privacy-policy-guide'] ) ) {
     26    wp_redirect( admin_url( 'privacy-policy-guide.php' ), 301 );
     27    exit;
     28} elseif ( isset( $_GET['page'] ) ) {
     29    // These were also moved to files in WP 5.3.
     30    if ( $_GET['page'] === 'export_personal_data' ) {
     31        wp_redirect( admin_url( 'export-personal-data.php' ), 301 );
     32        exit;
     33    } elseif ( $_GET['page'] === 'remove_personal_data' ) {
     34        wp_redirect( admin_url( 'erase-personal-data.php' ), 301 );
     35        exit;
     36    }
     37}
    1338
    14 if ( $is_privacy_guide ) {
    15     $title = __( 'Privacy Policy Guide' );
     39$title = __( 'Tools' );
    1640
    17     // "Borrow" xfn.js for now so we don't have to create new files.
    18     wp_enqueue_script( 'xfn' );
     41get_current_screen()->add_help_tab(
     42    array(
     43        'id'      => 'converter',
     44        'title'   => __( 'Categories and Tags Converter' ),
     45        'content' => '<p>' . __( 'Categories have hierarchy, meaning that you can nest sub-categories. Tags do not have hierarchy and cannot be nested. Sometimes people start out using one on their posts, then later realize that the other would work better for their content.' ) . '</p>' .
     46        '<p>' . __( 'The Categories and Tags Converter link on this screen will take you to the Import screen, where that Converter is one of the plugins you can install. Once that plugin is installed, the Activate Plugin &amp; Run Importer link will take you to a screen where you can choose to convert tags into categories or vice versa.' ) . '</p>',
     47    )
     48);
    1949
    20 } else {
    21 
    22     $title = __( 'Tools' );
    23 
    24     get_current_screen()->add_help_tab(
    25         array(
    26             'id'      => 'converter',
    27             'title'   => __( 'Categories and Tags Converter' ),
    28             'content' => '<p>' . __( 'Categories have hierarchy, meaning that you can nest sub-categories. Tags do not have hierarchy and cannot be nested. Sometimes people start out using one on their posts, then later realize that the other would work better for their content.' ) . '</p>' .
    29             '<p>' . __( 'The Categories and Tags Converter link on this screen will take you to the Import screen, where that Converter is one of the plugins you can install. Once that plugin is installed, the Activate Plugin &amp; Run Importer link will take you to a screen where you can choose to convert tags into categories or vice versa.' ) . '</p>',
    30         )
    31     );
    32 
    33     get_current_screen()->set_help_sidebar(
    34         '<p><strong>' . __( 'For more information:' ) . '</strong></p>' .
    35         '<p>' . __( '<a href="https://codex.wordpress.org/Tools_Screen">Documentation on Tools</a>' ) . '</p>' .
    36         '<p>' . __( '<a href="https://wordpress.org/support/">Support</a>' ) . '</p>'
    37     );
    38 }
     50get_current_screen()->set_help_sidebar(
     51    '<p><strong>' . __( 'For more information:' ) . '</strong></p>' .
     52    '<p>' . __( '<a href="https://codex.wordpress.org/Tools_Screen">Documentation on Tools</a>' ) . '</p>' .
     53    '<p>' . __( '<a href="https://wordpress.org/support/">Support</a>' ) . '</p>'
     54);
    3955
    4056require_once( ABSPATH . 'wp-admin/admin-header.php' );
     
    4460<h1><?php echo esc_html( $title ); ?></h1>
    4561<?php
    46 
    47 if ( $is_privacy_guide ) {
    48     ?>
    49     <div class="wp-privacy-policy-guide">
    50         <?php WP_Privacy_Policy_Content::privacy_policy_guide(); ?>
    51     </div>
    52     <?php
    53 
    54 } else {
    5562
    5663    if ( current_user_can( 'import' ) ) :
     
    7380     */
    7481    do_action( 'tool_box' );
    75 }
     82
    7683?>
    7784</div>
    7885<?php
     86
    7987include( ABSPATH . 'wp-admin/admin-footer.php' );
  • trunk/src/wp-includes/script-loader.php

    r45434 r45448  
    15431543
    15441544        $scripts->add( 'xfn', "/wp-admin/js/xfn$suffix.js", array( 'jquery' ), false, 1 );
    1545         did_action( 'init' ) && $scripts->localize(
    1546             'xfn',
    1547             'privacyToolsL10n',
    1548             array(
    1549                 'noDataFound'     => __( 'No personal data was found for this user.' ),
    1550                 'foundAndRemoved' => __( 'All of the personal data found for this user was erased.' ),
    1551                 'noneRemoved'     => __( 'Personal data was found for this user but was not erased.' ),
    1552                 'someNotRemoved'  => __( 'Personal data was found for this user but some of the personal data found was not erased.' ),
    1553                 'removalError'    => __( 'An error occurred while attempting to find and erase personal data.' ),
    1554                 'noExportFile'    => __( 'No personal data export file was generated.' ),
    1555                 'exportError'     => __( 'An error occurred while attempting to export personal data.' ),
    1556             )
    1557         );
    15581545
    15591546        $scripts->add( 'postbox', "/wp-admin/js/postbox$suffix.js", array( 'jquery-ui-sortable' ), false, 1 );
     
    16931680        $scripts->add( 'site-health', "/wp-admin/js/site-health$suffix.js", array( 'clipboard', 'jquery', 'wp-util', 'wp-a11y', 'wp-i18n' ), false, 1 );
    16941681        $scripts->set_translations( 'site-health' );
     1682
     1683        $scripts->add( 'privacy-tools', "/wp-admin/js/privacy-tools$suffix.js", array( 'jquery' ), false, 1 );
     1684        did_action( 'init' ) && $scripts->localize(
     1685            'privacy-tools',
     1686            'privacyToolsL10n',
     1687            array(
     1688                'noDataFound'     => __( 'No personal data was found for this user.' ),
     1689                'foundAndRemoved' => __( 'All of the personal data found for this user was erased.' ),
     1690                'noneRemoved'     => __( 'Personal data was found for this user but was not erased.' ),
     1691                'someNotRemoved'  => __( 'Personal data was found for this user but some of the personal data found was not erased.' ),
     1692                'removalError'    => __( 'An error occurred while attempting to find and erase personal data.' ),
     1693                'noExportFile'    => __( 'No personal data export file was generated.' ),
     1694                'exportError'     => __( 'An error occurred while attempting to export personal data.' ),
     1695            )
     1696        );
    16951697
    16961698        $scripts->add( 'updates', "/wp-admin/js/updates$suffix.js", array( 'jquery', 'wp-util', 'wp-a11y' ), false, 1 );
Note: See TracChangeset for help on using the changeset viewer.