Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ras-acc): update newsletters palette on theme primary color updates #3083

Conversation

chickenn00dle
Copy link
Contributor

@chickenn00dle chickenn00dle commented Apr 23, 2024

All Submissions:

Changes proposed in this Pull Request:

Part of https://app.asana.com/0/1206943664367847/1205668937699542/f

This PR is meant to be reviewed alongside these newsletters changes: Automattic/newspack-newsletters#1487

These changes ensure we are updating the newsletter color palette option with the latest primary and secondary theme colors before creating transactional emails from templates OR before triggering an update to email HTML when updating a sites primary or secondary newspack theme colors.

How to test the changes in this Pull Request:

  1. With both the changes in the newsletters pr as well as this one checked out, go to Newspack > Engagement > Show advanced settings and reset the one time password email.
  2. Go to the post editor for the OTP email by selecting the edit link
  3. Confirm the social icons are filled either white or black depending on the color of the email footer (should be contrasting)
  4. Send a test email to yourself
  5. Confirm the social icons are also filled with the same color in the email
  6. Go to Newspack > Site Design and change the sites primary color to something of the opposite darkness/lightness than it previously was and save
  7. Go back to the OTP email edit page and confirm the social icons are now the opposite color than they were before (black or white)
  8. Send another test email to yourself
  9. Confirm the social icons are also filled with the same color in the email

Other information:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes, as applicable?
  • Have you successfully ran tests with your changes locally?

@chickenn00dle chickenn00dle marked this pull request as ready for review April 23, 2024 20:06
@chickenn00dle chickenn00dle requested a review from a team as a code owner April 23, 2024 20:06
@chickenn00dle chickenn00dle added the [Status] Needs Review The issue or pull request needs to be reviewed label Apr 23, 2024
@chickenn00dle chickenn00dle force-pushed the feat/update-newsletters-palette-for-transactional-emails branch from d4a8b22 to 725786b Compare April 25, 2024 14:32
Copy link
Member

@adekbadek adekbadek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After updating the theme color, the primary email color is visible when editing the email, but not in the sent email HTML.

