取代古滕贝格的特色图像控制?

时间:2018-05-01 作者:Edward

我可以用PHP替换当前WP版本中的特色图像控件:

add_filter( \'admin_post_thumbnail_html\', \'my_admin_post_thumbnail_html\', 10, 2 );
我如何对古腾堡做同样的事情?

1 个回复
SO网友:Welcher

以下是向特征图像区域添加新组件的示例。这是从官方文档中获取的,并更新为使用JSX。我正在使用@wordpress/scripts 包来构建此。

// Import from the hooks package
import { addFilter } from \'@wordpress/hooks\';

// Some custom component to add.
const CustomComponent = ({ id }) => {
    return id ? (
        <h4>You selected an image, yay!</h4>
    ) : (
        <div>You have not selected anything</div>
    );
};

// Function to be called by the hook that returns a function containing the new UI
function replacePostFeaturedImage(OriginalComponent) {
    return (props) => {
        const { featuredImageId } = props;
        return (
            <div>
                <CustomComponent id={featuredImageId} />
                <OriginalComponent {...props} />
            </div>
        );
    };
}

// Register the hook.
addFilter(
    \'editor.PostFeaturedImage\',
    \'my-plugin/replace-post-featured-image\',
    replacePostFeaturedImage
);
要更换整个组件,只需拆下<OriginalComponent />replacePostFeaturedImage 作用

希望它有帮助,并高兴地添加任何进一步的背景需要!

结束

相关推荐