INN / link-roundups

A WordPress plugin to make it easy to collect links from around the web, turn them into roundup posts and streamline the production of daily/weekly roundup newsletters using MailChimp. Built and maintained by INN Labs.
https://wordpress.org/plugins/link-roundups/
GNU General Public License v2.0
20 stars 4 forks source link

Update INN/wordpress-mailchimp-tools submodule, and diverse other updates #139

Closed benlk closed 5 years ago

benlk commented 5 years ago

Changes

This PR merges the last couple year's work from the WordPress Mailchimp Tools repo into this plugin. Resolves https://github.com/INN/link-roundups/issues/136

Notable change from https://github.com/INN/wordpress-mailchimp-tools/commits/master:

Also:

Testing

Can these steps still be followed? https://github.com/INN/link-roundups/blob/master/docs/mailchimp.md

Why

To address several PHP errors and notices in the WordPress MailChimp Tools.

To support the new version of the MailChimp API, introduced in 2017: https://mailchi.mp/f2bbb62b3016/were-shutting-down-api-11-12-and-13

benlk commented 5 years ago

@kaylima assigning this to you for several tasks:

  1. Install the plugin from this zip (this is the v0.5-rc1 tag created today): wp-release.zip
  2. Can the instructions at https://github.com/INN/link-roundups/blob/master/docs/mailchimp.md be followed with a testing Mailchimp account?
benlk commented 5 years ago

The WordPress Mailchimp API submodule https://bitbucket.org/mailchimp/mailchimp-api-php hasn't been updated since 2015.

The Mailchimp API settings block seen in https://github.com/INN/link-roundups/blob/136-update-wordpress-mailchimp-tools/docs/mailchimp.md isn't appearing, in my specific install, at this time. This appears to be because my install lacks the entire vendor/ directory of components, which was present in wp-release.zip above. I don't know where or how that came from, and git submodule update --init --recursive is failing to create at least one submodule that should be in the vendor/ directory.

Next steps:

benlk commented 5 years ago

Correction: the MailChimp settings page is no longer in Link Roundups > Options; it's in Settings > MailChimp Settings. This is true of both the pure-git-clone branch and the wp-release.zip install above.


Edited 2019-05-02 to add: This, too, was caused by https://github.com/INN/link-roundups/commit/675a1631f85cb056ca183206749e1cf60b9bc498's removal of a lot of code into the INN/wordpress-mailchimp-tools module

benlk commented 5 years ago

After enabling the MailChimp API key in the energynews.test site settings, the site begins timing out when trying to reach https://energynews.test/wp-admin/edit.php?post_type=roundup&page=roundup_mailchimp_settings

benlk commented 5 years ago

The timing-out page doesn't come from this plugin directly; it's generated by the WordPress MailChimp Tools:

https://github.com/INN/wordpress-mailchimp-tools/blob/04f246d463053693bcbd355fb23ec3533a7d27bb/inc/admin/class-mailchimp-post-type-settings.php#L21

I'm guessing this is because the API query to get the list of campaigns, which runs on every fetch of the page, is timing out:

https://github.com/INN/wordpress-mailchimp-tools/blob/04f246d463053693bcbd355fb23ec3533a7d27bb/inc/admin/class-mailchimp-post-type-settings.php#L43-L50

benlk commented 5 years ago

The Mailchimp Tools Settings Page only displays 10 templates; the account I'm testing with has more than 10.

benlk commented 5 years ago
benlk commented 5 years ago

Draft created? Yes. Send a drafted campaign? Yes. Campaign works as described? No.

Screen Shot 2019-05-01 at 21 32 13
benlk commented 5 years ago

So it looks like 675a1631f85cb056ca183206749e1cf60b9bc498 removed this bit by removing the entire inc/lroundups/mailchimp-admin.php:

function _lroundups_render_mailchimp_template( $source, $post ) {
    $author = get_user_by( 'id', $post->post_author );

    $tags = array(
        '*|ROUNDUPLINKS|*'      => apply_filters( 'the_content', $post->post_content ),
        '*|ROUNDUPTITLE|*'      => $post->post_title,
        '*|ROUNDUPAUTHOR|*'     => $author->display_name,
        '*|ROUNDUPDATE|*'       => get_the_date( '',$post->ID ),
        '*|ROUNDUPPERMALINK|*'  => get_post_permalink( $post->ID )
    );

    foreach ( $tags as $tag => $value )
        $source = str_replace( $tag, $value, $source );

    return $source;
}

