Changeset 3401047
- Timestamp:
- 11/22/2025 05:18:46 PM (4 months ago)
- Location:
- all-posts-archive-page
- Files:
-
- 3 added
- 4 edited
-
assets/banner-1544x500.png (modified) (previous)
-
assets/banner-772x250.png (modified) (previous)
-
tags/0.60 (added)
-
tags/0.60/all-posts-archive-page.php (added)
-
tags/0.60/readme.txt (added)
-
trunk/all-posts-archive-page.php (modified) (11 diffs)
-
trunk/readme.txt (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
all-posts-archive-page/trunk/all-posts-archive-page.php
r3401042 r3401047 4 4 * Plugin URI: https://ericrosenberg.com/binge-reading-archive-page-template-for-wordpress/ 5 5 * Description: Display all posts month-by-month for binge reading. Uses your theme's styling by default. Supports optional category filtering and flexible month formats. 6 * Version: 0.56 6 * Version: 0.60 7 * Requires at least: 5.0 8 * Requires PHP: 7.0 9 * Tested up to: 6.8 7 10 * Author: Eric Rosenberg 8 11 * Author URI: https://ericrosenberg.com … … 63 66 // Show/hide post dates in list. 64 67 'show_post_date' => 'on', 68 // Enable transient caching for performance. 69 'enable_cache' => 'on', 70 // Cache duration in seconds (default 12 hours). 71 'cache_duration' => '43200', 65 72 ); 66 73 … … 233 240 234 241 /** 242 * Clear the archive cache. 243 * 244 * @return void 245 */ 246 function brap_clear_cache() { 247 global $wpdb; 248 $wpdb->query( "DELETE FROM {$wpdb->options} WHERE option_name LIKE '_transient_brap_archive_%' OR option_name LIKE '_transient_timeout_brap_archive_%'" ); 249 } 250 251 /** 252 * Clear cache when a post is published, updated, or deleted. 253 * 254 * @return void 255 */ 256 function brap_clear_cache_on_post_change() { 257 brap_clear_cache(); 258 } 259 add_action( 'save_post', 'brap_clear_cache_on_post_change' ); 260 add_action( 'delete_post', 'brap_clear_cache_on_post_change' ); 261 add_action( 'wp_trash_post', 'brap_clear_cache_on_post_change' ); 262 263 /** 235 264 * Generates the month-by-month post listing using stored settings and optional category filter. 236 265 * … … 250 279 ); 251 280 281 // Determine effective category filter (slug) with validation first for cache key. 282 $requested_slug = ''; 283 if ( isset( $atts['category'] ) ) { 284 $requested_slug = is_string( $atts['category'] ) ? $atts['category'] : ''; 285 } 286 $category_slug = brap_get_effective_category_slug( $requested_slug ); 287 288 // Check if caching is enabled. 289 $enable_cache = brap_get_setting( 'enable_cache' ); 290 $cache_duration = brap_get_setting( 'cache_duration' ); 291 $enable_cache = $enable_cache ? $enable_cache : 'on'; 292 $cache_duration = $cache_duration ? absint( $cache_duration ) : 43200; 293 294 // Generate unique cache key based on settings and category. 295 $cache_key = 'brap_archive_' . md5( serialize( $atts ) . get_locale() ); 296 297 // Try to get cached output if caching is enabled. 298 if ( 'on' === $enable_cache ) { 299 $cached_output = get_transient( $cache_key ); 300 if ( false !== $cached_output ) { 301 return $cached_output; 302 } 303 } 304 252 305 // Fetch user settings from our table. 253 306 $add_year_header = brap_get_setting( 'add_year_header' ); … … 279 332 // Convert to date() tokens used by WP's get_the_date(). 280 333 $tokens = brap_get_date_tokens( $month_format, $year_format ); 281 282 // Determine effective category filter (slug) with validation.283 $requested_slug = '';284 if ( isset( $atts['category'] ) ) {285 $requested_slug = is_string( $atts['category'] ) ? $atts['category'] : '';286 }287 $category_slug = brap_get_effective_category_slug( $requested_slug );288 334 289 335 // Build WP_Query args. … … 385 431 } 386 432 433 // Store in cache if caching is enabled. 434 if ( 'on' === $enable_cache && '' !== $output ) { 435 set_transient( $cache_key, $output, $cache_duration ); 436 } 437 387 438 return $output; 388 439 } … … 427 478 $add_month_header = isset( $_POST['add_month_header'] ) ? 'on' : 'off'; 428 479 $show_post_date = isset( $_POST['show_post_date'] ) ? 'on' : 'off'; 480 $enable_cache = isset( $_POST['enable_cache'] ) ? 'on' : 'off'; 429 481 $remove_on_uninstall = isset( $_POST['remove_db_table_on_uninstall'] ) ? 'yes' : 'no'; 430 482 … … 434 486 $month_format = isset( $_POST['month_format'] ) ? sanitize_text_field( wp_unslash( $_POST['month_format'] ) ) : 'MMM'; 435 487 $year_format = isset( $_POST['year_format'] ) ? sanitize_text_field( wp_unslash( $_POST['year_format'] ) ) : 'YYYY'; 488 489 $cache_duration = isset( $_POST['cache_duration'] ) ? absint( wp_unslash( $_POST['cache_duration'] ) ) : 43200; 490 if ( $cache_duration < 300 ) { 491 $cache_duration = 300; // Minimum 5 minutes. 492 } 493 if ( $cache_duration > 604800 ) { 494 $cache_duration = 604800; // Maximum 7 days. 495 } 436 496 437 497 $allowed_heading_levels = array( 'h1','h2','h3','h4','h5','h6' ); … … 472 532 brap_update_setting( 'year_format', $year_format ); 473 533 brap_update_setting( 'show_post_date', $show_post_date ); 534 brap_update_setting( 'enable_cache', $enable_cache ); 535 brap_update_setting( 'cache_duration', (string) $cache_duration ); 474 536 brap_update_setting( 'remove_db_table_on_uninstall', $remove_on_uninstall ); 475 537 brap_update_setting( 'category_filter', $category_filter_slug ); 538 539 // Clear cache when settings are saved. 540 brap_clear_cache(); 476 541 477 542 echo '<div class="updated"><p>' . esc_html__( 'Settings saved.', 'all-posts-archive-page' ) . '</p></div>'; … … 486 551 $year_format = brap_get_setting( 'year_format' ); 487 552 $show_post_date = brap_get_setting( 'show_post_date' ); 553 $enable_cache = brap_get_setting( 'enable_cache' ); 554 $cache_duration = brap_get_setting( 'cache_duration' ); 488 555 $remove_data = brap_get_setting( 'remove_db_table_on_uninstall' ); 489 556 $category_filter_value = brap_get_setting( 'category_filter' ); 557 558 // Set defaults if not set. 559 $enable_cache = $enable_cache ? $enable_cache : 'on'; 560 $cache_duration = $cache_duration ? absint( $cache_duration ) : 43200; 490 561 491 562 // Categories list for dropdown. … … 597 668 <hr /> 598 669 670 <h2><?php esc_html_e( 'Performance & Caching', 'all-posts-archive-page' ); ?></h2> 671 <label for="enable_cache"> 672 <input type="checkbox" name="enable_cache" id="enable_cache" <?php checked( $enable_cache, 'on' ); ?> /> 673 <?php esc_html_e( 'Enable output caching for faster page loads?', 'all-posts-archive-page' ); ?> 674 </label> 675 <p class="description"><?php esc_html_e( 'When enabled, the archive output is cached to improve performance. Cache is automatically cleared when posts are published, updated, or deleted.', 'all-posts-archive-page' ); ?></p> 676 677 <p> 678 <label for="cache_duration"> 679 <?php esc_html_e( 'Cache Duration (seconds)', 'all-posts-archive-page' ); ?> 680 </label><br /> 681 <input type="number" name="cache_duration" id="cache_duration" value="<?php echo esc_attr( $cache_duration ); ?>" min="300" max="604800" step="300" /> 682 <br /> 683 <span class="description"> 684 <?php 685 /* translators: %s: number of hours */ 686 echo esc_html( sprintf( __( 'Current setting: %s hours. Minimum: 5 minutes (300), Maximum: 7 days (604800).', 'all-posts-archive-page' ), number_format( $cache_duration / 3600, 1 ) ) ); 687 ?> 688 </span> 689 </p> 690 691 <hr /> 692 599 693 <h2><?php esc_html_e( 'Data Removal at Uninstall', 'all-posts-archive-page' ); ?></h2> 600 694 <label for="remove_db_table_on_uninstall"> -
all-posts-archive-page/trunk/readme.txt
r3346002 r3401047 4 4 Donate link: http://narrowbridgemedia.com/ 5 5 Requires at least: 5.0 6 Tested up to: 6.8.2 7 Stable tag: 0.55 6 Tested up to: 6.8 7 Requires PHP: 7.0 8 Stable tag: 0.60 8 9 License: GPLv2 or later 9 10 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 43 44 - Toggle month headings on/off and choose the heading size (H1–H6) 44 45 - Pick how months and years are formatted (e.g., `Jan 2023` or `01 23`) 45 - Decide whether to remove the plugin’s database table when uninstalling 46 - Show or hide post dates in the listing 47 - Enable performance caching for faster page loads 48 - Configure cache duration 49 - Filter posts by category 50 - Decide whether to remove the plugin's database table when uninstalling 46 51 47 52 == Screenshots == … … 54 59 55 60 == Changelog == 61 = 0.60 = 62 * Added performance caching system with configurable duration for faster page loads 63 * Cache automatically clears when posts are published, updated, or deleted 64 * Added option to show or hide post dates in the archive list 65 * Enhanced security with improved input validation and sanitization 66 * Added WordPress version requirements (5.0+) and PHP version requirements (7.0+) 67 * Optimized database queries for better performance 68 * Improved compatibility with modern WordPress versions (tested up to 6.8) 69 * Code quality improvements and WordPress coding standards compliance 70 71 = 0.56 = 72 * Added option to show or hide post dates in the archive list 73 56 74 = 0.55 = 57 75 * Added option to filter by category using a shortcode or plugin settings
Note: See TracChangeset
for help on using the changeset viewer.