PluginProbe
Profile Extra Fields by BestWebSoft / trunk
Profile Extra Fields by BestWebSoft vtrunk
1.3.7 1.3.6 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3.0 1.3.2 1.3.3 1.3.4 1.3.5 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 All 38 releases
profile-extra-fields / profile-extra-fields.php

profile-extra-fields.php in Profile Extra Fields by BestWebSoft trunk, at profile-extra-fields.php

5,656 lines 237.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 Plugin Name: Profile Extra Fields by BestWebSoft
4 Plugin URI: https://bestwebsoft.com/products/wordpress/plugins/profile-extra-fields/
5 Description: Add extra fields to default WordPress user profile. The easiest way to create and manage additional custom values.
6 Author: BestWebSoft
7 Text Domain: profile-extra-fields
8 Domain Path: /languages
9 Version: 1.3.7
10 Author URI: https://bestwebsoft.com/
11 License: GPLv3 or later
12 */
13
14 /*
15 @ Copyright 2021 BestWebSoft ( https://support.bestwebsoft.com )
16
17 This program is free software; you can redistribute it and/or modify
18 it under the terms of the GNU General Public License, version 2, as
19 published by the Free Software Foundation.
20
21 This program is distributed in the hope that it will be useful,
22 but WITHOUT ANY WARRANTY; without even the implied warranty of
23 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 GNU General Public License for more details.
25
26 You should have received a copy of the GNU General Public License
27 along with this program; if not, write to the Free Software
28 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
29 */
30
31 if ( ! defined( 'ABSPATH' ) ) {
32 exit;
33 }
34
35 if ( file_exists( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' ) ) {
36 /**
37 * Create new class to displaying fields*/
38 if ( ! class_exists( 'WP_List_Table' ) ) {
39 require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php';
40 }
41
42 require_once( dirname( __FILE__ ) . '/includes/class-prflxtrflds-fields-list.php' );
43
44 require_once( dirname( __FILE__ ) . '/includes/class-prflxtrflds-shortcode-list.php' );
45
46 require_once( dirname( __FILE__ ) . '/includes/class-prflxtrflds-userdata-list.php' );
47
48 }
49
50 if ( ! function_exists( 'prflxtrflds_admin_menu' ) ) {
51 /**
52 * Add WordPress page 'bws_panel' and sub-page of this plugin to admin-panel.
53 */
54 function prflxtrflds_admin_menu() {
55 global $submenu, $prflxtrflds_plugin_info, $wp_version;
56
57 $settings = add_menu_page(
58 __( 'All Fields', 'profile-extra-fields' ),
59 'Profile Extra Fields',
60 'manage_options',
61 'profile-extra-fields.php',
62 'prflxtrflds_fields'
63 );
64 add_submenu_page(
65 'profile-extra-fields.php',
66 __( 'All Fields', 'profile-extra-fields' ),
67 __( 'All Fields', 'profile-extra-fields' ),
68 'manage_options',
69 'profile-extra-fields.php',
70 'prflxtrflds_fields'
71 );
72 add_submenu_page(
73 'profile-extra-fields.php',
74 __( 'Add New Fields', 'profile-extra-fields' ),
75 __( 'Add New', 'profile-extra-fields' ),
76 'manage_options',
77 'profile-extra-field-add-new.php',
78 'prflxtrflds_edit_field'
79 );
80 add_submenu_page(
81 'profile-extra-fields.php',
82 __( 'Profile Extra Fields Settings', 'profile-extra-fields' ),
83 __( 'Settings', 'profile-extra-fields' ),
84 'manage_options',
85 'profile-extra-fields-settings.php',
86 'prflxtrflds_settings_page'
87 );
88 add_submenu_page(
89 'profile-extra-fields.php',
90 'BWS Panel',
91 'BWS Panel',
92 'manage_options',
93 'prflxtrflds-bws-panel',
94 'bws_add_menu_render'
95 );
96 if ( isset( $submenu['profile-extra-fields.php'] ) ) {
97 $submenu['profile-extra-fields.php'][] = array(
98 '<span style="color:#d86463"> ' . __( 'Upgrade to Pro', 'profile-extra-fields' ) . '</span>',
99 'manage_options',
100 'https://bestwebsoft.com/products/wordpress/plugins/profile-extra-fields/?k=c37eed44c2fe607f3400914345cbdc8a&pn=300&v=' . $prflxtrflds_plugin_info['Version'] . '&wp_v=' . $wp_version,
101 );
102 }
103
104 add_action( 'load-' . $settings, 'prflxtrflds_screen_options' );
105 }
106 }
107
108 if ( ! function_exists( 'prflxtrflds_plugins_loaded' ) ) {
109 /**
110 * Internationalization
111 */
112 function prflxtrflds_plugins_loaded() {
113 load_plugin_textdomain( 'profile-extra-fields', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
114 }
115 }
116
117 if ( ! function_exists( 'prflxtrflds_init' ) ) {
118 /**
119 * Plugin init
120 */
121 function prflxtrflds_init() {
122 global $prflxtrflds_plugin_info;
123
124 $plugins_data = apply_filters( 'bws_bkng_prflxtrflds_get_data', $plugins_data = array() );
125 foreach ( (array) $plugins_data as $plugin ) {
126 if ( isset( $plugin['actions'] ) ) {
127 foreach ( $plugin['actions'] as $action ) {
128 add_action( $action, 'prflxtrflds_fields_table' );
129 }
130 }
131 }
132
133 /** Add bws menu. use in prflxtrflds_admin_menu*/
134 require_once dirname( __FILE__ ) . '/bws_menu/bws_include.php';
135 bws_include_init( plugin_basename( __FILE__ ) );
136 /** Get plugin data */
137 if ( empty( $prflxtrflds_plugin_info ) ) {
138 if ( ! function_exists( 'get_plugin_data' ) ) {
139 require_once ABSPATH . 'wp-admin/includes/plugin.php';
140 }
141 $prflxtrflds_plugin_info = get_plugin_data( __FILE__ );
142 }
143 /** Function check if plugin is compatible with current WP version */
144 bws_wp_min_version_check( plugin_basename( __FILE__ ), $prflxtrflds_plugin_info, '4.5' );
145
146 /** Call register settings function */
147 if ( ! is_admin() || ( isset( $_GET['page'] ) && in_array( $_GET['page'], array( 'profile-extra-fields.php', 'profile-extra-fields-settings.php' ) ) ) ) {
148 prflxtrflds_settings();
149 }
150 }
151 }
152
153 if ( ! function_exists( 'prflxtrflds_admin_init' ) ) {
154 /**
155 * Admin init
156 */
157 function prflxtrflds_admin_init() {
158 global $bws_plugin_info, $prflxtrflds_plugin_info, $bws_shortcode_list, $pagenow, $prflxtrflds_options;
159 /** Add variable for bws_menu */
160 if ( empty( $bws_plugin_info ) ) {
161 $bws_plugin_info = array(
162 'id' => '300',
163 'version' => $prflxtrflds_plugin_info['Version'],
164 );
165 }
166
167 /** Add gallery to global $bws_shortcode_list */
168 $bws_shortcode_list['prflxtrflds'] = array(
169 'name' => 'Profile Extra Fields',
170 'js_function' => 'prflxtrflds_shortcode_init',
171 );
172
173 if ( 'plugins.php' === $pagenow ) {
174 /** Install the option defaults */
175 if ( function_exists( 'bws_plugin_banner_go_pro' ) ) {
176 prflxtrflds_settings();
177 bws_plugin_banner_go_pro( $prflxtrflds_options, $prflxtrflds_plugin_info, 'prflxtrflds', 'profile-extra-fields', 'c37eed44c2fe607f3400914345cbdc8a', '300', 'profile-extra-fields' );
178 }
179 }
180
181 if ( isset( $_POST['prflxtrflds_export_submit'] ) && isset( $_POST['prflxtrflds_export_field'] ) && wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['prflxtrflds_export_field'] ) ), 'prflxtrflds_export_action' ) ) {
182 if ( current_user_can( 'edit_users' ) && isset( $_POST['prflxtrflds_format_export'] ) ) {
183 $format_export = sanitize_text_field( wp_unslash( $_POST['prflxtrflds_format_export'] ) );
184 $format = in_array( $format_export, array( 'columns', 'rows' ) ) ? $format_export : 'columns';
185 $nonce = wp_create_nonce( 'prflxtrflds_export_action' );
186 prflxtrflds_export_file( $format, $nonce );
187 }
188 }
189 }
190 }
191
192 if ( ! function_exists( 'prflxtrflds_export_file' ) ) {
193 /**
194 * Admin init
195 *
196 * @param string $format Format for export.
197 * @param string $nonce Nonce for action.
198 */
199 function prflxtrflds_export_file( $format, $nonce ) {
200 if ( wp_verify_nonce( $nonce, 'prflxtrflds_export_action' ) && current_user_can( 'edit_users' ) ) {
201 global $wp_filesystem;
202 WP_Filesystem();
203 $param = array(
204 'display' => $format,
205 'export' => true,
206 );
207 $export = prflxtrflds_show_data( $param );
208 $upload_dir = wp_upload_dir();
209 $file_name = wp_tempnam( 'tmp', $upload_dir['path'] . '/' );
210 if ( ! $file_name ) {
211 return false;
212 }
213 $export_str = '';
214 if ( is_array( $export ) ) {
215 foreach ( $export as $export_array ) {
216 $export_str .= '"' . implode( '";"', $export_array ) . '";' . PHP_EOL;
217 }
218 }
219 $result = $wp_filesystem->put_contents( $file_name, $export_str );
220 if ( ! $result ) {
221 return false;
222 }
223 header( 'Content-Type: application/octet-stream' );
224 header( 'Content-Disposition: attachment; filename="prflxtrflds_' . $format . '_export.csv"' );
225 echo wp_kses_post( $wp_filesystem->get_contents( $file_name ) );
226 unlink( $file_name );
227 exit();
228 }
229 }
230 }
231
232 if ( ! function_exists( 'prflxtrflds_settings' ) ) {
233 /**
234 * This is settings functions
235 */
236 function prflxtrflds_settings() {
237 global $prflxtrflds_options, $prflxtrflds_plugin_info, $wpdb;
238 /** Db version in plugin */
239 $db_version = '1.6';
240
241 /** Install the option defaults */
242 if ( ! get_option( 'prflxtrflds_options' ) ) {
243 $option_defaults = prflxtrflds_get_options_default();
244 add_option( 'prflxtrflds_options', $option_defaults );
245 }
246
247 /** Get options from database */
248 $prflxtrflds_options = get_option( 'prflxtrflds_options' );
249 /** Update options if other option version */
250 if ( ! isset( $prflxtrflds_options['plugin_option_version'] ) || $prflxtrflds_options['plugin_option_version'] !== $prflxtrflds_plugin_info['Version'] ) {
251 if ( isset( $prflxtrflds_options['plugin_option_version'] ) ) {
252 $prflxtrflds_prev_version = str_replace( 'pro-', '', $prflxtrflds_options['plugin_option_version'] );
253 if ( version_compare( $prflxtrflds_prev_version, '1.1.4', '<=' ) ) {
254 /*In version 1.1.5, the field type "textarea" has been added and we need to rewrite the db*/
255 $wpdb->query( 'UPDATE `' . $wpdb->base_prefix . 'prflxtrflds_fields_id` SET `field_type_id` = IF ( `field_type_id` > 1 ,`field_type_id` + 1 , `field_type_id`);' );
256 }
257 }
258 if ( ! empty( $prflxtrflds_options['available_values'] ) ) {
259 foreach ( $prflxtrflds_options['available_values'] as $key => $value ) {
260 if ( '-1' === $value ) {
261 unset( $prflxtrflds_options['available_values'][ $key ] );
262 }
263 }
264 }
265 $option_defaults = prflxtrflds_get_options_default();
266 $option_defaults['display_settings_notice'] = 0;
267 $prflxtrflds_options = array_merge( $option_defaults, $prflxtrflds_options );
268 $prflxtrflds_options['plugin_option_version'] = $prflxtrflds_plugin_info['Version'];
269
270 /** Show pro features */
271 $prflxtrflds_options['hide_premium_options'] = array();
272
273 $update_option = true;
274 prflxtrflds_activation();
275 }
276
277 /** Update database */
278 if ( ! isset( $prflxtrflds_options['plugin_db_version'] ) ||
279 $prflxtrflds_options['plugin_db_version'] !== $db_version
280 ) {
281 prflxtrflds_create_table();
282
283 $column_exists = $wpdb->query( 'SHOW COLUMNS FROM `' . $wpdb->base_prefix . "prflxtrflds_roles_and_fields` LIKE 'editable'" );
284 if ( 0 === $column_exists ) {
285 $wpdb->query(
286 'ALTER TABLE `' . $wpdb->base_prefix . "prflxtrflds_roles_and_fields`
287 ADD `editable` tinyint(1) NOT NULL DEFAULT '1',
288 ADD `visible` tinyint(1) NOT NULL DEFAULT '1'"
289 );
290 }
291
292 $required_type = $wpdb->get_var(
293 "SELECT DATA_TYPE
294 FROM INFORMATION_SCHEMA.COLUMNS
295 WHERE
296 TABLE_NAME = '" . $wpdb->base_prefix . "prflxtrflds_fields_id' AND
297 COLUMN_NAME = 'required'"
298 );
299
300 if ( 'varchar' !== $required_type ) {
301 $wpdb->query(
302 'ALTER TABLE `' . $wpdb->base_prefix . 'prflxtrflds_fields_id`
303 MODIFY COLUMN `required` VARCHAR(255) COLLATE utf8_general_ci'
304 );
305
306 $wpdb->update(
307 $wpdb->base_prefix . 'prflxtrflds_fields_id',
308 array( 'required' => '' ),
309 array( 'required' => '0' )
310 );
311 $wpdb->update(
312 $wpdb->base_prefix . 'prflxtrflds_fields_id',
313 array( 'required' => '*' ),
314 array( 'required' => '1' )
315 );
316 }
317
318 $fields = $wpdb->get_results( 'SELECT * FROM `' . $wpdb->base_prefix . 'prflxtrflds_fields_id`' );
319
320 if ( ! empty( $fields ) && isset( $fields[0]->show_in_register_form ) ) {
321 foreach ( $fields as $field ) {
322 if ( 1 === $field->show_in_register_form ) {
323 $data = array(
324 'field_id' => $field->field_id,
325 'show_in' => 'register_form',
326 'value' => esc_sql( $field->show_in_register_form ),
327 );
328 $wpdb->insert( $wpdb->base_prefix . 'prflxtrflds_fields_meta', $data );
329 }
330 }
331 $wpdb->query( 'ALTER TABLE `' . $wpdb->base_prefix . 'prflxtrflds_fields_id` DROP COLUMN `show_in_register_form`' );
332 }
333
334 if ( ! empty( $fields ) && isset( $fields[0]->show_in_woocomerce_form ) ) {
335 foreach ( $fields as $field ) {
336 if ( 1 === $field->show_in_woocomerce_form ) {
337 $value = array(
338 'checkout' => $field->show_in_woocomerce_checkout,
339 'register' => $field->show_in_woocomerce_registration,
340 );
341 $data = array(
342 'field_id' => $field->field_id,
343 'show_in' => 'woocommerce',
344 'value' => maybe_serialize( $value ),
345 );
346 $wpdb->insert( $wpdb->base_prefix . 'prflxtrflds_fields_meta', $data );
347 }
348 }
349 $wpdb->query(
350 'ALTER TABLE `' . $wpdb->base_prefix . 'prflxtrflds_fields_id`
351 DROP `show_in_woocomerce_form`,
352 DROP `show_in_woocomerce_checkout`,
353 DROP `show_in_woocomerce_registration`'
354 );
355 }
356
357 $prflxtrflds_options['plugin_db_version'] = $db_version;
358 $update_option = true;
359 }
360
361 /** If option was updated */
362 if ( isset( $update_option ) ) {
363 update_option( 'prflxtrflds_options', $prflxtrflds_options );
364 }
365 }
366 }
367
368 if ( ! function_exists( 'prflxtrflds_get_options_default' ) ) {
369 /**
370 * Get default options for plugin
371 */
372 function prflxtrflds_get_options_default() {
373 global $prflxtrflds_plugin_info;
374 /** Create array with default options */
375 return array(
376 'plugin_option_version' => $prflxtrflds_plugin_info['Version'],
377 'display_settings_notice' => 1,
378 'suggest_feature_banner' => 1,
379 'sort_sequence' => 'ASC',
380 'available_fields' => array(),
381 'available_values' => array(),
382 'show_empty_columns' => 0,
383 'show_id' => 1,
384 'header_table' => 'columns', /*rows */
385 'empty_value' => __( 'The field is empty', 'profile-extra-fields' ),
386 'not_available_message' => __( 'N/A', 'profile-extra-fields' ),
387 'shortcode_debug' => 1,
388 'display_user_name' => 'username',
389 'user_section_profile_title' => __( 'Profile Extra Fields', 'profile-extra-fields' ),
390 'user_section_car_title' => __( 'Car Rental V2 Extra Fields', 'profile-extra-fields' ),
391 'notify_admin_register' => 0,//wp_new_user_notification_email_admin
392 'notify_user_register' => 0,
393 'notify_admin_register_subject' => __( 'New User Registration on Your Website', 'profile-extra-fields' ),
394 'notify_admin_register_message' => __( 'Hello,
395
396 A new user has registered on your website.
397
398 User Details:
399
400 Username: {username}
401
402 Email: {email}
403
404 Registration Date: {date}
405
406 {profile_extra_fields}
407
408 You can view and manage this user in your WordPress dashboard {dashboardurl}.', 'profile-extra-fields' ),
409 'notify_admin_update_subject' => __( 'User Profile Updated', 'profile-extra-fields' ),
410 'notify_admin_update_message' => __( 'Hello,
411
412 A user has updated their profile on your website.
413
414 User Details:
415
416 Username: {username}
417
418 Email: {email}
419
420 You may review the updated information in your WordPress dashboard {dashboardurl}.', 'profile-extra-fields' ),
421 'notify_user_register_subject' => __( 'Welcome! Your Registration is Complete', 'profile-extra-fields' ),
422 'notify_user_register_message' => __( 'Hello {username},
423
424 Thank you for registering on our website.
425
426 Your account has been successfully created, and you can now log in using your credentials.
427
428 To set your password, visit the following address: {loginurl}
429
430 If you have any questions, feel free to contact us.', 'profile-extra-fields' ),
431 'notify_user_update_subject' => __( 'Your Profile Has Been Updated', 'profile-extra-fields' ),
432 'notify_user_update_message' => __( 'Hello {username},
433
434 This is a confirmation that your profile information has been successfully updated.
435
436 If you did not make these changes, please contact us immediately or change your password {loginurl}.', 'profile-extra-fields' ),
437 );
438 }
439 }
440
441 if ( ! function_exists( 'prflxtrflds_get_field_type_id' ) ) {
442 /**
443 * All type for fields
444 */
445 function prflxtrflds_get_field_type_id() {
446 /** Conformity between field type id and field type name */
447 return array(
448 '1' => __( 'Text field', 'profile-extra-fields' ),
449 '2' => __( 'Textarea', 'profile-extra-fields' ),
450 '3' => __( 'Checkbox', 'profile-extra-fields' ),
451 '4' => __( 'Radio button', 'profile-extra-fields' ),
452 '5' => __( 'Drop down list', 'profile-extra-fields' ),
453 '6' => __( 'Date', 'profile-extra-fields' ),
454 '7' => __( 'Time', 'profile-extra-fields' ),
455 '8' => __( 'Datetime', 'profile-extra-fields' ),
456 '9' => __( 'Number', 'profile-extra-fields' ),
457 '10' => __( 'Phone number', 'profile-extra-fields' ),
458 '11' => __( 'URL link', 'profile-extra-fields' ),
459 '12' => __( 'Attachment', 'profile-extra-fields' ),
460 '13' => __( 'Country', 'profile-extra-fields' ),
461 );
462 }
463 }
464
465 if ( ! function_exists( 'prflxtrflds_get_country' ) ) {
466 /**
467 * Countries array
468 */
469 function prflxtrflds_get_country() {
470 return array(
471 '1' => __( 'Afghanistan', 'profile-extra-fields' ),
472 '2' => __( 'Albania', 'profile-extra-fields' ),
473 '3' => __( 'Algeria', 'profile-extra-fields' ),
474 '4' => __( 'Andorra', 'profile-extra-fields' ),
475 '5' => __( 'Angola', 'profile-extra-fields' ),
476 '6' => __( 'Antigua and Barbuda', 'profile-extra-fields' ),
477 '7' => __( 'Argentina', 'profile-extra-fields' ),
478 '8' => __( 'Armenia', 'profile-extra-fields' ),
479 '9' => __( 'Australia', 'profile-extra-fields' ),
480 '10' => __( 'Austria', 'profile-extra-fields' ),
481 '11' => __( 'Azerbaijan', 'profile-extra-fields' ),
482 '12' => __( 'Bahamas', 'profile-extra-fields' ),
483 '13' => __( 'Bahrain', 'profile-extra-fields' ),
484 '14' => __( 'Bangladesh', 'profile-extra-fields' ),
485 '15' => __( 'Barbados', 'profile-extra-fields' ),
486 '16' => __( 'Belarus', 'profile-extra-fields' ),
487 '17' => __( 'Belgium', 'profile-extra-fields' ),
488 '18' => __( 'Belize', 'profile-extra-fields' ),
489 '19' => __( 'Benin', 'profile-extra-fields' ),
490 '20' => __( 'Bhutan', 'profile-extra-fields' ),
491 '21' => __( 'Bolivia', 'profile-extra-fields' ),
492 '22' => __( 'Bosnia and Herzegovina', 'profile-extra-fields' ),
493 '23' => __( 'Botswana', 'profile-extra-fields' ),
494 '24' => __( 'Brazil', 'profile-extra-fields' ),
495 '25' => __( 'Brunei', 'profile-extra-fields' ),
496 '26' => __( 'Bulgaria', 'profile-extra-fields' ),
497 '27' => __( 'Burkina Faso', 'profile-extra-fields' ),
498 '28' => __( 'Burundi', 'profile-extra-fields' ),
499 '29' => __( 'Cambodia', 'profile-extra-fields' ),
500 '30' => __( 'Cameroon', 'profile-extra-fields' ),
501 '31' => __( 'Canada', 'profile-extra-fields' ),
502 '32' => __( 'Cape Verde', 'profile-extra-fields' ),
503 '33' => __( 'Central African Republic', 'profile-extra-fields' ),
504 '34' => __( 'Chad', 'profile-extra-fields' ),
505 '35' => __( 'Chile', 'profile-extra-fields' ),
506 '36' => __( 'China', 'profile-extra-fields' ),
507 '37' => __( 'Colombia', 'profile-extra-fields' ),
508 '38' => __( 'Comoros', 'profile-extra-fields' ),
509 '39' => __( 'Costa Rica', 'profile-extra-fields' ),
510 '40' => __( 'Croatia', 'profile-extra-fields' ),
511 '41' => __( 'Cuba', 'profile-extra-fields' ),
512 '42' => __( 'Cyprus', 'profile-extra-fields' ),
513 '43' => __( 'Czech Republic', 'profile-extra-fields' ),
514 '44' => __( 'Democratic Republic of the Congo', 'profile-extra-fields' ),
515 '45' => __( 'Denmark', 'profile-extra-fields' ),
516 '46' => __( 'Djibouti', 'profile-extra-fields' ),
517 '47' => __( 'Dominica', 'profile-extra-fields' ),
518 '48' => __( 'Dominican Republic', 'profile-extra-fields' ),
519 '49' => __( 'Ecuador', 'profile-extra-fields' ),
520 '50' => __( 'Egypt', 'profile-extra-fields' ),
521 '51' => __( 'El Salvador', 'profile-extra-fields' ),
522 '52' => __( 'Equatorial Guinea', 'profile-extra-fields' ),
523 '53' => __( 'Eritrea', 'profile-extra-fields' ),
524 '54' => __( 'Eswatini', 'profile-extra-fields' ),
525 '55' => __( 'Estonia', 'profile-extra-fields' ),
526 '56' => __( 'Ethiopia', 'profile-extra-fields' ),
527 '57' => __( 'Fiji', 'profile-extra-fields' ),
528 '58' => __( 'Finland', 'profile-extra-fields' ),
529 '59' => __( 'France', 'profile-extra-fields' ),
530 '60' => __( 'Gabon', 'profile-extra-fields' ),
531 '61' => __( 'Gambia', 'profile-extra-fields' ),
532 '62' => __( 'Georgia', 'profile-extra-fields' ),
533 '63' => __( 'Germany', 'profile-extra-fields' ),
534 '64' => __( 'Ghana', 'profile-extra-fields' ),
535 '65' => __( 'Greece', 'profile-extra-fields' ),
536 '66' => __( 'Grenada', 'profile-extra-fields' ),
537 '67' => __( 'Guatemala', 'profile-extra-fields' ),
538 '68' => __( 'Guinea', 'profile-extra-fields' ),
539 '69' => __( 'Guinea-Bissau', 'profile-extra-fields' ),
540 '70' => __( 'Guyana', 'profile-extra-fields' ),
541 '71' => __( 'Haiti', 'profile-extra-fields' ),
542 '72' => __( 'Honduras', 'profile-extra-fields' ),
543 '73' => __( 'Hungary', 'profile-extra-fields' ),
544 '74' => __( 'Iceland', 'profile-extra-fields' ),
545 '75' => __( 'India', 'profile-extra-fields' ),
546 '76' => __( 'Indonesia', 'profile-extra-fields' ),
547 '77' => __( 'Iran', 'profile-extra-fields' ),
548 '78' => __( 'Iraq', 'profile-extra-fields' ),
549 '79' => __( 'Ireland', 'profile-extra-fields' ),
550 '80' => __( 'Israel', 'profile-extra-fields' ),
551 '81' => __( 'Italy', 'profile-extra-fields' ),
552 '82' => __( 'Jamaica', 'profile-extra-fields' ),
553 '83' => __( 'Japan', 'profile-extra-fields' ),
554 '84' => __( 'Jordan', 'profile-extra-fields' ),
555 '85' => __( 'Kazakhstan', 'profile-extra-fields' ),
556 '86' => __( 'Kenya', 'profile-extra-fields' ),
557 '87' => __( 'Kiribati', 'profile-extra-fields' ),
558 '88' => __( 'Kuwait', 'profile-extra-fields' ),
559 '89' => __( 'Kyrgyzstan', 'profile-extra-fields' ),
560 '90' => __( 'Laos', 'profile-extra-fields' ),
561 '91' => __( 'Latvia', 'profile-extra-fields' ),
562 '92' => __( 'Lebanon', 'profile-extra-fields' ),
563 '93' => __( 'Lesotho', 'profile-extra-fields' ),
564 '94' => __( 'Liberia', 'profile-extra-fields' ),
565 '95' => __( 'Libya', 'profile-extra-fields' ),
566 '96' => __( 'Liechtenstein', 'profile-extra-fields' ),
567 '97' => __( 'Lithuania', 'profile-extra-fields' ),
568 '98' => __( 'Luxembourg', 'profile-extra-fields' ),
569 '99' => __( 'Madagascar', 'profile-extra-fields' ),
570 '100' => __( 'Malawi', 'profile-extra-fields' ),
571 '101' => __( 'Malaysia', 'profile-extra-fields' ),
572 '102' => __( 'Maldives', 'profile-extra-fields' ),
573 '103' => __( 'Mali', 'profile-extra-fields' ),
574 '104' => __( 'Malta', 'profile-extra-fields' ),
575 '105' => __( 'Marshall Islands', 'profile-extra-fields' ),
576 '106' => __( 'Mauritania', 'profile-extra-fields' ),
577 '107' => __( 'Mauritius', 'profile-extra-fields' ),
578 '108' => __( 'Mexico', 'profile-extra-fields' ),
579 '109' => __( 'Micronesia', 'profile-extra-fields' ),
580 '110' => __( 'Moldova', 'profile-extra-fields' ),
581 '111' => __( 'Monaco', 'profile-extra-fields' ),
582 '112' => __( 'Mongolia', 'profile-extra-fields' ),
583 '113' => __( 'Montenegro', 'profile-extra-fields' ),
584 '114' => __( 'Morocco', 'profile-extra-fields' ),
585 '115' => __( 'Mozambique', 'profile-extra-fields' ),
586 '116' => __( 'Myanmar', 'profile-extra-fields' ),
587 '117' => __( 'Namibia', 'profile-extra-fields' ),
588 '118' => __( 'Nauru', 'profile-extra-fields' ),
589 '119' => __( 'Nepal', 'profile-extra-fields' ),
590 '120' => __( 'Netherlands', 'profile-extra-fields' ),
591 '121' => __( 'New Zealand', 'profile-extra-fields' ),
592 '122' => __( 'Nicaragua', 'profile-extra-fields' ),
593 '123' => __( 'Niger', 'profile-extra-fields' ),
594 '124' => __( 'Nigeria', 'profile-extra-fields' ),
595 '125' => __( 'North Korea', 'profile-extra-fields' ),
596 '126' => __( 'North Macedonia', 'profile-extra-fields' ),
597 '127' => __( 'Norway', 'profile-extra-fields' ),
598 '128' => __( 'Oman', 'profile-extra-fields' ),
599 '129' => __( 'Pakistan', 'profile-extra-fields' ),
600 '130' => __( 'Palau', 'profile-extra-fields' ),
601 '131' => __( 'Palestine', 'profile-extra-fields' ),
602 '132' => __( 'Panama', 'profile-extra-fields' ),
603 '133' => __( 'Papua New Guinea', 'profile-extra-fields' ),
604 '134' => __( 'Paraguay', 'profile-extra-fields' ),
605 '135' => __( 'Peru', 'profile-extra-fields' ),
606 '136' => __( 'Philippines', 'profile-extra-fields' ),
607 '137' => __( 'Poland', 'profile-extra-fields' ),
608 '138' => __( 'Portugal', 'profile-extra-fields' ),
609 '139' => __( 'Qatar', 'profile-extra-fields' ),
610 '140' => __( 'Republic of the Congo', 'profile-extra-fields' ),
611 '141' => __( 'Romania', 'profile-extra-fields' ),
612 '142' => __( 'Russia', 'profile-extra-fields' ),
613 '143' => __( 'Rwanda', 'profile-extra-fields' ),
614 '144' => __( 'Saint Kitts and Nevis', 'profile-extra-fields' ),
615 '145' => __( 'Saint Lucia', 'profile-extra-fields' ),
616 '146' => __( 'Saint Vincent and the Grenadines', 'profile-extra-fields' ),
617 '147' => __( 'Samoa', 'profile-extra-fields' ),
618 '148' => __( 'San Marino', 'profile-extra-fields' ),
619 '149' => __( 'Sao Tome and Principe', 'profile-extra-fields' ),
620 '150' => __( 'Saudi Arabia', 'profile-extra-fields' ),
621 '151' => __( 'Senegal', 'profile-extra-fields' ),
622 '152' => __( 'Serbia', 'profile-extra-fields' ),
623 '153' => __( 'Seychelles', 'profile-extra-fields' ),
624 '154' => __( 'Sierra Leone', 'profile-extra-fields' ),
625 '155' => __( 'Singapore', 'profile-extra-fields' ),
626 '156' => __( 'Slovakia', 'profile-extra-fields' ),
627 '157' => __( 'Slovenia', 'profile-extra-fields' ),
628 '158' => __( 'Solomon Islands', 'profile-extra-fields' ),
629 '159' => __( 'Somalia', 'profile-extra-fields' ),
630 '160' => __( 'South Africa', 'profile-extra-fields' ),
631 '161' => __( 'South Korea', 'profile-extra-fields' ),
632 '162' => __( 'South Sudan', 'profile-extra-fields' ),
633 '163' => __( 'Spain', 'profile-extra-fields' ),
634 '164' => __( 'Sri Lanka', 'profile-extra-fields' ),
635 '165' => __( 'Sudan', 'profile-extra-fields' ),
636 '166' => __( 'Suriname', 'profile-extra-fields' ),
637 '167' => __( 'Sweden', 'profile-extra-fields' ),
638 '168' => __( 'Switzerland', 'profile-extra-fields' ),
639 '169' => __( 'Syria', 'profile-extra-fields' ),
640 '170' => __( 'Tajikistan', 'profile-extra-fields' ),
641 '171' => __( 'Tanzania', 'profile-extra-fields' ),
642 '172' => __( 'Thailand', 'profile-extra-fields' ),
643 '173' => __( 'Timor-Leste', 'profile-extra-fields' ),
644 '174' => __( 'Togo', 'profile-extra-fields' ),
645 '175' => __( 'Tonga', 'profile-extra-fields' ),
646 '176' => __( 'Trinidad and Tobago', 'profile-extra-fields' ),
647 '177' => __( 'Tunisia', 'profile-extra-fields' ),
648 '178' => __( 'Turkey', 'profile-extra-fields' ),
649 '179' => __( 'Turkmenistan', 'profile-extra-fields' ),
650 '180' => __( 'Tuvalu', 'profile-extra-fields' ),
651 '181' => __( 'Uganda', 'profile-extra-fields' ),
652 '182' => __( 'Ukraine', 'profile-extra-fields' ),
653 '183' => __( 'United Arab Emirates', 'profile-extra-fields' ),
654 '184' => __( 'United Kingdom', 'profile-extra-fields' ),
655 '185' => __( 'United States', 'profile-extra-fields' ),
656 '186' => __( 'Uruguay', 'profile-extra-fields' ),
657 '187' => __( 'Uzbekistan', 'profile-extra-fields' ),
658 '188' => __( 'Vanuatu', 'profile-extra-fields' ),
659 '189' => __( 'Vatican City', 'profile-extra-fields' ),
660 '190' => __( 'Venezuela', 'profile-extra-fields' ),
661 '191' => __( 'Vietnam', 'profile-extra-fields' ),
662 '192' => __( 'Yemen', 'profile-extra-fields' ),
663 '193' => __( 'Zambia', 'profile-extra-fields' ),
664 '194' => __( 'Zimbabwe', 'profile-extra-fields' ),
665 );
666 }
667 }
668
669 if ( ! function_exists( 'prflxtrflds_create_table' ) ) {
670 /**
671 * Create table in DB
672 */
673 function prflxtrflds_create_table() {
674 global $wpdb;
675
676 /** Require db Delta */
677 require_once ABSPATH . 'wp-admin/includes/upgrade.php';
678 /** Create table for roles types */
679 $table_name = $wpdb->base_prefix . 'prflxtrflds_roles_id';
680 $query = $wpdb->prepare( 'SHOW TABLES LIKE %s', $wpdb->esc_like( $table_name ) );
681 if ( $wpdb->get_var( $query ) !== $table_name ) {
682 /* create table for roles types */
683 $sql = 'CREATE TABLE `' . $table_name . '` (
684 `role_id` bigint(20) NOT NULL AUTO_INCREMENT,
685 `role` VARCHAR(255) NOT NULL COLLATE utf8_general_ci,
686 `role_name` VARCHAR(255) NOT NULL COLLATE utf8_general_ci,
687 UNIQUE KEY (role_id)
688 );';
689 /** Call dbDelta */
690 dbDelta( $sql );
691 }
692
693 $table_name = $wpdb->base_prefix . 'prflxtrflds_user_roles';
694 $query = $wpdb->prepare( 'SHOW TABLES LIKE %s', $wpdb->esc_like( $table_name ) );
695
696 if ( $wpdb->get_var( $query ) !== $table_name ) {
697 /* create table for conformity user_id and user role id */
698 $sql = 'CREATE TABLE `' . $table_name . '` (
699 `user_id` bigint(20) NOT NULL,
700 `role_id` bigint(20) NOT NULL,
701 UNIQUE KEY (user_id)
702 );';
703 /** Call dbDelta */
704 dbDelta( $sql );
705 }
706 /** Create roles id */
707 if ( function_exists( 'prflxtrflds_update_user_roles' ) ) {
708 prflxtrflds_update_user_roles();
709 }
710
711 $table_name = $wpdb->base_prefix . 'prflxtrflds_fields_id';
712 $query = $wpdb->prepare( 'SHOW TABLES LIKE %s', $wpdb->esc_like( $table_name ) );
713
714 if ( $wpdb->get_var( $query ) !== $table_name ) {
715 $sql = 'CREATE TABLE `' . $table_name . "` (
716 `field_id` bigint(20) NOT NULL AUTO_INCREMENT,
717 `field_name` text NOT NULL COLLATE utf8_general_ci,
718 `required` VARCHAR(255) NOT NULL COLLATE utf8_general_ci,
719 `show_default` int(1) NOT NULL DEFAULT '0',
720 `show_always` int(1) NOT NULL DEFAULT '0',
721 `description` text NOT NULL COLLATE utf8_general_ci,
722 `field_type_id` bigint(20) NOT NULL DEFAULT '0',
723 UNIQUE KEY (field_id)
724 );";
725 /** Call dbDelta */
726 dbDelta( $sql );
727 }
728
729 $table_name = $wpdb->base_prefix . 'prflxtrflds_fields_meta';
730 $query = $wpdb->prepare( 'SHOW TABLES LIKE %s', $wpdb->esc_like( $table_name ) );
731
732 if ( $wpdb->get_var( $query ) !== $table_name ) {
733 $sql = 'CREATE TABLE `' . $table_name . '` (
734 `meta_id` bigint(20) NOT NULL AUTO_INCREMENT,
735 `field_id` bigint(20) NOT NULL,
736 `show_in` VARCHAR(255) NOT NULL COLLATE utf8_general_ci,
737 `value` TEXT NOT NULL COLLATE utf8_general_ci,
738 PRIMARY KEY (meta_id),
739 CONSTRAINT prflxtrflds_unique_pair UNIQUE (field_id, show_in)
740 );';
741 /** Call dbDelta */
742 dbDelta( $sql );
743 }
744
745 $table_name = $wpdb->base_prefix . 'prflxtrflds_roles_and_fields';
746 $query = $wpdb->prepare( 'SHOW TABLES LIKE %s', $wpdb->esc_like( $table_name ) );
747
748 if ( $wpdb->get_var( $query ) !== $table_name ) {
749 /* create table conformity roles id with fields id */
750 $sql = 'CREATE TABLE `' . $table_name . "` (
751 `role_id` bigint(20) NOT NULL DEFAULT '0',
752 `field_id` bigint(20) NOT NULL DEFAULT '0',
753 `field_order` bigint(20) NOT NULL DEFAULT '0',
754 `editable` tinyint(1) NOT NULL DEFAULT '1',
755 `visible` tinyint(1) NOT NULL DEFAULT '1',
756 UNIQUE KEY (role_id, field_id)
757 );";
758 /** Call dbDelta */
759 dbDelta( $sql );
760 }
761
762 $table_name = $wpdb->base_prefix . 'prflxtrflds_field_values';
763 $query = $wpdb->prepare( 'SHOW TABLES LIKE %s', $wpdb->esc_like( $table_name ) );
764
765 if ( $wpdb->get_var( $query ) !== $table_name ) {
766 /* create table conformity field id with available value */
767 $sql = 'CREATE TABLE `' . $table_name . "` (
768 `value_id` bigint(20) NOT NULL AUTO_INCREMENT,
769 `field_id` bigint(20) NOT NULL DEFAULT '0',
770 `value_name` VARCHAR(255) NOT NULL COLLATE utf8_general_ci,
771 `order` bigint(20) NOT NULL DEFAULT '0',
772 UNIQUE KEY (value_id)
773 );";
774 /** Call dbDelta */
775 dbDelta( $sql );
776 }
777
778 $table_name = $wpdb->base_prefix . 'prflxtrflds_user_field_data';
779 $query = $wpdb->prepare( 'SHOW TABLES LIKE %s', $wpdb->esc_like( $table_name ) );
780
781 if ( $wpdb->get_var( $query ) !== $table_name ) {
782 /* create table conformity field id with available value */
783 $sql = 'CREATE TABLE `' . $table_name . '` (
784 `id` bigint(20) NOT NULL AUTO_INCREMENT,
785 `field_id` bigint(20) NOT NULL,
786 `user_id` bigint(20) NOT NULL,
787 `user_value` TEXT NOT NULL COLLATE utf8_general_ci,
788 UNIQUE KEY (id)
789 );';
790 /** Call dbDelta */
791 dbDelta( $sql );
792 }
793 }
794 }
795
796 if ( ! function_exists( 'prflxtrflds_activation' ) ) {
797 /**
798 * Register uninstallhook
799 */
800 function prflxtrflds_activation() {
801 /** Uninstall plugin */
802 if ( is_multisite() ) {
803 switch_to_blog( 1 );
804 register_uninstall_hook( __FILE__, 'prflxtrflds_uninstall' );
805 restore_current_blog();
806 } else {
807 register_uninstall_hook( __FILE__, 'prflxtrflds_uninstall' );
808 }
809 }
810 }
811
812 if ( ! function_exists( 'prflxtrflds_update_roles_id' ) ) {
813 /**
814 * Create conformity between roles and role_id
815 */
816 function prflxtrflds_update_roles_id() {
817 global $wpdb, $wp_roles;
818 /** Get all available role */
819 $all_roles = $wp_roles->roles;
820 if ( ! empty( $all_roles ) ) {
821 /** Get role name from array */
822 foreach ( $all_roles as $role_key => $role ) {
823 /** Check role for existing in plugin table */
824 if ( ! $wpdb->get_var( $wpdb->prepare( 'SELECT `role_id` FROM `' . $wpdb->base_prefix . 'prflxtrflds_roles_id` WHERE `role` = %s LIMIT 1', $role_key ) ) ) {
825 /** Create field if not exist */
826 $wpdb->insert(
827 $wpdb->base_prefix . 'prflxtrflds_roles_id',
828 array(
829 'role' => esc_sql( $role_key ),
830 'role_name' => esc_sql( $role['name'] ),
831 ),
832 array( '%s', '%s' )
833 );
834 }
835 }
836 }
837 }
838 }
839
840 if ( ! function_exists( 'prflxtrflds_update_user_roles' ) ) {
841 /**
842 * Create conformity between user_id and role_id
843 *
844 * @param number $user_id User ID for update.
845 * @param string $role User role for update.
846 */
847 function prflxtrflds_update_user_roles( $user_id = null, $role = null ) {
848 global $wpdb;
849 /** First, update roles id */
850 if ( function_exists( 'prflxtrflds_update_roles_id' ) ) {
851 prflxtrflds_update_roles_id();
852 }
853 if ( null !== $user_id && ( null === $role || ! is_string( $role ) ) ) {
854 /** Get role if not allowed */
855 require_once ABSPATH . 'wp-includes/pluggable.php';
856 $user_data = get_userdata( $user_id );
857 /** Get user role by id */
858 if ( isset( $user_data ) ) {
859 $role = implode( ', ', $user_data->roles );
860 }
861 }
862
863 if ( ! isset( $role ) ) {
864 $users = get_users();
865 if ( $users ) {
866 /** If no selected roles, update roles for all users */
867 foreach ( $users as $user ) {
868 foreach ( $user->roles as $role_key ) {
869 /** Role stored in array, get */
870 $role_id = $wpdb->get_var( $wpdb->prepare( 'SELECT `role_id` FROM `' . $wpdb->base_prefix . 'prflxtrflds_roles_id` WHERE `role`= %s LIMIT 1', $role_key ) );
871 if ( $role_id ) {
872 /** Insert value */
873 $wpdb->replace(
874 $wpdb->base_prefix . 'prflxtrflds_user_roles',
875 array(
876 'user_id' => $user->ID,
877 'role_id' => $role_id,
878 ),
879 array( '%d', '%d' )
880 );
881 }
882 }
883 }
884 }
885 } else {
886 /** If role select, update role only for this user */
887 $role_id = $wpdb->get_var( $wpdb->prepare( 'SELECT `role_id` FROM `' . $wpdb->base_prefix . 'prflxtrflds_roles_id` WHERE `role`=%s LIMIT 1', $role ) );
888 if ( $role_id ) {
889 $wpdb->replace(
890 $wpdb->base_prefix . 'prflxtrflds_user_roles',
891 array(
892 'user_id' => $user_id,
893 'role_id' => $role_id,
894 ),
895 array( '%d', '%d' )
896 );
897 }
898 }
899 }
900 }
901
902 if ( ! function_exists( 'prflxtrflds_edit_field' ) ) {
903 /**
904 * Edit or create new field
905 */
906 function prflxtrflds_edit_field() {
907 global $wpdb, $prflxtrflds_options, $wp_version, $prflxtrflds_plugin_info;
908
909 $prflxtrflds_field_type_id = prflxtrflds_get_field_type_id();
910
911 $field_name = '';
912 $description = '';
913 $field_maxlength = '';
914 $field_rows = '';
915 $field_cols = '';
916 $field_required = '';
917 $error = '';
918 $field_order = 0;
919 $field_show_default = 0;
920 $field_show_always = 0;
921 $field_pattern = '***-**-**';
922
923 $available_values = array();
924 $show_in = array();
925 $field_type_id = '1';
926 $field_date_format = get_option( 'date_format' );
927 $field_time_format = get_option( 'time_format' );
928
929 /** Get field id with post or get */
930 $field_id = isset( $_REQUEST['prflxtrflds_field_id'] ) && '' !== $_REQUEST['prflxtrflds_field_id'] ? absint( $_REQUEST['prflxtrflds_field_id'] ) : null;
931
932 /** If field id is NULL - create new entry */
933 if ( is_null( $field_id ) ) {
934 $field_id = $wpdb->get_var( 'SELECT MAX(`field_id`) FROM `' . $wpdb->base_prefix . 'prflxtrflds_fields_id`' );
935 if ( ! $field_id ) {
936 /** If table is empty */
937 $field_id = 1;
938 } else {
939 /** Generate new id */
940 $field_id++;
941 }
942 }
943
944 /** If is save settings page, call save field function */
945 if ( isset( $_POST['prflxtrflds_save_field'] ) && check_admin_referer( 'prflxtrflds_nonce_name' ) ) {
946 $field_name = isset( $_POST['prflxtrflds_field_name'] ) ? sanitize_text_field( wp_unslash( $_POST['prflxtrflds_field_name'] ) ) : '';
947 $field_type_id = isset( $_POST['prflxtrflds_type'] ) ? absint( $_POST['prflxtrflds_type'] ) : 1;
948 $error = 12 === $field_type_id ? __( 'Unable to create field of this type.', 'profile-extra-fields' ) : '';
949 $description = isset( $_POST['prflxtrflds_description'] ) ? sanitize_text_field( wp_unslash( $_POST['prflxtrflds_description'] ) ) : '';
950 $checked_roles_data = isset( $_POST['prflxtrflds_roles'] ) ? array_filter( array_map( 'absint', (array) $_POST['prflxtrflds_roles'] ) ) : array(); /** Is array */
951 $checked_editables = isset( $_POST['prflxtrflds_editable'] ) ? array_filter( array_map( 'absint', (array) $_POST['prflxtrflds_editable'] ) ) : array(); /** Is array */
952 $checked_visibilities = isset( $_POST['prflxtrflds_visibility'] ) ? array_filter( array_map( 'absint', (array) $_POST['prflxtrflds_visibility'] ) ) : array(); /** Is array */
953 $checked_roles = array();
954
955 foreach ( $checked_roles_data as $role_id ) {
956 $editable = in_array( $role_id, $checked_editables ) ? 1 : 0;
957 $visible = in_array( $role_id, $checked_visibilities ) ? 1 : 0;
958 $checked_roles[ $role_id ] = array(
959 'editable' => $editable,
960 'visible' => $visible,
961 );
962 }
963
964 $field_maxlength = isset( $_POST['prflxtrflds_maxlength'] ) && is_numeric( $_POST['prflxtrflds_maxlength'] ) ? absint( $_POST['prflxtrflds_maxlength'] ) : 255;
965
966 $field_rows = isset( $_POST['prflxtrflds_rows'] ) && is_numeric( $_POST['prflxtrflds_rows'] ) ? absint( $_POST['prflxtrflds_rows'] ) : 2;
967 $field_cols = isset( $_POST['prflxtrflds_cols'] ) && is_numeric( $_POST['prflxtrflds_cols'] ) ? absint( $_POST['prflxtrflds_cols'] ) : 50;
968
969 $field_pattern = isset( $_POST['prflxtrflds_pattern'] ) ? preg_replace( '/[^\*\-\(\)\+]/', '', sanitize_text_field( wp_unslash( $_POST['prflxtrflds_pattern'] ) ) ) : '***-**-**';
970
971 if ( isset( $_POST['prflxtrflds_time_format'] ) ) {
972 $field_time_format = ( 'custom' === sanitize_text_field( wp_unslash( $_POST['prflxtrflds_time_format'] ) ) && isset( $_POST['prflxtrflds_time_format_custom'] ) ) ? sanitize_text_field( wp_unslash( $_POST['prflxtrflds_time_format_custom'] ) ) : sanitize_text_field( wp_unslash( $_POST['prflxtrflds_time_format'] ) );
973 }
974 if ( isset( $_POST['prflxtrflds_date_format'] ) ) {
975 $field_date_format = ( 'custom' === sanitize_text_field( wp_unslash( $_POST['prflxtrflds_date_format'] ) ) && isset( $_POST['prflxtrflds_date_format_custom'] ) ) ? sanitize_text_field( wp_unslash( $_POST['prflxtrflds_date_format_custom'] ) ) : sanitize_text_field( wp_unslash( $_POST['prflxtrflds_date_format'] ) );
976 }
977
978 $field_order = isset( $_POST['prflxtrflds_order'] ) && is_numeric( $_POST['prflxtrflds_order'] ) ? absint( $_POST['prflxtrflds_order'] ) : 0;
979
980 $field_required = isset( $_POST['prflxtrflds_required'], $_POST['prflxtrflds_required_symbol'] ) ? sanitize_text_field( wp_unslash( $_POST['prflxtrflds_required_symbol'] ) ) : '';
981 $field_show_default = isset( $_POST['prflxtrflds_show_default'] ) ? 1 : 0;
982 $field_show_always = isset( $_POST['prflxtrflds_show_always'] ) ? 1 : 0;
983 $show_in = isset( $_POST['prflxtrflds_show_in'] ) ? $_POST['prflxtrflds_show_in'] : array();
984
985 if ( isset( $_POST['prflxtrflds-value-delete'] ) ) {
986 $field_value_to_delete = array_map( 'intval', $_POST['prflxtrflds-value-delete'] );
987 }
988
989 $i = 1;
990 if ( isset( $_POST['prflxtrflds_available_values'] ) && is_array( $_POST['prflxtrflds_available_values'] ) ) {
991 $nonsort_available_values = array_map( 'sanitize_text_field', array_map( 'wp_unslash', $_POST['prflxtrflds_available_values'] ) );
992 $value_ids = isset( $_POST['prflxtrflds_value_id'] ) ? array_map( 'absint', $_POST['prflxtrflds_value_id'] ) : array();
993 /** Is array */
994 foreach ( $nonsort_available_values as $key => $value ) {
995 if ( '' !== $value ) {
996 $available_values[] = array(
997 'value_name' => $value,
998 'value_id' => ( isset( $value_ids[ $key ] ) ) ? $value_ids[ $key ] : '',
999 'value_order' => $i,
1000 );
1001 $i++;
1002 } elseif ( ! empty( $value_ids[ $key ] ) ) {
1003 /** If field empty - delete entry */
1004 $field_value_to_delete[] = $value_ids[ $key ];
1005 }
1006 }
1007 }
1008
1009 /** Delete fields if necessary */
1010 if ( ! empty( $field_value_to_delete ) && is_array( $field_value_to_delete ) ) {
1011 foreach ( $field_value_to_delete as $deleting_value_id ) {
1012 if ( '' !== $deleting_value_id ) {
1013 /** Remove field */
1014 $wpdb->delete(
1015 $wpdb->base_prefix . 'prflxtrflds_field_values',
1016 array(
1017 'value_id' => intval( $deleting_value_id ),
1018 )
1019 );
1020 /** Remove user data */
1021 $wpdb->delete(
1022 $wpdb->base_prefix . 'prflxtrflds_user_field_data',
1023 array(
1024 'field_id' => $field_id,
1025 'user_value' => intval( $deleting_value_id ),
1026 )
1027 );
1028 }
1029 }
1030 }
1031 /** Name of page if error */
1032 $name_of_page = __( 'Edit Field', 'profile-extra-fields' );
1033
1034 if ( empty( $_POST['prflxtrflds_field_name'] ) ) {
1035 $error .= __( 'Field name is empty.', 'profile-extra-fields' );
1036 }
1037
1038 /** If roles not selected */
1039 if ( empty( $_POST['prflxtrflds_roles'] ) || 1 === count( $_POST['prflxtrflds_roles'] ) ) {
1040 $error .= __( 'Select at least one user role.', 'profile-extra-fields' );
1041 }
1042
1043 if ( 10 === $field_type_id ) {
1044 if ( empty( $_POST['prflxtrflds_pattern'] ) ) {
1045 $error .= sprintf( __( 'Please specify a mask which will be used for the phone validation, where * is a number. Use only the following symbols %1$s', 'profile-extra-fields' ), '* - ( ) +' );
1046 }
1047 } elseif ( in_array( $field_type_id, array( '3', '4', '5' ) ) &&
1048 ! empty( $_POST['prflxtrflds_available_values'] )
1049 ) {
1050 /** If not choisen values */
1051 if ( is_array( $_POST['prflxtrflds_available_values'] ) ) {
1052 $_POST['prflxtrflds_available_values'] = array_map( 'sanitize_text_field', array_map( 'wp_unslash', (array) $_POST['prflxtrflds_available_values'] ) );
1053 $filled = 0;
1054 foreach ( $_POST['prflxtrflds_available_values'] as $one_value ) {
1055 if ( ! empty( $one_value ) ) {
1056 $filled++;
1057 }
1058 }
1059 /** If all values is empty */
1060 if ( 0 === $filled ) {
1061 $error .= __( 'Select at least one available value.', 'profile-extra-fields' );
1062 } elseif ( 2 > $filled && ( 4 === $field_type_id || 5 === $field_type_id ) ) {
1063 /** If is radiobutton or select, select more if two available values */
1064 $error .= __( 'Select at least two available values.', 'profile-extra-fields' );
1065 }
1066 } else {
1067 $error .= __( 'Select at least one available value.', 'profile-extra-fields' );
1068 }
1069 }
1070 /** End check error */
1071 if ( empty( $error ) ) {
1072 /** Check for exist field id */
1073 if ( 1 === $wpdb->query( $wpdb->prepare( 'SELECT `field_id` FROM ' . $wpdb->base_prefix . 'prflxtrflds_fields_id WHERE `field_id`=%d', $field_id ) ) ) {
1074 $message = __( 'The field has been updated.', 'profile-extra-fields' );
1075 } else {
1076 $message = __( 'The field has been created.', 'profile-extra-fields' );
1077 }
1078
1079 /** Update data */
1080 $wpdb->replace(
1081 $wpdb->base_prefix . 'prflxtrflds_fields_id',
1082 array(
1083 'field_id' => esc_sql( $field_id ),
1084 'field_name' => esc_sql( $field_name ),
1085 'required' => esc_sql( $field_required ),
1086 'description' => esc_sql( $description ),
1087 'show_default' => esc_sql( $field_show_default ),
1088 'show_always' => esc_sql( $field_show_always ),
1089 'field_type_id' => esc_sql( $field_type_id ),
1090 )
1091 );
1092
1093 foreach ( $show_in as $show => $value ) {
1094 if ( '0' !== $value ) {
1095 $result = $wpdb->replace(
1096 $wpdb->base_prefix . 'prflxtrflds_fields_meta',
1097 array(
1098 'field_id' => $field_id,
1099 'show_in' => esc_sql( sanitize_text_field( wp_unslash( $show ) ) ),
1100 'value' => esc_sql( maybe_serialize( $value ) ),
1101 )
1102 );
1103 } else {
1104 $wpdb->delete(
1105 $wpdb->base_prefix . 'prflxtrflds_fields_meta',
1106 array(
1107 'field_id' => $field_id,
1108 'show_in' => esc_sql( sanitize_text_field( wp_unslash( $show ) ) ),
1109 )
1110 );
1111 }
1112 }
1113
1114 /** Get all available roles id */
1115 $all_roles_in_db = $wpdb->get_col( $wpdb->prepare( 'SELECT `role_id` FROM `' . $wpdb->base_prefix . 'prflxtrflds_roles_and_fields` WHERE `field_id` = %d', $field_id ) );
1116 if ( ! empty( $all_roles_in_db ) ) {
1117 foreach ( $all_roles_in_db as $role_id ) {
1118 if ( ! array_key_exists( $role_id, $checked_roles ) ) {
1119 /** Delete unchecked role */
1120 $wpdb->delete(
1121 $wpdb->base_prefix . 'prflxtrflds_roles_and_fields',
1122 array(
1123 'field_id' => $field_id,
1124 'role_id' => $role_id,
1125 )
1126 );
1127 }
1128 }
1129 }
1130 /** Update data */
1131 if ( ! empty( $checked_roles ) ) {
1132 /** If field order change, apply it for all roles */
1133 $default_order = $wpdb->get_var( $wpdb->prepare( 'SELECT `field_order` FROM `' . $wpdb->base_prefix . 'prflxtrflds_roles_and_fields` WHERE `field_id`= %d AND `role_id`=0', $field_id ) );
1134 if ( $field_order !== $default_order ) {
1135 foreach ( $checked_roles as $role_id => $role_value ) {
1136 $wpdb->replace(
1137 $wpdb->base_prefix . 'prflxtrflds_roles_and_fields',
1138 array(
1139 'field_id' => esc_sql( $field_id ),
1140 'role_id' => esc_sql( $role_id ),
1141 'field_order' => esc_sql( $field_order ),
1142 'editable' => esc_sql( $role_value['editable'] ),
1143 'visible' => esc_sql( $role_value['visible'] ),
1144 ),
1145 array( '%d', '%d', '%d', '%d', '%d' )
1146 );
1147 }
1148 } else {
1149 /** If field order not change, not apply it. Hold old data */
1150 foreach ( $checked_roles as $role_id => $role_value ) {
1151 $old_order = $wpdb->get_var( $wpdb->prepare( 'SELECT `field_order` FROM `' . $wpdb->base_prefix . 'prflxtrflds_roles_and_fields` WHERE `field_id`=%d AND `role_id`=%s', $field_id, $role_id ) );
1152 /** If old order not exists, set default order */
1153 if ( ( ! isset( $old_order ) ) && ( isset( $field_order ) ) ) {
1154 /** For new roles */
1155 $old_order = $field_order;
1156 } elseif ( ( ! isset( $old_order ) ) && ( ! isset( $field_order ) ) ) {
1157 /** Default order if not exist */
1158 $old_order = 0;
1159 }
1160
1161 $wpdb->replace(
1162 $wpdb->base_prefix . 'prflxtrflds_roles_and_fields',
1163 array(
1164 'field_id' => esc_sql( $field_id ),
1165 'role_id' => esc_sql( $role_id ),
1166 'field_order' => esc_sql( $old_order ),
1167 'editable' => esc_sql( $role_value['editable'] ),
1168 'visible' => esc_sql( $role_value['visible'] ),
1169 ),
1170 array( '%d', '%d', '%d', '%d', '%d' )
1171 );
1172 }
1173 }
1174 } else {
1175 /** If no available roles, create entry with role_id = 0 */
1176 $wpdb->replace(
1177 $wpdb->base_prefix . 'prflxtrflds_roles_and_fields',
1178 array(
1179 'field_id' => $field_id,
1180 'role_id' => 0,
1181 'field_order' => esc_sql( $field_order ),
1182 ),
1183 array( '%d', '%d', '%d' )
1184 );
1185 }
1186 /** Prflxtrflds_field_values update */
1187 if ( 1 === $field_type_id ||
1188 2 === $field_type_id ||
1189 6 === $field_type_id ||
1190 7 === $field_type_id ||
1191 8 === $field_type_id ||
1192 9 === $field_type_id ||
1193 10 === $field_type_id ||
1194 11 === $field_type_id ||
1195 13 === $field_type_id
1196 ) {
1197 switch ( $field_type_id ) {
1198 case '1':
1199 $value_name = $field_maxlength;
1200 break;
1201 case '2':
1202 $value_name = serialize(
1203 array(
1204 'rows' => $field_rows,
1205 'cols' => $field_cols,
1206 'max_length' => $field_maxlength,
1207 )
1208 );
1209 break;
1210 case '9':
1211 $value_name = $field_maxlength;
1212 break;
1213 case '10':
1214 $value_name = $field_pattern;
1215 break;
1216 case '11':
1217 $value_name = $field_maxlength;
1218 break;
1219 case '13':
1220 $value_name = $field_pattern;
1221 break;
1222 case '6':
1223 $value_name = $field_date_format;
1224 break;
1225 case '7':
1226 $value_name = $field_time_format;
1227 break;
1228 case '8':
1229 $value_name = serialize(
1230 array(
1231 'date' => $field_date_format,
1232 'time' => $field_time_format,
1233 )
1234 );
1235 break;
1236 }
1237 /** If entry with current id not exist, create new entry */
1238 if ( $wpdb->get_var( $wpdb->prepare( 'SELECT `field_id` FROM `' . $wpdb->base_prefix . 'prflxtrflds_field_values` WHERE `field_id`= %d', $field_id ) ) ) {
1239 if ( '' !== $value_name ) {
1240 $wpdb->update(
1241 $wpdb->base_prefix . 'prflxtrflds_field_values',
1242 array( 'value_name' => $value_name ),
1243 array( 'field_id' => $field_id )
1244 );
1245 } else {
1246 $wpdb->delete(
1247 $wpdb->base_prefix . 'prflxtrflds_field_values',
1248 array(
1249 'field_id' => $field_id,
1250 )
1251 );
1252 }
1253 } elseif ( '' !== $value_name ) {
1254 $wpdb->insert(
1255 $wpdb->base_prefix . 'prflxtrflds_field_values',
1256 array(
1257 'value_name' => esc_sql( $value_name ),
1258 'field_id' => esc_sql( $field_id ),
1259 )
1260 );
1261 }
1262 } elseif ( ! empty( $available_values ) ) {
1263 foreach ( $available_values as $i => $value ) {
1264 /** If entry with current id exists, update it */
1265 if ( ! empty( $value['value_id'] ) ) {
1266 /** Update entry if not empty field (rename entry) */
1267 $wpdb->update(
1268 $wpdb->base_prefix . 'prflxtrflds_field_values',
1269 array(
1270 'value_name' => $value['value_name'],
1271 'order' => $value['value_order'],
1272 ),
1273 array( 'value_id' => $value['value_id'] )
1274 );
1275 } else {
1276 /** If entry with current id not exist, create new entry */
1277 $wpdb->insert(
1278 $wpdb->base_prefix . 'prflxtrflds_field_values',
1279 array(
1280 'value_name' => esc_sql( $value['value_name'] ),
1281 'field_id' => esc_sql( $field_id ),
1282 'order' => esc_sql( $value['value_order'] ),
1283 )
1284 );
1285 $result_id = $wpdb->insert_id;
1286 $available_values[ $i ]['value_id'] = $result_id;
1287 }
1288 }
1289 }
1290 }
1291 }
1292
1293 if ( ! is_null( $field_id ) ) {
1294 /** Name of page if field exist */
1295 $name_of_page = __( 'Edit Field', 'profile-extra-fields' );
1296 /** If get $field_id - edit field */
1297 $field_options = $wpdb->get_row(
1298 $wpdb->prepare(
1299 'SELECT *
1300 FROM `' . $wpdb->base_prefix . 'prflxtrflds_fields_id`
1301 WHERE `field_id` = %d',
1302 $field_id
1303 ),
1304 ARRAY_A
1305 );
1306 $show_in_results = $wpdb->get_results(
1307 $wpdb->prepare(
1308 'SELECT `show_in`, `value`
1309 FROM `' . $wpdb->base_prefix . 'prflxtrflds_fields_meta`
1310 WHERE `field_id` = %d',
1311 $field_id
1312 ),
1313 ARRAY_A
1314 );
1315
1316 if ( ! empty( $show_in_results ) ) {
1317 foreach ( $show_in_results as $show ) {
1318 $show_in[ $show['show_in'] ] = maybe_unserialize( $show['value'] );
1319 }
1320 }
1321 if ( ! $field_options ) {
1322 /** If entry not exist - create new entry */
1323 $field_id = null;
1324 } else {
1325 $field_name = $field_options['field_name'];
1326 $field_required = $field_options['required'];
1327 $description = $field_options['description'];
1328 $field_show_default = $field_options['show_default'];
1329 $field_show_always = $field_options['show_always'];
1330 $field_type_id = $field_options['field_type_id'];
1331 /** Get avaliable roles */
1332 $checked_roles_data = $wpdb->get_results( $wpdb->prepare( 'SELECT `role_id`, `editable`, `visible` FROM `' . $wpdb->base_prefix . 'prflxtrflds_roles_and_fields` WHERE `field_id`=%d', $field_id ), ARRAY_A );
1333 foreach ( $checked_roles_data as $value ) {
1334 $checked_roles[ $value['role_id'] ] = array(
1335 'editable' => $value['editable'],
1336 'visible' => $value['visible'],
1337 );
1338 }
1339
1340 $field_order = $wpdb->get_var( $wpdb->prepare( 'SELECT `field_order` FROM `' . $wpdb->base_prefix . 'prflxtrflds_roles_and_fields` WHERE `field_id`=%d LIMIT 1', $field_id ) );
1341 /** Get available values to checkbox, radiobutton, select, etc */
1342 if ( '10' === $field_type_id ) {
1343 $field_pattern = $wpdb->get_var( $wpdb->prepare( 'SELECT `value_name` FROM `' . $wpdb->base_prefix . 'prflxtrflds_field_values` WHERE `field_id`=%d', $field_id ) );
1344 } elseif ( '6' === $field_type_id ) {
1345 $field_date_format = $wpdb->get_var( $wpdb->prepare( 'SELECT `value_name` FROM `' . $wpdb->base_prefix . 'prflxtrflds_field_values` WHERE `field_id`=%d', $field_id ) );
1346 } elseif ( '7' === $field_type_id ) {
1347 $field_time_format = $wpdb->get_var( $wpdb->prepare( 'SELECT `value_name` FROM `' . $wpdb->base_prefix . 'prflxtrflds_field_values` WHERE `field_id`=%d', $field_id ) );
1348 } elseif ( '8' === $field_type_id ) {
1349 $date_and_time = unserialize( $wpdb->get_var( $wpdb->prepare( 'SELECT `value_name` FROM `' . $wpdb->base_prefix . 'prflxtrflds_field_values` WHERE `field_id`=%d', $field_id ) ) );
1350 if ( isset( $date_and_time['date'] ) ) {
1351 $field_date_format = $date_and_time['date'];
1352 }
1353 if ( isset( $date_and_time['time'] ) ) {
1354 $field_time_format = $date_and_time['time'];
1355 }
1356 } elseif ( '1' === $field_type_id || '9' === $field_type_id ) {
1357 $field_maxlength = $wpdb->get_var( $wpdb->prepare( 'SELECT `value_name` FROM `' . $wpdb->base_prefix . 'prflxtrflds_field_values` WHERE `field_id`=%d', $field_id ) );
1358 } elseif ( '2' === $field_type_id ) {
1359 $unser_textarea = maybe_unserialize( $wpdb->get_var( $wpdb->prepare( 'SELECT `value_name` FROM `' . $wpdb->base_prefix . 'prflxtrflds_field_values` WHERE `field_id`=%d', $field_id ) ) );
1360 $field_rows = $unser_textarea['rows'];
1361 $field_cols = $unser_textarea['cols'];
1362 $field_maxlength = $unser_textarea['max_length'];
1363 } else {
1364 $available_values = $wpdb->get_results( $wpdb->prepare( 'SELECT `value_id`, `value_name`, `order` FROM `' . $wpdb->base_prefix . 'prflxtrflds_field_values` WHERE `field_id`=%d ORDER BY `order`', $field_id ), ARRAY_A );
1365 }
1366 }
1367 } else {
1368 $name_of_page = __( 'Add New Field', 'profile-extra-fields' );
1369 }
1370
1371 prflxtrflds_settings();
1372
1373 $bws_hide_premium_options_check = bws_hide_premium_options_check( $prflxtrflds_options );
1374 /** Update roles id */
1375 prflxtrflds_update_roles_id();
1376 /** Get all avaliable roles */
1377 $all_roles = $wpdb->get_results( 'SELECT * FROM `' . $wpdb->base_prefix . 'prflxtrflds_roles_id`' ); ?>
1378 <div class="wrap">
1379 <?php $tab_action_true = ( isset( $_GET['tab-action'] ) ) ? '&tab-action=' . sanitize_text_field( wp_unslash( $_GET['tab-action'] ) ) : ''; ?>
1380 <h1 class="wp-heading-inline"><?php echo esc_html( $name_of_page ); ?></h1>
1381 <?php if ( ! empty( $error ) ) { ?>
1382 <div class="error below-h2"><p><strong><?php echo esc_html( $error ); ?></strong></p></div>
1383 <?php } elseif ( ! empty( $message ) ) { ?>
1384 <div class="updated fade below-h2"><p><?php echo esc_html( $message ); ?></p></div>
1385 <?php
1386 }
1387 if ( empty( $field_id ) ) {
1388 $action = admin_url( 'admin.php?page=profile-extra-field-add-new.php&edit=1' );
1389 } else {
1390 $action = admin_url( sprintf( 'admin.php?page=profile-extra-field-add-new.php&edit=1&prflxtrflds_field_id=%d', $field_id ) );
1391 }
1392 $action_url = $action . $tab_action_true;
1393 ?>
1394 <form class="bws_form" method="post" action="<?php echo esc_url( $action_url ); ?>">
1395 <table class="form-table">
1396 <tbody>
1397 <tr>
1398 <th><?php esc_html_e( 'Name', 'profile-extra-fields' ); ?></th>
1399 <td>
1400 <input type="text" name="prflxtrflds_field_name" value="<?php echo esc_attr( $field_name ); ?>" />
1401 </td>
1402 </tr>
1403 <tr>
1404 <th><?php esc_html_e( 'Type', 'profile-extra-fields' ); ?></th>
1405 <td>
1406 <select id="prflxtrflds-select-type" name="prflxtrflds_type">
1407 <?php foreach ( $prflxtrflds_field_type_id as $id => $field_name ) { /** Create select with field types */ ?>
1408 <option value="<?php echo esc_attr( $id ); ?>" style="<?php echo 12 === $id ? 'background-color: #dcd6b8;' : ''; ?>" <?php echo 12 === $id ? 'disabled="disabled"' : ''; ?> <?php selected( $field_type_id, $id ); ?>><?php echo esc_html( $field_name ); ?></option>
1409 <?php } ?>
1410 </select>
1411 </td>
1412 </tr>
1413 <tr class="prflxtrflds-maxlength">
1414 <th><?php esc_html_e( 'Max Length', 'profile-extra-fields' ); ?></th>
1415 <td>
1416 <input type="number" min="1" name="prflxtrflds_maxlength" value="<?php echo ! empty( $field_maxlength ) ? intval( $field_maxlength ) : 255; ?>" />
1417 <div class="bws_info"><?php esc_html_e( 'Specify field max length (for text field and textarea type) or max number (for number field type).', 'profile-extra-fields' ); ?></div>
1418 </td>
1419 </tr>
1420 <tr class="prflxtrflds-cols">
1421 <th><?php esc_html_e( 'Field width in characters', 'profile-extra-fields' ); ?></th>
1422 <td>
1423 <input type="number" min="1" name="prflxtrflds_cols" value="<?php echo ! empty( $field_cols ) ? intval( $field_cols ) : 50; ?>" />
1424 </td>
1425 </tr>
1426 <tr class="prflxtrflds-rows">
1427 <th><?php esc_html_e( 'The height of the field in the text lines', 'profile-extra-fields' ); ?></th>
1428 <td>
1429 <input type="number" min="1" name="prflxtrflds_rows" value="<?php echo ! empty( $field_rows ) ? intval( $field_rows ) : 2; ?>" />
1430 </td>
1431 </tr>
1432 <tr class="prflxtrflds-date-format">
1433 <th scope="row"><?php esc_html_e( 'Date Format', 'profile-extra-fields' ); ?></th>
1434 <td>
1435 <fieldset>
1436 <legend class="screen-reader-text"><span><?php esc_html_e( 'Date Format', 'profile-extra-fields' ); ?></span></legend>
1437 <?php
1438 $date_formats = array_unique( apply_filters( 'date_formats', array( 'F j, Y', 'Y-m-d', 'm/d/Y', 'd/m/Y' ) ) );
1439 $custom = true;
1440 foreach ( $date_formats as $format ) {
1441 echo "\t<label title='" . esc_attr( $format ) . "'><input type='radio' name='prflxtrflds_date_format' value='" . esc_attr( $format ) . "'";
1442 if ( $field_date_format === $format ) {
1443 echo " checked='checked'";
1444 $custom = false;
1445 }
1446 echo ' /> ' . esc_html( date_i18n( $format ) ) . "</label><br />\n";
1447 }
1448 echo ' <label><input type="radio" name="prflxtrflds_date_format" id="prflxtrflds_date_format_custom_radio" value="custom"';
1449 checked( $custom );
1450 echo '/> ' . esc_html__( 'Custom:', 'profile-extra-fields' ) . '<span class="screen-reader-text"> ' . esc_html__( 'enter a custom date format in the following field', 'profile-extra-fields' ) . "</span></label>\n";
1451 echo '<label for="prflxtrflds_date_format_custom" class="screen-reader-text">' . esc_html__( 'Custom date format:', 'profile-extra-fields' ) . '</label><input type="text" name="prflxtrflds_date_format_custom" id="prflxtrflds_date_format_custom" value="' . esc_attr( $field_date_format ) . '" class="small-text" />
1452 <span class="screen-reader-text">' . esc_html__( 'example:', 'profile-extra-fields' ) . ' </span><span class="example"> ' . esc_html( date_i18n( $field_date_format ) ) . "</span> <span class='spinner'></span>\n";
1453 ?>
1454 <p><a target="_blank" href="https://codex.wordpress.org/Formatting_Date_and_Time"><?php esc_html_e( 'Documentation on date and time formatting.', 'profile-extra-fields' ); ?></a></p>
1455 </fieldset>
1456 </td>
1457 </tr>
1458 <tr class="prflxtrflds-time-format">
1459 <th scope="row"><?php esc_html_e( 'Time Format', 'profile-extra-fields' ); ?></th>
1460 <td>
1461 <fieldset>
1462 <legend class="screen-reader-text"><span><?php esc_html_e( 'Time Format', 'profile-extra-fields' ); ?></span></legend>
1463 <?php
1464 $time_formats = array_unique( apply_filters( 'time_formats', array( 'g:i a', 'g:i A', 'H:i' ) ) );
1465 $custom = true;
1466 foreach ( $time_formats as $format ) {
1467 echo "\t<label title='" . esc_attr( $format ) . "'><input type='radio' name='prflxtrflds_time_format' value='" . esc_attr( $format ) . "'";
1468 if ( $field_time_format === $format ) {
1469 echo " checked='checked'";
1470 $custom = false;
1471 }
1472 echo ' /> ' . esc_html( date_i18n( $format ) ) . "</label><br />\n";
1473 }
1474 echo ' <label><input type="radio" name="prflxtrflds_time_format" id="prflxtrflds_time_format_custom_radio" value="custom"';
1475 checked( $custom );
1476 echo '/> ' . esc_html__( 'Custom:', 'profile-extra-fields' ) . '<span class="screen-reader-text"> ' . esc_html__( 'enter a custom time format in the following field', 'profile-extra-fields' ) . "</span></label>\n";
1477 echo '<label for="prflxtrflds_time_format_custom" class="screen-reader-text">' . esc_html__( 'Custom time format:', 'profile-extra-fields' ) . '</label><input type="text" name="prflxtrflds_time_format_custom" id="prflxtrflds_time_format_custom" value="' . esc_attr( $field_time_format ) . '" class="small-text" /> <span class="screen-reader-text">' . esc_html__( 'example:', 'profile-extra-fields' ) . ' </span><span class="example"> ' . esc_html( date_i18n( $field_time_format ) ) . "</span> <span class='spinner'></span>\n";
1478 ?>
1479 <p><a target="_blank" href="https://codex.wordpress.org/Formatting_Date_and_Time"><?php esc_html_e( 'Documentation on date and time formatting.', 'profile-extra-fields' ); ?></a></p>
1480 </fieldset>
1481 </td>
1482 </tr>
1483 <tr class="prflxtrflds-pattern">
1484 <th><?php esc_html_e( 'Pattern', 'profile-extra-fields' ); ?></th>
1485 <td>
1486 <input type="text" name="prflxtrflds_pattern" value="<?php echo esc_attr( $field_pattern ); ?>" />
1487 <div class="bws_info"><?php printf( esc_html__( 'Please specify a mask which will be used for the phone validation, where * is a number. Use only the following symbols %1$s', 'profile-extra-fields' ), '* - ( ) +' ); ?></div>
1488 </td>
1489 </tr>
1490 <tr class="prflxtrflds-fields-container">
1491 <th><?php esc_html_e( 'Available Values', 'profile-extra-fields' ); ?></th>
1492 <td>
1493 <fieldset>
1494 <label><input type="radio" class="bws_option_affect" name="mode_edit_values" value="manually" data-affect-hide=".prflxtrflds-import-values" data-affect-show=".prflxtrflds-write-in-values" checked>&nbsp<?php esc_html_e( 'Edit values manually', 'profile-extra-fields' ); ?></label><br/>
1495 <div class="prflxtrflds-write-in-values">
1496 <div class="bws_info hide-if-js">
1497 <div class="prflxtrflds-value-name">
1498 <?php esc_html_e( 'Name of value', 'profile-extra-fields' ); ?>
1499 </div>
1500 <div class="prflxtrflds-delete">
1501 <?php esc_html_e( 'Delete', 'profile-extra-fields' ); ?>
1502 </div>
1503 </div><!--.prflxtrflds-values-info-->
1504 <div class="prflxtrflds-drag-values-container">
1505 <?php
1506 $count_available_values = count( $available_values );
1507 for ( $i = 0; $i < $count_available_values; $i++ ) {
1508 ?>
1509 <div class="prflxtrflds-drag-values">
1510 <input type="hidden" name="prflxtrflds_value_id[]" value="
1511 <?php
1512 if ( ! empty( $available_values[ $i ]['value_id'] ) ) {
1513 echo esc_attr( $available_values[ $i ]['value_id'] );}
1514 ?>
1515 " />
1516 <img class="prflxtrflds-drag-field hide-if-no-js prflxtrflds-hide-if-is-mobile" title="" src="<?php echo esc_url( plugins_url( 'images/dragging-arrow.png', __FILE__ ) ); ?>" alt="drag-arrow" />
1517 <input placeholder="<?php esc_html_e( 'Name of value', 'profile-extra-fields' ); ?>" class="prflxtrflds-add-options-input" type="text" name="prflxtrflds_available_values[]" value="<?php echo esc_attr( $available_values[ $i ]['value_name'] ); ?>" />
1518 <span class="prflxtrflds-value-delete"><input type="checkbox" name="prflxtrflds-value-delete[]" value="
1519 <?php
1520 if ( ! empty( $available_values[ $i ]['value_id'] ) ) {
1521 echo esc_attr( $available_values[ $i ]['value_id'] );}
1522 ?>
1523 " /><label></label></span>
1524 </div><!--.prflxtrflds-drag-values-->
1525 <?php } ?>
1526 <div class="prflxtrflds-drag-values
1527 <?php
1528 if ( ! empty( $available_values ) ) {
1529 echo 'hide-if-js';}
1530 ?>
1531 ">
1532 <input type="hidden" name="prflxtrflds_value_id[]" value="" />
1533 <img class="prflxtrflds-drag-field hide-if-no-js prflxtrflds-hide-if-is-mobile" title="" src="<?php echo esc_url( plugins_url( 'images/dragging-arrow.png', __FILE__ ) ); ?>" alt="drag-arrow" />
1534 <input placeholder="<?php esc_html_e( 'Name of value', 'profile-extra-fields' ); ?>" class="prflxtrflds-add-options-input" type="text" name="prflxtrflds_available_values[]" value="" />
1535 <span class="prflxtrflds-value-delete"><input type="checkbox" name="prflxtrflds-value-delete[]" value="" /><label></label></span>
1536 </div><!--.prflxtrflds-drag-values-->
1537 </div><!--.prflxtrflds-drag-values-container-->
1538 <div class="prflxtrflds-add-button-container">
1539 <input type="button" class="button-small button prflxtrflds-small-button hide-if-no-js" id="prflxtrflds-add-field" name="prflxtrflds-add-field" value="<?php esc_html_e( 'Add', 'profile-extra-fields' ); ?>" />
1540 <p class="hide-if-js"><?php esc_html_e( 'Click save button to add more values', 'profile-extra-fields' ); ?></p>
1541 </div>
1542 </div><br/>
1543 </fieldset>
1544 <?php if ( ! $bws_hide_premium_options_check ) { ?>
1545 <div class="bws_pro_version_bloc">
1546 <div class="bws_pro_version_table_bloc">
1547 <div class="bws_table_bg"></div>
1548 <table class="form-table bws_pro_version">
1549 <tbody>
1550 <tr>
1551 <td>
1552 <label><input type="radio" name="mode_edit_values" value="import" data-affect-hide=".prflxtrflds-write-in-values" disabled="disabled">&nbsp<?php esc_html_e( 'Import values', 'profile-extra-fields' ); ?><?php echo ( $bws_hide_premium_options_check ? 'disabled' : '' ); ?></label><br/>
1553 <div>
1554 <input type="file" name="prflxtrflds-import-file" accept=".xlsx" disabled="disabled" />
1555 <div class="bws_info"><?php esc_html_e( 'Upload XLSX file that includes the values to overwrite the standard values. Example: location1,location2,location3', 'profile-extra-fields' ); ?></div>
1556 </div>
1557 </td>
1558 </tr>
1559 </tbody>
1560 </table>
1561 </div>
1562 <div class="bws_pro_version_tooltip">
1563 <a class="bws_button" href="https://bestwebsoft.com/products/wordpress/plugins/profile-extra-fields/?k=c37eed44c2fe607f3400914345cbdca&pn=300&v=<?php echo esc_attr( $prflxtrflds_plugin_info['Version'] ); ?>&wp_v=<?php echo esc_attr( $wp_version ); ?>" target="_blank" title="Profile Extra Fields Pro"><?php esc_html_e( 'Upgrade to Pro', 'profile-extra-fields' ); ?></a>
1564 <div class="clear"></div>
1565 </div>
1566 </div>
1567 <?php } ?>
1568 </td>
1569 </tr>
1570 </tbody>
1571 </table>
1572 <?php if ( ! $bws_hide_premium_options_check ) { ?>
1573 <div class="bws_pro_version_bloc prflxtrflds-selected-extensions">
1574 <div class="bws_pro_version_table_bloc">
1575 <div class="bws_table_bg"></div>
1576 <table class="form-table bws_pro_version">
1577 <tbody>
1578 <tr class="prflxtrflds-selected-extensions">
1579 <th><?php esc_html_e( 'Available Extensions', 'profile-extra-fields' ); ?></th>
1580 <td>
1581 <select class="select" id="prflxtrflds_available_extensions" disabled="disabled" multiple>
1582 <?php
1583 $all_available_extensions = array( '.jpg', '.jpeg', '.png', '.gif', '.ico', '.pdf', '.doc', '.docx', '.ppt', '.pptx', '.pps', '.ppsx', '.odt', '.xls', '.xlsx', '.psd', '.mp3', '.m4a', '.ogg', '.wav', '.mp4', '.m4v', '.mov', '.wmv', '.avi', '.mpg', '.ogv', '.3gp', '.3g2' );
1584 foreach ( $all_available_extensions as $value ) {
1585 echo '<option value="' . esc_attr( $value ) . '">' . esc_attr( $value ) . '</option>';
1586 }
1587 ?>
1588 </select>
1589 </td>
1590 </tr>
1591 </tbody>
1592 </table>
1593 </div>
1594 <div class="bws_pro_version_tooltip">
1595 <a class="bws_button" href="https://bestwebsoft.com/products/wordpress/plugins/profile-extra-fields/?k=c37eed44c2fe607f3400914345cbdc8a&pn=300&v=<?php echo esc_attr( $prflxtrflds_plugin_info['Version'] ); ?>&wp_v=<?php echo esc_attr( $wp_version ); ?>" target="_blank" title="Profile Extra Fields Pro"><?php esc_html_e( 'Upgrade to Pro', 'profile-extra-fields' ); ?></a>
1596 <div class="clear"></div>
1597 </div>
1598 </div>
1599 <?php } ?>
1600 <table class="form-table prflxtrflds-fields-edit-table">
1601 <tbody>
1602 <tr>
1603 <th><?php esc_html_e( 'Description', 'profile-extra-fields' ); ?></th>
1604 <td>
1605 <textarea class="prflxtrflds-description" name="prflxtrflds_description"><?php echo esc_textarea( $description ); ?></textarea>
1606 </td>
1607 </tr>
1608 <tr>
1609 <th class="prflxtrflds-hide-on-mobile"><?php esc_html_e( 'Field Properties', 'profile-extra-fields' ); ?></th>
1610 <td>
1611 <table>
1612 <tr id="prflxtrflds-caption-checkboxes">
1613 <th class="prflxtrflds-hide-on-mobile"><?php esc_html_e( 'Available', 'profile-extra-fields' ); ?></th>
1614 <th class="prflxtrflds-hide-on-mobile"><?php esc_html_e( 'Editable', 'profile-extra-fields' ); ?></th>
1615 <th class="prflxtrflds-hide-on-mobile"><?php esc_html_e( 'Visible', 'profile-extra-fields' ); ?></th>
1616 </tr>
1617 <tr id="prflxtrflds-select-checkboxes">
1618 <th class="prflxtrflds-labels-for-mobiles"><?php esc_html_e( 'Available', 'profile-extra-fields' ); ?></th>
1619 <td class="prflxtrflds-checkboxes-for-roles">
1620 <div id="prflxtrflds-select-roles">
1621 <div class="prflxtrflds-div-select-all">
1622 <input class="prflxtrflds-checkboxes-select-all-in-roles prflxtrflds-checkboxes-available" type="checkbox" id="prflxtrflds-select-all"/>
1623 <span class="prflxtrflds-labels-for-mobiles"><b><?php esc_html_e( 'Select all', 'profile-extra-fields' ); ?></b></span>
1624 </div>
1625 <?php
1626 $args = array();
1627 foreach ( $all_roles as $role ) {
1628 $args[ $role->role_id ] = isset( $checked_roles ) ? array_key_exists( $role->role_id, $checked_roles ) : false;
1629 ?>
1630 <input type="checkbox" class="prflxtrflds-checkboxes-in-roles prflxtrflds-checkboxes-available" name="prflxtrflds_roles[]" value="<?php echo esc_attr( $role->role_id ); ?>"
1631 <?php
1632 if ( isset( $checked_roles ) ) {
1633 checked( array_key_exists( $role->role_id, $checked_roles ), true );
1634 }
1635 ?>
1636 data-prflxtrflds-role-id="<?php echo esc_attr( $role->role_id ); ?>"/>
1637 <span class="prflxtrflds-labels-for-mobiles"><?php echo esc_attr( translate_user_role( $role->role_name ) ); ?></span>
1638 <br />
1639 <?php } ?>
1640 </div>
1641 </td>
1642 <th class="prflxtrflds-labels-for-mobiles"><?php esc_html_e( 'Editable', 'profile-extra-fields' ); ?></th>
1643 <td class="prflxtrflds-checkboxes-for-roles">
1644 <div id="prflxtrflds-select-roles-editable">
1645 <div class="prflxtrflds-div-select-all-editable">
1646 <?php
1647 foreach ( $all_roles as $role ) {
1648 $attr = $args[ $role->role_id ] ? ( isset( $checked_roles[ $role->role_id ] ) ? '' : 'disabled="disabled"' ) : 'disabled="disabled"';
1649 }
1650 ?>
1651 <input class="prflxtrflds-checkboxes-select-all-in-roles prflxtrflds-checkboxes-editable" type="checkbox" name="prflxtrflds-select-all-editable" id="prflxtrflds-select-all-editable" data-prflxtrflds-role-id="all" <?php echo wp_kses_data( $attr ); ?> />
1652 <span class="prflxtrflds-labels-for-mobiles"><b><?php esc_html_e( 'Select all', 'profile-extra-fields' ); ?></b></span>
1653 </div>
1654 <?php
1655 foreach ( $all_roles as $role ) {
1656 $attr = $args[ $role->role_id ] ? ( isset( $checked_roles[ $role->role_id ] ) ? checked( $checked_roles[ $role->role_id ]['editable'], 1, false ) : '' ) : 'disabled="disabled"';
1657 ?>
1658 <input class="prflxtrflds-checkboxes-in-roles prflxtrflds-checkboxes-editable" type="checkbox" name="prflxtrflds_editable[]" value="<?php echo esc_attr( $role->role_id ); ?>" <?php echo wp_kses_data( $attr ); ?> data-prflxtrflds-role-id="<?php echo esc_attr( $role->role_id ); ?>"/>
1659 <span class="prflxtrflds-labels-for-mobiles"><?php echo esc_attr( translate_user_role( $role->role_name ) ); ?></span>
1660 <br />
1661 <?php } ?>
1662 </div>
1663 </td>
1664 <th class="prflxtrflds-labels-for-mobiles"><?php esc_html_e( 'Visible', 'profile-extra-fields' ); ?></th>
1665 <td class="prflxtrflds-checkboxes-for-roles">
1666 <div id="prflxtrflds-select-roles-visibility">
1667 <div class="prflxtrflds-div-select-all-visibility">
1668 <?php
1669 foreach ( $all_roles as $role ) {
1670 $attr = ( $args[ $role->role_id ] ) ? ( isset( $checked_roles[ $role->role_id ] ) ? '' : 'disabled="disabled"' ) : 'disabled="disabled"';
1671 }
1672 ?>
1673 <input class="prflxtrflds-checkboxes-select-all-in-roles prflxtrflds-checkboxes-visible" type="checkbox" name="prflxtrflds-select-all-visibility" id="prflxtrflds-select-all-visibility" data-prflxtrflds-role-id="all" <?php echo wp_kses_data( $attr ); ?> />
1674 <span class="prflxtrflds-labels-for-mobiles"><b><?php esc_html_e( 'Select all', 'profile-extra-fields' ); ?></b></span>
1675 </div>
1676 <?php
1677 foreach ( $all_roles as $role ) {
1678 $attr = $args[ $role->role_id ] ? ( isset( $checked_roles[ $role->role_id ] ) ? checked( $checked_roles[ $role->role_id ]['visible'], 1, false ) : '' ) : 'disabled="disabled"';
1679 ?>
1680 <input class="prflxtrflds-checkboxes-in-roles prflxtrflds-checkboxes-visible" type="checkbox" name="prflxtrflds_visibility[]" value="<?php echo esc_attr( $role->role_id ); ?>"<?php echo wp_kses_data( $attr ); ?> data-prflxtrflds-role-id="<?php echo esc_attr( $role->role_id ); ?>" />
1681 <span class="prflxtrflds-labels-for-mobiles"><?php echo esc_attr( translate_user_role( $role->role_name ) ); ?></span>
1682 <br />
1683 <?php } ?>
1684 </div>
1685 </td>
1686 <td class="prflxtrflds-checkboxes-for-roles prflxtrflds-hide-on-mobile">
1687 <fieldset id="prflxtrflds-select-roles"><!--#prflxtrflds-select-roles-->
1688 <?php if ( $all_roles ) { ?>
1689 <div id="prflxtrflds-div-select-all">
1690 <label for="prflxtrflds-select-all"><b><?php esc_html_e( 'Select all', 'profile-extra-fields' ); ?></b></label>
1691 </div><!--#prflxtrflds-div-select-all-->
1692 <input type="hidden" name="prflxtrflds_roles[]" id="0" value="0" />
1693 <?php foreach ( $all_roles as $role ) { ?>
1694 <label for="<?php echo esc_attr( $role->role_id ); ?>"><?php echo esc_attr( translate_user_role( $role->role_name ) ); ?></label>
1695 <br />
1696 <?php
1697 }
1698 }
1699 ?>
1700 </fieldset><!--#prflxtrflds-select-roles-->
1701 </td>
1702 </tr>
1703 </table>
1704 </td>
1705 </tr>
1706 <tr>
1707 <th><?php esc_html_e( 'Required', 'profile-extra-fields' ); ?></th>
1708 <td>
1709 <label>
1710 <input type="checkbox" id="prflxtrflds-show-in-required" name="prflxtrflds_required" value="1"
1711 <?php
1712 if ( ! empty( $field_required ) ) {
1713 echo 'checked="checked"';}
1714 ?>
1715 />
1716 <span class="bws_info"><?php esc_html_e( 'Enable to make this field required.', 'profile-extra-fields' ); ?></span>
1717 </label>
1718 </td>
1719 </tr>
1720 <tr class="prflxtrflds-show-in-required">
1721 <th><?php esc_html_e( 'Required Symbol', 'profile-extra-fields' ); ?></th>
1722 <td>
1723 <label>
1724 <input type="text" id="prflxtrflds-show-in-required-symbol" name="prflxtrflds_required_symbol" value="<?php echo ! empty( $field_required ) ? esc_attr( $field_required ) : '*'; ?>" maxlength="100" />
1725 </label>
1726 </td>
1727 </tr>
1728 <tr>
1729 <th><?php esc_html_e( 'Show by Default in User Data', 'profile-extra-fields' ); ?></th>
1730 <td>
1731 <label>
1732 <input type="checkbox" id="prflxtrflds-show-default" name="prflxtrflds_show_default" value="1"
1733 <?php
1734 if ( isset( $field_show_default ) ) {
1735 checked( $field_show_default, '1' );}
1736 ?>
1737 />
1738 <span class="bws_info"><?php esc_html_e( 'Show this field by default in User Data. You can change it using Screen Options tab.', 'profile-extra-fields' ); ?></span>
1739 </label>
1740 </td>
1741 </tr>
1742 <tr>
1743 <th><?php esc_html_e( 'Always Show in User Data', 'profile-extra-fields' ); ?></th>
1744 <td>
1745 <label>
1746 <input type="checkbox" id="prflxtrflds-show-always" name="prflxtrflds_show_always" value="1"
1747 <?php
1748 if ( isset( $field_show_always ) ) {
1749 checked( $field_show_always, '1' );}
1750 ?>
1751 />
1752 <span class="bws_info"><?php esc_html_e( 'Show this field in User Data on any display. You can change it using Screen Options tab.', 'profile-extra-fields' ); ?></span>
1753 </label>
1754 </td>
1755 </tr>
1756 <?php if ( ! is_multisite() ) { ?>
1757 <tr>
1758 <th><?php esc_html_e( 'Always Show in User Registration Form', 'profile-extra-fields' ); ?></th>
1759 <td>
1760 <label>
1761 <input type="checkbox" id="prflxtrflds-show-in-register-form" name="prflxtrflds_show_in[register_form]" value="1"
1762 <?php
1763 if ( isset( $show_in['register_form'] ) ) {
1764 checked( $show_in['register_form'], '1' );}
1765 ?>
1766 />
1767 <span class="bws_info"><?php esc_html_e( 'Show this field in user registration form.', 'profile-extra-fields' ); ?></span>
1768 </label>
1769 </td>
1770 </tr>
1771 <tr>
1772 <th><?php esc_html_e( 'BWS Register Form', 'profile-extra-fields' ); ?></th>
1773 <td>
1774 <label>
1775 <input type="checkbox" id="prflxtrflds-show-in-bws-register-form" name="prflxtrflds_show_in[bws_login_register_form]" value="1"
1776 <?php
1777 if ( isset( $show_in['bws_login_register_form'] ) ) {
1778 checked( $show_in['bws_login_register_form'], '1' );}
1779 ?>
1780 />
1781 </label>
1782 </td>
1783 </tr>
1784 <?php } ?>
1785 </tbody>
1786 </table>
1787 <?php if ( ! $bws_hide_premium_options_check ) { ?>
1788 <div class="bws_pro_version_bloc prflxtrflds-fields-edit-table">
1789 <div class="bws_pro_version_table_bloc">
1790 <div class="bws_table_bg"></div>
1791 <table class="form-table bws_pro_version">
1792 <tr>
1793 <th scope="row"><label for="prflxtrflds_show_woocommerce"><?php esc_html_e( 'WooСommerce', 'profile-extra-fields' ); ?></label></th>
1794 <td>
1795 <label>
1796 <input disabled="disabled" type="checkbox" id="prflxtrflds-show-woocommerce" name="prflxtrflds_show_woocommerce" value="1" />
1797 <span class="bws_info"><?php esc_html_e( 'Enable to display this field for WooCommerce.', 'profile-extra-fields' ); ?></span>
1798 </label>
1799 </td>
1800 </tr>
1801 <tr>
1802 <th ><label for="prflxtrflds_checkout_woocommerce"><?php esc_html_e( 'WooСommerce Сheckout Form', 'profile-extra-fields' ); ?></label></th>
1803 <td>
1804 <label>
1805 <input disabled="disabled" type="checkbox" id="prflxtrflds-checkout-woocommerce" name="prflxtrflds_checkout_woocommerce" value="1" />
1806 <span class="bws_info"><?php esc_html_e( 'Enable to display this field for WooCommerce Сheckout Form.', 'profile-extra-fields' ); ?></span>
1807 </label>
1808 </td>
1809 </tr>
1810 <tr>
1811 <th scope="row"><label for="prflxtrflds_registration_woocommerce"><?php esc_html_e( 'WooСommerce Registration Form', 'profile-extra-fields' ); ?></label></th>
1812 <td>
1813 <label>
1814 <input disabled="disabled" type="checkbox" id="prflxtrflds-registration-woocommerce" name="prflxtrflds_registration_woocommerce" value="1" />
1815 <span class="bws_info"><?php esc_html_e( 'Enable to display this field for WooCommerce Registration Form.', 'profile-extra-fields' ); ?></span>
1816 </label>
1817 </td>
1818 </tr>
1819 <tr>
1820 <th scope="row"><label for="prflxtrflds_show_subscriber">Subscriber</label></th>
1821 <td>
1822 <label>
1823 <input disabled="disabled" type="checkbox" id="prflxtrflds-show-subscriber" name="prflxtrflds_show_subscriber" value="1" />
1824 <span class="bws_info"><?php esc_html_e( 'Enable to display this field for Subscriber form.', 'profile-extra-fields' ); ?></span>
1825 </label>
1826 </td>
1827 </tr>
1828 </table>
1829 </div>
1830 <div class="bws_pro_version_tooltip">
1831 <a class="bws_button" href="https://bestwebsoft.com/products/wordpress/plugins/profile-extra-fields/?k=c37eed44c2fe607f3400914345cbdc8a&pn=300&v=<?php echo esc_attr( $prflxtrflds_plugin_info['Version'] ); ?>&wp_v=<?php echo esc_attr( $wp_version ); ?>" target="_blank" title="Profile Extra Fields Pro"><?php esc_html_e( 'Upgrade to Pro', 'profile-extra-fields' ); ?></a>
1832 <div class="clear"></div>
1833 </div>
1834 </div>
1835 <?php
1836 }
1837 $plugins_data = apply_filters( 'bws_bkng_prflxtrflds_get_data', $plugins_data = array() );
1838 ?>
1839 <table class="form-table prflxtrflds-fields-edit-table">
1840 <?php foreach ( $plugins_data as $plugin ) { ?>
1841 <tr>
1842 <th><?php echo esc_html( $plugin['name'] ); ?></th>
1843 <td>
1844 <label>
1845 <input type="checkbox" id="prflxtrflds-show-in-<?php echo esc_html( $plugin['slug'] ); ?>" name="prflxtrflds_show_in[<?php echo esc_html( $plugin['slug'] ); ?>]" value="1"
1846 <?php
1847 if ( isset( $show_in[ $plugin['slug'] ] ) && ( 1 === intval( $show_in[ $plugin['slug'] ] ) || is_array( $show_in[ $plugin['slug'] ] ) ) ) {
1848 echo ' checked="checked"';}
1849 ?>
1850 />
1851 <span class="bws_info"><?php printf( esc_html__( 'Enable to display this field for %1$s.', 'profile-extra-fields' ), esc_html( $plugin['name'] ) ); ?></span>
1852 </label>
1853 </td>
1854 </tr>
1855 <?php if ( isset( $plugin['show_in'] ) ) { ?>
1856 <?php foreach ( $plugin['show_in'] as $name => $slug ) { ?>
1857 <tr class="prflxtrflds-show-in-<?php echo esc_html( $plugin['slug'] ); ?>">
1858 <th><?php echo esc_html( $name ); ?></th>
1859 <td>
1860 <label>
1861 <input type="checkbox" name="prflxtrflds_show_in[<?php echo esc_html( $plugin['slug'] ); ?>][<?php echo esc_html( $slug ); ?>]" value="1"
1862 <?php
1863 if ( isset( $show_in[ $plugin['slug'] ][ $slug ] ) ) {
1864 checked( $show_in[ $plugin['slug'] ][ $slug ], '1' );}
1865 ?>
1866 />
1867 <span class="bws_info"><?php printf( esc_html__( 'Enable to display this field for %1$s.', 'profile-extra-fields' ), esc_attr( $name ) ); ?></span>
1868 </label>
1869 </td>
1870 </tr>
1871 <?php } ?>
1872 <?php } ?>
1873 <?php
1874 }
1875 $all_plugins = get_plugins();
1876 $bws_plugins = array(
1877 'bws-car-rental-pro/bws-car-rental-pro.php' => array(
1878 'name' => 'Car Rental V2',
1879 'slug' => 'bws-car-rental-pro',
1880 'link' => 'https://bestwebsoft.com/products/wordpress/plugins/car-rental-v2/?k=9c60bc19fcec6712a46bdc0afb464784&pn=300&v=' . $prflxtrflds_plugin_info['Version'] . '&wp_v=' . $wp_version,
1881 ),
1882 );
1883
1884 if ( ! empty( $plugins_data ) ) {
1885 foreach ( $bws_plugins as $key => $plugin ) {
1886 if ( preg_grep( '/.*' . $plugin['slug'] . '.*$/', array_keys( $plugins_data ) ) ) {
1887 unset( $bws_plugins[ $key ] );
1888 }
1889 }
1890 }
1891
1892 if ( ! empty( $bws_plugins ) ) {
1893 foreach ( $bws_plugins as $path => $plugin ) {
1894 if ( array_key_exists( $path, $all_plugins ) ) {
1895 $button_link = self_admin_url( 'plugins.php' );
1896 $button_text = __( 'Activate', 'profile-extra-fields' );
1897 } else {
1898 $button_link = $plugin['link'];
1899 $button_text = __( 'Download', 'profile-extra-fields' );
1900 }
1901 ?>
1902
1903 <tr>
1904 <th><?php echo esc_attr( $plugin['name'] ); ?></th>
1905 <td>
1906 <label>
1907 <input disabled="disabled" type="checkbox" value="1" />
1908 <span class="bws_info"><?php printf( esc_html__( 'Enable to display this field for %1$s.', 'profile-extra-fields' ), esc_html( $plugin['name'] ) ); ?>
1909 <?php printf( '<a href="%1$s" target="_blank">%2$s %3$s</a>', esc_url( $button_link ), esc_html( $button_text ), esc_html( $plugin['name'] ) ); ?>
1910 </span>
1911 </label>
1912 </td>
1913 </tr>
1914 <?php
1915 }
1916 }
1917 ?>
1918 </table>
1919 <table class="form-table prflxtrflds-fields-edit-table">
1920 <tbody>
1921 <tr>
1922 <th><?php esc_html_e( 'Field Order', 'profile-extra-fields' ); ?></th>
1923 <td>
1924 <input type="number" min="0" max="999" name="prflxtrflds_order" value="<?php echo ( isset( $field_order ) ) ? esc_attr( $field_order ) : '0'; ?>" />
1925 </td>
1926 </tr>
1927 </tbody>
1928 </table>
1929 <p class="submit prflxtrflds-fields-edit-table">
1930 <input type="hidden" name="prflxtrflds_save_field" value="true" />
1931 <input type="hidden" name="prflxtrflds_field_id" value="<?php echo esc_attr( $field_id ); ?>" />
1932 <input id="bws-submit-button" type="submit" class="button-primary" name="prflxtrflds_save_settings" value="<?php esc_html_e( 'Save Changes', 'profile-extra-fields' ); ?>" />
1933 <?php wp_nonce_field( 'prflxtrflds_nonce_name' ); ?>
1934 </p>
1935 </form>
1936 </div>
1937 <?php
1938 }
1939 }
1940
1941 if ( ! function_exists( 'prflxtrflds_screen_options' ) ) {
1942 /**
1943 * Screen option. Settings for display where items per page show in wp list table
1944 */
1945 function prflxtrflds_screen_options() {
1946 $screen = get_current_screen();
1947 $args = array(
1948 'id' => 'prflxtrflds',
1949 'section' => '201146449',
1950 );
1951 bws_help_tab( $screen, $args );
1952
1953 $option = 'per_page';
1954 $args = array(
1955 'label' => __( 'Fields per page', 'profile-extra-fields' ),
1956 'default' => 20,
1957 'option' => 'fields_per_page',
1958 );
1959 add_screen_option( $option, $args );
1960
1961 if ( isset( $_GET['tab-action'] ) && 'userdata' === sanitize_text_field( wp_unslash( $_GET['tab-action'] ) ) ) {
1962 global $prflxtrflds_userdatalist_table;
1963 if ( ! isset( $prflxtrflds_userdatalist_table ) ) {
1964 $prflxtrflds_userdatalist_table = new Prflxtrflds_Userdata_List();
1965 }
1966 } elseif ( isset( $_GET['tab-action'] ) && 'shortcode' === sanitize_text_field( wp_unslash( $_GET['tab-action'] ) ) ) {
1967 global $prflxtrflds_shortcodelist_table;
1968 if ( ! isset( $prflxtrflds_shortcodelist_table ) ) {
1969 $prflxtrflds_shortcodelist_table = new Prflxtrflds_Shortcode_List();
1970 }
1971 } else {
1972 global $prflxtrflds_fields_list_table;
1973 if ( ! isset( $prflxtrflds_fields_list_table ) ) {
1974 $prflxtrflds_fields_list_table = new Prflxtrflds_Fields_List();
1975 }
1976 }
1977 }
1978 }
1979
1980 if ( ! function_exists( 'prflxtrflds_set_screen_options' ) ) {
1981 /**
1982 * Set Screen option.
1983 *
1984 * @param mixed $status The value to save instead of the option value.
1985 * @param string $option The option name.
1986 * @param int $value The option value.
1987 * @return int $value
1988 */
1989 function prflxtrflds_set_screen_options( $status, $option, $value ) {
1990 if ( ! empty( $option ) && 'fields_per_page' === $option ) {
1991 return $value;
1992 }
1993 return $value;
1994 }
1995 }
1996
1997 if ( ! function_exists( 'prflxtrflds_remove_field' ) ) {
1998 /**
1999 * Remove info about field from database
2000 *
2001 * @param int $field_id Field ID for delete.
2002 */
2003 function prflxtrflds_remove_field( $field_id ) {
2004 global $wpdb;
2005 $wpdb->delete(
2006 $wpdb->base_prefix . 'prflxtrflds_fields_id',
2007 array(
2008 'field_id' => $field_id,
2009 )
2010 );
2011 $wpdb->delete(
2012 $wpdb->base_prefix . 'prflxtrflds_fields_meta',
2013 array(
2014 'field_id' => $field_id,
2015 )
2016 );
2017 $wpdb->delete(
2018 $wpdb->base_prefix . 'prflxtrflds_roles_and_fields',
2019 array(
2020 'field_id' => $field_id,
2021 )
2022 );
2023 $wpdb->delete(
2024 $wpdb->base_prefix . 'prflxtrflds_field_values',
2025 array(
2026 'field_id' => $field_id,
2027 )
2028 );
2029 $wpdb->delete(
2030 $wpdb->base_prefix . 'prflxtrflds_user_field_data',
2031 array(
2032 'field_id' => $field_id,
2033 )
2034 );
2035 }
2036 }
2037
2038 if ( ! function_exists( 'prflxtrflds_settings_page' ) ) {
2039 /**
2040 * Settings page
2041 */
2042 function prflxtrflds_settings_page() {
2043 if ( ! class_exists( 'Bws_Settings_Tabs' ) ) {
2044 require_once dirname( __FILE__ ) . '/bws_menu/class-bws-settings.php';
2045 }
2046 require_once dirname( __FILE__ ) . '/includes/class-prflxtrflds-settings.php';
2047 $page = new Prflxtrflds_Settings_Tabs( plugin_basename( __FILE__ ) );
2048 if ( method_exists( $page, 'add_request_feature' ) ) {
2049 $page->add_request_feature();
2050 }
2051 ?>
2052 <div class="wrap">
2053 <h1><?php esc_html_e( 'Profile Extra Fields Settings', 'profile-extra-fields' ); ?></h1>
2054 <?php $page->display_content(); ?>
2055 </div>
2056 <?php
2057 }
2058 }
2059
2060 if ( ! function_exists( 'prflxtrflds_fields' ) ) {
2061 /**
2062 * Display fields
2063 */
2064 function prflxtrflds_fields() {
2065 global $wpdb, $prflxtrflds_options, $prflxtrflds_plugin_info, $wp_version;
2066 $message = '';
2067 $error = '';
2068 $notice = '';
2069
2070 $plugin_basename = plugin_basename( __FILE__ );
2071 /** Remove slug */
2072 if ( isset( $_GET['remove'] ) && isset( $_GET['_wpnonce'] ) && wp_verify_nonce( sanitize_text_field( wp_unslash( $_GET['_wpnonce'] ) ), 'prflxtrflds_nonce_name' ) && current_user_can( 'edit_users' ) ) {
2073 if ( isset( $_GET['prflxtrflds_field_id'] ) ) {
2074 $field_id = filter_input( INPUT_GET, 'prflxtrflds_field_id', FILTER_SANITIZE_STRING );
2075 prflxtrflds_remove_field( $field_id );
2076 }
2077 }
2078
2079 /** Get all available fields and print it */
2080 $available_fields = $wpdb->get_col( 'SELECT `field_id` FROM `' . $wpdb->base_prefix . 'prflxtrflds_fields_id`;' );
2081
2082 if ( isset( $_GET['tab-action'] ) && 'shortcode' === $_GET['tab-action'] ) {
2083 if ( 0 < count( $available_fields ) ) {
2084 if ( isset( $_REQUEST['prflxtrflds_form_submit'] ) &&
2085 check_admin_referer( $plugin_basename, 'prflxtrflds_nonce_name' ) &&
2086 current_user_can( 'edit_users' )
2087 ) {
2088 $prflxtrflds_options['empty_value'] = isset( $_POST['prflxtrflds_empty_value'] ) ? sanitize_text_field( wp_unslash( $_POST['prflxtrflds_empty_value'] ) ) : '';
2089 $prflxtrflds_options['not_available_message'] = isset( $_POST['prflxtrflds_not_available_message'] ) ? sanitize_text_field( wp_unslash( $_POST['prflxtrflds_not_available_message'] ) ) : '';
2090 $prflxtrflds_options['sort_sequence'] = isset( $_POST['prflxtrflds_sort_sequence'] ) && in_array( $_POST['prflxtrflds_sort_sequence'], array( 'ASC', 'DESC' ) ) ? sanitize_text_field( wp_unslash( $_POST['prflxtrflds_sort_sequence'] ) ) : 'ASC';
2091 $prflxtrflds_options['show_empty_columns'] = isset( $_POST['prflxtrflds_show_empty_columns'] ) ? 1 : 0;
2092 $prflxtrflds_options['show_id'] = isset( $_POST['prflxtrflds_show_id'] ) ? 1 : 0;
2093 $prflxtrflds_options['header_table'] = isset( $_POST['prflxtrflds_header_table'] ) && in_array( $_POST['prflxtrflds_header_table'], array( 'columns', 'rows' ) ) ? sanitize_text_field( wp_unslash( $_POST['prflxtrflds_header_table'] ) ) : 'columns';
2094 $prflxtrflds_options['available_values'] = ! empty( $_POST['prflxtrflds_options_available_values'] ) ? array_map( 'sanitize_text_field', array_map( 'wp_unslash', $_POST['prflxtrflds_options_available_values'] ) ) : array();
2095 $prflxtrflds_options['shortcode_debug'] = isset( $_POST['prflxtrflds_shortcode_debug'] ) ? 1 : 0;
2096 $prflxtrflds_options['display_user_name'] = isset( $_POST['prflxtrflds_display_user_name'] ) && in_array( $_POST['prflxtrflds_display_user_name'], array( 'username', 'publicly_name' ) ) ? sanitize_text_field( wp_unslash( $_POST['prflxtrflds_display_user_name'] ) ) : 'username';
2097
2098 $available_fields = ! empty( $_POST['prflxtrflds_options_available_fields'] ) ? array_map( 'absint', $_POST['prflxtrflds_options_available_fields'] ) : $available_fields;
2099 $all_available_fields = ! empty( $_POST['prflxtrflds_options_available_fields_hidden'] ) ? array_map( 'absint', $_POST['prflxtrflds_options_available_fields_hidden'] ) : array();
2100
2101 $old_available_fields = array_diff( (array) $prflxtrflds_options['available_fields'], $all_available_fields );
2102
2103 $prflxtrflds_options['available_fields'] = array_unique( array_merge( $old_available_fields, $available_fields ) );
2104
2105 update_option( 'prflxtrflds_options', $prflxtrflds_options );
2106 $message = __( 'Settings saved', 'profile-extra-fields' );
2107 }
2108
2109 if ( isset( $_REQUEST['bws_restore_confirm'] ) &&
2110 check_admin_referer( $plugin_basename, 'bws_settings_nonce_name' ) &&
2111 current_user_can( 'edit_users' )
2112 ) {
2113 $prflxtrflds_options = prflxtrflds_get_options_default();
2114 update_option( 'prflxtrflds_options', $prflxtrflds_options );
2115 $message = __( 'All plugin settings were restored.', 'profile-extra-fields' );
2116 }
2117 }
2118 }
2119 $bws_hide_premium_options_check = bws_hide_premium_options_check( $prflxtrflds_options );
2120 /** GO PRO */
2121 if ( isset( $_GET['tab-action'] ) && 'go_pro' === $_GET['tab-action'] ) {
2122 $go_pro_result = bws_go_pro_tab_check( $plugin_basename, 'prflxtrflds_options' );
2123 if ( ! empty( $go_pro_result['error'] ) ) {
2124 $error = $go_pro_result['error'];
2125 } elseif ( ! empty( $go_pro_result['message'] ) ) {
2126 $message = $go_pro_result['message'];
2127 }
2128 }
2129 ?>
2130 <div class="wrap">
2131 <h1>
2132 Profile Extra Fields
2133 <a href="admin.php?page=profile-extra-field-add-new.php" class="page-title-action add-new-h2" ><?php esc_html_e( 'Add New', 'profile-extra-fields' ); ?></a>
2134 </h1>
2135 <h2 class="nav-tab-wrapper">
2136 <a class="nav-tab <?php echo ! isset( $_GET['tab-action'] ) ? esc_html( ' nav-tab-active' ) : ''; ?>" href="admin.php?page=profile-extra-fields.php"><?php esc_html_e( 'Extra Fields', 'profile-extra-fields' ); ?></a>
2137 <?php if ( ! $bws_hide_premium_options_check ) { ?>
2138 <a id="prflxtrflds-pro-options" class="nav-tab <?php echo isset( $_GET['tab-action'] ) && 'woocommerce' === $_GET['tab-action'] ? esc_html( ' nav-tab-active' ) : ''; ?>" href="admin.php?page=profile-extra-fields.php&amp;tab-action=woocommerce"><?php esc_html_e( 'WooСommerce', 'profile-extra-fields' ); ?></a>
2139 <a id="prflxtrflds-pro-options" class="nav-tab <?php echo isset( $_GET['tab-action'] ) && 'subscriber' === $_GET['tab-action'] ? esc_html( ' nav-tab-active' ) : ''; ?>" href="admin.php?page=profile-extra-fields.php&amp;tab-action=subscriber">Subscriber</a>
2140 <?php } ?>
2141 <a class="nav-tab <?php echo isset( $_GET['tab-action'] ) && 'booking' === $_GET['tab-action'] ? esc_html( ' nav-tab-active' ) : ''; ?>" href="admin.php?page=profile-extra-fields.php&amp;tab-action=booking"><?php esc_html_e( 'Booking', 'profile-extra-fields' ); ?></a>
2142 <a class="nav-tab <?php echo isset( $_GET['tab-action'] ) && 'login_register' === $_GET['tab-action'] ? esc_html( ' nav-tab-active' ) : ''; ?>" href="admin.php?page=profile-extra-fields.php&amp;tab-action=login_register"><?php esc_html_e( 'Login/Register', 'profile-extra-fields' ); ?></a>
2143 <a class="nav-tab <?php echo isset( $_GET['tab-action'] ) && 'userdata' === $_GET['tab-action'] ? esc_html( ' nav-tab-active' ) : ''; ?>" href="admin.php?page=profile-extra-fields.php&amp;tab-action=userdata"><?php esc_html_e( 'User Data', 'profile-extra-fields' ); ?></a>
2144 <?php if ( 0 < count( $available_fields ) ) { ?>
2145 <a class="nav-tab <?php echo isset( $_GET['tab-action'] ) && 'shortcode' === $_GET['tab-action'] ? esc_html( ' nav-tab-active' ) : ''; ?>" href="admin.php?page=profile-extra-fields.php&amp;tab-action=shortcode"><?php esc_html_e( 'Shortcode Settings', 'profile-extra-fields' ); ?></a>
2146 <?php } ?>
2147 </h2>
2148 <?php if ( ! isset( $_GET['tab-action'] ) ) { ?>
2149 <div class="prflxtrflds-wplisttable-fullwidth-sort-container">
2150 <?php
2151 $prflxtrflds_fields_list_table = new Prflxtrflds_Fields_List(); /** Wp list table to show all fields */
2152 $prflxtrflds_fields_list_table->prepare_items();
2153 if ( isset( $prflxtrflds_fields_list_table->items ) && ( 1 < count( $prflxtrflds_fields_list_table->items ) ) ) { /** Show drag-n-drop message if items > 2 */
2154 ?>
2155 <p class="hide-if-no-js prflxtrflds-hide-if-is-mobile">
2156 <?php esc_html_e( 'Drag each item into the order you would like to display it on the user page', 'profile-extra-fields' ); ?>
2157 </p>
2158 <?php } ?>
2159 <form class="prflxtrflds-wplisttable-searchform" method="get" action="<?php get_admin_url(); ?>?page=profile-extra-fields.php">
2160 <input type="hidden" name="page" value="profile-extra-fields.php" />
2161 <?php
2162 wp_nonce_field( 'prflxtrflds_nonce_name', 'prflxtrflds_nonce_name', false );
2163 $prflxtrflds_fields_list_table->search_box( __( 'Search', 'profile-extra-fields' ), 'search_id' );
2164 ?>
2165 <?php $prflxtrflds_fields_list_table->display(); ?>
2166 </form>
2167 </div><!-- .prflxtrflds-wplisttable-container -->
2168 <?php
2169 } elseif ( isset( $_GET['tab-action'] ) && ( 'woocommerce' === $_GET['tab-action'] || 'subscriber' === $_GET['tab-action'] ) ) {
2170 if ( ! $bws_hide_premium_options_check ) {
2171 ?>
2172 <div class="bws_pro_version_bloc">
2173 <div class="bws_pro_version_table_bloc">
2174 <div class="bws_table_bg"></div>
2175 <table class="form-table bws_pro_version">
2176 <div class="prflxtrflds-wplisttable-fullwidth-sort-container">
2177 <?php
2178 $prflxtrflds_fields_list_table = new Prflxtrflds_Fields_List(); /** Wp list table to show all fields */
2179 ?>
2180 <form class="prflxtrflds-wplisttable-searchform" method="get" action="<?php get_admin_url(); ?>?page=profile-extra-fields.php&tab-action=woocommerce">
2181 <?php
2182 wp_nonce_field( 'prflxtrflds_nonce_name', 'prflxtrflds_nonce_name', false );
2183 $prflxtrflds_fields_list_table->search_box( __( 'Search', 'profile-extra-fields' ), 'search_id' );
2184 ?>
2185 <?php $prflxtrflds_fields_list_table->display(); ?>
2186 </form>
2187 </div><!-- .prflxtrflds-wplisttable-container -->
2188 </table>
2189 </div>
2190 <div class="bws_pro_version_tooltip">
2191 <a class="bws_button" href="https://bestwebsoft.com/products/wordpress/plugins/profile-extra-fields/?k=23e9c49f512f7a6d0900c5a1503ded4f&pn=91&v=<?php echo esc_attr( $prflxtrflds_plugin_info['Version'] ); ?>&wp_v=<?php echo esc_attr( $wp_version ); ?>" target="_blank" title="Profile Extra Fields Pro"><?php esc_html_e( 'Upgrade to Pro', 'profile-extra-fields' ); ?></a>
2192 <div class="clear"></div>
2193 </div>
2194 </div>
2195 <?php } ?>
2196 <?php
2197 } elseif ( isset( $_GET['tab-action'] ) && 'booking' === $_GET['tab-action'] ) {
2198 $plugins_data = apply_filters( 'bws_bkng_prflxtrflds_get_data', $plugins_data = array() );
2199 if ( ! empty( $plugins_data ) ) {
2200 ?>
2201 <div class="prflxtrflds-wplisttable-fullwidth-sort-container">
2202 <?php
2203 $prflxtrflds_fields_list_table = new Prflxtrflds_Fields_List(); /** Wp list table to show all fields */
2204
2205 /** Show drag-n-drop message if items > 2 */
2206 if ( isset( $prflxtrflds_fields_list_table->items ) && ( 1 < count( $prflxtrflds_fields_list_table->items ) ) ) {
2207 ?>
2208 <p class="hide-if-no-js prflxtrflds-hide-if-is-mobile">
2209 <?php esc_html_e( 'Drag each item into the order you would like to display it on the user page', 'profile-extra-fields' ); ?>
2210 </p>
2211 <?php } ?>
2212 <form class="prflxtrflds-wplisttable-searchform" method="get" action="<?php get_admin_url(); ?>?page=profile-extra-fields.php&tab-action=booking">
2213 <input type="hidden" name="page" value="profile-extra-fields.php" />
2214 <?php
2215 wp_nonce_field( 'prflxtrflds_nonce_name', 'prflxtrflds_nonce_name', false );
2216 $prflxtrflds_fields_list_table->search_box( __( 'Search', 'profile-extra-fields' ), 'search_id' );
2217 $prflxtrflds_fields_list_table->display_tablenav( 'top' );
2218 $table_displayed = false;
2219 foreach ( $plugins_data as $plugin ) {
2220 $prflxtrflds_fields_list_table->prepare_items( $plugin['slug'] );
2221 if ( ! empty( $prflxtrflds_fields_list_table->items ) ) {
2222 $table_displayed = true;
2223 ?>
2224 <h2 class="hide-if-js"><?php echo esc_html( $plugin['name'] ); ?></h2>
2225 <?php
2226 $prflxtrflds_fields_list_table->display( false );
2227 ?>
2228 <input type="hidden" class="prflxtrflds-tables-name" value="<?php echo esc_attr( $plugin['name'] ); ?>">
2229 <?php
2230 }
2231 }
2232 if ( ! $table_displayed ) {
2233 $prflxtrflds_fields_list_table->display( false );
2234 }
2235 $prflxtrflds_fields_list_table->display_tablenav( 'bottom' );
2236 ?>
2237 </form>
2238 </div><!-- .prflxtrflds-wplisttable-container -->
2239 <?php
2240 }
2241 $all_plugins = get_plugins();
2242 $bws_plugins = array(
2243 'bws-car-rental-pro/bws-car-rental-pro.php' => array(
2244 'name' => 'Car Rental V2',
2245 'slug' => 'bws-car-rental-pro',
2246 'link' => 'https://bestwebsoft.com/products/wordpress/plugins/car-rental-v2/?k=9c60bc19fcec6712a46bdc0afb464784&pn=300&v=' . $prflxtrflds_plugin_info['Version'] . '&wp_v=' . $wp_version,
2247 ),
2248 );
2249
2250 if ( ! empty( $plugins_data ) ) {
2251 foreach ( $bws_plugins as $key => $plugin ) {
2252 if ( preg_grep( '/.*' . $plugin['slug'] . '.*$/', array_keys( $plugins_data ) ) ) {
2253 unset( $bws_plugins[ $key ] );
2254 }
2255 }
2256 }
2257
2258 if ( ! empty( $bws_plugins ) ) {
2259 foreach ( $bws_plugins as $path => $plugin ) {
2260 if ( array_key_exists( $path, $all_plugins ) ) {
2261 $message = sprintf( __( 'Activate %1$s to display fields for %2$s.', 'profile-extra-fields' ), $plugin['name'], $plugin['name'] );
2262 $button_link = self_admin_url( 'plugins.php' );
2263 $button_text = __( 'Activate', 'profile-extra-fields' );
2264 } else {
2265 $message = sprintf( __( 'Install %1$s to display fields for %2$s.', 'profile-extra-fields' ), $plugin['name'], $plugin['name'] );
2266 $button_link = $plugin['link'];
2267 $button_text = __( 'Download', 'profile-extra-fields' );
2268 }
2269 ?>
2270
2271 <tr>
2272 <td>
2273 <br>
2274 <span class="bws_info"><?php echo esc_attr( $message ); ?>
2275 <?php printf( '<a href="%1$s" target="_blank">%2$s %3$s</a>', esc_url( $button_link ), esc_html( $button_text ), esc_html( $plugin['name'] ) ); ?>
2276 </span>
2277 <br>
2278 </td>
2279 </tr>
2280 <?php } ?>
2281 <br>
2282 <?php } ?>
2283 <?php
2284 } elseif ( isset( $_GET['tab-action'] ) && 'userdata' === $_GET['tab-action'] ) {
2285 global $prflxtrflds_userdatalist_table, $prflxtrflds_plugin_info, $wp_version;
2286 if ( ! isset( $prflxtrflds_userdatalist_table ) ) {
2287 $prflxtrflds_userdatalist_table = new Prflxtrflds_Userdata_List();
2288 }
2289 $bws_hide_premium_options_check = bws_hide_premium_options_check( $prflxtrflds_options );
2290 $prflxtrflds_userdatalist_table->prepare_items();
2291 ?>
2292 <div class="prflxtrflds-wplisttable-fullwidth-container">
2293 <form class="bws_form" method="post" action="" enctype="multipart/form-data">
2294 <?php if ( ! $bws_hide_premium_options_check ) : ?>
2295 <div class="bws_pro_version_bloc">
2296 <div class="bws_pro_version_table_bloc">
2297 <button type="submit" name="bws_hide_premium_options"
2298 class="notice-dismiss bws_hide_premium_options"
2299 title="<?php esc_html_e( 'Close', 'profile-extra-fields' ); ?>"></button>
2300 <div class="bws_table_bg" style="top: 0;"></div>
2301 <table class="form-table prflxtrflds-export-table">
2302 <tr>
2303 <th><?php esc_html_e( 'Import Data', 'profile-extra-fields-pro' ); ?></th>
2304 <td>
2305 <label>
2306 <input type="file" name="prflxtrflds-import-file" accept=".csv">
2307 </label><br/>
2308 <input type="submit" name="prflxtrflds_import_submit" class="button" value="<?php esc_html_e( 'Import', 'profile-extra-fields' ); ?>" />
2309 </td>
2310 </tr>
2311 </table>
2312 </div>
2313 <div class="bws_pro_version_tooltip">
2314 <a class="bws_button" href="https://bestwebsoft.com/products/wordpress/plugins/profile-extra-fields/?k=c37eed44c2fe607f3400914345cbdc8a&pn=300&v=<?php echo esc_attr( $prflxtrflds_plugin_info['Version'] ); ?>&amp;wp_v=<?php echo esc_attr( $wp_version ); ?>" target="_blank" title="Profile Extra Fields Pro"><?php esc_html_e( 'Upgrade to Pro', 'profile-extra-fields' ); ?></a>
2315 <div class="clear"></div>
2316 </div>
2317 </div>
2318 <?php endif; ?>
2319 <table class="form-table prflxtrflds-export-table">
2320 <tr>
2321 <th><?php esc_html_e( 'Export Data', 'profile-extra-fields' ); ?></th>
2322 <td>
2323 <?php esc_html_e( 'Data layout', 'profile-extra-fields' ); ?>:
2324 <select name="prflxtrflds_format_export" >
2325 <option value="columns"<?php selected( $prflxtrflds_options['header_table'], 'columns' ); ?>><?php esc_html_e( 'Columns', 'profile-extra-fields' ); ?></option>
2326 <option value="rows"<?php selected( $prflxtrflds_options['header_table'], 'rows' ); ?>><?php esc_html_e( 'Rows', 'profile-extra-fields' ); ?></option>
2327 </select><br/>
2328 <input type="submit" name="prflxtrflds_export_submit" class="button" value="<?php esc_html_e( 'Export', 'profile-extra-fields' ); ?>" />
2329 <div class="bws_info"><?php esc_html_e( 'Data export does not depend on the selected filters for displaying data in the table below', 'profile-extra-fields' ); ?></div>
2330 </td>
2331 </tr>
2332 </table>
2333 <?php wp_nonce_field( 'prflxtrflds_export_action', 'prflxtrflds_export_field' ); ?>
2334 </form>
2335 <form method="get" class="prflxtrflds-wplisttable-form">
2336 <input type="hidden" name="page" value="profile-extra-fields.php" />
2337 <input type="hidden" name="tab-action" value="userdata" />
2338 <?php if ( ! empty( $_GET['role'] ) ) { ?>
2339 <input type="hidden" name="role" value="<?php echo esc_attr( sanitize_text_field( wp_unslash( $_GET['role'] ) ) ); ?>" />
2340 <?php
2341 }
2342 $prflxtrflds_userdatalist_table->search_box( __( 'Search', 'profile-extra-fields' ), 'search_id' );
2343 $prflxtrflds_userdatalist_table->display();
2344 ?>
2345 </form>
2346 </div>
2347 <?php
2348 } elseif ( isset( $_GET['tab-action'] ) && 'login_register' === $_GET['tab-action'] ) {
2349 if ( is_plugin_active( 'bws-login-register-pro/bws-login-register-pro.php' ) || is_plugin_active( 'bws-login-register/bws-login-register.php' ) ) { ?>
2350 <div class="prflxtrflds-wplisttable-fullwidth-sort-container">
2351 <?php
2352 $prflxtrflds_fields_list_table = new Prflxtrflds_Fields_List(); /* Wp list table to show all fields */
2353 $prflxtrflds_fields_list_table->prepare_items( 'bws_login_register_form' );
2354 if ( isset( $prflxtrflds_fields_list_table->items ) && ( 1 < count( $prflxtrflds_fields_list_table->items ) ) ) { /* Show drag-n-drop message if items > 2 */
2355 ?>
2356 <p class="hide-if-no-js prflxtrflds-hide-if-is-mobile">
2357 <?php esc_html_e( 'Drag each item into the order you would like to display it on the user page', 'profile-extra-fields-pro' ); ?>
2358 </p>
2359 <?php } ?>
2360 <form class="prflxtrflds-wplisttable-searchform" method="get" action="<?php get_admin_url(); ?>?page=profile-extra-fields-pro.php&tab-action=login_register">
2361 <input type="hidden" name="page" value="profile-extra-fields-pro.php" />
2362 <?php
2363 wp_nonce_field( 'prflxtrflds_nonce_name', 'prflxtrflds_nonce_name', false );
2364 $prflxtrflds_fields_list_table->search_box( __( 'Search', 'profile-extra-fields-pro' ), 'search_id' );
2365 ?>
2366 <?php $prflxtrflds_fields_list_table->display(); ?>
2367 </form>
2368 </div><!-- .prflxtrflds-wplisttable-container -->
2369 <?php
2370 } else {
2371 $all_plugins = get_plugins();
2372 if ( ! array_key_exists( 'bws-login-register-pro/bws-login-register-pro.php', $all_plugins ) && ! array_key_exists( 'bws-login-register/bws-login-register.php', $all_plugins ) ) {
2373 ?>
2374 <tr>
2375 <td>
2376 <br>
2377 <span class="bws_info"><?php esc_html_e( 'Install Subscriber to display fields for Subscriber.', 'profile-extra-fields-pro' ); ?> <a target="_blank" href="https://bestwebsoft.com/products/wordpress/plugins/subscriber/?k=1ede2c97fe3ff296c2a729ff6348e105&amp;pn=809&amp;v=<?php echo esc_attr( $prflxtrflds_plugin_info['Version'] ); ?>&amp;wp_v=<?php echo esc_attr( $wp_version ); ?>"><?php esc_html_e( 'Download Subscriber', 'profile-extra-fields-pro' ); ?></a></span>
2378 <br><br>
2379 </td>
2380 </tr>
2381 <?php } else { ?>
2382 <tr>
2383 <td>
2384 <br>
2385 <span class="bws_info"><?php esc_html_e( 'Activate Subscriber to display fields for Subscriber.', 'profile-extra-fields-pro' ); ?><?php printf( ' <a href="%s" target="_blank">%s Subscriber</a>', esc_url( self_admin_url( 'plugins.php' ) ), esc_html__( 'Activate', 'profile-extra-fields-pro' ) ); ?></span>
2386 <br><br>
2387 </td>
2388 </tr>
2389 <?php
2390 }
2391 }
2392 } elseif ( isset( $_GET['tab-action'] ) && 'shortcode' === $_GET['tab-action'] && 0 < count( $available_fields ) ) {
2393 bws_show_settings_notice();
2394 if ( ! empty( $message ) ) {
2395 ?>
2396 <div class="updated fade below-h2"><p><?php echo esc_html( $message ); ?></p></div>
2397 <?php } ?>
2398 <br/>
2399 <form class="bws_form" method="post" action="">
2400 <table class="form-table">
2401 <tbody>
2402 <tr>
2403 <th><?php esc_html_e( 'Message for Empty Field', 'profile-extra-fields' ); ?></th>
2404 <td>
2405 <input type="text" name="prflxtrflds_empty_value" value="<?php echo esc_textarea( $prflxtrflds_options['empty_value'] ); ?>" />
2406 </td>
2407 </tr>
2408 <tr>
2409 <th><?php esc_html_e( 'Message for the Field Unavaliable for the User', 'profile-extra-fields' ); ?></th>
2410 <td>
2411 <input type="text" name="prflxtrflds_not_available_message" value="<?php echo esc_textarea( $prflxtrflds_options['not_available_message'] ); ?>" />
2412 </td>
2413 </tr>
2414 <tr>
2415 <th><?php esc_html_e( 'Sort by User Name', 'profile-extra-fields' ); ?></th>
2416 <td>
2417 <select name="prflxtrflds_sort_sequence" >
2418 <option value="ASC" <?php selected( $prflxtrflds_options['sort_sequence'], 'ASC' ); ?>><?php esc_html_e( 'ASC', 'profile-extra-fields' ); ?></option>
2419 <option value="DESC" <?php selected( $prflxtrflds_options['sort_sequence'], 'DESC' ); ?>><?php esc_html_e( 'DESC', 'profile-extra-fields' ); ?></option>
2420 </select>
2421 </td>
2422 </tr>
2423 <tr>
2424 <th><?php esc_html_e( 'Display Name', 'profile-extra-fields' ); ?></th>
2425 <td>
2426 <fieldset>
2427 <label>
2428 <input type="radio" name="prflxtrflds_display_user_name" value="username" <?php checked( 'username' === $prflxtrflds_options['display_user_name'] ? 1 : 0 ); ?> /><?php esc_html_e( 'Username', 'profile-extra-fields' ); ?>
2429 </label><br>
2430 <label>
2431 <input type="radio" name="prflxtrflds_display_user_name" value="publicly_name" <?php checked( 'publicly_name' === $prflxtrflds_options['display_user_name'] ? 1 : 0 ); ?> ><?php esc_html_e( 'Public Name', 'profile-extra-fields' ); ?>
2432 </label>
2433 </fieldset>
2434 </td>
2435 </tr>
2436 <tr>
2437 <th><?php esc_html_e( 'Show Empty Fields', 'profile-extra-fields' ); ?></th>
2438 <td>
2439 <label>
2440 <input type="checkbox" name="prflxtrflds_show_empty_columns" value="1" <?php checked( $prflxtrflds_options['show_empty_columns'] ); ?> />
2441 <span class="bws_info"><?php esc_html_e( 'Enable to show the field if the value is not filled by a user.', 'profile-extra-fields' ); ?></span>
2442 </label>
2443 </td>
2444 </tr>
2445 <tr>
2446 <th><?php esc_html_e( 'Show User ID', 'profile-extra-fields' ); ?></th>
2447 <td>
2448 <input type="checkbox" name="prflxtrflds_show_id" value="1" <?php checked( $prflxtrflds_options['show_id'] ); ?> />
2449 </td>
2450 </tr>
2451 <tr>
2452 <th><?php esc_html_e( 'Data Rotation', 'profile-extra-fields' ); ?></th>
2453 <td>
2454 <select name="prflxtrflds_header_table" >
2455 <option value="columns"<?php selected( $prflxtrflds_options['header_table'], 'columns' ); ?>><?php esc_html_e( 'Columns', 'profile-extra-fields' ); ?></option>
2456 <option value="rows"<?php selected( $prflxtrflds_options['header_table'], 'rows' ); ?>><?php esc_html_e( 'Rows', 'profile-extra-fields' ); ?></option>
2457 </select>
2458 </td>
2459 </tr>
2460 <tr>
2461 <th><?php esc_html_e( 'Debug Mode', 'profile-extra-fields' ); ?></th>
2462 <td>
2463 <label>
2464 <input type="checkbox" name="prflxtrflds_shortcode_debug" value="1" <?php checked( $prflxtrflds_options['shortcode_debug'] ); ?> />
2465 <span class="bws_info"><?php esc_html_e( 'Enable to display error messages when shortcode formation is failed (i.e. there are no users for the selected roles).', 'profile-extra-fields' ); ?></span>
2466 </label>
2467 </td>
2468 </tr>
2469 </tbody>
2470 </table><!--.form-table-->
2471 <div class="prflxtrflds-wplisttable-container">
2472 <?php
2473 $prflxtrflds_shortcodelist_table = new Prflxtrflds_Shortcode_List();
2474 /** Wp lis table for shortcode settings */
2475 $prflxtrflds_shortcodelist_table->prepare_items();
2476 $prflxtrflds_shortcodelist_table->views();
2477 $prflxtrflds_shortcodelist_table->display();
2478 ?>
2479 </div><!--.prflxtrflds-wplisttable-container-->
2480 <p class="submit">
2481 <input type="hidden" name="prflxtrflds_form_submit" value="submit" />
2482 <?php wp_nonce_field( $plugin_basename, 'prflxtrflds_nonce_name' ); ?>
2483 <input id="bws-submit-button" type="submit" class="button-primary" name="prflxtrflds_save_changes" value="<?php esc_html_e( 'Save Changes', 'profile-extra-fields' ); ?>" />
2484 </p>
2485 </form>
2486 <?php } ?>
2487 </div><!--.wrap-->
2488 <?php
2489 }
2490 }
2491
2492 if ( ! function_exists( 'prflxtrflds_show_data' ) ) {
2493 /**
2494 * Print shortcode
2495 *
2496 * @param array $param Args for shortcode.
2497 */
2498 function prflxtrflds_show_data( $param ) {
2499 global $wpdb, $prflxtrflds_options;
2500 $error_message = '';
2501 $user_ids = array();
2502 $field_id = array();
2503 $export_action = ( isset( $param['export'] ) && true === $param['export'] ) ? true : false;
2504
2505 if ( ! isset( $prflxtrflds_options ) ) {
2506 prflxtrflds_settings();
2507 }
2508
2509 extract(
2510 shortcode_atts(
2511 array(
2512 'user_id' => '',
2513 'user_role' => '',
2514 'display' => '',
2515 'field_id' => '',
2516 ),
2517 $param
2518 )
2519 );
2520
2521 /** Get user id param */
2522 if ( ! empty( $param['user_id'] ) ) {
2523 if ( 'get_current_user' === $param['user_id'] ) {
2524 $user_ids = array( get_current_user_id() );
2525 } else {
2526 $user_ids = explode( ',', $param['user_id'] );
2527 if ( is_array( $user_ids ) ) {
2528 /** If lot user ids */
2529 foreach ( $user_ids as $user_id ) {
2530 /** Check for existing user */
2531 if ( ! is_numeric( $user_id ) || ! get_user_by( 'id', absint( $user_id ) ) ) {
2532 /** Show error if user id not exist, or data is uncorrect */
2533 $error_message = sprintf( __( 'User with entered id (id=%1$s) does not exist!', 'profile-extra-fields' ), esc_attr( $user_id ) );
2534 }
2535 }
2536 }
2537 }
2538 }
2539 /** Get user role param */
2540 if ( ! empty( $param['user_role'] ) ) {
2541 $user_roles = explode( ',', $param['user_role'] );
2542 if ( is_array( $user_roles ) ) {
2543 foreach ( $user_roles as $role ) {
2544 /** Check for exist user role */
2545 $role_id = $wpdb->get_var( $wpdb->prepare( 'SELECT `role_id` FROM `' . $wpdb->base_prefix . 'prflxtrflds_roles_id` WHERE `role` = %s', $role ) );
2546 if ( ! empty( $role_id ) ) {
2547 /** Get user ids by role */
2548 $ids_for_role = $wpdb->get_col( $wpdb->prepare( 'SELECT `user_id` FROM `' . $wpdb->base_prefix . 'prflxtrflds_user_roles` WHERE `role_id`=%d', $role_id ) );
2549 if ( ! empty( $ids_for_role ) ) {
2550 $user_ids = array_merge( $user_ids, $ids_for_role );
2551 }
2552 }
2553 }
2554 /** If not exist users for choisen role. User ids is empty and select all users */
2555 if ( empty( $user_ids ) ) {
2556 $error_message = sprintf( __( 'There are no users for the selected roles ( %1$s )', 'profile-extra-fields' ), esc_attr( $param['user_role'] ) );
2557 }
2558 }
2559 }
2560 /** Get display options */
2561 if ( ! empty( $param['display'] ) ) {
2562 /** If this values is not supported */
2563 if ( ! in_array( $param['display'], array( 'left', 'top', 'right', 'side', 'columns', 'rows' ) ) ) {
2564 $error_message .= sprintf( __( 'Unsupported shortcode option (display=%1$s)', 'profile-extra-fields' ), esc_attr( $param['display'] ) );
2565 } else {
2566 $display = $param['display'];
2567 }
2568 } else {
2569 /** If value not in shortcode, get from options. Top by default */
2570 $display = isset( $prflxtrflds_options['header_table'] ) ? $prflxtrflds_options['header_table'] : 'columns';
2571 }
2572 if ( ! empty( $error_message ) ) {
2573 if ( ! empty( $prflxtrflds_options['shortcode_debug'] ) ) {
2574 return sprintf( '<p>%1$s. %2$s</p>', __( 'Shortcode output error', 'profile-extra-fields' ), $error_message );
2575 } else {
2576 return '';
2577 }
2578 } else {
2579 $wp_users = $wpdb->base_prefix . 'users';
2580 $wp_usermeta = $wpdb->base_prefix . 'usermeta';
2581 $table_fields_id = $wpdb->base_prefix . 'prflxtrflds_fields_id';
2582 $table_user_field_data = $wpdb->base_prefix . 'prflxtrflds_user_field_data';
2583 $table_field_values = $wpdb->base_prefix . 'prflxtrflds_field_values';
2584 $table_roles_id = $wpdb->base_prefix . 'prflxtrflds_roles_id';
2585 $table_roles_and_fields = $wpdb->base_prefix . 'prflxtrflds_roles_and_fields';
2586 $table_user_roles = $wpdb->base_prefix . 'prflxtrflds_user_roles';
2587
2588 /** Collate all users ids */
2589 $get_for_selected_users = '';
2590 if ( ! empty( $user_ids ) ) {
2591 $get_for_selected_users = ' AND `' . $table_user_roles . "`.`user_id` IN ( '" . implode( "', '", $user_ids ) . "' )";
2592 }
2593
2594 /** Get options - Which fields must be displayed */
2595 $get_for_available_fields = '';
2596 if ( $export_action ) {
2597 $totalitems = $wpdb->get_col( 'SELECT `field_id` FROM `' . $wpdb->base_prefix . 'prflxtrflds_fields_id`' );
2598 $field_ids = implode( "', '", $totalitems );
2599 $get_for_available_fields = ' AND `' . $table_fields_id . "`.`field_id` IN ('" . $field_ids . "')";
2600 } else {
2601 if ( ! empty( $prflxtrflds_options['available_fields'] ) ) {
2602 $field_ids = implode( "', '", $prflxtrflds_options['available_fields'] );
2603 $get_for_available_fields = ' AND `' . $table_fields_id . "`.`field_id` IN ('" . $field_ids . "')";
2604 }
2605 }
2606
2607 $get_for_available_field_value = '';
2608 if ( ! empty( $prflxtrflds_options['available_values'] ) ) {
2609 $i = 0;
2610 $extended_value = '';
2611 foreach ( $prflxtrflds_options['available_values'] as $value => $key ) {
2612 if ( '' !== $key ) {
2613 if ( 0 !== $i ) {
2614 $extended_value .= ' OR ';
2615 }
2616
2617 $extended_value .= "(`user_value`='" . $key . "' AND `field_id`='" . $value . "')";
2618 $i++;
2619 }
2620 }
2621 if ( '' !== $extended_value ) {
2622 $get_for_available_field_value = ' AND `' . $table_user_roles . '`.`user_id` IN
2623 (SELECT `user_id`
2624 FROM `' . $table_user_field_data . '`
2625 WHERE ' . $extended_value . ')';
2626 }
2627 }
2628
2629 $get_users_data_sql = 'SELECT ' . $wp_users . '.`user_nicename` , `display_name` , ' .
2630 $table_user_roles . '.`user_id`, ' .
2631 $table_fields_id . '.`field_name`, ' .
2632 $table_fields_id . '.`field_id`, ' .
2633 $table_fields_id . '.`field_type_id` ' .
2634 'FROM ' . $wp_users .
2635 ' INNER JOIN ' . $table_user_roles .
2636 ' ON ' . $table_user_roles . '.`user_id`=' . $wp_users . '.`ID` ' . $get_for_selected_users . $get_for_available_field_value .
2637 ' LEFT JOIN ' . $table_roles_and_fields .
2638 ' ON ' . $table_roles_and_fields . '.`role_id`=' . $table_user_roles . '.`role_id` ' .
2639 ' LEFT JOIN ' . $table_roles_id .
2640 ' ON ' . $table_roles_id . '.`role_id`=' . $table_user_roles . '.`role_id` ' .
2641 ' LEFT JOIN ' . $table_fields_id .
2642 ' ON ' . $table_fields_id . '.`field_id`=' . $table_roles_and_fields . '.`field_id` ' . $get_for_available_fields;
2643
2644 if ( is_multisite() ) {
2645 $get_users_data_sql .= ' WHERE ' . $wp_users . '.`ID` IN ( ' . implode( ',', get_users( 'blog_id=' . get_current_blog_id() . '&fields=ID' ) ) . ')';
2646 }
2647
2648 /** Group all and Add sorting order */
2649 $get_users_data_sql .= ' GROUP BY `' . $wp_users . '`.`ID`, `' . $table_fields_id . '`.`field_id` ORDER BY `' . $wp_users . '`.`user_nicename` ' . $prflxtrflds_options['sort_sequence'];
2650 /** Begin collate data to print shortcode */
2651 ob_start();
2652
2653 $printed_table = $wpdb->get_results( $get_users_data_sql, ARRAY_A );
2654
2655 if ( ! empty( $printed_table ) ) {
2656 foreach ( $printed_table as $key => $column ) {
2657 if ( ! empty( $column['field_id'] ) ) {
2658 if ( in_array( $column['field_type_id'], array( '3', '4', '5' ) ) ) {
2659 $user_value = $wpdb->get_col(
2660 $wpdb->prepare(
2661 'SELECT `value_name`
2662 FROM ' . $table_field_values .
2663 ' WHERE `value_id` IN ( SELECT `user_value` FROM ' . $table_user_field_data . ' WHERE `user_id`=%d AND `field_id`=%d )',
2664 $column['user_id'],
2665 $column['field_id']
2666 )
2667 );
2668
2669 $printed_table[ $key ]['value'] = implode( ', ', $user_value );
2670 } elseif ( '13' === $column['field_type_id'] ) {
2671 $user_value = $wpdb->get_var(
2672 $wpdb->prepare(
2673 'SELECT `user_value`
2674 FROM `' . $table_user_field_data . '` WHERE `user_id`= %d
2675 AND `field_id`=%d LIMIT 1;',
2676 $column['user_id'],
2677 $column['field_id']
2678 )
2679 );
2680 $countries = prflxtrflds_get_country();
2681
2682 $printed_table[ $key ]['value'] = isset( $countries[ $user_value ] ) ? $countries[ $user_value ] : '';
2683 } else {
2684 $printed_table[ $key ]['value'] = $wpdb->get_var(
2685 $wpdb->prepare(
2686 'SELECT `user_value`
2687 FROM `' . $table_user_field_data . '` WHERE `user_id`= %d
2688 AND `field_id`=%d LIMIT 1;',
2689 $column['user_id'],
2690 $column['field_id']
2691 )
2692 );
2693 }
2694 }
2695 }
2696
2697 /** Get all field names */
2698 /** By default show all fields */
2699 $all_fields_sql = 'SELECT DISTINCT `field_id`, `field_name` FROM ' . $table_fields_id;
2700
2701 $all_fields = $wpdb->get_results( $all_fields_sql, ARRAY_A );
2702
2703 /** If need not show empty collumns */
2704 if ( ! $export_action && 0 === $prflxtrflds_options['show_empty_columns'] ) {
2705 /** Delete not filled columns */
2706 foreach ( $all_fields as $key => $one_field ) {
2707 $is_empty = 1;
2708 foreach ( $printed_table as $printed_line ) {
2709 /** If field not empty */
2710 if ( $printed_line['field_id'] === $one_field['field_id'] ) {
2711 if ( ! empty( $printed_line['value'] ) ) {
2712 $is_empty = 0;
2713 break;
2714 }
2715 }
2716 }
2717 if ( 1 === $is_empty ) {
2718 /** Delete if empty from all fields */
2719 unset( $all_fields[ $key ] );
2720 }
2721 }
2722 }
2723 if ( 'columns' === $display ) {
2724 if ( $export_action ) {
2725 $return_output_export = array();
2726 $output_export[] = __( 'User ID', 'profile-extra-fields' );
2727 $output_export[] = __( 'Username', 'profile-extra-fields' );
2728 $output_export[] = __( 'User role', 'profile-extra-fields' );
2729 $output_export[] = __( 'Name', 'profile-extra-fields' );
2730 $output_export[] = __( 'Email', 'profile-extra-fields' );
2731 $output_export[] = __( 'Posts', 'profile-extra-fields' );
2732
2733 foreach ( $all_fields as $one_field ) {
2734 $output_export[] = $one_field['field_name'];
2735 }
2736 $return_output_export[] = $output_export;
2737 unset( $output_export );
2738 foreach ( $printed_table as $column_key => $column ) {
2739 /** If is new username */
2740 if ( ! isset( $printed_table[ $column_key - 1 ] ) ||
2741 ( isset( $printed_table[ $column_key - 1 ] ) &&
2742 $printed_table[ $column_key - 1 ]['user_nicename'] !== $column['user_nicename'] )
2743 ) {
2744
2745 $user = get_user_by( 'ID', $column['user_id'] );
2746 $output_export[] = $column['user_id'];
2747 $output_export[] = esc_attr( $column['user_nicename'] );
2748 $output_export[] = implode( ', ', $user->roles );
2749 $output_export[] = $user->first_name . ' ' . $user->last_name;
2750 $output_export[] = $user->user_email;
2751 $output_export[] = count_user_posts( $user->ID );
2752
2753 $user_fields_temp = $all_fields;
2754 }
2755
2756 foreach ( $user_fields_temp as $key => $one_field ) {
2757 if ( $column['field_id'] === $one_field['field_id'] ) {
2758 $user_fields_temp[ $key ]['user_value'] = esc_attr( $column['value'] );
2759 break;
2760 }
2761 }
2762 if ( ! isset( $printed_table[ $column_key + 1 ] ) ||
2763 ( isset( $printed_table[ $column_key + 1 ] ) &&
2764 $printed_table[ $column_key + 1 ]['user_nicename'] !== $column['user_nicename'] )
2765 ) {
2766 if ( ! empty( $user_fields_temp ) ) {
2767 foreach ( $user_fields_temp as $key => $value ) {
2768 $output_export[] = $value['user_value'];
2769 }
2770 }
2771 $return_output_export[] = $output_export;
2772 unset( $output_export );
2773 }
2774 }
2775 return $return_output_export;
2776 }
2777 ?>
2778 <div style ="max-width: 100%; overflow-x: auto;margin-bottom: 15px;">
2779 <table>
2780 <thead>
2781 <tr>
2782 <?php if ( 1 === $prflxtrflds_options['show_id'] ) { ?>
2783 <th><?php esc_html_e( 'User ID', 'profile-extra-fields' ); ?></th>
2784 <?php } ?>
2785 <th><?php esc_html_e( 'Username', 'profile-extra-fields' ); ?></th>
2786 <?php foreach ( $all_fields as $one_field ) { ?>
2787 <th><?php echo esc_html( $one_field['field_name'] ); ?></th>
2788 <?php } ?>
2789 </tr>
2790 </thead>
2791 <tbody>
2792 <?php
2793 foreach ( $printed_table as $column_key => $column ) {
2794 /** If is new username */
2795 if ( ! isset( $printed_table[ $column_key - 1 ] ) ||
2796 ( isset( $printed_table[ $column_key - 1 ] ) &&
2797 $printed_table[ $column_key - 1 ]['user_nicename'] !== $column['user_nicename'] )
2798 ) {
2799 ?>
2800 <tr>
2801 <?php if ( 1 === $prflxtrflds_options['show_id'] ) { ?>
2802 <td><?php echo esc_attr( $column['user_id'] ); ?></td>
2803 <?php } ?>
2804 <td><?php echo esc_attr( $column[ 'username' === $prflxtrflds_options['display_user_name'] ? 'user_nicename' : 'display_name' ] ); ?></td>
2805 <?php
2806 $user_fields_temp = $all_fields;
2807 }
2808 foreach ( $user_fields_temp as $key => $one_field ) {
2809 if ( $column['field_id'] === $one_field['field_id'] ) {
2810 if ( ! empty( $column['value'] ) ) {
2811 if ( 11 === intval( $column['field_type_id'] ) ) {
2812 $user_fields_temp[ $key ]['user_value'] = '<a href="' . esc_url( $column['value'] ) . '" title="">' . esc_attr( $column['value'] ) . '</a>';
2813 } else {
2814 $user_fields_temp[ $key ]['user_value'] = wp_unslash( wp_kses_post( str_replace( PHP_EOL, '<br />', wp_unslash( $column['value'] ) ) ) );
2815 }
2816 break;
2817 } else {
2818 $user_fields_temp[ $key ]['user_value'] = $prflxtrflds_options['empty_value'];
2819 }
2820 }
2821 }
2822 if ( ! isset( $printed_table[ $column_key + 1 ] ) ||
2823 ( isset( $printed_table[ $column_key + 1 ] ) &&
2824 $printed_table[ $column_key + 1 ]['user_nicename'] !== $column['user_nicename'] )
2825 ) {
2826 if ( ! empty( $user_fields_temp ) ) {
2827 foreach ( $user_fields_temp as $key => $value ) {
2828 if ( isset( $value['user_value'] ) ) {
2829 echo '<td>' . wp_kses_post( wp_unslash( $value['user_value'] ) ) . '</td>';
2830 } else {
2831 echo '<td>' . wp_kses_post( $prflxtrflds_options['not_available_message'] ) . '</td>';
2832 }
2833 }
2834 }
2835 ?>
2836 </tr>
2837 <?php
2838 }
2839 }
2840 ?>
2841 </tbody>
2842 </table>
2843 </div>
2844 <?php
2845 } else {
2846 if ( $export_action ) {
2847 $distinct_users = array();
2848 $return_output_export = array();
2849 $output_export = array();
2850 foreach ( $printed_table as $one_row ) {
2851 /** Create array of distinct users */
2852 if ( 0 < $one_row['user_id'] && ! isset( $distinct_users[ $one_row['user_id'] ] ) ) {
2853 $distinct_users[ $one_row['user_id'] ] = $one_row[ 'username' === $prflxtrflds_options['display_user_name'] ? 'user_nicename' : 'display_name' ];
2854 }
2855 }
2856 $output_export[] = __( 'User ID', 'profile-extra-fields' );
2857 foreach ( array_keys( $distinct_users ) as $user_id ) {
2858 $output_export[] = esc_attr( $user_id );
2859 }
2860 $return_output_export[] = $output_export;
2861 unset( $output_export );
2862
2863 $output_export[] = __( 'Username', 'profile-extra-fields' );
2864 foreach ( $distinct_users as $user_name ) {
2865 $output_export[] = esc_attr( $user_name );
2866 }
2867 $return_output_export[] = $output_export;
2868 unset( $output_export );
2869
2870 $output_export[] = __( 'User role', 'profile-extra-fields' );
2871 foreach ( array_keys( $distinct_users ) as $user_id ) {
2872 $user = get_user_by( 'ID', $user_id );
2873 $output_export[] = implode( ', ', $user->roles );
2874 }
2875 $return_output_export[] = $output_export;
2876 unset( $output_export );
2877
2878 $output_export[] = __( 'Name', 'profile-extra-fields' );
2879 foreach ( array_keys( $distinct_users ) as $user_id ) {
2880 $user = get_user_by( 'ID', $user_id );
2881 $output_export[] = $user->first_name . ' ' . $user->last_name;
2882 }
2883 $return_output_export[] = $output_export;
2884 unset( $output_export );
2885
2886 $output_export[] = __( 'Email', 'profile-extra-fields' );
2887 foreach ( array_keys( $distinct_users ) as $user_id ) {
2888 $user = get_user_by( 'ID', $user_id );
2889 $output_export[] = $user->user_email;
2890 }
2891 $return_output_export[] = $output_export;
2892 unset( $output_export );
2893
2894 $output_export[] = __( 'Posts', 'profile-extra-fields' );
2895 foreach ( array_keys( $distinct_users ) as $user_id ) {
2896 $user = get_user_by( 'ID', $user_id );
2897 $output_export[] = count_user_posts( $user->ID );
2898 }
2899 $return_output_export[] = $output_export;
2900 unset( $output_export );
2901
2902 foreach ( $all_fields as $one_field ) { /** Create new row for every field */
2903 $output_export[] = esc_attr( $one_field['field_name'] );
2904 /** Create column for every user */
2905 foreach ( array_keys( $distinct_users ) as $one_user_id ) {
2906 /** Get data for current field id and user */
2907 foreach ( $printed_table as $one_row ) {
2908 /** Skip if data not for current user */
2909 if ( intval( $one_row['user_id'] ) !== $one_user_id ) {
2910 continue;
2911 }
2912 if ( $one_field['field_id'] === $one_row['field_id'] ) {
2913 /** If no key exist, no set $user_field_data */
2914 if ( key_exists( 'value', $one_row ) ) {
2915 if ( empty( $one_row['value'] ) ) {
2916 /** Empty data for empty user value */
2917 $user_field_data = '';
2918 } else {
2919 /** Save user value */
2920 $user_field_data = $one_row['value'];
2921 }
2922 }
2923 }
2924 }
2925 $output_export[] = esc_attr( $user_field_data );
2926 unset( $user_field_data );
2927 }
2928 $return_output_export[] = $output_export;
2929 unset( $output_export );
2930 }
2931 return $return_output_export;
2932 }
2933
2934 $distinct_users = array();
2935 foreach ( $printed_table as $one_row ) {
2936 /** Create array of distinct users */
2937 if ( 0 < $one_row['user_id'] && ! isset( $distinct_users[ $one_row['user_id'] ] ) ) {
2938 $distinct_users[ $one_row['user_id'] ] = $one_row[ 'username' === $prflxtrflds_options['display_user_name'] ? 'user_nicename' : 'display_name' ];
2939 }
2940 }
2941 ?>
2942 <div style ="max-width: 100%; overflow-x: auto;margin-bottom: 15px;">
2943 <table>
2944 <?php if ( 1 === $prflxtrflds_options['show_id'] ) { ?>
2945 <tr>
2946 <th><?php esc_html_e( 'User ID', 'profile-extra-fields' ); ?></th>
2947 <?php foreach ( array_keys( $distinct_users ) as $user_id ) { ?>
2948 <td><?php echo esc_attr( $user_id ); ?></td>
2949 <?php } ?>
2950 </tr>
2951 <?php } /** Show user name */ ?>
2952 <tr>
2953 <th><?php esc_html_e( 'Username', 'profile-extra-fields' ); ?></th>
2954 <?php foreach ( $distinct_users as $user_name ) { ?>
2955 <td><?php echo esc_attr( $user_name ); ?></td>
2956 <?php } ?>
2957 </tr>
2958 <?php foreach ( $all_fields as $one_field ) { /** Create new row for every field */ ?>
2959 <tr>
2960 <th><?php echo esc_attr( $one_field['field_name'] ); ?></th>
2961 <?php
2962 foreach ( array_keys( $distinct_users ) as $one_user_id ) { /** Create column for every user */
2963 foreach ( $printed_table as $one_row ) {
2964 /** Get data for current field id and user */
2965 /** Skip if data not for current user */
2966 if ( intval( $one_row['user_id'] ) !== $one_user_id ) {
2967 continue;
2968 }
2969 if ( $one_field['field_id'] === $one_row['field_id'] ) {
2970 /** If no key exist, no set $user_field_data */
2971 if ( key_exists( 'value', $one_row ) ) {
2972 if ( empty( $one_row['value'] ) ) {
2973 /** Empty data for empty user value */
2974 $user_field_data = '';
2975 } else {
2976 /** Save user value */
2977 if ( 11 === intval( $one_row['field_type_id'] ) ) {
2978 $user_field_data = '<a href="' . esc_url( $one_row['value'] ) . '" title="" >' . esc_attr( $one_row['value'] ) . '</a>';
2979 } else {
2980 $user_field_data = wp_unslash( wp_kses_post( str_replace( PHP_EOL, '<br />', $one_row['value'] ) ) );
2981 }
2982 }
2983 }
2984 }
2985 }
2986 ?>
2987 <td>
2988 <?php
2989 if ( ! isset( $user_field_data ) ) {
2990 /** Current field not avaialible for current user */
2991 echo esc_html( $prflxtrflds_options['not_available_message'] );
2992 } elseif ( empty( $user_field_data ) ) {
2993 /** This value is empty. Unset user data for next user */
2994 echo esc_html( $prflxtrflds_options['empty_value'] );
2995 unset( $user_field_data );
2996 } else {
2997 /** Print user data. Unset for next user */
2998 echo wp_kses_post( wp_unslash( $user_field_data ) );
2999 unset( $user_field_data );
3000 }
3001 ?>
3002 </td>
3003 <?php } ?>
3004 </tr>
3005 <?php } ?>
3006 </table>
3007 </div>
3008 <?php
3009 }
3010 /** If printed table is empty */
3011 } else {
3012 ?>
3013 <p><?php esc_html_e( 'No data for current shortcode settings', 'profile-extra-fields' ); ?></p>
3014 <?php
3015 }
3016 $prflxtrflds_shortcode_output = ob_get_contents();
3017 ob_end_clean();
3018
3019 if ( ! empty( $prflxtrflds_shortcode_output ) ) {
3020 return $prflxtrflds_shortcode_output;
3021 }
3022 }
3023 }
3024 }
3025
3026 if ( ! function_exists( 'prflxtrflds_show_field' ) ) {
3027 /**
3028 * Display fields
3029 *
3030 * @param array $param Args for shortcode.
3031 */
3032 function prflxtrflds_show_field( $param ) {
3033 global $wpdb, $prflxtrflds_options;
3034 $error_message = '';
3035
3036 if ( ! isset( $prflxtrflds_options ) ) {
3037 prflxtrflds_settings();
3038 }
3039
3040 extract(
3041 shortcode_atts(
3042 array(
3043 'field_id' => '',
3044 'user_id' => '',
3045 ),
3046 $param
3047 )
3048 );
3049
3050 if ( empty( $param['user_id'] ) ) {
3051 $user_id = get_current_user_id();
3052 } else {
3053 $user_id = $param['user_id'];
3054 if ( ! is_numeric( $user_id ) || ! get_user_by( 'id', intval( $user_id ) ) ) {
3055 /** Show error if user id not exist, or data is uncorrect */
3056 $error_message = sprintf( __( 'User with entered id(id=%1$s) does not exist!', 'profile-extra-fields' ), esc_attr( $user_id ) );
3057 }
3058 }
3059
3060 $field_ids = $wpdb->get_col( 'SELECT `field_id` FROM `' . $wpdb->base_prefix . 'prflxtrflds_fields_id`' );
3061
3062 if ( ! in_array( $param['field_id'], $field_ids ) ) {
3063 $error_message = sprintf( __( 'Field with entered id(id=%1$s) does not exist!', 'profile-extra-fields' ), esc_attr( $param['field_id'] ) );
3064 }
3065
3066 $field_type = $wpdb->get_var(
3067 $wpdb->prepare(
3068 'SELECT `field_type_id`
3069 FROM `' . $wpdb->prefix . 'prflxtrflds_fields_id`
3070 WHERE `field_id` =%d',
3071 $param['field_id']
3072 )
3073 );
3074
3075 if ( in_array( $field_type, array( '3', '4', '5' ) ) ) {
3076 /** Query if type of field is checkbox, radio or drop list*/
3077 $query = $wpdb->prepare(
3078 'SELECT `value_name`
3079 FROM `' . $wpdb->prefix . 'prflxtrflds_field_values`
3080 WHERE `value_id`
3081 IN ( SELECT `user_value` FROM `' . $wpdb->prefix . 'prflxtrflds_user_field_data` WHERE `user_id`=%d AND `field_id`=%d )',
3082 $user_id,
3083 $param['field_id']
3084 );
3085 $field = implode( ', ', $wpdb->get_col( $query ) );
3086 } else {
3087 $query = $wpdb->prepare(
3088 'SELECT `user_value`
3089 FROM `' . $wpdb->prefix . 'prflxtrflds_user_field_data`
3090 WHERE `field_id` = %d AND `user_id` = %d',
3091 $param['field_id'],
3092 $user_id
3093 );
3094 $field = $wpdb->get_var( $query );
3095 }
3096
3097 if ( ! empty( $error_message ) ) {
3098 if ( ! empty( $prflxtrflds_options['shortcode_debug'] ) ) {
3099 return sprintf( '<p>%1$s. %2$s</p>', esc_html__( 'Shortcode output error', 'profile-extra-fields' ), $error_message );
3100 } else {
3101 return '';
3102 }
3103 } else {
3104 return $field;
3105 }
3106 }
3107 }
3108
3109 if ( ! function_exists( 'prflxtrflds_show_edit_form' ) ) {
3110 /**
3111 * Display edit form on front
3112 */
3113 function prflxtrflds_show_edit_form() {
3114 global $wpdb, $prflxtrflds_options, $hook_suffix, $prflxtrflds_front_shortcode;
3115 $message = '';
3116 $error = '';
3117 $errors = new WP_Error();
3118
3119 if ( wp_is_json_request() ) {
3120 return;
3121 }
3122
3123 if ( ! isset( $prflxtrflds_options ) ) {
3124 prflxtrflds_settings();
3125 }
3126
3127 $user_id = get_current_user_id();
3128 if ( ! empty( $user_id ) ) {
3129 $user = wp_get_current_user();
3130 $user_info = get_userdata( $user_id );
3131 $user_role = isset( $user_info->roles ) ? implode( "', '", $user_info->roles ) : get_option( 'default_role' );
3132
3133 if ( isset( $_POST['prflxtrflds_front_info'] ) ) {
3134 if ( ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['prflxtrflds_front_info'] ) ), 'prflxtrflds_save_front_info' ) ) {
3135 $error = __( 'Sorry, your nonce did not verify.', 'profile-extra-fields' );
3136 } else {
3137 do_action_ref_array( 'user_profile_update_errors', array( &$errors, true, &$user ) );
3138 if ( ! empty( $errors->errors ) ) {
3139 $error = $errors->get_error_message();
3140 } else {
3141 if ( ! empty( $_POST['prflxtrflds_not_editable'] ) ) {
3142 /** Execute not_editable fields */
3143 $prflxtrflds_not_editable = array_map( 'intval', $_POST['prflxtrflds_not_editable'] );
3144 $not_editable_ids = "'" . implode( "','", $prflxtrflds_not_editable ) . "'";
3145 $wpdb->query(
3146 $wpdb->prepare(
3147 'DELETE FROM `' . $wpdb->base_prefix . 'prflxtrflds_user_field_data`
3148 WHERE `user_id` = %d
3149 AND `field_id` NOT IN (' . $not_editable_ids . ')',
3150 $user_id
3151 )
3152 );
3153 } else {
3154 $wpdb->delete(
3155 $wpdb->base_prefix . 'prflxtrflds_user_field_data',
3156 array( 'user_id' => $user_id )
3157 );
3158 }
3159 if ( isset( $_POST['prflxtrflds_user_field_value'] ) ) {
3160 foreach ( $_POST['prflxtrflds_user_field_value'] as $id => $val ) {
3161 if ( ! empty( $val ) ) {
3162 if ( is_array( $val ) ) {
3163 /** For checkboxes */
3164 foreach ( $val as $user_value ) {
3165 /** Insert or update value */
3166 $wpdb->replace(
3167 $wpdb->base_prefix . 'prflxtrflds_user_field_data',
3168 array(
3169 'user_id' => esc_sql( $user_id ),
3170 'field_id' => esc_sql( absint( $id ) ),
3171 'user_value' => esc_sql( wp_filter_post_kses( wp_unslash( $user_value ) ) ),
3172 )
3173 );
3174 }
3175 $message = __( 'Profile updated', 'profile-extra-fields' );
3176 } else {
3177 $user_value = wp_filter_post_kses( wp_unslash( $val ) );
3178 /** Insert or update value */
3179 $wpdb->replace(
3180 $wpdb->base_prefix . 'prflxtrflds_user_field_data',
3181 array(
3182 'user_id' => esc_sql( $user_id ),
3183 'field_id' => esc_sql( absint( $id ) ),
3184 'user_value' => esc_sql( $user_value ),
3185 )
3186 );
3187 $message = __( 'Profile updated', 'profile-extra-fields' );
3188 }
3189 }
3190 }
3191 }
3192 }
3193 }
3194 }
3195
3196 $plugins_data = apply_filters( 'bws_bkng_prflxtrflds_get_data', $plugins_data = array() );
3197 $enabled_plugins = array_column( $plugins_data, 'slug' );
3198 array_unshift(
3199 $plugins_data,
3200 array(
3201 'name' => 'Profile',
3202 'slug' => $enabled_plugins,
3203 'exclude' => true,
3204 )
3205 );
3206
3207 $hidden_nonvisible_field = '';
3208
3209 ob_start();
3210 ?>
3211 <div class="">
3212 <?php
3213 if ( ! empty( $message ) ) {
3214 echo '<div class="updated notice prflxtrflds-success"><p>' . esc_html( $message ) . '</p></div>';
3215 }
3216 if ( ! empty( $error ) ) {
3217 echo '<div class="error prflxtrflds-error"><p>' . esc_html( $error ) . '</p></div>';
3218 }
3219 ?>
3220 <form action="<?php the_permalink(); ?>" method="post">
3221 <?php
3222 foreach ( $plugins_data as $plugin ) {
3223 $args = array(
3224 'roles' => array( $user_role ),
3225 'show' => $plugin['slug'],
3226 'exclude' => isset( $plugin['exclude'] ) ? $plugin['exclude'] : false,
3227 );
3228 $all_entry = prflxtrflds_get_fields( $args );
3229 $custom_class = 'prflxtrflds_extra_fields_' . sanitize_title( $plugin['name'] );
3230 if ( empty( $all_entry ) ) {
3231 continue;
3232 }
3233 echo '<h3>' . esc_html( $plugin['name'] ) . ' ' . esc_html__( 'Extra Fields', 'profile-extra-fields' ) . '</h3>';
3234 echo '<table>';
3235 foreach ( $all_entry as $one_entry ) {
3236 /** Add field values */
3237 $one_entry['available_fields'] = $wpdb->get_results(
3238 $wpdb->prepare(
3239 'SELECT `value_id`, `value_name`
3240 FROM `' . $wpdb->base_prefix . 'prflxtrflds_field_values`
3241 WHERE `field_id` = %d
3242 ORDER BY `order`',
3243 $one_entry['field_id']
3244 ),
3245 ARRAY_A
3246 );
3247
3248 if ( ! empty( $_POST['prflxtrflds_user_field_value'] ) && isset( $_POST['prflxtrflds_user_fields'] ) && wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['prflxtrflds_user_fields'] ) ), 'prflxtrflds_user_field_action' ) ) {
3249 if ( isset( $_POST['prflxtrflds_user_field_value'][ $one_entry['field_id'] ] ) &&
3250 is_array( $_POST['prflxtrflds_user_field_value'][ $one_entry['field_id'] ] )
3251 ) {
3252 /** For checkboxes */
3253 foreach ( $_POST['prflxtrflds_user_field_value'][ $one_entry['field_id'] ] as $user_value ) {
3254 $one_entry['user_value'][] = sanitize_text_field( wp_unslash( $user_value ) );
3255 }
3256 } else {
3257 $one_entry['user_value'] = isset( $_POST['prflxtrflds_user_field_value'][ $one_entry['field_id'] ] ) ? sanitize_text_field( wp_unslash( $_POST['prflxtrflds_user_field_value'][ $one_entry['field_id'] ] ) ) : '';
3258 }
3259 } else {
3260 /** Add selected values */
3261 if ( '3' === $one_entry['field_type_id'] ) {
3262 $user_value = $wpdb->get_results(
3263 $wpdb->prepare(
3264 'SELECT `user_value` FROM `' . $wpdb->base_prefix . 'prflxtrflds_user_field_data`
3265 WHERE `user_id`= %d AND `field_id` = %d',
3266 $user_id,
3267 $one_entry['field_id']
3268 ),
3269 ARRAY_A
3270 );
3271
3272 if ( ! empty( $user_value ) ) {
3273 foreach ( $user_value as $key_value => $value_single ) {
3274 $one_entry['user_value'][] = $value_single['user_value'];
3275 }
3276 } else {
3277 $one_entry['user_value'] = array();
3278 }
3279 } else {
3280 $one_entry['user_value'] = $wpdb->get_var(
3281 $wpdb->prepare(
3282 'SELECT `user_value` FROM `' . $wpdb->base_prefix . 'prflxtrflds_user_field_data`
3283 WHERE `user_id`= %s AND `field_id` = %s',
3284 $user_id,
3285 $one_entry['field_id']
3286 )
3287 );
3288 }
3289 }
3290
3291 /** Change `editable` and `visible` data for non-current user editing */
3292 $editable_visible = $wpdb->get_row(
3293 $wpdb->prepare(
3294 'SELECT
3295 `' . $wpdb->base_prefix . 'prflxtrflds_roles_and_fields`.`editable`,
3296 `' . $wpdb->base_prefix . 'prflxtrflds_roles_and_fields`.`visible`
3297 FROM
3298 `' . $wpdb->base_prefix . 'prflxtrflds_fields_id`,
3299 `' . $wpdb->base_prefix . 'prflxtrflds_roles_and_fields`,
3300 `' . $wpdb->base_prefix . 'prflxtrflds_roles_id`
3301 WHERE
3302 `' . $wpdb->base_prefix . 'prflxtrflds_roles_and_fields`.`role_id`= `' . $wpdb->base_prefix . 'prflxtrflds_roles_id`.`role_id`
3303 AND `' . $wpdb->base_prefix . 'prflxtrflds_roles_and_fields`.`field_id`=`' . $wpdb->base_prefix . 'prflxtrflds_fields_id`.`field_id`
3304 AND `' . $wpdb->base_prefix . 'prflxtrflds_roles_and_fields`.`field_id`= %d
3305 AND `' . $wpdb->base_prefix . "prflxtrflds_roles_id`.`role` IN ( '" . $user_role . "' )",
3306 $one_entry['field_id']
3307 ),
3308 ARRAY_A
3309 );
3310
3311 $one_entry['editable'] = $editable_visible['editable'];
3312 $one_entry['visible'] = $editable_visible['visible'];
3313 if ( '0' === $one_entry['editable'] ) {
3314 $editable_attr = ' readonly="readonly" disabled="disabled"';
3315 $hidden_noneditable_field = '<input type="hidden" name="prflxtrflds_not_editable[]" value="' . $one_entry['field_id'] . '" />';
3316 } else {
3317 $editable_attr = '';
3318 $hidden_noneditable_field = '';
3319 }
3320
3321 $required_attr = ( ! empty( $one_entry['required'] ) && ! empty( $one_entry['editable'] ) ) ? ' required="required"' : '';
3322 if ( '1' === $one_entry['visible'] ) {
3323 ?>
3324 <tr>
3325 <th>
3326 <?php
3327 echo esc_html( $one_entry['field_name'] );
3328 if ( ! empty( $one_entry['required'] ) ) {
3329 ?>
3330 <span class="description"><?php echo esc_attr( $one_entry['required'] ); ?></span>
3331 <?php
3332 if ( '1' === $one_entry['editable'] ) {
3333 ?>
3334 <input type="hidden"
3335 name="prflxtrflds_required[<?php echo esc_attr( $one_entry['field_id'] ); ?>]"
3336 value="true"/>
3337 <?php
3338 }
3339 }
3340 ?>
3341 <input type="hidden"
3342 name="prflxtrflds_field_name[<?php echo esc_attr( $one_entry['field_id'] ); ?>]"
3343 value="<?php echo esc_attr( $one_entry['field_name'] ); ?>">
3344 </th>
3345 <td>
3346 <?php
3347 switch ( $one_entry['field_type_id'] ) {
3348 case '1':
3349 ?>
3350 <input type="text"
3351 id="prflxtrflds_user_field_value[<?php echo esc_attr( $one_entry['field_id'] ); ?>]"
3352 name="prflxtrflds_user_field_value[<?php echo esc_attr( $one_entry['field_id'] ); ?>]"
3353 value="<?php
3354 if ( isset( $one_entry['user_value'] ) ) {
3355 echo esc_attr( wp_unslash( $one_entry['user_value'] ) );
3356 }
3357 ?>"
3358 <?php
3359 if ( isset( $one_entry['available_fields'][0]['value_name'] ) ) {
3360 echo 'maxlength="' . esc_attr( $one_entry['available_fields'][0]['value_name'] ) . '"';
3361 }
3362 echo wp_kses_data( $editable_attr ) . wp_kses_data( $required_attr );
3363 ?>
3364 />
3365 <?php
3366 break;
3367 case '2':
3368 $unser_textarea = maybe_unserialize( $one_entry['available_fields'][0]['value_name'] );
3369 ?>
3370 <textarea
3371 id="prflxtrflds_user_field_value[<?php echo esc_attr( $one_entry['field_id'] ); ?>]"
3372 name="prflxtrflds_user_field_value[<?php echo esc_attr( $one_entry['field_id'] ); ?>]"
3373 rows="<?php echo esc_attr( $unser_textarea['rows'] ); ?>" cols="<?php echo esc_attr( $unser_textarea['cols'] ); ?>" maxlength="<?php echo esc_attr( $unser_textarea['max_length'] ); ?>"
3374 <?php echo wp_kses_data( $editable_attr ) . wp_kses_data( $required_attr ); ?>><?php echo esc_attr( wp_unslash( $one_entry['user_value'] ) ); ?></textarea>
3375 <?php
3376 break;
3377 case '3':
3378 foreach ( $one_entry['available_fields'] as $one_sub_entry ) {
3379 $checked = ( ! empty( $one_entry['user_value'] ) && in_array( $one_sub_entry['value_id'], $one_entry['user_value'] ) );
3380 ?>
3381 <label class="prflxtrflds-field
3382 <?php
3383 if ( $checked ) {
3384 echo wp_kses_data( 'checked' );
3385 }
3386 ?>
3387 ">
3388 <input type="checkbox" class="prflxtrflds_input_checkbox"
3389 name="prflxtrflds_user_field_value[<?php echo esc_attr( $one_entry['field_id'] ); ?>][]"
3390 value="<?php echo esc_attr( $one_sub_entry['value_id'] ); ?>"
3391 <?php
3392 if ( $checked ) {
3393 echo esc_attr( ' checked' );
3394 }
3395 echo wp_kses_data( $editable_attr );
3396 ?>
3397 />
3398 <?php echo esc_attr( $one_sub_entry['value_name'] ); ?>
3399 </label>
3400 <br/>
3401 <?php
3402 }
3403 break;
3404 case '4':
3405 foreach ( $one_entry['available_fields'] as $one_sub_entry ) {
3406 ?>
3407 <label class="prflxtrflds-field">
3408 <input type="radio" class="prflxtrflds_input_radio"
3409 name="prflxtrflds_user_field_value[<?php echo esc_attr( $one_entry['field_id'] ); ?>]"
3410 value="<?php echo esc_attr( $one_sub_entry['value_id'] ); ?>"
3411 <?php
3412 if ( isset( $one_entry['user_value'] ) && $one_sub_entry['value_id'] === $one_entry['user_value'] ) {
3413 echo esc_attr( ' checked' );
3414 }
3415 echo wp_kses_data( $editable_attr ) . wp_kses_data( $required_attr );
3416 ?>
3417 />
3418 <?php echo esc_attr( $one_sub_entry['value_name'] ); ?>
3419 </label>
3420 <br/>
3421 <?php
3422 }
3423 break;
3424 case '5':
3425 ?>
3426 <select
3427 id="prflxtrflds_user_field_value[<?php echo esc_attr( $one_entry['field_id'] ); ?>]"
3428 name="prflxtrflds_user_field_value[<?php echo esc_attr( $one_entry['field_id'] ); ?>]" <?php echo wp_kses_data( $editable_attr ) . wp_kses_data( $required_attr ); ?>>
3429 <option></option>
3430 <?php
3431 foreach ( $one_entry['available_fields'] as $one_sub_entry ) {
3432 ?>
3433 <option
3434 value="<?php echo esc_attr( $one_sub_entry['value_id'] ); ?>"
3435 <?php
3436 if ( isset( $one_entry['user_value'] ) && $one_sub_entry['value_id'] === $one_entry['user_value'] ) {
3437 echo ' selected';}
3438 ?>
3439 ><?php echo esc_attr( $one_sub_entry['value_name'] ); ?></option>
3440 <?php
3441 }
3442 ?>
3443 </select>
3444 <?php
3445 break;
3446 case '6':
3447 ?>
3448 <input class="prflxtrflds_datetimepicker" type="text"
3449 id="prflxtrflds_user_field_value[<?php echo esc_attr( $one_entry['field_id'] ); ?>]"
3450 name="prflxtrflds_user_field_value[<?php echo esc_attr( $one_entry['field_id'] ); ?>]"
3451 value="<?php
3452 if ( isset( $one_entry['user_value'] ) ) {
3453 echo esc_attr( $one_entry['user_value'] );}
3454 ?>"
3455 <?php echo wp_kses_data( $editable_attr ) . wp_kses_data( $required_attr ); ?>>
3456 <?php
3457 if ( isset( $one_entry['available_fields'][0] ) && strripos( $one_entry['available_fields'][0]['value_name'], 'T' ) ) {
3458 echo esc_attr( date_i18n( 'T' ) );
3459 }
3460 ?>
3461 <input type="hidden" name="prflxtrflds_date_format"
3462 value="<?php echo esc_attr( trim( str_replace( 'T', '', $one_entry['available_fields'][0]['value_name'] ) ) ); ?>">
3463 <input type="hidden"
3464 name="prflxtrflds_user_field_datetime[<?php echo esc_attr( $one_entry['field_id'] ); ?>]"
3465 value="<?php echo esc_attr( $one_entry['available_fields'][0]['value_name'] ); ?>">
3466 <?php
3467 break;
3468 case '7':
3469 ?>
3470 <input class="prflxtrflds_datetimepicker" type="text"
3471 id="prflxtrflds_user_field_value[<?php echo esc_attr( $one_entry['field_id'] ); ?>]"
3472 name="prflxtrflds_user_field_value[<?php echo esc_attr( $one_entry['field_id'] ); ?>]"
3473 value="<?php
3474 if ( isset( $one_entry['user_value'] ) ) {
3475 echo esc_attr( $one_entry['user_value'] );
3476 }
3477 ?>"
3478 <?php echo wp_kses_data( $editable_attr ) . wp_kses_data( $required_attr ); ?>>
3479 <?php
3480 if ( isset( $one_entry['available_fields'][0] ) && strripos( $one_entry['available_fields'][0]['value_name'], 'T' ) ) {
3481 echo esc_attr( date_i18n( 'T' ) );
3482 }
3483 ?>
3484 <input type="hidden" name="prflxtrflds_time_format"
3485 value="<?php echo esc_attr( trim( str_replace( 'T', '', $one_entry['available_fields'][0]['value_name'] ) ) ); ?>">
3486 <input type="hidden"
3487 name="prflxtrflds_user_field_datetime[<?php echo esc_attr( $one_entry['field_id'] ); ?>]"
3488 value="<?php echo esc_attr( $one_entry['available_fields'][0]['value_name'] ); ?>">
3489 <?php
3490 break;
3491 case '8':
3492 $date_and_time = unserialize( $one_entry['available_fields'][0]['value_name'] );
3493 ?>
3494 <input class="prflxtrflds_datetimepicker" type="text"
3495 id="prflxtrflds_user_field_value[<?php echo esc_attr( $one_entry['field_id'] ); ?>]"
3496 name="prflxtrflds_user_field_value[<?php echo esc_attr( $one_entry['field_id'] ); ?>]"
3497 value="<?php
3498 if ( isset( $one_entry['user_value'] ) ) {
3499 echo esc_attr( $one_entry['user_value'] );
3500 }
3501 ?>"
3502 <?php echo wp_kses_data( $editable_attr ) . wp_kses_data( $required_attr ); ?>>
3503 <?php
3504 if ( strripos( $date_and_time['time'], 'T' ) || strripos( $date_and_time['date'], 'T' ) ) {
3505 echo esc_attr( date_i18n( 'T' ) );
3506 }
3507 ?>
3508 <input type="hidden" name="prflxtrflds_time_format"
3509 value="<?php echo esc_attr( trim( str_replace( 'T', '', $date_and_time['time'] ) ) ); ?>">
3510 <input type="hidden" name="prflxtrflds_date_format"
3511 value="<?php echo esc_attr( trim( str_replace( 'T', '', $date_and_time['date'] ) ) ); ?>">
3512 <input type="hidden"
3513 name="prflxtrflds_user_field_datetime[<?php echo esc_attr( $one_entry['field_id'] ); ?>]"
3514 value="<?php echo esc_attr( $date_and_time['date'] ) . ' ' . esc_attr( $date_and_time['time'] ); ?>">
3515 <?php
3516 break;
3517 case '9':
3518 ?>
3519 <input type="number" class="prflxtrflds_number"
3520 id="prflxtrflds_user_field_value[<?php echo esc_attr( $one_entry['field_id'] ); ?>]"
3521 name="prflxtrflds_user_field_value[<?php echo esc_attr( $one_entry['field_id'] ); ?>]"
3522 value="<?php
3523 if ( isset( $one_entry['user_value'] ) ) {
3524 echo esc_attr( $one_entry['user_value'] );
3525 }
3526 ?>"
3527 <?php
3528 if ( isset( $one_entry['available_fields'][0]['value_name'] ) ) {
3529 echo 'max="' . esc_attr( $one_entry['available_fields'][0]['value_name'] ) . '"';}
3530 echo wp_kses_data( $editable_attr ) . wp_kses_data( $required_attr );
3531 ?>
3532 />
3533 <?php if ( isset( $one_entry['available_fields'][0]['value_name'] ) ) { ?>
3534 <input type="hidden"
3535 name="prflxtrflds_user_field_max_number[<?php echo esc_attr( $one_entry['field_id'] ); ?>]"
3536 value="<?php echo esc_attr( $one_entry['available_fields'][0]['value_name'] ); ?>">
3537 <?php
3538 }
3539 break;
3540 case '10':
3541 ?>
3542 <input type="text" class="prflxtrflds_phone"
3543 id="prflxtrflds_user_field_value[<?php echo esc_attr( $one_entry['field_id'] ); ?>]"
3544 name="prflxtrflds_user_field_value[<?php echo esc_attr( $one_entry['field_id'] ); ?>]"
3545 value="<?php
3546 if ( isset( $one_entry['user_value'] ) ) {
3547 echo esc_attr( wp_unslash( $one_entry['user_value'] ) );
3548 }
3549 ?>" <?php echo wp_kses_data( $editable_attr ) . wp_kses_data( $required_attr ); ?> >
3550 <input type="hidden"
3551 name="prflxtrflds_user_field_pattern[<?php echo esc_attr( $one_entry['field_id'] ); ?>]"
3552 value="<?php echo esc_attr( $one_entry['available_fields'][0]['value_name'] ); ?>">
3553 <?php
3554 break;
3555
3556 case '11':
3557 ?>
3558 <input type="url" class="prflxtrflds_url"
3559 id="prflxtrflds_user_field_value[<?php echo esc_attr( $one_entry['field_id'] ); ?>]"
3560 name="prflxtrflds_user_field_value[<?php echo esc_attr( $one_entry['field_id'] ); ?>]"
3561 value="<?php
3562 if ( isset( $one_entry['user_value'] ) ) {
3563 echo esc_attr( wp_unslash( $one_entry['user_value'] ) );
3564 }
3565 ?>"
3566 <?php
3567 if ( isset( $one_entry['available_fields'][0]['value_name'] ) ) {
3568 echo 'maxlength="' . esc_attr( $one_entry['available_fields'][0]['value_name'] ) . '"';}
3569 echo wp_kses_data( $editable_attr ) . wp_kses_data( $required_attr );
3570 ?>
3571 />
3572 <?php
3573 break;
3574 case '13':
3575 $countries = prflxtrflds_get_country();
3576 ?>
3577 <select id="prflxtrflds_user_field_value[<?php echo esc_attr( $one_entry['field_id'] ); ?>]" name="prflxtrflds_user_field_value[<?php echo esc_attr( $one_entry['field_id'] ); ?>]" <?php echo wp_kses_data( $editable_attr ) . wp_kses_data( $required_attr ); ?>>
3578 <?php
3579 foreach ( $countries as $country_id => $country_name ) {
3580 ?>
3581 <option value="<?php echo esc_attr( $country_id ); ?>" <?php selected( $one_entry['user_value'], $country_id ); ?>><?php echo esc_html( $country_name ); ?></option>
3582 <?php
3583 }
3584 ?>
3585 </select>
3586 <?php
3587 break;
3588 }
3589 echo wp_kses_data( $hidden_noneditable_field );
3590 if ( isset( $one_entry['description'] ) ) {
3591 ?>
3592 <p class="description"><?php echo esc_html( $one_entry['description'] ); ?></p>
3593 <?php } ?>
3594 </td>
3595 </tr>
3596 <?php
3597 } else {
3598 $hidden_nonvisible_field .= $hidden_noneditable_field;
3599 }
3600 }
3601 echo '</table>';
3602 echo wp_kses_data( $hidden_nonvisible_field );
3603 $prflxtrflds_front_shortcode = true;
3604
3605 }
3606 ?>
3607 <p>
3608 <input type="submit" value="<?php esc_html_e( 'Save Info', 'profile-extra-fields' ); ?>" />
3609 <?php wp_nonce_field( 'prflxtrflds_save_front_info', 'prflxtrflds_front_info' ); ?>
3610 </p>
3611 </form>
3612 </div>
3613 <?php
3614 $prflxtrflds_shortcode_output = ob_get_contents();
3615 ob_end_clean();
3616 if ( ! empty( $prflxtrflds_shortcode_output ) ) {
3617 return $prflxtrflds_shortcode_output;
3618 }
3619 }
3620 }
3621 }
3622
3623 if ( ! function_exists( 'prflxtrflds_fields_table' ) ) {
3624 /**
3625 * Show info in user profile page
3626 *
3627 * @param mixed $profileuser User object.
3628 */
3629 function prflxtrflds_fields_table( $profileuser = false ) {
3630 global $wpdb, $hook_suffix, $pagenow, $prflxtrflds_options;
3631 if ( ! isset( $prflxtrflds_options ) ) {
3632 prflxtrflds_settings();
3633 }
3634 if ( 'user-new.php' === $pagenow || 'user-edit.php' === $pagenow ) {
3635 $user_id = get_current_user_id();
3636 $user_info = get_userdata( $user_id );
3637 $user_role = isset( $user_info->roles ) ? implode( "', '", $user_info->roles ) : get_option( 'default_role' );
3638 if ( ! empty( $profileuser ) && is_object( $profileuser ) && isset( $profileuser->ID ) && $profileuser->ID !== $user_id ) {
3639 $user_id = $profileuser->ID;
3640 }
3641 } else {
3642 $user_id = isset( $profileuser->ID ) ? $profileuser->ID : get_current_user_id();
3643 $user_info = get_userdata( $user_id );
3644 $user_role = isset( $user_info->roles ) ? implode( "', '", $user_info->roles ) : get_option( 'default_role' );
3645 }
3646
3647 $plugins_data = apply_filters( 'bws_bkng_prflxtrflds_get_data', $plugins_data = array() );
3648
3649 preg_match( '/bws_bkng_(.*?)_(.*?)$/', current_filter(), $matches );
3650
3651 if ( empty( $matches ) ) {
3652 $enabled_plugins = array_column( $plugins_data, 'slug' );
3653 array_unshift(
3654 $plugins_data,
3655 array(
3656 'name' => 'Profile',
3657 'slug' => $enabled_plugins,
3658 'exclude' => true,
3659 )
3660 );
3661 } elseif ( ! empty( $matches[1] ) ) {
3662 $key = array_search( $matches[2], array_column( $plugins_data, 'slug' ) );
3663 $plugins_data = array_values( $plugins_data );
3664 $plugins_data = array( $plugins_data[ $key ] );
3665 $show_in = $matches[2];
3666 $certain_page = $matches[1];
3667 }
3668 prflxtrflds_enqueue_fields_styles();
3669
3670 $hidden_nonvisible_field = '';
3671
3672 foreach ( $plugins_data as $plugin ) {
3673 $args = array(
3674 'roles' => array( $user_role ),
3675 'show' => $plugin['slug'],
3676 'exclude' => isset( $plugin['exclude'] ) ? $plugin['exclude'] : false,
3677 );
3678 $all_entry = prflxtrflds_get_fields( $args );
3679 $custom_class = 'prflxtrflds_extra_fields_' . sanitize_title( $plugin['name'] );
3680
3681 if ( ! empty( $certain_page ) ) {
3682 foreach ( $all_entry as $key => $one_entry ) {
3683 $one_entry['certain_pages'] = maybe_unserialize(
3684 $wpdb->get_var(
3685 $wpdb->prepare(
3686 'SELECT `value`
3687 FROM `' . $wpdb->base_prefix . 'prflxtrflds_fields_meta`
3688 WHERE `field_id` = %d AND `show_in` = %s',
3689 $one_entry['field_id'],
3690 $show_in
3691 )
3692 )
3693 );
3694 if ( ! is_array( $one_entry['certain_pages'] ) || ! array_key_exists( $certain_page, $one_entry['certain_pages'] ) ) {
3695 unset( $all_entry[ $key ] );
3696 }
3697 }
3698 }
3699
3700 if ( empty( $all_entry ) ) {
3701 continue;
3702 }
3703 $title = '';
3704 switch ( $plugin['name'] ) {
3705 case 'Profile':
3706 $title = isset( $prflxtrflds_options['user_section_profile_title'] ) ? $prflxtrflds_options['user_section_profile_title'] : sprintf( esc_html__( '%1$s Extra Fields', 'profile-extra-fields' ), esc_html( $plugin['name'] ) );
3707 break;
3708 case 'Car Rental V2':
3709 $title = isset( $prflxtrflds_options['user_section_car_title'] ) ? $prflxtrflds_options['user_section_car_title'] : sprintf( esc_html__( '%1$s Extra Fields', 'profile-extra-fields' ), esc_html( $plugin['name'] ) );
3710 break;
3711 default:
3712 $title = sprintf( esc_html__( '%1$s Extra Fields', 'profile-extra-fields' ), esc_html( $plugin['name'] ) );
3713 break;
3714 }
3715
3716 ?>
3717 <h2 class="<?php echo esc_attr( $custom_class ); ?>"><?php echo esc_html( $title ); ?></h2>
3718 <table class="form-table <?php echo esc_attr( $custom_class ); ?>">
3719 <?php wp_nonce_field( 'prflxtrflds_user_field_action', 'prflxtrflds_user_fields' ); ?>
3720 <?php
3721 /** Group result array by field_id */
3722 foreach ( $all_entry as $one_entry ) {
3723 /** Add field values */
3724 $one_entry['available_fields'] = $wpdb->get_results(
3725 $wpdb->prepare(
3726 'SELECT `value_id`, `value_name`
3727 FROM `' . $wpdb->base_prefix . 'prflxtrflds_field_values`
3728 WHERE `field_id` = %d
3729 ORDER BY `order`',
3730 $one_entry['field_id']
3731 ),
3732 ARRAY_A
3733 );
3734
3735 if ( ! empty( $_POST['prflxtrflds_user_field_value'] ) && isset( $_POST['prflxtrflds_user_fields'] ) && wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['prflxtrflds_user_fields'] ) ), 'prflxtrflds_user_field_action' ) ) {
3736 if ( isset( $_POST['prflxtrflds_user_field_value'][ $one_entry['field_id'] ] ) &&
3737 is_array( $_POST['prflxtrflds_user_field_value'][ $one_entry['field_id'] ] )
3738 ) {
3739 /** For checkboxes */
3740 foreach ( $_POST['prflxtrflds_user_field_value'][ $one_entry['field_id'] ] as $user_value ) {
3741 $one_entry['user_value'][] = sanitize_text_field( wp_unslash( $user_value ) );
3742 }
3743 } else {
3744 $one_entry['user_value'] = isset( $_POST['prflxtrflds_user_field_value'][ $one_entry['field_id'] ] ) ? sanitize_text_field( wp_unslash( $_POST['prflxtrflds_user_field_value'][ $one_entry['field_id'] ] ) ) : '';
3745 }
3746 } else {
3747 /** Add selected values */
3748 if ( 'user-new.php' === $pagenow ) {
3749 if ( '3' === $one_entry['field_type_id'] ) {
3750 $one_entry['user_value'] = array();
3751 } else {
3752 $one_entry['user_value'] = '';
3753 }
3754 } else {
3755 if ( '3' === $one_entry['field_type_id'] ) {
3756 $user_value = $wpdb->get_results(
3757 $wpdb->prepare(
3758 'SELECT `user_value` FROM `' . $wpdb->base_prefix . 'prflxtrflds_user_field_data`
3759 WHERE `user_id`= %d AND `field_id` = %d',
3760 $user_id,
3761 $one_entry['field_id']
3762 ),
3763 ARRAY_A
3764 );
3765
3766 if ( ! empty( $user_value ) ) {
3767 foreach ( $user_value as $key_value => $value_single ) {
3768 $one_entry['user_value'][] = $value_single['user_value'];
3769 }
3770 } else {
3771 $one_entry['user_value'] = array();
3772 }
3773 } else {
3774 $one_entry['user_value'] = $wpdb->get_var(
3775 $wpdb->prepare(
3776 'SELECT `user_value` FROM `' . $wpdb->base_prefix . 'prflxtrflds_user_field_data`
3777 WHERE `user_id`= %s AND `field_id` = %s',
3778 $user_id,
3779 $one_entry['field_id']
3780 )
3781 );
3782 }
3783 }
3784 }
3785 if ( 'profile.php' !== $hook_suffix ) {
3786 /** Change `editable` and `visible` data for non-current user editing */
3787 $editable_visible = $wpdb->get_row(
3788 $wpdb->prepare(
3789 'SELECT
3790 `' . $wpdb->base_prefix . 'prflxtrflds_roles_and_fields`.`editable`,
3791 `' . $wpdb->base_prefix . 'prflxtrflds_roles_and_fields`.`visible`
3792 FROM
3793 `' . $wpdb->base_prefix . 'prflxtrflds_fields_id`,
3794 `' . $wpdb->base_prefix . 'prflxtrflds_roles_and_fields`,
3795 `' . $wpdb->base_prefix . 'prflxtrflds_roles_id`
3796 WHERE
3797 `' . $wpdb->base_prefix . 'prflxtrflds_roles_and_fields`.`role_id`= `' . $wpdb->base_prefix . 'prflxtrflds_roles_id`.`role_id`
3798 AND `' . $wpdb->base_prefix . 'prflxtrflds_roles_and_fields`.`field_id`=`' . $wpdb->base_prefix . 'prflxtrflds_fields_id`.`field_id`
3799 AND `' . $wpdb->base_prefix . 'prflxtrflds_roles_and_fields`.`field_id`= %d
3800 AND `' . $wpdb->base_prefix . "prflxtrflds_roles_id`.`role` IN ( '" . $user_role . "' )",
3801 $one_entry['field_id']
3802 ),
3803 ARRAY_A
3804 );
3805
3806 $one_entry['editable'] = $editable_visible['editable'];
3807 $one_entry['visible'] = $editable_visible['visible'];
3808 }
3809 if ( '0' === $one_entry['editable'] && ( 'profile.php' !== $hook_suffix || ! current_user_can( 'edit_users' ) ) ) {
3810 $editable_attr = ' readonly="readonly" disabled="disabled"';
3811 $hidden_noneditable_field = '<input type="hidden" name="prflxtrflds_not_editable[]" value="' . $one_entry['field_id'] . '" />';
3812 } else {
3813 $editable_attr = '';
3814 $hidden_noneditable_field = '';
3815 }
3816
3817 $required_attr = ( ! empty( $one_entry['required'] ) && ! empty( $one_entry['editable'] ) ) ? ' required="required"' : '';
3818
3819 if ( '1' === $one_entry['visible'] && ( 'profile.php' === $hook_suffix || current_user_can( 'edit_users' ) ) ) {
3820 ?>
3821 <tr>
3822 <th>
3823 <?php
3824 echo esc_html( $one_entry['field_name'] );
3825 if ( ! empty( $one_entry['required'] ) ) {
3826 ?>
3827 <span class="description"><?php echo esc_attr( $one_entry['required'] ); ?></span>
3828 <?php
3829 if ( '1' === $one_entry['editable'] ) {
3830 ?>
3831 <input type="hidden"
3832 name="prflxtrflds_required[<?php echo esc_attr( $one_entry['field_id'] ); ?>]"
3833 value="true"/>
3834 <?php
3835 }
3836 }
3837 ?>
3838 <input type="hidden"
3839 name="prflxtrflds_field_name[<?php echo esc_attr( $one_entry['field_id'] ); ?>]"
3840 value="<?php echo esc_attr( $one_entry['field_name'] ); ?>">
3841 </th>
3842 <td>
3843 <?php
3844 switch ( $one_entry['field_type_id'] ) {
3845 case '1':
3846 ?>
3847 <input type="text"
3848 id="prflxtrflds_user_field_value[<?php echo esc_attr( $one_entry['field_id'] ); ?>]"
3849 name="prflxtrflds_user_field_value[<?php echo esc_attr( $one_entry['field_id'] ); ?>]"
3850 value="<?php
3851 if ( isset( $one_entry['user_value'] ) ) {
3852 echo esc_attr( wp_unslash( $one_entry['user_value'] ) );
3853 }
3854 ?>"
3855 <?php
3856 if ( isset( $one_entry['available_fields'][0]['value_name'] ) ) {
3857 echo 'maxlength="' . esc_attr( $one_entry['available_fields'][0]['value_name'] ) . '"';
3858 }
3859 echo wp_kses_data( $editable_attr ) . wp_kses_data( $required_attr );
3860 ?>
3861 />
3862 <?php
3863 break;
3864 case '2':
3865 $unser_textarea = maybe_unserialize( $one_entry['available_fields'][0]['value_name'] );
3866 ?>
3867 <textarea
3868 id="prflxtrflds_user_field_value[<?php echo esc_attr( $one_entry['field_id'] ); ?>]"
3869 name="prflxtrflds_user_field_value[<?php echo esc_attr( $one_entry['field_id'] ); ?>]"
3870 rows="<?php echo esc_attr( $unser_textarea['rows'] ); ?>" cols="<?php echo esc_attr( $unser_textarea['cols'] ); ?>" maxlength="<?php echo esc_attr( $unser_textarea['max_length'] ); ?>"
3871 <?php echo wp_kses_data( $editable_attr ) . wp_kses_data( $required_attr ); ?>><?php echo esc_attr( wp_unslash( $one_entry['user_value'] ) ); ?></textarea>
3872 <?php
3873 break;
3874 case '3':
3875 foreach ( $one_entry['available_fields'] as $one_sub_entry ) {
3876 $checked = ( ! empty( $one_entry['user_value'] ) && in_array( $one_sub_entry['value_id'], $one_entry['user_value'] ) );
3877 ?>
3878 <label class="prflxtrflds-field
3879 <?php
3880 if ( $checked ) {
3881 echo wp_kses_data( 'checked' );
3882 }
3883 ?>
3884 ">
3885 <input type="checkbox" class="prflxtrflds_input_checkbox"
3886 name="prflxtrflds_user_field_value[<?php echo esc_attr( $one_entry['field_id'] ); ?>][]"
3887 value="<?php echo esc_attr( $one_sub_entry['value_id'] ); ?>"
3888 <?php
3889 if ( $checked ) {
3890 echo esc_attr( ' checked' );
3891 }
3892 echo wp_kses_data( $editable_attr );
3893 ?>
3894 />
3895 <?php echo esc_attr( $one_sub_entry['value_name'] ); ?>
3896 </label>
3897 <br/>
3898 <?php
3899 }
3900 break;
3901 case '4':
3902 foreach ( $one_entry['available_fields'] as $one_sub_entry ) {
3903 ?>
3904 <label class="prflxtrflds-field">
3905 <input type="radio" class="prflxtrflds_input_radio"
3906 name="prflxtrflds_user_field_value[<?php echo esc_attr( $one_entry['field_id'] ); ?>]"
3907 value="<?php echo esc_attr( $one_sub_entry['value_id'] ); ?>"
3908 <?php
3909 if ( isset( $one_entry['user_value'] ) && $one_sub_entry['value_id'] === $one_entry['user_value'] ) {
3910 echo esc_attr( ' checked' );
3911 }
3912 echo wp_kses_data( $editable_attr ) . wp_kses_data( $required_attr );
3913 ?>
3914 />
3915 <?php echo esc_attr( $one_sub_entry['value_name'] ); ?>
3916 </label>
3917 <br/>
3918 <?php
3919 }
3920 break;
3921 case '5':
3922 ?>
3923 <select
3924 id="prflxtrflds_user_field_value[<?php echo esc_attr( $one_entry['field_id'] ); ?>]"
3925 name="prflxtrflds_user_field_value[<?php echo esc_attr( $one_entry['field_id'] ); ?>]" <?php echo wp_kses_data( $editable_attr ) . wp_kses_data( $required_attr ); ?>>
3926 <option></option>
3927 <?php foreach ( $one_entry['available_fields'] as $one_sub_entry ) { ?>
3928 <option
3929 value="<?php echo esc_attr( $one_sub_entry['value_id'] ); ?>"
3930 <?php
3931 if ( isset( $one_entry['user_value'] ) && $one_sub_entry['value_id'] === $one_entry['user_value'] ) {
3932 echo ' selected';}
3933 ?>
3934 ><?php echo esc_attr( $one_sub_entry['value_name'] ); ?></option>
3935 <?php } ?>
3936 </select>
3937 <?php
3938 break;
3939 case '6':
3940 ?>
3941 <input class="prflxtrflds_datetimepicker" type="text"
3942 id="prflxtrflds_user_field_value[<?php echo esc_attr( $one_entry['field_id'] ); ?>]"
3943 name="prflxtrflds_user_field_value[<?php echo esc_attr( $one_entry['field_id'] ); ?>]"
3944 value="<?php
3945 if ( isset( $one_entry['user_value'] ) ) {
3946 echo esc_attr( $one_entry['user_value'] );
3947 }
3948 ?>"
3949 <?php echo wp_kses_data( $editable_attr ) . wp_kses_data( $required_attr ); ?>>
3950 <?php
3951 if ( isset( $one_entry['available_fields'][0] ) && strripos( $one_entry['available_fields'][0]['value_name'], 'T' ) ) {
3952 echo esc_attr( date_i18n( 'T' ) );
3953 }
3954 ?>
3955 <input type="hidden" name="prflxtrflds_date_format"
3956 value="<?php echo esc_attr( trim( str_replace( 'T', '', $one_entry['available_fields'][0]['value_name'] ) ) ); ?>">
3957 <input type="hidden"
3958 name="prflxtrflds_user_field_datetime[<?php echo esc_attr( $one_entry['field_id'] ); ?>]"
3959 value="<?php echo esc_attr( $one_entry['available_fields'][0]['value_name'] ); ?>">
3960 <?php
3961 break;
3962 case '7':
3963 ?>
3964 <input class="prflxtrflds_datetimepicker" type="text"
3965 id="prflxtrflds_user_field_value[<?php echo esc_attr( $one_entry['field_id'] ); ?>]"
3966 name="prflxtrflds_user_field_value[<?php echo esc_attr( $one_entry['field_id'] ); ?>]"
3967 value="<?php
3968 if ( isset( $one_entry['user_value'] ) ) {
3969 echo esc_attr( $one_entry['user_value'] );
3970 }
3971 ?>"
3972 <?php echo wp_kses_data( $editable_attr ) . wp_kses_data( $required_attr ); ?>>
3973 <?php
3974 if ( isset( $one_entry['available_fields'][0] ) && strripos( $one_entry['available_fields'][0]['value_name'], 'T' ) ) {
3975 echo esc_attr( date_i18n( 'T' ) );
3976 }
3977 ?>
3978 <input type="hidden" name="prflxtrflds_time_format"
3979 value="<?php echo esc_attr( trim( str_replace( 'T', '', $one_entry['available_fields'][0]['value_name'] ) ) ); ?>">
3980 <input type="hidden"
3981 name="prflxtrflds_user_field_datetime[<?php echo esc_attr( $one_entry['field_id'] ); ?>]"
3982 value="<?php echo esc_attr( $one_entry['available_fields'][0]['value_name'] ); ?>">
3983 <?php
3984 break;
3985 case '8':
3986 $date_and_time = unserialize( $one_entry['available_fields'][0]['value_name'] );
3987 ?>
3988 <input class="prflxtrflds_datetimepicker" type="text"
3989 id="prflxtrflds_user_field_value[<?php echo esc_attr( $one_entry['field_id'] ); ?>]"
3990 name="prflxtrflds_user_field_value[<?php echo esc_attr( $one_entry['field_id'] ); ?>]"
3991 value="<?php
3992 if ( isset( $one_entry['user_value'] ) ) {
3993 echo esc_attr( $one_entry['user_value'] );}
3994 ?>"
3995 <?php echo wp_kses_data( $editable_attr ) . wp_kses_data( $required_attr ); ?>>
3996 <?php
3997 if ( strripos( $date_and_time['time'], 'T' ) || strripos( $date_and_time['date'], 'T' ) ) {
3998 echo esc_attr( date_i18n( 'T' ) );
3999 }
4000 ?>
4001 <input type="hidden" name="prflxtrflds_time_format"
4002 value="<?php echo esc_attr( trim( str_replace( 'T', '', $date_and_time['time'] ) ) ); ?>">
4003 <input type="hidden" name="prflxtrflds_date_format"
4004 value="<?php echo esc_attr( trim( str_replace( 'T', '', $date_and_time['date'] ) ) ); ?>">
4005 <input type="hidden"
4006 name="prflxtrflds_user_field_datetime[<?php echo esc_attr( $one_entry['field_id'] ); ?>]"
4007 value="<?php echo esc_attr( $date_and_time['date'] ) . ' ' . esc_attr( $date_and_time['time'] ); ?>">
4008 <?php
4009 break;
4010 case '9':
4011 ?>
4012 <input type="number" class="prflxtrflds_number"
4013 id="prflxtrflds_user_field_value[<?php echo esc_attr( $one_entry['field_id'] ); ?>]"
4014 name="prflxtrflds_user_field_value[<?php echo esc_attr( $one_entry['field_id'] ); ?>]"
4015 value="<?php
4016 if ( isset( $one_entry['user_value'] ) ) {
4017 echo esc_attr( $one_entry['user_value'] );}
4018 ?>"
4019 <?php
4020 if ( isset( $one_entry['available_fields'][0]['value_name'] ) ) {
4021 echo 'max="' . esc_attr( $one_entry['available_fields'][0]['value_name'] ) . '"';}
4022 echo wp_kses_data( $editable_attr ) . wp_kses_data( $required_attr );
4023 ?>
4024 />
4025 <?php if ( isset( $one_entry['available_fields'][0]['value_name'] ) ) { ?>
4026 <input type="hidden"
4027 name="prflxtrflds_user_field_max_number[<?php echo esc_attr( $one_entry['field_id'] ); ?>]"
4028 value="<?php echo esc_attr( $one_entry['available_fields'][0]['value_name'] ); ?>">
4029 <?php
4030 }
4031 break;
4032 case '10':
4033 ?>
4034 <input type="text" class="prflxtrflds_phone"
4035 id="prflxtrflds_user_field_value[<?php echo esc_attr( $one_entry['field_id'] ); ?>]"
4036 name="prflxtrflds_user_field_value[<?php echo esc_attr( $one_entry['field_id'] ); ?>]"
4037 value="<?php
4038 if ( isset( $one_entry['user_value'] ) ) {
4039 echo esc_attr( wp_unslash( $one_entry['user_value'] ) );
4040 }
4041 ?>" <?php echo wp_kses_data( $editable_attr ) . wp_kses_data( $required_attr ); ?> >
4042 <input type="hidden"
4043 name="prflxtrflds_user_field_pattern[<?php echo esc_attr( $one_entry['field_id'] ); ?>]"
4044 value="<?php echo esc_attr( $one_entry['available_fields'][0]['value_name'] ); ?>">
4045 <?php
4046 break;
4047 case '11':
4048 ?>
4049 <input type="url" class="prflxtrflds_url"
4050 id="prflxtrflds_user_field_value[<?php echo esc_attr( $one_entry['field_id'] ); ?>]"
4051 name="prflxtrflds_user_field_value[<?php echo esc_attr( $one_entry['field_id'] ); ?>]"
4052 value="<?php
4053 if ( isset( $one_entry['user_value'] ) ) {
4054 echo esc_attr( wp_unslash( $one_entry['user_value'] ) );
4055 }
4056 ?>"
4057 <?php
4058 if ( isset( $one_entry['available_fields'][0]['value_name'] ) ) {
4059 echo 'maxlength="' . esc_attr( $one_entry['available_fields'][0]['value_name'] ) . '"';}
4060 echo wp_kses_data( $editable_attr ) . wp_kses_data( $required_attr );
4061 ?>
4062 />
4063 <?php
4064 break;
4065 case '13':
4066 $countries = prflxtrflds_get_country();
4067 ?>
4068 <select id="prflxtrflds_user_field_value[<?php echo esc_attr( $one_entry['field_id'] ); ?>]" name="prflxtrflds_user_field_value[<?php echo esc_attr( $one_entry['field_id'] ); ?>]" <?php echo wp_kses_data( $editable_attr ) . wp_kses_data( $required_attr ); ?>>
4069 <?php
4070 foreach ( $countries as $country_id => $country_name ) {
4071 ?>
4072 <option value="<?php echo esc_attr( $country_id ); ?>" <?php selected( $one_entry['user_value'], $country_id ); ?>><?php echo esc_html( $country_name ); ?></option>
4073 <?php
4074 }
4075 ?>
4076 </select>
4077 <?php
4078 break;
4079 }
4080 echo $hidden_noneditable_field;
4081 if ( isset( $one_entry['description'] ) ) {
4082 ?>
4083 <p class="description"><?php echo esc_html( $one_entry['description'] ); ?></p>
4084 <?php } ?>
4085 </td>
4086 </tr>
4087 <?php
4088 } else {
4089 $hidden_nonvisible_field .= $hidden_noneditable_field;
4090 }
4091 }
4092 ?>
4093 </table><!--.form-table-->
4094 <?php
4095 }
4096 echo $hidden_nonvisible_field;
4097 }
4098 }
4099
4100 /** Send errors to edit user page */
4101 if ( ! function_exists( 'prflxtrflds_create_user_error' ) ) {
4102 /**
4103 * Send errors to edit user page
4104 *
4105 * @param array $errors Wp errors.
4106 * @param mixed $update Flag for update.
4107 * @param mixed $user User.
4108 */
4109 function prflxtrflds_create_user_error( $errors, $update = null, $user = null ) {
4110 $required_array = array();
4111
4112 if ( ( isset( $_POST['prflxtrflds_user_register_field'] ) && wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['prflxtrflds_user_register_field'] ) ), 'prflxtrflds_user_register_action' ) )
4113 || ( isset( $_POST['prflxtrflds_user_fields'] ) && wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['prflxtrflds_user_fields'] ) ), 'prflxtrflds_user_field_action' ) )
4114 || ( isset( $_POST['prflxtrflds_front_info'] ) && wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['prflxtrflds_front_info'] ) ), 'prflxtrflds_save_front_info' ) )
4115 ) {
4116 if ( ! empty( $_POST['prflxtrflds_required'] ) ) {
4117 /** Get all reqired ids */
4118 foreach ( $_POST['prflxtrflds_required'] as $required_id => $required_value ) {
4119 if ( empty( $_POST['prflxtrflds_user_field_value'][ $required_id ] ) ) {
4120 /** Error for non-textfield */
4121 $name = isset( $_POST['prflxtrflds_field_name'][ $required_id ] ) ? sanitize_text_field( wp_unslash( $_POST['prflxtrflds_field_name'][ $required_id ] ) ) : '';
4122 $errors->add( 'prflxtrflds_required_error', sprintf( __( 'Required field %1$s is not filled. Data was not saved!', 'profile-extra-fields' ), '<strong>' . esc_html( $name ) . '</strong>' ) );
4123 $required_array[] = $required_id;
4124 }
4125 }
4126 }
4127 if ( ! empty( $_POST['prflxtrflds_user_field_pattern'] ) ) {
4128 foreach ( $_POST['prflxtrflds_user_field_pattern'] as $field_id => $pattern ) {
4129 if ( ! empty( $_POST['prflxtrflds_user_field_value'][ $field_id ] ) &&
4130 ! in_array( $field_id, $required_array )
4131 ) {
4132 if ( ! preg_match( '/^' . str_replace( '\*', '[0-9]', preg_quote( $pattern ) ) . '$/', sanitize_text_field( wp_unslash( $_POST['prflxtrflds_user_field_value'][ $field_id ] ) ) ) ) {
4133 $name = isset( $_POST['prflxtrflds_field_name'][ $field_id ] ) ? sanitize_text_field( wp_unslash( $_POST['prflxtrflds_field_name'][ $field_id ] ) ) : '';
4134 $errors->add( 'prflxtrflds_match_error', sprintf( __( 'Field %1$s does not match %2$s. Data was not saved!', 'profile-extra-fields' ), '<strong>' . esc_html( $name ) . '</strong>', '<strong>' . $pattern . '</strong>' ) );
4135 }
4136 }
4137 }
4138 }
4139
4140 if ( ! empty( $_POST['prflxtrflds_user_field_max_number'] ) ) {
4141 foreach ( $_POST['prflxtrflds_user_field_max_number'] as $field_id => $max_number ) {
4142 if ( ! empty( $_POST['prflxtrflds_user_field_value'][ $field_id ] ) &&
4143 ! in_array( $field_id, $required_array )
4144 ) {
4145 $max_number = absint( $max_number );
4146 if ( $max_number > 0 &&
4147 absint( $_POST['prflxtrflds_user_field_value'][ $field_id ] ) > $max_number
4148 ) {
4149 $_POST['prflxtrflds_user_field_value'][ $field_id ] = $max_number;
4150 }
4151 }
4152 }
4153 }
4154
4155 if ( ! empty( $_POST['prflxtrflds_user_field_datetime'] ) ) {
4156 foreach ( $_POST['prflxtrflds_user_field_datetime'] as $field_id => $pattern ) {
4157 if ( ! empty( $_POST['prflxtrflds_user_field_value'][ $field_id ] ) &&
4158 ! in_array( $field_id, $required_array )
4159 ) {
4160 $pattern = trim( str_replace( 'T', '', sanitize_text_field( wp_unslash( $pattern ) ) ) );
4161 if ( function_exists( 'date_create_from_format' ) ) {
4162 $d = date_create_from_format( $pattern, $_POST['prflxtrflds_user_field_value'][ $field_id ] );
4163 if ( ! $d || $d->format( $pattern ) !== $_POST['prflxtrflds_user_field_value'][ $field_id ] ) {
4164 $name = isset( $_POST['prflxtrflds_field_name'][ $field_id ] ) ? sanitize_text_field( wp_unslash( $_POST['prflxtrflds_field_name'][ $field_id ] ) ) : '';
4165 $errors->add( 'prflxtrflds_match_error', sprintf( __( 'Field %1$s does not match %2$s. Data was not saved!', 'profile-extra-fields' ), '<strong>' . esc_html( $name ) . '</strong>', '<strong>' . $pattern . '</strong>' ) );
4166 }
4167 } elseif ( ! strtotime( $_POST['prflxtrflds_user_field_value'][ $field_id ] ) ) {
4168 $name = isset( $_POST['prflxtrflds_field_name'][ $field_id ] ) ? sanitize_text_field( wp_unslash( $_POST['prflxtrflds_field_name'][ $field_id ] ) ) : '';
4169 $errors->add( 'prflxtrflds_match_error', sprintf( __( 'Field %1$s does not match %2$s. Data was not saved!', 'profile-extra-fields' ), '<strong>' . esc_html( $name ) . '</strong>', '<strong>' . $pattern . '</strong>' ) );
4170 }
4171 }
4172 }
4173 }
4174 }
4175 }
4176 }
4177
4178 if ( ! function_exists( 'prflxtrflds_save_user_data' ) ) {
4179 /**
4180 * Save user data from Edit user page
4181 */
4182 function prflxtrflds_save_user_data() {
4183 $user_id = isset( $_POST['user_id'] ) ? intval( $_POST['user_id'] ) : get_current_user_id();
4184 /** Get errors */
4185 $errors = edit_user( $user_id );
4186 if ( ! is_wp_error( $errors ) && ! empty( $_POST['prflxtrflds_user_field_value'] ) && isset( $_POST['prflxtrflds_user_fields'] ) && wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['prflxtrflds_user_fields'] ) ), 'prflxtrflds_user_field_action' ) ) {
4187 global $wpdb;
4188
4189 /** If array exists ( exist available fields for current user ), remove old data */
4190 if ( ! empty( $_POST['prflxtrflds_not_editable'] ) ) {
4191 /** Execute not_editable fields */
4192 $prflxtrflds_not_editable = array_map( 'intval', $_POST['prflxtrflds_not_editable'] );
4193 $not_editable_ids = "'" . implode( "','", $prflxtrflds_not_editable ) . "'";
4194 $wpdb->query(
4195 $wpdb->prepare(
4196 'DELETE FROM `' . $wpdb->base_prefix . 'prflxtrflds_user_field_data`
4197 WHERE `user_id` = %d
4198 AND `field_id` NOT IN (' . $not_editable_ids . ')',
4199 $user_id
4200 )
4201 );
4202 } else {
4203 $wpdb->delete(
4204 $wpdb->base_prefix . 'prflxtrflds_user_field_data',
4205 array( 'user_id' => $user_id )
4206 );
4207 }
4208
4209 /** Create array with user values */
4210 foreach ( $_POST['prflxtrflds_user_field_value'] as $id => $val ) {
4211 if ( ! empty( $val ) ) {
4212 if ( is_array( $val ) ) {
4213 /** For checkboxes */
4214 foreach ( $val as $user_value ) {
4215 /** Insert or update value */
4216 $wpdb->replace(
4217 $wpdb->base_prefix . 'prflxtrflds_user_field_data',
4218 array(
4219 'user_id' => esc_sql( $user_id ),
4220 'field_id' => esc_sql( absint( $id ) ),
4221 'user_value' => esc_sql( wp_filter_post_kses( wp_unslash( $user_value ) ) ),
4222 )
4223 );
4224 }
4225 } else {
4226 $user_value = wp_filter_post_kses( wp_unslash( $val ) );
4227 /** Insert or update value */
4228 $wpdb->replace(
4229 $wpdb->base_prefix . 'prflxtrflds_user_field_data',
4230 array(
4231 'user_id' => esc_sql( $user_id ),
4232 'field_id' => esc_sql( absint( $id ) ),
4233 'user_value' => esc_sql( $user_value ),
4234 )
4235 );
4236 }
4237 }
4238 }
4239 }
4240 }
4241 }
4242
4243 if ( ! function_exists( 'prflxtrflds_save_booking_fields' ) ) {
4244 /**
4245 * Save user data from WC
4246 *
4247 * @param array $data Data from WC.
4248 */
4249 function prflxtrflds_save_booking_fields( $data ) {
4250 global $wpdb;
4251
4252 if ( ! isset( $_POST['prflxtrflds_user_field_value'] ) ) {
4253 return $data;
4254 }
4255
4256 if ( isset( $_POST['prflxtrflds_required'] ) ) {
4257 foreach ( $_POST['prflxtrflds_required'] as $key => $value ) {
4258 if ( empty( $_POST['prflxtrflds_user_field_value'][ $key ] ) ) {
4259 add_filter( 'bws_bkng_required_bilings_fields', 'prflxtrflds_add_required_fields' );
4260 return $data;
4261 }
4262 }
4263 }
4264 $user_id = isset( $_POST['user_id'] ) ? intval( $_POST['user_id'] ) : get_current_user_id();
4265
4266 /** If array exists ( exist available fields for current user ), remove old data */
4267 if ( ! empty( $_POST['prflxtrflds_not_editable'] ) ) {
4268 /** Execute not_editable fields */
4269 $prflxtrflds_not_editable = array_map( 'intval', $_POST['prflxtrflds_not_editable'] );
4270 $not_editable_ids = "'" . implode( "','", $prflxtrflds_not_editable ) . "'";
4271
4272 $wpdb->query(
4273 $wpdb->prepare(
4274 'DELETE FROM `' . $wpdb->base_prefix . 'prflxtrflds_user_field_data`
4275 WHERE `user_id` = %d
4276 AND `field_id` NOT IN (' . $not_editable_ids . ')',
4277 $user_id
4278 )
4279 );
4280 } else {
4281 $wpdb->delete(
4282 $wpdb->base_prefix . 'prflxtrflds_user_field_data',
4283 array( 'user_id' => $user_id )
4284 );
4285 }
4286
4287 foreach ( $_POST['prflxtrflds_user_field_value'] as $id => $val ) {
4288 if ( ! empty( $val ) ) {
4289 if ( is_array( $val ) ) {
4290 /** For checkboxes */
4291 foreach ( $val as $user_value ) {
4292 /** Insert or update value */
4293 $wpdb->replace(
4294 $wpdb->base_prefix . 'prflxtrflds_user_field_data',
4295 array(
4296 'user_id' => esc_sql( $user_id ),
4297 'field_id' => esc_sql( absint( $id ) ),
4298 'user_value' => esc_sql( sanitize_text_field( wp_unslash( $user_value ) ) ),
4299 )
4300 );
4301 }
4302 } else {
4303 $user_value = esc_sql( sanitize_text_field( wp_unslash( $val ) ) );
4304 /** Insert or update value */
4305 $wpdb->replace(
4306 $wpdb->base_prefix . 'prflxtrflds_user_field_data',
4307 array(
4308 'user_id' => esc_sql( $user_id ),
4309 'field_id' => esc_sql( absint( $id ) ),
4310 'user_value' => esc_sql( $user_value ),
4311 )
4312 );
4313 }
4314 }
4315 }
4316
4317 return $data;
4318 }
4319 }
4320
4321 if ( ! function_exists( 'prflxtrflds_add_required_fields' ) ) {
4322 /**
4323 * Add field order
4324 *
4325 * @param array $fields Required fields array.
4326 */
4327 function prflxtrflds_add_required_fields( $fields ) {
4328 return array_merge( $fields, array( 'prflxtrflds_user_field_value' ) );
4329 }
4330 }
4331
4332 if ( ! function_exists( 'prflxtrflds_add_error_message' ) ) {
4333 /**
4334 * Add error message
4335 *
4336 * @param string $message Error message.
4337 * @param string $code Error code.
4338 */
4339 function prflxtrflds_add_error_message( $message, $code ) {
4340 return $message . ( 'prflxtrflds_user_field_value' === $code ) ? esc_html__( 'Please fill all required fields.', 'profile-extra-fields' ) : '';
4341 }
4342 }
4343
4344 if ( ! function_exists( 'prflxtrflds_table_order' ) ) {
4345 /**
4346 * Save field order from wp list table
4347 */
4348 function prflxtrflds_table_order() {
4349 /** Check ajax. Function fie if error */
4350 check_ajax_referer( plugin_basename( __FILE__ ), 'prflxtrflds_ajax_nonce_field' );
4351 /** If check ok, edit order */
4352 if ( isset( $_POST['table_order'] ) ) {
4353 /** Into string is values with coma separate */
4354 $sort_parametrs = filter_input( INPUT_POST, 'table_order', FILTER_SANITIZE_STRING );
4355
4356 /** Role id = 0 for 'all' users */
4357 $role_id = ( isset( $_POST['field_id'] ) && 'all' !== $_POST['field_id'] ) ? intval( $_POST['field_id'] ) : 0;
4358
4359 if ( '0' !== $sort_parametrs ) {
4360 global $wpdb;
4361 $table_roles_and_fields = $wpdb->base_prefix . 'prflxtrflds_roles_and_fields';
4362 /** Create array */
4363 $sort_parametrs = explode( ', ', $sort_parametrs );
4364 if ( is_array( $sort_parametrs ) ) {
4365 $i = 0;
4366 foreach ( $sort_parametrs as $field_id ) {
4367 $field_id = intval( $field_id );
4368 if ( 0 !== $role_id ) {
4369 $wpdb->update(
4370 $table_roles_and_fields,
4371 array(
4372 'field_order' => $i,
4373 ),
4374 array(
4375 'field_id' => $field_id,
4376 'role_id' => $role_id,
4377 ),
4378 array( '%d' ),
4379 array( '%d', '%d' )
4380 );
4381 } else {
4382 /** If role id === 0, change sort settings for all roles */
4383 $wpdb->update(
4384 $table_roles_and_fields,
4385 array(
4386 'field_order' => $i,
4387 ),
4388 array(
4389 'field_id' => $field_id,
4390 ),
4391 array( '%d' ),
4392 array( '%d' )
4393 );
4394 }
4395 $i++;
4396 }
4397 }
4398 }
4399 }
4400 wp_die();
4401 }
4402 }
4403
4404 if ( ! function_exists( 'prflxtrflds_get_users' ) ) {
4405 /**
4406 * Dispaly all users
4407 */
4408 function prflxtrflds_get_users() {
4409 /** Check ajax. Function fie if error */
4410 check_ajax_referer( plugin_basename( __FILE__ ), 'prflxtrflds_ajax_nonce_field' );
4411 $users = get_users();
4412 if ( ! empty( $users ) ) {
4413 foreach ( $users as $user ) {
4414 ?>
4415 <option value="<?php echo esc_attr( $user->ID ); ?>"><?php echo esc_attr( $user->display_name ); ?></option>
4416 <?php
4417 }
4418 }
4419 wp_die();
4420 }
4421 }
4422
4423 if ( ! function_exists( 'prflxtrflds_get_roles' ) ) {
4424 /**
4425 * Dispaly all roles
4426 */
4427 function prflxtrflds_get_roles() {
4428 global $wpdb;
4429 /** Check ajax. Function fie if error */
4430 check_ajax_referer( plugin_basename( __FILE__ ), 'prflxtrflds_ajax_nonce_field' );
4431 $roles = $wpdb->get_results( 'SELECT `role`, `role_name` FROM `' . $wpdb->base_prefix . 'prflxtrflds_roles_id`', ARRAY_A );
4432 if ( ! empty( $roles ) ) {
4433 foreach ( $roles as $role ) {
4434 ?>
4435 <option value="<?php echo esc_attr( $role['role'] ); ?>"><?php echo esc_attr( $role['role_name'] ); ?></option>
4436 <?php
4437 }
4438 }
4439 wp_die();
4440 }
4441 }
4442
4443 if ( ! function_exists( 'prflxtrflds_get_fields_name' ) ) {
4444 /**
4445 * Dispaly field name
4446 */
4447 function prflxtrflds_get_fields_name() {
4448 global $wpdb;
4449 /** Check ajax. Function fie if error */
4450 check_ajax_referer( plugin_basename( __FILE__ ), 'prflxtrflds_ajax_nonce_field' );
4451 $fields = $wpdb->get_results( 'SELECT `field_id`, `field_name` FROM `' . $wpdb->base_prefix . 'prflxtrflds_fields_id`', ARRAY_A );
4452 if ( ! empty( $fields ) ) {
4453 foreach ( $fields as $field ) {
4454 ?>
4455 <option value="<?php echo esc_attr( $field['field_id'] ); ?>"><?php echo esc_attr( $field['field_name'] ); ?></option>
4456 <?php
4457 }
4458 }
4459 wp_die();
4460 }
4461 }
4462
4463 if ( ! function_exists( 'prflxtrflds_shortcode_button_content' ) ) {
4464 /**
4465 * Add shortcode content
4466 *
4467 * @param string $content Content for shortcode.
4468 */
4469 function prflxtrflds_shortcode_button_content( $content ) {
4470 global $prflxtrflds_options;
4471
4472 if ( ! isset( $prflxtrflds_options ) ) {
4473 prflxtrflds_settings();
4474 }
4475 $display_users = array(
4476 'all' => __( 'Display all users data', 'profile-extra-fields' ),
4477 'current_user' => __( 'Display logged in user data', 'profile-extra-fields' ),
4478 'specify_roles' => __( 'Specify a user role', 'profile-extra-fields' ),
4479 'specify_users' => __( 'Specify a user', 'profile-extra-fields' ),
4480 );
4481 ?>
4482 <div id="prflxtrflds" style="display:none;">
4483 <p>
4484 <span style="vertical-align: middle;"><?php esc_html_e( 'Select Shortcode', 'profile-extra-fields' ); ?>:</span>&emsp;
4485 <select name="prflxtrflds_shortcode">
4486 <option value="table" selected="selected"><?php esc_html_e( 'Table', 'profile-extra-fields' ); ?></option>
4487 <option value="field"><?php esc_html_e( 'Field Value', 'profile-extra-fields' ); ?></option>
4488 </select>
4489 </p>
4490 <div class="prflxtrflds_table_block">
4491 <p>
4492 <span style="vertical-align: middle;"><?php esc_html_e( 'Data Rotation', 'profile-extra-fields' ); ?>:</span>&emsp;
4493 <select class='prflxtrflds_header_table' name="prflxtrflds_header_table">
4494 <option value="columns"<?php selected( $prflxtrflds_options['header_table'], 'columns' ); ?>><?php esc_html_e( 'Columns', 'profile-extra-fields' ); ?></option>
4495 <option value="rows"<?php selected( $prflxtrflds_options['header_table'], 'rows' ); ?>><?php esc_html_e( 'Rows', 'profile-extra-fields' ); ?></option>
4496 </select>
4497 </p>
4498 <p>
4499 <span style="vertical-align: middle;"><?php esc_html_e( 'Users', 'profile-extra-fields' ); ?>:</span>&emsp;
4500 <select class='prflxtrflds_specify' name="prflxtrflds_specify">
4501 <?php foreach ( $display_users as $users => $label ) { ?>
4502 <option value="<?php echo esc_attr( $users ); ?>" <?php selected( $users, 'all' ); ?> >
4503 <?php echo esc_html( $label ); ?>
4504 </option>
4505 <?php } ?>
4506 </select>
4507 </p>
4508 <img class="prflxtrflds_table_loader hidden" src="<?php echo esc_url( plugins_url( 'images/loader.gif', __FILE__ ) ); ?>" alt="Loading" />
4509 <p>
4510 <select class='prflxtrflds_user_roles hidden' name="prflxtrflds_user_roles" multiple="multiple" style="max-height: 70px; width: 355px;"></select>
4511 <select class='prflxtrflds_users hidden' name="prflxtrflds_users" multiple="multiple" style="max-height: 55px; width: 355px;"></select>
4512 </p>
4513 </div>
4514
4515 <input class="bws_default_shortcode" type="hidden" name="default" value="[prflxtrflds_user_data]" />
4516 <?php
4517 $script = "function prflxtrflds_get_shortcode() {
4518 ( function( $ ) {
4519 var shortcodeType = $( '.mce-reset select[name=\"prflxtrflds_shortcode\"]' ).val();
4520 if ( 'table' === shortcodeType ) {
4521 var header = $( '.mce-reset .prflxtrflds_header_table option:selected' ).val();
4522
4523 var specify = $( '.mce-reset .prflxtrflds_specify option:selected' ).val();
4524
4525 if ( 'specify_roles' === specify ) {
4526 var user_role = $( '.mce-reset .prflxtrflds_user_roles option:selected' ).map( function() { return this.value.replace( / /gi, '_' ); } ).get().join( \",\" );
4527 } else if ( 'specify_users' === specify ) {
4528 var user = $( '.mce-reset .prflxtrflds_users option:selected' ).map( function(){ return this.value } ).get().join( \",\" );
4529 } else if ( 'current_user' === specify ) {
4530 var user = 'get_current_user';
4531 }
4532
4533 var shortcode = '[prflxtrflds_user_data';
4534 if ( user_role ) {
4535 shortcode = shortcode + ' user_role=' + user_role;
4536 }
4537 if ( user ) {
4538 shortcode = shortcode + ' user_id=' + user;
4539 }
4540 if ( header ) {
4541 shortcode = shortcode + ' display=' + header;
4542 }
4543 shortcode = shortcode + ']';
4544 } else {
4545 var user = $( '.mce-reset .prflxtrflds_user option:selected' ).val();
4546
4547 if ( 'specify_user' === user ) {
4548 var user_id = $( '.mce-reset .prflxtrflds_specify_user option:selected' ).val();
4549 }
4550
4551 shortcode = '[prflxtrflds_field';
4552
4553 if ( user_id ) {
4554 shortcode = shortcode + ' user_id=' + user_id;
4555 }
4556 shortcode = shortcode + ']';
4557 }
4558
4559 $( '.mce-reset #bws_shortcode_display' ).text( shortcode );
4560 } )( jQuery );
4561 }
4562 function prflxtrflds_shortcode_init() {
4563 ( function( $ ) {
4564 $( '.mce-reset select[name=\"prflxtrflds_shortcode\"]' ).on( 'change', function() {
4565 var shortcodeType = $( this ).val();
4566 if ( 'table' === shortcodeType ) {
4567 $( '.mce-reset .prflxtrflds_table_block' ).show();
4568 $( '.mce-reset .prflxtrflds_field_block' ).hide();
4569
4570 } else {
4571 $( '.mce-reset .prflxtrflds_table_block' ).hide();
4572 $( '.mce-reset .prflxtrflds_field_block' ).show();
4573 $.ajax( {
4574 url: ajaxurl,
4575 type: \"POST\",
4576 data: 'action=prflxtrflds_get_fields_name&prflxtrflds_ajax_nonce_field=" . wp_create_nonce( plugin_basename( __FILE__ ), 'prflxtrflds_ajax_nonce_field' ) . "',
4577 success: function( result ) {
4578 $( '.mce-reset .prflxtrflds_field' ).html( result );
4579 $( '.mce-reset .prflxtrflds_field :first' ).attr( 'selected' );
4580 $( '.mce-reset .prflxtrflds_field' ).show();
4581 prflxtrflds_get_shortcode();
4582 },
4583 error: function( request, status, error ) {
4584 console.log( error + request.status );
4585 }
4586 } );
4587 }
4588 } ).trigger( 'change' );
4589
4590 $( '.mce-reset .prflxtrflds_specify' ).on( 'change', function() {
4591 var specify = $( this ).val();
4592 if( 'all' === specify || 'gcurrent_user' === specify ) {
4593 $( '.mce-reset .prflxtrflds_user_roles' ).hide();
4594 $( '.mce-reset .prflxtrflds_users' ).hide();
4595 } else if( 'specify_roles' === specify ) {
4596 $( '.mce-reset .prflxtrflds_users' ).hide();
4597 if ( $( '.mce-reset .prflxtrflds_table_loader' ).length > 0 ) {
4598 $( '.mce-reset .prflxtrflds_table_loader' ).show();
4599 $.ajax( {
4600 url: ajaxurl,
4601 type: \"POST\",
4602 data: 'action=prflxtrflds_get_roles&prflxtrflds_ajax_nonce_field=" . wp_create_nonce( plugin_basename( __FILE__ ), 'prflxtrflds_ajax_nonce_field' ) . "',
4603 success: function( result ) {
4604 $( '.mce-reset .prflxtrflds_user_roles' ).html( result );
4605 $( '.mce-reset .prflxtrflds_user_roles' ).show();
4606 $( '.mce-reset .prflxtrflds_table_loader' ).hide();
4607 },
4608 error: function( request, status, error ) {
4609 console.log( error + request.status );
4610 }
4611 } );
4612 } else {
4613 $( '.mce-reset .prflxtrflds_user_roles' ).show();
4614 }
4615 } else if ( 'specify_users' === specify ) {
4616 $( '.mce-reset .prflxtrflds_user_roles' ).hide();
4617 if ( $( '.mce-reset .prflxtrflds_table_loader' ).length > 0 ) {
4618 $( '.mce-reset .prflxtrflds_table_loader' ).show();
4619 $.ajax( {
4620 url: ajaxurl,
4621 type: \"POST\",
4622 data: 'action=prflxtrflds_get_users&prflxtrflds_ajax_nonce_field=" . wp_create_nonce( plugin_basename( __FILE__ ), 'prflxtrflds_ajax_nonce_field' ) . "',
4623 success: function( result ) {
4624 $( '.mce-reset .prflxtrflds_users' ).html( result );
4625 $( '.mce-reset .prflxtrflds_users' ).show();
4626 $( '.mce-reset .prflxtrflds_table_loader' ).hide();
4627 },
4628 error: function( request, status, error ) {
4629 console.log( error + request.status );
4630 }
4631 } );
4632 } else {
4633 $( '.mce-reset .prflxtrflds_users' ).show();
4634 }
4635 }
4636 } );
4637
4638 $( '.mce-reset .prflxtrflds_user' ).on( 'change', function() {
4639 var user = $( this ).val();
4640 if ( 'specify_user' === user ){
4641 $( '.mce-reset .prflxtrflds_specify_user' ).show();
4642 } else {
4643 $( '.mce-reset .prflxtrflds_specify_user' ).hide();
4644 }
4645 } );
4646
4647 $( '.mce-reset #prflxtrflds input, .mce-reset #prflxtrflds select' ).on( 'change', function() {
4648 prflxtrflds_get_shortcode();
4649 } );
4650 /** Add specific css for shortcode window */
4651 $( '.mce-window-body' ).css( 'padding-bottom', '80px' );
4652 $( '.mce-window' ).css( 'height', '520px' );
4653 } )( jQuery );
4654 }";
4655
4656 wp_register_script( 'prflxtrflds_get_shortcode', '' );
4657 wp_enqueue_script( 'prflxtrflds_get_shortcode' );
4658 wp_add_inline_script( 'prflxtrflds_get_shortcode', sprintf( $script ) );
4659 ?>
4660 <div class="clear"></div>
4661 </div>
4662 <?php
4663 }
4664 }
4665
4666 if ( ! function_exists( 'prflxtrflds_plugin_action_links' ) ) {
4667 /**
4668 * This links under plugin name
4669 *
4670 * @param array $links All plugins links array.
4671 * @param string $file File name.
4672 */
4673 function prflxtrflds_plugin_action_links( $links, $file ) {
4674 if ( ! is_network_admin() ) {
4675 /** Static so we don't call plugin_basename on every plugin row. */
4676 static $this_plugin;
4677 if ( ! $this_plugin ) {
4678 $this_plugin = plugin_basename( __FILE__ );
4679 }
4680 if ( $file === $this_plugin ) {
4681 $settings_link = '<a href="admin.php?page=profile-extra-fields.php">' . __( 'Settings', 'profile-extra-fields' ) . '</a>';
4682 array_unshift( $links, $settings_link ); /** Add settings link to begin of array */
4683 }
4684 }
4685 return $links;
4686 }
4687 }
4688
4689 if ( ! function_exists( 'prflxtrflds_register_plugin_links' ) ) {
4690 /**
4691 * Added Settings, FAQ and Support links
4692 *
4693 * @param array $links All plugins links array.
4694 * @param string $file File name.
4695 */
4696 function prflxtrflds_register_plugin_links( $links, $file ) {
4697 $base = plugin_basename( __FILE__ );
4698 if ( $file === $base ) {
4699 if ( ! is_network_admin() ) {
4700 $links[] = '<a href="admin.php?page=profile-extra-fields.php">' . __( 'Settings', 'profile-extra-fields' ) . '</a>';
4701 }
4702 $links[] = '<a href="https://support.bestwebsoft.com/hc/en-us/sections/201146449/">' . __( 'FAQ', 'profile-extra-fields' ) . '</a>';
4703 $links[] = '<a href="https://support.bestwebsoft.com">' . __( 'Support', 'profile-extra-fields' ) . '</a>';
4704 }
4705 return $links;
4706 }
4707 }
4708
4709 if ( ! function_exists( 'prflxtrflds_admin_notices' ) ) {
4710 /**
4711 * Add admin notices
4712 */
4713 function prflxtrflds_admin_notices() {
4714 global $hook_suffix, $prflxtrflds_plugin_info;
4715 if ( 'plugins.php' === $hook_suffix && ! is_network_admin() ) {
4716 bws_plugin_banner_to_settings( $prflxtrflds_plugin_info, 'prflxtrflds_options', 'profile-extra-fields', 'admin.php?page=profile-extra-fields.php' );
4717 }
4718 if ( isset( $_GET['page'] ) && 'profile-extra-fields.php' === $_GET['page'] ) {
4719 bws_plugin_suggest_feature_banner( $prflxtrflds_plugin_info, 'prflxtrflds_options', 'profile-extra-fields' );
4720 }
4721 }
4722 }
4723
4724 if ( ! function_exists( 'prflxtrflds_load_script' ) ) {
4725 /**
4726 * Register scripts
4727 */
4728 function prflxtrflds_load_script() {
4729 global $hook_suffix;
4730
4731 if ( isset( $_GET['page'] ) && in_array( $_GET['page'], array( 'profile-extra-fields.php', 'profile-extra-field-add-new.php', 'profile-extra-fields-settings.php' ) ) ) {
4732
4733 if ( wp_is_mobile() ) {
4734 wp_enqueue_script( 'jquery-touch-punch' );
4735 }
4736
4737 wp_enqueue_script( 'prflxtrflds_script', plugins_url( '/js/script.js', __FILE__ ), array( 'jquery', 'jquery-ui-sortable' ), '1.2.4' );
4738 $script_vars = array(
4739 'prflxtrflds_ajax_url' => admin_url( 'admin-ajax.php' ),
4740 'prflxtrflds_nonce' => wp_create_nonce( plugin_basename( __FILE__ ), 'prflxtrflds_ajax_nonce_field' ),
4741 );
4742 wp_localize_script( 'prflxtrflds_script', 'prflxtrflds_ajax', $script_vars );
4743
4744 bws_enqueue_settings_scripts();
4745 bws_plugins_include_codemirror();
4746 }
4747
4748 if ( 'user-edit.php' === $hook_suffix || 'profile.php' === $hook_suffix ) {
4749 prflxtrflds_enqueue_fields_styles();
4750 }
4751 }
4752 }
4753
4754 if ( ! function_exists( 'prflxtrflds_uninstall' ) ) {
4755 /**
4756 * Uninstall plugin
4757 */
4758 function prflxtrflds_uninstall() {
4759 global $wpdb;
4760 $all_plugins = get_plugins();
4761 /** Drop all plugin tables */
4762 if ( ! array_key_exists( 'profile-extra-fields-pro/profile-extra-fields-pro.php', $all_plugins ) ) {
4763 $table_names = array(
4764 '`' . $wpdb->base_prefix . 'prflxtrflds_fields_id`',
4765 '`' . $wpdb->base_prefix . 'prflxtrflds_field_types`',
4766 '`' . $wpdb->base_prefix . 'prflxtrflds_field_values`',
4767 '`' . $wpdb->base_prefix . 'prflxtrflds_roles_and_fields`',
4768 '`' . $wpdb->base_prefix . 'prflxtrflds_roles_id`',
4769 '`' . $wpdb->base_prefix . 'prflxtrflds_user_field_data`',
4770 '`' . $wpdb->base_prefix . 'prflxtrflds_user_roles`',
4771 );
4772 $wpdb->query( 'DROP TABLE IF EXISTS ' . implode( ', ', $table_names ) );
4773 /** Delete options */
4774 if ( function_exists( 'is_multisite' ) && is_multisite() ) {
4775 $old_blog = $wpdb->blogid;
4776 /** Get all blog ids */
4777 $blogids = $wpdb->get_col( "SELECT `blog_id` FROM $wpdb->blogs" );
4778 foreach ( $blogids as $blog_id ) {
4779 switch_to_blog( $blog_id );
4780 delete_option( 'prflxtrflds_options' );
4781 }
4782 switch_to_blog( $old_blog );
4783 } else {
4784 delete_option( 'prflxtrflds_options' );
4785 }
4786
4787 require_once dirname( __FILE__ ) . '/bws_menu/bws_include.php';
4788 bws_include_init( plugin_basename( __FILE__ ) );
4789 bws_delete_plugin( plugin_basename( __FILE__ ) );
4790 }
4791 }
4792 }
4793
4794 if ( ! function_exists( 'prflxtrflds_get_fields' ) ) {
4795 /**
4796 * Get fileds by args
4797 *
4798 * @param array $args Args for query.
4799 */
4800 function prflxtrflds_get_fields( $args = array() ) {
4801 global $wpdb;
4802
4803 $defaults = array(
4804 'roles' => array(),
4805 'visible' => false,
4806 'editable' => false,
4807 'required' => false,
4808 'show' => false,
4809 'exclude' => false,
4810 );
4811
4812 $args = wp_parse_args( $args, $defaults );
4813
4814 $where = '';
4815
4816 if ( ! empty( $args['roles'] ) && is_array( $args['roles'] ) ) {
4817 $roles = implode( '", "', $args['roles'] );
4818 $where .= 'AND `' . $wpdb->base_prefix . "prflxtrflds_roles_id`.`role` IN ( '" . $roles . "' ) ";
4819 }
4820
4821 if ( false !== $args['visible'] ) {
4822 $where .= 'AND `' . $wpdb->base_prefix . "prflxtrflds_roles_and_fields`.`visible`='" . absint( $args['visible'] ) . "' ";
4823 }
4824
4825 if ( false !== $args['editable'] ) {
4826 $where .= 'AND `' . $wpdb->base_prefix . "prflxtrflds_roles_and_fields`.`editable`='" . absint( $args['editable'] ) . "' ";
4827 }
4828
4829 if ( false !== $args['required'] ) {
4830 $where .= 'AND `' . $wpdb->base_prefix . "prflxtrflds_fields_id`.`required` != '' ";
4831 }
4832
4833 if ( false !== $args['show'] ) {
4834 $exclude = $args['exclude'] ? 'NOT' : '';
4835
4836 if ( is_array( $args['show'] ) ) {
4837 $fields = implode( "', '", $args['show'] );
4838 $where_show_in = "IN ( '" . $fields . "' )";
4839 } else {
4840 $where_show_in = "= '" . $args['show'] . "'";
4841 }
4842
4843 $where .= 'AND `' . $wpdb->base_prefix . 'prflxtrflds_fields_id`.`field_id` ' . $exclude . ' IN (
4844 SELECT `' . $wpdb->base_prefix . 'prflxtrflds_fields_meta`.`field_id`
4845 FROM `' . $wpdb->base_prefix . 'prflxtrflds_fields_meta`
4846 WHERE `' . $wpdb->base_prefix . 'prflxtrflds_fields_meta`.`show_in` ' . $where_show_in . ' AND `' . $wpdb->base_prefix . 'prflxtrflds_fields_meta`.`value` != ""
4847 )';
4848 }
4849
4850 $sql_query = 'SELECT
4851 `' . $wpdb->base_prefix . 'prflxtrflds_fields_id`.`field_id`,
4852 `' . $wpdb->base_prefix . 'prflxtrflds_fields_id`.`field_name`,
4853 `' . $wpdb->base_prefix . 'prflxtrflds_fields_id`.`required`,
4854 `' . $wpdb->base_prefix . 'prflxtrflds_fields_id`.`description`,
4855 `' . $wpdb->base_prefix . 'prflxtrflds_fields_id`.`field_type_id`,
4856 `' . $wpdb->base_prefix . 'prflxtrflds_roles_and_fields`.`field_order`,
4857 `' . $wpdb->base_prefix . 'prflxtrflds_roles_and_fields`.`editable`,
4858 `' . $wpdb->base_prefix . 'prflxtrflds_roles_and_fields`.`visible`,
4859 `' . $wpdb->base_prefix . 'prflxtrflds_field_values`.`value_name`
4860 FROM
4861 `' . $wpdb->base_prefix . 'prflxtrflds_fields_id`,
4862 `' . $wpdb->base_prefix . 'prflxtrflds_roles_and_fields`,
4863 `' . $wpdb->base_prefix . 'prflxtrflds_roles_id`,
4864 `' . $wpdb->base_prefix . 'prflxtrflds_field_values`
4865 WHERE
4866 `' . $wpdb->base_prefix . 'prflxtrflds_roles_and_fields`.`role_id`= `' . $wpdb->base_prefix . 'prflxtrflds_roles_id`.`role_id`
4867 AND `' . $wpdb->base_prefix . 'prflxtrflds_roles_and_fields`.`field_id`=`' . $wpdb->base_prefix . 'prflxtrflds_fields_id`.`field_id`
4868 AND `' . $wpdb->base_prefix . 'prflxtrflds_field_values`.`field_id`=`' . $wpdb->base_prefix . 'prflxtrflds_fields_id`.`field_id`
4869 ' . $where . '
4870 GROUP BY `' . $wpdb->base_prefix . 'prflxtrflds_roles_and_fields`.`field_id`
4871 ORDER BY `' . $wpdb->base_prefix . 'prflxtrflds_roles_and_fields`.`field_order` ASC,
4872 `' . $wpdb->base_prefix . 'prflxtrflds_roles_and_fields`.`field_id` ASC';
4873 $entries = $wpdb->get_results( $sql_query, ARRAY_A );
4874
4875 if ( ! $entries ) {
4876 /* If data for current role not exists, update table and try again */
4877 prflxtrflds_update_roles_id();
4878 $entries = $wpdb->get_results( $sql_query, ARRAY_A );
4879 }
4880
4881 return $entries;
4882 }
4883 }
4884
4885 if ( ! function_exists( 'prflxtrflds_get_field_html' ) ) {
4886 /**
4887 * This function show fields in registration form
4888 *
4889 * @param array $field_data Fields data.
4890 * @param string $name Field name.
4891 * @param array $atts Atts array.
4892 * @param bool $echo Flag for echo.
4893 */
4894 function prflxtrflds_get_field_html( $field_data = array(), $name = 'prflxtrflds_user_field_value', $atts = array(), $echo = false ) {
4895 $field_types = array(
4896 '1' => 'text',
4897 '2' => 'textarea',
4898 '3' => 'checkbox',
4899 '4' => 'radio',
4900 '5' => 'select',
4901 '6' => 'date',
4902 '7' => 'time',
4903 '8' => 'datetime',
4904 '9' => 'number',
4905 '10' => 'phone',
4906 '11' => 'url',
4907 '13' => 'country',
4908 );
4909 $html = '';
4910 $rows = '';
4911 $cols = '';
4912
4913 $max_length_textarea = '';
4914
4915 $value = ( isset( $field_data['user_value'] ) ) ? $field_data['user_value'] : '';
4916 if ( '' === $value && isset( $_POST[ $name ][ $field_data['field_id'] ] ) ) {
4917 $value = sanitize_text_field( wp_unslash( $_POST[ $name ][ $field_data['field_id'] ] ) );
4918 }
4919 $max_length = ( isset( $field_data['available_fields'][0]['value_name'] ) ) ? 'maxlength="' . $field_data['available_fields'][0]['value_name'] . '"' : '';
4920
4921 if ( 2 === intval( $field_data['field_type_id'] ) ) {
4922 $unser_textarea = maybe_unserialize( $field_data['available_fields'][0]['value_name'] );
4923 $rows = $unser_textarea['rows'];
4924 $cols = $unser_textarea['cols'];
4925 $max_length_textarea = $unser_textarea['max_length'];
4926 }
4927
4928 if ( 9 === intval( $field_data['field_type_id'] ) ) {
4929 $max_length_number = ( isset( $field_data['available_fields'][0]['value_name'] ) ) ? 'max="' . $field_data['available_fields'][0]['value_name'] . '"' : '';
4930 }
4931
4932 $editable_attr = implode( ' ', $atts );
4933 $editable_attr .= disabled( empty( $field_data['editable'] ), true, false );
4934
4935 $required_attr = ( ! empty( $field_data['required'] ) && ! empty( $field_data['editable'] ) && ! isset( $field_data['gravity_form'] ) ) ? ' required="required"' : '';
4936
4937 if ( 'text' === $field_types[ $field_data['field_type_id'] ] ) {
4938 $html = sprintf(
4939 '<input type="text" name="%1$s[%2$s]" value="%3$s" %4$s %5$s %6$s>',
4940 $name,
4941 $field_data['field_id'],
4942 $value,
4943 $max_length,
4944 $editable_attr,
4945 $required_attr
4946 );
4947 }
4948
4949 if ( 'textarea' === $field_types[ $field_data['field_type_id'] ] ) {
4950 $html = sprintf(
4951 '<textarea name="%1$s[%2$s]" rows="%3$s" cols="%4$s" maxlength="%5$s" %6$s %7$s>%8$s</textarea>',
4952 $name,
4953 $field_data['field_id'],
4954 $rows,
4955 $cols,
4956 $max_length_textarea,
4957 $editable_attr,
4958 $required_attr,
4959 esc_textarea( $value )
4960 );
4961 }
4962
4963 if ( 'checkbox' === $field_types[ $field_data['field_type_id'] ] ) {
4964 if ( is_array( $field_data['available_fields'] ) ) {
4965 foreach ( $field_data['available_fields'] as $key => $checkbox_data ) {
4966 $html .= sprintf(
4967 '<label class="prflxtrflds-field"><input class="prflxtrflds_input_checkbox" type="checkbox" name="%1$s[%2$s][' . $key . ']" value="%3$s" %4$s %5$s %6$s /> %7$s</label><br />',
4968 $name,
4969 $field_data['field_id'],
4970 $checkbox_data['value_id'],
4971 $editable_attr,
4972 $required_attr,
4973 checked( ! empty( $value ) && is_array( $value ) && in_array( $checkbox_data['value_id'], $value ), true, false ),
4974 $checkbox_data['value_name']
4975 );
4976 }
4977 }
4978 }
4979
4980 if ( 'radio' === $field_types[ $field_data['field_type_id'] ] ) {
4981 if ( is_array( $field_data['available_fields'] ) ) {
4982 foreach ( $field_data['available_fields'] as $key => $radio_data ) {
4983 $html .= sprintf(
4984 '<label class="prflxtrflds-field"><input class="prflxtrflds_input_radio" type="radio" name="%1$s[%2$s]" value="%3$s" %4$s %5$s %6$s > %7$s</label><br />',
4985 $name,
4986 $field_data['field_id'],
4987 $radio_data['value_id'],
4988 $editable_attr,
4989 $required_attr,
4990 checked( ! empty( $value ) && $value === $radio_data['value_id'], true, false ),
4991 $radio_data['value_name']
4992 );
4993 }
4994 }
4995 }
4996
4997 if ( 'select' === $field_types[ $field_data['field_type_id'] ] ) {
4998 if ( is_array( $field_data['available_fields'] ) ) {
4999 $html = sprintf(
5000 '<select name="%1$s[%2$s]" %3$s><option></option>',
5001 $name,
5002 $field_data['field_id'],
5003 $editable_attr
5004 );
5005 foreach ( $field_data['available_fields'] as $key => $option_data ) {
5006 $html .= sprintf(
5007 '<option value="%1$s" %2$s>%3$s</option><br />',
5008 $option_data['value_id'],
5009 selected( ! empty( $value ) && $value === $option_data['value_id'], true, false ),
5010 $option_data['value_name']
5011 );
5012 }
5013 $html .= '</select>';
5014 }
5015 }
5016
5017 if ( 'date' === $field_types[ $field_data['field_type_id'] ] ) {
5018 foreach ( $field_data['available_fields'] as $key => $date_data ) {
5019 $html = sprintf(
5020 '<input class="prflxtrflds_datetimepicker" type="text" name="%1$s[%2$s]" %3$s %4$s value="%6$s">
5021 <input type="hidden" name="prflxtrflds_date_format" value="%5$s">
5022 <input type="hidden" name="prflxtrflds_user_field_datetime[%2$s]" value="%5$s">',
5023 $name,
5024 $field_data['field_id'],
5025 $editable_attr,
5026 $required_attr,
5027 $date_data['value_name'],
5028 $value
5029 );
5030 }
5031 }
5032
5033 if ( 'time' === $field_types[ $field_data['field_type_id'] ] ) {
5034 $time_data = array();
5035 foreach ( $field_data['available_fields'] as $key => $time_data ) {
5036 $time_value[] = $time_data;
5037 $html = sprintf(
5038 '<input class="prflxtrflds_datetimepicker" type="text" name="%1$s[%2$s]" %3$s %4$s value="%6$s">
5039 <input type="hidden" name="prflxtrflds_time_format" value="%5$s">
5040 <input type="hidden" name="prflxtrflds_user_field_datetime[%2$s]" value="%5$s">',
5041 $name,
5042 $field_data['field_id'],
5043 $editable_attr,
5044 $required_attr,
5045 $time_value[ $key ]['value_name'],
5046 $value
5047 );
5048 }
5049 }
5050
5051 if ( 'datetime' === $field_types[ $field_data['field_type_id'] ] ) {
5052 foreach ( $field_data['available_fields'] as $key => $time_data ) {
5053 $datetime_format = maybe_unserialize( $time_data['value_name'] );
5054 $html = sprintf(
5055 '<input class="prflxtrflds_datetimepicker" type="text" name="%1$s[%2$s]" %3$s %4$s value="%7$s">
5056 <input type="hidden" name="prflxtrflds_time_format" value="%6$s">
5057 <input type="hidden" name="prflxtrflds_date_format" value="%5$s">
5058 <input type="hidden" name="prflxtrflds_user_field_datetime[%2$s]" value="%5$s %6$s">',
5059 $name,
5060 $field_data['field_id'],
5061 $editable_attr,
5062 $required_attr,
5063 $datetime_format['date'],
5064 $datetime_format['time'],
5065 $value
5066 );
5067 }
5068 }
5069
5070 if ( 'number' === $field_types[ $field_data['field_type_id'] ] ) {
5071 foreach ( $field_data['available_fields'] as $key => $number_data ) {
5072 $html = sprintf(
5073 '<input type="number" class="prflxtrflds_number" name="%1$s[%2$s]" %3$s %4$s %5$s value="%6$s"/>
5074 <input type="hidden" name="prflxtrflds_user_field_max_number[%2$s]" value="%7$s">',
5075 $name,
5076 $field_data['field_id'],
5077 $max_length_number,
5078 $editable_attr,
5079 $required_attr,
5080 $value,
5081 $number_data['value_name']
5082 );
5083 }
5084 }
5085
5086 if ( 'phone' === $field_types[ $field_data['field_type_id'] ] ) {
5087 foreach ( $field_data['available_fields'] as $key => $phone_data ) {
5088 $html = sprintf(
5089 '<input type="text" class="prflxtrflds_phone" name="%1$s[%2$s]" %4$s %5$s value="%6$s"/>
5090 <input type="hidden" name="prflxtrflds_user_field_pattern[%2$s]" value="%3$s">',
5091 $name,
5092 $field_data['field_id'],
5093 $phone_data['value_name'],
5094 $editable_attr,
5095 $required_attr,
5096 $value
5097 );
5098 }
5099 }
5100
5101 if ( 'url' === $field_types[ $field_data['field_type_id'] ] ) {
5102 $html = sprintf(
5103 '<input type="text" class="medium" name="%1$s[%2$s]" %3$s %4$s %5$s value="%6$s" />',
5104 $name,
5105 $field_data['field_id'],
5106 $max_length,
5107 $editable_attr,
5108 $required_attr,
5109 $value
5110 );
5111 }
5112
5113 if ( 'country' === $field_types[$field_data['field_type_id']] ) {
5114 if ( is_array( $field_data['available_fields'] ) ) {
5115 $html = sprintf(
5116 '<select name="%1$s[%2$s]" %3$s>',
5117 $name,
5118 $field_data['field_id'],
5119 $editable_attr
5120 );
5121 $countries = prflxtrflds_get_country();
5122 foreach ( $countries as $country_id => $country_name ) {
5123 $html .= sprintf(
5124 '<option value="%1$s" %2$s>%3$s</option>',
5125 $country_id,
5126 selected( ! empty( $value ) && $value === $country_id, true, false ),
5127 $country_name
5128 );
5129 }
5130 $html .= '</select>';
5131 }
5132 }
5133
5134
5135 if ( $echo ) {
5136 echo $html;
5137 }
5138
5139 return $html;
5140 }
5141 }
5142
5143 if ( ! function_exists( 'prflxtrflds_user_profile_fields_in_register_form' ) ) {
5144 /**
5145 * This function show fields in registration form
5146 */
5147 function prflxtrflds_user_profile_fields_in_register_form() {
5148
5149 if ( ! is_multisite() ) {
5150
5151 global $wpdb, $hook_suffix;
5152
5153 $role = get_option( 'default_role' );
5154
5155 $args = array(
5156 'roles' => array( $role ),
5157 'show' => 'register_form',
5158 );
5159 $all_entry = prflxtrflds_get_fields( $args );
5160
5161 /** Group result array by field_id */
5162 foreach ( $all_entry as $key => $one_entry ) {
5163 /** Add field values */
5164 $all_entry[ $key ]['available_fields'] = $wpdb->get_results(
5165 $wpdb->prepare(
5166 'SELECT `value_id`, `value_name`
5167 FROM `' . $wpdb->base_prefix . 'prflxtrflds_field_values`
5168 WHERE `field_id` = %d ORDER BY `order`',
5169 $one_entry['field_id']
5170 ),
5171 ARRAY_A
5172 );
5173 }
5174 ?>
5175
5176 <!-- Begin code from user role extra field -->
5177 <table class="form-table">
5178 <?php wp_nonce_field( 'prflxtrflds_user_register_action', 'prflxtrflds_user_register_field' ); ?>
5179 <?php
5180 foreach ( $all_entry as $one_entry ) {
5181 if (
5182 empty( $one_entry['editable'] ) ||
5183 empty( $one_entry['visible'] )
5184 ) {
5185 echo '<input type="hidden" name="prflxtrflds_not_editable[]" value="' . esc_attr( $one_entry['field_id'] ) . '" />';
5186 } else {
5187 ?>
5188 <tr>
5189 <input type="hidden"
5190 name="prflxtrflds_field_name[<?php echo esc_attr( $one_entry['field_id'] ); ?>]"
5191 value="<?php echo esc_attr( $one_entry['field_name'] ); ?>">
5192 <p>
5193 <label>
5194 <?php
5195 esc_html_e( $one_entry['field_name'], 'profile-extra-fields' );
5196 if ( ! empty( $one_entry['required'] ) ) {
5197 echo esc_attr( $one_entry['required'] );
5198 }
5199 ?>
5200 </label>
5201 <br/>
5202 <?php prflxtrflds_get_field_html( $one_entry, 'prflxtrflds_user_field_value', array(), true ); ?>
5203 </p>
5204 <br />
5205 </tr>
5206 <?php
5207 }
5208 }
5209 ?>
5210 </table><!--.form-table-->
5211
5212 <?php
5213 }
5214
5215 }
5216 }
5217
5218 if ( ! function_exists( 'prflxtrflds_login_enqueue_scripts' ) ) {
5219 /**
5220 * Connecting CSS styles to the registration form
5221 */
5222 function prflxtrflds_login_enqueue_scripts() {
5223 if ( isset( $_GET['action'] ) && 'register' === $_GET['action'] ) {
5224 wp_enqueue_style( 'prflxtrflds_stylesheet', plugins_url( 'css/style.css', __FILE__ ), array(), '1.2.4' );
5225
5226 prflxtrflds_enqueue_fields_styles();
5227 }
5228 }
5229 }
5230 if ( ! function_exists( 'prflxtrflds_enqueue_scripts' ) ) {
5231 /**
5232 * Connecting CSS styles to front
5233 */
5234 function prflxtrflds_enqueue_scripts() {
5235 wp_enqueue_style( 'prflxtrflds_front_stylesheet', plugins_url( 'css/front_style.css', __FILE__ ), array(), '1.2.4' );
5236 }
5237 }
5238 if ( ! function_exists( 'prflxtrflds_enqueue_fields_styles' ) ) {
5239 /**
5240 * Connecting JS and CSS styles
5241 */
5242 function prflxtrflds_enqueue_fields_styles() {
5243 wp_enqueue_style( 'jquery.datetimepicker.css', plugins_url( 'css/jquery.datetimepicker.css', __FILE__ ), array(), '1.2.4' );
5244
5245 wp_enqueue_script( 'jquery.datetimepicker.full.min.js', plugins_url( '/js/jquery.datetimepicker.full.min.js', __FILE__ ), array( 'jquery' ), '1.2.4', true );
5246
5247 wp_enqueue_script( 'inputmask.js', plugins_url( '/js/inputmask.js', __FILE__ ), array(), '1.2.4', true );
5248 wp_enqueue_script( 'jquery.inputmask.js', plugins_url( '/js/jquery.inputmask.js', __FILE__ ), array(), '1.2.4', true );
5249
5250 wp_enqueue_script( 'prflxtrflds_profile_script', plugins_url( '/js/profile_script.js', __FILE__ ), array(), '1.2.4', true );
5251 $script_vars = array(
5252 'prflxtrflds_nonce' => wp_create_nonce( plugin_basename( __FILE__ ), 'prflxtrflds_ajax_nonce_field' ),
5253 );
5254 wp_localize_script( 'prflxtrflds_profile_script', 'prflxtrflds_vars', $script_vars );
5255 }
5256 }
5257
5258 if ( ! function_exists( 'prflxtrflds_save_data_from_registration_form' ) ) {
5259 /**
5260 * Save user data from register form
5261 *
5262 * @param number $user_id User ID.
5263 */
5264 function prflxtrflds_save_data_from_registration_form( $user_id ) {
5265 if ( 0 !== $user_id ) {
5266
5267 global $wpdb;
5268
5269 if ( ( isset( $_POST['prflxtrflds_user_register_field'] ) && wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['prflxtrflds_user_register_field'] ) ), 'prflxtrflds_user_register_action' ) ) || ( isset( $_POST['prflxtrflds_user_fields'] ) && wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['prflxtrflds_user_fields'] ) ), 'prflxtrflds_user_field_action' ) ) ) {
5270
5271 /** If array exists ( exist available fields for current user ), remove old data */
5272 if ( ! empty( $_POST['prflxtrflds_not_editable'] ) ) {
5273 /** Execute not_editable fields */
5274 $prflxtrflds_not_editable = array_map( 'absint', $_POST['prflxtrflds_not_editable'] );
5275 $not_editable_ids = "'" . implode( "','", $prflxtrflds_not_editable ) . "'";
5276
5277 $wpdb->query(
5278 $wpdb->prepare(
5279 'DELETE FROM `' . $wpdb->base_prefix . 'prflxtrflds_user_field_data`
5280 WHERE `user_id` = %d
5281 AND `field_id` NOT IN (' . $not_editable_ids . ')',
5282 $user_id
5283 )
5284 );
5285 } else {
5286 $wpdb->delete(
5287 $wpdb->base_prefix . 'prflxtrflds_user_field_data',
5288 array( 'user_id' => $user_id )
5289 );
5290 }
5291
5292 /** Create array with user values */
5293 if ( isset( $_POST['prflxtrflds_user_field_value'] ) ) {
5294 foreach ( $_POST['prflxtrflds_user_field_value'] as $id => $val ) {
5295 if ( ! empty( $val ) ) {
5296 if ( is_array( $val ) ) {
5297 /** For checkboxes */
5298 foreach ( $val as $user_value ) {
5299 /** Insert or update value */
5300 $wpdb->replace(
5301 $wpdb->base_prefix . 'prflxtrflds_user_field_data',
5302 array(
5303 'user_id' => esc_sql( $user_id ),
5304 'field_id' => esc_sql( absint( $id ) ),
5305 'user_value' => esc_sql( sanitize_text_field( wp_unslash( $user_value ) ) ),
5306 )
5307 );
5308 }
5309 } else {
5310 /** Insert or update value */
5311 $wpdb->replace(
5312 $wpdb->base_prefix . 'prflxtrflds_user_field_data',
5313 array(
5314 'user_id' => esc_sql( $user_id ),
5315 'field_id' => esc_sql( absint( $id ) ),
5316 'user_value' => esc_sql( sanitize_text_field( wp_unslash( $val ) ) ),
5317 )
5318 );
5319 }
5320 }
5321 }
5322 }
5323 }
5324 }
5325 }
5326 }
5327
5328 if ( ! function_exists( 'prflxtrflds_register_check' ) ) {
5329 /**
5330 * Form validation
5331 *
5332 * @param bool $allow Flag for allow.
5333 */
5334 function prflxtrflds_register_check( $allow ) {
5335 global $wpdb;
5336
5337 $role = get_option( 'default_role' );
5338
5339 $args = array(
5340 'roles' => array( $role ),
5341 'visible' => 1,
5342 'editable' => 1,
5343 'required' => true,
5344 'show' => 'register_form',
5345 );
5346 $required_entries = prflxtrflds_get_fields( $args );
5347 $error_fields = array();
5348
5349 if ( ! empty( $required_entries ) ) {
5350 foreach ( $required_entries as $entry ) {
5351 if ( empty( $_POST['prflxtrflds_user_field_value'][ $entry['field_id'] ] ) ) {
5352 $error_fields[] = $entry['field_name'];
5353 }
5354 }
5355 }
5356
5357 if ( ! empty( $error_fields ) ) {
5358 $message = sprintf(
5359 '%1$s %2$s: %3$s',
5360 __( 'Please fill all required fields.', 'profile-extra-fields' ),
5361 __( 'The following fields are required', 'profile-extra-fields' ),
5362 implode( ', ', $error_fields )
5363 );
5364 $allow = new WP_Error( 'prflxtrflds_error', $message );
5365 }
5366
5367 return $allow;
5368 }
5369 }
5370
5371 if ( ! function_exists( 'prflxtrflds_admin_style' ) ) {
5372 /**
5373 * Add css styles to the admin panel
5374 */
5375 function prflxtrflds_admin_style() {
5376 wp_enqueue_style( 'prflxtrflds_style_admin', plugins_url( 'css/style.css', __FILE__ ), array(), '1.2.4' );
5377 }
5378 }
5379
5380 if ( ! function_exists( 'prflxtrflds_register_error' ) ) {
5381 /**
5382 * Send errors to registration user form
5383 */
5384 function prflxtrflds_register_error( $errors, $update = null, $user = null ) {
5385 $required_array = array();
5386
5387 if ( isset( $_POST['prflxtrflds_user_register_field'] ) && wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['prflxtrflds_user_register_field'] ) ), 'prflxtrflds_user_register_action' ) ) {
5388
5389 if ( ! empty( $_POST['prflxtrflds_required'] ) ) {
5390 /** Get all reqired ids */
5391 foreach ( $_POST['prflxtrflds_required'] as $required_id => $required_value ) {
5392 if ( empty( $_POST['prflxtrflds_user_field_value'][ $required_id ] ) ) {
5393 /** Error for non-textfield */
5394 $name = isset( $_POST['prflxtrflds_field_name'][ $required_id ] ) ? sanitize_text_field( wp_unslash( $_POST['prflxtrflds_field_name'][ $required_id ] ) ) : '';
5395 $errors->add( 'prflxtrflds_required_error', sprintf( __( 'Required field %1$s is not filled. Data was not saved!', 'profile-extra-fields' ), '<strong>' . $name . '</strong>' ) );
5396 $required_array[] = $required_id;
5397 }
5398 }
5399 }
5400 if ( ! empty( $_POST['prflxtrflds_user_field_pattern'] ) ) {
5401 foreach ( $_POST['prflxtrflds_user_field_pattern'] as $field_id => $pattern ) {
5402 if ( ! empty( $_POST['prflxtrflds_user_field_value'][ $field_id ] ) && ! in_array( $field_id, $required_array ) ) {
5403 if ( ! preg_match( '/^' . str_replace( '\*', '[0-9]', preg_quote( $pattern ) ) . '$/', sanitize_text_field( wp_unslash( $_POST['prflxtrflds_user_field_value'][ $field_id ] ) ) ) ) {
5404 $name = isset( $_POST['prflxtrflds_field_name'][ $field_id ] ) ? sanitize_text_field( wp_unslash( $_POST['prflxtrflds_field_name'][ $field_id ] ) ) : '';
5405 $errors->add( 'prflxtrflds_match_error', sprintf( __( 'Field %1$s does not match %2$s. Data was not saved!', 'profile-extra-fields' ), '<strong>' . $name . '</strong>', '<strong>' . $pattern . '</strong>' ) );
5406 }
5407 }
5408 }
5409 }
5410
5411 if ( ! empty( $_POST['prflxtrflds_user_field_max_number'] ) ) {
5412 foreach ( $_POST['prflxtrflds_user_field_max_number'] as $field_id => $max_number ) {
5413 if ( ! empty( $_POST['prflxtrflds_user_field_value'][ $field_id ] ) &&
5414 ! in_array( $field_id, $required_array )
5415 ) {
5416 $max_number = intval( $max_number );
5417 if ( $max_number > 0 &&
5418 intval( $_POST['prflxtrflds_user_field_value'][ $field_id ] ) > $max_number
5419 ) {
5420 $_POST['prflxtrflds_user_field_value'][ $field_id ] = $max_number;
5421 }
5422 }
5423 }
5424 }
5425
5426 if ( ! empty( $_POST['prflxtrflds_user_field_datetime'] ) ) {
5427 foreach ( $_POST['prflxtrflds_user_field_datetime'] as $field_id => $pattern ) {
5428 if ( ! empty( $_POST['prflxtrflds_user_field_value'][ $field_id ] ) &&
5429 ! in_array( $field_id, $required_array )
5430 ) {
5431 $pattern = trim( str_replace( 'T', '', $pattern ) );
5432 if ( function_exists( 'date_create_from_format' ) ) {
5433 $d = date_create_from_format( $pattern, sanitize_text_field( wp_unslash( $_POST['prflxtrflds_user_field_value'][ $field_id ] ) ) );
5434 if ( ! $d || ! $d->format( $pattern ) === $_POST['prflxtrflds_user_field_value'][ $field_id ] ) {
5435 $name = isset( $_POST['prflxtrflds_field_name'][ $field_id ] ) ? sanitize_text_field( wp_unslash( $_POST['prflxtrflds_field_name'][ $field_id ] ) ) : '';
5436 $errors->add( 'prflxtrflds_match_error', sprintf( __( 'Field %1$s does not match %2$s. Data was not saved!', 'profile-extra-fields' ), '<strong>' . $name . '</strong>', '<strong>' . $pattern . '</strong>' ) );
5437 }
5438 } elseif ( ! strtotime( sanitize_text_field( wp_unslash( $_POST['prflxtrflds_user_field_value'][ $field_id ] ) ) ) ) {
5439 $name = isset( $_POST['prflxtrflds_field_name'][ $field_id ] ) ? sanitize_text_field( wp_unslash( $_POST['prflxtrflds_field_name'][ $field_id ] ) ) : '';
5440 $errors->add( 'prflxtrflds_match_error', sprintf( __( 'Field %1$s does not match %2$s. Data was not saved!', 'profile-extra-fields' ), '<strong>' . $name . '</strong>', '<strong>' . $pattern . '</strong>' ) );
5441 }
5442 }
5443 }
5444 }
5445 }
5446
5447 return $errors;
5448 }
5449 }
5450
5451 if ( ! function_exists( 'prflxtrflds_display_front_script' ) ) {
5452 /**
5453 * Front JS and CSS
5454 */
5455 function prflxtrflds_display_front_script() {
5456 global $prflxtrflds_front_shortcode;
5457 if ( true === $prflxtrflds_front_shortcode ) {
5458 wp_enqueue_style( 'jquery.datetimepicker.css', plugins_url( 'css/jquery.datetimepicker.css', __FILE__ ), array(), '1.2.4' );
5459
5460 wp_enqueue_script( 'jquery.datetimepicker.full.min.js', plugins_url( '/js/jquery.datetimepicker.full.min.js', __FILE__ ), array( 'jquery' ), '1.2.4', true );
5461
5462 wp_enqueue_script( 'inputmask.js', plugins_url( '/js/inputmask.js', __FILE__ ), array(), '1.2.4', true );
5463 wp_enqueue_script( 'jquery.inputmask.js', plugins_url( '/js/jquery.inputmask.js', __FILE__ ), array(), '1.2.4', true );
5464
5465 wp_enqueue_script( 'prflxtrflds_profile_script', plugins_url( '/js/profile_script.js', __FILE__ ), array(), '1.2.4', true );
5466 }
5467 }
5468 }
5469
5470 if ( ! function_exists( 'prflxtrflds_wp_new_user_notification_email_admin' ) ) {
5471 /**
5472 * Admin email message for new user
5473 *
5474 * @param array $wp_new_user_notification_email_admin Email array for admin.
5475 * @param object $user User object.
5476 * @param string $blogname Blog name.
5477 */
5478 function prflxtrflds_wp_new_user_notification_email_admin( $wp_new_user_notification_email_admin, $user, $blogname ) {
5479 global $prflxtrflds_options;
5480 $prflxtrflds_field_message = '';
5481
5482 if ( isset( $_POST['prflxtrflds_field_name'], $_POST['prflxtrflds_user_field_value'] ) ) {
5483 $prflxtrflds_field_name = array_map( 'sanitize_text_field', array_map( 'wp_unslash', $_POST['prflxtrflds_field_name'] ) );
5484 foreach ( $prflxtrflds_field_name as $key => $name ) {
5485 $value = isset( $_POST['prflxtrflds_user_field_value'][ $key ] ) ? ( is_array( $_POST['prflxtrflds_user_field_value'][ $key ] ) ? implode( ',', array_map( 'sanitize_text_field', array_map( 'wp_unslash', $_POST['prflxtrflds_user_field_value'][ $key ] ) ) ) : sanitize_text_field( wp_unslash( $_POST['prflxtrflds_user_field_value'][ $key ] ) ) ) : '';
5486 $prflxtrflds_field_message .= $name . ': ' . $value . "\r\n\r\n";
5487 }
5488 }
5489
5490 if ( isset( $prflxtrflds_options['notify_admin_register'] ) && 1 === $prflxtrflds_options['notify_admin_register'] ) {
5491 if ( ! empty( $prflxtrflds_options['notify_admin_register_subject'] ) ) {
5492 $wp_new_user_notification_email_admin['subject'] = $prflxtrflds_options['notify_admin_register_subject'];
5493 }
5494 if ( ! empty( $prflxtrflds_options['notify_admin_register_message'] ) ) {
5495 $wp_new_user_notification_email_admin['message'] = $prflxtrflds_options['notify_admin_register_message'];
5496 $wp_new_user_notification_email_admin['message'] = str_replace( array( '{username}', '{email}', '{date}', '{profile_extra_fields}', '{dashboardurl}' ), array( $user->user_login, $user->user_email, wp_date( get_option( 'date_format' ), admin_url() ), $prflxtrflds_field_message ), $wp_new_user_notification_email_admin['message'] );
5497 }
5498 } else {
5499 if ( isset( $_POST['prflxtrflds_field_name'], $_POST['prflxtrflds_user_field_value'] ) ) {
5500 $wp_new_user_notification_email_admin['message'] .= "\r\n" . $prflxtrflds_field_message . "\r\n";
5501 }
5502 }
5503
5504 return $wp_new_user_notification_email_admin;
5505 }
5506 }
5507
5508 if ( ! function_exists( 'prflxtrflds_wp_new_user_notification_email_user' ) ) {
5509 /**
5510 * Email message to new user
5511 *
5512 * @param array $wp_new_user_notification_email Email array for user.
5513 * @param object $user User object.
5514 * @param string $blogname Blog name.
5515 */
5516 function prflxtrflds_wp_new_user_notification_email_user( $wp_new_user_notification_email, $user, $blogname ) {
5517 global $prflxtrflds_options;
5518
5519 if ( isset( $prflxtrflds_options['notify_user_register'] ) && 1 === $prflxtrflds_options['notify_user_register'] ) {
5520 if ( ! empty( $prflxtrflds_options['notify_user_register_subject'] ) ) {
5521 $wp_new_user_notification_email['subject'] = $prflxtrflds_options['notify_user_register_subject'];
5522 }
5523 if ( ! empty( $prflxtrflds_options['notify_user_register_message'] ) ) {
5524 $key = get_password_reset_key( $user );
5525 if ( ! is_wp_error( $key ) ) {
5526 $login_url = network_site_url( 'wp-login.php?login=' . rawurlencode( $user->user_login ) . "&key=$key&action=rp", 'login' ) . "\r\n\r\n" . wp_login_url();
5527
5528 $wp_new_user_notification_email['message'] = $prflxtrflds_options['notify_user_register_message'];
5529 $wp_new_user_notification_email['message'] = str_replace( array( '{username}', '{loginurl}' ), array( $user->user_login, $login_url ), $wp_new_user_notification_email['message'] );
5530 }
5531 }
5532 }
5533
5534 return $wp_new_user_notification_email;
5535 }
5536 }
5537
5538 if ( ! function_exists( 'prflxtrflds_get_lgnrgstrfrm_fields_table' ) ) {
5539 /**
5540 * Get BWS Login Register plugin table
5541 *
5542 * @param string $content Content.
5543 */
5544 function prflxtrflds_get_lgnrgstrfrm_fields_table( $content, $form = '' ) {
5545 global $wpdb, $prflxtrflds_options;
5546
5547 prflxtrflds_settings();
5548
5549 /* Group result array by field_id */
5550
5551 $args = array( 'show' => 'bws_login_register_form' );
5552 $fields = prflxtrflds_get_fields( $args );
5553
5554 foreach ( $fields as $key => $field ) {
5555 /* add field values */
5556 $fields[ $key ]['available_fields'] = $wpdb->get_results(
5557 $wpdb->prepare(
5558 'SELECT `value_id`, `value_name`
5559 FROM `' . $wpdb->base_prefix . 'prflxtrflds_field_values`
5560 WHERE `field_id` = %d ORDER BY `order`',
5561 $field['field_id']
5562 ),
5563 ARRAY_A
5564 );
5565 }
5566 $input = wp_nonce_field( 'prflxtrflds_user_register_action', 'prflxtrflds_user_register_field', true, false );;
5567
5568 foreach ( $fields as $data ) {
5569 if (
5570 empty( $data['editable'] ) ||
5571 empty( $data['visible'] )
5572 ) {
5573 $input .= '<div class="form-row"><input type="hidden" name="prflxtrflds_not_editable[]" value="' . esc_attr( $data['field_id'] ) . '" />';
5574 } else {
5575 $input .= '<div class="form-row"><input type="hidden" name="prflxtrflds_field_name[' . esc_attr( $data['field_id'] ) . ']" value="' . esc_attr( $data['field_name'] ) . '">
5576 <label>' . $data['field_name'] . ' ';
5577 if ( ! empty( $data['required'] ) ) {
5578 $input .= '<span>' . $data['required'] . '</span>';
5579 }
5580 $input .= '</label>' . prflxtrflds_get_field_html( $data, 'prflxtrflds_user_field_value', array( 'placeholder="' . $data['description'] . '"' ) );
5581 $input .= '</div>';
5582 }
5583 }
5584
5585 prflxtrflds_enqueue_fields_styles();
5586
5587 return $content . $input;
5588 }
5589 }
5590
5591 register_activation_hook( __FILE__, 'prflxtrflds_activation' );
5592 /** Add css styles to the admin panel */
5593 add_action( 'admin_head', 'prflxtrflds_admin_style' );
5594 /** Bws menu */
5595 add_action( 'admin_menu', 'prflxtrflds_admin_menu' );
5596 /** Plugin init */
5597 add_action( 'init', 'prflxtrflds_init' );
5598 add_action( 'admin_init', 'prflxtrflds_admin_init' );
5599 add_action( 'plugins_loaded', 'prflxtrflds_plugins_loaded' );
5600 add_filter( 'set-screen-option', 'prflxtrflds_set_screen_options', 10, 3 );
5601 /** This links under plugin name */
5602 add_filter( 'plugin_action_links', 'prflxtrflds_plugin_action_links', 10, 2 );
5603 /** This links in plugin description */
5604 add_filter( 'plugin_row_meta', 'prflxtrflds_register_plugin_links', 10, 2 );
5605 /** Add admin notices */
5606 add_action( 'admin_notices', 'prflxtrflds_admin_notices' );
5607 /** Add basic shortcode*/
5608 add_shortcode( 'prflxtrflds_user_data', 'prflxtrflds_show_data' );
5609 add_shortcode( 'prflxtrflds_field', 'prflxtrflds_show_field' );
5610 add_shortcode( 'prflxtrflds_user_data_edit_form', 'prflxtrflds_show_edit_form' );
5611 add_filter( 'widget_text', 'do_shortcode' );
5612 /** Update table if user create */
5613 add_action( 'user_register', 'prflxtrflds_update_user_roles', 10, 2 );
5614 /** Update table on edit user profile */
5615 add_action( 'profile_update', 'prflxtrflds_update_user_roles', 10, 2 );
5616 /** Update on set user role */
5617 add_action( 'set_user_role', 'prflxtrflds_update_user_roles', 10, 2 );
5618 /** Show info in user profile page*/
5619 add_action( 'show_user_profile', 'prflxtrflds_fields_table' );
5620 add_action( 'edit_user_profile', 'prflxtrflds_fields_table' );
5621 /** Add custom fields to the user registration form */
5622 add_action( 'user_new_form', 'prflxtrflds_fields_table' );
5623 /** Save user information where Save button is pressed */
5624 add_action( 'edit_user_profile_update', 'prflxtrflds_save_user_data' );
5625 add_action( 'personal_options_update', 'prflxtrflds_save_user_data' );
5626 add_filter( 'bws_bkng_billing_data', 'prflxtrflds_save_booking_fields' );
5627 add_filter( 'bws_bkng_order_errors', 'prflxtrflds_add_error_message', 10, 2 );
5628 /** Load scripts */
5629 add_action( 'admin_enqueue_scripts', 'prflxtrflds_load_script' );
5630 /** Check fields from user settings page */
5631 add_filter( 'user_profile_update_errors', 'prflxtrflds_create_user_error' );
5632 /** Adding fields to the admin email after registering a new user */
5633 add_filter( 'wp_new_user_notification_email_admin', 'prflxtrflds_wp_new_user_notification_email_admin', 10, 3 );
5634 add_filter( 'wp_new_user_notification_email', 'prflxtrflds_wp_new_user_notification_email_user', 10, 3 );
5635 /** Save order through ajax */
5636 add_action( 'wp_ajax_prflxtrflds_table_order', 'prflxtrflds_table_order' );
5637 add_action( 'wp_ajax_prflxtrflds_get_users', 'prflxtrflds_get_users' );
5638 add_action( 'wp_ajax_prflxtrflds_get_roles', 'prflxtrflds_get_roles' );
5639 add_action( 'wp_ajax_prflxtrflds_get_fields_name', 'prflxtrflds_get_fields_name' );
5640 /** Custom filter for bws button in tinyMCE */
5641 add_filter( 'bws_shortcode_button_content', 'prflxtrflds_shortcode_button_content' );
5642 /** Add fields to the user registration form */
5643 add_action( 'register_form', 'prflxtrflds_user_profile_fields_in_register_form' );
5644 /** Connecting CSS styles to the registration form. */
5645 add_action( 'login_enqueue_scripts', 'prflxtrflds_login_enqueue_scripts', 1 );
5646 add_action( 'wp_enqueue_scripts', 'prflxtrflds_enqueue_scripts' );
5647 /** Save user data from register form */
5648 add_action( 'user_register', 'prflxtrflds_save_data_from_registration_form' );
5649 /** Form validation */
5650 add_filter( 'registration_errors', 'prflxtrflds_register_check', 10, 1 );
5651 add_filter( 'registration_errors', 'prflxtrflds_register_error' );
5652 /** Hook for display script in footer */
5653 add_action( 'wp_footer', 'prflxtrflds_display_front_script' );
5654 /* BWS Login Register compatibility */
5655 add_filter( 'lgnrgstrfrm_add_field', 'prflxtrflds_get_lgnrgstrfrm_fields_table', 10, 2 );
5656