-
Notifications
You must be signed in to change notification settings - Fork 83
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
No way to purge specific URL #521
Comments
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Still no changes in version 4.12.4. |
I'm also looking for this and it's related to #160 We have some content on our site which comes from an API. Possible new method for Hooks: public function purgeCacheByUrl($url)
{
$wpDomainList = $this->integrationAPI->getDomainList();
if (!count($wpDomainList)) {
return;
}
$wpDomain = $wpDomainList[0];
$zoneTag = $this->api->getZoneTag($wpDomain);
if (!isset($zoneTag)) {
return;
}
// Don't attempt to purge anything outside of the provided zone.
if (!Utils::strEndsWith(parse_url($url, PHP_URL_HOST), $wpDomain)) {
return;
}
$isOK = $this->api->zonePurgeFiles($zoneTag, array($url));
$isOK = ($isOK) ? 'succeeded' : 'failed';
$this->logger->debug("purgeCacheByUrl " . $isOK);
} Would this be accepted as a pull request? |
Addition to you code we should add this filter also in
|
If anyone is looking for a quick fix, I ended up adding the creds as constants in the wp-config.php file. // Check if the cloudflare constants are defined.
if ( defined( 'CLOUDFLARE_ZONE_ID' ) && defined( 'CLOUDFLARE_API_KEY' ) && defined( 'CLOUDFLARE_EMAIL' ) ) {
$ch = curl_init();
curl_setopt( $ch, CURLOPT_URL, 'https://api.cloudflare.com/client/v4/zones/' . CLOUDFLARE_ZONE_ID . '/purge_cache' );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt( $ch, CURLOPT_CUSTOMREQUEST, 'DELETE' );
$headers = array();
$headers[] = 'X-Auth-Email: ' . CLOUDFLARE_EMAIL;
$headers[] = 'X-Auth-Key: ' . CLOUDFLARE_API_KEY;
$headers[] = 'Content-Type: application/json';
curl_setopt( $ch, CURLOPT_HTTPHEADER, $headers );
$data = '{"files":["' . $url_to_flush . '"]}';
curl_setopt( $ch, CURLOPT_POSTFIELDS, $data );
$result = curl_exec( $ch );
if ( curl_errno( $ch ) ) {
$response .= 'Error clearing Cloudflare. ';
}
$responseObj = json_decode( $result );
if ( isset( $responseObj->success ) && $responseObj->success ) {
$response .= 'Cloudflare cleared. ';
}
curl_close( $ch );
} |
Confirmation
WordPress version
6.2.2
Cloudflare-WordPress version
4.12.2
PHP version
8.0
Expected result
purgeCacheByRelevantURLs should accept URLs, also.
Actual result
purgeCacheByRelevantURLs function accepts post IDs only.
Steps to reproduce
Additional factoids
No response
References
No response
The text was updated successfully, but these errors were encountered: