Moylgrove Mailshot
Send email about upcoming events
by Alan Cameron Wills · github.com/alancameronwills/moylgrove-mailshot
Install
No release zip yet. The repository archive installs, but the folder name will carry the branch suffix and updates will not flow:
wp plugin install https://github.com/alancameronwills/moylgrove-mailshot/archive/refs/heads/main.zipReadme
Moylgrove Events Mailshot - WordPress plugin
Creates a summary on MailChimp of events published on your website.
Built for https://moylgrove.wales
Website prerequisites
Assumptions about your WordPress site:
- There is an
eventcategory which contains the posts to be included in the mails - The site's repertoire of image sizes includes
medium - Each event is a post that has a title and a featured image
- ACF is installed, and the following fields are used:
expires- Date after which the event is no longer displayeddtstart- DateTime on which the event occurssubtitle- string, may be emptyprice- string, may be empty
Assumptions about your MailChimp account:
- You've set up a separate folder for the emails generated by this plugin
Keys
Requires a file 'MailChimpKeys.php' (not on GitHub) that contains MailChimp keys:
<?php
class MailChimpKeys {
protected const MailChimpKey = "XXXXX"; // API key provided by MailChimp
protected const MailChimpAuthorization = "Basic YYYYY"; //Authorization: base64 rendition of x:{MailChimpKey}
protected const MailChimpUrl = "https://ZZZZ.api.mailchimp.com/3.0/";
protected const FolderID = "MMMMM"; // MailChimp campaign folder for these generated emails
}
Easiest way of getting MailChimpAuthorization is to use curl:
curl --headers https://ZZZZ.api.mailchimp.com/3.0/ping --user x:XXXXX
where 'x' can be anything, including just 'x', and XXXXX is the MailChimpKey.
Look at the request header that curl sends, and copy the Authorization header.
Usage
Set up a page that won't be visible to the public - e.g. a post with "Uncategorized" category or Draft status.
Include in it a shortcode:
[ moylgrove_mailshot ]
View the page and you'll see a version of the email that will be generated.
Refresh the page with a query appended to the URL:
?test=1- Will send a test email?send=1- Sends to the default audience of the MailChimp account. Also deletes all previous mails in the folder.?ping=1- Tests the connection to MailChimp