Skip to content

Commit

Permalink
Social: Prevent the editor extension loading for unsupported post types
Browse files Browse the repository at this point in the history
There's a bug #20357 that means if code is loaded that relies on the
`@wordpress/editor` or `@wordpress/edit-post` packages, then it crashes
the Site Editor.

This change checks the post type being editted and whether it supports
Publicize. If it doesn't, we skip loading the JS code.
  • Loading branch information
pablinos committed May 27, 2022
1 parent 9d414ea commit 805e26b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
4 changes: 4 additions & 0 deletions projects/plugins/social/changelog/fix-social-site-editor
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: fixed

Site Editor: Prevent the editor extension loading for unsupported post types
16 changes: 15 additions & 1 deletion projects/plugins/social/src/class-jetpack-social.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,25 @@ public function initial_state() {
);
}

/**
* Checks to see if the current post supports Publicize
*
* @return boolean True if Publicize is supported
*/
public function is_supported_post() {
$post_type = get_post_type();
return ! empty( $post_type ) && post_type_supports( $post_type, 'publicize' );
}

/**
* Enqueue block editor scripts and styles.
*/
public function enqueue_block_editor_scripts() {
if ( ! ( new Modules() )->is_active( self::JETPACK_PUBLICIZE_MODULE_SLUG ) || class_exists( 'Jetpack' ) ) {
if (
! ( new Modules() )->is_active( self::JETPACK_PUBLICIZE_MODULE_SLUG ) ||
class_exists( 'Jetpack' ) ||
! $this->is_supported_post()
) {
return;
}

Expand Down

0 comments on commit 805e26b

Please sign in to comment.