| 1 |
<?php |
| 2 |
/** |
| 3 |
* UsersWP Tabs in form builder |
| 4 |
* |
| 5 |
* @author AyeCode |
| 6 |
* @category Admin |
| 7 |
* @package userswp/Admin |
| 8 |
* @version 1.0.24 |
| 9 |
*/ |
| 10 |
|
| 11 |
if ( ! defined( 'ABSPATH' ) ) { |
| 12 |
exit; // Exit if accessed directly |
| 13 |
} |
| 14 |
|
| 15 |
if ( ! class_exists( 'UsersWP_Settings_Profile_Tabs', false ) ) { |
| 16 |
|
| 17 |
/** |
| 18 |
* UsersWP_Settings_Email. |
| 19 |
*/ |
| 20 |
class UsersWP_Settings_Profile_Tabs { |
| 21 |
|
| 22 |
public function __construct() { |
| 23 |
|
| 24 |
add_filter( 'uwp_form_builder_tabs_array', array( $this, 'form_builder_tab_items' ), 99 ); |
| 25 |
add_filter( 'uwp_form_builder_available_fields_head', array( $this, 'tabs_available_fields_head' ), 10, 2 ); |
| 26 |
add_filter( 'uwp_form_builder_available_fields_note', array( $this, 'tabs_available_fields_note' ), 10, 2 ); |
| 27 |
add_filter( 'uwp_form_builder_selected_fields_head', array( $this, 'tabs_selected_fields_head' ), 10, 2 ); |
| 28 |
add_filter( 'uwp_form_builder_selected_fields_note', array( $this, 'tabs_selected_fields_note' ), 10, 2 ); |
| 29 |
add_action( 'uwp_manage_available_fields', array( $this, 'manage_tabs_available_fields' ), 10, 1 ); |
| 30 |
add_action( 'uwp_manage_available_fields_predefined', array( $this, 'manage_tabs_predefined_fields' ), 10, 1 ); |
| 31 |
add_action( 'uwp_manage_available_fields_custom', array( $this, 'manage_available_fields_custom' ), 10, 1 ); |
| 32 |
add_action( 'uwp_manage_selected_fields', array( $this, 'manage_tabs_selected_fields' ), 10, 1 ); |
| 33 |
add_action( 'wp_ajax_uwp_ajax_profile_tabs_action', array( $this, 'tabs_ajax_handler' ) ); |
| 34 |
} |
| 35 |
|
| 36 |
/** |
| 37 |
* Add a tab to form builder |
| 38 |
* |
| 39 |
* @since 1.0.0 |
| 40 |
* @package userswp |
| 41 |
* |
| 42 |
* @param array $tabs Tabs |
| 43 |
* |
| 44 |
* @return array $tabs |
| 45 |
*/ |
| 46 |
public function form_builder_tab_items( $tabs ) { |
| 47 |
$tabs['profile-tabs'] = __( 'Profile Tabs', 'userswp' ); |
| 48 |
|
| 49 |
return $tabs; |
| 50 |
} |
| 51 |
|
| 52 |
/** |
| 53 |
* Add a tab to form builder |
| 54 |
* |
| 55 |
* @since 2.0.0 |
| 56 |
* @package userswp |
| 57 |
* |
| 58 |
* @param string $heading Heading |
| 59 |
* @param string $form_type Form type |
| 60 |
* |
| 61 |
* @return string |
| 62 |
*/ |
| 63 |
public function tabs_available_fields_head( $heading, $form_type ) { |
| 64 |
switch ( $form_type ) { |
| 65 |
case 'profile-tabs': |
| 66 |
$heading = __( 'Available profile tabs.', 'userswp' ); |
| 67 |
break; |
| 68 |
} |
| 69 |
|
| 70 |
return $heading; |
| 71 |
} |
| 72 |
|
| 73 |
/** |
| 74 |
* Add a note above available fields. |
| 75 |
* |
| 76 |
* @since 2.0.0 |
| 77 |
* @package userswp |
| 78 |
* |
| 79 |
* @param string $note Note to display |
| 80 |
* @param string $form_type Form type |
| 81 |
* |
| 82 |
* @return string |
| 83 |
*/ |
| 84 |
public function tabs_available_fields_note( $note, $form_type ) { |
| 85 |
switch ( $form_type ) { |
| 86 |
case 'profile-tabs': |
| 87 |
$note = __( 'Fields that can be added to the profile tabs.', 'userswp' ); |
| 88 |
break; |
| 89 |
} |
| 90 |
|
| 91 |
return $note; |
| 92 |
} |
| 93 |
|
| 94 |
/** |
| 95 |
* Heading for the selected fields |
| 96 |
* |
| 97 |
* @since 2.0.0 |
| 98 |
* @package userswp |
| 99 |
* |
| 100 |
* @param string $heading Heading to display |
| 101 |
* @param string $form_type Form type |
| 102 |
* |
| 103 |
* @return string |
| 104 |
*/ |
| 105 |
public function tabs_selected_fields_head( $heading, $form_type ) { |
| 106 |
switch ( $form_type ) { |
| 107 |
case 'profile-tabs': |
| 108 |
$heading = __( 'Profile Tabs', 'userswp' ); |
| 109 |
break; |
| 110 |
} |
| 111 |
|
| 112 |
return $heading; |
| 113 |
} |
| 114 |
|
| 115 |
/** |
| 116 |
* Add a note above selected fields. |
| 117 |
* |
| 118 |
* @since 2.0.0 |
| 119 |
* @package userswp |
| 120 |
* |
| 121 |
* @param string $note Note to display |
| 122 |
* @param string $form_type Form type |
| 123 |
* |
| 124 |
* @return string |
| 125 |
*/ |
| 126 |
public function tabs_selected_fields_note( $note, $form_type ) { |
| 127 |
switch ( $form_type ) { |
| 128 |
case 'profile-tabs': |
| 129 |
$note = __( 'Choose the items from left panel to create the profile tabs.', 'userswp' ); |
| 130 |
break; |
| 131 |
} |
| 132 |
|
| 133 |
return $note; |
| 134 |
} |
| 135 |
|
| 136 |
/** |
| 137 |
* Display available fields |
| 138 |
* |
| 139 |
* @since 2.0.0 |
| 140 |
* @package userswp |
| 141 |
* |
| 142 |
* @param string $form_type Form type |
| 143 |
* |
| 144 |
*/ |
| 145 |
public function manage_tabs_available_fields( $form_type ) { |
| 146 |
if ( 'profile-tabs' == $form_type ) { |
| 147 |
$this->tabs_available_fields( $form_type ); |
| 148 |
} |
| 149 |
} |
| 150 |
|
| 151 |
/** |
| 152 |
* Display predefined fields |
| 153 |
* |
| 154 |
* @since 2.0.0 |
| 155 |
* @package userswp |
| 156 |
* |
| 157 |
* @param string $form_type Form type |
| 158 |
* |
| 159 |
*/ |
| 160 |
public function manage_tabs_predefined_fields( $form_type ) { |
| 161 |
if ( 'profile-tabs' == $form_type ) { |
| 162 |
$this->tabs_predefined_fields( $form_type ); |
| 163 |
} |
| 164 |
} |
| 165 |
|
| 166 |
/** |
| 167 |
* Display custom fields |
| 168 |
* |
| 169 |
* @since 2.0.0 |
| 170 |
* @package userswp |
| 171 |
* |
| 172 |
* @param string $form_type Form type |
| 173 |
* |
| 174 |
*/ |
| 175 |
public function manage_available_fields_custom( $form_type ) { |
| 176 |
if ( 'profile-tabs' == $form_type ) { |
| 177 |
$this->tabs_custom_fields( $form_type ); |
| 178 |
} |
| 179 |
} |
| 180 |
|
| 181 |
/** |
| 182 |
* Display selected fields |
| 183 |
* |
| 184 |
* @since 2.0.0 |
| 185 |
* @package userswp |
| 186 |
* |
| 187 |
* @param string $form_type Form type |
| 188 |
* |
| 189 |
*/ |
| 190 |
public function manage_tabs_selected_fields( $form_type ) { |
| 191 |
if ( 'profile-tabs' == $form_type ) { |
| 192 |
$this->tabs_selected_fields( $form_type ); |
| 193 |
} |
| 194 |
} |
| 195 |
|
| 196 |
/** |
| 197 |
* Display custom fields |
| 198 |
* |
| 199 |
* @since 2.0.0 |
| 200 |
* @package userswp |
| 201 |
* |
| 202 |
* @param string $form_type Form type |
| 203 |
* |
| 204 |
*/ |
| 205 |
public function tabs_custom_fields( $form_type ) { |
| 206 |
// insert the required code for the SD button. |
| 207 |
$js_insert_function = $this->insert_shortcode_function(); |
| 208 |
WP_Super_Duper::shortcode_insert_button( '', $js_insert_function ); |
| 209 |
|
| 210 |
$fields = array(); |
| 211 |
$fields[] = array( |
| 212 |
'tab_type' => 'shortcode', |
| 213 |
'tab_name' => __( 'Shortcode', 'userswp' ), |
| 214 |
'tab_icon' => 'fas fa-cubes', |
| 215 |
'tab_key' => '', |
| 216 |
'tab_content' => '', |
| 217 |
|
| 218 |
); |
| 219 |
|
| 220 |
?> |
| 221 |
<input type="hidden" name="form_type" id="form_type" value="<?php echo esc_attr( $form_type ); ?>"/> |
| 222 |
<input type="hidden" name="manage_field_type" class="manage_field_type" value="profile_tabs"> |
| 223 |
<?php wp_nonce_field( 'uwp-admin-settings' ); ?> |
| 224 |
<ul class="row row-cols-2 px-2 mb-0"> |
| 225 |
<?php |
| 226 |
|
| 227 |
foreach ( $fields as $id => $field ) { |
| 228 |
|
| 229 |
?> |
| 230 |
<li class="col px-1" > |
| 231 |
<a id="uwp-<?php echo esc_attr( $field['tab_key'] ); ?>" |
| 232 |
data-field-custom-type="predefined" |
| 233 |
class="uwp-draggable-form-itemsx btn btn-sm d-block m-0 btn-outline-gray text-dark text-start" |
| 234 |
data-tab_layout="profile" |
| 235 |
data-field-type-key="uwp-<?php echo esc_attr( $field['tab_key'] ); ?>" |
| 236 |
data-tab_type="<?php echo isset( $field['tab_type'] ) ? esc_attr( $field['tab_type'] ) : ''; ?>" |
| 237 |
data-tab_name="<?php echo isset( $field['tab_name'] ) ? esc_attr( $field['tab_name'] ) : ''; ?>" |
| 238 |
data-tab_icon="<?php echo isset( $field['tab_icon'] ) ? esc_attr( $field['tab_icon'] ) : ''; ?>" |
| 239 |
data-tab_key="<?php echo isset( $field['tab_key'] ) ? esc_attr( $field['tab_key'] ) : ''; ?>" |
| 240 |
data-tab_level="<?php echo isset( $field['tab_level'] ) ? esc_attr( $field['tab_level'] ) : 0; ?>" |
| 241 |
data-tab_parent="<?php echo isset( $field['tab_parent'] ) ? esc_attr( $field['tab_parent'] ) : ''; ?>" |
| 242 |
data-tab_content="<?php echo isset( $field['tab_content'] ) ? esc_attr( $field['tab_content'] ) : ''; ?>" |
| 243 |
data-tab_privacy="<?php echo isset( $field['tab_privacy'] ) ? esc_attr( $field['tab_privacy'] ) : 0; ?>" |
| 244 |
data-user_decided="<?php echo isset( $field['user_decided'] ) ? esc_attr( $field['user_decided'] ) : 0; ?>" |
| 245 |
href="javascript:void(0);"> |
| 246 |
|
| 247 |
<?php |
| 248 |
$icon = $field['tab_icon']; |
| 249 |
if ( uwp_is_fa_icon( $icon ) ) { |
| 250 |
$tab_icon = '<i class="' . esc_attr( $icon ) . '" aria-hidden="true"></i>'; |
| 251 |
} elseif ( uwp_is_icon_url( $icon ) ) { |
| 252 |
$tab_icon = '<b style="background-image: url("' . esc_url( $icon ) . '")"></b>'; |
| 253 |
} else { |
| 254 |
$tab_icon = '<i class="fas fa-cog" aria-hidden="true"></i>'; |
| 255 |
} |
| 256 |
?> |
| 257 |
<?php echo $tab_icon; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?> |
| 258 |
<?php echo esc_attr( $field['tab_name'] ); ?> |
| 259 |
</a> |
| 260 |
</li> |
| 261 |
<?php |
| 262 |
} |
| 263 |
?> |
| 264 |
</ul> |
| 265 |
<?php |
| 266 |
} |
| 267 |
|
| 268 |
/** |
| 269 |
* Insert the shortcode function. |
| 270 |
* |
| 271 |
* @return string |
| 272 |
*/ |
| 273 |
public function insert_shortcode_function() { |
| 274 |
ob_start(); |
| 275 |
?> |
| 276 |
function sd_insert_shortcode(){ |
| 277 |
$shortcode = jQuery('#sd-shortcode-output').val(); |
| 278 |
if($shortcode){ |
| 279 |
jQuery('#uwp-field-settings textarea').val($shortcode); |
| 280 |
tb_remove(); |
| 281 |
} |
| 282 |
} |
| 283 |
<?php |
| 284 |
return ob_get_clean(); |
| 285 |
} |
| 286 |
|
| 287 |
/** |
| 288 |
* Display available tabs fields |
| 289 |
* |
| 290 |
* @since 2.0.0 |
| 291 |
* @package userswp |
| 292 |
* |
| 293 |
* @param string $form_type Form type |
| 294 |
* |
| 295 |
*/ |
| 296 |
public function tabs_available_fields( $form_type ) { |
| 297 |
global $wpdb; |
| 298 |
|
| 299 |
$form_id = ! empty( $_REQUEST['form'] ) ? (int) $_REQUEST['form'] : 1; |
| 300 |
|
| 301 |
$table_name = uwp_get_table_prefix() . 'uwp_profile_tabs'; |
| 302 |
|
| 303 |
$existing_fields = $wpdb->get_results( 'select tab_key from ' . $table_name . " where form_type ='" . $form_type . "'" ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching |
| 304 |
|
| 305 |
$existing_field_ids = array(); |
| 306 |
if ( ! empty( $existing_fields ) ) { |
| 307 |
foreach ( $existing_fields as $existing_field ) { |
| 308 |
$existing_field_ids[] = $existing_field->tab_key; |
| 309 |
} |
| 310 |
} |
| 311 |
|
| 312 |
?> |
| 313 |
<input type="hidden" name="form_type" id="form_type" value="<?php echo esc_attr( $form_type ); ?>"/> |
| 314 |
<input type="hidden" name="manage_field_type" class="manage_field_type" value="profile_tabs"> |
| 315 |
<ul class="row row-cols-2 px-2 mb-0"> |
| 316 |
<?php |
| 317 |
|
| 318 |
$fields = $this->tabs_fields( $form_type, $form_id ); |
| 319 |
|
| 320 |
if ( ! empty( $fields ) ) { |
| 321 |
foreach ( $fields as $field ) { |
| 322 |
$field = stripslashes_deep( $field ); // strip slashes |
| 323 |
|
| 324 |
$fieldset_width = ''; |
| 325 |
if ( $field['tab_type'] == 'fieldset' ) { |
| 326 |
$fieldset_width = 'width:100%;'; |
| 327 |
} |
| 328 |
|
| 329 |
$display = ''; |
| 330 |
if ( in_array( $field['tab_key'], $existing_field_ids ) ) { |
| 331 |
$display = 'display:none;'; |
| 332 |
} |
| 333 |
|
| 334 |
$style = 'style="' . $display . $fieldset_width . '"'; |
| 335 |
|
| 336 |
$icon = $field['tab_icon']; |
| 337 |
if ( uwp_is_fa_icon( $icon ) ) { |
| 338 |
$tab_icon = '<i class="' . esc_attr( $icon ) . '" aria-hidden="true"></i>'; |
| 339 |
} elseif ( uwp_is_icon_url( $icon ) ) { |
| 340 |
$tab_icon = '<b style="background-image: url("' . esc_url( $icon ) . '")"></b>'; |
| 341 |
} else { |
| 342 |
$tab_icon = '<i class="fas fa-cog" aria-hidden="true"></i>'; |
| 343 |
} |
| 344 |
?> |
| 345 |
<li <?php echo esc_attr( $style ); ?> class="col px-1" > |
| 346 |
<a id="uwp-<?php echo esc_attr( $field['tab_key'] ); ?>" |
| 347 |
data-field-custom-type="custom" |
| 348 |
class="uwp-draggable-form-itemsx btn btn-sm d-block m-0 btn-outline-gray text-dark text-start" |
| 349 |
data-tab_layout="profile" |
| 350 |
data-tab_type="<?php echo isset( $field['tab_type'] ) ? esc_attr( $field['tab_type'] ) : ''; ?>" |
| 351 |
data-tab_name="<?php echo isset( $field['tab_name'] ) ? esc_attr( $field['tab_name'] ) : ''; ?>" |
| 352 |
data-tab_icon="<?php echo isset( $field['tab_icon'] ) ? esc_attr( $field['tab_icon'] ) : ''; ?>" |
| 353 |
data-tab_key="<?php echo isset( $field['tab_key'] ) ? esc_attr( $field['tab_key'] ) : ''; ?>" |
| 354 |
data-tab_level="<?php echo isset( $field['tab_level'] ) ? esc_attr( $field['tab_level'] ) : 0; ?>" |
| 355 |
data-tab_parent="<?php echo isset( $field['tab_parent'] ) ? esc_attr( $field['tab_parent'] ) : ''; ?>" |
| 356 |
data-tab_content="<?php echo isset( $field['tab_content'] ) ? esc_attr( $field['tab_content'] ) : ''; ?>" |
| 357 |
data-tab_privacy="<?php echo isset( $field['tab_privacy'] ) ? esc_attr( $field['tab_privacy'] ) : 0; ?>" |
| 358 |
data-user_decided="<?php echo isset( $field['user_decided'] ) ? esc_attr( $field['user_decided'] ) : 0; ?>" |
| 359 |
href="javascript:void(0);"> |
| 360 |
<?php echo $tab_icon; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?> |
| 361 |
<?php echo esc_attr( $field['tab_name'] ); ?> |
| 362 |
</a> |
| 363 |
</li> |
| 364 |
<?php |
| 365 |
} |
| 366 |
} |
| 367 |
?> |
| 368 |
</ul> |
| 369 |
<?php |
| 370 |
} |
| 371 |
|
| 372 |
/** |
| 373 |
* Display predefined tabs fields |
| 374 |
* |
| 375 |
* @since 2.0.0 |
| 376 |
* @package userswp |
| 377 |
* |
| 378 |
* @param string $form_type Form type |
| 379 |
* |
| 380 |
*/ |
| 381 |
public function tabs_predefined_fields( $form_type ) { |
| 382 |
$fields = array(); |
| 383 |
|
| 384 |
$fields[] = array( |
| 385 |
'tab_type' => 'standard', |
| 386 |
'tab_name' => __( 'More Info', 'userswp' ), |
| 387 |
'tab_icon' => 'fas fa-info-circle', |
| 388 |
'tab_key' => 'more_info', |
| 389 |
'tab_content' => '', |
| 390 |
); |
| 391 |
|
| 392 |
$fields[] = array( |
| 393 |
'tab_type' => 'standard', |
| 394 |
'tab_name' => __( 'Posts', 'userswp' ), |
| 395 |
'tab_icon' => 'fas fa-info-circle', |
| 396 |
'tab_key' => 'posts', |
| 397 |
'tab_content' => '', |
| 398 |
); |
| 399 |
|
| 400 |
$fields[] = array( |
| 401 |
'tab_type' => 'standard', |
| 402 |
'tab_name' => __( 'Comments', 'userswp' ), |
| 403 |
'tab_icon' => 'fas fa-comments', |
| 404 |
'tab_key' => 'comments', |
| 405 |
'tab_content' => '', |
| 406 |
); |
| 407 |
|
| 408 |
$fields[] = array( |
| 409 |
'tab_type' => 'standard', |
| 410 |
'tab_name' => __( 'User Comments', 'userswp' ), |
| 411 |
'tab_icon' => 'fas fa-comments', |
| 412 |
'tab_key' => 'user-comments', |
| 413 |
'tab_content' => '', |
| 414 |
); |
| 415 |
|
| 416 |
$fields = apply_filters( 'uwp_profile_tabs_predefined_fields', $fields, $form_type ); |
| 417 |
|
| 418 |
?> |
| 419 |
<input type="hidden" name="form_type" id="form_type" value="<?php echo esc_attr( $form_type ); ?>"/> |
| 420 |
<input type="hidden" name="manage_field_type" class="manage_field_type" value="profile_tabs"> |
| 421 |
<?php |
| 422 |
if ( ! empty( $fields ) ) { |
| 423 |
?> |
| 424 |
<ul class="row row-cols-2 px-2 mb-0"> |
| 425 |
<?php |
| 426 |
foreach ( $fields as $id => $field ) { |
| 427 |
|
| 428 |
?> |
| 429 |
<li class="col px-1" > |
| 430 |
<a id="uwp-<?php echo esc_attr( $field['tab_key'] ); ?>" |
| 431 |
data-field-custom-type="predefined" |
| 432 |
class="uwp-draggable-form-itemsx btn btn-sm d-block m-0 btn-outline-gray text-dark text-start" |
| 433 |
data-tab_layout="profile" |
| 434 |
data-field-type-key="uwp-<?php echo esc_attr( $field['tab_key'] ); ?>" |
| 435 |
data-tab_type="<?php echo isset( $field['tab_type'] ) ? esc_attr( $field['tab_type'] ) : ''; ?>" |
| 436 |
data-tab_name="<?php echo isset( $field['tab_name'] ) ? esc_attr( $field['tab_name'] ) : ''; ?>" |
| 437 |
data-tab_icon="<?php echo isset( $field['tab_icon'] ) ? esc_attr( $field['tab_icon'] ) : ''; ?>" |
| 438 |
data-tab_key="<?php echo isset( $field['tab_key'] ) ? esc_attr( $field['tab_key'] ) : ''; ?>" |
| 439 |
data-tab_level="<?php echo isset( $field['tab_level'] ) ? esc_attr( $field['tab_level'] ) : 0; ?>" |
| 440 |
data-tab_parent="<?php echo isset( $field['tab_parent'] ) ? esc_attr( $field['tab_parent'] ) : ''; ?>" |
| 441 |
data-tab_content="<?php echo isset( $field['tab_content'] ) ? esc_attr( $field['tab_content'] ) : ''; ?>" |
| 442 |
data-tab_privacy="<?php echo isset( $field['tab_privacy'] ) ? esc_attr( $field['tab_privacy'] ) : 0; ?>" |
| 443 |
data-user_decided="<?php echo isset( $field['user_decided'] ) ? esc_attr( $field['user_decided'] ) : 0; ?>" |
| 444 |
href="javascript:void(0);"> |
| 445 |
|
| 446 |
<?php |
| 447 |
$icon = $field['tab_icon']; |
| 448 |
if ( uwp_is_fa_icon( $icon ) ) { |
| 449 |
$tab_icon = '<i class="' . esc_attr( $icon ) . '" aria-hidden="true"></i>'; |
| 450 |
} elseif ( uwp_is_icon_url( $icon ) ) { |
| 451 |
$tab_icon = '<b style="background-image: url("' . esc_url( $icon ) . '")"></b>'; |
| 452 |
} else { |
| 453 |
$tab_icon = '<i class="fas fa-cog" aria-hidden="true"></i>'; |
| 454 |
} |
| 455 |
?> |
| 456 |
<?php echo $tab_icon; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?> |
| 457 |
<?php echo esc_attr( $field['tab_name'] ); ?> |
| 458 |
</a> |
| 459 |
</li> |
| 460 |
<?php |
| 461 |
} |
| 462 |
} |
| 463 |
} |
| 464 |
|
| 465 |
/** |
| 466 |
* Display selected tabs fields |
| 467 |
* |
| 468 |
* @since 2.0.0 |
| 469 |
* @package userswp |
| 470 |
* |
| 471 |
* @param string $form_type Form type |
| 472 |
* |
| 473 |
*/ |
| 474 |
public function tabs_selected_fields( $form_type ) { |
| 475 |
global $wpdb; |
| 476 |
$form_id = ! empty( $_REQUEST['form'] ) ? absint( $_REQUEST['form'] ) : 1; |
| 477 |
$table_name = uwp_get_table_prefix() . 'uwp_profile_tabs'; |
| 478 |
$tabs = $wpdb->get_results( $wpdb->prepare( 'SELECT * FROM ' . $table_name . ' where form_type = %s AND form_id = %s order by sort_order asc', array( $form_type, $form_id ) ) ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching |
| 479 |
|
| 480 |
?> |
| 481 |
<input type="hidden" name="form_type" id="form_type" value="<?php echo esc_attr( $form_type ); ?>"/> |
| 482 |
<input type="hidden" name="manage_field_type" class="manage_field_type" value="profile_tabs"> |
| 483 |
<ul class="uwp-profile-tabs-selected core uwp_form_extras ps-0 list-group"> |
| 484 |
<?php |
| 485 |
if ( ! empty( $tabs ) ) { |
| 486 |
foreach ( $tabs as $key => $tab ) { |
| 487 |
$field_ins_upd = 'display'; |
| 488 |
|
| 489 |
if ( $tab->tab_level == '1' ) { |
| 490 |
continue; |
| 491 |
} |
| 492 |
|
| 493 |
ob_start(); |
| 494 |
$this->tabs_field_adminhtml( $tab, $field_ins_upd ); |
| 495 |
$tab_rendered = ob_get_clean(); |
| 496 |
|
| 497 |
$tab_rendered = str_replace( '</li>', '', $tab_rendered ); |
| 498 |
$child_tabs = ''; |
| 499 |
foreach ( $tabs as $child_tab ) { |
| 500 |
if ( $child_tab->tab_parent == $tab->id ) { |
| 501 |
ob_start(); |
| 502 |
$this->tabs_field_adminhtml( $child_tab, $field_ins_upd ); |
| 503 |
$child_tabs .= ob_get_clean(); |
| 504 |
} |
| 505 |
} |
| 506 |
|
| 507 |
if ( $child_tabs ) { |
| 508 |
$tab_rendered .= '<ul>'; |
| 509 |
$tab_rendered .= $child_tabs; |
| 510 |
$tab_rendered .= '</ul>'; |
| 511 |
} |
| 512 |
|
| 513 |
echo $tab_rendered; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 514 |
echo '</li>'; |
| 515 |
|
| 516 |
unset( $tabs[ $key ] ); |
| 517 |
} |
| 518 |
} |
| 519 |
?> |
| 520 |
</ul> |
| 521 |
<?php |
| 522 |
} |
| 523 |
|
| 524 |
/** |
| 525 |
* Returns tabs fields |
| 526 |
* |
| 527 |
* @since 2.0.0 |
| 528 |
* @package userswp |
| 529 |
* |
| 530 |
* @param string $form_type Form type |
| 531 |
* |
| 532 |
* @return array |
| 533 |
* |
| 534 |
*/ |
| 535 |
public function tabs_fields( $form_type, $form_id = 1 ) { |
| 536 |
$fields = array(); |
| 537 |
|
| 538 |
return apply_filters( 'uwp_tabs_fields', $fields, $form_type, $form_id ); |
| 539 |
} |
| 540 |
|
| 541 |
/** |
| 542 |
* Displays tab field HTML |
| 543 |
* |
| 544 |
* @since 2.0.0 |
| 545 |
* @package userswp |
| 546 |
* |
| 547 |
* @param mixed $result_str Field |
| 548 |
* @param string $field_ins_upd Field action |
| 549 |
* @param array $request Request data |
| 550 |
* |
| 551 |
*/ |
| 552 |
public function tabs_field_adminhtml( $result_str, $field_ins_upd = '', $request = array() ) { |
| 553 |
global $wpdb; |
| 554 |
|
| 555 |
$tabs_table_name = uwp_get_table_prefix() . 'uwp_profile_tabs'; |
| 556 |
|
| 557 |
$cf = $result_str; |
| 558 |
if ( ! is_object( $cf ) && (is_int( $cf ) || ctype_digit( $cf )) ) { |
| 559 |
$field_info = $wpdb->get_row( $wpdb->prepare( 'select * from ' . $tabs_table_name . ' where id= %d', array( $cf ) ) ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching |
| 560 |
} elseif ( is_object( $cf ) ) { |
| 561 |
$result_str = $cf->id; |
| 562 |
$field_info = $wpdb->get_row( $wpdb->prepare( 'select * from ' . $tabs_table_name . ' where id= %d', array( (int)$cf->id ) ) ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching |
| 563 |
} elseif ( isset( $cf ) && ! empty( $cf ) ) { |
| 564 |
$field_info = $wpdb->get_row( $wpdb->prepare( 'select * from ' . $tabs_table_name . ' where tab_key= %s', array( $cf ) ) ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching |
| 565 |
} else { |
| 566 |
$field_info = array(); |
| 567 |
} |
| 568 |
|
| 569 |
if ( isset( $request['tab_type'] ) && $request['tab_type'] != '' ) { |
| 570 |
$tab_type = esc_attr( $request['tab_type'] ); |
| 571 |
} elseif ( $field_info && isset( $field_info->tab_type ) ) { |
| 572 |
$tab_type = $field_info->tab_type; |
| 573 |
} else { |
| 574 |
$tab_type = ''; |
| 575 |
} |
| 576 |
|
| 577 |
if ( isset( $request['tab_name'] ) ) { |
| 578 |
$field_site_name = esc_attr( $request['tab_name'] ); |
| 579 |
} elseif ( $field_info && isset( $field_info->tab_name ) ) { |
| 580 |
$field_site_name = $field_info->tab_name; |
| 581 |
} else { |
| 582 |
$field_site_name = ''; |
| 583 |
} |
| 584 |
|
| 585 |
if ( isset( $request['tab_key'] ) && $request['tab_key'] != '' ) { |
| 586 |
$tab_key = esc_attr( $request['tab_key'] ); |
| 587 |
} elseif ( $field_info && isset( $field_info->tab_key ) ) { |
| 588 |
$tab_key = $field_info->tab_key; |
| 589 |
} else { |
| 590 |
$tab_key = ''; |
| 591 |
} |
| 592 |
|
| 593 |
if ( isset( $request['tab_content'] ) && $request['tab_content'] != '' ) { |
| 594 |
$tab_content = esc_attr( $request['tab_content'] ); |
| 595 |
} elseif ( $field_info && isset( $field_info->tab_content ) ) { |
| 596 |
$tab_content = $field_info->tab_content; |
| 597 |
} else { |
| 598 |
$tab_content = ''; |
| 599 |
} |
| 600 |
|
| 601 |
if ( isset( $request['tab_icon'] ) && $request['tab_icon'] != '' ) { |
| 602 |
$icon = esc_attr( $request['tab_icon'] ); |
| 603 |
} elseif ( $field_info && isset( $field_info->tab_icon ) ) { |
| 604 |
$icon = $field_info->tab_icon; |
| 605 |
} else { |
| 606 |
$icon = 'fas fa-cog'; |
| 607 |
} |
| 608 |
|
| 609 |
if ( uwp_is_fa_icon( $icon ) ) { |
| 610 |
$field_icon = '<i class="' . esc_attr( $icon ) . '" aria-hidden="true"></i>'; |
| 611 |
} elseif ( uwp_is_icon_url( $icon ) ) { |
| 612 |
$field_icon = '<b style="background-image: url("' . esc_url( $icon ) . '")"></b>'; |
| 613 |
} elseif ( isset( $field_info->tab_type ) && $field_info->tab_type == 'fieldset' ) { |
| 614 |
$field_icon = '<i class="fas fa-arrows-h" aria-hidden="true"></i>'; |
| 615 |
} else { |
| 616 |
$field_icon = '<i class="fas fa-cog" aria-hidden="true"></i>'; |
| 617 |
} |
| 618 |
|
| 619 |
if ( isset( $request['tab_privacy'] ) && $request['tab_privacy'] != '' ) { |
| 620 |
$privacy = absint( $request['tab_privacy'] ); |
| 621 |
} elseif ( $field_info && isset( $field_info->tab_privacy ) ) { |
| 622 |
$privacy = $field_info->tab_privacy; |
| 623 |
} else { |
| 624 |
$privacy = 1; |
| 625 |
} |
| 626 |
|
| 627 |
if ( isset( $request['user_decided'] ) && $request['user_decided'] != '' ) { |
| 628 |
$user_decided = esc_attr( $request['user_decided'] ); |
| 629 |
} elseif ( $field_info && isset( $field_info->user_decided ) ) { |
| 630 |
$user_decided = $field_info->user_decided; |
| 631 |
} else { |
| 632 |
$user_decided = 0; |
| 633 |
} |
| 634 |
|
| 635 |
if ( isset( $request['tab_parent'] ) && $request['tab_parent'] != '' ) { |
| 636 |
$tab_parent = esc_attr( $request['tab_parent'] ); |
| 637 |
} elseif ( $field_info && isset( $field_info->tab_parent ) ) { |
| 638 |
$tab_parent = $field_info->tab_parent; |
| 639 |
} else { |
| 640 |
$tab_parent = 0; |
| 641 |
} |
| 642 |
|
| 643 |
if ( isset( $request['tab_level'] ) && $request['tab_level'] != '' ) { |
| 644 |
$tab_level = esc_attr( $request['tab_level'] ); |
| 645 |
} elseif ( $field_info && isset( $field_info->tab_level ) ) { |
| 646 |
$tab_level = $field_info->tab_level; |
| 647 |
} else { |
| 648 |
$tab_level = 0; |
| 649 |
} |
| 650 |
|
| 651 |
$exclude_privacy_tab = apply_filters( 'uwp_exclude_privacy_settings_tabs', array() ); |
| 652 |
$exclude_privacy_option = false; |
| 653 |
if ( ! empty( $exclude_privacy_tab ) && in_array( $tab_key, $exclude_privacy_tab ) ) { |
| 654 |
$exclude_privacy_option = true; |
| 655 |
} |
| 656 |
|
| 657 |
$nonce = wp_create_nonce( 'uwp_tabs_extras_nonce_' . $result_str ); |
| 658 |
?> |
| 659 |
<li class="text li-settings" id="licontainer_<?php echo esc_attr( $result_str ); ?>"> |
| 660 |
<!-- <i class="fas fa-caret-down toggle-arrow" aria-hidden="true" onclick="uwp_show_hide(this);"></i> --> |
| 661 |
<div class="title title<?php echo esc_attr( $result_str ); ?> uwp-fieldset hover-shadow dd-form d-flex justify-content-between rounded c-pointer list-group-item border rounded-smx text-start bg-light " onclick="uwp_tabs_item_settings(this);"> |
| 662 |
<div class=" flex-fill font-weight-bold fw-bold"> |
| 663 |
<?php echo $field_icon; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?> |
| 664 |
<b><?php echo esc_html( uwp_ucwords( ' ' . $field_site_name ) ); ?></b> |
| 665 |
<span class="field-type float-end text-end small"><?php echo ' (' . esc_html( uwp_ucwords( $tab_type ) ) . ')'; ?></span> |
| 666 |
</div> |
| 667 |
<div class="dd-handle ui-sortable-handle"> |
| 668 |
<i class="far fa-trash-alt text-danger ml-2 ms-2" id="delete-16" |
| 669 |
onclick="delete_field('<?php echo esc_attr( $result_str ); ?>', '<?php echo esc_attr( wp_create_nonce( 'uwp_form_tab_delete_nonce_' . $result_str ) ); ?>', '<?php echo esc_attr( $tab_key ); ?>', 'profile_tab');event.stopPropagation();return false;"></i> |
| 670 |
<i class="fas fa-grip-vertical text-muted ml-2 ms-2" style="cursor: move" aria-hidden="true"></i> |
| 671 |
</div> |
| 672 |
|
| 673 |
</div> |
| 674 |
<?php // store the form as a template. This saves a load of memory on page load. ?> |
| 675 |
<script type="text/template" class="dd-setting <?php echo 'dd-type-' . esc_attr( $tab_type ); ?>"> |
| 676 |
<div id="field_frm<?php echo esc_attr( $result_str ); ?>" class="field_frm" style="<?php echo ( $field_ins_upd == 'submit' ) ? 'display:block;' : ''; ?>"> |
| 677 |
<input type="hidden" name="_wpnonce" id="uwp_tabs_extras_nonce" value="<?php echo esc_attr( $nonce ); ?>"/> |
| 678 |
<input type="hidden" name="field_id" id="field_id" value="<?php echo esc_attr( $result_str ); ?>"/> |
| 679 |
<input type="hidden" name="form_type" id="form_type" value="profile-tabs"/> |
| 680 |
<input type="hidden" name="tab_type" id="tab_type" value="<?php echo esc_attr( $tab_type ); ?>"/> |
| 681 |
<input type="hidden" name="tab_parent" value="<?php echo esc_attr( $tab_parent ); ?>"/> |
| 682 |
<input type="hidden" name="tab_level" value="<?php echo esc_attr( $tab_level ); ?>"/> |
| 683 |
|
| 684 |
<?php |
| 685 |
// tab name |
| 686 |
aui()->input( |
| 687 |
array( |
| 688 |
'id' => 'tab_name', |
| 689 |
'name' => 'tab_name', |
| 690 |
'label_type' => 'top', |
| 691 |
'label' => esc_html__( 'Tab Name', 'userswp' ) . uwp_help_tip( __( 'This will be the name of profile tab.', 'userswp' ) ), // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 692 |
'type' => 'text', |
| 693 |
// 'wrap_class' => uwp_advanced_toggle_class(), |
| 694 |
'value' => $field_site_name, |
| 695 |
), |
| 696 |
true |
| 697 |
); |
| 698 |
|
| 699 |
// tab_key |
| 700 |
|
| 701 |
$extra_attributes = array(); |
| 702 |
$class = ''; |
| 703 |
if ( ! empty( $tab_key ) && $tab_key != '' ) { |
| 704 |
$extra_attributes['readonly'] = 'readonly'; $class = 'bg-opacity-50 bg-gray'; |
| 705 |
} |
| 706 |
|
| 707 |
aui()->input( |
| 708 |
array( |
| 709 |
'id' => 'tab_key', |
| 710 |
'name' => 'tab_key', |
| 711 |
'label_type' => 'top', |
| 712 |
'label' => esc_html__( 'Tab key', 'userswp' ) . uwp_help_tip( __( 'Key and URL slug for the profile tab.', 'userswp' ) ), // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 713 |
'type' => 'text', |
| 714 |
// 'wrap_class' => uwp_advanced_toggle_class(), |
| 715 |
'value' => $tab_key, |
| 716 |
'extra_attributes' => $extra_attributes, |
| 717 |
'class' => $class, |
| 718 |
), |
| 719 |
true |
| 720 |
); |
| 721 |
|
| 722 |
// tab name |
| 723 |
aui()->input( |
| 724 |
array( |
| 725 |
'id' => 'tab_icon', |
| 726 |
'name' => 'tab_icon', |
| 727 |
'label_type' => 'top', |
| 728 |
'label' => __( 'Tab icon', 'userswp' ) . uwp_help_tip( __( 'This will be the icon for profile tab.', 'userswp' ) ), |
| 729 |
'type' => 'iconpicker', |
| 730 |
//'wrap_class' => uwp_advanced_toggle_class(), |
| 731 |
'value' => $icon, |
| 732 |
'extra_attributes' => defined( 'FAS_PRO' ) && FAS_PRO ? array( |
| 733 |
'data-fa-icons' => true, |
| 734 |
'data-bs-toggle' => 'tooltip', |
| 735 |
'data-bs-trigger' => 'focus', |
| 736 |
'title' => __( 'For pro icon variants (light, thin, duotone), paste the class here', 'userswp' ), |
| 737 |
) : array(), |
| 738 |
), |
| 739 |
true |
| 740 |
); |
| 741 |
|
| 742 |
$privacy_options = array( |
| 743 |
0 => __( 'Anyone', 'userswp' ), |
| 744 |
1 => __( 'Logged in', 'userswp' ), |
| 745 |
2 => __( 'Author only', 'userswp' ), |
| 746 |
); |
| 747 |
|
| 748 |
$privacy_options = apply_filters( 'uwp_tab_privacy_options', $privacy_options, $result_str, $request ); |
| 749 |
|
| 750 |
if ( $exclude_privacy_option ) { |
| 751 |
?> |
| 752 |
<label for="privacy" class="uwp-tooltip-wrap"> |
| 753 |
<?php |
| 754 |
echo uwp_help_tip( __( 'Select privacy for displaying profile tab and content.', 'userswp' ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 755 |
esc_html_e( 'Privacy:', 'userswp' ); |
| 756 |
?> |
| 757 |
</label> |
| 758 |
<input type="hidden" name="tab_privacy" value="<?php echo esc_attr( $privacy ); ?>"> |
| 759 |
<p> |
| 760 |
<?php |
| 761 |
$privacy_option_val = ! empty( $privacy_options[ $privacy ] ) ? $privacy_options[ $privacy ] : ''; |
| 762 |
echo esc_html( wp_sprintf( __( '%s (Not Changeable)', 'userswp' ), $privacy_option_val ) ); |
| 763 |
?> |
| 764 |
</p> |
| 765 |
<?php |
| 766 |
} else { |
| 767 |
aui()->select( |
| 768 |
array( |
| 769 |
'id' => 'tab_privacy', |
| 770 |
'name' => 'tab_privacy', |
| 771 |
'label_type' => 'top', |
| 772 |
'multiple' => false, |
| 773 |
'class' => ' mw-100', |
| 774 |
'options' => $privacy_options, |
| 775 |
'label' => __( 'Privacy', 'userswp' ) . uwp_help_tip( __( 'Select privacy for displaying profile tab and content.', 'userswp' ) ), |
| 776 |
'value' => $privacy, |
| 777 |
// 'wrap_class' => uwp_advanced_toggle_class(), |
| 778 |
), |
| 779 |
true |
| 780 |
); |
| 781 |
} |
| 782 |
|
| 783 |
aui()->input( |
| 784 |
array( |
| 785 |
'id' => 'user_decided', |
| 786 |
'name' => 'user_decided', |
| 787 |
'type' => 'checkbox', //'!$exclude_privacy_option ? 'hidden' : 'checkbox', |
| 788 |
'label_type' => 'horizontal', |
| 789 |
'label_col' => '4', |
| 790 |
'label' => __( 'Let user decide', 'userswp' ), |
| 791 |
'checked' => $user_decided, |
| 792 |
'value' => '1', |
| 793 |
'switch' => 'md', |
| 794 |
'label_force_left' => true, |
| 795 |
'help_text' => uwp_help_tip( __( 'Enable to allow user to decide privacy for displaying profile tab and content.', 'userswp' ) ), |
| 796 |
'wrap_class' => $exclude_privacy_option ? 'd-none' : '', //uwp_advanced_toggle_class(), |
| 797 |
), |
| 798 |
true |
| 799 |
); |
| 800 |
|
| 801 |
do_action( 'uwp_profile_tab_custom_fields', $result_str ); |
| 802 |
|
| 803 |
if ( $tab_type == 'shortcode' ) { |
| 804 |
aui()->textarea( |
| 805 |
array( |
| 806 |
'id' => 'tab_content', |
| 807 |
'name' => 'tab_content', |
| 808 |
'placeholder' => __( 'Add shortcode here.', 'userswp' ), |
| 809 |
'value' => wp_kses_post( stripslashes( $tab_content ) ), |
| 810 |
'help_text' => __( 'Content to display in profile tab. Shortcode allowed.', 'userswp' ), // . WP_Super_Duper::shortcode_button("'tab_content'"), // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped, |
| 811 |
'label_type' => 'top', |
| 812 |
'label' => __( 'Tab content', 'userswp' ), |
| 813 |
'rows' => '4', |
| 814 |
// 'wrap_class' => isset( $field->css_class ) ? esc_attr( $field->css_class ) : '', |
| 815 |
), |
| 816 |
true |
| 817 |
); |
| 818 |
|
| 819 |
// echo WP_Super_Duper::shortcode_button("'tab_content'"); _e('(select a shortcode)', 'userswp'); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 820 |
|
| 821 |
} else { |
| 822 |
echo '<input type="hidden" name="tab_content" value="' . esc_attr( $tab_content ) . '">'; |
| 823 |
} |
| 824 |
?> |
| 825 |
|
| 826 |
<div class="uwp-input-wrap uwp-tab-actions" data-setting="save_button"> |
| 827 |
<a class=" btn btn-link text-muted" href="javascript:void(0);" onclick="uwp_tabs_close_settings(this); return false;"><?php _e( 'Close', 'userswp' ); ?></a> |
| 828 |
<a href='javascript:void(0);' |
| 829 |
type="button" |
| 830 |
class="btn btn-primary" |
| 831 |
id="save" |
| 832 |
onclick="save_field('<?php echo esc_attr( $result_str ); ?>', 'profile_tab');return false;"> |
| 833 |
<?php echo esc_attr( __( 'Save', 'userswp' ) ); ?> |
| 834 |
</a> |
| 835 |
</div> |
| 836 |
</div> |
| 837 |
</script> |
| 838 |
</li> |
| 839 |
<?php |
| 840 |
} |
| 841 |
|
| 842 |
/** |
| 843 |
* Handles tabs fields AJAX |
| 844 |
* |
| 845 |
* @since 2.0.0 |
| 846 |
* @package userswp |
| 847 |
* |
| 848 |
* @return mixed|void |
| 849 |
* |
| 850 |
*/ |
| 851 |
public function tabs_ajax_handler() { |
| 852 |
|
| 853 |
if ( isset( $_REQUEST['create_field'] ) ) { |
| 854 |
|
| 855 |
if ( ! current_user_can( 'manage_options' ) ) { |
| 856 |
wp_die( -1 ); |
| 857 |
} |
| 858 |
|
| 859 |
$field_id = isset( $_REQUEST['field_id'] ) ? trim( sanitize_text_field( $_REQUEST['field_id'] ), '_' ) : ''; |
| 860 |
$field_action = isset( $_REQUEST['field_ins_upd'] ) ? sanitize_text_field( $_REQUEST['field_ins_upd'] ) : ''; |
| 861 |
$form_id = isset( $_REQUEST['form_id'] ) ? absint( $_REQUEST['form_id'] ) : 1; |
| 862 |
|
| 863 |
/* ------- check nonce field ------- */ |
| 864 |
if ( isset( $_REQUEST['update'] ) && $_REQUEST['update'] == 'update' ) { |
| 865 |
|
| 866 |
if ( ! empty( $_REQUEST['tabs'] ) && is_array( $_REQUEST['tabs'] ) ) { |
| 867 |
if ( ! wp_verify_nonce( $_REQUEST['_wpnonce'], 'uwp-admin-settings' ) ) { |
| 868 |
return; |
| 869 |
} |
| 870 |
$tabs = $_REQUEST['tabs']; |
| 871 |
$this->update_field_order( $tabs, $form_id ); |
| 872 |
|
| 873 |
} |
| 874 |
} |
| 875 |
|
| 876 |
/* ---- Show field form in admin ---- */ |
| 877 |
if ( $field_action == 'new' ) { |
| 878 |
if ( ! wp_verify_nonce( $_REQUEST['_wpnonce'], 'uwp-admin-settings' ) ) { |
| 879 |
return; |
| 880 |
} |
| 881 |
$htmlvar_name = isset( $_REQUEST['htmlvar_name'] ) ? sanitize_text_field( $_REQUEST['htmlvar_name'] ) : sanitize_text_field( $_REQUEST['tab_key'] ); |
| 882 |
|
| 883 |
$this->tabs_field_adminhtml( $htmlvar_name, $field_action, $_REQUEST ); |
| 884 |
} |
| 885 |
|
| 886 |
/* ---- Delete field ---- */ |
| 887 |
if ( $field_id != '' && $field_action == 'delete' && isset( $_REQUEST['_wpnonce'] ) ) { |
| 888 |
if ( ! wp_verify_nonce( $_REQUEST['_wpnonce'], 'uwp_form_tab_delete_nonce_' . $field_id ) ) { |
| 889 |
return; |
| 890 |
} |
| 891 |
|
| 892 |
$this->tabs_field_delete( $field_id ); |
| 893 |
} |
| 894 |
|
| 895 |
/* ---- Save field ---- */ |
| 896 |
if ( $field_action == 'submit' && isset( $_REQUEST['_wpnonce'] ) ) { |
| 897 |
if ( ! wp_verify_nonce( $_REQUEST['_wpnonce'], 'uwp_tabs_extras_nonce_' . $field_id ) ) { |
| 898 |
return; |
| 899 |
} |
| 900 |
|
| 901 |
foreach ( $_REQUEST as $pkey => $pval ) { |
| 902 |
$tags = is_array( $_REQUEST[ $pkey ] ) ? 'skip_field' : ''; |
| 903 |
|
| 904 |
if ( $tags != 'skip_field' && $pkey != 'tab_content' ) { |
| 905 |
$_REQUEST[ $pkey ] = strip_tags( sanitize_text_field( $_REQUEST[ $pkey ] ), $tags ); |
| 906 |
} |
| 907 |
} |
| 908 |
|
| 909 |
$lastid = $this->tabs_field_save( $_REQUEST ); |
| 910 |
|
| 911 |
if ( is_int( $lastid ) && $lastid > 0 ) { |
| 912 |
$this->tabs_field_adminhtml( $lastid, 'submit' ); |
| 913 |
} else { |
| 914 |
echo esc_html( $lastid ); |
| 915 |
} |
| 916 |
} |
| 917 |
} |
| 918 |
die(); |
| 919 |
} |
| 920 |
|
| 921 |
/** |
| 922 |
* Save tabs fields |
| 923 |
* |
| 924 |
* @since 2.0.0 |
| 925 |
* @package userswp |
| 926 |
* |
| 927 |
* @param array $request_field Request data |
| 928 |
* |
| 929 |
* @return string|int |
| 930 |
* |
| 931 |
*/ |
| 932 |
public function tabs_field_save( $request_field = array() ) { |
| 933 |
global $wpdb; |
| 934 |
$table_name = uwp_get_table_prefix() . 'uwp_profile_tabs'; |
| 935 |
|
| 936 |
$tab_id = isset( $request_field['field_id'] ) && $request_field['field_id'] ? absint( $request_field['field_id'] ) : ''; |
| 937 |
$tab_name = isset( $request_field['tab_name'] ) ? sanitize_text_field( $request_field['tab_name'] ) : ''; |
| 938 |
$tab_icon = isset( $request_field['tab_icon'] ) ? sanitize_text_field( $request_field['tab_icon'] ) : ''; |
| 939 |
$tab_key = ! empty( $request_field['tab_key'] ) ? sanitize_title( $request_field['tab_key'] ) : sanitize_title( $tab_name, 'uwp-tab-' . $tab_name ); |
| 940 |
$tab_level = ! empty( $request_field['tab_level'] ) ? sanitize_text_field( $request_field['tab_level'] ) : 0; |
| 941 |
$tab_parent = ! empty( $request_field['tab_parent'] ) ? sanitize_text_field( $request_field['tab_parent'] ) : 0; |
| 942 |
$tab_type = isset( $request_field['tab_type'] ) ? sanitize_text_field( $request_field['tab_type'] ) : 'standard'; |
| 943 |
$form_type = isset( $request_field['form_type'] ) ? $request_field['form_type'] : $tab_type; |
| 944 |
$tab_privacy = isset( $request_field['tab_privacy'] ) ? (int)$request_field['tab_privacy'] : 0; |
| 945 |
$user_decided = isset( $request_field['user_decided'] ) ? (int)$request_field['user_decided'] : 0; |
| 946 |
$form_id = isset( $request_field['form_id'] ) ? (int)$request_field['form_id'] : 1; |
| 947 |
|
| 948 |
$total_tabs = $wpdb->get_var( "SELECT COUNT(id) FROM {$table_name}" ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching |
| 949 |
|
| 950 |
$data = array( |
| 951 |
'form_type' => 'profile-tabs', |
| 952 |
'sort_order' => $total_tabs + 1, |
| 953 |
'tab_layout' => 'profile', |
| 954 |
'tab_type' => $tab_type, |
| 955 |
'tab_level' => sanitize_text_field( $tab_level ), |
| 956 |
'tab_parent' => sanitize_text_field( $tab_parent ), |
| 957 |
'tab_name' => $tab_name, |
| 958 |
'tab_icon' => $tab_icon, |
| 959 |
'tab_key' => sanitize_text_field( $tab_key ), |
| 960 |
'tab_content' => wp_kses_post( $request_field['tab_content'] ), |
| 961 |
'tab_privacy' => $tab_privacy, |
| 962 |
'user_decided' => $user_decided, |
| 963 |
'form_id' => $form_id, |
| 964 |
); |
| 965 |
|
| 966 |
$format = array_fill( 0, count( $data ), '%s' ); |
| 967 |
|
| 968 |
$check_html_variable = $wpdb->get_var( $wpdb->prepare( 'select COUNT(*) from ' . $table_name . ' where tab_type = %s AND tab_name LIKE %s AND tab_key = %s AND form_type = %s AND form_id = %s', array( $tab_type, $tab_name, $tab_key, $form_type, $form_id ) ) ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching |
| 969 |
|
| 970 |
if ( ! $tab_id && (int)$check_html_variable > 0 ) { |
| 971 |
return 'invalid_key'; |
| 972 |
} |
| 973 |
|
| 974 |
if ( $tab_id ) { // update |
| 975 |
|
| 976 |
$wpdb->update( // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching |
| 977 |
$table_name, |
| 978 |
$data, |
| 979 |
array( 'id' => $tab_id ), |
| 980 |
$format |
| 981 |
); |
| 982 |
|
| 983 |
$lastid = $tab_id; |
| 984 |
|
| 985 |
} else { // insert |
| 986 |
$wpdb->insert( // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery |
| 987 |
$table_name, |
| 988 |
$data, |
| 989 |
$format |
| 990 |
); |
| 991 |
|
| 992 |
$lastid = $wpdb->insert_id; |
| 993 |
} |
| 994 |
|
| 995 |
return (int) $lastid; |
| 996 |
} |
| 997 |
|
| 998 |
/** |
| 999 |
* Save tabs fields |
| 1000 |
* |
| 1001 |
* @since 2.0.0 |
| 1002 |
* @package userswp |
| 1003 |
* |
| 1004 |
* @param string $field_id Request data |
| 1005 |
* |
| 1006 |
* @return int |
| 1007 |
* |
| 1008 |
*/ |
| 1009 |
public function tabs_field_delete( $field_id = '' ) { |
| 1010 |
global $wpdb; |
| 1011 |
$table_name = uwp_get_table_prefix() . 'uwp_profile_tabs'; |
| 1012 |
|
| 1013 |
if ( $field_id != '' ) { |
| 1014 |
$cf = trim( $field_id, '_' ); |
| 1015 |
$wpdb->query( $wpdb->prepare( 'delete from ' . $table_name . ' where id= %d ', array( $cf ) ) ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching |
| 1016 |
return $field_id; |
| 1017 |
} else { |
| 1018 |
return 0; |
| 1019 |
} |
| 1020 |
} |
| 1021 |
|
| 1022 |
/** |
| 1023 |
* Updates profile tabs sort order. |
| 1024 |
* |
| 1025 |
* @param array $tabs Tabs array. |
| 1026 |
* |
| 1027 |
* @return object|bool Sorted tabs. |
| 1028 |
*/ |
| 1029 |
public function update_field_order( $tabs = array(), $form_id = 1 ) { |
| 1030 |
global $wpdb; |
| 1031 |
$table_name = uwp_get_table_prefix() . 'uwp_profile_tabs'; |
| 1032 |
|
| 1033 |
$count = 0; |
| 1034 |
if ( ! empty( $tabs ) ) { |
| 1035 |
$result = false; |
| 1036 |
foreach ( $tabs as $index => $tab ) { |
| 1037 |
$result = $wpdb->update( // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching |
| 1038 |
$table_name, |
| 1039 |
array( |
| 1040 |
'sort_order' => $index, |
| 1041 |
'tab_level' => (int)$tab['tab_level'], |
| 1042 |
'tab_parent' => (int)$tab['tab_parent'], |
| 1043 |
), |
| 1044 |
array( |
| 1045 |
'id' => absint( $tab['id'] ), |
| 1046 |
'form_id' => $form_id, |
| 1047 |
), |
| 1048 |
array( '%d', '%d' ) |
| 1049 |
); |
| 1050 |
++$count; |
| 1051 |
} |
| 1052 |
if ( $result !== false ) { |
| 1053 |
return true; |
| 1054 |
} else { |
| 1055 |
return new WP_Error( 'failed', __( 'Failed to sort tab items.', 'userswp' ) ); |
| 1056 |
} |
| 1057 |
} else { |
| 1058 |
return new WP_Error( 'failed', __( 'Failed to sort tab items.', 'userswp' ) ); |
| 1059 |
} |
| 1060 |
} |
| 1061 |
} |
| 1062 |
|
| 1063 |
} |
| 1064 |
|
| 1065 |
|
| 1066 |
new UsersWP_Settings_Profile_Tabs(); |
| 1067 |
|