PluginProbe
Profile Extra Fields by BestWebSoft / 1.2.9
Profile Extra Fields by BestWebSoft v1.2.9
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 1.2.9, at profile-extra-fields.php

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