Hooks, Filters and Shortcodes
MailerHive keeps its settings screen short and leaves the edge cases to code. If you need a different set of share networks, extra lists for some issues or a badge on certain titles, a filter does it without touching the plugin.
Put these snippets in a small custom plugin or your snippets plugin, not in the theme. Theme isolation keeps your theme’s code off MailerHive pages.
Filters
| Filter | Arguments | What it changes |
|---|---|---|
mailerhive_share_networks | array $nets, WP_Post $post | The share bar. Each entry is key => [label, icon, url]. Return an empty array to hide the bar |
mailerhive_draft_list_ids | array $list_ids, WP_Post $post | The MailerPress lists an issue’s draft goes to |
mailerhive_mirror_list_ids | array $list_ids | The lists that make a sent campaign eligible for mirroring |
mailerhive_issue_badge | string $html, WP_Post $post | Markup after an issue title in the archive, on the newsletter page and in [mailerhive_issues] |
mailerhive_issue_body | null, WP_Post $post | Return HTML to replace an issue’s body on its page |
mailerhive_theme_roots | array $roots | The folders theme isolation treats as your theme |
Actions
| Action | Arguments | When it fires |
|---|---|---|
mailerhive_issue_mirrored | int $post_id, array $list_ids | After a MailerPress campaign becomes an issue, before its content is saved |
mailerhive_issue_meta_box | WP_Post $post | Inside the Issue details box, to add your own fields |
mailerhive_issue_meta_save | int $post_id | When the Issue details box is saved |
mailerhive_landing_after_hero | none | On the newsletter page, after the signup card |
Change the Share Networks
Share URLs accept http, https and mailto addresses. Icons come from MailerHive’s assets/icons folder by name, such as link, mail or news.
add_filter( 'mailerhive_share_networks', function ( array $nets, WP_Post $post ): array {
unset( $nets['whatsapp'], $nets['threads'] );
$nets['hackernews'] = array(
'Hacker News',
'news',
'https://news.ycombinator.com/submitlink?u=' . rawurlencode( get_permalink( $post ) ) . '&t=' . rawurlencode( get_the_title( $post ) ),
);
return $nets;
}, 10, 2 );
Send Some Issues to Another List
add_filter( 'mailerhive_draft_list_ids', function ( array $lists, WP_Post $post ): array {
if ( has_term( 'announcements', 'post_tag', $post ) ) {
$lists[] = 12; // a MailerPress list ID
}
return $lists;
}, 10, 2 );
Issues don’t have tags by default, so adapt the condition to whatever marks those issues on your site, such as a custom field.
Add a Badge to Some Titles
add_filter( 'mailerhive_issue_badge', function ( string $html, WP_Post $post ): string {
if ( get_post_meta( $post->ID, 'featured_issue', true ) ) {
$html .= ' <span class="my-badge">Featured</span>';
}
return $html;
}, 10, 2 );
Shortcodes
| Shortcode | Attributes | Output |
|---|---|---|
[mailerhive_issues] | limit, default 6 | The latest issues as a list |
[mailerhive_plans] | tier, heading | Paid plan cards. Needs the paid module |
[mailerhive_account] | none | The reader’s paid access, or the reading link form. Needs the paid module |
Reading links and the account box covers the 2 paid shortcodes in detail.
Constants
MAILERHIVE_VERSION, MAILERHIVE_FILE, MAILERHIVE_DIR and MAILERHIVE_URL are defined when the plugin loads. Check defined( 'MAILERHIVE_VERSION' ) before calling MailerHive from another plugin.