Skip to content

Commit 76a250f

Browse files
add instructions to README
1 parent b65eb67 commit 76a250f

10 files changed

Lines changed: 62 additions & 10 deletions

README.md

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ ibericode mods
33

44
A collection of lightweight WordPress plugins that we commonly use on our sites.
55

6-
- Allow SVG uploads
6+
- Reject all WP Login attempts if submitted within 2.5 seconds of page load.
7+
- Configure `wp_mail()` to use SMTP through a few PHP constants.
8+
- Allow SVG uploads for administrators.
79
- Disable the `/wp-json/wp/v2/users` REST API endpoint.
10+
- Set HTTP `Cache-Control` header on all safe requests for logged-out users.
811
- Adds `Robots: noindex` HTTP header to all non-singular pages (except the front page).
9-
- Reject all WP Login attempts if submitted within 2.5 seconds of page load.
1012
- Purge Bunny CDN Cache on `save_post`
11-
- Set HTTP `Cache-Control` header on all safe requests for logged-out users.
12-
- Configure `wp_mail()` to use SMTP.
1313
- Automatically mark comments as spam through a collection of empirically discovered checks.
1414

1515
Some of these are simple no-ops if the relevant PHP constants are not set.
@@ -22,6 +22,31 @@ Go to **Plugins > Add Plugin > Upload Plugin** to install the plugin.
2222

2323
Alternatively, download or clone this repository and place in `/wp-content/plugins/`.
2424

25+
26+
## Configuring
27+
28+
### Email through SMTP
29+
30+
To configure WordPress to send emails via SMTP instead of the default `mail()` function, define the following constants in your `wp-config.php` file:
31+
32+
```php
33+
define( 'SMTP_HOST', 'smtp.example.com' );
34+
define( 'SMTP_USER', 'youremail@example.com' );
35+
define( 'SMTP_PASSWORD', 'your_password' ); // Optional
36+
define( 'SMTP_PORT', 587 ); // Optional
37+
define( 'SMTP_ENCRYPTION', 'tls' ); // Optional, defaults to 'tls' (PHPMailer::ENCRYPTION_STARTTLS)
38+
```
39+
40+
The plugin will automatically use `SMTP_USER` as the default "From" email address.
41+
42+
### Bunny CDN Purging
43+
44+
To automatically purge the Bunny CDN cache for a post's URL (and the sitemap) when it is saved or updated, define your Bunny API key in your `wp-config.php` file:
45+
46+
```php
47+
define( 'BUNNY_API_KEY', 'your-bunny-cdn-api-key' );
48+
```
49+
2550
## License
2651

2752
GPL v2 or later

includes/allow-svg-uploads.php

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

3+
// Prevent direct file access
4+
defined('ABSPATH') or exit;
5+
36
add_filter('upload_mimes', function (array $mime_types): array {
47
if (current_user_can('manage_options')) {
58
$mime_types['svg'] = 'image/svg+xml';

includes/disable-rest-api-users-endpoint.php

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

3+
// Prevent direct file access
4+
defined('ABSPATH') or exit;
5+
36
// Do not allow access to WordPress REST API for non-logged-in users
47
add_filter('rest_authentication_errors', function ($result) {
58
if (is_wp_error($result)) {

includes/disable-xmlrpc.php

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

3+
// Prevent direct file access
4+
defined('ABSPATH') or exit;
5+
36
add_filter('xmlrpc_enabled', '__return_false');

includes/noindex-archive-pages.php

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

3+
// Prevent direct file access
4+
defined('ABSPATH') or exit;
5+
36
add_filter('wp_robots', function (array $robots): array {
47
if (!is_singular() && !is_front_page()) {
58
$robots['noindex'] = true;

includes/protect-wp-login.php

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

3+
// Prevent direct file access
4+
defined('ABSPATH') or exit;
5+
36
add_action('login_footer', function () {
47
?><style>
58
#wp-submit {

includes/purge-bunny-cdn-cache.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
namespace ibericode;
44

5+
// Prevent direct file access
6+
defined('ABSPATH') or exit;
7+
58
function purge_cache_for_url(string $url)
69
{
710
$request_url = 'https://api.bunny.net/purge?url=' . urlencode($url);

includes/set-cache-headers.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,33 @@
11
<?php
22

3+
// Prevent direct file access
4+
defined('ABSPATH') or exit;
5+
36
add_filter('wp_headers', function ($headers) {
47
if (WP_DEBUG || isset($headers['Cache-Control']) || is_admin()) {
58
return $headers;
69
}
710

811
// only set cache-headers on safe HTTP methods
912
$method = $_SERVER['REQUEST_METHOD'] ?? 'POST';
10-
if ($method !== 'GET') {
13+
if ($method !== 'GET' && $method !== 'HEAD') {
1114
return $headers;
1215
}
1316

1417
// never set cache headers for logged-in users
1518
if (is_user_logged_in()) {
1619
$headers['Cache-Control'] = 'must-revalidate, max-age=0, private';
1720

18-
// cache 404 pages for 1 hour
21+
// cache 404 pages for 1 hour (shared), 5 minutes (browser)
1922
} elseif (is_404()) {
20-
$headers['Cache-Control'] = 'public, max-age=3600';
23+
$headers['Cache-Control'] = 'public, s-max-age=3600, max-age=300';
2124

22-
// cache feeds and XML files (ie sitemap) for 1 day
25+
// cache feeds and XML files (ie sitemap) for 1 day (both shared and browser)
2326
} elseif (is_feed() || str_ends_with($_SERVER['REQUEST_URI'] ?? '', '.xml')) {
2427
$headers['Cache-Control'] = 'public, max-age=86400';
25-
// cache all other pages for 30 days
28+
// cache all other pages for 30 days (shared) or 1 day (browser cache)
2629
} else {
27-
$headers['Cache-Control'] = 'public, max-age=2592000';
30+
$headers['Cache-Control'] = 'public, s-max-age=2592000, max-age=86400';
2831
}
2932

3033
return $headers;

includes/smtp-mailer.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
use PHPMailer\PHPMailer\PHPMailer;
44

5+
// Prevent direct file access
6+
defined('ABSPATH') or exit;
7+
58
add_action('phpmailer_init', function (PHPMailer $phpmailer) {
69
// make sure all configuration constants are given
710
if (! defined('SMTP_HOST') || ! defined('SMTP_USER')) {

includes/stop-comment-spam.php

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

3+
// Prevent direct file access
4+
defined('ABSPATH') or exit;
5+
36
/**
47
* @param mixed $approved One of 1, 0, 'spam', 'trash', WP_Error
58
* @param array $commentdata {

0 commit comments

Comments
 (0)