That commit just outright removed the file, and the file doesn't appear to have been replaced. Nor was the functionality in there.

That was release v0.4.

I remember us having bug reports about it, but I can't find an issue for it.

benlk commented 5 years ago

In https://secure.helpscout.net/conversation/573233977/1940?folderId=1259183 on May 30, 2018:

I wanted to make sure that MailChimp merge tags worked, and they do in the single-column templates we were experimenting with (Sherry made one and I made an additional one to troubleshoot). Neither will pull in the link roundup tags. I tried in caps and in all lowercase in case it was a syntax error on my part. None of the other link roundup tags were working for me either (*|ROUNDUPAUTHOR|*, etc.). Do you have any idea of where we went wrong?

https://github.com/INN/link-roundups/issues/146

benlk commented 5 years ago

146 should be fixable by re-adding that removed function.

What's not clear there yet is:

benlk commented 5 years ago

The removed function was applied here:

        /** 
         * Replace the template tags in the MailChimp post  
         */ 
        $html = _lroundups_render_mailchimp_template( $template_info['source'], $post );    
        $campaign_content = array(  
            'html' => $html, // the content!    
            'text' => '' // Leave blank for the auto-generated text content 
        );

The analogous functionality in the current WP MC Tools is:

https://github.com/INN/wordpress-mailchimp-tools/blob/0ff5674b85b8604895a1022c9d0c7f83cf3a0c10/inc/admin/class-mailchimp-campaign-editor.php#L234-L242

But there's no way to configure the parameters that are set on that email. So:

benlk commented 5 years ago

It is currently creating the email, but entirely replacing the content of the email with the *|ROUNDUPLINKS|* content rather than filling the template areas. This should be investigated.

Right now it's using a drag-and-drop template with a block that contains the following:

This should be the roundup title:
<section mc:edit="ROUNDUPTITLE">This should be replaced with the roundup title</section>
This should be the roundup author:

<section mc:edit="ROUNDUPAUTHOR">This should be replaced with the roundup author</section>
This should be the roundup date:

<section mc:edit="ROUNDUPDATE">This should be replaced with the roundup date</section>
This should be the roundup links:

<section mc:edit="ROUNDUPLINKS">This should be replaced with the roundup links</section>
This should be the roundup permalink:

<section mc:edit="ROUNDUPPERMALINK">This should be replaced with the roundup permalink</section>

<hr />
<h1 style="text-align: center;">*|ROUNDUPTITLE|*</h1>

<p><em>*|ROUNDUPAUTHOR|* &mdash; *|ROUNDUPDATE|*</em></p>
*|ROUNDUPLINKS|*

<p>Originally posted at *|ROUNDUPPERMALINK|*</p>
benlk commented 5 years ago

It's not possible to get the whole default content of a template via the API.

The closest thing is https://developer.mailchimp.com/documentation/mailchimp/reference/templates/default-content/, which returns the default content of the various editable areas defined in the template, but not the whole body content of the campaign. Therefore, the approach taken in the previous version of the WordPress MailChimp Tools to set the $html parameter to the post content will not work for the Link Roundup Plugin's purposes.

The filter introduced in https://github.com/INN/wordpress-mailchimp-tools/commit/4e768f7661a2fe8fc2785140e8313280eb230c3f will have to be used to set the HTML parameter on the campaign content, if the user of the WMT package desires to have that set.

Because the whole content cannot be accessed, the idea of filtering that content for the various merge tags in this plugin to do a search and replace for this plugin's desired content output is no longer valid.

benlk commented 5 years ago

It worked. https://us1.admin.mailchimp.com/reports/show?id=2907321

benlk commented 5 years ago

Consolidating earlier checklists:

benlk commented 5 years ago
benlk commented 5 years ago

🎉

Next step: Someone please test that this works for them.