Skip to content

Commit e90e840

Browse files
author
Aaron Holbrook
committed
Add ability to flush cache via function directly. Update readme
1 parent 38ff3da commit e90e840

3 files changed

Lines changed: 26 additions & 10 deletions

File tree

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,8 @@ Make a GET request to your site's URL with the query parameter `?wpe-cache-flush
5656
```
5757
GET http://example.com/?wpe-cache-flush=$private_key
5858
```
59+
60+
You can also call the flush function directly from your code via
61+
```php
62+
\A7\WPE_Cache_Flush\cache_flush()
63+
```

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"description": "Programmatically flush the WP Engine Cache",
44
"type": "library",
55
"license": "UNLICENSE",
6-
"version": "0.2.3",
6+
"version": "0.3.0",
77
"authors": [
88
{
99
"name": "A7",

wpe-cache-flush.php

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,26 @@ function get_flush_token() {
4242
return;
4343
}
4444

45+
$error = cache_flush();
46+
47+
header( "Content-Type: text/plain" );
48+
header( "X-WPE-Host: " . gethostname() . " " . $_SERVER['SERVER_ADDR'] );
49+
50+
echo "All Caches were purged!";
51+
echo $error;
52+
53+
exit( 0 );
54+
} );
55+
56+
/**
57+
* Allow cache flushing to be called independently of web hook
58+
*
59+
* @return string|bool
60+
*/
61+
function cache_flush() {
4562
// Don't cause a fatal if there is no WpeCommon class
4663
if ( ! class_exists( 'WpeCommon' ) ) {
47-
return;
64+
return false;
4865
}
4966

5067
if ( function_exists( 'WpeCommon::purge_memcached' ) ) {
@@ -72,11 +89,5 @@ function get_flush_token() {
7289
}
7390
}
7491

75-
header( "Content-Type: text/plain" );
76-
header( "X-WPE-Host: " . gethostname() . " " . $_SERVER['SERVER_ADDR'] );
77-
78-
echo "All Caches were purged!";
79-
echo $error;
80-
81-
exit( 0 );
82-
} );
92+
return $error;
93+
}

0 commit comments

Comments
 (0)