Skip to content

Instantly share code, notes, and snippets.

@JulioPotier
Created April 25, 2018 14:42
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 JulioPotier/480bc095363f69592d6e086a62085ac1 to your computer and use it in GitHub Desktop.
Save JulioPotier/480bc095363f69592d6e086a62085ac1 to your computer and use it in GitHub Desktop.
<?php
if ( ! isset( $remote_version ) ) {
return;
}
$body = get_transient( 'secupress_updates_message' );
if ( ! isset( $body[ $remote_version ] ) ) {
$url = 'https://plugins.svn.wordpress.org/secupress/trunk/readme.txt';
$response = wp_remote_get( $url );
if ( is_wp_error( $response ) || 200 !== wp_remote_retrieve_response_code( $response ) ) {
return;
}
$body = wp_remote_retrieve_body( $response );
set_transient( 'secupress_updates_message' , array( $remote_version => $body ) );
} else {
$body = $body[ $remote_version ];
}
// Find the Notes for this version.
$regexp = '#== Upgrade Notice ==.*= ' . preg_quote( $remote_version ) . ' =(.*)=#Us';
if ( preg_match( $regexp, $body, $matches ) ) {
$notes = (array) preg_split( '#[\r\n]+#', trim( $matches[1] ) );
$date = str_replace( '* ', '', wp_kses_post( array_shift( $notes ) ) );
echo '<div>';
/** Translators: %1$s is the version number, %2$s is a date. */
echo '<strong>' . sprintf( __( 'Please read these special notes for this update, version %1$s - %2$s', 'secupress' ), $remote_version, $date ) . '</strong>';
echo '<ul style="list-style:square;margin-left:20px;line-height:1em">';
foreach ( $notes as $note ) {
echo '<li>' . str_replace( '* ', '', wp_kses_post( $note ) ) . '</li>';
}
echo '</ul>';
echo '</div>';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment