/var/www/(Del)hsihk.com/wp-content/plugins/ninja-forms/includes/fields/credit-card.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
<?php
/*
 * Function to register a new field for user's country
 *
 * @since 2.2.37
 * @returns void
 */

function ninja_forms_register_field_credit_card(){

    
$reg_field apply_filters'ninja_forms_enable_credit_card_field'false );

    
$args = array(
        
'name' => __'Credit Card''ninja-forms' ),
        
'sidebar' => '',
        
'display_function' => 'ninja_forms_field_credit_card_display',
        
'group' => 'standard_fields',
        
'edit_conditional' => true,
        
'edit_custom_class' => false,
        
'edit_options' => array(),
        
//'post_process' => 'ninja_forms_field_credit_card_test',
        
'save_sub' => false,
        
'process_field' => false,
        
'edit_label' => false,
        
'edit_label_pos' => false,
        
'edit_options' => array(
            array(
                
'type' => 'hidden',
                
'name' => 'payment_field_group',
                
'default' => 1,
            ),
            array(
                
'type'         => 'text',
                
'name'         => 'cc_number_label',
                
'label'        => __'Card Number Label''ninja-forms' ),
                
'default'     => __'Card Number''ninja-forms' ),
                
'width'     => 'wide',
                
'class'     => 'widefat',
            ),
            array(
                
'type'         => 'text',
                
'name'         => 'cc_number_desc',
                
'label'        => __'Card Number Description''ninja-forms' ),
                
'default'     => __'The (typically) 16 digits on the front of your credit card.''ninja-forms' ),
                
'width'     => 'wide',
                
'class'     => 'widefat',
            ),
            array(
                
'type'         => 'text',
                
'name'         => 'cc_cvc_label',
                
'label'        => __'Card CVC Label''ninja-forms' ),
                
'default'     => __'CVC''ninja-forms' ),
                
'width'     => 'wide',
                
'class'     => 'widefat',
            ),
            array(
                
'type'         => 'text',
                
'name'         => 'cc_cvc_desc',
                
'label'        => __'Card CVC Description''ninja-forms' ),
                
'default'     => __'The 3 digit (back) or 4 digit (front) value on your card.''ninja-forms' ),
                
'width'     => 'wide',
                
'class'     => 'widefat',
            ),
            array(
                
'type'         => 'text',
                
'name'         => 'cc_name_label',
                
'label'        => __'Card Name Label''ninja-forms' ),
                
'default'     => __'Name on the card''ninja-forms' ),
                
'width'     => 'wide',
                
'class'     => 'widefat',
            ),
            array(
                
'type'         => 'text',
                
'name'         => 'cc_name_desc',
                
'label'        => __'Card Name Description''ninja-forms' ),
                
'default'     => __'The name printed on the front of your credit card.''ninja-forms' ),
                
'width'     => 'wide',
                
'class'     => 'widefat',
            ),
            array(
                
'type'         => 'text',
                
'name'         => 'cc_exp_month_label',
                
'label'        => __'Card Expiry Month Label''ninja-forms' ),
                
'default'     => __'Expiration month (MM)''ninja-forms' ),
                
'width'     => 'wide',
                
'class'     => 'widefat',
            ),
            array(
                
'type'         => 'text',
                
'name'         => 'cc_exp_month_desc',
                
'label'        => __'Card Expiry Month Description''ninja-forms' ),
                
'default'     => __'The month your credit card expires, typically on the front of the card.''ninja-forms' ),
                
'width'     => 'wide',
                
'class'     => 'widefat',
            ),
            array(
                
'type'         => 'text',
                
'name'         => 'cc_exp_year_label',
                
'label'        => __'Card Expiry Year Label''ninja-forms' ),
                
'default'     => __'Expiration year (YYYY)''ninja-forms' ),
                
'width'     => 'wide',
                
'class'     => 'widefat',
            ),
            array(
                
'type'         => 'text',
                
'name'         => 'cc_exp_year_desc',
                
'label'        => __'Card Expiry Year Description''ninja-forms' ),
                
'default'     => __'The year your credit card expires, typically on the front of the card.''ninja-forms' ),
                
'width'     => 'wide',
                
'class'     => 'widefat',
            ),

        ),
    );

    if ( 
$reg_field ) {
        
ninja_forms_register_field'_credit_card'$args );
    }
}

add_action'init''ninja_forms_register_field_credit_card' );

/*
 * Function to display our credit_card field on the front-end.
 *
 * @since 2.2.37
 * @returns void
 */

function ninja_forms_field_credit_card_display$field_id$data$form_id '' ) {
    global 
$ninja_forms_processing;

    if( isset( 
$data['default_value'] ) ) {
        
$default_value $data['default_value'];
    }else{
        
$default_value '';
    }

    if ( isset ( 
$data['label_pos'] ) ) {
        
$label_pos $data['label_pos'];
    } else {
        
$label_pos 'above';
    }

    
$cc_number_label = isset ( $data['cc_number_label'] ) ? $data['cc_number_label'] : __'Card Number''ninja-forms' );
    
