/** * Form Settings document sidebar panel. * * Renders the Redirect / Set Role / Ajax / Display Messages controls in the * Document sidebar (one panel for both wppb-rf-cpt and wppb-epf-cpt). Values * read from / written to virtual flat REST meta keys (wppb_fb_*) which * `form-builder-rest-mirror.php` folds into the legacy nested * `wppb_*_page_settings` array. */ import { __ } from '@wordpress/i18n'; import { registerPlugin } from '@wordpress/plugins'; import { PluginDocumentSettingPanel } from '@wordpress/edit-post'; import { TextControl, SelectControl, ToggleControl } from '@wordpress/components'; import { useEntityProp } from '@wordpress/core-data'; import { useSelect } from '@wordpress/data'; const FormSettingsPanel = () => { const postType = useSelect( ( select ) => select( 'core/editor' ).getCurrentPostType(), [] ); if ( ! [ 'wppb-rf-cpt', 'wppb-epf-cpt' ].includes( postType ) ) return null; const [ meta, setMeta ] = useEntityProp( 'postType', postType, 'meta' ); if ( ! meta ) return null; return ( setMeta( { wppb_fb_redirect: val } ) } help={ __( 'Whether to redirect the user to a specific page after submission.', 'profile-builder' ) } /> { meta.wppb_fb_redirect === 'Yes' && ( <> setMeta( { wppb_fb_url: val } ) } help={ __( 'Destination URL. Use the format: https://www.example.com', 'profile-builder' ) } /> { const n = Math.max( 0, Math.min( 250, parseInt( val, 10 ) || 0 ) ); setMeta( { wppb_fb_display_messages: String( n ) } ); } } help={ __( 'Allowed time to display any success messages (in seconds). 0 disables.', 'profile-builder' ) } /> ) } { postType === 'wppb-rf-cpt' && ( <> setMeta( { wppb_fb_set_role: val } ) } help={ __( 'Role assigned to users registered through this form.', 'profile-builder' ) } /> setMeta( { wppb_fb_automatically_log_in: val ? 'Yes' : 'No' } ) } /> ) } setMeta( { wppb_fb_ajax: val ? 'true' : '' } ) } help={ __( 'Validate this form without reloading the page.', 'profile-builder' ) } /> ); }; registerPlugin( 'wppb-form-settings-plugin', { render: FormSettingsPanel, } );