@wordpress/block-library
Version:
Block library for the WordPress editor.
27 lines (26 loc) • 1.04 kB
JavaScript
;
Object.defineProperties(exports, {
__esModule: { value: true },
[Symbol.toStringTag]: { value: "Module" }
});
let _wordpress_core_data = require("@wordpress/core-data");
let _wordpress_data = require("@wordpress/data");
// packages/block-library/src/query-title/use-post-type-label.js
/**
* Hook to fetch the singular label for the current post type.
*
* @param {string} contextPostType Context provided post type.
*/
function usePostTypeLabel(contextPostType) {
const currentPostType = (0, _wordpress_data.useSelect)((select) => {
const { getCurrentPostType } = select("core/editor");
return getCurrentPostType();
}, []);
return (0, _wordpress_data.useSelect)((select) => {
const { getPostType } = select(_wordpress_core_data.store);
const postType = getPostType(contextPostType || currentPostType);
return { postTypeLabel: postType ? postType.labels.singular_name : "" };
}, [contextPostType, currentPostType]);
}
exports.usePostTypeLabel = usePostTypeLabel;
//# sourceMappingURL=use-post-type-label.cjs.map