@wordpress/block-library
Version:
Block library for the WordPress editor.
46 lines (42 loc) • 1.32 kB
JavaScript
/**
* WordPress dependencies
*/
import { store as coreStore } from '@wordpress/core-data';
import { useSelect } from '@wordpress/data';
export default function usePostTerms(_ref) {
var _term$visibility2;
let {
postId,
term
} = _ref;
const {
slug
} = term;
return useSelect(select => {
var _term$visibility;
const visible = term === null || term === void 0 ? void 0 : (_term$visibility = term.visibility) === null || _term$visibility === void 0 ? void 0 : _term$visibility.publicly_queryable;
if (!visible) {
return {
postTerms: [],
_isLoading: false,
hasPostTerms: false
};
}
const {
getEntityRecords,
isResolving
} = select(coreStore);
const taxonomyArgs = ['taxonomy', slug, {
post: postId,
per_page: -1,
context: 'view'
}];
const terms = getEntityRecords(...taxonomyArgs);
return {
postTerms: terms,
isLoading: isResolving('getEntityRecords', taxonomyArgs),
hasPostTerms: !!(terms !== null && terms !== void 0 && terms.length)
};
}, [postId, term === null || term === void 0 ? void 0 : (_term$visibility2 = term.visibility) === null || _term$visibility2 === void 0 ? void 0 : _term$visibility2.publicly_queryable]);
}
//# sourceMappingURL=use-post-terms.js.map