Plugin Directory

Changeset 3094130


Ignore:
Timestamp:
05/28/2024 07:40:52 PM (22 months ago)
Author:
getpantheon
Message:

Update to version 2.0.0 from GitHub

Location:
pantheon-advanced-page-cache
Files:
2 added
8 edited
1 copied

Legend:

Unmodified
Added
Removed
  • pantheon-advanced-page-cache/tags/2.0.0/assets/css/styles.css

    r3092217 r3094130  
    1 .pantheon-page-cache hr{display:none}.pantheon-page-cache tr.cache-default-max-age{display:block;padding:10px;background:#fff;color:#1e1e1e;box-shadow:0 0 10px 5px rgba(0,0,0,.1)}.pantheon-page-cache tr.cache-default-max-age td{padding:0}.pantheon-page-cache tr.cache-default-max-age .pantheon-cache-default-max-age{padding:0 10px 10px 0}.pantheon-page-cache tr.cache-default-max-age .pantheon-cache-default-max-age h3{margin-top:.5em}.pantheon-page-cache tr.cache-default-max-age .pantheon-cache-default-max-age i{margin-right:10px;line-height:1em}.pantheon-page-cache tr.cache-default-max-age .pantheon-cache-default-max-age-info-bar{background:#1d7afc;color:#fff;padding:10px 0 10px 10px;text-align:left;display:block;width:100%;margin-bottom:1em}.pantheon-page-cache tr.cache-default-max-age .pantheon-cache-default-max-age-info-bar a{color:#fff;text-decoration:underline}.pantheon-page-cache tr.cache-default-max-age .pantheon-cache-default-max-age-info-bar a:active,.pantheon-page-cache tr.cache-default-max-age .pantheon-cache-default-max-age-info-bar a:hover{color:#fff;text-decoration:none}.pantheon-page-cache tr.cache-default-max-age .pantheon-cache-default-max-age select{background-color:#fff;color:#1e1e1e;border:1px solid #757575;border-radius:0}.pantheon-page-cache tr.cache-default-max-age .pantheon-cache-default-max-age-description{color:#757575;margin:10px 0 0}
     1.pantheon-page-cache hr {
     2  display: none;
     3}
     4.pantheon-page-cache tr.cache-default-max-age {
     5  display: block;
     6  padding: 10px;
     7  background: #ffffff;
     8  color: #1e1e1e;
     9  box-shadow: 0 0 10px 5px rgba(0, 0, 0, 0.1);
     10}
     11.pantheon-page-cache tr.cache-default-max-age td {
     12  padding: 0;
     13}
     14.pantheon-page-cache tr.cache-default-max-age .pantheon-cache-default-max-age {
     15  padding: 0 10px 10px 0;
     16}
     17.pantheon-page-cache tr.cache-default-max-age .pantheon-cache-default-max-age h3 {
     18  margin-top: 0.5em;
     19}
     20.pantheon-page-cache tr.cache-default-max-age .pantheon-cache-default-max-age i {
     21  margin-right: 10px;
     22  line-height: 1em;
     23}
     24.pantheon-page-cache tr.cache-default-max-age .pantheon-cache-default-max-age-info-bar {
     25  background: #1d7afc;
     26  color: #ffffff;
     27  padding: 10px 0 10px 10px;
     28  text-align: left;
     29  display: block;
     30  width: 100%;
     31  margin-bottom: 1em;
     32}
     33.pantheon-page-cache tr.cache-default-max-age .pantheon-cache-default-max-age-info-bar a {
     34  color: #ffffff;
     35  text-decoration: underline;
     36}
     37.pantheon-page-cache tr.cache-default-max-age .pantheon-cache-default-max-age-info-bar a:hover, .pantheon-page-cache tr.cache-default-max-age .pantheon-cache-default-max-age-info-bar a:active {
     38  color: #ffffff;
     39  text-decoration: none;
     40}
     41.pantheon-page-cache tr.cache-default-max-age .pantheon-cache-default-max-age select {
     42  background-color: #ffffff;
     43  color: #1e1e1e;
     44  border: 1px solid #757575;
     45  border-radius: 0;
     46}
     47.pantheon-page-cache tr.cache-default-max-age .pantheon-cache-default-max-age-description {
     48  color: #757575;
     49  margin: 10px 0 0 0;
     50}
  • pantheon-advanced-page-cache/tags/2.0.0/inc/admin-interface.php

    r3091792 r3094130  
    33 * Controller for the admin interface that builds on top of the Pantheon MU plugin.
    44 *
    5  * @since 2.0.0-dev
     5 * @since 2.0.0
    66 * @package Pantheon_Advanced_Page_Cache
    77 */
     
    1212 * Kick off the important bits.
    1313 *
    14  * @since 2.0.0-dev
     14 * @since 2.0.0
    1515 * @return void
    1616 */
     
    4343    add_filter( 'pantheon_cache_max_age_input', __NAMESPACE__ . '\\update_default_ttl_input' );
    4444    add_filter( 'pantheon_cache_max_age_input_allowed_html', __NAMESPACE__ . '\\max_age_input_allowed_html' );
     45    add_filter( 'nonce_life', __NAMESPACE__ . '\\filter_nonce_cache_lifetime' );
    4546}
    4647
     
    4849 * Enqueue admin assets.
    4950 *
    50  * @since 2.0.0-dev
     51 * @since 2.0.0
    5152 * @return void
    5253 */
     
    6061    // If WP_DEBUG is true, append a timestamp to the end of the path so we get a fresh copy of the css.
    6162    $debug = defined( 'WP_DEBUG' ) && WP_DEBUG ? '-' . time() : '';
    62     wp_enqueue_style( 'papc-admin', plugin_dir_url( __DIR__ ) . 'assets/css/styles.css', [], '2.0.0' . $debug );
     63    // Use minified css unless SCRIPT_DEBUG is true.
     64    $min = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
     65    wp_enqueue_style( 'papc-admin', plugin_dir_url( __DIR__ ) . "assets/css/styles$min.css", [], '2.0.0' . $debug );
    6366}
    6467
     
    6669 * Add a header to the max-age setting field.
    6770 *
    68  * @since 2.0.0-dev
     71 * @since 2.0.0
    6972 * @return string
    7073 */
     
    8790 * Add a description to the max-age setting field.
    8891 *
    89  * @since 2.0.0-dev
     92 * @since 2.0.0
    9093 * @return string
    9194 */
     
    122125 * @param int $default_input The default TTL input field from the mu-plugin.
    123126 *
    124  * @since 2.0.0-dev
     127 * @since 2.0.0
    125128 * @return int
    126129 */
     
    160163 * Filter the allowed HTML for the max-age input field.
    161164 *
    162  * @since 2.0.0-dev
     165 * @since 2.0.0
    163166 * @param array $allowed_html The allowed HTML.
    164167 * @return array
     
    173176 * Get the default max age options. Default values are 1 week, 1 month, 1 year.
    174177 *
    175  * @since 2.0.0-dev
     178 * @since 2.0.0
    176179 * @return array
    177180 */
     
    195198 * Display an admin notice if the Pantheon MU plugin was not found.
    196199 *
    197  * @since 2.0.0-dev
     200 * @since 2.0.0
    198201 * @return void
    199202 */
     
    222225 * Display an admin notice if the Pantheon MU plugin is out of date.
    223226 *
    224  * @since 2.0.0-dev
     227 * @since 2.0.0
    225228 * @return void
    226229 */
     
    260263 * Display an admin notice if the max-age is less than a week but not equal to 600 seconds.
    261264 *
    262  * @since 2.0.0-dev
     265 * @since 2.0.0
    263266 * @return void
    264267 */
     
    330333 * If the site existed prior to 1.4.0 of the mu-plugin, the default value is 600 seconds. Otherwise, the default value is 1 week.
    331334 *
    332  * @since 2.0.0-dev
     335 * @since 2.0.0
    333336 * @return int
    334337 */
     
    349352 * @param array $tests The Site Health tests.
    350353 *
    351  * @since 2.0.0-dev
     354 * @since 2.0.0
    352355 * @return array
    353356 */
     
    366369 * @param bool $recommended Whether to get the recommended max-age.
    367370 *
    368  * @since 2.0.0-dev
     371 * @since 2.0.0
    369372 * @return string
    370373 */
     
    380383 * Get the default max-age.
    381384 *
    382  * @since 2.0.0-dev
     385 * @since 2.0.0
    383386 * @return int
    384387 */
     
    390393 * Compare the current max-age to the default max-age.
    391394 *
    392  * @since 2.0.0-dev
     395 * @since 2.0.0
    393396 * @return int A ranked value from 0 to 10 where 0 is optimal (equal to or greater than the recommended max age) and 10 is very bad.
    394397 */
     
    419422 * The GCDN cache max-age Site Health test.
    420423 *
    421  * @since 2.0.0-dev
     424 * @since 2.0.0
    422425 * @return array
    423426 */
     
    485488 * Clear the max-age compare cache when the max-age is updated.
    486489 *
    487  * @since 2.0.0-dev
     490 * @since 2.0.0
    488491 * @return void
    489492 */
     
    495498 * Set the default_ttl from the mu-plugin to WEEK_IN_SECONDS if it was saved as 600 seconds.
    496499 *
    497  * @since 2.0.0-dev
     500 * @since 2.0.0
    498501 * @return bool
    499502 */
     
    530533 * Display an admin notice if the max-age was updated.
    531534 *
    532  * @since 2.0.0-dev
     535 * @since 2.0.0
    533536 * @return void
    534537 */
     
    584587    update_user_meta( $current_user_id, 'pantheon_max_age_updated_notice', true );
    585588}
     589
     590/**
     591 * Filter the nonce cache lifetime.
     592 *
     593 * @param int $lifetime The lifetime of the nonce.
     594 *
     595 * @since 2.0.0
     596 * @return int
     597 */
     598function filter_nonce_cache_lifetime( $lifetime ) {
     599    // Bail early if we're in the admin.
     600    if ( is_admin() ) {
     601        return $lifetime;
     602    }
     603
     604    // Filter the cache default max age to less than the nonce lifetime when creating nonces on the front-end. This prevents the cache from keeping the nonce around longer than it should.
     605    add_filter( 'pantheon_cache_default_max_age', function () use ( $lifetime ) {
     606        return $lifetime - HOUR_IN_SECONDS;
     607    } );
     608
     609    return $lifetime;
     610}
  • pantheon-advanced-page-cache/tags/2.0.0/pantheon-advanced-page-cache.php

    r3092255 r3094130  
    11<?php
    22/**
    3  * Plugin Name:     Pantheon Advanced Page Cache
    4  * Plugin URI:      https://wordpress.org/plugins/pantheon-advanced-page-cache/
    5  * Description:     Automatically clear related pages from Pantheon's Edge when you update content. High TTL. Fresh content. Visitors never wait.
    6  * Author:          Pantheon
    7  * Author URI:      https://pantheon.io
    8  * Text Domain:     pantheon-advanced-page-cache
    9  * Domain Path:     /languages
    10  * Version:         1.5.0
     3 * Plugin Name: Pantheon Advanced Page Cache
     4 * Plugin URI: https://wordpress.org/plugins/pantheon-advanced-page-cache/
     5 * Description: Automatically clear related pages from Pantheon's Edge when you update content. High TTL. Fresh content. Visitors never wait.
     6 * Author: Pantheon
     7 * Author URI: https://pantheon.io
     8 * Text Domain: pantheon-advanced-page-cache
     9 * Domain Path: /languages
     10 * Version: 2.0.0
     11 * Requires at least: 6.4
     12 * Tested up to: 6.5.3
    1113 *
    1214 * @package         Pantheon_Advanced_Page_Cache
     
    102104
    103105/**
     106 * Bootstrapper for namespaced files that aren't classes.
     107 *
     108 * Expects that a bootstrap() function exists in the namespaced file.
     109 *
     110 * @since 2.0.0
     111 * @return void
     112 */
     113function pantheon_bootstrap_namespaces() {
     114    $namespaced_files = [
     115        '\\Pantheon_Advanced_Page_Cache\\Admin_Interface' => __DIR__ . '/inc/admin-interface.php',
     116    ];
     117
     118    foreach ( $namespaced_files as $namespace => $file ) {
     119        if ( file_exists( $file ) ) {
     120            require $file;
     121            call_user_func( $namespace . '\\bootstrap' );
     122        } else {
     123            wp_die( esc_html( "Could not find $file" ), 'Pantheon Advanced Page Cache error' );
     124
     125        }
     126    }
     127}
     128
     129/**
    104130 * Registers the class autoloader.
    105131 */
     
    122148    }
    123149);
     150
     151/**
     152 * Init namespaced files.
     153 */
     154add_action( 'plugins_loaded', 'pantheon_bootstrap_namespaces' );
    124155
    125156/**
  • pantheon-advanced-page-cache/tags/2.0.0/readme.txt

    r3092255 r3094130  
    22Contributors: getpantheon, danielbachhuber, kporras07, jspellman, jazzs3quence, ryanshoover, rwagner00, pwtyler
    33Tags: pantheon, cdn, cache
    4 Requires at least: 4.7
    5 Tested up to: 6.4.3
    6 Stable tag: 1.5.0
     4Requires at least: 6.4
     5Tested up to: 6.5.3
     6Stable tag: 2.0.0
    77License: GPLv2 or later
    88License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    151151This will prevent the cache from being purged if the given post type is updated.
    152152
     153= Setting the Cache Max Age with a filter =
     154
     155The cache max age setting is controlled by the [Pantheon Page Cache](https://docs.pantheon.io/guides/wordpress-configurations/wordpress-cache-plugin) admin page. As of 2.0.0, there are three cache age options by default — 1 week, 1 month, 1 year. Pantheon Advanced Page Cache automatically purges the cache of updated and related posts and pages, but you might want to override the cache max age value and set it programmatically. In this case, you can use the `pantheon_cache_default_max_age` filter added in [Pantheon MU plugin 1.4.0+](https://docs.pantheon.io/guides/wordpress-configurations/wordpress-cache-plugin#override-the-default-max-age). For example:
     156
     157    add_filter( 'pantheon_cache_default_max_age', function() {
     158        return 10 * DAY_IN_SECONDS;
     159    } );
     160
     161When the cache max age is filtered in this way, the admin option is disabled and a notice is displayed.
     162
    153163== WP-CLI Commands ==
    154164
     
    322332    add_filter('pantheon_should_add_terms', 'custom_should_add_terms', 10, 2);
    323333
     334== Other Filters ==
     335
     336= `pantheon_apc_disable_admin_notices` =
     337Since 2.0.0, Pantheon Advanced Page Cache displays a number of admin notices about your current cache max age value. You can disable these notices with the `pantheon_apc_disable_admin_notices` filter.
     338
     339    add_filter( 'pantheon_apc_disable_admin_notices', '__return_true' );
     340
     341Alternately, the function callback is passed into the `pantheon_apc_disable_admin_notices` filter, allowing you to specify precisely _which_ notice to disable, for example:
     342
     343    add_filter( 'pantheon_apc_disable_admin_notices', function( $disable_notices, $callback ) {
     344        if ( $callback === '\\Pantheon_Advanced_Page_Cache\\Admin_Interface\\admin_notice_maybe_recommend_higher_max_age' ) {
     345            return true;
     346        }
     347        return $disable_notices;
     348    }, 10, 2 );
     349
     350The above example would disable _only_ the admin notice recommending a higher cache max age.
     351
    324352== Plugin Integrations ==
    325353
     
    333361
    334362== Changelog ==
     363= 2.0.0 (28 May 2024) =
     364* Adds new admin alerts and Site Health tests about default cache max age settings and recommendations [[#268](https://github.com/pantheon-systems/pantheon-advanced-page-cache/pull/268), [#271](https://github.com/pantheon-systems/pantheon-advanced-page-cache/pull/271)]. The default Pantheon GCDN cache max age value has been updated to 1 week in the [Pantheon MU plugin](https://github.com/pantheon-systems/pantheon-mu-plugin). For more information, see the [release note](https://docs.pantheon.io/release-notes/2024/04/pantheon-mu-plugin-1-4-0-update).
     365* Updated UI in Pantheon Page Cache admin page when used in a Pantheon environment (with the Pantheon MU plugin). [[#272](https://github.com/pantheon-systems/pantheon-advanced-page-cache/pull/272)]
     366* Automatically updates the cache max age to the recommended value (1 week) if it was saved at the old default value (600 seconds). [[#269](https://github.com/pantheon-systems/pantheon-advanced-page-cache/pull/269)]
     367* Adds a hook into the `nonce_life` filter when nonces are created on the front-end to set the `pantheon_cache_default_max_age` to less than the nonce lifetime to avoid nonces expiring before the cache does. [[#282](https://github.com/pantheon-systems/pantheon-advanced-page-cache/pull/282)] props [@ryanshoover](https://profiles.wordpress.org/ryanshoover/)
     368
    335369= 1.5.0 (11 March 2024) =
    336370* Adds filter `pantheon_purge_post_type_ignored` to allow an array of post types to ignore before purging cache [[#258](https://github.com/pantheon-systems/pantheon-advanced-page-cache/pull/258)]
     
    410444
    411445== Upgrade Notice ==
    412 
    413 = Latest =
     446= 2.0.0 (28 May 2024) =
     447This release requires a minimum WordPress version of 6.4.0. It uses Site Health checks and the `wp_admin_notices` function to alert users to the new cache max-age default settings and recommendations. The plugin will still function with earlier versions, but you will not get the benefit of the alerts and Site Health checks.
     448
     449This version also automatically updates the cache max age (set in the [Pantheon Page Cache settings](https://docs.pantheon.io/guides/wordpress-configurations/wordpress-cache-plugin)) to the recommended value (1 week) if it was saved at the old default value (600 seconds). If the cache max age was set to any other value (or not set at all), it will not be changed. A one-time notice will be displayed in the admin interface to inform administrators of this change.
     450
     451= 1.3.0 =
    414452Note that the Pantheon Advanced Page Cache 1.3.0 release now prefixes keys on a WordPress Multisite (WPMS) with the blog ID. For users who already have this plugin installed on a WPMS, they will need to click the Clear Cache button on the settings page to generate the prefixed keys.
  • pantheon-advanced-page-cache/trunk/assets/css/styles.css

    r3092217 r3094130  
    1 .pantheon-page-cache hr{display:none}.pantheon-page-cache tr.cache-default-max-age{display:block;padding:10px;background:#fff;color:#1e1e1e;box-shadow:0 0 10px 5px rgba(0,0,0,.1)}.pantheon-page-cache tr.cache-default-max-age td{padding:0}.pantheon-page-cache tr.cache-default-max-age .pantheon-cache-default-max-age{padding:0 10px 10px 0}.pantheon-page-cache tr.cache-default-max-age .pantheon-cache-default-max-age h3{margin-top:.5em}.pantheon-page-cache tr.cache-default-max-age .pantheon-cache-default-max-age i{margin-right:10px;line-height:1em}.pantheon-page-cache tr.cache-default-max-age .pantheon-cache-default-max-age-info-bar{background:#1d7afc;color:#fff;padding:10px 0 10px 10px;text-align:left;display:block;width:100%;margin-bottom:1em}.pantheon-page-cache tr.cache-default-max-age .pantheon-cache-default-max-age-info-bar a{color:#fff;text-decoration:underline}.pantheon-page-cache tr.cache-default-max-age .pantheon-cache-default-max-age-info-bar a:active,.pantheon-page-cache tr.cache-default-max-age .pantheon-cache-default-max-age-info-bar a:hover{color:#fff;text-decoration:none}.pantheon-page-cache tr.cache-default-max-age .pantheon-cache-default-max-age select{background-color:#fff;color:#1e1e1e;border:1px solid #757575;border-radius:0}.pantheon-page-cache tr.cache-default-max-age .pantheon-cache-default-max-age-description{color:#757575;margin:10px 0 0}
     1.pantheon-page-cache hr {
     2  display: none;
     3}
     4.pantheon-page-cache tr.cache-default-max-age {
     5  display: block;
     6  padding: 10px;
     7  background: #ffffff;
     8  color: #1e1e1e;
     9  box-shadow: 0 0 10px 5px rgba(0, 0, 0, 0.1);
     10}
     11.pantheon-page-cache tr.cache-default-max-age td {
     12  padding: 0;
     13}
     14.pantheon-page-cache tr.cache-default-max-age .pantheon-cache-default-max-age {
     15  padding: 0 10px 10px 0;
     16}
     17.pantheon-page-cache tr.cache-default-max-age .pantheon-cache-default-max-age h3 {
     18  margin-top: 0.5em;
     19}
     20.pantheon-page-cache tr.cache-default-max-age .pantheon-cache-default-max-age i {
     21  margin-right: 10px;
     22  line-height: 1em;
     23}
     24.pantheon-page-cache tr.cache-default-max-age .pantheon-cache-default-max-age-info-bar {
     25  background: #1d7afc;
     26  color: #ffffff;
     27  padding: 10px 0 10px 10px;
     28  text-align: left;
     29  display: block;
     30  width: 100%;
     31  margin-bottom: 1em;
     32}
     33.pantheon-page-cache tr.cache-default-max-age .pantheon-cache-default-max-age-info-bar a {
     34  color: #ffffff;
     35  text-decoration: underline;
     36}
     37.pantheon-page-cache tr.cache-default-max-age .pantheon-cache-default-max-age-info-bar a:hover, .pantheon-page-cache tr.cache-default-max-age .pantheon-cache-default-max-age-info-bar a:active {
     38  color: #ffffff;
     39  text-decoration: none;
     40}
     41.pantheon-page-cache tr.cache-default-max-age .pantheon-cache-default-max-age select {
     42  background-color: #ffffff;
     43  color: #1e1e1e;
     44  border: 1px solid #757575;
     45  border-radius: 0;
     46}
     47.pantheon-page-cache tr.cache-default-max-age .pantheon-cache-default-max-age-description {
     48  color: #757575;
     49  margin: 10px 0 0 0;
     50}
  • pantheon-advanced-page-cache/trunk/inc/admin-interface.php

    r3091792 r3094130  
    33 * Controller for the admin interface that builds on top of the Pantheon MU plugin.
    44 *
    5  * @since 2.0.0-dev
     5 * @since 2.0.0
    66 * @package Pantheon_Advanced_Page_Cache
    77 */
     
    1212 * Kick off the important bits.
    1313 *
    14  * @since 2.0.0-dev
     14 * @since 2.0.0
    1515 * @return void
    1616 */
     
    4343    add_filter( 'pantheon_cache_max_age_input', __NAMESPACE__ . '\\update_default_ttl_input' );
    4444    add_filter( 'pantheon_cache_max_age_input_allowed_html', __NAMESPACE__ . '\\max_age_input_allowed_html' );
     45    add_filter( 'nonce_life', __NAMESPACE__ . '\\filter_nonce_cache_lifetime' );
    4546}
    4647
     
    4849 * Enqueue admin assets.
    4950 *
    50  * @since 2.0.0-dev
     51 * @since 2.0.0
    5152 * @return void
    5253 */
     
    6061    // If WP_DEBUG is true, append a timestamp to the end of the path so we get a fresh copy of the css.
    6162    $debug = defined( 'WP_DEBUG' ) && WP_DEBUG ? '-' . time() : '';
    62     wp_enqueue_style( 'papc-admin', plugin_dir_url( __DIR__ ) . 'assets/css/styles.css', [], '2.0.0' . $debug );
     63    // Use minified css unless SCRIPT_DEBUG is true.
     64    $min = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
     65    wp_enqueue_style( 'papc-admin', plugin_dir_url( __DIR__ ) . "assets/css/styles$min.css", [], '2.0.0' . $debug );
    6366}
    6467
     
    6669 * Add a header to the max-age setting field.
    6770 *
    68  * @since 2.0.0-dev
     71 * @since 2.0.0
    6972 * @return string
    7073 */
     
    8790 * Add a description to the max-age setting field.
    8891 *
    89  * @since 2.0.0-dev
     92 * @since 2.0.0
    9093 * @return string
    9194 */
     
    122125 * @param int $default_input The default TTL input field from the mu-plugin.
    123126 *
    124  * @since 2.0.0-dev
     127 * @since 2.0.0
    125128 * @return int
    126129 */
     
    160163 * Filter the allowed HTML for the max-age input field.
    161164 *
    162  * @since 2.0.0-dev
     165 * @since 2.0.0
    163166 * @param array $allowed_html The allowed HTML.
    164167 * @return array
     
    173176 * Get the default max age options. Default values are 1 week, 1 month, 1 year.
    174177 *
    175  * @since 2.0.0-dev
     178 * @since 2.0.0
    176179 * @return array
    177180 */
     
    195198 * Display an admin notice if the Pantheon MU plugin was not found.
    196199 *
    197  * @since 2.0.0-dev
     200 * @since 2.0.0
    198201 * @return void
    199202 */
     
    222225 * Display an admin notice if the Pantheon MU plugin is out of date.
    223226 *
    224  * @since 2.0.0-dev
     227 * @since 2.0.0
    225228 * @return void
    226229 */
     
    260263 * Display an admin notice if the max-age is less than a week but not equal to 600 seconds.
    261264 *
    262  * @since 2.0.0-dev
     265 * @since 2.0.0
    263266 * @return void
    264267 */
     
    330333 * If the site existed prior to 1.4.0 of the mu-plugin, the default value is 600 seconds. Otherwise, the default value is 1 week.
    331334 *
    332  * @since 2.0.0-dev
     335 * @since 2.0.0
    333336 * @return int
    334337 */
     
    349352 * @param array $tests The Site Health tests.
    350353 *
    351  * @since 2.0.0-dev
     354 * @since 2.0.0
    352355 * @return array
    353356 */
     
    366369 * @param bool $recommended Whether to get the recommended max-age.
    367370 *
    368  * @since 2.0.0-dev
     371 * @since 2.0.0
    369372 * @return string
    370373 */
     
    380383 * Get the default max-age.
    381384 *
    382  * @since 2.0.0-dev
     385 * @since 2.0.0
    383386 * @return int
    384387 */
     
    390393 * Compare the current max-age to the default max-age.
    391394 *
    392  * @since 2.0.0-dev
     395 * @since 2.0.0
    393396 * @return int A ranked value from 0 to 10 where 0 is optimal (equal to or greater than the recommended max age) and 10 is very bad.
    394397 */
     
    419422 * The GCDN cache max-age Site Health test.
    420423 *
    421  * @since 2.0.0-dev
     424 * @since 2.0.0
    422425 * @return array
    423426 */
     
    485488 * Clear the max-age compare cache when the max-age is updated.
    486489 *
    487  * @since 2.0.0-dev
     490 * @since 2.0.0
    488491 * @return void
    489492 */
     
    495498 * Set the default_ttl from the mu-plugin to WEEK_IN_SECONDS if it was saved as 600 seconds.
    496499 *
    497  * @since 2.0.0-dev
     500 * @since 2.0.0
    498501 * @return bool
    499502 */
     
    530533 * Display an admin notice if the max-age was updated.
    531534 *
    532  * @since 2.0.0-dev
     535 * @since 2.0.0
    533536 * @return void
    534537 */
     
    584587    update_user_meta( $current_user_id, 'pantheon_max_age_updated_notice', true );
    585588}
     589
     590/**
     591 * Filter the nonce cache lifetime.
     592 *
     593 * @param int $lifetime The lifetime of the nonce.
     594 *
     595 * @since 2.0.0
     596 * @return int
     597 */
     598function filter_nonce_cache_lifetime( $lifetime ) {
     599    // Bail early if we're in the admin.
     600    if ( is_admin() ) {
     601        return $lifetime;
     602    }
     603
     604    // Filter the cache default max age to less than the nonce lifetime when creating nonces on the front-end. This prevents the cache from keeping the nonce around longer than it should.
     605    add_filter( 'pantheon_cache_default_max_age', function () use ( $lifetime ) {
     606        return $lifetime - HOUR_IN_SECONDS;
     607    } );
     608
     609    return $lifetime;
     610}
  • pantheon-advanced-page-cache/trunk/pantheon-advanced-page-cache.php

    r3092255 r3094130  
    11<?php
    22/**
    3  * Plugin Name:     Pantheon Advanced Page Cache
    4  * Plugin URI:      https://wordpress.org/plugins/pantheon-advanced-page-cache/
    5  * Description:     Automatically clear related pages from Pantheon's Edge when you update content. High TTL. Fresh content. Visitors never wait.
    6  * Author:          Pantheon
    7  * Author URI:      https://pantheon.io
    8  * Text Domain:     pantheon-advanced-page-cache
    9  * Domain Path:     /languages
    10  * Version:         1.5.0
     3 * Plugin Name: Pantheon Advanced Page Cache
     4 * Plugin URI: https://wordpress.org/plugins/pantheon-advanced-page-cache/
     5 * Description: Automatically clear related pages from Pantheon's Edge when you update content. High TTL. Fresh content. Visitors never wait.
     6 * Author: Pantheon
     7 * Author URI: https://pantheon.io
     8 * Text Domain: pantheon-advanced-page-cache
     9 * Domain Path: /languages
     10 * Version: 2.0.0
     11 * Requires at least: 6.4
     12 * Tested up to: 6.5.3
    1113 *
    1214 * @package         Pantheon_Advanced_Page_Cache
     
    102104
    103105/**
     106 * Bootstrapper for namespaced files that aren't classes.
     107 *
     108 * Expects that a bootstrap() function exists in the namespaced file.
     109 *
     110 * @since 2.0.0
     111 * @return void
     112 */
     113function pantheon_bootstrap_namespaces() {
     114    $namespaced_files = [
     115        '\\Pantheon_Advanced_Page_Cache\\Admin_Interface' => __DIR__ . '/inc/admin-interface.php',
     116    ];
     117
     118    foreach ( $namespaced_files as $namespace => $file ) {
     119        if ( file_exists( $file ) ) {
     120            require $file;
     121            call_user_func( $namespace . '\\bootstrap' );
     122        } else {
     123            wp_die( esc_html( "Could not find $file" ), 'Pantheon Advanced Page Cache error' );
     124
     125        }
     126    }
     127}
     128
     129/**
    104130 * Registers the class autoloader.
    105131 */
     
    122148    }
    123149);
     150
     151/**
     152 * Init namespaced files.
     153 */
     154add_action( 'plugins_loaded', 'pantheon_bootstrap_namespaces' );
    124155
    125156/**
  • pantheon-advanced-page-cache/trunk/readme.txt

    r3092255 r3094130  
    22Contributors: getpantheon, danielbachhuber, kporras07, jspellman, jazzs3quence, ryanshoover, rwagner00, pwtyler
    33Tags: pantheon, cdn, cache
    4 Requires at least: 4.7
    5 Tested up to: 6.4.3
    6 Stable tag: 1.5.0
     4Requires at least: 6.4
     5Tested up to: 6.5.3
     6Stable tag: 2.0.0
    77License: GPLv2 or later
    88License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    151151This will prevent the cache from being purged if the given post type is updated.
    152152
     153= Setting the Cache Max Age with a filter =
     154
     155The cache max age setting is controlled by the [Pantheon Page Cache](https://docs.pantheon.io/guides/wordpress-configurations/wordpress-cache-plugin) admin page. As of 2.0.0, there are three cache age options by default — 1 week, 1 month, 1 year. Pantheon Advanced Page Cache automatically purges the cache of updated and related posts and pages, but you might want to override the cache max age value and set it programmatically. In this case, you can use the `pantheon_cache_default_max_age` filter added in [Pantheon MU plugin 1.4.0+](https://docs.pantheon.io/guides/wordpress-configurations/wordpress-cache-plugin#override-the-default-max-age). For example:
     156
     157    add_filter( 'pantheon_cache_default_max_age', function() {
     158        return 10 * DAY_IN_SECONDS;
     159    } );
     160
     161When the cache max age is filtered in this way, the admin option is disabled and a notice is displayed.
     162
    153163== WP-CLI Commands ==
    154164
     
    322332    add_filter('pantheon_should_add_terms', 'custom_should_add_terms', 10, 2);
    323333
     334== Other Filters ==
     335
     336= `pantheon_apc_disable_admin_notices` =
     337Since 2.0.0, Pantheon Advanced Page Cache displays a number of admin notices about your current cache max age value. You can disable these notices with the `pantheon_apc_disable_admin_notices` filter.
     338
     339    add_filter( 'pantheon_apc_disable_admin_notices', '__return_true' );
     340
     341Alternately, the function callback is passed into the `pantheon_apc_disable_admin_notices` filter, allowing you to specify precisely _which_ notice to disable, for example:
     342
     343    add_filter( 'pantheon_apc_disable_admin_notices', function( $disable_notices, $callback ) {
     344        if ( $callback === '\\Pantheon_Advanced_Page_Cache\\Admin_Interface\\admin_notice_maybe_recommend_higher_max_age' ) {
     345            return true;
     346        }
     347        return $disable_notices;
     348    }, 10, 2 );
     349
     350The above example would disable _only_ the admin notice recommending a higher cache max age.
     351
    324352== Plugin Integrations ==
    325353
     
    333361
    334362== Changelog ==
     363= 2.0.0 (28 May 2024) =
     364* Adds new admin alerts and Site Health tests about default cache max age settings and recommendations [[#268](https://github.com/pantheon-systems/pantheon-advanced-page-cache/pull/268), [#271](https://github.com/pantheon-systems/pantheon-advanced-page-cache/pull/271)]. The default Pantheon GCDN cache max age value has been updated to 1 week in the [Pantheon MU plugin](https://github.com/pantheon-systems/pantheon-mu-plugin). For more information, see the [release note](https://docs.pantheon.io/release-notes/2024/04/pantheon-mu-plugin-1-4-0-update).
     365* Updated UI in Pantheon Page Cache admin page when used in a Pantheon environment (with the Pantheon MU plugin). [[#272](https://github.com/pantheon-systems/pantheon-advanced-page-cache/pull/272)]
     366* Automatically updates the cache max age to the recommended value (1 week) if it was saved at the old default value (600 seconds). [[#269](https://github.com/pantheon-systems/pantheon-advanced-page-cache/pull/269)]
     367* Adds a hook into the `nonce_life` filter when nonces are created on the front-end to set the `pantheon_cache_default_max_age` to less than the nonce lifetime to avoid nonces expiring before the cache does. [[#282](https://github.com/pantheon-systems/pantheon-advanced-page-cache/pull/282)] props [@ryanshoover](https://profiles.wordpress.org/ryanshoover/)
     368
    335369= 1.5.0 (11 March 2024) =
    336370* Adds filter `pantheon_purge_post_type_ignored` to allow an array of post types to ignore before purging cache [[#258](https://github.com/pantheon-systems/pantheon-advanced-page-cache/pull/258)]
     
    410444
    411445== Upgrade Notice ==
    412 
    413 = Latest =
     446= 2.0.0 (28 May 2024) =
     447This release requires a minimum WordPress version of 6.4.0. It uses Site Health checks and the `wp_admin_notices` function to alert users to the new cache max-age default settings and recommendations. The plugin will still function with earlier versions, but you will not get the benefit of the alerts and Site Health checks.
     448
     449This version also automatically updates the cache max age (set in the [Pantheon Page Cache settings](https://docs.pantheon.io/guides/wordpress-configurations/wordpress-cache-plugin)) to the recommended value (1 week) if it was saved at the old default value (600 seconds). If the cache max age was set to any other value (or not set at all), it will not be changed. A one-time notice will be displayed in the admin interface to inform administrators of this change.
     450
     451= 1.3.0 =
    414452Note that the Pantheon Advanced Page Cache 1.3.0 release now prefixes keys on a WordPress Multisite (WPMS) with the blog ID. For users who already have this plugin installed on a WPMS, they will need to click the Clear Cache button on the settings page to generate the prefixed keys.
Note: See TracChangeset for help on using the changeset viewer.