Skip to content

Instantly share code, notes, and snippets.

@gschoppe
Created December 6, 2018 16:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gschoppe/714f4bba6d5026ee5a417b404232e139 to your computer and use it in GitHub Desktop.
Save gschoppe/714f4bba6d5026ee5a417b404232e139 to your computer and use it in GitHub Desktop.
WordPress Update Watch
<?php
if( !empty($_GET['request']) ) {
$current_version = "";
$url = "https://api.wordpress.org/core/version-check/1.7/";
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => $url
));
$result = curl_exec($curl);
if( $result ) {
$array = json_decode($result, true);
if( isset( $array['offers']) && is_array( $array['offers'] ) ) {
foreach( $array['offers'] as $offer ) {
if( isset($offer['response']) && $offer['response'] == 'upgrade' ) {
if( isset( $offer['current'] ) ) {
$current_version = $offer['current'];
}
}
}
}
}
echo $current_version;
die();
}
?>
<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
<title>WordPress release Monitor</title>
</head>
<body>
<h1>The Current WordPress version is <span class="current-wp-ver">loading</span></h1>
<!-- Optional JavaScript -->
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script src="https://code.jquery.com/jquery-3.3.1.min.js" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>
<style>
body {
background-color: #080;
}
body.it-happened {
background-color: #800;
}
h1 {
position: absolute;
top: 50%;
left: 50%;
-webkit-transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
color: #fff;
text-align: center;
}
h1 .current-wp-ver {
display: block;
font-size: 6em;
}
</style>
<script>
jQuery(function($) {
var known_version = false;
function check_version() {
jQuery.get( location.href, { 'request': 1 }, function(response) {
if( response ) {
if(!known_version) {
known_version = response;
} else {
if( response != known_version ) {
$(body).addClass('it-happened');
}
}
$('.current-wp-ver').text(response);
}
setTimeout(function() {
check_version();
}, 5000);
} );
}
check_version();
});
</script>
</body>
</html>
@gschoppe
Copy link
Author

gschoppe commented Dec 6, 2018

Please note: this code was not built with any sort of coding standards or rate limiting in mind (I had about 10 minutes free while switching tasks), and it includes bootstrap 4 for no reason whatsoever.

enjoy

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment