-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclass-activation.php
More file actions
56 lines (48 loc) · 1.8 KB
/
class-activation.php
File metadata and controls
56 lines (48 loc) · 1.8 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
<?php
/**
* When plugin is activated, loop through all forms and add a new field
* Field is set to administrative-view only (will not render on frontend)
* This field will hold the "Fishbowl Integration Status" for individual entries.
*
* This is not mission-critical for the integration, but adds a helpful layer of visibility to any entries that may not have posted.
*
* This field will persist if the plugin is deactivated. Ideally it would be removed when the plugin is deactivated, but skipping that in the interest of time.
*/
namespace GF_Fishbowl;
class Activation {
public static function activate() {
// $this->add_crm_status_fields();
// $this->set_cron_jobs();
}
public function add_crm_status_fields(){
$forms = \GFAPI::get_forms();
// On form activation, add a custom "Fishbowl Status" field to all forms.
foreach ( $forms as $form ) {
// Check if current form already has a "fishbowl status" field. If so we can skip to the next form.
$has_field = false;
foreach ( $form['fields'] as $field ) {
if ( strtolower( $field->label ) === 'fishbowl status' ) {
// error_log("Field already exists");
$has_field = true;
break;
}
}
if ( ! $has_field ) {
$new_field_id = \GFFormsModel::get_next_field_id( $form['fields'] );
$properties['id'] = $new_field_id;
$properties['type'] = 'text';
$properties['label'] = 'Fishbowl Status';
$properties['adminOnly'] = true;
$field = \GF_Fields::create( $properties );
$form['fields'][] = $field;
\GFAPI::update_form( $form );
}
}
}
public static function set_cron_jobs(){
// Add hourly cron job to re-send failed API submissions to Fishbowl
if ( ! wp_next_scheduled('twb_fishbowl_retry_api')) {
wp_schedule_event(time(), 'hourly', 'twb_fishbowl_retry_api');
}
}
}