Changeset 43225 for branches/4.9/src/wp-admin/includes/misc.php
- Timestamp:
- 05/10/2018 08:07:11 PM (8 years ago)
- Location:
- branches/4.9
- Files:
-
- 2 edited
-
. (modified) (1 prop)
-
src/wp-admin/includes/misc.php (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/4.9
-
branches/4.9/src/wp-admin/includes/misc.php
r43207 r43225 1272 1272 // The site doesn't have a privacy policy. 1273 1273 if ( empty( $policy_page_id ) ) { 1274 return ;1274 return false; 1275 1275 } 1276 1276 1277 1277 if ( ! current_user_can( 'edit_post', $policy_page_id ) ) { 1278 return; 1279 } 1280 1281 // Also run when the option doesn't exist yet. 1282 if ( get_option( '_wp_privacy_text_change_check' ) === 'no-check' ) { 1283 return; 1278 return false; 1284 1279 } 1285 1280 1286 1281 $old = (array) get_post_meta( $policy_page_id, '_wp_suggested_privacy_policy_content' ); 1282 1283 // Updates are not relevant if the user has not reviewed any suggestions yet. 1284 if ( empty( $old ) ) { 1285 return false; 1286 } 1287 1288 $cached = get_option( '_wp_suggested_policy_text_has_changed' ); 1289 1290 /* 1291 * When this function is called before `admin_init`, `self::$policy_content` 1292 * has not been populated yet, so use the cached result from the last 1293 * execution instead. 1294 */ 1295 if ( ! did_action( 'admin_init' ) ) { 1296 return 'changed' === $cached; 1297 } 1298 1287 1299 $new = self::$policy_content; 1288 1300 1289 1301 // Remove the extra values added to the meta. 1290 1302 foreach ( $old as $key => $data ) { 1303 if ( ! empty( $data['removed'] ) ) { 1304 unset( $old[ $key ] ); 1305 continue; 1306 } 1307 1291 1308 $old[ $key ] = array( 1292 1309 'plugin_name' => $data['plugin_name'], … … 1295 1312 } 1296 1313 1314 // Normalize the order of texts, to facilitate comparison. 1315 sort( $old ); 1316 sort( $new ); 1317 1297 1318 // The == operator (equal, not identical) was used intentionally. 1298 1319 // See http://php.net/manual/en/language.operators.array.php 1299 1320 if ( $new != $old ) { 1300 1321 // A plugin was activated or deactivated, or some policy text has changed. 1301 // Show a notice on all screens in wp-admin.1322 // Show a notice on the relevant screens to inform the admin. 1302 1323 add_action( 'admin_notices', array( 'WP_Privacy_Policy_Content', 'policy_text_changed_notice' ) ); 1324 $state = 'changed'; 1303 1325 } else { 1304 // Stop checking. 1305 update_option( '_wp_privacy_text_change_check', 'no-check' ); 1306 } 1326 $state = 'not-changed'; 1327 } 1328 1329 // Cache the result for use before `admin_init` (see above). 1330 if ( $cached !== $state ) { 1331 update_option( '_wp_suggested_policy_text_has_changed', $state ); 1332 } 1333 1334 return 'changed' === $state; 1307 1335 } 1308 1336 1309 1337 /** 1310 * Output a n admin noticewhen some privacy info has changed.1338 * Output a warning when some privacy info has changed. 1311 1339 * 1312 1340 * @since 4.9.6 … … 1314 1342 public static function policy_text_changed_notice() { 1315 1343 global $post; 1316 $policy_page_id = (int) get_option( 'wp_page_for_privacy_policy' ); 1344 1345 $screen = get_current_screen()->id; 1346 1347 if ( 'privacy' !== $screen ) { 1348 return; 1349 } 1317 1350 1318 1351 ?> 1319 1352 <div class="policy-text-updated notice notice-warning is-dismissible"> 1320 1353 <p><?php 1321 1322 _e( 'The suggested privacy policy text has changed.' ); 1323 1324 if ( empty( $post ) || $post->ID != $policy_page_id ) { 1325 ?> 1326 <a href="<?php echo get_edit_post_link( $policy_page_id ); ?>"><?php _e( 'Edit the privacy policy.' ); ?></a> 1327 <?php 1328 } 1329 1354 _e( 'The suggested privacy policy text has changed. Please update your privacy policy.' ); 1330 1355 ?></p> 1331 1356 </div> … … 1334 1359 1335 1360 /** 1336 * Stop checking for changed privacy info when the policy page is updated.1361 * Update the cached policy info when the policy page is updated. 1337 1362 * 1338 1363 * @since 4.9.6 … … 1346 1371 } 1347 1372 1348 // The policy page was updated. 1349 // Stop checking for text changes. 1350 update_option( '_wp_privacy_text_change_check', 'no-check' ); 1373 // Update the cache in case the user hasn't visited the policy guide. 1374 self::get_suggested_policy_text(); 1351 1375 1352 1376 // Remove updated|removed status. … … 1448 1472 if ( ! empty( $new_data['plugin_name'] ) && ! empty( $new_data['policy_text'] ) ) { 1449 1473 $new_data['added'] = $time; 1450 array_unshift( $checked, $new_data );1474 $checked[] = $new_data; 1451 1475 } 1452 1476 } … … 1463 1487 'removed' => $time, 1464 1488 ); 1465 array_unshift( $checked, $data ); 1489 1490 $checked[] = $data; 1466 1491 } 1467 1492 } … … 1475 1500 add_post_meta( $policy_page_id, '_wp_suggested_privacy_policy_content', $data ); 1476 1501 } 1477 }1478 1479 // Stop checking for changes after the page has been loaded.1480 if ( get_option( '_wp_privacy_text_change_check' ) !== 'no-check' ) {1481 update_option( '_wp_privacy_text_change_check', 'no-check' );1482 1502 } 1483 1503
Note: See TracChangeset
for help on using the changeset viewer.