Changeset 43223 for trunk/src/wp-admin/includes/misc.php
- Timestamp:
- 05/10/2018 07:51:58 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/includes/misc.php
r43206 r43223 1321 1321 // The site doesn't have a privacy policy. 1322 1322 if ( empty( $policy_page_id ) ) { 1323 return ;1323 return false; 1324 1324 } 1325 1325 1326 1326 if ( ! current_user_can( 'edit_post', $policy_page_id ) ) { 1327 return; 1328 } 1329 1330 // Also run when the option doesn't exist yet. 1331 if ( get_option( '_wp_privacy_text_change_check' ) === 'no-check' ) { 1332 return; 1327 return false; 1333 1328 } 1334 1329 1335 1330 $old = (array) get_post_meta( $policy_page_id, '_wp_suggested_privacy_policy_content' ); 1331 1332 // Updates are not relevant if the user has not reviewed any suggestions yet. 1333 if ( empty( $old ) ) { 1334 return false; 1335 } 1336 1337 $cached = get_option( '_wp_suggested_policy_text_has_changed' ); 1338 1339 /* 1340 * When this function is called before `admin_init`, `self::$policy_content` 1341 * has not been populated yet, so use the cached result from the last 1342 * execution instead. 1343 */ 1344 if ( ! did_action( 'admin_init' ) ) { 1345 return 'changed' === $cached; 1346 } 1347 1336 1348 $new = self::$policy_content; 1337 1349 1338 1350 // Remove the extra values added to the meta. 1339 1351 foreach ( $old as $key => $data ) { 1352 if ( ! empty( $data['removed'] ) ) { 1353 unset( $old[ $key ] ); 1354 continue; 1355 } 1356 1340 1357 $old[ $key ] = array( 1341 1358 'plugin_name' => $data['plugin_name'], … … 1344 1361 } 1345 1362 1363 // Normalize the order of texts, to facilitate comparison. 1364 sort( $old ); 1365 sort( $new ); 1366 1346 1367 // The == operator (equal, not identical) was used intentionally. 1347 1368 // See http://php.net/manual/en/language.operators.array.php 1348 1369 if ( $new != $old ) { 1349 1370 // A plugin was activated or deactivated, or some policy text has changed. 1350 // Show a notice on all screens in wp-admin.1371 // Show a notice on the relevant screens to inform the admin. 1351 1372 add_action( 'admin_notices', array( 'WP_Privacy_Policy_Content', 'policy_text_changed_notice' ) ); 1373 $state = 'changed'; 1352 1374 } else { 1353 // Stop checking. 1354 update_option( '_wp_privacy_text_change_check', 'no-check' ); 1355 } 1375 $state = 'not-changed'; 1376 } 1377 1378 // Cache the result for use before `admin_init` (see above). 1379 if ( $cached !== $state ) { 1380 update_option( '_wp_suggested_policy_text_has_changed', $state ); 1381 } 1382 1383 return 'changed' === $state; 1356 1384 } 1357 1385 1358 1386 /** 1359 * Output a n admin noticewhen some privacy info has changed.1387 * Output a warning when some privacy info has changed. 1360 1388 * 1361 1389 * @since 4.9.6 … … 1363 1391 public static function policy_text_changed_notice() { 1364 1392 global $post; 1365 $policy_page_id = (int) get_option( 'wp_page_for_privacy_policy' ); 1393 1394 $screen = get_current_screen()->id; 1395 1396 if ( 'privacy' !== $screen ) { 1397 return; 1398 } 1366 1399 1367 1400 ?> 1368 1401 <div class="policy-text-updated notice notice-warning is-dismissible"> 1369 1402 <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 1403 _e( 'The suggested privacy policy text has changed. Please update your privacy policy.' ); 1379 1404 ?></p> 1380 1405 </div> … … 1383 1408 1384 1409 /** 1385 * Stop checking for changed privacy info when the policy page is updated.1410 * Update the cached policy info when the policy page is updated. 1386 1411 * 1387 1412 * @since 4.9.6 … … 1395 1420 } 1396 1421 1397 // The policy page was updated. 1398 // Stop checking for text changes. 1399 update_option( '_wp_privacy_text_change_check', 'no-check' ); 1422 // Update the cache in case the user hasn't visited the policy guide. 1423 self::get_suggested_policy_text(); 1400 1424 1401 1425 // Remove updated|removed status. … … 1497 1521 if ( ! empty( $new_data['plugin_name'] ) && ! empty( $new_data['policy_text'] ) ) { 1498 1522 $new_data['added'] = $time; 1499 array_unshift( $checked, $new_data );1523 $checked[] = $new_data; 1500 1524 } 1501 1525 } … … 1512 1536 'removed' => $time, 1513 1537 ); 1514 array_unshift( $checked, $data ); 1538 1539 $checked[] = $data; 1515 1540 } 1516 1541 } … … 1524 1549 add_post_meta( $policy_page_id, '_wp_suggested_privacy_policy_content', $data ); 1525 1550 } 1526 }1527 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 1551 } 1532 1552
Note: See TracChangeset
for help on using the changeset viewer.