Skip to content

Commit

Permalink
Merge pull request #372 from rtCamp/feat/add-amp-url-purge
Browse files Browse the repository at this point in the history
Add Purge for AMP URL when a Post or Page is Published.
  • Loading branch information
Vedant-Gandhi authored Dec 18, 2024
2 parents 2f2902c + cbfc429 commit d60281e
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 0 deletions.
21 changes: 21 additions & 0 deletions admin/class-fastcgi-purger.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,29 @@ public function purge_url( $url, $feed = true ) {
break;

}

if( ( is_page() || is_single() ) && $nginx_helper_admin->options['purge_amp_urls'] ) {
$this->purge_amp_version( $url );
}

}

/**
* Purge AMP version of a URL.
*
* @param string $url_base The base URL to purge.
*/
private function purge_amp_version( $url_base ) {
$amp_url = sprintf( '%s/amp/', rtrim( $url_base, '/' ) );

$this->log( '- Purging AMP URL | ' . $amp_url );

if ( 'unlink_files' === $this->nginx_helper_admin->options['purge_method'] ) {
$this->delete_cache_file_for( $amp_url );
} else {
$this->do_remote_get( $amp_url );
}
}

/**
* Function to custom purge urls.
Expand Down
1 change: 1 addition & 0 deletions admin/class-nginx-helper-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ public function nginx_helper_default_settings() {
'redis_password' => '',
'purge_url' => '',
'redis_enabled_by_constant' => 0,
'purge_amp_urls' => 1,
'redis_socket_enabled_by_constant' => 0,
'redis_acl_enabled_by_constant' => 0,
'preload_cache' => 0,
Expand Down
33 changes: 33 additions & 0 deletions admin/partials/nginx-helper-general-options.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
'purge_page_on_deleted_comment',
'purge_feeds',
'smart_http_expire_form_nonce',
'purge_amp_urls',
'preload_cache',
);

Expand Down Expand Up @@ -641,6 +642,38 @@
</td>
</tr>
</table>
<table class="form-table rtnginx-table">
<tr valign="top">
<th scope="row">
<h4>
<?php esc_html_e( 'Purge AMP URL:', 'nginx-helper' ); ?>
</h4>
</th>
<td>
<fieldset>
<legend class="screen-reader-text">
<span>
&nbsp;
<?php
esc_html_e( 'purge amp urls', 'nginx-helper' );
?>
</span>
</legend>
<label for="purge_amp_urls">
<input type="checkbox" value="1" id="purge_amp_urls" name="purge_amp_urls" <?php checked( $nginx_helper_settings['purge_amp_urls'], 1 ); ?> />
&nbsp;
<?php
echo wp_kses(
__( 'purge <strong>amp urls</strong> along with <strong>posts</strong> & <strong>pages</strong>.', 'nginx-helper' ),
array( 'strong' => array() )
);
?>
</label>
<br />
</fieldset>
</td>
</tr>
</table>
<table class="form-table rtnginx-table">
<tr valign="top">
<th scope="row">
Expand Down

0 comments on commit d60281e

Please sign in to comment.