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

epic: consolidate newsletter editor data and UI #1658

Merged
merged 54 commits into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from 51 commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
1371bac
feat: make "Send To" UI autocomplete instead of dropdowns (#1577)
dkoo Aug 2, 2024
c83f3b2
Merge branch 'trunk' into epic/update-editor-uis
dkoo Aug 2, 2024
7a43381
Merge branch 'trunk' into epic/update-editor-uis
dkoo Aug 2, 2024
a4bbe2a
Merge branch 'trunk' into epic/update-editor-uis
miguelpeixe Aug 12, 2024
0762860
fix(editor): render notice on sync error (#1606)
miguelpeixe Aug 14, 2024
7bc6ff5
fix(mailchimp): improve sync error messages (#1619)
miguelpeixe Aug 16, 2024
612741e
fix(activecampaign): default message on request error (#1618)
miguelpeixe Aug 16, 2024
6936113
Merge branch 'trunk' into epic/update-editor-uis
dkoo Aug 19, 2024
f07b7b3
Merge branch 'trunk' into epic/update-editor-uis
miguelpeixe Aug 26, 2024
05c1e23
Merge branch 'trunk' into epic/update-editor-uis
dkoo Aug 28, 2024
2df6fef
feat: cross-ESP send-lists
dkoo Aug 29, 2024
7c0d36a
refactor: move API namespace and permission callback to main class
dkoo Aug 29, 2024
92b3348
feat: support send lists in provider classes
dkoo Aug 29, 2024
b729290
feat: refactor editor JS to use new standardized data
dkoo Aug 29, 2024
93dc8c5
fix: ensure Newsletters plugin blocks are grouped under Newspack cate…
dkoo Sep 3, 2024
00006cd
feat: send list classes (#1629)
dkoo Sep 3, 2024
5a44389
Merge branch 'trunk' into epic/update-editor-uis
dkoo Sep 6, 2024
1ed1e50
feat: support send lists in ESP classes (#1631)
dkoo Sep 9, 2024
ada9d71
Merge branch 'trunk' into epic/update-editor-uis
dkoo Sep 9, 2024
de61ff9
Merge branch 'epic/update-editor-uis' into feat/send-lists-editor-js
dkoo Sep 10, 2024
c7fc917
fix: return Send_List objects as arrays from provider methods
dkoo Sep 10, 2024
3d3430c
fix: avoid unnecessary send-list API requests
dkoo Sep 10, 2024
0b530bc
chore: remove unneeded methods
dkoo Sep 10, 2024
3ff1e65
fix: fatal error due to get_send_lists returning Send_List arrays ins…
dkoo Sep 11, 2024
1f302c3
Revert "fix: fatal error due to get_send_lists returning Send_List ar…
dkoo Sep 11, 2024
7a48870
fix: allow get_send_list methods to return either Send_List[] or arrays
dkoo Sep 11, 2024
be52969
fix: correct type for supportedESPs fallback value
dkoo Sep 11, 2024
3ffcd6b
fix(mc): subscriber send count in pre-send modal summary
dkoo Sep 11, 2024
a22b721
fix: formatting error
dkoo Sep 11, 2024
c00aca5
fix: ensure supported_esps is an array, not an object
dkoo Sep 12, 2024
a43989c
fix: missed callable
dkoo Sep 12, 2024
6f85a8b
fix: cc error handling
miguelpeixe Sep 12, 2024
f5555c2
fix: better error handling for retrieve/sync request errors
dkoo Sep 12, 2024
5627680
refactor: unify retrieve error handling across all ESPs
dkoo Sep 12, 2024
399cc89
refactor: throw error for missing MC creds, too
dkoo Sep 12, 2024
55a7d7f
test: update expected exception message
dkoo Sep 12, 2024
d7ef0c8
Merge pull request #1632 from Automattic/feat/send-lists-editor-js
dkoo Sep 13, 2024
decefdb
refactor: consolidate ESP data getters into Redux store
dkoo Sep 13, 2024
bf8b204
docs: update inline docs for Redux store
dkoo Sep 13, 2024
5a43634
Merge branch 'trunk' into epic/update-editor-uis
dkoo Sep 16, 2024
26247f9
Merge branch 'epic/update-editor-uis' into fix/store-improvements
dkoo Sep 16, 2024
6c82b6e
fix: move SendTo to Sidebar component; avoid parallel retrieve requests
dkoo Sep 16, 2024
2a28758
refactor: always prefetch sublists on list select
dkoo Sep 16, 2024
a8e10da
fix: account for missing selected list or sublist info
dkoo Sep 16, 2024
b27a3c0
fix: default sender/send-to for saved layouts
dkoo Aug 29, 2024
919a4d0
fix: campaign_defaults meta field name
dkoo Sep 16, 2024
b27f195
fix: don't overwrite fetched lists/sublists info on retrieve
dkoo Sep 16, 2024
999829f
Merge pull request #1657 from Automattic/fix/store-improvements
dkoo Sep 17, 2024
2e7497e
Merge branch 'epic/update-editor-uis' into fix/layout-defaults-for-se…
dkoo Sep 17, 2024
4fb1e4c
Merge pull request #1633 from Automattic/fix/layout-defaults-for-send…
dkoo Sep 17, 2024
9657be1
fix: force release
dkoo Sep 17, 2024
44f3118
feat: add link to campaign in provider (#1661)
miguelpeixe Sep 19, 2024
c83ffa4
Merge branch 'trunk' into epic/update-editor-uis
dkoo Oct 9, 2024
25a9e2d
fix: parse legacy layout defaults (#1663)
dkoo Oct 10, 2024
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
12 changes: 1 addition & 11 deletions includes/class-newspack-newsletters-ads.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,21 +75,11 @@ public static function rest_api_init() {
[
'callback' => [ __CLASS__, 'get_ads_config' ],
'methods' => 'GET',
'permission_callback' => [ __CLASS__, 'permission_callback' ],
'permission_callback' => [ 'Newspack_Newsletters', 'api_authoring_permissions_check' ],
]
);
}

/**
* Check capabilities for using the API for authoring tasks.
*
* @param WP_REST_Request $request API request object.
* @return bool|WP_Error
*/
public static function permission_callback( $request ) {
return current_user_can( 'edit_posts' );
}

/**
* Register custom fields.
*/
Expand Down
30 changes: 21 additions & 9 deletions includes/class-newspack-newsletters-editor.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public function __construct() {
add_action( 'the_post', [ __CLASS__, 'strip_editor_modifications' ] );
add_action( 'after_setup_theme', [ __CLASS__, 'newspack_font_sizes' ], 11 );
add_action( 'enqueue_block_editor_assets', [ __CLASS__, 'enqueue_block_editor_assets' ] );
add_filter( 'block_categories_all', [ __CLASS__, 'add_custom_block_category' ] );
add_filter( 'allowed_block_types_all', [ __CLASS__, 'newsletters_allowed_block_types' ], 10, 2 );
add_action( 'rest_post_query', [ __CLASS__, 'maybe_filter_excerpt_length' ], 10, 2 );
add_action( 'rest_post_query', [ __CLASS__, 'maybe_exclude_sponsored_posts' ], 10, 2 );
Expand Down Expand Up @@ -249,6 +250,24 @@ public static function newspack_font_sizes() {
);
}

/**
* Add the "Newspack" block category.
*
* @param array $block_categories Default block categories.
* @return array
*/
public static function add_custom_block_category( $block_categories ) {
array_unshift(
$block_categories,
[
'slug' => 'newspack',
'title' => 'Newspack',
]
);

return $block_categories;
}

/**
* Restrict block types for Newsletter CPT.
*
Expand Down Expand Up @@ -302,14 +321,9 @@ public static function enqueue_block_editor_assets() {
$mjml_handling_post_types = array_values( array_diff( self::get_email_editor_cpts(), [ Newspack_Newsletters_Ads::CPT ] ) );
$provider = Newspack_Newsletters::get_service_provider();
$conditional_tag_support = false;
$error_message = false;

if ( $provider && ( self::is_editing_newsletter() || self::is_editing_newsletter_ad() ) ) {
$conditional_tag_support = $provider::get_conditional_tag_support();

// Fetch async error messages to display on editor load.
$transient_name = $provider->get_transient_name( get_the_ID() );
$error_message = get_transient( $transient_name );
}

$email_editor_data = [
Expand All @@ -324,12 +338,9 @@ public static function enqueue_block_editor_assets() {
'byline_connector_label' => __( 'and ', 'newspack-newsletters' ),
],
'supported_social_icon_services' => Newspack_Newsletters_Renderer::get_supported_social_icons_services(),
'supported_esps' => Newspack_Newsletters::get_supported_providers(),
];

if ( $error_message ) {
$email_editor_data['error_message'] = $error_message;
}

if ( self::is_editing_email() ) {
wp_register_style(
'newspack-newsletters',
Expand Down Expand Up @@ -371,6 +382,7 @@ public static function enqueue_block_editor_assets() {
'is_service_provider_configured' => Newspack_Newsletters::is_service_provider_configured(),
'service_provider' => Newspack_Newsletters::service_provider(),
'user_test_emails' => self::get_current_user_test_emails(),
'labels' => $provider ? $provider::get_labels() : [],
]
);
wp_register_style(
Expand Down
2 changes: 1 addition & 1 deletion includes/class-newspack-newsletters-layouts.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public static function register_meta() {
\register_meta( 'post', 'font_body', $meta_default_params );
\register_meta( 'post', 'background_color', $meta_default_params );
\register_meta( 'post', 'custom_css', $meta_default_params );
\register_meta( 'post', 'layout_defaults', $meta_default_params );
\register_meta( 'post', 'campaign_defaults', $meta_default_params );
}

/**
Expand Down
2 changes: 1 addition & 1 deletion includes/class-newspack-newsletters-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,7 @@ public static function update_option_newspack_newsletters_public_posts_slug( $ol
/**
* Update settings.
*
* @param string $settings Update.
* @param array $settings Update.
*/
public static function update_settings( $settings ) {
foreach ( $settings as $key => $value ) {
Expand Down
34 changes: 11 additions & 23 deletions includes/class-newspack-newsletters-subscription.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@
* Manages Settings Subscription Class.
*/
class Newspack_Newsletters_Subscription {

const API_NAMESPACE = 'newspack-newsletters/v1';

const EMAIL_VERIFIED_META = 'newspack_newsletters_email_verified';
const EMAIL_VERIFIED_REQUEST = 'newspack_newsletters_email_verification_request';
const EMAIL_VERIFIED_CONFIRM = 'newspack_newsletters_email_verification';
Expand Down Expand Up @@ -62,7 +59,7 @@ public static function init() {
*/
public static function register_api_endpoints() {
register_rest_route(
self::API_NAMESPACE,
Newspack_Newsletters::API_NAMESPACE,
'/lists_config',
[
'methods' => \WP_REST_Server::READABLE,
Expand All @@ -71,21 +68,21 @@ public static function register_api_endpoints() {
]
);
register_rest_route(
self::API_NAMESPACE,
Newspack_Newsletters::API_NAMESPACE,
'/lists',
[
'methods' => \WP_REST_Server::READABLE,
'callback' => [ __CLASS__, 'api_get_lists' ],
'permission_callback' => [ __CLASS__, 'api_permission_callback' ],
'permission_callback' => [ 'Newspack_Newsletters', 'api_administration_permissions_check' ],
]
);
register_rest_route(
self::API_NAMESPACE,
Newspack_Newsletters::API_NAMESPACE,
'/lists',
[
'methods' => \WP_REST_Server::EDITABLE,
'callback' => [ __CLASS__, 'api_update_lists' ],
'permission_callback' => [ __CLASS__, 'api_permission_callback' ],
'permission_callback' => [ 'Newspack_Newsletters', 'api_administration_permissions_check' ],
'args' => [
'lists' => [
'type' => 'array',
Expand Down Expand Up @@ -113,15 +110,6 @@ public static function register_api_endpoints() {
);
}

/**
* Whether the current user can manage subscription lists.
*
* @return bool Whether the current user can manage subscription lists.
*/
public static function api_permission_callback() {
return current_user_can( 'manage_options' );
}

/**
* API method to retrieve the current lists configuration.
*
Expand Down Expand Up @@ -229,7 +217,7 @@ function ( $list ) {
public static function get_lists_config() {
$provider = Newspack_Newsletters::get_service_provider();
if ( empty( $provider ) ) {
return new WP_Error( 'newspack_newsletters_invalid_provider', __( 'Provider is not set.' ) );
return new WP_Error( 'newspack_newsletters_invalid_provider', __( 'Provider is not set.', 'newspack-newsletters' ) );
}

$saved_lists = Subscription_Lists::get_configured_for_current_provider();
Expand Down Expand Up @@ -262,11 +250,11 @@ public static function get_lists_config() {
public static function update_lists( $lists ) {
$provider = Newspack_Newsletters::get_service_provider();
if ( empty( $provider ) ) {
return new WP_Error( 'newspack_newsletters_invalid_provider', __( 'Provider is not set.' ) );
return new WP_Error( 'newspack_newsletters_invalid_provider', __( 'Provider is not set.', 'newspack-newsletters' ) );
}
$lists = self::sanitize_lists( $lists );
if ( empty( $lists ) ) {
return new WP_Error( 'newspack_newsletters_invalid_lists', __( 'Invalid list configuration.' ) );
return new WP_Error( 'newspack_newsletters_invalid_lists', __( 'Invalid list configuration.', 'newspack-newsletters' ) );
}

return Subscription_Lists::update_lists( $lists );
Expand Down Expand Up @@ -321,16 +309,16 @@ public static function has_subscription_management() {
*/
public static function get_contact_data( $email_address, $return_details = false ) {
if ( ! $email_address || empty( $email_address ) ) {
return new WP_Error( 'newspack_newsletters_invalid_email', __( 'Missing email address.' ) );
return new WP_Error( 'newspack_newsletters_invalid_email', __( 'Missing email address.', 'newspack-newsletters' ) );
}

$provider = Newspack_Newsletters::get_service_provider();
if ( empty( $provider ) ) {
return new WP_Error( 'newspack_newsletters_invalid_provider', __( 'Provider is not set.' ) );
return new WP_Error( 'newspack_newsletters_invalid_provider', __( 'Provider is not set.', 'newspack-newsletters' ) );
}

if ( ! method_exists( $provider, 'get_contact_data' ) ) {
return new WP_Error( 'newspack_newsletters_not_implemented', __( 'Provider does not handle the contact-exists check.' ) );
return new WP_Error( 'newspack_newsletters_not_implemented', __( 'Provider does not handle the contact-exists check.', 'newspack-newsletters' ) );
}

return $provider->get_contact_data( $email_address, $return_details );
Expand Down
Loading