PluginProbe
User Profile Builder – Beautiful User Registration Forms, User Profiles & User Role Editor / 4.0.3
User Profile Builder – Beautiful User Registration Forms, User Profiles & User Role Editor v4.0.3
4.0.3 4.0.2 4.0.1 4.0.0 3.16.6 3.16.5 3.16.4 3.16.3 3.16.2 3.16.1 3.16.0 3.15.9 3.9.9 3.9.5 3.9.6 3.9.7 3.9.8 1.1.7 1.1.8 1.1.9 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 All 341 releases
profile-builder / form-builder / blocks / src / components / FormSettingsPanel.js

FormSettingsPanel.js in User Profile Builder – Beautiful User Registration Forms, User Profiles & User Role Editor 4.0.3, at form-builder/blocks/src/components/FormSettingsPanel.js

99 lines 4.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /**
2 * Form Settings document sidebar panel.
3 *
4 * Renders the Redirect / Set Role / Ajax / Display Messages controls in the
5 * Document sidebar (one panel for both wppb-rf-cpt and wppb-epf-cpt). Values
6 * read from / written to virtual flat REST meta keys (wppb_fb_*) which
7 * `form-builder-rest-mirror.php` folds into the legacy nested
8 * `wppb_*_page_settings` array.
9 */
10
11 import { __ } from '@wordpress/i18n';
12 import { registerPlugin } from '@wordpress/plugins';
13 import { PluginDocumentSettingPanel } from '@wordpress/edit-post';
14 import { TextControl, SelectControl, ToggleControl } from '@wordpress/components';
15 import { useEntityProp } from '@wordpress/core-data';
16 import { useSelect } from '@wordpress/data';
17
18 const FormSettingsPanel = () => {
19 const postType = useSelect( ( select ) => select( 'core/editor' ).getCurrentPostType(), [] );
20 if ( ! [ 'wppb-rf-cpt', 'wppb-epf-cpt' ].includes( postType ) ) return null;
21
22 const [ meta, setMeta ] = useEntityProp( 'postType', postType, 'meta' );
23
24 if ( ! meta ) return null;
25
26 return (
27 <PluginDocumentSettingPanel
28 name="wppb-form-settings"
29 title={ __( 'Form Settings', 'profile-builder' ) }
30 >
31 <SelectControl
32 label={ __( 'Redirect', 'profile-builder' ) }
33 value={ meta.wppb_fb_redirect || '-' }
34 options={ [
35 { label: __( 'Default', 'profile-builder' ), value: '-' },
36 { label: __( 'No', 'profile-builder' ), value: 'No' },
37 { label: __( 'Yes', 'profile-builder' ), value: 'Yes' },
38 ] }
39 onChange={ ( val ) => setMeta( { wppb_fb_redirect: val } ) }
40 help={ __( 'Whether to redirect the user to a specific page after submission.', 'profile-builder' ) }
41 />
42
43 { meta.wppb_fb_redirect === 'Yes' && (
44 <>
45 <TextControl
46 label={ __( 'URL', 'profile-builder' ) }
47 value={ meta.wppb_fb_url || '' }
48 onChange={ ( val ) => setMeta( { wppb_fb_url: val } ) }
49 help={ __( 'Destination URL. Use the format: https://www.example.com', 'profile-builder' ) }
50 />
51 <TextControl
52 label={ __( 'Display Messages (seconds)', 'profile-builder' ) }
53 type="number"
54 min={ 0 }
55 max={ 250 }
56 step={ 1 }
57 value={ String( meta.wppb_fb_display_messages || '1' ) }
58 onChange={ ( val ) => {
59 const n = Math.max( 0, Math.min( 250, parseInt( val, 10 ) || 0 ) );
60 setMeta( { wppb_fb_display_messages: String( n ) } );
61 } }
62 help={ __( 'Allowed time to display any success messages (in seconds). 0 disables.', 'profile-builder' ) }
63 />
64 </>
65 ) }
66
67 { postType === 'wppb-rf-cpt' && (
68 <>
69 <SelectControl
70 label={ __( 'Set Role', 'profile-builder' ) }
71 value={ meta.wppb_fb_set_role || 'default role' }
72 options={ ( window.wppbFb && window.wppbFb.formSettings && window.wppbFb.formSettings.roles ) || [
73 { label: __( 'Default Role', 'profile-builder' ), value: 'default role' },
74 ] }
75 onChange={ ( val ) => setMeta( { wppb_fb_set_role: val } ) }
76 help={ __( 'Role assigned to users registered through this form.', 'profile-builder' ) }
77 />
78 <ToggleControl
79 label={ __( 'Automatically Log In', 'profile-builder' ) }
80 checked={ meta.wppb_fb_automatically_log_in === 'Yes' }
81 onChange={ ( val ) => setMeta( { wppb_fb_automatically_log_in: val ? 'Yes' : 'No' } ) }
82 />
83 </>
84 ) }
85
86 <ToggleControl
87 label={ __( 'Ajax Validation', 'profile-builder' ) }
88 checked={ meta.wppb_fb_ajax === 'true' }
89 onChange={ ( val ) => setMeta( { wppb_fb_ajax: val ? 'true' : '' } ) }
90 help={ __( 'Validate this form without reloading the page.', 'profile-builder' ) }
91 />
92 </PluginDocumentSettingPanel>
93 );
94 };
95
96 registerPlugin( 'wppb-form-settings-plugin', {
97 render: FormSettingsPanel,
98 } );
99