manifest / unclassified / mailchimp-cpt
Mailchimp CPT Importer
WordPress plugin that imports a newsletter from a public URL, such as a Mailchimp campaign page, into a Newsletter CPT.
by Rolando Escobar · github.com/rolandototo/mailchimp-cpt · website
★ 0stars
0forks
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/rolandototo/mailchimp-cpt/archive/refs/heads/main.zipA WordPress plugin that imports a newsletter from a public web page, such as a Mailchimp campaign archive page, into a Newsletter custom post type. Each import is saved as a draft so you can review it before publishing.
It reads the public HTML page, so you don't need a Mailchimp API key.
Features
- Newsletter post type: registers a public
newsletterpost type with an archive at/newsletter/. It supports a title, the editor, a featured image and an excerpt. Rewrite rules are flushed on activation, so the URLs work right away. - Import screen: adds Newsletters > Import Newsletter, a form with one URL field. It's available to administrators (
manage_options), and the request is checked with a nonce and the same capability. - Automatic mapping: fetches the page with
wp_safe_remote_get(), parses it withDOMDocumentand fills in the post:- Title: the page's
<title>, then its first<h1>, then "Newsletter imported on (date)" - Content: the inner HTML of
<body>, without scripts, styles or meta tags, filtered withwp_kses_post(). Relative image and link URLs are made absolute. - Excerpt: the first paragraph with text, trimmed to 55 words
- Featured image: the first image on the page, downloaded into the Media Library and attached to the post
- Title: the page's
- Drafts only: imported newsletters are saved as drafts. The success message links straight to the draft; errors (bad URL, HTTP error, empty page) are shown on the same screen.
Requirements
- WordPress 6.0+
- PHP 7.4+ with the
domextension, which most hosts enable by default - The server must be able to make outbound HTTP requests to the newsletter URL.
Installation
- Download this repository as a ZIP (Code > Download ZIP).
- In WordPress, go to Plugins > Add New > Upload Plugin, upload the ZIP and activate Mailchimp CPT Importer.
Or clone it into wp-content/plugins/.
Usage
- Open a campaign in your browser and copy its public URL (for example, the "View this email in your browser" link of a Mailchimp campaign).
- In WordPress, go to Newsletters > Import Newsletter.
- Paste the URL and click Import Newsletter.
- Click Review and publish it in the success message, check the draft and publish it.
Limitations
- The body keeps the email's layout tables and inline styles, so the post looks like the email.
wp_kses_post()may drop some inline CSS properties. - The first image on the page becomes the featured image, even if it's a logo.
- Only the featured image is downloaded. Other images in the content still load from the original host (for Mailchimp, its CDN).
- URLs on local or private networks are refused, because the plugin fetches with
wp_safe_remote_get(). - It imports one URL at a time.
Changelog
0.2.0
- Success and error messages now appear on the import screen.
- The import checks the
manage_optionscapability, not just the nonce. - Rewrite rules are flushed on activation, so
/newsletter/no longer returns 404 until permalinks are saved. - Cleaner content: no
<body>tag, scripts or styles, and relative URLs are made absolute. - Title and featured image fallbacks. Pages without a charset are read as UTF-8.
- The admin CSS loads only on the import screen. The text domain is now
mailchimp-cpt.
0.1.1
- Imported newsletters are saved as drafts.
File structure
mailchimp-cpt.php Main plugin file (loads includes, activation hooks, admin styles)
includes/cpt-newsletter.php Registers the "newsletter" post type
includes/mailchimp-importer.php Fetches, parses and imports a newsletter URL
admin/import-page.php "Import Newsletter" screen and form handler
assets/css/admin-style.css Admin styles
readme.txt WordPress-style readme
LICENSE GNU GPL v2
Author
Rolando Escobar, WordPress developer. rolandowp.com
License
GPL-2.0-or-later. See LICENSE.