PluginProbe
Stream – Activity Log & Audit Trail / 3.8.2
Stream – Activity Log & Audit Trail v3.8.2
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.8.2, at connectors/class-connector-gravityforms.php

975 lines 24.8 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 $lead = \GFFormsModel::get_lead( $lead_id );
676 $form = $this->get_form( $lead['form_id'] );
677
678 $this->log(
679 /* translators: %1$d: an ID, %2$d: another ID, %3$s: a form title (e.g. "42", "7", "Contact Form") */
680 __( 'Note #%1$d added to lead #%2$d on "%3$s" form', 'stream' ),
681 array(
682 'note_id' => $note_id,
683 'lead_id' => $lead_id,
684 'form_title' => $form['title'],
685 'form_id' => $form['id'],
686 ),
687 $note_id,
688 'notes',
689 'added'
690 );
691 }
692
693 /**
694 * Logs note deletion
695 *
696 * @action gform_pre_note_deleted
697 *
698 * @param int $note_id Note ID.
699 * @param int $lead_id Lead ID.
700 */
701 public function callback_gform_pre_note_deleted( $note_id, $lead_id ) {
702 $lead = $this->get_lead( $lead_id );
703 $form = $this->get_form( $lead['form_id'] );
704
705 $this->log(
706 /* translators: %2$d an ID, another ID, and a form title (e.g. "42", "7", "Contact Form") */
707 __( 'Note #%1$d deleted from lead #%2$d on "%3$s" form', 'stream' ),
708 array(
709 'note_id' => $note_id,
710 'lead_id' => $lead_id,
711 'form_title' => $form['title'],
712 'form_id' => $form['id'],
713 ),
714 $note_id,
715 'notes',
716 'deleted'
717 );
718 }
719
720 /**
721 * Logs form status updates.
722 *
723 * @action gform_update_status
724 *
725 * @param int $lead_id Lead ID.
726 * @param string $status New form status.
727 * @param string $prev Old form status.
728 */
729 public function callback_gform_update_status( $lead_id, $status, $prev = '' ) {
730 $lead = $this->get_lead( $lead_id );
731 $form = $this->get_form( $lead['form_id'] );
732
733 if ( 'active' === $status && 'trash' === $prev ) {
734 $status = 'restore';
735 }
736
737 $actions = array(
738 'active' => esc_html__( 'activated', 'stream' ),
739 'spam' => esc_html__( 'marked as spam', 'stream' ),
740 'trash' => esc_html__( 'trashed', 'stream' ),
741 'restore' => esc_html__( 'restored', 'stream' ),
742 );
743
744 if ( ! isset( $actions[ $status ] ) ) {
745 return;
746 }
747
748 $this->log(
749 sprintf(
750 /* translators: %1$d: an ID, %2$s: a status, %3$s: a form title (e.g. "42", "activated", "Contact Form") */
751 __( 'Lead #%1$d %2$s on "%3$s" form', 'stream' ),
752 $lead_id,
753 $actions[ $status ],
754 $form['title']
755 ),
756 array(
757 'lead_id' => $lead_id,
758 'form_title' => $form['title'],
759 'form_id' => $form['id'],
760 'status' => $status,
761 'prev' => $prev,
762 ),
763 $lead_id,
764 'entries',
765 $status
766 );
767 }
768
769 /**
770 * Callback fired when an entry is read/unread
771 *
772 * @action update_is_read
773 *
774 * @param int $lead_id Lead ID.
775 * @param string $status Status.
776 */
777 public function callback_gform_update_is_read( $lead_id, $status ) {
778 $lead = $this->get_lead( $lead_id );
779 $form = $this->get_form( $lead['form_id'] );
780 $status = ( ! empty( $status ) ) ? esc_html__( 'read', 'stream' ) : esc_html__( 'unread', 'stream' );
781
782 $this->log(
783 sprintf(
784 /* 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") */
785 __( 'Entry #%1$d marked as %2$s on form #%3$d ("%4$s")', 'stream' ),
786 $lead_id,
787 $status,
788 $form['id'],
789 $form['title']
790 ),
791 array(
792 'lead_id' => $lead_id,
793 'lead_status' => $status,
794 'form_id' => $form['id'],
795 'form_title' => $form['title'],
796 ),
797 $lead_id,
798 'entries',
799 'updated'
800 );
801 }
802
803 /**
804 * Callback fired when an entry is starred/unstarred
805 *
806 * @action gform_update_is_starred
807 *
808 * @param int $lead_id Lead ID.
809 * @param int $status Status.
810 */
811 public function callback_gform_update_is_starred( $lead_id, $status ) {
812 $lead = $this->get_lead( $lead_id );
813 $form = $this->get_form( $lead['form_id'] );
814 $status = ( ! empty( $status ) ) ? esc_html__( 'starred', 'stream' ) : esc_html__( 'unstarred', 'stream' );
815 $action = $status;
816
817 $this->log(
818 sprintf(
819 /* translators: %1$d: an ID, %2$s: a status, %3$d: a form title (e.g. "42", "starred", "Contact Form") */
820 __( 'Entry #%1$d %2$s on form #%3$d ("%4$s")', 'stream' ),
821 $lead_id,
822 $status,
823 $form['id'],
824 $form['title']
825 ),
826 array(
827 'lead_id' => $lead_id,
828 'lead_status' => $status,
829 'form_id' => $form['id'],
830 'form_title' => $form['title'],
831 ),
832 $lead_id,
833 'entries',
834 $action
835 );
836 }
837
838 /**
839 * Callback fired when a form is deleted
840 *
841 * @action gform_before_delete_form
842 *
843 * @param int $form_id Form ID.
844 */
845 public function callback_gform_before_delete_form( $form_id ) {
846 $this->log_form_action( $form_id, 'deleted' );
847 }
848
849 /**
850 * Callback fired when a form is trashed
851 *
852 * @action gform_post_form_trashed
853 *
854 * @param int $form_id Form ID.
855 */
856 public function callback_gform_post_form_trashed( $form_id ) {
857 $this->log_form_action( $form_id, 'trashed' );
858 }
859
860 /**
861 * Callback fired when a form is restored
862 *
863 * @action gform_post_form_restored
864 *
865 * @param int $form_id Form ID.
866 */
867 public function callback_gform_post_form_restored( $form_id ) {
868 $this->log_form_action( $form_id, 'untrashed' );
869 }
870
871 /**
872 * Callback fired when a form is activated
873 *
874 * @action gform_post_form_activated
875 *
876 * @param int $form_id Form ID.
877 */
878 public function callback_gform_post_form_activated( $form_id ) {
879 $this->log_form_action( $form_id, 'activated' );
880 }
881
882 /**
883 * Callback fired when a form is deactivated
884 *
885 * @action gform_post_form_deactivated
886 *
887 * @param int $form_id Form ID.
888 */
889 public function callback_gform_post_form_deactivated( $form_id ) {
890 $this->log_form_action( $form_id, 'deactivated' );
891 }
892
893 /**
894 * Callback fired when a form is duplicated
895 *
896 * @action gform_post_form_duplicated
897 *
898 * @param int $form_id Form ID.
899 */
900 public function callback_gform_post_form_duplicated( $form_id ) {
901 $this->log_form_action( $form_id, 'duplicated' );
902 }
903
904 /**
905 * Callback fired when a form's views are reset
906 *
907 * @action gform_post_form_views_deleted
908 *
909 * @param int $form_id Form ID.
910 */
911 public function callback_gform_post_form_views_deleted( $form_id ) {
912 $this->log_form_action( $form_id, 'views_deleted' );
913 }
914
915 /**
916 * Track status change of forms
917 *
918 * @param int $form_id Form ID.
919 * @param string $action Action.
920 */
921 public function log_form_action( $form_id, $action ) {
922 $form = $this->get_form( $form_id );
923
924 if ( empty( $form ) ) {
925 return;
926 }
927
928 $actions = array(
929 'activated' => esc_html__( 'Activated', 'stream' ),
930 'deactivated' => esc_html__( 'Deactivated', 'stream' ),
931 'trashed' => esc_html__( 'Trashed', 'stream' ),
932 'untrashed' => esc_html__( 'Restored', 'stream' ),
933 'duplicated' => esc_html__( 'Duplicated', 'stream' ),
934 'deleted' => esc_html__( 'Deleted', 'stream' ),
935 'views_deleted' => esc_html__( 'Views Reset', 'stream' ),
936 );
937
938 $this->log(
939 sprintf(
940 /* translators: %1$d: an ID, %2$s: a form title, %3$s: a status (e.g. "42", "Contact Form", "Activated") */
941 __( 'Form #%1$d ("%2$s") %3$s', 'stream' ),
942 $form_id,
943 $form['title'],
944 strtolower( $actions[ $action ] )
945 ),
946 array(
947 'form_id' => $form_id,
948 'form_title' => $form['title'],
949 'form_status' => strtolower( $action ),
950 ),
951 $form['id'],
952 'forms',
953 $action
954 );
955 }
956
957 /**
958 * Helper function to get a single entry
959 *
960 * @param int $lead_id Lead ID.
961 */
962 private function get_lead( $lead_id ) {
963 return \GFFormsModel::get_lead( $lead_id );
964 }
965
966 /**
967 * Helper function to get a single form
968 *
969 * @param int $form_id Form ID.
970 */
971 private function get_form( $form_id ) {
972 return \GFFormsModel::get_form_meta( $form_id );
973 }
974 }
975