| 1 |
<?php |
| 2 |
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
| 3 |
|
| 4 |
// the function to display the custom fields in the back-end |
| 5 |
function wppb_display_fields_in_admin( $user ){ |
| 6 |
$admin_fields = ''; |
| 7 |
?> |
| 8 |
<script type="text/javascript"> |
| 9 |
var form = document.getElementById('your-profile'); |
| 10 |
form.encoding = "multipart/form-data"; //IE5.5 |
| 11 |
form.setAttribute('enctype', 'multipart/form-data'); //required for IE6 (is interpreted into "encType") |
| 12 |
|
| 13 |
jQuery(function(){ |
| 14 |
//hover states on the static widgets |
| 15 |
jQuery('#dialog_link, ul#icons li').on('mouseenter', function() { jQuery(this).addClass('ui-state-hover'); }); |
| 16 |
jQuery('#dialog_link, ul#icons li').on('mouseleave', function() { jQuery(this).removeClass('ui-state-hover'); }); |
| 17 |
}); |
| 18 |
</script> |
| 19 |
<?php |
| 20 |
|
| 21 |
$all_data = get_option( 'wppb_manage_fields' ); |
| 22 |
if ( is_array( $all_data ) ){ |
| 23 |
foreach ( $all_data as $value ) { |
| 24 |
|
| 25 |
$display_field = apply_filters( 'wppb_output_display_form_field', true, $value, 'back_end', 'all', $user->ID ); |
| 26 |
|
| 27 |
if( $display_field == false ) |
| 28 |
continue; |
| 29 |
|
| 30 |
$admin_fields .= apply_filters( 'wppb_admin_output_form_field_'.Wordpress_Creation_Kit_PB::wck_generate_slug( $value['field'] ), '', 'back_end', $value, $user->ID, array(), $_REQUEST ); |
| 31 |
} |
| 32 |
|
| 33 |
} |
| 34 |
|
| 35 |
echo $admin_fields; //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 36 |
} |
| 37 |
|
| 38 |
// the function to save the values from the custom fields in the back-end |
| 39 |
function wppb_save_fields_in_admin( $user_id ){ |
| 40 |
$global_request = $_REQUEST; |
| 41 |
$all_data = apply_filters( 'wppb_form_fields', get_option( 'wppb_manage_fields' ), array( 'context' => 'validate_backend' ) ); |
| 42 |
if ( is_array( $all_data ) ){ |
| 43 |
foreach ( $all_data as $field ){ |
| 44 |
/* check to see if we have any error for the field. if we do don't save it */ |
| 45 |
$error_for_field = apply_filters( 'wppb_check_form_field_'.Wordpress_Creation_Kit_PB::wck_generate_slug( $field['field'] ), '', $field, $global_request, 'back_end', '', $user_id ); |
| 46 |
if( empty( $error_for_field ) ) |
| 47 |
do_action( 'wppb_backend_save_form_field', $field, $user_id, $global_request, 'backend-form' ); |
| 48 |
} |
| 49 |
} |
| 50 |
} |
| 51 |
|
| 52 |
/* the function that checks for field error in the backend */ |
| 53 |
function wppb_validate_fields_in_admin( &$errors, $update, &$user ){ |
| 54 |
|
| 55 |
$all_data = apply_filters( 'wppb_form_fields', get_option( 'wppb_manage_fields' ), array( 'context' => 'validate_backend' ) ); |
| 56 |
$global_request = $_REQUEST; |
| 57 |
if ( is_array( $all_data ) ){ |
| 58 |
foreach ( $all_data as $field ){ |
| 59 |
$error_for_field = apply_filters( 'wppb_check_form_field_'.Wordpress_Creation_Kit_PB::wck_generate_slug( $field['field'] ), '', $field, $global_request, 'back_end', '', $user->ID ); |
| 60 |
|
| 61 |
if( !empty( $error_for_field ) ){ |
| 62 |
$errors->add( $field['id'], '<strong>'. __( 'ERROR', 'profile-builder' ).'</strong> '.$field['field-title'].':'.$error_for_field); |
| 63 |
} |
| 64 |
} |
| 65 |
} |
| 66 |
} |
| 67 |
|