PluginProbe
User Profile Builder – Beautiful User Registration Forms, User Profiles & User Role Editor / 2.0.4
User Profile Builder – Beautiful User Registration Forms, User Profiles & User Role Editor v2.0.4
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 2.0.7 All 340 releases
profile-builder / admin / manage-fields.php

manage-fields.php in User Profile Builder – Beautiful User Registration Forms, User Profiles & User Role Editor 2.0.4, at admin/manage-fields.php

505 lines 33.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Function that creates the Manage Fields submenu and populates it with a repeater field form
4 *
5 * @since v.2.0
6 *
7 * @return void
8 */
9 function wppb_manage_fields_submenu(){
10 // create a new sub_menu page which holds the data for the default + extra fields
11 $args = array(
12 'menu_title' => __( 'Manage Fields', 'profilebuilder' ),
13 'page_title' => __( 'Manage Default and Extra Fields', 'profilebuilder' ),
14 'menu_slug' => 'manage-fields',
15 'page_type' => 'submenu_page',
16 'capability' => 'manage_options',
17 'priority' => 5,
18 'parent_slug' => 'profile-builder'
19 );
20 $all_fields = new WCK_Page_Creator_PB( $args );
21
22
23 // populate this page
24 $manage_field_types[] = 'Default - Name (Heading)';
25 $manage_field_types[] = 'Default - Contact Info (Heading)';
26 $manage_field_types[] = 'Default - About Yourself (Heading)';
27 $manage_field_types[] = 'Default - Username';
28 $manage_field_types[] = 'Default - First Name';
29 $manage_field_types[] = 'Default - Last Name';
30 $manage_field_types[] = 'Default - Nickname';
31 $manage_field_types[] = 'Default - E-mail';
32 $manage_field_types[] = 'Default - Website';
33
34 // Default contact methods were removed in WP 3.6. A filter dictates contact methods.
35 if ( apply_filters( 'wppb_remove_default_contact_methods', get_site_option( 'initial_db_version' ) < 23588 ) ){
36 $manage_field_types[] = 'Default - AIM';
37 $manage_field_types[] = 'Default - Yahoo IM';
38 $manage_field_types[] = 'Default - Jabber / Google Talk';
39 }
40
41 $manage_field_types[] = 'Default - Password';
42 $manage_field_types[] = 'Default - Repeat Password';
43 $manage_field_types[] = 'Default - Biographical Info';
44 $manage_field_types[] = 'Default - Display name publicly as';
45
46 if( PROFILE_BUILDER != 'Profile Builder Free' ) {
47 $manage_field_types[] = 'Heading';
48 $manage_field_types[] = 'Input';
49 $manage_field_types[] = 'Input (Hidden)';
50 $manage_field_types[] = 'Textarea';
51 $manage_field_types[] = 'Select';
52 $manage_field_types[] = 'Select (Multiple)';
53 $manage_field_types[] = 'Select (Country)';
54 $manage_field_types[] = 'Select (Timezone)';
55 $manage_field_types[] = 'Checkbox';
56 $manage_field_types[] = 'Checkbox (Terms and Conditions)';
57 $manage_field_types[] = 'Radio';
58 $manage_field_types[] = 'Upload';
59 $manage_field_types[] = 'Avatar';
60 $manage_field_types[] = 'Datepicker';
61 $manage_field_types[] = 'reCAPTCHA';
62 }
63
64
65 //Free to Pro call to action on Manage Fields page
66 $field_description = 'Choose one of the supported field types';
67 if( PROFILE_BUILDER == 'Profile Builder Free' ) {
68 $field_description .='. Extra Field Types are available in %1$sHobbyist or PRO versions%2$s.';
69 }
70
71 // set up the fields array
72 $fields = apply_filters( 'wppb_manage_fields', array(
73
74 array( 'type' => 'text', 'slug' => 'field-title', 'title' => __( 'Field Title', 'profilebuilder' ), 'description' => __( 'Title of the field', 'profilebuilder' ) ),
75 array( 'type' => 'select', 'slug' => 'field', 'title' => __( 'Field', 'profilebuilder' ), 'options' => apply_filters( 'wppb_manage_fields_types', $manage_field_types ), 'default-option' => true, 'description' => sprintf(__( $field_description, 'profilebuilder' ), '<a href="http://www.cozmoslabs.com/wordpress-profile-builder/?utm_source=wpbackend&utm_medium=clientsite&utm_content=manage-fields-link&utm_campaign=PBFree">', '</a>') ),
76 array( 'type' => 'text', 'slug' => 'meta-name', 'title' => __( 'Meta-name', 'profilebuilder' ), 'default' => wppb_get_meta_name(), 'description' => __( 'Use this in conjuction with WordPress functions to display the value in the page of your choosing<br/>Auto-completed but in some cases editable (in which case it must be uniqe)<br/>Changing this might take long in case of a very big user-count', 'profilebuilder' ) ),
77 array( 'type' => 'text', 'slug' => 'id', 'title' => __( 'ID', 'profilebuilder' ), 'default' => wppb_get_unique_id(), 'description' => __( "A unique, auto-generated ID for this particular field<br/>You can use this in conjuction with filters to target this element if needed<br/>Can't be edited", 'profilebuilder' ), 'readonly' => true ),
78 array( 'type' => 'textarea', 'slug' => 'description', 'title' => __( 'Description', 'profilebuilder' ), 'description' => __( 'Enter a (detailed) description of the option for end users to read<br/>Optional', 'profilebuilder') ),
79 array( 'type' => 'text', 'slug' => 'row-count', 'title' => __( 'Row Count', 'profilebuilder' ), 'default' => 5, 'description' => __( "Specify the number of rows for a 'Textarea' field<br/>If not specified, defaults to 5", 'profilebuilder' ) ),
80 array( 'type' => 'text', 'slug' => 'allowed-image-extensions', 'title' => __( 'Allowed Image Extensions', 'profilebuilder' ), 'default' => '.*', 'description' => __( 'Specify the extension(s) you want to limit to upload<br/>Example: .ext1,.ext2,.ext3<br/>If not specified, defaults to all existing image extensions (.*)', 'profilebuilder' ) ),
81 array( 'type' => 'text', 'slug' => 'allowed-upload-extensions', 'title' => __( 'Allowed Upload Extensions', 'profilebuilder' ), 'default' => '.*', 'description' => __( 'Specify the extension(s) you want to limit to upload<br/>Example: .ext1,.ext2,.ext3<br/>If not specified, defaults to all existing extensions (.*)', 'profilebuilder' ) ),
82 array( 'type' => 'text', 'slug' => 'avatar-size', 'title' => __( 'Avatar Size', 'profilebuilder' ), 'default' => 100, 'description' => __( "Enter a value (between 20 and 200) for the size of the 'Avatar'<br/>If not specified, defaults to 100", 'profilebuilder' ) ),
83 array( 'type' => 'text', 'slug' => 'date-format', 'title' => __( 'Date-format', 'profilebuilder' ), 'default' => 'mm/dd/yy', 'description' => __( 'Specify the format of the date when using Datepicker<br/>Valid options: mm/dd/yy, mm/yy/dd, dd/yy/mm, dd/mm/yy, yy/dd/mm, yy/mm/dd<br/>If not specified, defaults to mm/dd/yy', 'profilebuilder' ) ),
84 array( 'type' => 'textarea', 'slug' => 'terms-of-agreement', 'title' => __( 'Terms of Agreement', 'profilebuilder' ), 'description' => __( 'Enter a detailed description of the temrs of agreement for the user to read.<br/>Links can be inserted by using standard HTML syntax: &lt;a href="custom_url"&gt;custom_text&lt;/a&gt;', 'profilebuilder' ) ),
85 array( 'type' => 'text', 'slug' => 'options', 'title' => __( 'Options', 'profilebuilder' ), 'description' => __( "Enter a comma separated list of values<br/>This can be anything, as it is hidden from the user, but should not contain special characters or apostrophes", 'profilebuilder' ) ),
86 array( 'type' => 'text', 'slug' => 'labels', 'title' => __( 'Labels', 'profilebuilder' ), 'description' => __( "Enter a comma separated list of labels<br/>Visible for the user", 'profilebuilder' ) ),
87 array( 'type' => 'text', 'slug' => 'public-key', 'title' => __( 'Public Key', 'profilebuilder' ), 'description' => __( 'The public key from Google, <a href="http://www.google.com/recaptcha" target="_blank">www.google.com/recaptcha</a>', 'profilebuilder' ) ),
88 array( 'type' => 'text', 'slug' => 'private-key', 'title' => __( 'Private Key', 'profilebuilder' ), 'description' => __( 'The private key from Google, <a href="http://www.google.com/recaptcha" target="_blank">www.google.com/recaptcha</a>', 'profilebuilder' ) ),
89 array( 'type' => 'text', 'slug' => 'default-value', 'title' => __( 'Default Value', 'profilebuilder' ), 'description' => __( "Default value of the field", 'profilebuilder' ) ),
90 array( 'type' => 'text', 'slug' => 'default-option', 'title' => __( 'Default Option', 'profilebuilder' ), 'description' => __( "Specify the option which should be selected by default", 'profilebuilder' ) ),
91 array( 'type' => 'text', 'slug' => 'default-options', 'title' => __( 'Default Option(s)', 'profilebuilder' ), 'description' => __( "Specify the option which should be checked by default<br/>If there are multiple values, separate them with a ',' (comma)", 'profilebuilder' ) ),
92 array( 'type' => 'textarea', 'slug' => 'default-content', 'title' => __( 'Default Content', 'profilebuilder' ), 'description' => __( "Default value of the textarea", 'profilebuilder' ) ),
93 array( 'type' => 'select', 'slug' => 'required', 'title' => __( 'Required', 'profilebuilder' ), 'options' => array( 'No', 'Yes' ), 'default' => 'No', 'description' => __( 'Whether the field is required or not', 'profilebuilder' ) ),
94 array( 'type' => 'select', 'slug' => 'overwrite-existing', 'title' => __( 'Overwrite Existing', 'profilebuilder' ), 'options' => array( 'No', 'Yes' ), 'default' => 'No', 'description' => __( "Selecting 'Yes' will add the field to the list, but will overwrite any other field in the database that has the same meta-name<br/>Use this at your own risk", 'profilebuilder' ) ),
95 ) );
96
97 // create the new submenu with the above options
98 $args = array(
99 'metabox_id' => 'manage-fields',
100 'metabox_title' => __( 'Field Properties', 'profilebuilder' ),
101 'post_type' => 'manage-fields',
102 'meta_name' => 'wppb_manage_fields',
103 'meta_array' => $fields,
104 'context' => 'option'
105 );
106 new Wordpress_Creation_Kit_PB( $args );
107
108 wppb_prepopulate_fields();
109
110 // create the info side meta-box
111 $args = array(
112 'metabox_id' => 'manage-fields-info',
113 'metabox_title' => __( 'Registration & Edit Profile', 'profilebuilder' ),
114 'post_type' => 'manage-fields',
115 'meta_name' => 'wppb_manage_fields_info',
116 'meta_array' => '',
117 'context' => 'option',
118 'mb_context' => 'side'
119 );
120 new Wordpress_Creation_Kit_PB( $args );
121 }
122 add_action( 'init', 'wppb_manage_fields_submenu', 10 );
123
124 /**
125 * Function that prepopulates the manage fields list with the default fields of WP
126 *
127 * @since v.2.0
128 *
129 * @return void
130 */
131 function wppb_prepopulate_fields(){
132 $prepopulated_fields[] = array( 'field' => 'Default - Name (Heading)', 'field-title' => __( 'Name', 'profilebuilder' ), 'meta-name' => '', 'overwrite-existing' => 'No', 'id' => '1', 'description' => '', 'row-count' => '5', 'allowed-image-extensions' => '.*', 'allowed-upload-extensions' => '.*', 'avatar-size' => '100', 'date-format' => 'mm/dd/yy', 'terms-of-agreement' => '', 'options' => '', 'labels' => '', 'public-key' => '', 'private-key' => '', 'default-value' => '', 'default-option' => '', 'default-options' => '', 'default-content' => '', 'required' => 'No' );
133 $prepopulated_fields[] = array( 'field' => 'Default - Username', 'field-title' => __( 'Username', 'profilebuilder' ), 'meta-name' => '', 'overwrite-existing' => 'No', 'id' => '2', 'description' => __( 'Usernames cannot be changed.', 'profilebuilder' ), 'row-count' => '5', 'allowed-image-extensions' => '.*', 'allowed-upload-extensions' => '.*', 'avatar-size' => '100', 'date-format' => 'mm/dd/yy', 'terms-of-agreement' => '', 'options' => '', 'labels' => '', 'public-key' => '', 'private-key' => '', 'default-value' => '', 'default-option' => '', 'default-options' => '', 'default-content' => '', 'required' => 'Yes' );
134 $prepopulated_fields[] = array( 'field' => 'Default - First Name', 'field-title' => __( 'First Name', 'profilebuilder' ), 'meta-name' => 'first_name', 'overwrite-existing' => 'No', 'id' => '3', 'description' => '', 'row-count' => '5', 'allowed-image-extensions' => '.*', 'allowed-upload-extensions' => '.*', 'avatar-size' => '100', 'date-format' => 'mm/dd/yy', 'terms-of-agreement' => '', 'options' => '', 'labels' => '', 'public-key' => '', 'private-key' => '', 'default-value' => '', 'default-option' => '', 'default-options' => '', 'default-content' => '', 'required' => 'No' );
135 $prepopulated_fields[] = array( 'field' => 'Default - Last Name', 'field-title' => __( 'Last Name', 'profilebuilder' ), 'meta-name' => 'last_name', 'overwrite-existing' => 'No', 'id' => '4', 'description' => '', 'row-count' => '5', 'allowed-image-extensions' => '.*', 'allowed-upload-extensions' => '.*', 'avatar-size' => '100', 'date-format' => 'mm/dd/yy', 'terms-of-agreement' => '', 'options' => '', 'labels' => '', 'public-key' => '', 'private-key' => '', 'default-value' => '', 'default-option' => '', 'default-options' => '', 'default-content' => '', 'required' => 'No' );
136 $prepopulated_fields[] = array( 'field' => 'Default - Nickname', 'field-title' => __( 'Nickname', 'profilebuilder' ), 'meta-name' => 'nickname', 'overwrite-existing' => 'No', 'id' => '5', 'description' => '', 'row-count' => '5', 'allowed-image-extensions' => '.*', 'allowed-upload-extensions' => '.*', 'avatar-size' => '100', 'date-format' => 'mm/dd/yy', 'terms-of-agreement' => '', 'options' => '', 'labels' => '', 'public-key' => '', 'private-key' => '', 'default-value' => '', 'default-option' => '', 'default-options' => '', 'default-content' => '', 'required' => 'Yes' );
137 $prepopulated_fields[] = array( 'field' => 'Default - Display name publicly as', 'field-title' => __( 'Display name publicly as', 'profilebuilder' ), 'meta-name' => '', 'overwrite-existing' => 'No', 'id' => '6', 'description' => '', 'row-count' => '5', 'allowed-image-extensions' => '.*', 'allowed-upload-extensions' => '.*', 'avatar-size' => '100', 'date-format' => 'mm/dd/yy', 'terms-of-agreement' => '', 'options' => '', 'labels' => '', 'public-key' => '', 'private-key' => '', 'default-value' => '', 'default-option' => '', 'default-options' => '', 'default-content' => '', 'required' => 'No' );
138 $prepopulated_fields[] = array( 'field' => 'Default - Contact Info (Heading)', 'field-title' => __( 'Contact Info', 'profilebuilder' ), 'meta-name' => '', 'overwrite-existing' => 'No', 'id' => '7', 'description' => '', 'row-count' => '5', 'allowed-image-extensions' => '.*', 'allowed-upload-extensions' => '.*', 'avatar-size' => '100', 'date-format' => 'mm/dd/yy', 'terms-of-agreement' => '', 'options' => '', 'labels' => '', 'public-key' => '', 'private-key' => '', 'default-value' => '', 'default-option' => '', 'default-options' => '', 'default-content' => '', 'required' => 'No' );
139 $prepopulated_fields[] = array( 'field' => 'Default - E-mail', 'field-title' => __( 'E-mail', 'profilebuilder' ), 'meta-name' => '', 'overwrite-existing' => 'No', 'id' => '8', 'description' => '', 'row-count' => '5', 'allowed-image-extensions' => '.*', 'allowed-upload-extensions' => '.*', 'avatar-size' => '100', 'date-format' => 'mm/dd/yy', 'terms-of-agreement' => '', 'options' => '', 'labels' => '', 'public-key' => '', 'private-key' => '', 'default-value' => '', 'default-option' => '', 'default-options' => '', 'default-content' => '', 'required' => 'Yes' );
140 $prepopulated_fields[] = array( 'field' => 'Default - Website', 'field-title' => __( 'Website', 'profilebuilder' ), 'meta-name' => '', 'overwrite-existing' => 'No', 'id' => '9', 'description' => '', 'row-count' => '5', 'allowed-image-extensions' => '.*', 'allowed-upload-extensions' => '.*', 'avatar-size' => '100', 'date-format' => 'mm/dd/yy', 'terms-of-agreement' => '', 'options' => '', 'labels' => '', 'public-key' => '', 'private-key' => '', 'default-value' => '', 'default-option' => '', 'default-options' => '', 'default-content' => '', 'required' => 'No' );
141
142 // Default contact methods were removed in WP 3.6. A filter dictates contact methods.
143 if ( apply_filters( 'wppb_remove_default_contact_methods', get_site_option( 'initial_db_version' ) < 23588 ) ){
144 $prepopulated_fields[] = array( 'field' => 'Default - AIM', 'field-title' => __( 'AIM', 'profilebuilder' ), 'meta-name' => 'aim', 'overwrite-existing' => 'No', 'id' => '10', 'description' => '', 'row-count' => '5', 'allowed-image-extensions' => '.*', 'allowed-upload-extensions' => '.*', 'avatar-size' => '100', 'date-format' => 'mm/dd/yy', 'terms-of-agreement' => '', 'options' => '', 'labels' => '', 'public-key' => '', 'private-key' => '', 'default-value' => '', 'default-option' => '', 'default-options' => '', 'default-content' => '', 'required' => 'No' );
145 $prepopulated_fields[] = array( 'field' => 'Default - Yahoo IM', 'field-title' => __( 'Yahoo IM', 'profilebuilder' ), 'meta-name' => 'yim', 'overwrite-existing' => 'No', 'id' => '11', 'description' => '', 'row-count' => '5', 'allowed-image-extensions' => '.*', 'allowed-upload-extensions' => '.*', 'avatar-size' => '100', 'date-format' => 'mm/dd/yy', 'terms-of-agreement' => '', 'options' => '', 'labels' => '', 'public-key' => '', 'private-key' => '', 'default-value' => '', 'default-option' => '', 'default-options' => '', 'default-content' => '', 'required' => 'No' );
146 $prepopulated_fields[] = array( 'field' => 'Default - Jabber / Google Talk', 'field-title' => __( 'Jabber / Google Talk', 'profilebuilder' ), 'meta-name' => 'jabber', 'overwrite-existing' => 'No', 'id' => '12', 'description' => '', 'row-count' => '5', 'allowed-image-extensions' => '.*', 'allowed-upload-extensions' => '.*', 'avatar-size' => '100', 'date-format' => 'mm/dd/yy', 'terms-of-agreement' => '', 'options' => '', 'labels' => '', 'public-key' => '', 'private-key' => '', 'default-value' => '', 'default-option' => '', 'default-options' => '', 'default-content' => '', 'required' => 'No' );
147 }
148
149 $prepopulated_fields[] = array( 'field' => 'Default - About Yourself (Heading)', 'field-title' => __( 'About Yourself', 'profilebuilder' ), 'meta-name' => '', 'overwrite-existing' => 'No', 'id' => '13', 'description' => '', 'row-count' => '5', 'allowed-image-extensions' => '.*', 'allowed-upload-extensions' => '.*', 'avatar-size' => '100', 'date-format' => 'mm/dd/yy', 'terms-of-agreement' => '', 'options' => '', 'labels' => '', 'public-key' => '', 'private-key' => '', 'default-value' => '', 'default-option' => '', 'default-options' => '', 'default-content' => '', 'required' => 'No' );
150 $prepopulated_fields[] = array( 'field' => 'Default - Biographical Info', 'field-title' => __( 'Biographical Info', 'profilebuilder' ), 'meta-name' => 'description', 'overwrite-existing' => 'No', 'id' => '14', 'description' => __( 'Share a little biographical information to fill out your profile. This may be shown publicly.', 'profilebuilder' ), 'row-count' => '5', 'allowed-image-extensions' => '.*', 'allowed-upload-extensions' => '.*', 'avatar-size' => '100', 'date-format' => 'mm/dd/yy', 'terms-of-agreement' => '', 'options' => '', 'labels' => '', 'public-key' => '', 'private-key' => '', 'default-value' => '', 'default-option' => '', 'default-options' => '', 'required' => 'No' );
151 $prepopulated_fields[] = array( 'field' => 'Default - Password', 'field-title' => __( 'Password', 'profilebuilder' ), 'meta-name' => '', 'overwrite-existing' => 'No', 'id' => '15', 'description' => __( 'Type your password.', 'profilebuilder' ), 'row-count' => '5', 'allowed-image-extensions' => '.*', 'allowed-upload-extensions' => '.*', 'avatar-size' => '100', 'date-format' => 'mm/dd/yy', 'terms-of-agreement' => '', 'options' => '', 'labels' => '', 'public-key' => '', 'private-key' => '', 'default-value' => '', 'default-option' => '', 'default-options' => '', 'default-content' => '', 'required' => 'Yes' );
152 $prepopulated_fields[] = array( 'field' => 'Default - Repeat Password', 'field-title' => __( 'Repeat Password', 'profilebuilder' ), 'meta-name' => '', 'overwrite-existing' => 'No', 'id' => '16', 'description' => __( 'Type your password again. ', 'profilebuilder' ), 'row-count' => '5', 'allowed-image-extensions' => '.*', 'allowed-upload-extensions' => '.*', 'avatar-size' => '100', 'date-format' => 'mm/dd/yy', 'terms-of-agreement' => '', 'options' => '', 'labels' => '', 'public-key' => '', 'private-key' => '', 'default-value' => '', 'default-option' => '', 'default-options' => '', 'default-content' => '', 'required' => 'Yes' );
153
154 add_option ( 'wppb_manage_fields', apply_filters ( 'wppb_prepopulated_fields', $prepopulated_fields ) );
155 }
156
157 /**
158 * Function that returns a unique meta-name
159 *
160 * @since v.2.0
161 *
162 * @return string
163 */
164 function wppb_get_meta_name(){
165 $id = 1;
166
167 $wppb_manage_fields = get_option( 'wppb_manage_fields', 'not_found' );
168 if ( ( $wppb_manage_fields === 'not_found' ) || ( empty( $wppb_manage_fields ) ) ){
169 return 'custom_field'.$id;
170 }
171 else{
172 $meta_names = array();
173 foreach( $wppb_manage_fields as $value ){
174 if ( strpos( $value['meta-name'], 'custom_field' ) === 0 ){
175 $meta_names[] = $value['meta-name'];
176 }
177 }
178
179 if( !empty( $meta_names ) ){
180 $meta_numbers = array();
181 foreach( $meta_names as $meta_name ){
182 $number = str_replace( 'custom_field', '', $meta_name );
183 /* backwards compatibility check in PB 1.3 meta_name was custom_field_# */
184 $number = str_replace( '_', '', $number );
185
186 $meta_numbers[] = $number;
187 }
188 if( !empty( $meta_numbers ) ){
189 rsort( $meta_numbers );
190 $id = $meta_numbers[0]+1;
191 }
192 }
193
194 return 'custom_field'.$id;
195 }
196 }
197
198
199 /**
200 * Function that returns a unique, incremented ID
201 *
202 * @since v.2.0
203 *
204 * @return integer id
205 */
206 function wppb_get_unique_id(){
207 $id = 1;
208
209 $wppb_manage_fields = get_option( 'wppb_manage_fields', 'not_found' );
210 if ( ( $wppb_manage_fields === 'not_found' ) || ( empty( $wppb_manage_fields ) ) ){
211 return $id;
212 }
213 else{
214 $ids_array = array();
215 foreach( $wppb_manage_fields as $value ){
216 $ids_array[] = $value['id'];
217 }
218 if( !empty( $ids_array ) ){
219 rsort( $ids_array );
220 $id = $ids_array[0]+1;
221 }
222 }
223 return $id;
224 }
225
226 function wppb_return_unique_field_list( $only_default_fields = false ){
227
228 $unique_field_list[] = 'Default - Name (Heading)';
229 $unique_field_list[] = 'Default - Contact Info (Heading)';
230 $unique_field_list[] = 'Default - About Yourself (Heading)';
231 $unique_field_list[] = 'Default - Username';
232 $unique_field_list[] = 'Default - First Name';
233 $unique_field_list[] = 'Default - Last Name';
234 $unique_field_list[] = 'Default - Nickname';
235 $unique_field_list[] = 'Default - E-mail';
236 $unique_field_list[] = 'Default - Website';
237
238 // Default contact methods were removed in WP 3.6. A filter dictates contact methods.
239 if ( apply_filters( 'wppb_remove_default_contact_methods', get_site_option( 'initial_db_version' ) < 23588 ) ){
240 $unique_field_list[] = 'Default - AIM';
241 $unique_field_list[] = 'Default - Yahoo IM';
242 $unique_field_list[] = 'Default - Jabber / Google Talk';
243 }
244
245 $unique_field_list[] = 'Default - Password';
246 $unique_field_list[] = 'Default - Repeat Password';
247 $unique_field_list[] = 'Default - Biographical Info';
248 $unique_field_list[] = 'Default - Display name publicly as';
249 if( !$only_default_fields ){
250 $unique_field_list[] = 'Avatar';
251 $unique_field_list[] = 'reCAPTCHA';
252 }
253
254 return apply_filters ( 'wppb_unique_field_list', $unique_field_list );
255 }
256
257
258 /**
259 * Function that checks several things when adding/editin the fields
260 *
261 * @since v.2.0
262 *
263 * @param string $message - the message to be displayed
264 * @param array $fields - the added fields
265 * @param array $required_fields
266 * @param string $meta - the meta-name of the option
267 * @param string $values - The values entered for each option
268 * @param integer $post_id
269 * @return boolean
270 */
271 function wppb_check_field_on_edit_add( $message, $fields, $required_fields, $meta_name, $posted_values, $post_id ){
272 global $wpdb;
273
274 if ( $meta_name == 'wppb_manage_fields' ){
275
276 // check for a valid field-type (fallback)
277 if ( $posted_values['field'] == '' )
278 $message .= __( "You must select a field\n", 'profilebuilder' );
279 // END check for a valid field-type (fallback)
280
281 $unique_field_list = wppb_return_unique_field_list();
282 $all_fields = get_option ( $meta_name, 'not_set' );
283
284 // check if the unique fields are only added once
285 if( $all_fields != 'not_set' ){
286 foreach( $all_fields as $field ){
287 if ( ( in_array ( $posted_values['field'], $unique_field_list ) ) && ( $posted_values['field'] == $field['field'] ) && ( $posted_values['id'] != $field['id'] ) ){
288 $message .= __( "Please choose a different field type as this one already exists in your form (must be unique)\n", 'profilebuilder' );
289 break;
290 }
291 }
292 }
293 // END check if the unique fields are only added once
294
295 // check for avatar size
296 if ( $posted_values['field'] == 'Avatar' ){
297 if ( is_numeric( $posted_values['avatar-size'] ) ){
298 if ( ( $posted_values['avatar-size'] < 20 ) || ( $posted_values['avatar-size'] > 200 ) )
299 $message .= __( "The entered avatar size is not between 20 and 200\n", 'profilebuilder' );
300
301 }else
302 $message .= __( "The entered avatar size is not numerical\n", 'profilebuilder' );
303
304 }
305 // END check for avatar size
306
307 // check for correct row value
308 if ( ( $posted_values['field'] == 'Default - Biographical Info' ) || ( $posted_values['field'] == 'Textarea' ) ){
309 if ( !is_numeric( $posted_values['row-count'] ) )
310 $message .= __( "The entered row number is not numerical\n", 'profilebuilder' );
311
312 elseif ( trim( $posted_values['row-count'] ) == '' )
313 $message .= __( "You must enter a value for the row number\n", 'profilebuilder' );
314 }
315 // END check for correct row value
316
317
318 // check for the public and private keys
319 if ( $posted_values['field'] == 'reCAPTCHA'){
320 if ( trim( $posted_values['public-key'] ) == '' )
321 $message .= __( "You must enter the public key\n", 'profilebuilder' );
322 if ( trim( $posted_values['private-key'] ) == '' )
323 $message .= __( "You must enter the private key\n", 'profilebuilder' );
324 }
325 // END check for the public and private keys
326
327 // check for the correct the date-format
328 if ( $posted_values['field'] == 'Datepicker' ){
329 $date_format = strtolower( $posted_values['date-format'] );
330 if ( ( trim( $date_format ) != 'mm/dd/yy' ) && ( trim( $date_format ) != 'mm/yy/dd' ) && ( trim( $date_format ) != 'dd/yy/mm' ) && ( trim( $date_format ) != 'dd/mm/yy' ) && ( trim( $date_format ) != 'yy/dd/mm' ) && ( trim( $date_format ) != 'yy/mm/dd' ) )
331 $message .= __( "The entered value for the Datepicker is not a valid date-format\n", 'profilebuilder' );
332
333 elseif ( trim( $date_format ) == '' )
334 $message .= __( "You must enter a value for the date-format\n", 'profilebuilder' );
335 }
336 // END check for the correct the date-format
337
338 //check duplicate meta-name
339 if ( $posted_values['overwrite-existing'] == 'No' ){
340 $skip_check_for_fields = wppb_return_unique_field_list(true);
341 $skip_check_for_fields = apply_filters ( 'wppb_skip_check_for_fields', $skip_check_for_fields );
342
343 if ( !in_array( trim( $posted_values['field'] ), $skip_check_for_fields ) ){
344 $unique_meta_name_list = array( 'first_name', 'last_name', 'nickname', 'description' );
345
346 // Default contact methods were removed in WP 3.6. A filter dictates contact methods.
347 if ( apply_filters( 'wppb_remove_default_contact_methods', get_site_option( 'initial_db_version' ) < 23588 ) ){
348 $unique_meta_name_list[] = 'aim';
349 $unique_meta_name_list[] = 'yim';
350 $unique_meta_name_list[] = 'jabber';
351 }
352
353 // if the desired meta-name is one of the following, automatically give an error
354 if ( in_array( trim( $posted_values['meta-name'] ), apply_filters ( 'wppb_unique_meta_name_list', $unique_meta_name_list ) ) )
355 $message .= __( "That meta-name is already in use\n", 'profilebuilder' );
356
357 else{
358 $found_in_custom_fields = false;
359
360 if( $all_fields != 'not_set' )
361 foreach( $all_fields as $field ){
362 if ( $posted_values['meta-name'] != '' && ( $field['meta-name'] == $posted_values['meta-name'] ) && ( $field['id'] != $posted_values['id'] ) ){
363 $message .= __( "That meta-name is already in use\n", 'profilebuilder' );
364 $found_in_custom_fields = true;
365
366 }elseif ( ( $field['meta-name'] == $posted_values['meta-name'] ) && ( $field['id'] == $posted_values['id'] ) )
367 $found_in_custom_fields = true;
368 }
369
370 if ( $found_in_custom_fields === false ){
371 $found_meta_name = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->usermeta WHERE meta_key = %s", $posted_values['meta-name'] ) );
372 if ( $found_meta_name != null )
373 $message .= __( "That meta-name is already in use\n", 'profilebuilder' );
374 }
375 }
376 }
377 }
378 //END check duplicate meta-name
379
380 // check for valid default option (checkbox, select, radio)
381 if ( ( $posted_values['field'] == 'Checkbox' ) || ( $posted_values['field'] == 'Select (Multiple)' ) ) {
382 $options = array_map( 'trim', explode( ',', $posted_values['options'] ) );
383 $default_options = ( ( trim( $posted_values['default-options'] ) == '' ) ? array() : array_map( 'trim', explode( ',', $posted_values['default-options'] ) ) );
384
385 /* echo "<script>console.log( Posted options: " . print_r($options, true) . "' );</script>";
386 echo "<script>console.log( Default options: " . print_r($default_options, true) . "' );</script>"; */
387
388 $not_found = '';
389 foreach ( $default_options as $key => $value ){
390 if ( !in_array( $value, $options ) )
391 $not_found .= $value . ', ';
392 }
393
394 if ( $not_found != '' )
395 $message .= sprintf( __( "The following option(s) did not coincide with the ones in the options list: %s\n", 'profilebuilder' ), trim( $not_found, ', ' ) );
396
397 }elseif ( ( $posted_values['field'] == 'Radio' ) || ( $posted_values['field'] == 'Select' ) ){
398 if ( ( trim( $posted_values['default-option'] ) != '' ) && ( !in_array( $posted_values['default-option'], array_map( 'trim', explode( ',', $posted_values['options'] ) ) ) ) )
399 $message .= sprintf( __( "The following option did not coincide with the ones in the options list: %s\n", 'profilebuilder' ), $posted_values['default-option'] );
400 }
401 // END check for valid default option (checkbox, select, radio)
402
403 }elseif ( ( $meta_name == 'wppb_rf_fields' ) || ( $meta_name == 'wppb_epf_fields' ) ){
404 if ( $posted_values['field'] == '' ){
405 $message .= __( "You must select a field\n", 'profilebuilder' );
406
407 }else{
408 $fields_so_far = get_post_meta ( $post_id, $meta_name, true );
409
410 foreach ( $fields_so_far as $key => $value ){
411 if ( $value['field'] == $posted_values['field'] )
412 $message .= __( "That field is already added in this form\n", 'profilebuilder' );
413 }
414 }
415 }
416 return $message;
417 }
418 add_filter( 'wck_extra_message', 'wppb_check_field_on_edit_add', 10, 6 );
419
420
421 /**
422 * Function that calls the wppb_hide_properties_for_already_added_fields after a field-update
423 *
424 * @since v.2.0
425 *
426 * @param void
427 *
428 * @return string
429 */
430 function wppb_manage_fields_after_refresh_list( $id ){
431 echo "<script type=\"text/javascript\">wppb_hide_properties_for_already_added_fields( '#container_wppb_manage_fields' );</script>";
432 }
433 add_action( "wck_refresh_list_wppb_manage_fields", "wppb_manage_fields_after_refresh_list" );
434 add_action( "wck_refresh_entry_wppb_manage_fields", "wppb_manage_fields_after_refresh_list" );
435
436
437 /**
438 * Function that calls the wppb_hide_all
439 *
440 * @since v.2.0
441 *
442 * @param void
443 *
444 * @return string
445 */
446 function wppb_hide_all_after_add( $id ){
447 echo "<script type=\"text/javascript\">wppb_hide_all( '#wppb_manage_fields' );</script>";
448 }
449 add_action("wck_ajax_add_form_wppb_manage_fields", "wppb_hide_all_after_add" );
450
451 /**
452 * Function that modifies the table header in Manage Fields to add Field Name, Field Type, Meta Key, Required
453 *
454 * @since v.2.0
455 *
456 * @param $list, $id
457 *
458 * @return string
459 */
460 function wppb_manage_fields_header( $list_header ){
461 return '<thead><tr><th class="wck-number">#</th><th class="wck-content">'. __( '<pre>Title</pre><pre>Type</pre><pre>Meta Name</pre><pre class="wppb-mb-head-required">Required</pre>', 'profilebuilder' ) .'</th><th class="wck-edit">'. __( 'Edit', 'profilebuilder' ) .'</th><th class="wck-delete">'. __( 'Delete', 'profilebuilder' ) .'</th></tr></thead>';
462 }
463 add_action( 'wck_metabox_content_header_wppb_manage_fields', 'wppb_manage_fields_header' );
464
465 /**
466 * Add contextual help to the side of manage fields for the shortcodes
467 *
468 * @since v.2.0
469 *
470 * @param $hook
471 *
472 * @return string
473 */
474 function wppb_add_content_before_manage_fields(){
475 ?>
476 <p><?php _e('Use these shortcodes on the pages you want the forms to be displayed:', 'profilebuilder'); ?></p>
477 <ul>
478 <li><strong class="nowrap">[wppb-register]</strong></li>
479 <li><strong class="nowrap">[wppb-edit-profile]</strong></li>
480 <li><strong class="nowrap">[wppb-register role="author"]</strong></li>
481 </ul>
482 <p><?php _e("If you're interested in displaying different fields in the registration and edit profile forms, please use the Multiple Registration & Edit Profile Forms Addon.", 'profilebuilder'); ?></p>
483 <?php
484 }
485 add_action('wck_metabox_content_wppb_manage_fields_info', 'wppb_add_content_before_manage_fields');
486
487
488 /**
489 * Function that calls the wppb_edit_form_properties
490 *
491 * @since v.2.0
492 *
493 * @param void
494 *
495 * @return string
496 */
497 function wppb_remove_properties_from_added_form( $meta_name, $id, $element_id ){
498 if ( ( $meta_name == 'wppb_epf_fields' ) || ( $meta_name == 'wppb_rf_fields' ) )
499 echo "<script type=\"text/javascript\">wppb_disable_delete_on_default_mandatory_fields();</script>";
500
501 if ( $meta_name == 'wppb_manage_fields' )
502 echo "<script type=\"text/javascript\">wppb_edit_form_properties( '#container_wppb_manage_fields', 'update_container_wppb_manage_fields_".$element_id."' );</script>";
503 }
504 add_action("wck_after_adding_form", "wppb_remove_properties_from_added_form", 10, 3);
505