Skip to content

Commit 3f6f946

Browse files
Merge pull request #171 from MITLibraries/web-2050
Add filter to allow conditional max cache ages
2 parents f08b5a5 + 5166cd1 commit 3f6f946

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

scripts/composer/class-mitcomposerscripts.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ public static function multidev_search_replace_syntax( $event ): void {
6363
$multidev = self::multidev_name( $event );
6464
$terminus_command = "terminus remote:wp mitlib-wp-network.$multidev -- search-replace libraries.mit.edu $multidev-mitlib-wp-network.pantheonsite.io --url=libraries.mit.edu --network";
6565
$event->getIO()->write( $terminus_command );
66+
$terminus_command = "terminus remote:wp mitlib-wp-network.$multidev -- search-replace noreply@$multidev-mitlib-wp-network.pantheonsite.io [email protected] --network";
67+
$event->getIO()->write( $terminus_command );
6668
$event->getIO()->write( '-----' );
6769
}
6870
}

web/app/themes/mitlib-parent/functions.php

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,35 @@ function setup_scss_folders() {
111111
}
112112

113113
/**
114-
* Register and selectively enqueue the scripts and stylesheets needed for this
115-
* page.
114+
* Override max cache age for certain conditions.
115+
*
116+
* The default cache behavior is defined by the combination of two plugins:
117+
* Pantheon MU Plugin and Pantheon Advanced Page Cache. The cache lifetime is
118+
* typically set to 1 week via the former plugin, but certain pages require a
119+
* shorter cache life. This function implements those alternative lifetimes.
120+
*
121+
* @link https://docs.pantheon.io/guides/wordpress-configurations/wordpress-cache-plugin#override-the-default-max-age
116122
*/
123+
function override_cache_default_max_age() {
124+
$site = parse_url( get_site_url(), PHP_URL_PATH );
125+
if ( is_page( 'hours' ) ) { // All hours pages (including those with query parameters).
126+
return 1 * DAY_IN_SECONDS;
127+
} elseif ( '/news' == $site && is_page( 'events' ) ) { // The news site events page.
128+
return 1 * DAY_IN_SECONDS;
129+
} elseif ( '/exhibits' == $site && is_page( '' ) ) { // The exhibits site homepage.
130+
return 1 * DAY_IN_SECONDS;
131+
} elseif ( '/exhibits' == $site && is_page( 'current-upcoming-past-exhibits' ) ) { // The exhibits site composite listing.
132+
return 1 * DAY_IN_SECONDS;
133+
} else { // All other content should be cached for a week.
134+
return 1 * WEEK_IN_SECONDS;
135+
}
136+
}
137+
add_filter( 'pantheon_cache_default_max_age', 'Mitlib\Parent\override_cache_default_max_age' );
138+
139+
/**
140+
* Register and selectively enqueue the scripts and stylesheets needed for this
141+
* page.
142+
*/
117143
function setup_scripts_styles() {
118144
// This allows us to cache-bust these assets without needing to remember to
119145
// increment the theme version here.

0 commit comments

Comments
 (0)