Skip to content

Commit

Permalink
Merge pull request #118 from alleyinteractive/feature/sendgrid-provid…
Browse files Browse the repository at this point in the history
…er-updates

Feature: SendGrid Provider Updates
  • Loading branch information
efuller authored May 9, 2024
2 parents 7e50d63 + 793f593 commit e4543ed
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 18 deletions.
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`

## 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();

Check failure on line 64 in src/class-email-types.php

View workflow job for this annotation

GitHub Actions / phpstan / phpstan PHP 8.2

Method class@anonymous/src/class-email-types.php:55::presave() should return array<string> but returns array<string>|string.
}
},
'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'] = [];

Check failure on line 182 in src/class-settings.php

View workflow job for this annotation

GitHub Actions / phpstan / phpstan PHP 8.2

Cannot access offset 'from_names' on mixed.
}

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 );

Check failure on line 178 in src/email-providers/class-sendgrid.php

View workflow job for this annotation

GitHub Actions / phpstan / phpstan PHP 8.2

Cannot cast mixed to int.

$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

0 comments on commit e4543ed

Please sign in to comment.