Skip to content

feat: Add Mailchimp Campaign Archive block and shortcode (#811)#829

Open
faisalahammad wants to merge 3 commits intoibericode:mainfrom
faisalahammad:feature/811-campaign-archive-block
Open

feat: Add Mailchimp Campaign Archive block and shortcode (#811)#829
faisalahammad wants to merge 3 commits intoibericode:mainfrom
faisalahammad:feature/811-campaign-archive-block

Conversation

@faisalahammad
Copy link
Copy Markdown
Contributor

@faisalahammad faisalahammad commented Mar 23, 2026

Summary

Adds a new shortcode [mc4wp_campaigns] and a native Gutenberg block to display an archive of sent Mailchimp campaigns directly on a WordPress site.

Fixes #811

Problem

Users currently lack an official, built-in way to display their Mailchimp campaign history on their sites without relying on third-party plugins or manual embeds.

Solution

Implemented a WordPress shortcode and a Gutenberg block that fetch and render the user's sent campaigns. We use the existing MC4WP_API_V3 wrapper and transient caching to ensure performance and prevent rate-limiting.

Changes

includes/campaigns/class-archive.php

Before:

// File didn't exist

After:

public function shortcode($attributes = []) {
    // ...
    $campaigns = $this->get_campaigns($count);
    if (empty($campaigns) || ! is_array($campaigns)) {
        return is_string($campaigns) ? $campaigns : '';
    }
    // ...
}

Why: Centralized logic for both the shortcode and server-side block rendering. It correctly extracts the campaigns array from the API response object and leverages transient caching.

assets/src/js/campaigns-block.js

Before:

// File didn't exist

After:

edit: function ({ attributes, setAttributes }) {
    return (
      <div>
        <InspectorControls>
          // ...
        </InspectorControls>
        // ...
      </div>
    )
}

Why: Registers editor UI that aligns with mailchimp-for-wp standards. It is explicitly wrapped in standard <div> instead of React Fragment <> syntax to guarantee @babel/preset-env compatibility during compilation.

Testing

Test 1: Shortcode Rendering
Steps:

  1. Added [mc4wp_campaigns]
  2. Verified shortcode maps settings correctly
  3. Cached on load

Result: Works as expected

Test 2: Transient Caching & API Errors
Steps:

  1. Disconnected API
  2. View frontend
  3. Handled gracefully with HTML debug comment for admins only

Result: Handled correctly

Automated:

$ composer run-script test
OK (62 tests, 190 assertions)

$ vendor/bin/phpcs -n -s
Exit code: 0

Build

mailchimp-for-wp-feature-811.zip available for manual testing
Install: WP Admin → Plugins → Upload

Screenshot

image image

@faisalahammad faisalahammad force-pushed the feature/811-campaign-archive-block branch from 3b58b21 to 47b316b Compare March 23, 2026 04:53
@faisalahammad faisalahammad force-pushed the feature/811-campaign-archive-block branch from 4e7ee98 to fb9b13a Compare March 23, 2026 05:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature: Block showing archive of Mailchimp campaigns

1 participant