Skip to content

Commit

Permalink
Merge pull request #181 from alleyinteractive/feature/LEDE-2719/updat…
Browse files Browse the repository at this point in the history
…e-newsletter-builder-and-fixes

LEDE-2719: Update Newsletter Builder Version + Minor Fixes
  • Loading branch information
xmattus authored Sep 5, 2024
2 parents 2fccf9f + 01c9fad commit 6c81180
Show file tree
Hide file tree
Showing 23 changed files with 28 additions and 200 deletions.
9 changes: 0 additions & 9 deletions blocks/button/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,6 @@
* @see https://developer.wordpress.org/reference/functions/register_block_type/
*/
function wp_newsletter_builder_button_block_init(): void {
/**
* Filters whether to register the block.
*
* @param bool $register Whether to register the block. Default true.
* @param string $name Block name.
*/
if ( ! apply_filters( 'wp_newsletter_builder_register_block', true, 'button' ) ) {
return;
}
// Register the block by passing the location of block.json.
register_block_type(
__DIR__
Expand Down
9 changes: 0 additions & 9 deletions blocks/divider/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,6 @@
* @see https://developer.wordpress.org/reference/functions/register_block_type/
*/
function wp_newsletter_builder_divider_block_init(): void {
/**
* Filters whether to register the block.
*
* @param bool $register Whether to register the block. Default true.
* @param string $name Block name.
*/
if ( ! apply_filters( 'wp_newsletter_builder_register_block', true, 'divider' ) ) {
return;
}
// Register the block by passing the location of block.json.
register_block_type(
__DIR__
Expand Down
1 change: 1 addition & 0 deletions blocks/email-settings/edit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ export default function Edit() {
value={suppressionGroup}
options={suppressionLists.map((item) => ({ label: item.Name, value: item.ListID }))}
onChange={(newValue: string) => setMeta({ nb_newsletter_suppression_group: newValue })}
required
/>
) : (
/* @ts-ignore */
Expand Down
9 changes: 0 additions & 9 deletions blocks/email-settings/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,6 @@
* @see https://developer.wordpress.org/reference/functions/register_block_type/
*/
function wp_newsletter_builder_email_settings_block_init(): void {
/**
* Filters whether to register the block.
*
* @param bool $register Whether to register the block. Default true.
* @param string $name Block name.
*/
if ( ! apply_filters( 'wp_newsletter_builder_register_block', true, 'email-settings' ) ) {
return;
}
// Register the block by passing the location of block.json.
register_block_type(
__DIR__
Expand Down
9 changes: 0 additions & 9 deletions blocks/footer/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,6 @@
* @see https://developer.wordpress.org/reference/functions/register_block_type/
*/
function wp_newsletter_builder_footer_block_init(): void {
/**
* Filters whether to register the block.
*
* @param bool $register Whether to register the block. Default true.
* @param string $name Block name.
*/
if ( ! apply_filters( 'wp_newsletter_builder_register_block', true, 'footer' ) ) {
return;
}
// Register the block by passing the location of block.json.
register_block_type(
__DIR__
Expand Down
9 changes: 0 additions & 9 deletions blocks/header/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,6 @@
* @see https://developer.wordpress.org/reference/functions/register_block_type/
*/
function wp_newsletter_builder_header_block_init(): void {
/**
* Filters whether to register the block.
*
* @param bool $register Whether to register the block. Default true.
* @param string $name Block name.
*/
if ( ! apply_filters( 'wp_newsletter_builder_register_block', true, 'header' ) ) {
return;
}
// Register the block by passing the location of block.json.
register_block_type(
__DIR__
Expand Down
9 changes: 0 additions & 9 deletions blocks/heading/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,6 @@
* @see https://developer.wordpress.org/reference/functions/register_block_type/
*/
function wp_newsletter_builder_heading_block_init(): void {
/**
* Filters whether to register the block.
*
* @param bool $register Whether to register the block. Default true.
* @param string $name Block name.
*/
if ( ! apply_filters( 'wp_newsletter_builder_register_block', true, 'heading' ) ) {
return;
}
// Register the block by passing the location of block.json.
register_block_type(
__DIR__
Expand Down
9 changes: 0 additions & 9 deletions blocks/list/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,6 @@
* @see https://developer.wordpress.org/reference/functions/register_block_type/
*/
function wp_newsletter_builder_list_block_init(): void {
/**
* Filters whether to register the block.
*
* @param bool $register Whether to register the block. Default true.
* @param string $name Block name.
*/
if ( ! apply_filters( 'wp_newsletter_builder_register_block', true, 'list' ) ) {
return;
}
// Register the block by passing the location of block.json.
register_block_type(
__DIR__
Expand Down
9 changes: 0 additions & 9 deletions blocks/paragraph/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,6 @@
* @see https://developer.wordpress.org/reference/functions/register_block_type/
*/
function wp_newsletter_builder_paragraph_block_init(): void {
/**
* Filters whether to register the block.
*
* @param bool $register Whether to register the block. Default true.
* @param string $name Block name.
*/
if ( ! apply_filters( 'wp_newsletter_builder_register_block', true, 'paragraph' ) ) {
return;
}
// Register the block by passing the location of block.json.
register_block_type(
__DIR__
Expand Down
9 changes: 0 additions & 9 deletions blocks/post-byline/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,6 @@
* @see https://developer.wordpress.org/reference/functions/register_block_type/
*/
function wp_newsletter_builder_post_byline_block_init(): void {
/**
* Filters whether to register the block.
*
* @param bool $register Whether to register the block. Default true.
* @param string $name Block name.
*/
if ( ! apply_filters( 'wp_newsletter_builder_register_block', true, 'post-byline' ) ) {
return;
}
// Register the block by passing the location of block.json.
register_block_type(
__DIR__
Expand Down
9 changes: 0 additions & 9 deletions blocks/post-content/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,6 @@
* @see https://developer.wordpress.org/reference/functions/register_block_type/
*/
function wp_newsletter_builder_post_content_block_init(): void {
/**
* Filters whether to register the block.
*
* @param bool $register Whether to register the block. Default true.
* @param string $name Block name.
*/
if ( ! apply_filters( 'wp_newsletter_builder_register_block', true, 'post-content' ) ) {
return;
}
// Register the block by passing the location of block.json.
register_block_type(
__DIR__
Expand Down
9 changes: 0 additions & 9 deletions blocks/post-excerpt/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,6 @@
* @see https://developer.wordpress.org/reference/functions/register_block_type/
*/
function wp_newsletter_builder_post_excerpt_block_init(): void {
/**
* Filters whether to register the block.
*
* @param bool $register Whether to register the block. Default true.
* @param string $name Block name.
*/
if ( ! apply_filters( 'wp_newsletter_builder_register_block', true, 'post-excerpt' ) ) {
return;
}
// Register the block by passing the location of block.json.
register_block_type(
__DIR__
Expand Down
9 changes: 0 additions & 9 deletions blocks/post-featured-image/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,6 @@
* @see https://developer.wordpress.org/reference/functions/register_block_type/
*/
function wp_newsletter_builder_post_featured_image_block_init(): void {
/**
* Filters whether to register the block.
*
* @param bool $register Whether to register the block. Default true.
* @param string $name Block name.
*/
if ( ! apply_filters( 'wp_newsletter_builder_register_block', true, 'post-featured-image' ) ) {
return;
}
// Register the block by passing the location of block.json.
register_block_type(
__DIR__
Expand Down
9 changes: 0 additions & 9 deletions blocks/post-item/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,6 @@
* @see https://developer.wordpress.org/reference/functions/register_block_type/
*/
function wp_newsletter_builder_post_item_block_init(): void {
/**
* Filters whether to register the block.
*
* @param bool $register Whether to register the block. Default true.
* @param string $name Block name.
*/
if ( ! apply_filters( 'wp_newsletter_builder_register_block', true, 'post-item' ) ) {
return;
}
// Register the block by passing the location of block.json.
register_block_type(
__DIR__
Expand Down
9 changes: 0 additions & 9 deletions blocks/post-read-more/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,6 @@
* @see https://developer.wordpress.org/reference/functions/register_block_type/
*/
function wp_newsletter_builder_post_read_more_block_init(): void {
/**
* Filters whether to register the block.
*
* @param bool $register Whether to register the block. Default true.
* @param string $name Block name.
*/
if ( ! apply_filters( 'wp_newsletter_builder_register_block', true, 'post-read-more' ) ) {
return;
}
// Register the block by passing the location of block.json.
register_block_type(
__DIR__
Expand Down
9 changes: 0 additions & 9 deletions blocks/post-title/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,6 @@
* @see https://developer.wordpress.org/reference/functions/register_block_type/
*/
function wp_newsletter_builder_post_title_block_init(): void {
/**
* Filters whether to register the block.
*
* @param bool $register Whether to register the block. Default true.
* @param string $name Block name.
*/
if ( ! apply_filters( 'wp_newsletter_builder_register_block', true, 'post-title' ) ) {
return;
}
// Register the block by passing the location of block.json.
register_block_type(
__DIR__
Expand Down
9 changes: 0 additions & 9 deletions blocks/post/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,6 @@
* @see https://developer.wordpress.org/reference/functions/register_block_type/
*/
function wp_newsletter_builder_post_block_init(): void {
/**
* Filters whether to register the block.
*
* @param bool $register Whether to register the block. Default true.
* @param string $name Block name.
*/
if ( ! apply_filters( 'wp_newsletter_builder_register_block', true, 'post' ) ) {
return;
}
// Register the block by passing the location of block.json.
register_block_type(
__DIR__
Expand Down
9 changes: 0 additions & 9 deletions blocks/section/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,6 @@
* @see https://developer.wordpress.org/reference/functions/register_block_type/
*/
function wp_newsletter_builder_section_block_init(): void {
/**
* Filters whether to register the block.
*
* @param bool $register Whether to register the block. Default true.
* @param string $name Block name.
*/
if ( ! apply_filters( 'wp_newsletter_builder_register_block', true, 'section' ) ) {
return;
}
// Register the block by passing the location of block.json.
register_block_type(
__DIR__
Expand Down
9 changes: 0 additions & 9 deletions blocks/two-up-post/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,6 @@
* @see https://developer.wordpress.org/reference/functions/register_block_type/
*/
function wp_newsletter_builder_two_up_post_block_init(): void {
/**
* Filters whether to register the block.
*
* @param bool $register Whether to register the block. Default true.
* @param string $name Block name.
*/
if ( ! apply_filters( 'wp_newsletter_builder_register_block', true, 'two-up-post' ) ) {
return;
}
// Register the block by passing the location of block.json.
register_block_type(
__DIR__
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.4.1
* Version: 0.4.2
* Author: Alley Interactive
* Author URI: https://github.com/alleyinteractive/wp-newsletter-builder
* Requires at least: 6.2
Expand Down
29 changes: 25 additions & 4 deletions plugins/pre-publish-checks/pre-publish-panel.tsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,40 @@
import { PluginPrePublishPanel } from '@wordpress/edit-post';
import { useDispatch, useSelect } from '@wordpress/data';
import { __ } from '@wordpress/i18n';
import { usePostMetaValue } from '@alleyinteractive/block-editor-tools';

const SUPPRESSION_ID_LOCK = 'suppression-group-id-lock';
const TITLE_LOCK = 'title-empty-lock';

function PrePublishPanel() {
// @ts-ignore
const postTitle = useSelect((select) => select('core/editor').getEditedPostAttribute('title'));
const [supressionGroupId] = usePostMetaValue('nb_newsletter_suppression_group');
const isTitleOk = postTitle.trim().length > 0;

const { lockPostSaving, unlockPostSaving } = useDispatch('core/editor');
const { createWarningNotice, removeNotice } = useDispatch('core/notices');

if (!isTitleOk) {
lockPostSaving('title-empty-lock');
lockPostSaving(TITLE_LOCK);
createWarningNotice(
__('Please enter a newsletter title before publishing.', 'wp-newsletter-builder'),
{ id: 'title-empty-lock', isDismissible: false },
{ id: TITLE_LOCK, isDismissible: false },
);
} else {
unlockPostSaving(TITLE_LOCK);
removeNotice(TITLE_LOCK);
}

if (!supressionGroupId) {
lockPostSaving(SUPPRESSION_ID_LOCK);
createWarningNotice(
__('Please select a suppression group before publishing.', 'wp-newsletter-builder'),
{ id: SUPPRESSION_ID_LOCK, isDismissible: false },
);
} else {
unlockPostSaving('title-empty-lock');
removeNotice('title-empty-lock');
unlockPostSaving(SUPPRESSION_ID_LOCK);
removeNotice(SUPPRESSION_ID_LOCK);
}

return (
Expand All @@ -31,6 +47,11 @@ function PrePublishPanel() {
? __('All headline requirements are met.', 'wp-newsletter-builder')
: __('Headline is required before publishing.', 'wp-newsletter-builder')}
</p>
<p>
{supressionGroupId
? __('Suppression group selected.', 'wp-newsletter-builder')
: __('Suppression group is required before publishing.', 'wp-newsletter-builder')}
</p>
</PluginPrePublishPanel>
);
}
Expand Down
Loading

0 comments on commit 6c81180

Please sign in to comment.