Skip to content

Commit

Permalink
feat: remove any other editor modifications
Browse files Browse the repository at this point in the history
So that theme styles are not applied to the Newsletter
  • Loading branch information
adekbadek committed Apr 9, 2020
1 parent 5a30354 commit 946bc04
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 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( 'admin_init', [ __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 @@ -52,6 +53,39 @@ 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() {
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
$post = isset( $_GET['post'] ) ? sanitize_text_field( $_GET['post'] ) : false;
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
$post_type = isset( $_GET['post_type'] ) ? sanitize_text_field( $_GET['post_type'] ) : false;
if ( ! $post && ! $post_type ) {
return;
}
if ( $post ) {
$post_type = get_post_type( $post );
}
if ( $post_type && self::NEWSPACK_NEWSLETTERS_CPT != $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 );
if ( ! in_array( __CLASS__ . '::enqueue_block_editor_assets', $action_handlers ) ) {
foreach ( $action_handlers as $handler ) {
remove_action( 'enqueue_block_editor_assets', $handler, $index );
}
}
}

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

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

0 comments on commit 946bc04

Please sign in to comment.