Skip to content

Add actions and filters #182

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Apr 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions admin/class-fastcgi-purger.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@ public function purge_url( $url, $feed = true ) {

global $nginx_helper_admin;

/**
* Filters the URL to be purged.
*
* @since 2.1.0
*
* @param string $url URL to be purged.
*/
$url = apply_filters( 'rt_nginx_helper_purge_url', $url );

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

$parse = wp_parse_url( $url );
Expand Down Expand Up @@ -166,6 +175,12 @@ public function purge_all() {
$this->log( '* Purged Everything!' );
$this->log( '* * * * *' );

/**
* Fire an action after the FastCGI cache has been purged.
*
* @since 2.1.0
*/
do_action( 'rt_nginx_helper_after_fastcgi_purge_all' );
}

}
15 changes: 15 additions & 0 deletions admin/class-phpredis-purger.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@ public function purge_all() {

$this->log( '* * * * *' );

/**
* Fire an action after the Redis cache has been purged.
*
* @since 2.1.0
*/
do_action( 'rt_nginx_helper_after_redis_purge_all' );
}

/**
Expand All @@ -97,6 +103,15 @@ public function purge_url( $url, $feed = true ) {

global $nginx_helper_admin;

/**
* Filters the URL to be purged.
*
* @since 2.1.0
*
* @param string $url URL to be purged.
*/
$url = apply_filters( 'rt_nginx_helper_purge_url', $url );

$parse = wp_parse_url( $url );

if ( ! isset( $parse['path'] ) ) {
Expand Down
15 changes: 15 additions & 0 deletions admin/class-predis-purger.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,12 @@ public function purge_all() {

$this->log( '* * * * *' );

/**
* Fire an action after the Redis cache has been purged.
*
* @since 2.1.0
*/
do_action( 'rt_nginx_helper_after_redis_purge_all' );
}

/**
Expand All @@ -94,6 +100,15 @@ public function purge_url( $url, $feed = true ) {

global $nginx_helper_admin;

/**
* Filters the URL to be purged.
*
* @since 2.1.0
*
* @param string $url URL to be purged.
*/
$url = apply_filters( 'rt_nginx_helper_purge_url', $url );

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

$parse = wp_parse_url( $url );
Expand Down
45 changes: 45 additions & 0 deletions admin/class-purger.php
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,15 @@ protected function delete_cache_file_for( $url ) {
// Set path to cached file.
$cached_file = $cache_path . substr( $hash, -1 ) . '/' . substr( $hash, -3, 2 ) . '/' . $hash;

/**
* Filters the cached file name.
*
* @since 2.1.0
*
* @param string $cached_file Cached file name.
*/
$cached_file = apply_filters( 'rt_nginx_helper_purge_cached_file', $cached_file );

// Verify cached file exists.
if ( ! file_exists( $cached_file ) ) {

Expand All @@ -408,6 +417,16 @@ protected function delete_cache_file_for( $url ) {
// Delete the cached file.
if ( unlink( $cached_file ) ) {
$this->log( '- - ' . $url . ' *** PURGED ***' );

/**
* Fire an action after deleting file from cache.
*
* @since 2.1.0
*
* @param string $url URL to be purged.
* @param string $cached_file Cached file name.
*/
do_action( 'rt_nginx_helper_purged_file', $url, $cached_file );
} else {
$this->log( '- - An error occurred deleting the cache file. Check the server logs for a PHP warning.', 'ERROR' );
}
Expand All @@ -420,6 +439,23 @@ protected function delete_cache_file_for( $url ) {
* @param string $url URL to do remote request.
*/
protected function do_remote_get( $url ) {
/**
* Filters the URL to be purged.
*
* @since 2.1.0
*
* @param string $url URL to be purged.
*/
$url = apply_filters( 'rt_nginx_helper_remote_purge_url', $url );

/**
* Fire an action before purging URL.
*
* @since 2.1.0
*
* @param string $url URL to be purged.
*/
do_action( 'rt_nginx_helper_before_remote_purge_url', $url );

$response = wp_remote_get( $url );

Expand Down Expand Up @@ -447,6 +483,15 @@ protected function do_remote_get( $url ) {

}

/**
* Fire an action after remote purge request.
*
* @since 2.1.0
*
* @param string $url URL to be purged.
* @param array $response Array of results including HTTP headers.
*/
do_action( 'rt_nginx_helper_after_remote_purge_url', $url, $response );
}

}
Expand Down