diff --git a/assets/components/render-controls/index.js b/assets/components/render-controls/index.js index 0dae8479..88a83ee2 100644 --- a/assets/components/render-controls/index.js +++ b/assets/components/render-controls/index.js @@ -6,6 +6,8 @@ import { cloneDeep } from 'lodash'; import { Component, Fragment, RawHTML } from '@wordpress/element'; import { applyFilters } from '@wordpress/hooks'; import { PanelBody, Notice } from '@wordpress/components'; +import { select } from '@wordpress/data'; +import { __ } from '@wordpress/i18n'; /** * Internal dependencies. @@ -316,12 +318,36 @@ export default class RenderControls extends Component { if (controlResult) { const val = controlRenderData.getValue(); - let controlNotice = ''; + const controlNotice = []; + + // Display an error for meta controls when the post type doesn't support custom fields and the control is configured to save_in_meta fields. + if (controlData.save_in_meta === 'true') { + const postType = select('core/editor').getCurrentPostType(); + const postTypeObject = select('core').getPostType(postType); + + const postTypeSupportMeta = + postTypeObject?.supports?.['custom-fields'] || false; + if (!postTypeSupportMeta) { + controlNotice.push( + + {__( + "This post type doesn't support custom fields", + 'lazy-blocks' + )} + + ); + } + } // show error for required fields const requiredError = checkControlValidity(val, controlData); if (allowErrorNotice && requiredError) { - controlNotice = ( + controlNotice.push(