-
Notifications
You must be signed in to change notification settings - Fork 2
/
forms.php
1234 lines (1053 loc) · 31.5 KB
/
forms.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
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/**
* Gravity Forms Pages Forms Functions
*
* @package Gravity Forms Pages
* @subpackage Main
*/
// Exit if accessed directly
defined( 'ABSPATH' ) || exit;
/** Query *********************************************************************/
/**
* Setup and run the Forms query
*
* @since 1.0.0
*
* @param array $args Query arguments.
* @return bool Has the query returned any results?
*/
function gf_pages_query_forms( $args = array() ) {
// Get query object
$query = gf_pages()->form_query;
// Reset query defaults
$query->in_the_loop = false;
$query->current_form = -1;
$query->form_count = 0;
$query->form = null;
$query->forms = array();
// Define query args
$r = wp_parse_args( $args, array(
'number' => gf_pages_get_forms_per_page(),
'paged' => gf_pages_get_paged(),
'fields' => 'all',
'show_active' => true,
'orderby' => 'date_created',
'order' => 'DESC'
) );
// Pagination
if ( (int) $r['number'] > 0 ) {
$r['paged'] = absint( $r['paged'] );
if ( $r['paged'] == 0 ) {
$r['paged'] = 1;
}
$r['offset'] = absint( ( $r['paged'] - 1 ) * $r['number'] );
} else {
$r['number'] = -1;
}
// Run query to get the forms
if ( method_exists( $query, 'query' ) ) {
$query->query( $r );
} else {
$query->forms = gf_pages_get_forms( $r );
}
// Set query results
$query->form_count = count( $query->forms );
if ( $query->form_count > 0 ) {
$query->form = $query->forms[0];
}
// Determine the total form count
if ( isset( $r['offset'] ) && ! $query->form_count < $r['number'] ) {
$query->found_forms = gf_pages_query_forms_found_rows( $r );
} else {
$query->found_forms = $query->form_count;
}
if ( $query->found_forms > $query->form_count ) {
$query->max_num_pages = (int) ceil( $query->found_forms / $r['number'] );
} else {
$query->max_num_pages = 1;
}
// Return whether the query has returned results
return gf_pages_has_forms();
}
/**
* Return whether the query has Forms to loop over
*
* @since 1.0.0
*
* @return bool Query has Forms
*/
function gf_pages_has_forms() {
// Get query object
$query = gf_pages()->form_query;
// Get array keys
$form_keys = array_keys( $query->forms );
// Current element is not the last
$has_next = $query->form_count && $query->current_form < end( $form_keys );
// We're in the loop when there are still elements
if ( ! $has_next ) {
$query->in_the_loop = false;
// Clean up after the loop
gf_pages_rewind_forms();
}
return $has_next;
}
/**
* Setup next Volume in the current loop
*
* @since 1.0.0
*/
function gf_pages_the_form() {
// Get query object
$query = gf_pages()->form_query;
// We're looping
$query->in_the_loop = true;
// Increase current form index
$query->current_form++;
// Get next form in list
if ( isset( $query->forms[ $query->current_form ] ) ) {
$query->form = $query->forms[ $query->current_form ];
}
}
/**
* Rewind the forms and reset form index
*
* @since 1.0.0
*/
function gf_pages_rewind_forms() {
// Get query object
$query = gf_pages()->form_query;
// Reset current form index
$query->current_form = -1;
if ( $query->form_count > 0 ) {
$query->form = $query->forms[0];
}
}
/**
* Return whether we're in the Form loop
*
* @since 1.0.0
*
* @return bool Are we in the Form loop?
*/
function gf_pages_in_the_form_loop() {
return isset( gf_pages()->form_query->in_the_loop ) ? gf_pages()->form_query->in_the_loop : false;
}
/** Single Form ***************************************************************/
/**
* Output the current form ID
*
* @since 1.0.0
*/
function gf_pages_the_form_id() {
echo gf_pages_get_form_id();
}
/**
* Get the current form ID
*
* @since 1.0.0
*
* @uses apply_filters() Calls 'gf_pages_get_form_id'
* @return int Form ID
*/
function gf_pages_get_form_id() {
$form = gf_pages_get_form();
$form_id = 0;
if ( ! empty( $form ) ) {
$form_id = $form->id;
}
return (int) apply_filters( 'gf_pages_get_form_id', $form_id, $form );
}
/**
* Output the current form title
*
* @since 1.0.0
*
* @param object|int $form Optional. Form data or ID. Defaults to the current form.
*/
function gf_pages_the_form_title( $form = 0 ) {
echo gf_pages_get_form_title( $form );
}
/**
* Get the current form title
*
* @since 1.0.0
*
* @uses apply_filters() Calls 'gf_pages_get_form_title'
*
* @param object|int $form Optional. Form data or ID. Defaults to the current form.
* @return string Form title
*/
function gf_pages_get_form_title( $form = 0 ) {
$form = gf_pages_get_form( $form );
$title = '';
if ( ! empty( $form ) ) {
$title = $form->title;
}
return apply_filters( 'gf_pages_get_form_title', $title, $form );
}
/**
* Output the current form description
*
* @since 1.0.0
*
* @param object|int $form Optional. Form data or ID. Defaults to the current form.
*/
function gf_pages_the_form_description( $form = 0 ) {
echo gf_pages_get_form_description( $form );
}
/**
* Get the current form description
*
* @since 1.0.0
*
* @uses apply_filters() Calls 'gf_pages_get_form_description'
*
* @param object|int $form Optional. Form data or ID. Defaults to the current form.
* @return string Form description
*/
function gf_pages_get_form_description( $form = 0 ) {
$form = gf_pages_get_form( $form );
$desc = '';
if ( ! empty( $form ) ) {
$desc = $form->description;
// Provide default description
if ( empty( $desc ) ) {
$desc = apply_filters( 'gf_pages_default_form_description', esc_html__( 'There is no description provided for this form.', 'gravityforms-pages' ), $form );
}
}
return apply_filters( 'gf_pages_get_form_description', $desc, $form );
}
/**
* Output the current form content
*
* @since 1.0.0
*
* @param object|int $form Optional. Form data or ID. Defaults to the current form.
* @param bool $title Optional. Whether to add the form title. Defaults to false.
* @param bool $description Optional. Whether to add the form description. Defaults to true.
* @param bool $ajax Optional. Whether to add ajax functionality. Defaults to false.
*/
function gf_pages_the_form_content( $form = 0, $title = false, $description = true, $ajax = false ) {
echo gf_pages_get_form_content( $form, $title, $description, $ajax );
}
/**
* Get the current form content
*
* Builds the form shortcode and returns it.
*
* @since 1.0.0
*
* @uses apply_filters() Calls 'gf_pages_get_form_content'
*
* @param object|int $form Optional. Form data or ID. Defaults to the current form.
* @param bool $title Optional. Whether to add the form title. Defaults to false.
* @param bool $description Optional. Whether to add the form description. Defaults to true.
* @param bool $ajax Optional. Whether to add ajax functionality. Defaults to false.
* @return string Form content
*/
function gf_pages_get_form_content( $form = 0, $title = false, $description = true, $ajax = false ) {
$form = gf_pages_get_form( $form );
$content = '';
// Build shortcode
if ( ! empty( $form ) ) {
// Start shortcode
$content = '[gravityforms id="' . $form->id . '"';
if ( ! $title ) {
$content .= ' title="false"';
}
// With description
if ( ! $description ) {
$content .= ' description="false"';
}
// With AJAX
if ( $ajax || gf_pages_force_ajax() ) {
$content .= ' ajax="true"';
}
// End shortcode
$content .= ']';
}
return apply_filters( 'gf_pages_get_form_content', $content, $form, $title, $description, $ajax );
}
/**
* Output the current form excerpt from form description
*
* @since 1.0.0
*
* @param object|int $form Optional. Form data or ID. Defaults to the current form.
* @param int $length Optional. Length of the excerpt. Defaults to 55 words.
*/
function gf_pages_the_form_excerpt( $form = 0, $length = 55 ) {
echo gf_pages_get_form_excerpt( $form );
}
/**
* Get the current form excerpt from form description
*
* @since 1.0.0
*
* @uses apply_filters() Calls 'gf_pages_get_form_excerpt'
*
* @param object|int $form Optional. Form data or ID. Defaults to the current form.
* @param int $length Optional. Length of the excerpt in words. Defaults to 55 words.
* @return string Form excerpt
*/
function gf_pages_get_form_excerpt( $form = 0, $length = 55 ) {
$form = gf_pages_get_form( $form );
$length = (int) $length;
$desc = gf_get_form_description( $form );
$excerpt = '';
// When form description is available
if ( ! empty( $form ) && $desc ) {
$excerpt = trim( strip_tags( $desc ) );
$excerpt = wp_trim_words( $excerpt, $length );
}
return apply_filters( 'gf_pages_get_form_excerpt', $excerpt, $form, $length );
}
/**
* Output the current form post date
*
* @since 1.0.0
*
* @param string $format Optional. Date format. Defaults to 'Y-m-d'.
* @param object|int $form Optional. Form data or ID. Defaults to the current form.
*/
function gf_pages_the_form_post_date( $format = 'Y-m-d', $form = 0 ) {
echo gf_pages_get_form_post_date( $format, $form );
}
/**
* Get the current form post date
*
* @since 1.0.0
*
* @uses apply_filters() Calls 'gf_pages_get_form_post_date'
*
* @param string $format Optional. Date format. Defaults to 'Y-m-d'.
* @param object|int $form Optional. Form data or ID. Defaults to the current form.
* @return string Form post date
*/
function gf_pages_get_form_post_date( $format = 'Y-m-d', $form = 0 ) {
$form = gf_pages_get_form( $form );
$date = false;
$formatted = '';
if ( ! empty( $form ) ) {
$date = $form->date_created;
if ( $date ) {
$date = DateTime::createFromFormat( 'Y-m-d H:i:s', $date );
$formatted = date_i18n( $format, $date->format( 'U' ) );
}
}
return apply_filters( 'gf_pages_get_form_post_date', $formatted, $format, $form, $date );
}
/**
* Output the form open date
*
* @since 1.0.0
*
* @param string $format Optional. Date format. Defaults to 'Y-m-d'.
* @param object|int $form Optional. Form data or ID. Defaults to the current form.
*/
function gf_pages_the_form_open_date( $format = 'Y-m-d', $form = 0 ) {
echo gf_pages_get_form_open_date( $format, $form );
}
/**
* Get the current form open date
*
* @since 1.0.0
*
* @uses apply_filters() Calls 'gf_pages_get_form_open_date'
*
* @param string $format Optional. Date format. Defaults to 'Y-m-d'.
* @param object|int $form Optional. Form data or ID. Defaults to the current form.
* @return string Form open date
*/
function gf_pages_get_form_open_date( $format = 'Y-m-d', $form = 0 ) {
$form = gf_pages_get_form( $form );
$date = false;
$formatted = '';
if ( ! empty( $form ) ) {
// Form is scheduled and has defined start date
if ( isset( $form->scheduleForm ) && $form->scheduleForm && ! empty( $form->scheduleStart ) ) {
// Force leading zeros on minutes
$minutes = sprintf( '%02d', $form->scheduleStartMinute );
// Create readable date format
$date = "{$form->scheduleStart} {$form->scheduleStartHour}:{$minutes} {$form->scheduleStartAmpm}";
$date = DateTime::createFromFormat( 'm/d/Y g:i a', $date );
$formatted = date_i18n( $format, $date->format( 'U' ) );
} else {
$formatted = gf_pages_get_form_post_date( $format, $form );
}
}
return apply_filters( 'gf_pages_get_form_open_date', $formatted, $format, $form, $date );
}
/**
* Output the form close date
*
* @since 1.0.0
*
* @param string $format Optional. Date format. Defaults to 'Y-m-d'.
* @param object|int $form Optional. Form data or ID. Defaults to the current form.
*/
function gf_pages_the_form_close_date( $format = 'Y-m-d', $form = 0 ) {
echo gf_pages_get_form_close_date( $format, $form );
}
/**
* Get the current form close date
*
* @since 1.0.0
*
* @uses apply_filters() Calls 'gf_pages_get_form_close_date'
*
* @param string $format Optional. Date format. Defaults to 'Y-m-d'.
* @param object|int $form Optional. Form data or ID. Defaults to the current form.
* @return string Form close date
*/
function gf_pages_get_form_close_date( $format = 'Y-m-d', $form = 0 ) {
$form = gf_pages_get_form( $form );
$date = false;
$formatted = '';
if ( ! empty( $form ) ) {
// Form is scheduled and has defined end date
if ( isset( $form->scheduleForm ) && $form->scheduleForm && ! empty( $form->scheduleEnd ) ) {
// Force leading zeros on minutes
$minutes = sprintf( '%02d', $form->scheduleEndMinute );
// Create readable date format
$date = "{$form->scheduleEnd} {$form->scheduleEndHour}:{$minutes} {$form->scheduleEndAmpm}";
$date = DateTime::createFromFormat( 'm/d/Y g:i a', $date );
$formatted = date_i18n( $format, $date->format( 'U' ) );
}
}
return apply_filters( 'gf_pages_get_form_close_date', $formatted, $format, $form, $date );
}
/**
* Return whether the form is open for entries
*
* @since 1.0.0
*
* @uses apply_filters() Calls 'gf_pages_is_form_open'
*
* @param object|int $form Optional. Form data or ID. Defaults to the current form.
* @return bool Form is open
*/
function gf_pages_is_form_open( $form = 0 ) {
$form = gf_pages_get_form( $form );
$open = true;
if ( ! empty( $form ) ) {
// Inactive forms are closed
if ( gf_pages_is_form_inactive( $form ) ) {
$open = false;
// Is form schedule enabled
} elseif ( isset( $form->scheduleForm ) && $form->scheduleForm ) {
// We're here before opening hours
if ( time() < gf_pages_get_form_open_date( 'U', $form ) ) {
$open = false;
}
}
}
return (bool) apply_filters( 'gf_pages_is_form_open', $open, $form );
}
/**
* Return whether the form is not open for entries anymore
*
* @since 1.0.0
*
* @uses apply_filters() Calls 'gf_pages_is_form_closed'
*
* @param object|int $form Optional. Form data or ID. Defaults to the current form.
* @return bool Form is closed
*/
function gf_pages_is_form_closed( $form = 0 ) {
$form = gf_pages_get_form( $form );
$closed = false;
if ( ! empty( $form ) ) {
// Inactive forms are closed
if ( gf_pages_is_form_inactive( $form ) ) {
$closed = true;
// Is form schedule enabled
} elseif ( isset( $form->scheduleForm ) && $form->scheduleForm ) {
// We're past due date
if ( time() > gf_pages_get_form_close_date( 'U', $form ) ) {
$closed = true;
}
}
}
return (bool) apply_filters( 'gf_pages_is_form_closed', $closed, $form );
}
/**
* Output the current form link
*
* @since 1.0.0
*
* @param array $args See {@see gf_pages_get_form_link()}.
*/
function gf_pages_the_form_link( $args = array() ) {
echo gf_pages_get_form_link( $args );
}
/**
* Get the current form link
*
* @since 1.0.0
*
* @uses apply_filters() Calls 'gf_pages_get_form_link'
*
* @param array $args Function arguments, supports these args:
* - form: Form object or ID. Defaults to the current form.
* - link_before: Markup to put before the link. Defaults to an empty string.
* - link_after: Markup to put after the link. Defaults to an empty string.
* - link_text: Link text. Defaults to the form title.
* @return string Form link
*/
function gf_pages_get_form_link( $args = array() ) {
$r = wp_parse_args( $args, array(
'form' => 0,
'link_before' => '',
'link_after' => '',
'link_text' => '',
) );
$form = gf_pages_get_form( $r['form'] );
$link = '';
if ( ! empty( $form ) ) {
$url = gf_pages_get_form_url( $form );
if ( $url ) {
$link = sprintf( '%s<a href="%s" title="%s">%s</a>%s',
$r['link_before'],
esc_url( $url ),
sprintf( esc_html__( 'Complete form %s', 'gravityforms-pages' ), gf_pages_get_form_title( $form ) ),
! empty( $r['link_text'] ) ? $r['link_text'] : gf_pages_get_form_title( $form ),
$r['link_after']
);
}
}
return apply_filters( 'gf_pages_get_form_link', $link, $form, $r );
}
/**
* Output the current form url
*
* @since 1.0.0
*
* @param object|int $form Optional. Form data or ID. Defaults to the current form.
*/
function gf_pages_the_form_url( $form = 0 ) {
echo gf_pages_get_form_url( $form );
}
/**
* Get the current form url
*
* @since 1.0.0
*
* @uses apply_filters() Calls 'gf_pages_get_form_url'
*
* @param object|int $form Optional. Form data or ID. Defaults to the current form.
* @return string Form url
*/
function gf_pages_get_form_url( $form = 0 ) {
global $wp_rewrite;
$form = gf_pages_get_form( $form );
$url = '';
if ( ! empty( $form ) ) {
// Using pretty permalinks
if ( $wp_rewrite->using_permalinks() ) {
$url = home_url( trailingslashit( $wp_rewrite->root . gf_pages_get_forms_slug() . '/' . gf_pages_get_form_slug( $form ) ) );
// Unpretty permalinks
} else {
$url = add_query_arg( gf_pages_get_form_rewrite_id(), $form->id, home_url( '/' ) );
}
}
return apply_filters( 'gf_pages_get_form_url', $url, $form );
}
/**
* Output the form's edit link
*
* @since 1.0.0
*
* @param array $args See {@see gf_pages_get_form_edit_link()}.
*/
function gf_pages_the_form_edit_link( $args = array() ) {
echo gf_pages_get_form_edit_link( $args );
}
/**
* Get the form's edit link
*
* @since 1.0.0
*
* @uses apply_filters() Calls 'gf_pages_get_form_edit_link'
*
* @param array $args Function arguments, supports these args:
* - form: Form object or ID. Defaults to the current form.
* - link_before: Markup to put before the link. Defaults to an empty string.
* - link_after: Markup to put after the link. Defaults to an empty string.
* - link_text: Link text. Defaults to 'Edit'.
* @return string Edit form link
*/
function gf_pages_get_form_edit_link( $args = array() ) {
$r = wp_parse_args( $args, array(
'form' => 0,
'link_before' => '',
'link_after' => '',
'link_text' => esc_html__( 'Edit', 'gravityforms-pages' ),
) );
$form = gf_pages_get_form( $r['form'] );
$link = '';
if ( ! empty( $form ) ) {
$url = gf_pages_get_form_edit_url( $form );
if ( $url ) {
$link = sprintf( '%s<a href="%s" title="%s">%s</a>%s',
$r['link_before'],
esc_url( $url ),
sprintf( esc_html__( 'Edit form %s', 'gravityforms-pages' ), gf_pages_get_form_title( $form ) ),
$r['link_text'],
$r['link_after']
);
}
}
return apply_filters( 'gf_pages_get_form_edit_link', $link, $form, $r );
}
/**
* Output the form's edit url
*
* @since 1.0.0
*
* @param object|int $form Optional. Form data or ID. Defaults to the current form.
*/
function gf_pages_the_form_edit_url( $form = 0 ) {
echo gf_pages_get_form_edit_url( $form );
}
/**
* Get the form's edit url
*
* @since 1.0.0
*
* @uses apply_filters() Calls 'gf_pages_get_form_edit_url'
*
* @param object|int $form Optional. Form data or ID. Defaults to the current form.
* @return string Edit form url
*/
function gf_pages_get_form_edit_url( $form = 0 ) {
$form = gf_pages_get_form( $form );
$url = '';
if ( ! empty( $form ) ) {
$url = add_query_arg( array( 'page' => 'gf_edit_forms', 'id' => $form->id ), admin_url( 'admin.php' ) );
}
return apply_filters( 'gf_pages_get_form_edit_url', $url, $form );
}
/**
* Output the view form entries url
*
* @since 1.0.0
*
* @param object|int $form Optional. Form data or ID. Defaults to the current form.
*/
function gf_pages_the_view_form_entries_url( $form = 0 ) {
echo gf_pages_get_view_form_entries_url( $form );
}
/**
* Get the view form entries url
*
* @since 1.0.0
*
* @uses apply_filters() Calls 'gf_pages_get_view_form_entries_url'
*
* @param object|int $form Optional. Form data or ID. Defaults to the current form.
* @return string Edit form url
*/
function gf_pages_get_view_form_entries_url( $form = 0 ) {
$form = gf_pages_get_form( $form );
$url = '';
if ( ! empty( $form ) ) {
$url = add_query_arg( array( 'page' => 'gf_entries', 'id' => $form->id ), admin_url( '/admin.php' ) );
}
return apply_filters( 'gf_pages_get_view_form_entries_url', $url, $form );
}
/**
* Output the current form view count
*
* @since 1.0.0
*
* @param object|int $form Optional. Form data or ID. Defaults to the current form.
*/
function gf_pages_the_form_view_count( $form = 0 ) {
echo gf_pages_get_form_view_count( $form );
}
/**
* Get the current form view count
*
* @since 1.0.0
*
* @uses apply_filters() Calls 'gf_pages_get_form_view_count'
*
* @param object|int $form Optional. Form data or ID. Defaults to the current form.
* @return string Form view count
*/
function gf_pages_get_form_view_count( $form = 0 ) {
$form = gf_pages_get_form( $form );
$count = 0;
if ( ! empty( $form ) ) {
$count = $form->view_count;
}
return (int) apply_filters( 'gf_pages_get_form_view_count', $count, $form );
}
/**
* Output the current form lead count
*
* @since 1.0.0
*
* @param object|int $form Optional. Form data or ID. Defaults to the current form.
*/
function gf_pages_the_form_entry_count( $form = 0 ) {
echo gf_pages_get_form_entry_count( $form );
}
/**
* Get the current form lead count
*
* @since 1.0.0
*
* @uses apply_filters() Calls 'gf_pages_get_form_entry_count'
*
* @todo Fix corrupt lead count, empty when it should not
*
* @param object|int $form Optional. Form data or ID. Defaults to the current form.
* @return string Form lead count
*/
function gf_pages_get_form_entry_count( $form = 0 ) {
$form = gf_pages_get_form( $form );
$count = 0;
if ( ! empty( $form ) ) {
$count = $form->lead_count;
}
return (int) apply_filters( 'gf_pages_get_form_entry_count', $count, $form );
}
/**
* Output the form entry count display
*
* @since 1.0.0
*
* @param object|int $form Optional. Form data or ID. Defaults to the current form.
*/
function gf_pages_the_form_display_entry_count( $form = 0 ) {
echo gf_pages_get_form_display_entry_count( $form );
}
/**
* Get the form entry count display
*
* @since 1.0.0
*
* @uses apply_filters() Calls 'gf_pages_form_display_entry_count_class'
* @uses apply_filters() Calls 'gf_pages_get_form_display_entry_count'
*
* @param object|int $form Optional. Form data or ID. Defaults to the current form.
* @return string Form entry count display
*/
function gf_pages_get_form_display_entry_count( $form = 0 ) {
$form = gf_pages_get_form( $form );
$retval = '';
if ( ! empty( $form ) ) {
$count = gf_pages_get_form_entry_count( $form );
$class = apply_filters( 'gf_pages_form_display_entry_count_class', 'entry-count', $form );
$args = array();
// Form has entry limit
if ( gf_pages_has_form_entry_limit( $form ) ) {
$text = __( '%s of %s Entries', 'gravityforms-pages' );
$args[] = sprintf( '<span class="%s">%d</span>', $class, $count );
$args[] = sprintf( '<span class="entry-count-limit">%d</span>', gf_pages_get_form_entry_limit( $form ) );
// No limit
} else {
$text = _n( '%s Entry', '%s Entries', $count, 'gravityforms-pages' );
$args[] = sprintf( '<span class="%s">%d</span>', $class, $count );
}
// Merge entry count text
$retval = vsprintf( $text, $args );
}
return apply_filters( 'gf_pages_get_form_display_entry_count', $retval, $form );
}
/** Form Archive **************************************************************/
/**
* Output the form archive title
*
* @since 1.0.0
*/
function gf_pages_the_form_archive_title() {
echo gf_pages_get_form_archive_title();
}
/**
* Get the form archive title
*
* @since 1.0.0
*
* @uses apply_filters() Calls 'gf_pages_form_archive_title'
* @return string Form archive title
*/
function gf_pages_get_form_archive_title() {
$title = gf_pages_form_archive_title();
// Set default title
if ( ! $title ) {
$title = esc_html_x( 'Forms', 'Default form archive title', 'gravityforms-pages' );
}
return apply_filters( 'gf_pages_get_form_archive_title', $title );
}
/**
* Output the form archive description
*
* @since 1.0.0
*/
function gf_pages_the_form_archive_description() {
echo gf_pages_get_form_archive_description();
}
/**
* Get the form archive description
*
* @since 1.0.0
*
* @uses apply_filters() Calls 'gf_pages_form_archive_description'
* @return string Form archive description
*/
function gf_pages_get_form_archive_description() {
return apply_filters( 'gf_pages_get_form_archive_description', gf_pages_form_archive_description() );
}
/**
* Output the archive form link
*
* @since 1.0.0
*
* @param array $args See {@see gf_pages_get_form_archive_link()}.
*/
function gf_pages_the_form_archive_link( $args = array() ) {
echo gf_pages_get_form_archive_link( $args );
}
/**
* Get the archive form link
*
* @since 1.0.0
*
* @uses apply_filters() Calls 'gf_pages_get_form_archive_link'
*
* @param array $args Function arguments, supports these args:
* - link_before: Markup to put before the link. Defaults to an empty string.
* - link_after: Markup to put after the link. Defaults to an empty string.
* - link_text: Link text. Defaults to the archive title.
* @return string Form link
*/
function gf_pages_get_form_archive_link( $args = array() ) {
$r = wp_parse_args( $args, array(
'link_before' => '',
'link_after' => '',
'link_text' => gf_pages_get_form_archive_title(),
) );
$url = gf_pages_get_form_archive_url();
$link = '';
if ( $url ) {
$link = sprintf( '%s<a href="%s">%s</a>%s',
$r['link_before'],
esc_url( $url ),
$r['link_text'],
$r['link_after']
);
}
return apply_filters( 'gf_pages_get_form_archive_link', $link, $r );
}
/**
* Output the archive form url
*
* @since 1.0.0
*/
function gf_pages_the_form_archive_url() {
echo gf_pages_get_form_archive_url();
}
/**
* Get the archive form url
*
* @since 1.0.0
*