UNPKG

@wordpress/editor

Version:
47 lines (39 loc) 1.11 kB
/** * WordPress dependencies */ import { useSelect } from '@wordpress/data'; import { store as coreStore } from '@wordpress/core-data'; /** * Internal dependencies */ import { store as editorStore } from '../../store'; /** * Check if the post URL is valid and visible. * * @param {Object} props The component props. * @param {React.ReactNode} props.children The child components. * * @return {React.ReactNode} The child components if the post URL is valid and visible, otherwise null. */ export default function PostURLCheck( { children } ) { const isVisible = useSelect( ( select ) => { const postTypeSlug = select( editorStore ).getCurrentPostType(); const postType = select( coreStore ).getPostType( postTypeSlug ); if ( ! postType?.viewable ) { return false; } const post = select( editorStore ).getCurrentPost(); if ( ! post.link ) { return false; } const permalinkParts = select( editorStore ).getPermalinkParts(); if ( ! permalinkParts ) { return false; } return true; }, [] ); if ( ! isVisible ) { return null; } return children; }