diff --git a/connectors/class-connector-gravityforms.php b/connectors/class-connector-gravityforms.php index 2c6122e2a..67be7192d 100644 --- a/connectors/class-connector-gravityforms.php +++ b/connectors/class-connector-gravityforms.php @@ -1,7 +1,9 @@ =' ) ) { return true; } return false; + } /** @@ -86,7 +89,9 @@ public function is_dependency_satisfied() { * @return string Translated connector label */ public function get_label() { + return esc_html_x( 'Gravity Forms', 'gravityforms', 'stream' ); + } /** @@ -95,6 +100,7 @@ public function get_label() { * @return array Action label translations */ public function get_action_labels() { + return array( 'created' => esc_html_x( 'Created', 'gravityforms', 'stream' ), 'updated' => esc_html_x( 'Updated', 'gravityforms', 'stream' ), @@ -108,7 +114,10 @@ public function get_action_labels() { 'activated' => esc_html_x( 'Activated', 'gravityforms', 'stream' ), 'deactivated' => esc_html_x( 'Deactivated', 'gravityforms', 'stream' ), 'views_deleted' => esc_html_x( 'Views Reset', 'gravityforms', 'stream' ), + 'starred' => esc_html_x( 'Starred', 'gravityforms', 'stream' ), + 'unstarred' => esc_html_x( 'Unstarred', 'gravityforms', 'stream' ), ); + } /** @@ -117,6 +126,7 @@ public function get_action_labels() { * @return array Context label translations */ public function get_context_labels() { + return array( 'forms' => esc_html_x( 'Forms', 'gravityforms', 'stream' ), 'settings' => esc_html_x( 'Settings', 'gravityforms', 'stream' ), @@ -124,6 +134,7 @@ public function get_context_labels() { 'entries' => esc_html_x( 'Entries', 'gravityforms', 'stream' ), 'notes' => esc_html_x( 'Notes', 'gravityforms', 'stream' ), ); + } /** @@ -137,6 +148,7 @@ public function get_context_labels() { * @return array Action links */ public function action_links( $links, $record ) { + if ( 'forms' === $record->context ) { $links[ esc_html__( 'Edit', 'stream' ) ] = add_query_arg( array( @@ -175,32 +187,41 @@ public function action_links( $links, $record ) { } return $links; + } public function register() { + parent::register(); $this->options = array( - 'rg_gforms_disable_css' => array( + 'rg_gforms_disable_css' => array( 'label' => esc_html_x( 'Output CSS', 'gravityforms', 'stream' ), ), - 'rg_gforms_enable_html5' => array( + + 'rg_gforms_enable_html5' => array( 'label' => esc_html_x( 'Output HTML5', 'gravityforms', 'stream' ), ), - 'gform_enable_noconflict' => array( + + 'gform_enable_noconflict' => array( 'label' => esc_html_x( 'No-Conflict Mode', 'gravityforms', 'stream' ), ), - 'rg_gforms_currency' => array( + + 'rg_gforms_currency' => array( 'label' => esc_html_x( 'Currency', 'gravityforms', 'stream' ), ), - 'rg_gforms_captcha_public_key' => array( + + 'rg_gforms_captcha_public_key' => array( 'label' => esc_html_x( 'reCAPTCHA Public Key', 'gravityforms', 'stream' ), ), + 'rg_gforms_captcha_private_key' => array( 'label' => esc_html_x( 'reCAPTCHA Private Key', 'gravityforms', 'stream' ), ), - 'rg_gforms_key' => null, + + 'rg_gforms_key' => null, ); + } /** @@ -208,10 +229,12 @@ public function register() { * * @param array $form * @param bool $is_new + * @return void */ public function callback_gform_after_save_form( $form, $is_new ) { - $title = $form['title']; - $id = $form['id']; + + $title = $form[ 'title' ]; + $id = $form[ 'id' ]; $this->log( sprintf( @@ -228,6 +251,7 @@ public function callback_gform_after_save_form( $form, $is_new ) { 'forms', $is_new ? 'created' : 'updated' ); + } /** @@ -236,10 +260,10 @@ public function callback_gform_after_save_form( $form, $is_new ) { * @param array $confirmation * @param array $form * @param bool $is_new - * * @return array */ public function callback_gform_pre_confirmation_save( $confirmation, $form, $is_new = true ) { + if ( ! isset( $is_new ) ) { $is_new = false; } @@ -249,18 +273,19 @@ public function callback_gform_pre_confirmation_save( $confirmation, $form, $is_ __( '"%1$s" confirmation %2$s for "%3$s"', 'stream' ), $confirmation['name'], $is_new ? esc_html__( 'created', 'stream' ) : esc_html__( 'updated', 'stream' ), - $form['title'] + $form[ 'title' ] ), array( 'is_new' => $is_new, - 'form_id' => $form['id'], + 'form_id' => $form[ 'id' ], ), - $form['id'], + $form[ 'id' ], 'forms', 'updated' ); return $confirmation; + } /** @@ -269,10 +294,10 @@ public function callback_gform_pre_confirmation_save( $confirmation, $form, $is_ * @param array $notification * @param array $form * @param bool $is_new - * * @return array */ public function callback_gform_pre_notification_save( $notification, $form, $is_new = true ) { + if ( ! isset( $is_new ) ) { $is_new = false; } @@ -282,18 +307,19 @@ public function callback_gform_pre_notification_save( $notification, $form, $is_ __( '"%1$s" notification %2$s for "%3$s"', 'stream' ), $notification['name'], $is_new ? esc_html__( 'created', 'stream' ) : esc_html__( 'updated', 'stream' ), - $form['title'] + $form[ 'title' ] ), array( 'is_update' => $is_new, - 'form_id' => $form['id'], + 'form_id' => $form[ 'id' ], ), - $form['id'], + $form[ 'id' ], 'forms', 'updated' ); return $notification; + } /** @@ -301,22 +327,25 @@ public function callback_gform_pre_notification_save( $notification, $form, $is_ * * @param array $notification * @param array $form + * @return void */ public function callback_gform_pre_notification_deleted( $notification, $form ) { + $this->log( sprintf( __( '"%1$s" notification deleted from "%2$s"', 'stream' ), $notification['name'], - $form['title'] + $form[ 'title' ] ), array( - 'form_id' => $form['id'], + 'form_id' => $form[ 'id' ], 'notification' => $notification, ), - $form['id'], + $form[ 'id' ], 'forms', 'updated' ); + } /** @@ -324,22 +353,25 @@ public function callback_gform_pre_notification_deleted( $notification, $form ) * * @param array $confirmation * @param array $form + * @return void */ public function callback_gform_pre_confirmation_deleted( $confirmation, $form ) { + $this->log( sprintf( __( '"%1$s" confirmation deleted from "%2$s"', 'stream' ), $confirmation['name'], - $form['title'] + $form[ 'title' ] ), array( - 'form_id' => $form['id'], + 'form_id' => $form[ 'id' ], 'confirmation' => $confirmation, ), - $form['id'], + $form[ 'id' ], 'forms', 'updated' ); + } /** @@ -348,17 +380,19 @@ public function callback_gform_pre_confirmation_deleted( $confirmation, $form ) * @param array $confirmation * @param array $form * @param bool $is_active + * @return void */ public function callback_gform_confirmation_status( $confirmation, $form, $is_active ) { + $this->log( sprintf( __( '"%1$s" confirmation %2$s from "%3$s"', 'stream' ), $confirmation['name'], $is_active ? esc_html__( 'activated', 'stream' ) : esc_html__( 'deactivated', 'stream' ), - $form['title'] + $form[ 'title' ] ), array( - 'form_id' => $form['id'], + 'form_id' => $form[ 'id' ], 'confirmation' => $confirmation, 'is_active' => $is_active, ), @@ -366,6 +400,7 @@ public function callback_gform_confirmation_status( $confirmation, $form, $is_ac 'forms', 'updated' ); + } /** @@ -374,24 +409,27 @@ public function callback_gform_confirmation_status( $confirmation, $form, $is_ac * @param array $notification * @param array $form * @param bool $is_active + * @return void */ public function callback_gform_notification_status( $notification, $form, $is_active ) { + $this->log( sprintf( __( '"%1$s" notification %2$s from "%3$s"', 'stream' ), $notification['name'], $is_active ? esc_html__( 'activated', 'stream' ) : esc_html__( 'deactivated', 'stream' ), - $form['title'] + $form[ 'title' ] ), array( - 'form_id' => $form['id'], + 'form_id' => $form[ 'id' ], 'notification' => $notification, 'is_active' => $is_active, ), - $form['id'], + $form[ 'id' ], 'forms', 'updated' ); + } public function callback_update_option( $option, $old, $new ) { @@ -419,6 +457,7 @@ public function callback_delete_site_option( $option ) { } public function check( $option, $old_value, $new_value ) { + if ( ! array_key_exists( $option, $this->options ) ) { return; } @@ -438,9 +477,11 @@ public function check( $option, $old_value, $new_value ) { isset( $data['action'] ) ? $data['action'] : 'updated' ); } + } public function check_rg_gforms_key( $old_value, $new_value ) { + $is_update = ( $new_value && strlen( $new_value ) ); $option = 'rg_gforms_key'; @@ -454,38 +495,68 @@ public function check_rg_gforms_key( $old_value, $new_value ) { 'settings', $is_update ? 'updated' : 'deleted' ); + } - public function callback_gform_export_separator( $dummy, $form_id ) { - $form = $this->get_form( $form_id ); + public function callback_gform_post_export_entries( $form, $start_date, $end_date, $fields ) { $this->log( - __( '"%s" form exported', 'stream' ), + __( '"%s" form entries exported', 'stream' ), array( - 'form_title' => $form['title'], - 'form_id' => $form_id, + 'form_title' => $form[ 'title' ], + 'form_id' => $form[ 'id' ], + 'start_date' => empty( $start_date ) ? null : $start_date, + 'end_date' => empty( $end_date ) ? null : $end_date ), - $form_id, + $form[ 'id' ], 'export', 'exported' ); - return $dummy; } - public function callback_gform_import_form_xml_options( $dummy ) { + public function callback_gform_forms_post_import( $forms ) { + + $forms_total = count( $forms ); + $forms_label = ( 1 === $forms_total ) ? 'form' : 'forms'; + $forms_ids = wp_list_pluck( $forms, 'id' ); + $forms_titles = wp_list_pluck( $forms, 'title' ); + $this->log( - __( 'Import process started', 'stream' ), - array(), + __( '%d ' . $forms_label . ' imported', 'stream' ), + array( + 'count' => $forms_total, + 'ids' => $forms_ids, + 'titles' => $forms_titles + ), null, 'export', 'imported' ); + } + + public function callback_gform_export_separator( $dummy, $form_id ) { + + $form = $this->get_form( $form_id ); + + $this->log( + __( '"%s" form exported', 'stream' ), + array( + 'form_title' => $form[ 'title' ], + 'form_id' => $form_id, + ), + $form_id, + 'export', + 'exported' + ); + return $dummy; + } public function callback_gform_export_options( $dummy, $forms ) { + $ids = wp_list_pluck( $forms, 'id' ); $titles = wp_list_pluck( $forms, 'title' ); @@ -502,64 +573,72 @@ public function callback_gform_export_options( $dummy, $forms ) { ); return $dummy; + } public function callback_gform_delete_lead( $lead_id ) { - $lead = \GFFormsModel::get_lead( $lead_id ); - $form = $this->get_form( $lead['form_id'] ); + + $lead = $this->get_lead( $lead_id ); + $form = $this->get_form( $lead[ 'form_id' ] ); $this->log( __( 'Lead #%1$d from "%2$s" deleted', 'stream' ), array( 'lead_id' => $lead_id, - 'form_title' => $form['title'], - 'form_id' => $form['id'], + 'form_title' => $form[ 'title' ], + 'form_id' => $form[ 'id' ], ), $lead_id, 'entries', 'deleted' ); + } public function callback_gform_post_note_added( $note_id, $lead_id, $user_id, $user_name, $note, $note_type ) { + $lead = \GFFormsModel::get_lead( $lead_id ); - $form = $this->get_form( $lead['form_id'] ); + $form = $this->get_form( $lead[ 'form_id' ] ); $this->log( __( 'Note #%1$d added to lead #%2$d on "%3$s" form', 'stream' ), array( 'note_id' => $note_id, 'lead_id' => $lead_id, - 'form_title' => $form['title'], - 'form_id' => $form['id'], + 'form_title' => $form[ 'title' ], + 'form_id' => $form[ 'id' ], ), $note_id, 'notes', 'added' ); + } public function callback_gform_pre_note_deleted( $note_id, $lead_id ) { - $lead = \GFFormsModel::get_lead( $lead_id ); - $form = $this->get_form( $lead['form_id'] ); + + $lead = $this->get_lead( $lead_id ); + $form = $this->get_form( $lead[ 'form_id' ] ); $this->log( __( 'Note #%1$d deleted from lead #%2$d on "%3$s" form', 'stream' ), array( 'note_id' => $note_id, 'lead_id' => $lead_id, - 'form_title' => $form['title'], - 'form_id' => $form['id'], + 'form_title' => $form[ 'title' ], + 'form_id' => $form[ 'id' ], ), $note_id, 'notes', 'deleted' ); + } public function callback_gform_update_status( $lead_id, $status, $prev = '' ) { - $lead = \GFFormsModel::get_lead( $lead_id ); - $form = $this->get_form( $lead['form_id'] ); + + $lead = $this->get_lead( $lead_id ); + $form = $this->get_form( $lead[ 'form_id' ] ); if ( 'active' === $status && 'trash' === $prev ) { $status = 'restore'; @@ -581,12 +660,12 @@ public function callback_gform_update_status( $lead_id, $status, $prev = '' ) { __( 'Lead #%1$d %2$s on "%3$s" form', 'stream' ), $lead_id, $actions[ $status ], - $form['title'] + $form[ 'title' ] ), array( 'lead_id' => $lead_id, - 'form_title' => $form['title'], - 'form_id' => $form['id'], + 'form_title' => $form[ 'title' ], + 'form_id' => $form[ 'id' ], 'status' => $status, 'prev' => $prev, ), @@ -594,90 +673,176 @@ public function callback_gform_update_status( $lead_id, $status, $prev = '' ) { 'entries', $status ); + } + /** + * Callback fired when an entry is read/unread + * + * @param int $lead_id + * @param int $status + * @return void + */ public function callback_gform_update_is_read( $lead_id, $status ) { - $lead = \GFFormsModel::get_lead( $lead_id ); - $form = $this->get_form( $lead['form_id'] ); + + $lead = $this->get_lead( $lead_id ); + $form = $this->get_form( $lead[ 'form_id' ] ); + $status = ( ! empty( $status ) ) ? esc_html__( 'read', 'stream' ) : esc_html__( 'unread', 'stream' ); $this->log( sprintf( - __( 'Lead #%1$d marked as %2$s on "%3$s" form', 'stream' ), + __( 'Entry #%1$d marked as %2$s on form #%3$d ("%4$s")', 'stream' ), $lead_id, - $status ? esc_html__( 'read', 'stream' ) : esc_html__( 'unread', 'stream' ), - $form['title'] + $status, + $form[ 'id' ], + $form[ 'title' ] ), + array( - 'lead_id' => $lead_id, - 'form_title' => $form['title'], - 'form_id' => $form['id'], - 'status' => $status, + 'lead_id' => $lead_id, + 'lead_status' => $status, + 'form_id' => $form[ 'id' ], + 'form_title' => $form[ 'title' ], ), + $lead_id, 'entries', 'updated' ); + } + /** + * Callback fired when an entry is starred/unstarred + * + * @param int $lead_id + * @param int $status + * @return void + */ public function callback_gform_update_is_starred( $lead_id, $status ) { - $lead = \GFFormsModel::get_lead( $lead_id ); - $form = $this->get_form( $lead['form_id'] ); + + $lead = $this->get_lead( $lead_id ); + $form = $this->get_form( $lead[ 'form_id' ] ); + $status = ( ! empty( $status ) ) ? esc_html__( 'starred', 'stream' ) : esc_html__( 'unstarred', 'stream' ); + $action = $status; $this->log( sprintf( - __( 'Lead #%1$d %2$s on "%3$s" form', 'stream' ), + __( 'Entry #%1$d %2$s on form #%3$d ("%4$s")', 'stream' ), $lead_id, - $status ? esc_html__( 'starred', 'stream' ) : esc_html__( 'unstarred', 'stream' ), - $form['title'] + $status, + $form[ 'id' ], + $form[ 'title' ] ), + array( - 'lead_id' => $lead_id, - 'form_title' => $form['title'], - 'form_id' => $form['id'], - 'status' => $status, + 'lead_id' => $lead_id, + 'lead_status' => $status, + 'form_id' => $form[ 'id' ], + 'form_title' => $form[ 'title' ], ), + $lead_id, 'entries', - 'updated' + $action ); + } + /** + * Callback fired when a form is deleted + * + * @param int $form_id Form ID + * @return void + */ public function callback_gform_before_delete_form( $form_id ) { + $this->log_form_action( $form_id, 'deleted' ); + } + /** + * Callback fired when a form is trashed + * + * @param int $form_id Form ID + * @return void + */ public function callback_gform_post_form_trashed( $form_id ) { + $this->log_form_action( $form_id, 'trashed' ); + } + /** + * Callback fired when a form is restored + * + * @param int $form_id Form ID + * @return void + */ public function callback_gform_post_form_restored( $form_id ) { + $this->log_form_action( $form_id, 'untrashed' ); + } + /** + * Callback fired when a form is activated + * + * @param int $form_id Form ID + * @return void + */ public function callback_gform_post_form_activated( $form_id ) { + $this->log_form_action( $form_id, 'activated' ); + } + /** + * Callback fired when a form is deactivated + * + * @param int $form_id Form ID + * @return void + */ public function callback_gform_post_form_deactivated( $form_id ) { + $this->log_form_action( $form_id, 'deactivated' ); + } + /** + * Callback fired when a form is duplicated + * + * @param int $form_id Form ID + * @return void + */ public function callback_gform_post_form_duplicated( $form_id ) { + $this->log_form_action( $form_id, 'duplicated' ); + } + /** + * Callback fired when a form's views are reset + * + * @param int $form_id Form ID + * @return void + */ public function callback_gform_post_form_views_deleted( $form_id ) { + $this->log_form_action( $form_id, 'views_deleted' ); + } /** * Track status change of forms * - * @param integer $form_id + * @param int $form_id * @param string $action + * @return void */ public function log_form_action( $form_id, $action ) { - $form = $this->get_form( $form_id ); + + $form = $this->get_form( $form_id ); if ( empty( $form ) ) { return; @@ -695,23 +860,47 @@ public function log_form_action( $form_id, $action ) { $this->log( sprintf( - __( '"%1$s" form %2$s', 'stream' ), - $form['title'], - $actions[ $action ] + __( 'Form #%1$d ("%2$s") %3$s', 'stream' ), + $form_id, + $form[ 'title' ], + strtolower( $actions[ $action ] ) ), + array( - 'form_title' => $form['title'], - 'form_id' => $form_id, + 'form_id' => $form_id, + 'form_title' => $form[ 'title' ], + 'form_status' => strtolower( $action ) ), - $form['id'], + + $form[ 'id' ], 'forms', $action ); + + } + + /** + * Helper function to get a single entry + * + * @param int $lead_id Lead ID + * @return array + */ + private function get_lead( $lead_id ) { + + return \GFFormsModel::get_lead( $lead_id ); + } + /** + * Helper function to get a single form + * + * @param int $form_id Form ID + * @return array + */ private function get_form( $form_id ) { - $form = \GFFormsModel::get_form_meta_by_id( $form_id ); - return reset( $form ); + return \GFFormsModel::get_form_meta( $form_id ); + } + }