diff --git a/projects/plugins/jetpack/changelog/update-external-media-store b/projects/plugins/jetpack/changelog/update-external-media-store new file mode 100644 index 0000000000000..d34284e631488 --- /dev/null +++ b/projects/plugins/jetpack/changelog/update-external-media-store @@ -0,0 +1,4 @@ +Significance: patch +Type: other + +External Media: support editor changes in WordPress 6.5. diff --git a/projects/plugins/jetpack/extensions/shared/external-media/media-service/index.ts b/projects/plugins/jetpack/extensions/shared/external-media/media-service/index.ts index c665bbfdaeb07..394396bc8a344 100644 --- a/projects/plugins/jetpack/extensions/shared/external-media/media-service/index.ts +++ b/projects/plugins/jetpack/extensions/shared/external-media/media-service/index.ts @@ -195,10 +195,23 @@ const isMediaSourceConnected = async ( source: MediaSource ) => * * @returns {boolean} True if the inserter is opened false otherwise. */ -const isInserterOpened = (): boolean => - select( 'core/edit-post' )?.isInserterOpened() || - select( 'core/edit-site' )?.isInserterOpened() || - select( 'core/edit-widgets' )?.isInserterOpened?.(); +const isInserterOpened = (): boolean => { + // Prior to WP 6.5, the isInserterOpened selector was available in core/edit-post. + // In WP 6.5, it was moved to core/editor. This check is to support both versions of WordPress. + // @to-do: remove exception when Jetpack requires WordPress 6.5. + const selectIsInserterOpened = + /* eslint-disable-next-line @typescript-eslint/no-explicit-any */ + ( select( 'core/editor' ) as any )?.isInserterOpened ?? + select( 'core/edit-post' )?.isInserterOpened; + + const editorIsInserterOpened = selectIsInserterOpened?.(); + + return ( + editorIsInserterOpened || + select( 'core/edit-site' )?.isInserterOpened() || + select( 'core/edit-widgets' )?.isInserterOpened() + ); +}; const registerInInserter = ( mediaCategoryProvider: () => object ) => // Remove as soon @types/wordpress__block-editor is up to date