Skip to content

Commit e7bedbb

Browse files
kraftbjmatticbot
authored andcommitted
feat: check supercache_last_cached option for array type (#46814)
Co-authored-by: Илья Салигжанов <saligzhanov.i@spectrumdata.ru> Co-authored-by: Brandon Kraft <public@brandonkraft.com> Committed via a GitHub action: https://github.com/Automattic/jetpack/actions/runs/24097626420 Upstream-Ref: Automattic/jetpack@6c91920
1 parent 453db4b commit e7bedbb

2 files changed

Lines changed: 15 additions & 4 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ This is an alpha version! The changes listed here are not final.
2222

2323
### Fixed
2424
- Ensure proper flags are used with `json_encode()`.
25+
- Fix a PHP warning when the newest cached pages list is unavailable.
2526
- Fix TS errors detected by tsgo.
2627
- Fix `str_starts_with()` PHP 8.1+ deprecation when `$wp_cache_home_path` is null in `get_current_url_supercache_dir()`.
2728

wp-cache.php

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1376,16 +1376,26 @@ function toggleLayer( whichLayer ) {
13761376
}
13771377
?>
13781378
<p><?php printf( __( 'Cached pages since %1$s : <strong>%2$s</strong>', 'wp-super-cache' ), date( 'M j, Y', $start_date ), number_format( get_option( 'wpsupercache_count' ) ) ); ?></p>
1379+
<?php
1380+
$supercache_last_cached_option = get_option( 'supercache_last_cached' );
1381+
if ( is_array( $supercache_last_cached_option ) ) {
1382+
?>
13791383
<p><?php _e( 'Newest Cached Pages:', 'wp-super-cache' ); ?><ol>
13801384
<?php
1381-
foreach ( array_reverse( (array) get_option( 'supercache_last_cached' ) ) as $url ) {
1382-
$since = time() - strtotime( $url['date'] );
1383-
echo "<li><a title='" . sprintf( esc_html__( 'Cached %s seconds ago', 'wp-super-cache' ), (int) $since ) . "' href='" . site_url( $url['url'] ) . "'>" . substr( $url['url'], 0, 20 ) . "</a></li>\n";
1385+
foreach ( array_reverse( $supercache_last_cached_option ) as $url ) {
1386+
if ( ! is_array( $url ) ) {
1387+
continue;
1388+
}
1389+
$since = time() - strtotime( $url['date'] ?? '' );
1390+
// translators: %s is the number of seconds since the page was cached.
1391+
echo "<li><a title='" . sprintf( esc_html__( 'Cached %s seconds ago', 'wp-super-cache' ), (int) $since ) . "' href='" . esc_url( site_url( $url['url'] ?? '' ) ) . "'>" . esc_html( substr( $url['url'] ?? '', 0, 20 ) ) . "</a></li>\n";
13841392
}
13851393
?>
13861394
</ol>
13871395
<small><?php esc_html_e( '(may not always be accurate on busy sites)', 'wp-super-cache' ); ?></small>
1388-
</p><?php
1396+
</p>
1397+
<?php
1398+
}
13891399
} elseif ( false == get_option( 'wpsupercache_start' ) ) {
13901400
update_option( 'wpsupercache_start', time() );
13911401
update_option( 'wpsupercache_count', 0 );

0 commit comments

Comments
 (0)