$cc_number_desc = isset ( $data['cc_number_desc'] ) ? $data['cc_number_desc'] : __'The (typically) 16 digits on the front of your credit card.''ninja-forms' );
    
    
$cc_cvc_label = isset ( $data['cc_cvc_label'] ) ? $data['cc_cvc_label'] : __'CVC''ninja-forms' );
    
$cc_cvc_desc = isset ( $data['cc_cvc_desc'] ) ? $data['cc_cvc_desc'] : __'The 3 digit (back) or 4 digit (front) value on your card.''ninja-forms' );

    
$cc_name_label = isset ( $data['cc_name_label'] ) ? $data['cc_name_label'] : __'Name on the card''ninja-forms' );
    
$cc_name_desc = isset ( $data['cc_name_desc'] ) ? $data['cc_name_desc'] : __'The name printed on the front of your credit card.''ninja-forms' );

    
$cc_exp_month_label = isset ( $data['cc_exp_month_label'] ) ? $data['cc_exp_month_label'] : __'Expiration month (MM)''ninja-forms' );
    
$cc_exp_month_desc = isset ( $data['cc_exp_month_desc'] ) ? $data['cc_exp_month_desc'] : __'The month your credit card expires, typically on the front of the card.''ninja-forms' );

    
$cc_exp_year_label = isset ( $data['cc_exp_year_label'] ) ? $data['cc_exp_year_label'] : __'Expiration year (YYY)''ninja-forms' );
    
$cc_exp_year_desc = isset ( $data['cc_exp_year_desc'] ) ? $data['cc_exp_year_desc'] : __'The year your credit card expires, typically on the front of the card.''ninja-forms' );

    if ( isset ( 
$ninja_forms_processing ) ){
        
$name $ninja_forms_processing->get_extra_value'_credit_card_name' );
        
$expiry_month $ninja_forms_processing->get_extra_value'_credit_card_expiry_month' );
        
$expiry_year $ninja_forms_processing->get_extra_value'_credit_card_expiry_year' );
        
$card_number_errors $ninja_forms_processing->get_errors_by_location'credit_card_number' );
        
$card_cvc_errors $ninja_forms_processing->get_errors_by_location'credit_card_cvc' );
        
$card_name_errors $ninja_forms_processing->get_errors_by_location'credit_card_name' );
        
$card_month_errors $ninja_forms_processing->get_errors_by_location'credit_card_month' );
        
$card_year_errors $ninja_forms_processing->get_errors_by_location'credit_card_year' );
    } else {
        
$name '';
        
$expiry_month '';
        
$expiry_year '';
        
$card_number_errors '';
        
$card_cvc_errors '';
        
$card_name_errors '';
        
$card_month_errors '';
        
$card_year_errors '';
    }

    
$field_class ninja_forms_get_field_class$field_id$form_id );
    
$post_field apply_filters'ninja_forms_post_credit_card_field'false );
    
$desc_pos apply_filters'ninja_forms_credit_card_field_desc_pos''after_label' );
    
$hide_cc_fields apply_filters'ninja_forms_hide_cc_field', array() );
    
    if( !
in_array'number' $hide_cc_fields ) ){
    
?>
        <div class="ninja-forms-credit-card-number label-<?php echo $label_pos?> field-wrap"> <!-- Open Credit Card Wrap -->
            <?php
            
if ( $desc_pos == 'before_label' or $desc_pos == 'before_everything' ) {
                
?>
                <span><?php echo apply_filters'ninja_forms_credit_card_number_desc'$cc_number_desc ); ?></span>
                <?php
            
}

            if ( 
$label_pos == 'above' or $label_pos == 'left' ) {
                
?>
                <label><?php echo apply_filters'ninja_forms_credit_card_cvc_label'$cc_number_label ); ?></label>
                <?php
            
}

            if ( 
$desc_pos == 'after_label' ) {
                
?>
                <span><?php echo apply_filters'ninja_forms_credit_card_number_desc'$cc_number_desc ); ?></span>
                <?php
            
}
            
?>
            
            <input type="text" <?php if ( $post_field ){ echo 'name="_credit_card_number"'; } ?> class="ninja-forms-field card-number">
            
            <?php
            
if ( $label_pos == 'below' or $label_pos == 'right' ) {
                
?>
                <label><?php echo apply_filters'ninja_forms_credit_card_cvc_label'$cc_number_label ); ?></label>
                <?php
            
}

            if ( 
$desc_pos == 'after_everything' ) {
                
?>
                <span><?php echo apply_filters'ninja_forms_credit_card_number_desc'$cc_number_desc ); ?></span>
                <?php
            
}
            
