Ticket #17323: 17323.2.diff

File 17323.2.diff, 2.0 KB (added by aaroncampbell, 2 years ago)

Keep the sky up + longer caching

Line 
1Index: wp-admin/includes/update.php
2===================================================================
3--- wp-admin/includes/update.php        (revision 17792)
4+++ wp-admin/includes/update.php        (working copy)
5@@ -309,4 +309,53 @@
6 }
7 add_action( 'admin_notices', 'maintenance_nag' );
8 
9+/**
10+ * Display a nag in the footer if the user is using an outdated browser.  If
11+ * that browser is IE < 8 mention that it is insecure
12+ *
13+ * @since 3.1.2
14+ */
15+function browser_upgrade_nag() {
16+       $key = md5( $_SERVER['HTTP_USER_AGENT'] );
17+
18+       if ( false !== ($response = get_site_transient('browsehappy_' . $key) ) ) {
19+
20+               $options = array(
21+                       'body'                  => array( 'useragent' => $_SERVER['HTTP_USER_AGENT'] ),
22+                       'user-agent'    => 'WordPress/' . $wp_version . '; ' . get_bloginfo( 'url' )
23+               );
24+
25+               $raw_response = wp_remote_post( 'http://api.wordpress.org/core/browse-happy/1.0/', $options );
26+
27+               if ( is_wp_error( $raw_response ) || 200 != $raw_response['response']['code'] )
28+                       return;
29+
30+               /**
31+                * Response should be an array with:
32+                *  'name' - string- A user friendly browser name
33+                *  'version' - string - The most recent version of the browser
34+                *  'upgrade' - boolean - Whether the browser needs an upgrade
35+                *  'insecure' - boolean - Whether the browser is deemed insecure
36+                */
37+               $response = unserialize( $raw_response['body'] );
38+
39+               if ( ! $response )
40+                       return;
41+
42+               set_site_transient( 'browsehappy_' . $key, $response, 604800 ); // cache for 1 week
43+       }
44+
45+       if ( ! $response['upgrade'] )
46+               return;
47+
48+       if ( $response['insecure'] ) {
49+               $msg = sprintf( __( 'Your version of %s is insecure.  WordPress recommends an update.' ), $response['name'] );
50+       } else {
51+               $msg = sprintf( __( 'Your version of %s is out of date.  WordPress recommends an update.' ), $response['name'] );
52+       }
53+
54+       echo apply_filters( 'browse-happy-notice', '<div id="bh"><a href="http://browsehappy.com/" title="' . esc_attr__( 'Browse Happy' ) . '">' . esc_html( $msg ) . '</a></div>' );
55+}
56+add_action( 'admin_footer', 'browser_upgrade_nag' );
57+
58 ?>