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