?>
        </div>
        <div class="ninja-forms-error">
            <div class="ninja-forms-credit-card-number-error ninja-forms-field-error">
                <?php
                
if ( $card_number_errors ) {
                    if( 
is_array$card_number_errors ) ) {
                        foreach ( 
$card_number_errors as $error ) {
                            echo 
'<p>'.$error['msg'].'</p>';
                        }
                    }
                }
                
?>
            </div>
        </div>
    <?php
    
    
}
    if( !
in_array'cvc' $hide_cc_fields ) ){
    
    
?>
        <div class="ninja-forms-credit-card-cvc label-<?php echo $label_pos?> field-wrap"> <!-- [open_cvc_wrap] -->
            <?php
            
if ( $desc_pos == 'before_label' or $desc_pos == 'before_everything' ) {
                
?>
                <span><?php echo apply_filters'ninja_forms_credit_card_cvc_desc'$cc_cvc_desc ); ?></span>
                <?php
            
}

            if ( 
$label_pos == 'above' or $label_pos == 'left' ) {
                
?>
                <label><?php echo apply_filters'ninja_forms_credit_card_cvc_label'$cc_cvc_label ); ?></label>
                <?php
            
}

            if ( 
$desc_pos == 'after_label' ) {
                
?>
                <span><?php echo apply_filters'ninja_forms_credit_card_cvc_desc'$cc_cvc_desc ); ?></span>
                <?php
            
}
            
?>
            
            <input type="text" <?php if ( $post_field ){ echo 'name="_credit_card_cvc"'; } ?> class="ninja-forms-field card-cvc">
        
            <?php
            
if ( $label_pos == 'below' or $label_pos == 'right' ) {
                
?>
                <label><?php echo apply_filters'ninja_forms_credit_card_cvc_label'$cc_cvc_label ); ?></label>
                <?php
            
}

            if ( 
$desc_pos == 'after_everything' ) {
                
?>
                <span><?php echo apply_filters'ninja_forms_credit_card_cvc_desc'$cc_cvc_desc ); ?></span>
                <?php
            
}
            
?>

        </div>
        <div class="ninja-forms-error">
            <div class="ninja-forms-credit-card-cvc-error ninja-forms-field-error">
                <?php
                
if ( $card_cvc_errors ) {
                    if( 
is_array$card_cvc_errors ) ) {
                        foreach ( 
$card_cvc_errors as $error ) {
                            echo 
'<p>'.$error['msg'].'</p>';
                        }
                    }
                }
                
?>
            </div>
        </div>
    <?php
    
    
}
    if( !
in_array'name' $hide_cc_fields ) ){
    
    
?>    
        
        <div class="ninja-forms-credit-card-name label-<?php echo $label_pos?> field-wrap"> <!-- [open_nameoncard_wrap] -->
            <?php
            
if ( $desc_pos == 'before_label' or $desc_pos == 'before_everything' ) {
                
?>
                <span><?php echo apply_filters'ninja_forms_credit_card_name_desc'$cc_name_desc ); ?></span>
                <?php
            
}

            if ( 
$label_pos == 'above' or $label_pos == 'left' ) {
                
?>
                <label><?php echo apply_filters'ninja_forms_credit_card_name_label'$cc_name_label ); ?></label>
                <?php
            
}

            if ( 
$desc_pos == 'after_label' ) {
                
?>
                <span><?php echo apply_filters'ninja_forms_credit_card_name_desc'$cc_name_desc ); ?></span>
                <?php
            
}
            
?>
            
            <input type="text" <?php if ( $post_field ){ echo 'name="_credit_card_name"'; } ?> class="ninja-forms-field card-name" value="<?php echo $name;?>">
            
            <?php
            
if ( $label_pos == 'below' or $label_pos == 'right' ) {
                
?>
                <label><?php echo apply_filters'ninja_forms_credit_card_name_label'$cc_name_label ); ?></label>
                <?php
            
}

            if ( 
$desc_pos == 'after_everything' ) {
                
?>
                <span><?php echo apply_filters'ninja_forms_credit_card_name_desc'$cc_name_desc ); ?></span>
                <?php
            
}
            
?>

        </div>
        <div class="ninja-forms-error">
            <div class="ninja-forms-credit-card-name-error ninja-forms-field-error">
                <?php
                
if ( $card_name_errors ) {
                    if( 
is_array$card_name_errors ) ) {
                        foreach ( 
$card_name_errors as $error ) {
                            echo 
'<p>'.$error['msg'].'</p>';
                        }
                    }
                }
                
