Make WordPress Core

Changeset 43098


Ignore:
Timestamp:
05/02/2018 02:45:22 AM (7 years ago)
Author:
SergeyBiryukov
Message:

Add Privacy Tools admin page under the Tools menu.

Props allendav, xkon, azaozz.
Merges [42814] to the 4.9 branch.
See #43435.

Location:
branches/4.9
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • branches/4.9

  • branches/4.9/src/wp-admin/about.php

    r42933 r43098  
    2828            <a href="credits.php" class="nav-tab"><?php _e( 'Credits' ); ?></a>
    2929            <a href="freedoms.php" class="nav-tab"><?php _e( 'Freedoms' ); ?></a>
    30             <a href="privacy.php" class="nav-tab"><?php _e( 'Privacy' ); ?></a>
     30            <a href="freedoms.php?privacy-notice" class="nav-tab"><?php _e( 'Privacy' ); ?></a>
    3131        </h2>
    3232
  • branches/4.9/src/wp-admin/credits.php

    r43033 r43098  
    2929    <a href="credits.php" class="nav-tab nav-tab-active"><?php _e( 'Credits' ); ?></a>
    3030    <a href="freedoms.php" class="nav-tab"><?php _e( 'Freedoms' ); ?></a>
    31     <a href="privacy.php" class="nav-tab"><?php _e( 'Privacy' ); ?></a>
     31    <a href="freedoms.php?privacy-notice" class="nav-tab"><?php _e( 'Privacy' ); ?></a>
    3232</h2>
    3333
  • branches/4.9/src/wp-admin/freedoms.php

    r42158 r43098  
    1515
    1616include( ABSPATH . 'wp-admin/admin-header.php' );
     17
     18$is_privacy_notice = isset( $_GET['privacy-notice'] );
     19
    1720?>
    1821<div class="wrap about-wrap full-width-layout">
     
    2730    <a href="about.php" class="nav-tab"><?php _e( 'What&#8217;s New' ); ?></a>
    2831    <a href="credits.php" class="nav-tab"><?php _e( 'Credits' ); ?></a>
    29     <a href="freedoms.php" class="nav-tab nav-tab-active"><?php _e( 'Freedoms' ); ?></a>
    30     <a href="privacy.php" class="nav-tab"><?php _e( 'Privacy' ); ?></a>
     32    <a href="freedoms.php" class="nav-tab<?php if ( ! $is_privacy_notice ) { echo ' nav-tab-active'; } ?>"><?php _e( 'Freedoms' ); ?></a>
     33    <a href="freedoms.php?privacy-notice" class="nav-tab<?php if ( $is_privacy_notice ) { echo ' nav-tab-active'; } ?>"><?php _e( 'Privacy' ); ?></a>
    3134</h2>
    3235
     36<?php if ( $is_privacy_notice ) : ?>
     37
     38<div class="about-wrap-content">
     39    <p class="about-description"><?php _e( 'From time to time, your WordPress site may send data to WordPress.org &#8212; including, but not limited to &#8212; the version of WordPress you are using, and a list of installed plugins and themes.' ); ?></p>
     40
     41    <p><?php printf( __( 'This data is used to provide general enhancements to WordPress, which includes helping to protect your site by finding and automatically installing new updates. It is also used to calculate statistics, such as those shown on the <a href="%s">WordPress.org stats page</a>.' ), 'https://wordpress.org/about/stats/' ); ?></p>
     42
     43    <p><?php printf( __( 'We take privacy and transparency very seriously. To learn more about what data we collect, and how we use it, please visit <a href="%s">WordPress.org/about/privacy</a>.' ), 'https://wordpress.org/about/privacy/' ); ?></p>
     44</div>
     45
     46<?php else : ?>
    3347<div class="about-wrap-content">
    3448    <p class="about-description"><?php printf( __( 'WordPress is Free and open source software, built by a distributed community of mostly volunteer developers from around the world. WordPress comes with some awesome, worldview-changing rights courtesy of its <a href="%s">license</a>, the GPL.' ), 'https://wordpress.org/about/license/' ); ?></p>
     
    5367</div>
    5468
     69<?php endif; ?>
    5570</div>
    5671<?php include( ABSPATH . 'wp-admin/admin-footer.php' ); ?>
  • branches/4.9/src/wp-admin/menu.php

    r41268 r43098  
    245245    $submenu['tools.php'][10] = array( __('Import'), 'import', 'import.php' );
    246246    $submenu['tools.php'][15] = array( __('Export'), 'export', 'export.php' );
     247    $submenu['tools.php'][20] = array( __( 'Privacy' ), 'manage_options', 'privacy.php' );
    247248    if ( is_multisite() && !is_main_site() )
    248249        $submenu['tools.php'][25] = array( __('Delete Site'), 'delete_site', 'ms-delete-site.php' );
  • branches/4.9/src/wp-admin/privacy.php

    • Property svn:eol-style set to native
    r42158 r43098  
    11<?php
    22/**
    3  * Privacy administration panel.
     3 * Privacy Tools Screen.
    44 *
    55 * @package WordPress
     
    1010require_once( dirname( __FILE__ ) . '/admin.php' );
    1111
    12 $title = __( 'Privacy' );
    13 
    14 list( $display_version ) = explode( '-', get_bloginfo( 'version' ) );
    15 
    16 include( ABSPATH . 'wp-admin/admin-header.php' );
     12if ( ! current_user_can( 'manage_options' ) ) {
     13    wp_die( __( 'Sorry, you are not allowed to manage privacy on this site.' ) );
     14}
     15
     16// "Borrow" xfn.js for now so we don't have to create new files.
     17// wp_enqueue_script( 'xfn' );
     18
     19$action = isset( $_POST['action'] ) ? $_POST['action'] : '';
     20
     21if ( ! empty( $action ) ) {
     22    check_admin_referer( $action );
     23
     24    if ( 'set-privacy-page' === $action ) {
     25        $privacy_policy_page_id = isset( $_POST['page_for_privacy_policy'] ) ? (int) $_POST['page_for_privacy_policy'] : 0;
     26        update_option( 'wp_page_for_privacy_policy', $privacy_policy_page_id );
     27
     28        add_settings_error(
     29            'page_for_privacy_policy',
     30            'page_for_privacy_policy',
     31            __( 'Privacy policy page updated successfully.' ),
     32            'updated'
     33        );
     34    } elseif ( 'create-privacy-page' === $action ) {
     35        $privacy_policy_page_id = wp_insert_post(
     36            array(
     37                'post_title'  => __( 'Privacy Policy' ),
     38                'post_status' => 'draft',
     39                'post_type'   => 'page',
     40            ),
     41            true
     42        );
     43
     44        if ( is_wp_error( $privacy_policy_page_id ) ) {
     45            add_settings_error(
     46                'page_for_privacy_policy',
     47                'page_for_privacy_policy',
     48                __( 'Unable to create privacy policy page.' ),
     49                'error'
     50            );
     51        } else {
     52            update_option( 'wp_page_for_privacy_policy', $privacy_policy_page_id );
     53            add_settings_error(
     54                'page_for_privacy_policy',
     55                'page_for_privacy_policy',
     56                __( 'Privacy policy page created successfully.' ),
     57                'updated'
     58            );
     59        }
     60    }
     61}
     62
     63// If a privacy policy page ID is available, make sure the page actually exists. If not, display a warning
     64$privacy_policy_page_exists = false;
     65$privacy_policy_page_id = (int) get_option( 'wp_page_for_privacy_policy' );
     66
     67if ( ! empty( $privacy_policy_page_id ) ) {
     68        $privacy_policy_page = get_post( $privacy_policy_page_id );
     69        if ( ! $privacy_policy_page instanceof WP_Post ) {
     70            add_settings_error(
     71                'page_for_privacy_policy',
     72                'page_for_privacy_policy',
     73                __( 'The currently selected privacy policy page does not exist. Please create or select new page.' ),
     74                'warning'
     75            );
     76        } else {
     77            if ( 'trash' === $privacy_policy_page->post_status ) {
     78                add_settings_error(
     79                    'page_for_privacy_policy',
     80                    'page_for_privacy_policy',
     81                    sprintf(
     82                        __( 'The currently selected privacy policy page is in the trash. Please create or select new privacy policy page or <a href="%s">restore the current page</a>.' ),
     83                        'edit.php?post_status=trash&post_type=page'
     84                    ),
     85                    'error'
     86                );
     87            } else {
     88                $privacy_policy_page_exists = true;
     89            }
     90        }
     91}
     92
     93$title = __( 'Privacy Tools' );
     94
     95get_current_screen()->add_help_tab( array(
     96    'id'      => 'privacy',
     97    'title'   => __( 'Privacy' ),
     98    'content' => '<p>' . __( 'This page provides tools with which you can manage your user\'s personal data and site\'s privacy policy.' ) . '</p>',
     99) );
     100
     101get_current_screen()->set_help_sidebar(
     102    '<p><strong>' . __( 'For more information:' ) . '</strong></p>' .
     103    '<p>' . __( '<a href="#">Documentation on privacy</a>' ) . '</p>'
     104);
     105
     106require_once( ABSPATH . 'wp-admin/admin-header.php' );
     107
    17108?>
    18 <div class="wrap about-wrap full-width-layout">
    19 
    20 <h1><?php printf( __( 'Welcome to WordPress %s' ), $display_version ); ?></h1>
    21 
    22 <p class="about-text"><?php printf( __( 'Thank you for updating to the latest version! WordPress %s will smooth your design workflow and keep you safe from coding errors.' ), $display_version ); ?></p>
    23 
    24 <div class="wp-badge"><?php printf( __( 'Version %s' ), $display_version ); ?></div>
    25 
    26 <h2 class="nav-tab-wrapper wp-clearfix">
    27     <a href="about.php" class="nav-tab"><?php _e( 'What&#8217;s New' ); ?></a>
    28     <a href="credits.php" class="nav-tab"><?php _e( 'Credits' ); ?></a>
    29     <a href="freedoms.php" class="nav-tab"><?php _e( 'Freedoms' ); ?></a>
    30     <a href="privacy.php" class="nav-tab nav-tab-active"><?php _e( 'Privacy' ); ?></a>
    31 </h2>
    32 
    33 <div class="about-wrap-content">
    34     <p class="about-description"><?php _e( 'From time to time, your WordPress site may send data to WordPress.org &#8212; including, but not limited to &#8212; the version of WordPress you are using, and a list of installed plugins and themes.' ); ?></p>
    35 
    36     <p><?php printf( __( 'This data is used to provide general enhancements to WordPress, which includes helping to protect your site by finding and automatically installing new updates. It is also used to calculate statistics, such as those shown on the <a href="%s">WordPress.org stats page</a>.' ), 'https://wordpress.org/about/stats/' ); ?></p>
    37 
    38     <p><?php printf( __( 'We take privacy and transparency very seriously. To learn more about what data we collect, and how we use it, please visit <a href="%s">WordPress.org/about/privacy</a>.' ), 'https://wordpress.org/about/privacy/' ); ?></p>
     109<div class="wrap">
     110    <h1><?php echo esc_html( $title ); ?></h1>
     111    <?php settings_errors(); ?>
     112
     113    <h2 class="title"><?php _e( 'Privacy policy page' ); ?></h2>
     114    <table class="form-table">
     115        <?php
     116
     117        if ( $privacy_policy_page_exists ) {
     118            $edit_href = add_query_arg(
     119                array(
     120                    'post'  => $privacy_policy_page_id,
     121                    'action' => 'edit',
     122                ),
     123                admin_url( 'post.php' )
     124            );
     125            $view_href = get_permalink( $privacy_policy_page_id );
     126
     127            ?>
     128            <tr>
     129                <th colspan="2">
     130                    <?php
     131                    printf(
     132                        __( '<a href="%1$s">Edit</a> or <a href="%2$s">view</a> your privacy policy.' ),
     133                        $edit_href,
     134                        $view_href
     135                    );
     136                    ?>
     137                </th>
     138            </tr>
     139            <?php
     140        }
     141
     142        ?>
     143        <tr>
     144            <th scope="row">
     145            <?php
     146
     147            if ( $privacy_policy_page_exists ) {
     148                _e( 'Select another page for your privacy policy' );
     149            } else {
     150                _e( 'Select an existing privacy policy page' );
     151            }
     152
     153            ?>
     154            </th>
     155            <td id="front-static-pages">
     156                <form method="post" action="">
     157                    <?php wp_nonce_field( 'set-privacy-page' ); ?>
     158                    <input type="hidden" name="action" value="set-privacy-page" />
     159                    <fieldset>
     160                        <legend class="screen-reader-text"><span><?php _e( 'Select your privacy policy page.' ); ?></span></legend>
     161                        <label for="page_for_privacy_policy">
     162                            <?php wp_dropdown_pages(
     163                                array(
     164                                    'name'              => 'page_for_privacy_policy',
     165                                    'show_option_none'  => __( '&mdash; Select &mdash;' ),
     166                                    'option_none_value' => '0',
     167                                    'selected'          => $privacy_policy_page_id,
     168                                    'post_status'       => array( 'draft', 'publish' ),
     169                                )
     170                            );
     171                            ?>
     172                        </label>
     173                    </fieldset>
     174                        <?php submit_button( __( 'Set Page' ) ); ?>
     175                </form>
     176            </td>
     177        </tr>
     178        <?php
     179
     180        if ( ! $privacy_policy_page_exists ) {
     181            ?>
     182            <tr>
     183                <th scope="row"><?php _e( 'Create new page for your privacy policy' ); ?></th>
     184                <td>
     185                    <form method="post" action="">
     186                        <input type="hidden" name="action" value="create-privacy-page" />
     187                        <?php wp_nonce_field( 'create-privacy-page' ); ?>
     188                        <?php submit_button( __( 'Create Page' ) ); ?>
     189                    </form>
     190                </td>
     191            </tr>
     192            <?php
     193        }
     194
     195        ?>
     196    </table>
    39197</div>
    40198
    41 </div>
    42 <?php include( ABSPATH . 'wp-admin/admin-footer.php' ); ?>
     199<?php
     200
     201include( ABSPATH . 'wp-admin/admin-footer.php' );
Note: See TracChangeset for help on using the changeset viewer.