Skip to content

Commit

Permalink
feat: remove any other editor modifications (#8)
Browse files Browse the repository at this point in the history
So that theme styles are not applied to the Newsletter

Co-authored-by: Jefferson Rabb <jeff@atavist.net>
  • Loading branch information
adekbadek and jeffersonrabb authored Apr 20, 2020
2 parents f104b21 + 83bb65d commit 2cb3f4c
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions includes/class-newspack-newsletters.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public static function instance() {
* Constructor.
*/
public function __construct() {
add_action( 'the_post', [ __CLASS__, 'remove_other_editor_modifications' ] );
add_action( 'init', [ __CLASS__, 'register_cpt' ] );
add_action( 'init', [ __CLASS__, 'register_meta' ] );
add_action( 'enqueue_block_editor_assets', [ __CLASS__, 'enqueue_block_editor_assets' ] );
Expand All @@ -67,6 +68,30 @@ public function __construct() {
include_once dirname( __FILE__ ) . '/class-newspack-newsletters-renderer.php';
}

/**
* Remove all editor enqueued assets besides this plugins'.
* This is to prevent theme styles being loaded in the editor.
* Remove editor color palette theme supports - the MJML parser uses a static list of default editor colors.
*/
public static function remove_other_editor_modifications() {
if ( self::NEWSPACK_NEWSLETTERS_CPT != get_post_type() ) {
return;
}

$enqueue_block_editor_assets_filters = $GLOBALS['wp_filter']['enqueue_block_editor_assets']->callbacks;
foreach ( $enqueue_block_editor_assets_filters as $index => $filter ) {
$action_handlers = array_keys( $filter );
foreach ( $action_handlers as $handler ) {
if ( __CLASS__ . '::enqueue_block_editor_assets' != $handler ) {
remove_action( 'enqueue_block_editor_assets', $handler, $index );
}
}
}

remove_editor_styles();
remove_theme_support( 'editor-color-palette' );
}

/**
* Register the custom post type.
*/
Expand Down

0 comments on commit 2cb3f4c

Please sign in to comment.