?>
            </div>
        </div>
    <?php
    
    
}
    if( !
in_array'expires' $hide_cc_fields ) ){
    
    
?>
        <div class="ninja-forms-credit-card-exp-month label-<?php echo $label_pos?> field-wrap"> <!-- [open_expires_wrap] -->
            <?php
            
if ( $desc_pos == 'before_label' or $desc_pos == 'before_everything' ) {
                
?>
                <span><?php echo apply_filters'ninja_forms_credit_card_exp_month_desc'$cc_exp_month_desc ); ?></span>
                <?php
            
}

            if ( 
$label_pos == 'above' or $label_pos == 'left' ) {
                
?>
                <label><?php echo apply_filters'ninja_forms_credit_card_exp_month_label'$cc_exp_month_label ); ?></label>
                <?php
            
}

            if ( 
$desc_pos == 'after_label' ) {
                
?>
                <span><?php echo apply_filters'ninja_forms_credit_card_exp_month_desc'$cc_exp_month_desc ); ?></span>
                <?php
            
}
            
?>

            <input type="text" <?php if ( $post_field ){ echo 'name="_credit_card_expires_month"'; } ?> class="ninja-forms-field ninja-forms-mask card-expiry-month" data-mask="99" value="<?php echo $expiry_month;?>">
            
            <?php
            
if ( $label_pos == 'below' or $label_pos == 'right' ) {
                
?>
                <label><?php echo apply_filters'ninja_forms_credit_card_exp_month_label'$cc_exp_month_label ); ?></label>
                <?php
            
}

            if ( 
$desc_pos == 'after_everything' ) {
                
?>
                <span><?php echo apply_filters'ninja_forms_credit_card_exp_month_desc'$cc_exp_month_desc ); ?></span>
                <?php
            
}
            
?>

        </div>
        <div class="ninja-forms-error">
            <div class="ninja-forms-credit-card-exp-month-error ninja-forms-field-error">
                <?php
                
if ( $card_month_errors ) {
                    if( 
is_array$card_month_errors ) ) {
                        foreach ( 
$card_month_errors as $error ) {
                            echo 
'<p>'.$error['msg'].'</p>';
                        }
                    }
                }
                
?>
            </div> <!-- [close_exp_month_wrap] -->
        </div>
        <div class="ninja-forms-credit-card-exp-year label-<?php echo $label_pos?> field-wrap"> <!-- [open_exp_year_wrap] -->
            <?php
            
if ( $desc_pos == 'before_label' or $desc_pos == 'before_everything' ) {
                
?>
                <span><?php echo apply_filters'ninja_forms_credit_card_exp_year_desc'$cc_exp_year_desc ); ?></span>
                <?php
            
}

            if ( 
$label_pos == 'above' or $label_pos == 'left' ) {
                
?>
                <label><?php echo apply_filters'ninja_forms_credit_card_exp_year_label'$cc_exp_year_label ); ?></label>
                <?php
            
}

            if ( 
$desc_pos == 'after_label' ) {
                
?>
                <span><?php echo apply_filters'ninja_forms_credit_card_exp_year_desc'$cc_exp_year_desc ); ?></span>
                <?php
            
}
            
?>

            <input type="text" <?php if ( $post_field ){ echo 'name="_credit_card_expires_year"'; } ?> class="ninja-forms-field ninja-forms-mask card-expiry-year" data-mask="9999" value="<?php echo $expiry_year;?>">
        
            <?php
            
if ( $label_pos == 'below' or $label_pos == 'right' ) {
                
?>
                <label><?php echo apply_filters'ninja_forms_credit_card_exp_year_label'$cc_exp_year_label ); ?></label>
                <?php
            
}

            if ( 
$desc_pos == 'after_everything' ) {
                
?>
                <span><?php echo apply_filters'ninja_forms_credit_card_exp_year_desc'$cc_exp_year_desc ); ?></span>
                <?php
            
}
            
?>

        </div>
        <div class="ninja-forms-error">
            <div class="ninja-forms-credit-card-exp-year-error ninja-forms-field-error">
                <?php
                
if ( $card_year_errors ) {
                    if( 
is_array$card_year_errors ) ) {
                        foreach ( 
$card_year_errors as $error ) {
                            echo 
'<p>'.$error['msg'].'</p>';
                        }
                    }
                }
                
?>
            </div> <!-- [close_exp_month_wrap] -->
        </div>
    <?php
    
}
}

/*
 *
 * Function that filters the display script field data so that the mask is included for the expires field.
 *
 * @since 2.2.37
 * @returns array $data
 */

function ninja_forms_field_credit_card_expire_filter$data$field_id ){
    
$field ninja_forms_get_field_by_id$field_id );
    if ( 
$field['type'] == '_credit_card' ) {
        
$data['mask'] = '99/9999';
    }
    return 
$data;
}

add_action'ninja_forms_display_script_field_data''ninja_forms_field_credit_card_expire_filter'10);