PluginProbe
Stream – Activity Log & Audit Trail / 3.10.0
Stream – Activity Log & Audit Trail v3.10.0
4.4.0 4.3.0 4.2.2 4.2.1 trunk 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.1 3.1.1 3.10.0 3.2.0 3.2.1 3.2.2 3.2.3 All 50 releases
stream / connectors / class-connector-gravityforms.php

class-connector-gravityforms.php in Stream – Activity Log & Audit Trail 3.10.0, at connectors/class-connector-gravityforms.php

980 lines 24.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Connector for Gravity Forms
4 *
5 * @package WP_Stream
6 */
7
8 namespace WP_Stream;
9
10 /**
11 * Class - Connector_GravityForms
12 */
13 class Connector_GravityForms extends Connector {
14 /**
15 * Connector slug
16 *
17 * @var string
18 */
19 public $name = 'gravityforms';
20
21 /**
22 * Holds tracked plugin minimum version required
23 *
24 * @const string
25 */
26 const PLUGIN_MIN_VERSION = '1.9.14';
27
28 /**
29 * Actions registered for this connector
30 *
31 * @var array
32 */
33 public $actions = array(
34 'gform_after_save_form',
35 'gform_pre_confirmation_save',
36 'gform_pre_notification_save',
37 'gform_pre_notification_deleted',
38 'gform_pre_confirmation_deleted',
39 'gform_before_delete_form',
40 'gform_post_form_trashed',
41 'gform_post_form_restored',
42 'gform_post_form_activated',
43 'gform_post_form_deactivated',
44 'gform_post_form_duplicated',
45 'gform_post_form_views_deleted',
46 'gform_post_export_entries',
47 'gform_forms_post_import',
48 'gform_delete_lead',
49 'gform_post_note_added',
50 'gform_pre_note_deleted',
51 'gform_update_status',
52 'gform_update_is_read',
53 'gform_update_is_starred',
54 'update_option',
55 'add_option',
56 'delete_option',
57 'update_site_option',
58 'add_site_option',
59 'delete_site_option',
60 );
61
62 /**
63 * Tracked option keys
64 *
65 * @var array
66 */
67 public $options = array();
68
69 /**
70 * Tracking registered Settings, with overridden data
71 *
72 * @var array
73 */
74 public $options_override = array();
75
76 /**
77 * Check if plugin dependencies are satisfied and add an admin notice if not
78 *
79 * @return bool
80 */
81 public function is_dependency_satisfied() {
82 if ( class_exists( 'GFForms' ) && version_compare( \GFCommon::$version, self::PLUGIN_MIN_VERSION, '>=' ) ) {
83 return true;
84 }
85
86 return false;
87 }
88
89 /**
90 * Return translated connector label
91 *
92 * @return string Translated connector label
93 */
94 public function get_label() {
95 return esc_html_x( 'Gravity Forms', 'gravityforms', 'stream' );
96 }
97
98 /**
99 * Return translated action labels
100 *
101 * @return array Action label translations
102 */
103 public function get_action_labels() {
104 return array(
105 'created' => esc_html_x( 'Created', 'gravityforms', 'stream' ),
106 'updated' => esc_html_x( 'Updated', 'gravityforms', 'stream' ),
107 'exported' => esc_html_x( 'Exported', 'gravityforms', 'stream' ),
108 'imported' => esc_html_x( 'Imported', 'gravityforms', 'stream' ),
109 'added' => esc_html_x( 'Added', 'gravityforms', 'stream' ),
110 'deleted' => esc_html_x( 'Deleted', 'gravityforms', 'stream' ),
111 'trashed' => esc_html_x( 'Trashed', 'gravityforms', 'stream' ),
112 'untrashed' => esc_html_x( 'Restored', 'gravityforms', 'stream' ),
113 'duplicated' => esc_html_x( 'Duplicated', 'gravityforms', 'stream' ),
114 'activated' => esc_html_x( 'Activated', 'gravityforms', 'stream' ),
115 'deactivated' => esc_html_x( 'Deactivated', 'gravityforms', 'stream' ),
116 'views_deleted' => esc_html_x( 'Views Reset', 'gravityforms', 'stream' ),
117 'starred' => esc_html_x( 'Starred', 'gravityforms', 'stream' ),
118 'unstarred' => esc_html_x( 'Unstarred', 'gravityforms', 'stream' ),
119 );
120 }
121
122 /**
123 * Return translated context labels
124 *
125 * @return array Context label translations
126 */
127 public function get_context_labels() {
128 return array(
129 'forms' => esc_html_x( 'Forms', 'gravityforms', 'stream' ),
130 'settings' => esc_html_x( 'Settings', 'gravityforms', 'stream' ),
131 'export' => esc_html_x( 'Import/Export', 'gravityforms', 'stream' ),
132 'entries' => esc_html_x( 'Entries', 'gravityforms', 'stream' ),
133 'notes' => esc_html_x( 'Notes', 'gravityforms', 'stream' ),
134 );
135 }
136
137 /**
138 * Add action links to Stream drop row in admin list screen
139 *
140 * @filter wp_stream_action_links_{connector}
141 *
142 * @param array $links Previous links registered.
143 * @param object $record Stream record.
144 *
145 * @return array Action links
146 */
147 public function action_links( $links, $record ) {
148 if ( 'forms' === $record->context ) {
149 $links[ esc_html__( 'Edit', 'stream' ) ] = add_query_arg(
150 array(
151 'page' => 'gf_edit_forms',
152 'id' => $record->object_id,
153 ),
154 admin_url( 'admin.php' )
155 );
156 } elseif ( 'entries' === $record->context ) {
157 $links[ esc_html__( 'View', 'stream' ) ] = add_query_arg(
158 array(
159 'page' => 'gf_entries',
160 'view' => 'entry',
161 'lid' => $record->object_id,
162 'id' => $record->get_meta( 'form_id', true ),
163 ),
164 admin_url( 'admin.php' )
165 );
166 } elseif ( 'notes' === $record->context ) {
167 $links[ esc_html__( 'View', 'stream' ) ] = add_query_arg(
168 array(
169 'page' => 'gf_entries',
170 'view' => 'entry',
171 'lid' => $record->get_meta( 'lead_id', true ),
172 'id' => $record->get_meta( 'form_id', true ),
173 ),
174 admin_url( 'admin.php' )
175 );
176 } elseif ( 'settings' === $record->context ) {
177 $links[ esc_html__( 'Edit Settings', 'stream' ) ] = add_query_arg(
178 array(
179 'page' => 'gf_settings',
180 ),
181 admin_url( 'admin.php' )
182 );
183 }
184
185 return $links;
186 }
187
188 /**
189 * Register all context hooks
190 */
191 public function register() {
192 parent::register();
193
194 $this->options = array(
195 'rg_gforms_disable_css' => array(
196 'label' => esc_html_x( 'Output CSS', 'gravityforms', 'stream' ),
197 ),
198 'rg_gforms_enable_html5' => array(
199 'label' => esc_html_x( 'Output HTML5', 'gravityforms', 'stream' ),
200 ),
201 'gform_enable_noconflict' => array(
202 'label' => esc_html_x( 'No-Conflict Mode', 'gravityforms', 'stream' ),
203 ),
204 'rg_gforms_currency' => array(
205 'label' => esc_html_x( 'Currency', 'gravityforms', 'stream' ),
206 ),
207 'rg_gforms_captcha_public_key' => array(
208 'label' => esc_html_x( 'reCAPTCHA Public Key', 'gravityforms', 'stream' ),
209 ),
210 'rg_gforms_captcha_private_key' => array(
211 'label' => esc_html_x( 'reCAPTCHA Private Key', 'gravityforms', 'stream' ),
212 ),
213 'rg_gforms_key' => null,
214 );
215 }
216
217 /**
218 * Track Create/Update actions on Forms
219 *
220 * @param array $form Form data.
221 * @param bool $is_new Is this a new form?.
222 */
223 public function callback_gform_after_save_form( $form, $is_new ) {
224 $title = $form['title'];
225 $id = $form['id'];
226
227 $this->log(
228 sprintf(
229 /* translators: %1$s a form title, %2$s a status (e.g. "Contact Form", "created") */
230 __( '"%1$s" form %2$s', 'stream' ),
231 $title,
232 $is_new ? esc_html__( 'created', 'stream' ) : esc_html__( 'updated', 'stream' )
233 ),
234 array(
235 'action' => $is_new,
236 'id' => $id,
237 'title' => $title,
238 ),
239 $id,
240 'forms',
241 $is_new ? 'created' : 'updated'
242 );
243 }
244
245 /**
246 * Track saving form confirmations
247 *
248 * @param array $confirmation Confirmation data.
249 * @param array $form Form data.
250 * @param bool $is_new Is this a new form?.
251 */
252 public function callback_gform_pre_confirmation_save( $confirmation, $form, $is_new = true ) {
253 if ( ! isset( $is_new ) ) {
254 $is_new = false;
255 }
256
257 $this->log(
258 sprintf(
259 /* translators: %1$s: a confirmation name, %2$s: a status, %3$s: a form title (e.g. "Email", "created", "Contact Form") */
260 __( '"%1$s" confirmation %2$s for "%3$s"', 'stream' ),
261 $confirmation['name'],
262 $is_new ? esc_html__( 'created', 'stream' ) : esc_html__( 'updated', 'stream' ),
263 $form['title']
264 ),
265 array(
266 'is_new' => $is_new,
267 'form_id' => $form['id'],
268 ),
269 $form['id'],
270 'forms',
271 'updated'
272 );
273
274 return $confirmation;
275 }
276
277 /**
278 * Track saving form notifications
279 *
280 * @param array $notification Notification data.
281 * @param array $form Form data.
282 * @param bool $is_new Is this a new form?.
283 * @return array
284 */
285 public function callback_gform_pre_notification_save( $notification, $form, $is_new = true ) {
286 if ( ! isset( $is_new ) ) {
287 $is_new = false;
288 }
289
290 $this->log(
291 sprintf(
292 /* translators: %1$s: a notification name, %2$s: a status, %3$s: a form title (e.g. "Email", "created", "Contact Form") */
293 __( '"%1$s" notification %2$s for "%3$s"', 'stream' ),
294 $notification['name'],
295 $is_new ? esc_html__( 'created', 'stream' ) : esc_html__( 'updated', 'stream' ),
296 $form['title']
297 ),
298 array(
299 'is_update' => $is_new,
300 'form_id' => $form['id'],
301 ),
302 $form['id'],
303 'forms',
304 'updated'
305 );
306
307 return $notification;
308 }
309
310 /**
311 * Track deletion of notifications
312 *
313 * @param array $notification Notification data.
314 * @param array $form Form data.
315 */
316 public function callback_gform_pre_notification_deleted( $notification, $form ) {
317 $this->log(
318 sprintf(
319 /* translators: %1$s: a notification name, %2$s: a form title (e.g. "Email", "Contact Form") */
320 __( '"%1$s" notification deleted from "%2$s"', 'stream' ),
321 $notification['name'],
322 $form['title']
323 ),
324 array(
325 'form_id' => $form['id'],
326 'notification' => $notification,
327 ),
328 $form['id'],
329 'forms',
330 'updated'
331 );
332 }
333
334 /**
335 * Track deletion of confirmations
336 *
337 * @param array $confirmation Confirmation data.
338 * @param array $form Form data.
339 */
340 public function callback_gform_pre_confirmation_deleted( $confirmation, $form ) {
341 $this->log(
342 sprintf(
343 /* translators: %1$s: a confirmation name, %2$s: a form title (e.g. "Email", "Contact Form") */
344 __( '"%1$s" confirmation deleted from "%2$s"', 'stream' ),
345 $confirmation['name'],
346 $form['title']
347 ),
348 array(
349 'form_id' => $form['id'],
350 'confirmation' => $confirmation,
351 ),
352 $form['id'],
353 'forms',
354 'updated'
355 );
356 }
357
358 /**
359 * Track status change of confirmations
360 *
361 * @param array $confirmation Confirmation data.
362 * @param array $form Form data.
363 * @param bool $is_active Is this form active?.
364 */
365 public function callback_gform_confirmation_status( $confirmation, $form, $is_active ) {
366 $this->log(
367 sprintf(
368 /* translators: %1$s: a confirmation name, %2$s: a status, %3$s: a form title (e.g. "Email", "activated", "Contact Form") */
369 __( '"%1$s" confirmation %2$s from "%3$s"', 'stream' ),
370 $confirmation['name'],
371 $is_active ? esc_html__( 'activated', 'stream' ) : esc_html__( 'deactivated', 'stream' ),
372 $form['title']
373 ),
374 array(
375 'form_id' => $form['id'],
376 'confirmation' => $confirmation,
377 'is_active' => $is_active,
378 ),
379 null,
380 'forms',
381 'updated'
382 );
383 }
384
385 /**
386 * Track status change of notifications
387 *
388 * @param array $notification Notification data.
389 * @param array $form Form data.
390 * @param bool $is_active Is this form active?.
391 */
392 public function callback_gform_notification_status( $notification, $form, $is_active ) {
393 $this->log(
394 sprintf(
395 /* translators: %1$s: a notification name, %2$s: a status, %3$s: a form title (e.g. "Email", "activated", "Contact Form") */
396 __( '"%1$s" notification %2$s from "%3$s"', 'stream' ),
397 $notification['name'],
398 $is_active ? esc_html__( 'activated', 'stream' ) : esc_html__( 'deactivated', 'stream' ),
399 $form['title']
400 ),
401 array(
402 'form_id' => $form['id'],
403 'notification' => $notification,
404 'is_active' => $is_active,
405 ),
406 $form['id'],
407 'forms',
408 'updated'
409 );
410 }
411
412 /**
413 * Track GravityForms-specific option changes.
414 *
415 * @param string $option Option key.
416 * @param string $old Old value.
417 * @param string $new New value.
418 */
419 public function callback_update_option( $option, $old, $new ) {
420 $this->check( $option, $old, $new );
421 }
422
423 /**
424 * Track GravityForms-specific option creations.
425 *
426 * @param string $option Option key.
427 * @param string $val Value.
428 */
429 public function callback_add_option( $option, $val ) {
430 $this->check( $option, null, $val );
431 }
432
433 /**
434 * Track GravityForms-specific option deletions.
435 *
436 * @param string $option Option key.
437 */
438 public function callback_delete_option( $option ) {
439 $this->check( $option, null, null );
440 }
441
442 /**
443 * Track GravityForms-specific site option changes
444 *
445 * @param string $option Option key.
446 * @param string $old Old value.
447 * @param string $new New value.
448 */
449 public function callback_update_site_option( $option, $old, $new ) {
450 $this->check( $option, $old, $new );
451 }
452
453 /**
454 * Track GravityForms-specific site option creations.
455 *
456 * @param string $option Option key.
457 * @param string $val Value.
458 */
459 public function callback_add_site_option( $option, $val ) {
460 $this->check( $option, null, $val );
461 }
462
463 /**
464 * Track GravityForms-specific site option deletions.
465 *
466 * @param string $option Option key.
467 */
468 public function callback_delete_site_option( $option ) {
469 $this->check( $option, null, null );
470 }
471
472 /**
473 * Logs GravityForms-specific (site) option activity.
474 *
475 * @param string $option Option key.
476 * @param string $old_value Old value.
477 * @param string $new_value New value.
478 */
479 public function check( $option, $old_value, $new_value ) {
480 if ( ! array_key_exists( $option, $this->options ) ) {
481 return;
482 }
483
484 if ( is_null( $this->options[ $option ] ) ) {
485 call_user_func( array( $this, 'check_' . str_replace( '-', '_', $option ) ), $old_value, $new_value );
486 } else {
487 $data = $this->options[ $option ];
488 $option_title = $data['label'];
489 $context = isset( $data['context'] ) ? $data['context'] : 'settings';
490
491 $this->log(
492 /* translators: %s: a setting title (e.g. "Language") */
493 __( '"%s" setting updated', 'stream' ),
494 compact( 'option_title', 'option', 'old_value', 'new_value' ),
495 null,
496 $context,
497 isset( $data['action'] ) ? $data['action'] : 'updated'
498 );
499 }
500 }
501
502 /**
503 * Log GravityForm license key changes
504 *
505 * @param string $old_value Old license key.
506 * @param string $new_value New license key.
507 * @return void
508 */
509 public function check_rg_gforms_key( $old_value, $new_value ) {
510 $is_update = ( $new_value && strlen( $new_value ) );
511 $option = 'rg_gforms_key';
512
513 $this->log(
514 sprintf(
515 /* translators: %s: a status (e.g. "updated") */
516 __( 'Gravity Forms license key %s', 'stream' ),
517 $is_update ? esc_html__( 'updated', 'stream' ) : esc_html__( 'deleted', 'stream' )
518 ),
519 compact( 'option', 'old_value', 'new_value' ),
520 null,
521 'settings',
522 $is_update ? 'updated' : 'deleted'
523 );
524 }
525
526 /**
527 * Logs form entry exports.
528 *
529 * @action gform_post_export_entries
530 *
531 * @param object $form Form data.
532 * @param string $start_date Form start date.
533 * @param string $end_date Form completion date.
534 * @param array $fields Form fields data.
535 */
536 public function callback_gform_post_export_entries( $form, $start_date, $end_date, $fields ) {
537 unset( $fields );
538 $this->log(
539 /* translators: %s: a form title (e.g. "Contact Form") */
540 __( '"%s" form entries exported', 'stream' ),
541 array(
542 'form_title' => $form['title'],
543 'form_id' => $form['id'],
544 'start_date' => empty( $start_date ) ? null : $start_date,
545 'end_date' => empty( $end_date ) ? null : $end_date,
546 ),
547 $form['id'],
548 'export',
549 'exported'
550 );
551 }
552
553 /**
554 * Logs form imports.
555 *
556 * @action gform_forms_post_import
557 *
558 * @param array $forms List of form data.
559 */
560 public function callback_gform_forms_post_import( $forms ) {
561 $forms_total = count( $forms );
562 $forms_ids = wp_list_pluck( $forms, 'id' );
563 $forms_titles = wp_list_pluck( $forms, 'title' );
564
565 $this->log(
566 /* translators: %d: a number of forms (e.g. "42") */
567 _n( '%d form imported', '%d forms imported', $forms_total, 'stream' ),
568 array(
569 'count' => $forms_total,
570 'ids' => $forms_ids,
571 'titles' => $forms_titles,
572 ),
573 null,
574 'export',
575 'imported'
576 );
577 }
578
579 /**
580 * Logs form exports
581 *
582 * @action gform_export_separator
583 *
584 * @param string $dummy Unused.
585 * @param int $form_id Form ID.
586 */
587 public function callback_gform_export_separator( $dummy, $form_id ) {
588 $form = $this->get_form( $form_id );
589
590 $this->log(
591 /* translators: %s: a form title (e.g. "Contact Form") */
592 __( '"%s" form exported', 'stream' ),
593 array(
594 'form_title' => $form['title'],
595 'form_id' => $form_id,
596 ),
597 $form_id,
598 'export',
599 'exported'
600 );
601
602 return $dummy;
603 }
604
605 /**
606 * Log bulk form exports
607 *
608 * @param string $dummy Unused.
609 * @param array $forms Form data.
610 */
611 public function callback_gform_export_options( $dummy, $forms ) {
612 $ids = wp_list_pluck( $forms, 'id' );
613 $titles = wp_list_pluck( $forms, 'title' );
614
615 $this->log(
616 /* translators: %d: a number of forms (e.g. "42") */
617 _n( 'Export process started for %d form', 'Export process started for %d forms', count( $forms ), 'stream' ),
618 array(
619 'count' => count( $forms ),
620 'ids' => $ids,
621 'titles' => $titles,
622 ),
623 null,
624 'export',
625 'imported'
626 );
627
628 return $dummy;
629 }
630
631 /**
632 * Logs lead deletions.
633 *
634 * @action gform_delete_lead
635 *
636 * @param int $lead_id Lead ID.
637 * @return void
638 */
639 public function callback_gform_delete_lead( $lead_id ) {
640 $lead = $this->get_lead( $lead_id );
641 $form = $this->get_form( $lead['form_id'] );
642
643 $this->log(
644 /* translators: %1$d: to an ID, %2$s: a form title (e.g. "42", "Contact Form") */
645 __( 'Lead #%1$d from "%2$s" deleted', 'stream' ),
646 array(
647 'lead_id' => $lead_id,
648 'form_title' => $form['title'],
649 'form_id' => $form['id'],
650 ),
651 $lead_id,
652 'entries',
653 'deleted'
654 );
655 }
656
657 /**
658 * Logs note creation on lead.
659 *
660 * @action gform_post_note_added
661 *
662 * @param int $note_id Note ID.
663 * @param int $lead_id Lead ID.
664 * @param int $user_id User ID of note author.
665 * @param string $user_name Username of note author.
666 * @param string $note Note object.
667 * @param string $note_type Note type.
668 */
669 public function callback_gform_post_note_added( $note_id, $lead_id, $user_id, $user_name, $note, $note_type ) {
670 unset( $user_id );
671 unset( $user_name );
672 unset( $note );
673 unset( $note_type );
674
675 // Skip if no entry/lead id (e.g. Save and Continue notifications)
676 if ( empty( $lead_id ) ) {
677 return;
678 }
679
680 $lead = \GFFormsModel::get_lead( $lead_id );
681 $form = $this->get_form( $lead['form_id'] );
682
683 $this->log(
684 /* translators: %1$d: an ID, %2$d: another ID, %3$s: a form title (e.g. "42", "7", "Contact Form") */
685 __( 'Note #%1$d added to lead #%2$d on "%3$s" form', 'stream' ),
686 array(
687 'note_id' => $note_id,
688 'lead_id' => $lead_id,
689 'form_title' => $form['title'],
690 'form_id' => $form['id'],
691 ),
692 $note_id,
693 'notes',
694 'added'
695 );
696 }
697
698 /**
699 * Logs note deletion
700 *
701 * @action gform_pre_note_deleted
702 *
703 * @param int $note_id Note ID.
704 * @param int $lead_id Lead ID.
705 */
706 public function callback_gform_pre_note_deleted( $note_id, $lead_id ) {
707 $lead = $this->get_lead( $lead_id );
708 $form = $this->get_form( $lead['form_id'] );
709
710 $this->log(
711 /* translators: %2$d an ID, another ID, and a form title (e.g. "42", "7", "Contact Form") */
712 __( 'Note #%1$d deleted from lead #%2$d on "%3$s" form', 'stream' ),
713 array(
714 'note_id' => $note_id,
715 'lead_id' => $lead_id,
716 'form_title' => $form['title'],
717 'form_id' => $form['id'],
718 ),
719 $note_id,
720 'notes',
721 'deleted'
722 );
723 }
724
725 /**
726 * Logs form status updates.
727 *
728 * @action gform_update_status
729 *
730 * @param int $lead_id Lead ID.
731 * @param string $status New form status.
732 * @param string $prev Old form status.
733 */
734 public function callback_gform_update_status( $lead_id, $status, $prev = '' ) {
735 $lead = $this->get_lead( $lead_id );
736 $form = $this->get_form( $lead['form_id'] );
737
738 if ( 'active' === $status && 'trash' === $prev ) {
739 $status = 'restore';
740 }
741
742 $actions = array(
743 'active' => esc_html__( 'activated', 'stream' ),
744 'spam' => esc_html__( 'marked as spam', 'stream' ),
745 'trash' => esc_html__( 'trashed', 'stream' ),
746 'restore' => esc_html__( 'restored', 'stream' ),
747 );
748
749 if ( ! isset( $actions[ $status ] ) ) {
750 return;
751 }
752
753 $this->log(
754 sprintf(
755 /* translators: %1$d: an ID, %2$s: a status, %3$s: a form title (e.g. "42", "activated", "Contact Form") */
756 __( 'Lead #%1$d %2$s on "%3$s" form', 'stream' ),
757 $lead_id,
758 $actions[ $status ],
759 $form['title']
760 ),
761 array(
762 'lead_id' => $lead_id,
763 'form_title' => $form['title'],
764 'form_id' => $form['id'],
765 'status' => $status,
766 'prev' => $prev,
767 ),
768 $lead_id,
769 'entries',
770 $status
771 );
772 }
773
774 /**
775 * Callback fired when an entry is read/unread
776 *
777 * @action update_is_read
778 *
779 * @param int $lead_id Lead ID.
780 * @param string $status Status.
781 */
782 public function callback_gform_update_is_read( $lead_id, $status ) {
783 $lead = $this->get_lead( $lead_id );
784 $form = $this->get_form( $lead['form_id'] );
785 $status = ( ! empty( $status ) ) ? esc_html__( 'read', 'stream' ) : esc_html__( 'unread', 'stream' );
786
787 $this->log(
788 sprintf(
789 /* translators: %1$d: a lead ID, %2$s: a status, %3$s: a form ID, %4$s: a form title (e.g. "42", "unread", "Contact Form") */
790 __( 'Entry #%1$d marked as %2$s on form #%3$d ("%4$s")', 'stream' ),
791 $lead_id,
792 $status,
793 $form['id'],
794 $form['title']
795 ),
796 array(
797 'lead_id' => $lead_id,
798 'lead_status' => $status,
799 'form_id' => $form['id'],
800 'form_title' => $form['title'],
801 ),
802 $lead_id,
803 'entries',
804 'updated'
805 );
806 }
807
808 /**
809 * Callback fired when an entry is starred/unstarred
810 *
811 * @action gform_update_is_starred
812 *
813 * @param int $lead_id Lead ID.
814 * @param int $status Status.
815 */
816 public function callback_gform_update_is_starred( $lead_id, $status ) {
817 $lead = $this->get_lead( $lead_id );
818 $form = $this->get_form( $lead['form_id'] );
819 $status = ( ! empty( $status ) ) ? esc_html__( 'starred', 'stream' ) : esc_html__( 'unstarred', 'stream' );
820 $action = $status;
821
822 $this->log(
823 sprintf(
824 /* translators: %1$d: an ID, %2$s: a status, %3$d: a form title (e.g. "42", "starred", "Contact Form") */
825 __( 'Entry #%1$d %2$s on form #%3$d ("%4$s")', 'stream' ),
826 $lead_id,
827 $status,
828 $form['id'],
829 $form['title']
830 ),
831 array(
832 'lead_id' => $lead_id,
833 'lead_status' => $status,
834 'form_id' => $form['id'],
835 'form_title' => $form['title'],
836 ),
837 $lead_id,
838 'entries',
839 $action
840 );
841 }
842
843 /**
844 * Callback fired when a form is deleted
845 *
846 * @action gform_before_delete_form
847 *
848 * @param int $form_id Form ID.
849 */
850 public function callback_gform_before_delete_form( $form_id ) {
851 $this->log_form_action( $form_id, 'deleted' );
852 }
853
854 /**
855 * Callback fired when a form is trashed
856 *
857 * @action gform_post_form_trashed
858 *
859 * @param int $form_id Form ID.
860 */
861 public function callback_gform_post_form_trashed( $form_id ) {
862 $this->log_form_action( $form_id, 'trashed' );
863 }
864
865 /**
866 * Callback fired when a form is restored
867 *
868 * @action gform_post_form_restored
869 *
870 * @param int $form_id Form ID.
871 */
872 public function callback_gform_post_form_restored( $form_id ) {
873 $this->log_form_action( $form_id, 'untrashed' );
874 }
875
876 /**
877 * Callback fired when a form is activated
878 *
879 * @action gform_post_form_activated
880 *
881 * @param int $form_id Form ID.
882 */
883 public function callback_gform_post_form_activated( $form_id ) {
884 $this->log_form_action( $form_id, 'activated' );
885 }
886
887 /**
888 * Callback fired when a form is deactivated
889 *
890 * @action gform_post_form_deactivated
891 *
892 * @param int $form_id Form ID.
893 */
894 public function callback_gform_post_form_deactivated( $form_id ) {
895 $this->log_form_action( $form_id, 'deactivated' );
896 }
897
898 /**
899 * Callback fired when a form is duplicated
900 *
901 * @action gform_post_form_duplicated
902 *
903 * @param int $form_id Form ID.
904 */
905 public function callback_gform_post_form_duplicated( $form_id ) {
906 $this->log_form_action( $form_id, 'duplicated' );
907 }
908
909 /**
910 * Callback fired when a form's views are reset
911 *
912 * @action gform_post_form_views_deleted
913 *
914 * @param int $form_id Form ID.
915 */
916 public function callback_gform_post_form_views_deleted( $form_id ) {
917 $this->log_form_action( $form_id, 'views_deleted' );
918 }
919
920 /**
921 * Track status change of forms
922 *
923 * @param int $form_id Form ID.
924 * @param string $action Action.
925 */
926 public function log_form_action( $form_id, $action ) {
927 $form = $this->get_form( $form_id );
928
929 if ( empty( $form ) ) {
930 return;
931 }
932
933 $actions = array(
934 'activated' => esc_html__( 'Activated', 'stream' ),
935 'deactivated' => esc_html__( 'Deactivated', 'stream' ),
936 'trashed' => esc_html__( 'Trashed', 'stream' ),
937 'untrashed' => esc_html__( 'Restored', 'stream' ),
938 'duplicated' => esc_html__( 'Duplicated', 'stream' ),
939 'deleted' => esc_html__( 'Deleted', 'stream' ),
940 'views_deleted' => esc_html__( 'Views Reset', 'stream' ),
941 );
942
943 $this->log(
944 sprintf(
945 /* translators: %1$d: an ID, %2$s: a form title, %3$s: a status (e.g. "42", "Contact Form", "Activated") */
946 __( 'Form #%1$d ("%2$s") %3$s', 'stream' ),
947 $form_id,
948 $form['title'],
949 strtolower( $actions[ $action ] )
950 ),
951 array(
952 'form_id' => $form_id,
953 'form_title' => $form['title'],
954 'form_status' => strtolower( $action ),
955 ),
956 $form['id'],
957 'forms',
958 $action
959 );
960 }
961
962 /**
963 * Helper function to get a single entry
964 *
965 * @param int $lead_id Lead ID.
966 */
967 private function get_lead( $lead_id ) {
968 return \GFFormsModel::get_lead( $lead_id );
969 }
970
971 /**
972 * Helper function to get a single form
973 *
974 * @param int $form_id Form ID.
975 */
976 private function get_form( $form_id ) {
977 return \GFFormsModel::get_form_meta( $form_id );
978 }
979 }
980