' ) && version_compare( $r['version'], ADSEC_VERSION, '<=' ) ) {
$out[] = $r;
}
}
// Pure bug-fix versions only add noise next to real news.
$news = array_values( array_filter( $out, function ( $r ) {
return array('Bug fixes.') !== array_values( (array) $r['en'] );
} ) );
return array_slice( ( $news ? $news : $out ), 0, self::MAX_UNSEEN );
}
/** "Got it" under the news. */
public static function handle_seen() {
if ( !current_user_can( 'manage_options' ) || !check_admin_referer( 'adsec_seen_release' ) ) {
wp_die( esc_html__( 'Not allowed.', 'sectivio' ) );
}
update_user_meta( get_current_user_id(), self::SEEN_META, ADSEC_VERSION );
wp_safe_redirect( admin_url( 'admin.php?page=adaptive-sections' ) );
exit;
}
/** Notes in the WordPress language: German for de_*, English otherwise. */
private static function notes_list( $release ) {
$de = 0 === strpos( (string) get_user_locale(), 'de' );
$notes = ( isset( $release['de'] ) ? ( $de ? $release['de'] : $release['en'] ) : (( !$de && !empty( $release['notes_en'] ) ? $release['notes_en'] : $release['notes'] ?? array() )) );
$out = '
';
foreach ( (array) $notes as $n ) {
$out .= '- ' . esc_html( $n ) . '
';
}
return $out . '
';
}
private static function date_of( $release ) {
return ( !empty( $release['date'] ) ? date_i18n( get_option( 'date_format' ), strtotime( $release['date'] . ' 12:00' ) ) : '' );
}
/** News under the version line – for every edition (0.49.0). */
private static function render_local_notes( array $i ) {
$unseen = self::unseen();
if ( $unseen ) {
echo '' . esc_html__( 'New since your last update', 'sectivio' ) . '
';
foreach ( $unseen as $r ) {
echo '';
/* translators: %s: version number. */
printf( esc_html__( 'Version %s', 'sectivio' ), esc_html( $r['version'] ) );
echo ' ' . esc_html( self::date_of( $r ) ) . '
';
echo wp_kses_post( self::notes_list( $r ) );
}
echo '';
return;
}
foreach ( self::local_releases() as $r ) {
if ( version_compare( $r['version'], $i['current'], '==' ) ) {
echo '';
/* translators: %s: version number. */
printf( esc_html__( 'What’s new in version %s?', 'sectivio' ), esc_html( $i['current'] ) );
echo '
' . wp_kses_post( self::notes_list( $r ) ) . ' ';
return;
}
}
}
/** Alles, was die Karte braucht. */
public static function info() {
$current = ADSEC_VERSION;
$basename = plugin_basename( ADSEC_PLUGIN_FILE );
// Was WordPress selbst an Updates kennt (Freemius bzw. wordpress.org).
$wp_new = '';
$updates = get_site_transient( 'update_plugins' );
if ( is_object( $updates ) && isset( $updates->response[$basename]->new_version ) ) {
$wp_new = (string) $updates->response[$basename]->new_version;
}
$info = array(
'current' => $current,
'latest' => $wp_new,
'has_update' => '' !== $wp_new && version_compare( $wp_new, $current, '>' ),
'update_url' => ( '' !== $wp_new && version_compare( $wp_new, $current, '>' ) && current_user_can( 'update_plugins' ) ? wp_nonce_url( self_admin_url( 'update.php?action=upgrade-plugin&plugin=' . rawurlencode( $basename ) ), 'upgrade-plugin_' . $basename ) : '' ),
);
return $info;
}
/** Karte im Dashboard. */
public static function render() {
$i = self::info();
$note = ( $i['update_url'] ? '' : __( 'As soon as WordPress offers the update, you will find it under “Plugins”.', 'sectivio' ) );
?>