Plugin Directory

Changeset 3401047


Ignore:
Timestamp:
11/22/2025 05:18:46 PM (4 months ago)
Author:
eric1985
Message:

Version 0.60: Major performance and security update - Added caching system, show/hide post dates option, enhanced security, and improved WordPress 6.8 compatibility

Location:
all-posts-archive-page
Files:
3 added
4 edited

Legend:

Unmodified
Added
Removed
  • all-posts-archive-page/trunk/all-posts-archive-page.php

    r3401042 r3401047  
    44 * Plugin URI:  https://ericrosenberg.com/binge-reading-archive-page-template-for-wordpress/
    55 * 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
    710 * Author:      Eric Rosenberg
    811 * Author URI:  https://ericrosenberg.com
     
    6366        // Show/hide post dates in list.
    6467        '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',
    6572    );
    6673
     
    233240
    234241/**
     242 * Clear the archive cache.
     243 *
     244 * @return void
     245 */
     246function 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 */
     256function brap_clear_cache_on_post_change() {
     257    brap_clear_cache();
     258}
     259add_action( 'save_post', 'brap_clear_cache_on_post_change' );
     260add_action( 'delete_post', 'brap_clear_cache_on_post_change' );
     261add_action( 'wp_trash_post', 'brap_clear_cache_on_post_change' );
     262
     263/**
    235264 * Generates the month-by-month post listing using stored settings and optional category filter.
    236265 *
     
    250279    );
    251280
     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
    252305    // Fetch user settings from our table.
    253306    $add_year_header    = brap_get_setting( 'add_year_header' );
     
    279332    // Convert to date() tokens used by WP's get_the_date().
    280333    $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 );
    288334
    289335    // Build WP_Query args.
     
    385431    }
    386432
     433    // Store in cache if caching is enabled.
     434    if ( 'on' === $enable_cache && '' !== $output ) {
     435        set_transient( $cache_key, $output, $cache_duration );
     436    }
     437
    387438    return $output;
    388439}
     
    427478        $add_month_header    = isset( $_POST['add_month_header'] ) ? 'on' : 'off';
    428479        $show_post_date      = isset( $_POST['show_post_date'] ) ? 'on' : 'off';
     480        $enable_cache        = isset( $_POST['enable_cache'] ) ? 'on' : 'off';
    429481        $remove_on_uninstall = isset( $_POST['remove_db_table_on_uninstall'] ) ? 'yes' : 'no';
    430482
     
    434486        $month_format = isset( $_POST['month_format'] ) ? sanitize_text_field( wp_unslash( $_POST['month_format'] ) ) : 'MMM';
    435487        $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        }
    436496
    437497        $allowed_heading_levels = array( 'h1','h2','h3','h4','h5','h6' );
     
    472532        brap_update_setting( 'year_format', $year_format );
    473533        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 );
    474536        brap_update_setting( 'remove_db_table_on_uninstall', $remove_on_uninstall );
    475537        brap_update_setting( 'category_filter', $category_filter_slug );
     538
     539        // Clear cache when settings are saved.
     540        brap_clear_cache();
    476541
    477542        echo '<div class="updated"><p>' . esc_html__( 'Settings saved.', 'all-posts-archive-page' ) . '</p></div>';
     
    486551    $year_format           = brap_get_setting( 'year_format' );
    487552    $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' );
    488555    $remove_data           = brap_get_setting( 'remove_db_table_on_uninstall' );
    489556    $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;
    490561
    491562    // Categories list for dropdown.
     
    597668            <hr />
    598669
     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
    599693            <h2><?php esc_html_e( 'Data Removal at Uninstall', 'all-posts-archive-page' ); ?></h2>
    600694            <label for="remove_db_table_on_uninstall">
  • all-posts-archive-page/trunk/readme.txt

    r3346002 r3401047  
    44Donate link: http://narrowbridgemedia.com/
    55Requires at least: 5.0
    6 Tested up to: 6.8.2
    7 Stable tag: 0.55
     6Tested up to: 6.8
     7Requires PHP: 7.0
     8Stable tag: 0.60
    89License: GPLv2 or later
    910License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    4344- Toggle month headings on/off and choose the heading size (H1–H6)
    4445- 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
    4651
    4752== Screenshots ==
     
    5459
    5560== 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
    5674= 0.55 =
    5775* Added option to filter by category using a shortcode or plugin settings
Note: See TracChangeset for help on using the changeset viewer.