Skip to content

Commit

Permalink
External Media: support editor changes in WordPress 6.5 (#36188)
Browse files Browse the repository at this point in the history
* External Media: support editor changes in WordPress 6.5

Fixes #36186

* Avoid build errors

* Try to be more explicit in checking for isInserterOpened

* Another try around TypeScript

* Media Store: Update call to is inserter opened

---------

Co-authored-by: Renato Augusto Gama dos Santos <[email protected]>
  • Loading branch information
2 people authored and pkuliga committed May 9, 2024
1 parent 067080e commit 1631696
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: other

External Media: support editor changes in WordPress 6.5.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 1631696

Please sign in to comment.