Skip to content

Commit bb100f6

Browse files
minor improvements
1 parent 52d262d commit bb100f6

4 files changed

Lines changed: 31 additions & 21 deletions

File tree

includes/allow-svg-uploads.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<?php
22

33
add_filter('upload_mimes', function (array $mime_types): array {
4-
$mime_types['svg'] = 'image/svg+xml';
4+
if (current_user_can('manage_options')) {
5+
$mime_types['svg'] = 'image/svg+xml';
6+
}
57
return $mime_types;
68
});

includes/purge-bunny-cdn-cache.php

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,34 +4,42 @@
44

55
function purge_cache_for_url(string $url)
66
{
7-
$url = urlencode($url);
8-
$curl = curl_init();
9-
curl_setopt_array($curl, [
10-
CURLOPT_URL => "https://api.bunny.net/purge?url=$url",
11-
CURLOPT_RETURNTRANSFER => true,
12-
CURLOPT_POST => true,
13-
CURLOPT_MAXREDIRS => 5,
14-
CURLOPT_TIMEOUT => 10,
15-
CURLOPT_HTTPHEADER => [
16-
"AccessKey: " . constant('BUNNY_API_KEY'),
7+
$request_url = 'https://api.bunny.net/purge?url=' . urlencode($url);
8+
9+
$response = wp_remote_post($request_url, [
10+
'timeout' => 10,
11+
'redirection' => 5,
12+
'headers' => [
13+
'AccessKey' => constant('BUNNY_API_KEY'),
1714
],
1815
]);
1916

20-
curl_exec($curl);
21-
$error = curl_error($curl);
22-
if ($error) {
23-
error_log("Error purging Bunny CDN cache: $error");
17+
if (is_wp_error($response)) {
18+
error_log('Error purging Bunny CDN cache: ' . $response->get_error_message());
19+
return;
20+
}
21+
22+
$status_code = wp_remote_retrieve_response_code($response);
23+
if ($status_code < 200 || $status_code >= 300) {
24+
error_log('Error purging Bunny CDN cache: HTTP ' . $status_code);
2425
}
2526
}
2627

2728
add_action('save_post', function ($post_id) {
29+
// No-op if BUNNY_API_KEY constant is not set
30+
if (! defined('BUNNY_API_KEY')) {
31+
return;
32+
}
33+
2834
// Check if it's not an autosave
29-
if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
35+
if ((defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) || wp_is_post_autosave($post_id) || wp_is_post_revision($post_id)) {
3036
return;
3137
}
3238

33-
// No-op if BUNNY_API_KEY constant is not set
34-
if (! defined('BUNNY_API_KEY')) {
39+
40+
$post_type = get_post_type($post_id);
41+
$post_type_object = $post_type ? get_post_type_object($post_type) : null;
42+
if (! $post_type_object || ! $post_type_object->public) {
3543
return;
3644
}
3745

includes/set-cache-headers.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121

2222
// cache feeds and XML files (ie sitemap) for 1 day
2323
} elseif (is_feed() || str_ends_with($_SERVER['REQUEST_URI'] ?? '', '.xml')) {
24-
$headers['Cache-Control'] = 'public, max-age=81600';
25-
// cache all other pages for 1 year
24+
$headers['Cache-Control'] = 'public, max-age=86400';
25+
// cache all other pages for 30 days
2626
} else {
2727
$headers['Cache-Control'] = 'public, max-age=2592000';
2828
}

includes/stop-comment-spam.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
|| (strlen($commentdata['comment_author_email']) > 0 && preg_match('/^\w+_\w+@(yahoo|gmail|hotmail)\.com$/', $commentdata['comment_author_email']) && strlen($commentdata['comment_author_url']) > 0)
4141

4242
// if comment contains a russian character
43-
|| (mb_strpos($commentdata['comment_content'], "н") !== false)
43+
|| (function_exists('mb_strpos') && mb_strpos($commentdata['comment_content'], "н") !== false)
4444

4545
// if URL is given and does not contain at least one dot
4646
|| (strlen($commentdata['comment_author_url']) > 0 && !str_contains($commentdata['comment_author_url'], '.'))

0 commit comments

Comments
 (0)