-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclass-gf-capsulecrm.php
More file actions
2167 lines (1796 loc) · 59 KB
/
Copy pathclass-gf-capsulecrm.php
File metadata and controls
2167 lines (1796 loc) · 59 KB
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
// don't load directly
if ( ! defined( 'ABSPATH' ) ) {
die();
}
/**
* Contains the primary functionality of the Capsule CRM add-on.
*
* @package gravityformscapsulecrm
*/
GFForms::include_feed_addon_framework();
/**
* The main class for the Capsule CRM add-on.
*
* @package GFCapsuleCRM
*
* @uses GFFeedAddOn
*/
class GFCapsuleCRM extends GFFeedAddOn {
/**
* Defines the add-on version.
*
* @var string
*/
protected $_version = GF_CAPSULECRM_VERSION;
/**
* Defines minimum gravity forms version required.
*
* @var string
*/
protected $_min_gravityforms_version = '2.5';
/**
* The add-on slug.
*
* @var string
*/
protected $_slug = 'gravityformscapsulecrm';
/**
* The path to the main plugin file.
*
* Relative to the WordPress plugins folder.
*
* @var string
*/
protected $_path = 'gravityformscapsulecrm/capsulecrm.php';
/**
* The full path to this file.
*
* @var string
*/
protected $_full_path = __FILE__;
/**
* The add-on URL.
*
* @var string
*/
protected $_url = 'http://www.gravityforms.com';
/**
* The title of the add-on.
*
* @var string
*/
protected $_title = 'Gravity Forms Capsule CRM Add-On';
/**
* The add-on short title.
*
* @var string
*/
protected $_short_title = 'Capsule CRM';
/**
* If this add-on should allow auto-updates.
*
* @var string
*/
protected $_enable_rg_autoupgrade = true;
/**
* Stores the API class.
*
* @var GF_CapsuleCRM_API
*/
protected $api = null;
/**
* Stores the instance of this class.
*
* @var GFCapsuleCRM|null
*/
private static $_instance = null;
/* Members plugin integration */
/**
* Capabilites required for this add-on.
*
* @var array
*/
protected $_capabilities = array( 'gravityforms_capsulecrm', 'gravityforms_capsulecrm_uninstall' );
/**
* Permissions required to access theadd-on on the Gravity Forms settings page.
*
* @var string
*/
protected $_capabilities_settings_page = 'gravityforms_capsulecrm';
/**
* Permissions required to access the add-on on the form settings page.
*
* @var string
*/
protected $_capabilities_form_settings = 'gravityforms_capsulecrm';
/**
* Permissions required to uninstall this add-on.
*
* @var string
*/
protected $_capabilities_uninstall = 'gravityforms_capsulecrm_uninstall';
/**
* Enabling background feed processing to prevent performance issues delaying form submission completion.
*
* @since 1.7
*
* @var bool
*/
protected $_async_feed_processing = true;
/**
* Get instance of this class.
*
* @since 1.0
* @access public
*
* @return GFCapsuleCRM
*/
public static function get_instance() {
if ( self::$_instance == null ) {
self::$_instance = new self;
}
return self::$_instance;
}
/**
* Register needed plugin hooks and PayPal delayed payment support.
*
* @since 1.0
* @access public
*
* @uses GFCommon::add_dismissible_message()
* @uses GFFeedAddOn::add_delayed_payment_support()
*/
public function init() {
parent::init();
if ( get_option( 'gform_capsulecrm_oauth_upgrade_needed' ) ) {
// Prepare message.
$message = sprintf(
esc_html__( "Recent upgrades to Capsule CRM's API require re-authenticating your account. %sClick here to update your authentication settings.%s %sNo Capsule CRM feeds will be processed until reauthenticated.%s", 'gravityformscapsulecrm' ),
'<a href="' . admin_url( 'admin.php?page=gf_settings&subview=gravityformscapsulecrm' ) . '">',
'</a>',
'<strong>',
'</strong>'
);
GFCommon::add_dismissible_message( $message, 'capsulecrm_oauth_upgrade', 'error', false, true );
}
$this->add_delayed_payment_support(
array(
'option_label' => esc_html__( 'Create Capsule CRM object only when payment is received.', 'gravityformscapsulecrm' ),
)
);
}
/**
* Register needed styles.
*
* @since 1.0
* @access public
*
* @uses GFAddOn::get_base_url()
*
* @return array $styles
*/
public function styles() {
$min = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG || isset( $_GET['gform_debug'] ) ? '' : '.min';
$styles = array(
array(
'handle' => 'gform_capsulecrm_form_settings_css',
'src' => $this->get_base_url() . "/css/form_settings{$min}.css",
'version' => $this->_version,
'enqueue' => array(
array( 'admin_page' => array( 'form_settings' ) ),
),
),
);
return array_merge( parent::styles(), $styles );
}
// # PLUGIN SETTINGS -----------------------------------------------------------------------------------------------
/**
* Setup plugin settings fields.
*
* @since 1.0
* @access public
*
* @uses GFCapsuleCRM::initialize_api()
*
* @return array
*/
public function plugin_settings_fields() {
// Prepare description.
$description = sprintf(
'<p>%s</p>',
sprintf(
esc_html__( 'Capsule CRM is a contact management tool that makes it easy to track cases, opportunities, people, and tasks. Use Gravity Forms to collect customer information and automatically add it to your Capsule CRM account. If you don\'t have a Capsule CRM account, you can %1$s sign up for one here.%2$s', 'gravityformscapsulecrm' ),
'<a href="http://www.capsulecrm.com/" target="_blank">',
'</a>'
)
);
// Add authentication instructions to description.
$description .= sprintf(
'<p>%s</p>',
esc_html__( 'Gravity Forms Capsule CRM Add-On requires a personal access token, which you can find in your account under My Preferences -> API Authentication Tokens.', 'gravityformscapsulecrm' )
);
return array(
array(
'title' => '',
'description' => $description,
'fields' => array(
array(
'name' => 'authToken',
'label' => esc_html__( 'Personal Access Token', 'gravityformscapsulecrm' ),
'type' => 'text',
'class' => 'large',
'feedback_callback' => array( $this, 'initialize_api' ),
),
array(
'type' => 'save',
'messages' => array(
'success' => esc_html__( 'Capsule CRM settings have been updated.', 'gravityformscapsulecrm' ),
),
),
),
),
);
}
/**
* Updates plugin settings with the provided settings.
* (Forked to trigger milestone migration.)
*
* @since 1.2
* @access public
*
* @param array $settings Plugin settings to be saved.
*
* @uses GFCapsuleCRM::upgrade_milestones()
*/
public function update_plugin_settings( $settings ) {
// Update plugin settings.
parent::update_plugin_settings( $settings );
// If upgrade flag is not set, exit.
if ( ! get_option( 'gform_capsulecrm_oauth_upgrade_needed' ) ) {
return;
}
// If API is initialized, upgrade.
if ( $this->initialize_api() ) {
$this->upgrade_milestones();
}
}
// # FEED SETTINGS -------------------------------------------------------------------------------------------------
/**
* Setup fields for feed settings.
*
* @since 1.0
* @access public
*
* @uses GFCapsuleCRM::custom_fields_for_feed_mapping()
* @uses GFCapsuleCRM::get_categories_as_choices()
* @uses GFCapsuleCRM::get_milestones_as_choices()
* @uses GFCapsuleCRM::get_task_assignments_as_choices()
* @uses GFCapsuleCRM::get_users_as_choices()
* @uses GFCapsuleCRM::standard_fields_for_feed_mapping()
* @uses GFFeedAddOn::get_default_feed_name()
*
* @return array
*/
public function feed_settings_fields() {
return array(
array(
'title' => '',
'fields' => array(
array(
'name' => 'feed_name',
'label' => esc_html__( 'Feed Name', 'gravityformscapsulecrm' ),
'type' => 'text',
'required' => true,
'class' => 'medium',
'default_value' => $this->get_default_feed_name(),
'tooltip' => sprintf(
'<h6>%s</h6>%s',
esc_html__( 'Name', 'gravityformscapsulecrm' ),
esc_html__( 'Enter a feed name to uniquely identify this setup.', 'gravityformscapsulecrm' )
),
),
array(
'name' => 'action',
'label' => esc_html__( 'Action', 'gravityformscapsulecrm' ),
'type' => 'checkbox',
'required' => true,
'onclick' => "jQuery(this).parents('form').submit();",
'choices' => array(
array(
'name' => 'create_person',
'label' => esc_html__( 'Create New Person', 'gravityformscapsulecrm' ),
),
array(
'name' => 'create_task',
'label' => esc_html__( 'Create New Task', 'gravityformscapsulecrm' ),
),
),
),
),
),
array(
'title' => esc_html__( 'Person Details', 'gravityformscapsulecrm' ),
'dependency' => array( 'field' => 'create_person', 'values' => array( '1' ) ),
'fields' => array(
array(
'name' => 'person_standard_fields',
'label' => esc_html__( 'Map Fields', 'gravityformscapsulecrm' ),
'type' => 'field_map',
'field_map' => $this->standard_fields_for_feed_mapping(),
'tooltip' => sprintf(
'<h6>%s</h6>%s',
esc_html__( 'Map Fields', 'gravityformscapsulecrm' ),
esc_html__( 'Select which Gravity Form fields pair with their respective Capsule CRM fields.', 'gravityformscapsulecrm' )
),
),
array(
'name' => 'person_custom_fields',
'label' => '',
'type' => 'generic_map',
'key_field' => array(
'choices' => $this->custom_fields_for_feed_mapping(),
'allow_custom' => false,
),
'value_field' => array(
'allow_custom' => false,
),
),
array(
'name' => 'person_about',
'label' => esc_html__( 'About', 'gravityformscapsulecrm' ),
'type' => 'textarea',
'class' => 'medium merge-tag-support mt-position-right mt-hide_all_fields',
),
array(
'name' => 'update_person',
'label' => esc_html__( 'Update Person', 'gravityformscapsulecrm' ),
'type' => 'checkbox_and_select',
'tooltip' => sprintf(
'<h6>%s</h6>%s',
esc_html__( 'Update Person', 'gravityformscapsulecrm' ),
esc_html__( 'If enabled and an existing person is found, their contact details will either be replaced or appended. Job title and organization will be replaced whether replace or append is chosen.', 'gravityformscapsulecrm' )
),
'checkbox' => array(
'name' => 'update_person_enable',
'label' => esc_html__( 'Update Person if already exists', 'gravityformscapsulecrm' ),
),
'select' => array(
'name' => 'update_person_action',
'choices' => array(
array(
'label' => esc_html__( 'and replace existing data', 'gravityformscapsulecrm' ),
'value' => 'replace',
),
array(
'label' => esc_html__( 'and append new data', 'gravityformscapsulecrm' ),
'value' => 'append',
),
),
),
),
array(
'name' => 'assign_to',
'label' => esc_html__( 'Assign To', 'gravityformscapsulecrm' ),
'type' => 'checkbox',
'onclick' => "jQuery(this).parents('form').submit();",
'choices' => array(
array(
'name' => 'create_case',
'label' => esc_html__( 'Assign Person to a New Case', 'gravityformscapsulecrm' ),
),
array(
'name' => 'create_opportunity',
'label' => esc_html__( 'Assign Person to a New Opportunity', 'gravityformscapsulecrm' ),
),
),
),
),
),
array(
'title' => esc_html__( 'Case Details', 'gravityformscapsulecrm' ),
'dependency' => array( 'field' => 'create_case', 'values' => array( '1' ) ),
'fields' => array(
array(
'name' => 'case_name',
'type' => 'text',
'required' => true,
'class' => 'medium merge-tag-support mt-position-right mt-hide_all_fields',
'label' => esc_html__( 'Name', 'gravityformscapsulecrm' ),
),
array(
'name' => 'case_description',
'type' => 'text',
'class' => 'medium merge-tag-support mt-position-right mt-hide_all_fields',
'label' => esc_html__( 'Description', 'gravityformscapsulecrm' ),
),
array(
'name' => 'case_status',
'type' => 'select',
'label' => esc_html__( 'Status', 'gravityformscapsulecrm' ),
'choices' => array(
array(
'label' => esc_html__( 'Open', 'gravityformscapsulecrm' ),
'value' => 'OPEN',
),
array(
'label' => esc_html__( 'Closed', 'gravityformscapsulecrm' ),
'value' => 'CLOSED',
),
),
),
array(
'name' => 'case_owner',
'type' => 'select',
'label' => esc_html__( 'Owner', 'gravityformscapsulecrm' ),
'choices' => $this->get_users_as_choices(),
),
),
),
array(
'title' => esc_html__( 'Opportunity Details', 'gravityformscapsulecrm' ),
'dependency' => array( 'field' => 'create_opportunity', 'values' => array( '1' ) ),
'fields' => array(
array(
'name' => 'opportunity_name',
'type' => 'text',
'required' => true,
'class' => 'medium merge-tag-support mt-position-right mt-hide_all_fields',
'label' => esc_html__( 'Name', 'gravityformscapsulecrm' ),
),
array(
'name' => 'opportunity_description',
'type' => 'text',
'class' => 'medium merge-tag-support mt-position-right mt-hide_all_fields',
'label' => esc_html__( 'Description', 'gravityformscapsulecrm' ),
),
array(
'name' => 'opportunity_milestone',
'type' => 'select',
'required' => true,
'label' => esc_html__( 'Milestone', 'gravityformscapsulecrm' ),
'choices' => $this->get_milestones_as_choices(),
),
array(
'name' => 'opportunity_owner',
'type' => 'select',
'label' => esc_html__( 'Owner', 'gravityformscapsulecrm' ),
'choices' => $this->get_users_as_choices(),
),
),
),
array(
'title' => esc_html__( 'Task Details', 'gravityformscapsulecrm' ),
'dependency' => array( 'field' => 'create_task', 'values' => ( '1' ) ),
'fields' => array(
array(
'name' => 'task_description',
'type' => 'text',
'required' => true,
'class' => 'medium merge-tag-support mt-position-right mt-hide_all_fields',
'label' => esc_html__( 'Description', 'gravityformscapsulecrm' ),
),
array(
'name' => 'task_detail',
'type' => 'text',
'class' => 'medium merge-tag-support mt-position-right mt-hide_all_fields',
'label' => esc_html__( 'Detail', 'gravityformscapsulecrm' ),
),
array(
'name' => 'task_days_until_due',
'type' => 'text',
'required' => true,
'class' => 'small',
'label' => esc_html__( 'Days Until Due', 'gravityformscapsulecrm' ),
'validation_callback' => array( $this, 'validate_task_days_until_due' ),
),
array(
'name' => 'task_status',
'type' => 'select',
'label' => esc_html__( 'Status', 'gravityformscapsulecrm' ),
'choices' => array(
array(
'label' => esc_html__( 'Open', 'gravityformscapsulecrm' ),
'value' => 'OPEN',
),
array(
'label' => esc_html__( 'Completed', 'gravityformscapsulecrm' ),
'value' => 'COMPLETED',
),
),
),
array(
'name' => 'task_category',
'type' => 'select',
'label' => esc_html__( 'Category', 'gravityformscapsulecrm' ),
'choices' => $this->get_categories_as_choices(),
),
array(
'name' => 'task_owner',
'type' => 'select',
'label' => esc_html__( 'Owner', 'gravityformscapsulecrm' ),
'choices' => $this->get_users_as_choices(),
),
array(
'name' => 'assign_task',
'label' => esc_html__( 'Assign Task', 'gravityformscapsulecrm' ),
'type' => 'select',
'choices' => $this->get_task_assignments_as_choices(),
),
),
),
array(
'title' => esc_html__( 'Feed Conditional Logic', 'gravityformscapsulecrm' ),
'dependency' => array( $this, 'show_conditional_logic_field' ),
'fields' => array(
array(
'name' => 'feed_condition',
'type' => 'feed_condition',
'label' => esc_html__( 'Conditional Logic', 'gravityformscapsulecrm' ),
'checkbox_label' => esc_html__( 'Enable', 'gravityformscapsulecrm' ),
'instructions' => esc_html__( 'Export to Capsule CRM if', 'gravityformscapsulecrm' ),
'tooltip' => sprintf(
'<h6>%s</h6>%s',
esc_html__( 'Conditional Logic', 'gravityformscapsulecrm' ),
esc_html__( 'When conditional logic is enabled, form submissions will only be exported to Capsule CRM when the condition is met. When disabled, all form submissions will be posted.', 'gravityformscapsulecrm' )
),
),
),
),
);
}
/**
* Set custom dependency for conditional logic.
*
* @since 1.0
* @access public
*
* @uses GFAddOn::get_setting()
*
* @return bool
*/
public function show_conditional_logic_field() {
return $this->get_setting( 'create_person' ) || $this->get_setting( 'create_task' );
}
/**
* Check if "Task Days Until Due" setting is numeric.
*
* @since 1.0
* @access public
*
* @param array $field The field being validated.
* @param string $field_setting The setting to validate.
*
* @uses GFAddOn::set_field_error()
*/
public function validate_task_days_until_due( $field, $field_setting ) {
if ( ! is_numeric( $field_setting ) ) {
$this->set_field_error( $field, esc_html__( 'This field must be numeric.', 'gravityforms' ) );
}
}
/**
* Get Capsule CRM users for feed settings field.
*
* @since 1.0
* @access public
*
* @uses GFCapsuleCRM::initialize_api()
* @uses GF_CapsuleCRM_API::get_milestones()
*
* @return array
*/
public function get_users_as_choices() {
// If API is not initialized, return.
if ( ! $this->initialize_api() ) {
return array();
}
$users = $this->api->get_users();
if ( is_wp_error( $users ) ) {
$this->log_error( __METHOD__ . '(): Unable to retrieve Capsule CRM users; ' . $users->get_error_message() );
return array();
}
if ( empty( $users ) || ! is_array( $users ) ) {
return array();
}
$choices = array(
array(
'label' => esc_html__( 'Choose a Capsule CRM User', 'gravityformscapsulecrm' ),
'value' => '',
),
);
// Loop through milestones.
foreach ( $users as $user ) {
// Add milestone as choice.
$choices[] = array(
'label' => esc_html( $user['name'] ),
'value' => esc_html( $user['username'] ),
);
}
return $choices;
}
/**
* Get Capsule CRM opportunity milestones for feed settings field.
*
* @since 1.0
* @access public
*
* @uses GFCapsuleCRM::initialize_api()
* @uses GF_CapsuleCRM_API::get_milestones()
*
* @return array
*/
public function get_milestones_as_choices() {
// If API is not initialized, return.
if ( ! $this->initialize_api() ) {
return array();
}
$milestones = $this->api->get_milestones();
if ( is_wp_error( $milestones ) ) {
$this->log_error( __METHOD__ . '(): Unable to retrieve Capsule CRM milestones; ' . $milestones->get_error_message() );
return array();
}
if ( empty( $milestones ) || ! is_array( $milestones ) ) {
return array();
}
// Initialize choices array.
$choices = array(
array(
'label' => esc_html__( 'Choose a Milestone', 'gravityformscapsulecrm' ),
'value' => '',
),
);
// Loop through milestones.
foreach ( $milestones as $milestone ) {
// Add milestone as choice.
$choices[] = array(
'label' => esc_html( $milestone['name'] ),
'value' => esc_html( $milestone['name'] ),
);
}
return $choices;
}
/**
* Get Capsule CRM task categories for feed settings field.
*
* @since 1.0
* @access public
*
* @uses GFCapsuleCRM::initialize_api()
* @uses GF_CapsuleCRM_API::get_categories()
*
* @return array
*/
public function get_categories_as_choices() {
// If API is not initialized, return.
if ( ! $this->initialize_api() ) {
return array();
}
$categories = $this->api->get_categories();
if ( is_wp_error( $categories ) ) {
$this->log_error( __METHOD__ . '(): Unable to retrieve Capsule CRM categories; ' . $categories->get_error_message() );
return array();
}
if ( empty( $categories ) || ! is_array( $categories ) ) {
return array();
}
// Initialize choices array.
$choices = array(
array(
'label' => esc_html__( 'Choose a Category', 'gravityformscapsulecrm' ),
'value' => '',
),
);
// Loop through categories.
foreach ( $categories as $category ) {
// Add category as choice.
$choices[] = array(
'label' => esc_html( $category['name'] ),
'value' => esc_html( $category['name'] ),
);
}
return $choices;
}
/**
* Get task assignment options for feed settings fields.
*
* @since 1.0
* @access public
*
* @uses GFAddOn::get_setting()
*
* @return array
*/
public function get_task_assignments_as_choices() {
// Initialize choices array.
$choices = array(
array(
'value' => 'none',
'label' => esc_html__( 'Do Not Assign Task', 'gravityformscapsulecrm' ),
),
);
// Add case field as choice.
if ( $this->get_setting( 'create_case' ) ) {
$choices[] = array(
'value' => 'case',
'label' => esc_html__( 'Assign Task to Created Case', 'gravityformscapsulecrm' ),
);
}
// Add person field as choice.
if ( $this->get_setting( 'create_person' ) ) {
$choices[] = array(
'value' => 'person',
'label' => esc_html__( 'Assign Task to Created Person', 'gravityformscapsulecrm' ),
);
}
// Add opportunity field as choice.
if ( $this->get_setting( 'create_opportunity' ) ) {
$choices[] = array(
'value' => 'opportunity',
'label' => esc_html__( 'Assign Task to Created Opportunity', 'gravityformscapsulecrm' ),
);
}
return $choices;
}
/**
* Prepare standard fields for feed field mapping.
*
* @since 1.0
* @access public
*
* @return array
*/
public function standard_fields_for_feed_mapping() {
return array(
array(
'name' => 'first_name',
'label' => esc_html__( 'First Name', 'gravityformscapsulecrm' ),
'required' => true,
'field_type' => array( 'name', 'text', 'hidden' ),
),
array(
'name' => 'last_name',
'label' => esc_html__( 'Last Name', 'gravityformscapsulecrm' ),
'required' => true,
'field_type' => array( 'name', 'text', 'hidden' ),
),
array(
'name' => 'email_address',
'label' => esc_html__( 'Email Address', 'gravityformscapsulecrm' ),
'required' => true,
'field_type' => array( 'email', 'hidden' ),
),
);
}
/**
* Prepare contact and custom fields for feed field mapping.
*
* @since 1.0
* @access public
*
* @return array
*/
public function custom_fields_for_feed_mapping() {
$fields = array(
array(
'value' => 'title',
'label' => esc_html__( 'Job Title', 'gravityformscapsulecrm' ),
),
array(
'value' => 'organization',
'label' => esc_html__( 'Organization', 'gravityformscapsulecrm' ),
),
array(
'label' => esc_html__( 'Email Address', 'gravityformscapsulecrm' ),
'choices' => array(
array(
'label' => esc_html__( 'Work', 'gravityformscapsulecrm' ),
'value' => 'email_work',
),
array(
'label' => esc_html__( 'Home', 'gravityformscapsulecrm' ),
'value' => 'email_home',
),
),
),
array(
'label' => esc_html__( 'Phone Number', 'gravityformscapsulecrm' ),
'choices' => array(
array(
'label' => esc_html__( 'Work', 'gravityformscapsulecrm' ),
'value' => 'phone_work',
),
array(
'label' => esc_html__( 'Mobile', 'gravityformscapsulecrm' ),
'value' => 'phone_mobile',
),
array(
'label' => esc_html__( 'Fax', 'gravityformscapsulecrm' ),
'value' => 'phone_fax',
),
array(
'label' => esc_html__( 'Home', 'gravityformscapsulecrm' ),
'value' => 'phone_home',
),
array(
'label' => esc_html__( 'Direct', 'gravityformscapsulecrm' ),
'value' => 'phone_direct',
),
),
),
array(
'label' => esc_html__( 'Address', 'gravityformscapsulecrm' ),
'choices' => array(
array(
'label' => esc_html__( 'Office', 'gravityformscapsulecrm' ),
'value' => 'address_office',
),
array(
'label' => esc_html__( 'Home', 'gravityformscapsulecrm' ),
'value' => 'address_home',
),
array(
'label' => esc_html__( 'Postal', 'gravityformscapsulecrm' ),
'value' => 'address_postal',
),
),
),
array(
'label' => esc_html__( 'Website', 'gravityformscapsulecrm' ),
'choices' => array(
array(
'label' => esc_html__( 'URL', 'gravityformscapsulecrm' ),
'value' => 'website_url',
),
array(
'label' => esc_html__( 'Skype', 'gravityformscapsulecrm' ),
'value' => 'website_skype',
),
array(
'label' => esc_html__( 'Twitter', 'gravityformscapsulecrm' ),
'value' => 'website_twitter',
),
array(
'label' => esc_html__( 'Facebook', 'gravityformscapsulecrm' ),
'value' => 'website_facebook',
),
array(
'label' => esc_html__( 'LinkedIn', 'gravityformscapsulecrm' ),
'value' => 'website_linked_in',
),
array(
'label' => esc_html__( 'Xing', 'gravityformscapsulecrm' ),
'value' => 'website_xing',
),
array(
'label' => esc_html__( 'Feed', 'gravityformscapsulecrm' ),
'value' => 'website_feed',
),
array(
'label' => esc_html__( 'Google Plus', 'gravityformscapsulecrm' ),
'value' => 'website_google_plus',
),
array(
'label' => esc_html__( 'Flickr', 'gravityformscapsulecrm' ),
'value' => 'website_flickr',
),
array(
'label' => esc_html__( 'GitHub', 'gravityformscapsulecrm' ),
'value' => 'website_github',
),
array(
'label' => esc_html__( 'YouTube', 'gravityformscapsulecrm' ),
'value' => 'website_youtube',
),
),
),
);
if ( ! $this->is_gravityforms_supported( '2.5' ) ) {
$placeholder = array(