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

Feature: SendGrid Provider Updates #118

Merged
merged 9 commits into from
May 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

All notable changes to `Newsletter Builder` will be documented in this file.

## 0.3.11 - 2024-05-09

- Adds a `NewsletterSpinner` wrapper component for the `<Spinner />` component from `@wordpress/components`
- [see link to GitHub issue](https://github.com/WordPress/gutenberg/issues/61322)
- Change `nb_newsletter_template` post meta from type `string` to type `number`
- Change SendGrid Provider to send `suppression_group_id` and remove sending `custom_unsubscribe_url`
Copy link
Collaborator

Choose a reason for hiding this comment

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

FYI: #108


## 0.3.10 - 2024-05-06

- Removes instances of `@phpstan-ignore-next-line the Fieldmanager doc block is incorrect` which are unnecessary now that WordPress Fieldmanager doc blocks have been updated
Expand Down
11 changes: 11 additions & 0 deletions components/newsletterSpinner/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { Spinner } from '@wordpress/components';

/**
* Wrapper for the spinner component.
*
* @see https://github.com/WordPress/gutenberg/issues/61322
*/
export default function NewsletterSpinner() {
// @ts-ignore
return <Spinner />;
}
2 changes: 1 addition & 1 deletion config/post-meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"post_types": [
"nb_newsletter"
],
"type": "string"
"type": "number"
},
"nb_newsletter_from_name": {
"post_types": [
Expand Down
2 changes: 1 addition & 1 deletion plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Plugin Name: Newsletter Builder
* Plugin URI: https://github.com/alleyinteractive/wp-newsletter-builder
* Description: Interface to manage email newsletters
* Version: 0.3.10
* Version: 0.3.11
* Author: Alley Interactive
* Author URI: https://github.com/alleyinteractive/wp-newsletter-builder
* Requires at least: 6.2
Expand Down
4 changes: 2 additions & 2 deletions plugins/newsletter-from-post/email-settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { PluginSidebar } from '@wordpress/edit-post';
import {
PanelBody,
TextareaControl,
Spinner,
CheckboxControl,
} from '@wordpress/components';
import { __ } from '@wordpress/i18n';
Expand All @@ -17,6 +16,7 @@ import { usePostMeta } from '@alleyinteractive/block-editor-tools';
import { MultiSelect } from 'react-multi-select-component';
import { parse, serialize } from '@wordpress/blocks';

import NewsletterSpinner from '@/components/newsletterSpinner';
import EmailTypeSelector from '../../components/emailTypeSelector';
import SentNewsletter from './sent-newsletter';

Expand Down Expand Up @@ -191,7 +191,7 @@ function EmailSettings() {
/>
</label>
) : (
<Spinner />
<NewsletterSpinner />
)}
<div style={{ marginTop: '1rem' }}>
<CheckboxControl
Expand Down
5 changes: 3 additions & 2 deletions plugins/newsletter-status/newsletterStatusPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import { PluginDocumentSettingPanel } from '@wordpress/edit-post';
import { __ } from '@wordpress/i18n';
import { select } from '@wordpress/data';
import apiFetch from '@wordpress/api-fetch';
import { Button, Spinner } from '@wordpress/components';
import { Button } from '@wordpress/components';
import NewsletterSpinner from '@/components/newsletterSpinner';

interface Status {
Bounced?: number;
Expand Down Expand Up @@ -99,7 +100,7 @@ export default function NewsletterStatusPanel() {
</Button>
</>
) : (
<Spinner />
<NewsletterSpinner />
)}
</PluginDocumentSettingPanel>
);
Expand Down
2 changes: 1 addition & 1 deletion src/class-email-types.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function register_fields(): void {
* @return array<string> The sanitized values.
*/
public function presave( $value, $current_value = [] ) {
return $current_value ?: [ wp_generate_uuid4() ];
return $current_value ?: wp_generate_uuid4();
}
},
'label' => new \Fieldmanager_TextField( __( 'Label', 'wp-newsletter-builder' ) ),
Expand Down
4 changes: 2 additions & 2 deletions src/class-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,9 @@ public function get_footer_settings(): array|false {
* @return array<string>|false
*/
public function get_from_names(): array|false {
$settings = get_option( static::SETTINGS_KEY );
$settings = get_option( static::SETTINGS_KEY, [] );
if ( empty( $settings ) || ! is_array( $settings ) || empty( $settings['from_names'] ) || ! is_array( $settings['from_names'] ) ) {
return false;
$settings['from_names'] = [];
}

return apply_filters( 'wp_newsletter_builder_from_names', $settings['from_names'] );
Expand Down
17 changes: 8 additions & 9 deletions src/email-providers/class-sendgrid.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public function create_campaign( int $newsletter_id, array $list_ids, string $ca
return false;
}
foreach ( $body as $sender ) {
if ( sprintf( '%s <%s>', $sender->from->name, $sender->from->email ) === $from_name ) {
if ( sprintf( '%s (%s)', $sender->from->name, $sender->from->email ) === $from_name ) {
$sender_id = $sender->id;
break;
}
Expand All @@ -164,19 +164,18 @@ public function create_campaign( int $newsletter_id, array $list_ids, string $ca
$text_content = wp_strip_all_tags( $html_content );
$subject = get_post_meta( $newsletter_id, 'nb_newsletter_subject', true );

$request_body = (object) [];
$request_body->name = get_the_title( $newsletter_id );
$request_body->categories = [];
$request_body->email_config = (object) [];
$request_body->send_to = (object) [];
// $request_body->email_config->custom_unsubscribe_url = '';
$request_body = (object) [];
$request_body->name = get_the_title( $newsletter_id );
$request_body->categories = [];
$request_body->email_config = (object) [];
$request_body->send_to = (object) [];
$request_body->email_config->html_content = $html_content;
$request_body->email_config->ip_pool = null;
$request_body->email_config->plain_content = $text_content;
$request_body->email_config->generate_plain_content = true;
$request_body->email_config->sender_id = $sender_id ?? 0;
$request_body->email_config->subject = $subject;
$request_body->email_config->suppression_group_id = get_post_meta( $newsletter_id, 'nb_newsletter_suppression_group', true );
$request_body->email_config->suppression_group_id = (int) get_post_meta( $newsletter_id, 'nb_newsletter_suppression_group', true );

$request_body->send_to->list_ids = $list_ids;
$request_body->send_to->segment_ids = [];
Expand Down Expand Up @@ -362,7 +361,7 @@ private function get_senders(): array {
return [];
}
foreach ( $body as $sender ) {
$senders[] = sprintf( '%s <%s>', $sender->from->name, $sender->from->email );
$senders[] = sprintf( '%s (%s)', $sender->from->name, $sender->from->email );
}
return $senders;
}
Expand Down