@@ -488,6 +488,19 @@ public static function get_email_config_by_type( $type ) {
/** Only attempt to create the email post if wp-includes/pluggable.php is loaded. */
return false;
} else {
// Make sure newsletters color palette is updated with latest theme colors.
if ( self::supports_emails() ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Despite this check, the test are failing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah. I think this is because the Plugin_Manager downloads the latest release for newsletters, which does not yet have the required method:

'Download' => 'https://github.com/Automattic/newspack-newsletters/releases/latest/download/newspack-newsletters.zip',

I guess we can hold off on moving forward with this one until the next newsletters release.

@chickenn00dle
Copy link
Contributor Author

Thanks for testing this @adekbadek!

After updating the theme color, the primary email color is visible when editing the email, but not in the sent email HTML.

That's strange. I am seeing the colors change in both the editor as well as the email:

Screen.Recording.2024-05-07.at.15.03.20.mov

Are you resetting the email template once again after changing the primary/secondary colors by any chance?

@adekbadek
Copy link
Member

@chickenn00dle

Are you resetting the email template once again after changing the primary/secondary colors by any chance?

No. I tested by requesting the OTP as a reader, but when testing with the "Testing" sidebar panel (as on the video), the effect is the same. I've inspected the newspack_email_html post meta, and even after saving the post in the editor it still has the old color.

FWIW, I've found that on updating the theme color in the Site Design wizard, the first condition in the get_email_config_by_type is always satisfied, so Newspack_Newsletters::update_color_palette is never called.

@chickenn00dle chickenn00dle force-pushed the feat/update-newsletters-palette-for-transactional-emails branch 2 times, most recently from cd97ff6 to 132d897 Compare May 15, 2024 18:53
@chickenn00dle
Copy link
Contributor Author

chickenn00dle commented May 15, 2024

FWIW, I've found that on updating the theme color in the Site Design wizard, the first condition in the get_email_config_by_type is always satisfied, so Newspack_Newsletters::update_color_palette is never called.

Ah. We actually update the newsletters color palette in two places in this PR. The first is where you pointed out here, where we need to be sure the palette is updated with the latest before we initially create our email templates (after a template is reset for example).

The second is here:

if ( $previous_value['primary_color_hex'] !== $updated_value['primary_color_hex'] || $previous_value['secondary_color_hex'] !== $updated_value['secondary_color_hex'] ) {
// Update the newsletters color palette.
$updated = \Newspack_Newsletters::update_color_palette(
[
'primary' => $updated_value['primary_color_hex'],
'secondary' => $updated_value['secondary_color_hex'],
'primary-text' => newspack_get_color_contrast( $updated_value['primary_color_hex'] ),
'secondary-text' => newspack_get_color_contrast( $updated_value['secondary_color_hex'] ),
]
);

This triggers whenever the sites primary or secondary color are updated.

That said, I spoke with @dkoo about this and he pointed out the issue is actually related to a limitation with the mjml library in which newsletter HTML meta won't actually update unless the editor is open and the send/test button is clicked. Luckily, he was able to get a workaround for this added in 7463b3c

So this should be working as expected now, regardless of how you trigger the email after updating site color.

Copy link
Member

@adekbadek adekbadek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just noticed that maybe_update_email_templates will only be called if no child theme is used (due to get_template() use in the hook). The hook won't be called if a child theme is set, and so the email templates won't get updated.

@chickenn00dle
Copy link
Contributor Author

Just noticed that maybe_update_email_templates will only be called if no child theme is used (due to get_template() use in the hook). The hook won't be called if a child theme is set, and so the email templates won't get updated.

Good catch @adekbadek! I've fixed in 96aaf98

Copy link
Member

@adekbadek adekbadek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Child theme is now handled, but noticed a different issue 😬

'primary' => $theme_colors['primary_color'],
'secondary' => $theme_colors['secondary_color'],
'primary-text' => $theme_colors['primary_text_color'],
'secondary-text' => $theme_colors['secondary_text_color'],
Copy link
Member

@adekbadek adekbadek May 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

newspack_get_theme_colors does not return primary_text_color and secondary_text_color keys:

return [
'primary_color' => $primary_color,
'primary_text_color' => newspack_get_color_contrast( $primary_color ),
];

So it should be:

'primary-text'   => newspack_get_color_contrast( $theme_colors['primary_color'] ),
'secondary-text' => newspack_get_color_contrast( $theme_colors['secondary_color'] ),

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah! That's right. We removed the secondary color from the email templates, so now this should only reference primary_color and primary_text_color. I've updated in e898500.

Thanks for the keen eye!

@chickenn00dle chickenn00dle force-pushed the feat/update-newsletters-palette-for-transactional-emails branch from 96aaf98 to e898500 Compare May 17, 2024 14:49
@github-actions github-actions bot added [Status] Approved The pull request has been reviewed and is ready to merge and removed [Status] Needs Review The issue or pull request needs to be reviewed labels May 20, 2024
@chickenn00dle chickenn00dle changed the title Feat/update newsletters palette for transactional emails feat(ras-acc): update newsletters palette on theme primary color updates May 20, 2024
@chickenn00dle chickenn00dle merged commit a8a1f19 into epic/ras-acc May 20, 2024
8 checks passed
@chickenn00dle chickenn00dle deleted the feat/update-newsletters-palette-for-transactional-emails branch May 20, 2024 18:46
@matticbot
Copy link
Contributor

🎉 This PR is included in version 3.9.0-epic-ras-acc.4 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

@matticbot
Copy link
Contributor

🎉 This PR is included in version 4.1.0-epic-ras-acc.1 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

@matticbot
Copy link
Contributor

🎉 This PR is included in version 4.2.0-epic-ras-acc.1 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
released on @epic/ras-acc [Status] Approved The pull request has been reviewed and is ready to merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants