我知道这个问题已经提出了几个月了,但我使用以下代码绕过了这个问题,并认为它可能对其他人有所帮助。也许有更好的方法,但这是可行的:
import ColorSchemeSelect from "./components/color-scheme-select";
import includes from "lodash/includes";
const { select } = wp.data;
const { registerPlugin } = wp.plugins;
const { PluginSidebar } = wp.editPost;
registerPlugin(\'ahr-sidebar-post-options\', {
render() {
const postType = select("core/editor").getCurrentPostType();
if ( !includes(["post", "page"], postType) ) {
return null;
}
return (
<PluginSidebar name="ahr-sidebar-post-options" icon="admin-customizer" title="Color settings">
<div style={{ padding: 16 }}>
<ColorSchemeSelect />
</div>
</PluginSidebar>
);
},
});
在我的示例中,我只想显示帖子和页面的某个侧栏,所以我使用
!includes(["post", "page"], postType)
要测试惠特与否,应显示侧栏。如果你只想要一个特定的职位类型,你就去
postType === "my-post-type"
相反