Warning for out of date and insecure browsers, props aaroncampbell, fixes #17323
git-svn-id: http://svn.automattic.com/wordpress/trunk@17887 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
@@ -25,6 +25,16 @@ function wp_dashboard_setup() {
|
||||
|
||||
/* Register Widgets and Controls */
|
||||
|
||||
$response = wp_check_browser_version();
|
||||
|
||||
if ( $response['upgrade'] ) {
|
||||
add_filter( 'postbox_classes_dashboard_dashboard_browser_nag', 'dashboard_browser_nag_class' );
|
||||
if ( $response['insecure'] )
|
||||
wp_add_dashboard_widget( 'dashboard_browser_nag', __( 'You are using an insecure browser!' ), 'wp_dashboard_browser_nag' );
|
||||
else
|
||||
wp_add_dashboard_widget( 'dashboard_browser_nag', __( 'Your browser is out of date!' ), 'wp_dashboard_browser_nag' );
|
||||
}
|
||||
|
||||
// Right Now
|
||||
if ( is_blog_admin() && current_user_can('edit_posts') )
|
||||
wp_add_dashboard_widget( 'dashboard_right_now', __( 'Right Now' ), 'wp_dashboard_right_now' );
|
||||
@@ -1147,6 +1157,83 @@ function wp_dashboard_quota() {
|
||||
}
|
||||
add_action( 'activity_box_end', 'wp_dashboard_quota' );
|
||||
|
||||
// Display Browser Nag Meta Box
|
||||
function wp_dashboard_browser_nag() {
|
||||
$notice = '';
|
||||
$response = wp_check_browser_version();
|
||||
|
||||
if ( $response['insecure'] ) {
|
||||
$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'] ) );
|
||||
} else {
|
||||
$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'] ) );
|
||||
}
|
||||
|
||||
$browser_nag_class = '';
|
||||
if ( !empty( $response['img_src'] ) ) {
|
||||
$img_src = ( is_ssl() && ! empty( $response['img_src_ssl'] ) )? $response['img_src_ssl'] : $response['img_src'];
|
||||
|
||||
$notice .= '<div class="alignright browser-icon"><a href="' . esc_attr($response['update_url']) . '"><img src="' . esc_attr( $img_src ) . '" alt="" /></a></div>';
|
||||
$browser_nag_class = ' has-browser-icon';
|
||||
}
|
||||
$notice .= "<p class='browser-update-nag{$browser_nag_class}'>{$msg}</p>";
|
||||
$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/' );
|
||||
$notice .= '<p><a href="" class="dismiss">' . __( 'Dismiss' ) . '</a></p>';
|
||||
$notice .= '<div class="clear"></div>';
|
||||
|
||||
echo apply_filters( 'browse-happy-notice', $notice, $response );
|
||||
}
|
||||
|
||||
function dashboard_browser_nag_class( $classes ) {
|
||||
$response = wp_check_browser_version();
|
||||
|
||||
if ( $response['insecure'] )
|
||||
$classes[] = 'browser-insecure';
|
||||
|
||||
return $classes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the user needs a browser update
|
||||
*
|
||||
* @since 3.2
|
||||
*/
|
||||
function wp_check_browser_version() {
|
||||
$key = md5( $_SERVER['HTTP_USER_AGENT'] );
|
||||
|
||||
if ( false === ($response = get_site_transient('browsehappy_' . $key) ) ) {
|
||||
global $wp_version;
|
||||
|
||||
$options = array(
|
||||
'body' => array( 'useragent' => $_SERVER['HTTP_USER_AGENT'] ),
|
||||
'user-agent' => 'WordPress/' . $wp_version . '; ' . get_bloginfo( 'url' )
|
||||
);
|
||||
|
||||
$raw_response = wp_remote_post( 'http://api.wordpress.org/core/browse-happy/1.0/', $options );
|
||||
|
||||
if ( is_wp_error( $raw_response ) || 200 != $raw_response['response']['code'] )
|
||||
return;
|
||||
|
||||
/**
|
||||
* Response should be an array with:
|
||||
* 'name' - string- A user friendly browser name
|
||||
* 'version' - string - The most recent version of the browser
|
||||
* 'current_version' - string - The version of the browser the user is using
|
||||
* 'upgrade' - boolean - Whether the browser needs an upgrade
|
||||
* 'insecure' - boolean - Whether the browser is deemed insecure
|
||||
* 'upgrade_url' - string - The url to visit to upgrade
|
||||
* 'img_src' - string - An image representing the browser
|
||||
*/
|
||||
$response = unserialize( $raw_response['body'] );
|
||||
|
||||
if ( ! $response )
|
||||
return;
|
||||
|
||||
set_site_transient( 'browsehappy_' . $key, $response, 604800 ); // cache for 1 week
|
||||
}
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Empty function usable by plugins to output empty dashboard widget (to be populated later by JS).
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user