Instantly share code, notes, and snippets.

Embed
What would you like to do?
<?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