Make WordPress Core

Ticket #43954: 43954.2.diff

File 43954.2.diff, 9.4 KB (added by azaozz, 7 years ago)
  • src/wp-admin/css/forms.css

     
    10891089}
    10901090
    10911091.tools-privacy-edit {
    1092         margin: 2.3em 0;
     1092        margin: 1.5em 0;
    10931093}
    10941094
    10951095.tools-privacy-policy-page span {
  • src/wp-admin/includes/admin-filters.php

     
    138138add_action( 'wp_privacy_personal_data_export_file', 'wp_privacy_generate_personal_data_export_file', 10 );
    139139
    140140// Privacy policy text changes check.
    141 add_action( 'admin_init', array( 'WP_Privacy_Policy_Content', 'text_change_check' ), 20 );
     141add_action( 'admin_init', array( 'WP_Privacy_Policy_Content', 'text_change_check' ), 100 );
    142142
    143143// Show a "postbox" with the text suggestions for a privacy policy.
    144144add_action( 'edit_form_after_title', array( 'WP_Privacy_Policy_Content', 'notice' ) );
     
    146146// Add the suggested policy text from WordPress.
    147147add_action( 'admin_init', array( 'WP_Privacy_Policy_Content', 'add_suggested_content' ), 1 );
    148148
    149 // Stop checking for text changes after the policy page is updated.
     149// Update the cached policy info when the policy page is updated.
    150150add_action( 'post_updated', array( 'WP_Privacy_Policy_Content', '_policy_page_updated' ) );
  • src/wp-admin/includes/misc.php

     
    13201320
    13211321                // The site doesn't have a privacy policy.
    13221322                if ( empty( $policy_page_id ) ) {
    1323                         return;
     1323                        return false;
    13241324                }
    13251325
    13261326                if ( ! current_user_can( 'edit_post', $policy_page_id ) ) {
    1327                         return;
     1327                        return false;
    13281328                }
    13291329
    1330                 // Also run when the option doesn't exist yet.
    1331                 if ( get_option( '_wp_privacy_text_change_check' ) === 'no-check' ) {
    1332                         return;
     1330                $old = (array) get_post_meta( $policy_page_id, '_wp_suggested_privacy_policy_content' );
     1331
     1332                // The users have never seen the Privacy Policy Guide screen (usually happens after fresh install or update).
     1333                // No point to show warnings about updated content there.
     1334                if ( empty( $old ) ) {
     1335                        return false;
    13331336                }
    13341337
    1335                 $old = (array) get_post_meta( $policy_page_id, '_wp_suggested_privacy_policy_content' );
     1338                $cached = get_option( '_wp_suggested_policy_text_has_changed' );
     1339
     1340                // Too early to get the privacy info, use the cache.
     1341                // This check also runs on the 'admin_init' action and will update the cache if needed.
     1342                if ( ! did_action( 'admin_init' ) ) {
     1343                        return $cached === 'changed';
     1344                }
     1345
    13361346                $new = self::$policy_content;
    13371347
    13381348                // Remove the extra values added to the meta.
    13391349                foreach ( $old as $key => $data ) {
    1340                         $old[ $key ] = array(
    1341                                 'plugin_name' => $data['plugin_name'],
    1342                                 'policy_text' => $data['policy_text'],
    1343                         );
     1350                        if ( ! empty( $data['removed'] ) ) {
     1351                                unset( $old[ $key ] );
     1352                        } else {
     1353                                $old[ $key ] = array(
     1354                                        'plugin_name' => $data['plugin_name'],
     1355                                        'policy_text' => $data['policy_text'],
     1356                                );
     1357                        }
    13441358                }
    13451359
    13461360                // The == operator (equal, not identical) was used intentionally.
     
    13471361                // See http://php.net/manual/en/language.operators.array.php
    13481362                if ( $new != $old ) {
    13491363                        // A plugin was activated or deactivated, or some policy text has changed.
    1350                         // Show a notice on all screens in wp-admin.
     1364                        // Show a notice on the Edit Page screen when editing the policy page.
    13511365                        add_action( 'admin_notices', array( 'WP_Privacy_Policy_Content', 'policy_text_changed_notice' ) );
     1366                        $state = 'changed';
    13521367                } else {
    1353                         // Stop checking.
    1354                         update_option( '_wp_privacy_text_change_check', 'no-check' );
     1368                        $state = 'not-changed';
    13551369                }
     1370
     1371                if ( $cached !== $state ) {
     1372                        update_option( '_wp_suggested_policy_text_has_changed', $state );
     1373                }
     1374
     1375                return $state === 'changed';
    13561376        }
    13571377
    13581378        /**
    1359          * Output an admin notice when some privacy info has changed.
     1379         * Output a warning when some privacy info has changed.
    13601380         *
    13611381         * @since 4.9.6
    13621382         */
    13631383        public static function policy_text_changed_notice() {
    13641384                global $post;
     1385
     1386                $screen = get_current_screen()->id;
    13651387                $policy_page_id = (int) get_option( 'wp_page_for_privacy_policy' );
    13661388
    1367                 ?>
    1368                 <div class="policy-text-updated notice notice-warning is-dismissible">
    1369                         <p><?php
    1370 
    1371                                 _e( 'The suggested privacy policy text has changed.' );
    1372 
    1373                                 if ( empty( $post ) || $post->ID != $policy_page_id ) {
    1374                                         ?>
    1375                                         <a href="<?php echo get_edit_post_link( $policy_page_id ); ?>"><?php _e( 'Edit the privacy policy.' ); ?></a>
    1376                                         <?php
    1377                                 }
    1378 
    1379                         ?></p>
    1380                 </div>
    1381                 <?php
     1389                if ( $screen === 'privacy' || ( $screen === 'page' && ! empty( $post ) && (int) $post->ID === $policy_page_id ) ) {
     1390                        ?>
     1391                        <div class="policy-text-updated notice notice-warning is-dismissible">
     1392                                <p><?php _e( 'The suggested privacy policy text has changed. Please update your privacy policy.' ); ?></p>
     1393                        </div>
     1394                        <?php
     1395                }
    13821396        }
    13831397
    13841398        /**
    1385          * Stop checking for changed privacy info when the policy page is updated.
     1399         * Update the cached policy info when the policy page is updated.
    13861400         *
    13871401         * @since 4.9.6
    13881402         * @access private
     
    13941408                        return;
    13951409                }
    13961410
    1397                 // The policy page was updated.
    1398                 // Stop checking for text changes.
    1399                 update_option( '_wp_privacy_text_change_check', 'no-check' );
    1400 
    14011411                // Remove updated|removed status.
    14021412                $old = (array) get_post_meta( $policy_page_id, '_wp_suggested_privacy_policy_content' );
    14031413                $done = array();
     
    14961506                        foreach ( $new as $new_data ) {
    14971507                                if ( ! empty( $new_data['plugin_name'] ) && ! empty( $new_data['policy_text'] ) ) {
    14981508                                        $new_data['added'] = $time;
    1499                                         array_unshift( $checked, $new_data );
     1509                                        $checked[] = $new_data;
    15001510                                }
    15011511                        }
    15021512                        $update_cache = true;
     
    15111521                                                'policy_text' => $old_data['policy_text'],
    15121522                                                'removed'     => $time,
    15131523                                        );
    1514                                         array_unshift( $checked, $data );
     1524
     1525                                        $checked[] = $data;
    15151526                                }
    15161527                        }
    15171528                        $update_cache = true;
     
    15251536                        }
    15261537                }
    15271538
    1528                 // Stop checking for changes after the page has been loaded.
    1529                 if ( get_option( '_wp_privacy_text_change_check' ) !== 'no-check' ) {
    1530                         update_option( '_wp_privacy_text_change_check', 'no-check' );
    1531                 }
    1532 
    15331539                return $checked;
    15341540        }
    15351541
  • src/wp-admin/menu.php

     
    263263        $submenu['tools.php'][50] = array( __( 'Network Setup' ), 'setup_network', 'network.php' );
    264264}
    265265
    266 $menu[80]                               = array( __( 'Settings' ), 'manage_options', 'options-general.php', '', 'menu-top menu-icon-settings', 'menu-settings', 'dashicons-admin-settings' );
     266$change_notice = '';
     267if ( current_user_can( 'manage_privacy_options' ) && WP_Privacy_Policy_Content::text_change_check() ) {
     268        $change_notice = ' <span class="update-plugins 1"><span class="plugin-count">' . number_format_i18n( 1 ) . '</span></span>';
     269}
     270
     271$menu[80]                               = array( sprintf( __( 'Settings %s' ), $change_notice ), 'manage_options', 'options-general.php', '', 'menu-top menu-icon-settings', 'menu-settings', 'dashicons-admin-settings' );
    267272        $submenu['options-general.php'][10] = array( _x( 'General', 'settings screen' ), 'manage_options', 'options-general.php' );
    268273        $submenu['options-general.php'][15] = array( __( 'Writing' ), 'manage_options', 'options-writing.php' );
    269274        $submenu['options-general.php'][20] = array( __( 'Reading' ), 'manage_options', 'options-reading.php' );
     
    270275        $submenu['options-general.php'][25] = array( __( 'Discussion' ), 'manage_options', 'options-discussion.php' );
    271276        $submenu['options-general.php'][30] = array( __( 'Media' ), 'manage_options', 'options-media.php' );
    272277        $submenu['options-general.php'][40] = array( __( 'Permalinks' ), 'manage_options', 'options-permalink.php' );
    273         $submenu['options-general.php'][45] = array( __( 'Privacy' ), 'manage_privacy_options', 'privacy.php' );
     278        $submenu['options-general.php'][45] = array( sprintf( __( 'Privacy %s' ), $change_notice ), 'manage_privacy_options', 'privacy.php' );
    274279
    275280$_wp_last_utility_menu = 80; // The index of the last top-level menu in the utility menu group
    276281
  • src/wp-includes/default-filters.php

     
    562562// Capabilities
    563563add_filter( 'user_has_cap', 'wp_maybe_grant_install_languages_cap', 1 );
    564564
    565 // Trigger the check for policy text changes after active plugins change.
    566 add_action( 'update_site_option_active_sitewide_plugins', '_wp_privacy_active_plugins_change' );
    567 add_action( 'update_option_active_plugins', '_wp_privacy_active_plugins_change' );
    568 
    569565unset( $filter, $action );
  • src/wp-includes/functions.php

     
    62496249}
    62506250
    62516251/**
    6252  * Trigger the check for policy text changes.
    6253  *
    6254  * @since 4.9.6
    6255  * @access private
    6256  */
    6257 function _wp_privacy_active_plugins_change() {
    6258         update_option( '_wp_privacy_text_change_check', 'check' );
    6259 }
    6260 
    6261 /**
    62626252 * Schedule a `WP_Cron` job to delete expired export files.
    62636253 *
    62646254 * @since 4.9.6