Changeset 17887 for trunk/wp-admin/includes/dashboard.php
- Timestamp:
- 05/12/2011 03:33:27 AM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-admin/includes/dashboard.php
r17829 r17887 25 25 26 26 /* Register Widgets and Controls */ 27 28 $response = wp_check_browser_version(); 29 30 if ( $response['upgrade'] ) { 31 add_filter( 'postbox_classes_dashboard_dashboard_browser_nag', 'dashboard_browser_nag_class' ); 32 if ( $response['insecure'] ) 33 wp_add_dashboard_widget( 'dashboard_browser_nag', __( 'You are using an insecure browser!' ), 'wp_dashboard_browser_nag' ); 34 else 35 wp_add_dashboard_widget( 'dashboard_browser_nag', __( 'Your browser is out of date!' ), 'wp_dashboard_browser_nag' ); 36 } 27 37 28 38 // Right Now … … 1148 1158 add_action( 'activity_box_end', 'wp_dashboard_quota' ); 1149 1159 1160 // Display Browser Nag Meta Box 1161 function wp_dashboard_browser_nag() { 1162 $notice = ''; 1163 $response = wp_check_browser_version(); 1164 1165 if ( $response['insecure'] ) { 1166 $msg = sprintf( __( 'It looks like you\'re using an insecure version of <a href="%1$s">%2$s</a>. Using an outdated browser makes your computer unsafe. For the best WordPress experience, please update your browser.' ), esc_attr( $response['update_url'] ), esc_html( $response['name'] ) ); 1167 } else { 1168 $msg = sprintf( __( 'It looks like you\'re using an old version of <a href="%1$s">%2$s</a>. Using an outdated browser makes your computer unsafe. For the best WordPress experience, please update your browser.' ), esc_attr( $response['update_url'] ), esc_html( $response['name'] ) ); 1169 } 1170 1171 $browser_nag_class = ''; 1172 if ( !empty( $response['img_src'] ) ) { 1173 $img_src = ( is_ssl() && ! empty( $response['img_src_ssl'] ) )? $response['img_src_ssl'] : $response['img_src']; 1174 1175 $notice .= '<div class="alignright browser-icon"><a href="' . esc_attr($response['update_url']) . '"><img src="' . esc_attr( $img_src ) . '" alt="" /></a></div>'; 1176 $browser_nag_class = ' has-browser-icon'; 1177 } 1178 $notice .= "<p class='browser-update-nag{$browser_nag_class}'>{$msg}</p>"; 1179 $notice .= sprintf( __( '<p><a href="%1$s" class="update-browser-link">Update %2$s</a> or learn how to <a href="%3$s" class="browse-happy-link">browse happy</a></p>' ), esc_attr( $response['update_url'] ), esc_html( $response['name'] ), 'http://browsehappy.com/' ); 1180 $notice .= '<p><a href="" class="dismiss">' . __( 'Dismiss' ) . '</a></p>'; 1181 $notice .= '<div class="clear"></div>'; 1182 1183 echo apply_filters( 'browse-happy-notice', $notice, $response ); 1184 } 1185 1186 function dashboard_browser_nag_class( $classes ) { 1187 $response = wp_check_browser_version(); 1188 1189 if ( $response['insecure'] ) 1190 $classes[] = 'browser-insecure'; 1191 1192 return $classes; 1193 } 1194 1195 /** 1196 * Check if the user needs a browser update 1197 * 1198 * @since 3.2 1199 */ 1200 function wp_check_browser_version() { 1201 $key = md5( $_SERVER['HTTP_USER_AGENT'] ); 1202 1203 if ( false === ($response = get_site_transient('browsehappy_' . $key) ) ) { 1204 global $wp_version; 1205 1206 $options = array( 1207 'body' => array( 'useragent' => $_SERVER['HTTP_USER_AGENT'] ), 1208 'user-agent' => 'WordPress/' . $wp_version . '; ' . get_bloginfo( 'url' ) 1209 ); 1210 1211 $raw_response = wp_remote_post( 'http://api.wordpress.org/core/browse-happy/1.0/', $options ); 1212 1213 if ( is_wp_error( $raw_response ) || 200 != $raw_response['response']['code'] ) 1214 return; 1215 1216 /** 1217 * Response should be an array with: 1218 * 'name' - string- A user friendly browser name 1219 * 'version' - string - The most recent version of the browser 1220 * 'current_version' - string - The version of the browser the user is using 1221 * 'upgrade' - boolean - Whether the browser needs an upgrade 1222 * 'insecure' - boolean - Whether the browser is deemed insecure 1223 * 'upgrade_url' - string - The url to visit to upgrade 1224 * 'img_src' - string - An image representing the browser 1225 */ 1226 $response = unserialize( $raw_response['body'] ); 1227 1228 if ( ! $response ) 1229 return; 1230 1231 set_site_transient( 'browsehappy_' . $key, $response, 604800 ); // cache for 1 week 1232 } 1233 1234 return $response; 1235 } 1236 1150 1237 /** 1151 1238 * Empty function usable by plugins to output empty dashboard widget (to be populated later by JS).
Note: See TracChangeset
for help on using the changeset viewer.