diff --git a/README.md b/README.md index 467af9d..b87a8e8 100644 --- a/README.md +++ b/README.md @@ -44,14 +44,14 @@ add_filter( 'pantheon_wp_login_text', function() { } ); ``` -#### `pantheon_cache_default_ttl` -Filter the default cache age for the Pantheon Edge Cache. +#### `pantheon_cache_default_max_age` +Filter the default cache max-age for the Pantheon Edge Cache. **Default Value:** `WEEK_IN_SECONDS` (604800) **Example:** ```php -add_filter( 'pantheon_cache_default_ttl', function() { +add_filter( 'pantheon_cache_default_max_age', function() { return 2 * WEEK_IN_SECONDS; } ); ``` diff --git a/inc/pantheon-page-cache.php b/inc/pantheon-page-cache.php index 1b92169..776deea 100644 --- a/inc/pantheon-page-cache.php +++ b/inc/pantheon-page-cache.php @@ -88,16 +88,16 @@ protected function __construct() { */ protected function setup() { /** - * Modify the default TTL for the Pantheon cache. Defaults to 1 week. + * Modify the default max-age for the Pantheon cache. Defaults to 1 week (604800 seconds). * * Usage: - * add_filter( 'pantheon_cache_default_ttl', function() { + * add_filter( 'pantheon_cache_default_max_age', function() { * return DAY_IN_SECONDS; * } ); * - * @param int $default_ttl The default TTL in seconds. + * @param int $default_ttl The default max-age in seconds. */ - $default_ttl = apply_filters( 'pantheon_cache_default_ttl', WEEK_IN_SECONDS ); + $default_ttl = apply_filters( 'pantheon_cache_default_max_age', WEEK_IN_SECONDS ); $this->options = get_option( self::SLUG, [] ); $this->default_options = [ @@ -221,19 +221,19 @@ public function action_admin_footer_trigger_plugin_open() { } /** - * Add the HTML for the default TTL field. + * Add the HTML for the default max-age field. * * @return void */ public function default_ttl_field() { - $disabled = ( has_filter( 'pantheon_cache_default_ttl' ) ) ? ' disabled' : ''; - echo '

' . esc_html__( 'Default Time to Live (TTL)', 'pantheon-cache' ) . '

'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped - echo '

' . esc_html__( 'Maximum time a cached page will be served. A higher TTL typically improves site performance.', 'pantheon-cache' ) . '

'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped + $disabled = ( has_filter( 'pantheon_cache_default_max_age' ) ) ? ' disabled' : ''; + echo '

' . esc_html__( 'Default Max Age', 'pantheon-cache' ) . '

'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped + echo '

' . esc_html__( 'Maximum time a cached page will be served. A higher max-age typically improves site performance.', 'pantheon-cache' ) . '

'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped echo ' ' . esc_html__( 'seconds', 'pantheon-cache' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped // Display a message if the setting is disabled. if ( $disabled ) { - echo '

' . esc_html__( 'This setting is disabled because the default TTL has been filtered to the current value.', 'pantheon-cache' ) . '

'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped + echo '

' . esc_html__( 'This setting is disabled because the default max-age has been filtered to the current value.', 'pantheon-cache' ) . '

'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped } } diff --git a/tests/phpunit/test-page-cache.php b/tests/phpunit/test-page-cache.php index 34311c6..f51ca3b 100644 --- a/tests/phpunit/test-page-cache.php +++ b/tests/phpunit/test-page-cache.php @@ -95,7 +95,7 @@ public function test_sanitize_empty_or_missing_values() { ]; $expected_output = [ - 'default_ttl' => 60, // Default TTL is set to 60 on live environments. + 'default_ttl' => 60, // Default max-age is set to 60 on live environments. 'maintenance_mode' => 'disabled', ]; $output = $this->pantheon_cache->sanitize_options( $input ); @@ -194,21 +194,21 @@ public function test_enqueue_regex() { } /** - * Test the filtered value and display if the pantheon_cache_default_ttl filter is used. + * Test the filtered value and display if the pantheon_cache_default_max_age filter is used. */ - public function test_pantheon_cache_default_ttl_filter() { - // Add a filter to change the default TTL to 120 seconds. - add_filter( 'pantheon_cache_default_ttl', function () { + public function test_pantheon_cache_default_max_age_filter() { + // Add a filter to change the default max-age to 120 seconds. + add_filter( 'pantheon_cache_default_max_age', function () { return 120; } ); - // Get the filtered default TTL. - $filtered_default_ttl = apply_filters( 'pantheon_cache_default_ttl', get_option( 'default_ttl' ) ); + // Get the filtered default max-age. + $filtered_default_ttl = apply_filters( 'pantheon_cache_default_max_age', get_option( 'default_ttl' ) ); - // The filtered default TTL should be 120 seconds. + // The filtered default max-age should be 120 seconds. $this->assertEquals( 120, $filtered_default_ttl ); // Remove the filter. - remove_all_filters( 'pantheon_cache_default_ttl' ); + remove_all_filters( 'pantheon_cache_default_max_age' ); } }