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