Skip to content

Commit 9f095e1

Browse files
GaryJonesclaude
andcommitted
fix: add backwards compatibility for PluginDocumentSettingPanel
The original change imported PluginDocumentSettingPanel from @wordpress/editor to resolve a deprecation warning in WordPress 6.6+. However, this component only exists in @wordpress/editor from WordPress 6.6 onwards; in WordPress 6.4-6.5 it remains in @wordpress/edit-post. This implements a runtime fallback pattern that checks wp.editor first (WordPress 6.6+) and falls back to wp.editPost (WordPress 6.4-6.5), maintaining compatibility across the supported WordPress version range whilst eliminating the deprecation warning in newer versions. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent b5be893 commit 9f095e1

File tree

2 files changed

+72
-1
lines changed

2 files changed

+72
-1
lines changed
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/**
2+
* Tests for PluginDocumentSettingPanel backwards compatibility.
3+
*
4+
* The component moved from @wordpress/edit-post to @wordpress/editor in WP 6.6.
5+
* We use a runtime fallback to support both WP 6.4-6.5 (edit-post) and WP 6.6+ (editor).
6+
*/
7+
8+
describe( 'PluginDocumentSettingPanel compatibility', () => {
9+
const MockComponent = () => 'MockPluginDocumentSettingPanel';
10+
11+
beforeEach( () => {
12+
// Reset the wp global before each test
13+
global.wp = {};
14+
} );
15+
16+
afterEach( () => {
17+
// Clean up
18+
delete global.wp;
19+
} );
20+
21+
it( 'should use wp.editor.PluginDocumentSettingPanel when available (WP 6.6+)', () => {
22+
global.wp = {
23+
editor: {
24+
PluginDocumentSettingPanel: MockComponent,
25+
},
26+
editPost: {
27+
PluginDocumentSettingPanel: () => 'OldComponent',
28+
},
29+
};
30+
31+
const PluginDocumentSettingPanel =
32+
wp.editor?.PluginDocumentSettingPanel ||
33+
wp.editPost?.PluginDocumentSettingPanel;
34+
35+
expect( PluginDocumentSettingPanel ).toBe( MockComponent );
36+
} );
37+
38+
it( 'should fall back to wp.editPost.PluginDocumentSettingPanel (WP 6.4-6.5)', () => {
39+
global.wp = {
40+
editor: {},
41+
editPost: {
42+
PluginDocumentSettingPanel: MockComponent,
43+
},
44+
};
45+
46+
const PluginDocumentSettingPanel =
47+
wp.editor?.PluginDocumentSettingPanel ||
48+
wp.editPost?.PluginDocumentSettingPanel;
49+
50+
expect( PluginDocumentSettingPanel ).toBe( MockComponent );
51+
} );
52+
53+
it( 'should handle wp.editor being undefined (WP 6.4-6.5)', () => {
54+
global.wp = {
55+
editPost: {
56+
PluginDocumentSettingPanel: MockComponent,
57+
},
58+
};
59+
60+
const PluginDocumentSettingPanel =
61+
wp.editor?.PluginDocumentSettingPanel ||
62+
wp.editPost?.PluginDocumentSettingPanel;
63+
64+
expect( PluginDocumentSettingPanel ).toBe( MockComponent );
65+
} );
66+
} );

src/index.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,15 @@
22
* WordPress dependencies
33
*/
44
import { registerPlugin } from '@wordpress/plugins';
5-
import { PluginDocumentSettingPanel } from '@wordpress/editor';
65
import { __ } from '@wordpress/i18n';
76
import { select, subscribe } from "@wordpress/data";
87

8+
// PluginDocumentSettingPanel moved from @wordpress/edit-post to @wordpress/editor in WP 6.6.
9+
// Use fallback for backwards compatibility with WP 6.4-6.5.
10+
const PluginDocumentSettingPanel =
11+
wp.editor?.PluginDocumentSettingPanel ||
12+
wp.editPost?.PluginDocumentSettingPanel;
13+
914
/**
1015
* Components
1116
*/

0 commit comments

Comments
 (0)