Skip to content

Commit

Permalink
Simplify approach to one single function
Browse files Browse the repository at this point in the history
- keep that function in a file that is already synchronized with WordPress.com
- include both wpcom and Jetpack tracking approaches in that function.
- remove the dev mode check since this will be addressed in #13711
  • Loading branch information
jeherve committed Oct 11, 2019
1 parent 767d527 commit 0894993
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 94 deletions.
1 change: 0 additions & 1 deletion bin/phpcs-whitelist.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ module.exports = [
'_inc/lib/debugger/',
'_inc/lib/plans.php',
'load-jetpack.php',
'modules/contact-form/tracks-events.php',
'modules/masterbar/',
'modules/memberships/',
'modules/module-extras.php',
Expand Down
68 changes: 50 additions & 18 deletions modules/contact-form/grunion-contact-form.php
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
<?php
<?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName
/**
* Grunion Contact Form
* Add a contact form to any post, page or text widget.
* Emails will be sent to the post's author by default, or any email address you choose.
*
* @package Jetpack
*/

use Automattic\Jetpack\Assets;

/*
Plugin Name: Grunion Contact Form
Description: Add a contact form to any post, page or text widget. Emails will be sent to the post's author by default, or any email address you choose. As seen on WordPress.com.
Plugin URI: https://automattic.com/#
AUthor: Automattic, Inc.
Author URI: https://automattic.com/
Version: 2.4
License: GPLv2 or later
*/

use Automattic\Jetpack\Sync\Settings;

define( 'GRUNION_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
Expand All @@ -26,12 +22,6 @@ function grunion_contact_form_require_endpoint() {
require_once GRUNION_PLUGIN_DIR . 'class-grunion-contact-form-endpoint.php';
}

if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) {
require_once GRUNION_PLUGIN_DIR . 'tracks-events-wpcom.php';
} else {
require_once GRUNION_PLUGIN_DIR . 'tracks-events.php';
}

/**
* Sets up various actions, filters, post types, post statuses, shortcodes.
*/
Expand Down Expand Up @@ -3527,3 +3517,45 @@ function grunion_delete_old_spam() {
wp_schedule_single_event( time() + 700, 'grunion_scheduled_delete' );
}
}

/**
* Send an event to Tracks on form submission.
*
* @param int $post_id - the post_id for the CPT that is created.
* @param array $all_values - fields from the default contact form.
* @param array $extra_values - extra fields added to from the contact form.
* @return null|void
*/
function jetpack_tracks_record_grunion_pre_message_sent( $post_id, $all_values, $extra_values ) {
// Do not do anything if the submission is not from a block.
if (
! isset( $extra_values['is_block'] )
|| ! $extra_values['is_block']
) {
return;
}

/*
* Event details.
*/
$event_user = wp_get_current_user();
$event_name = 'jetpack_contact_form_block_message_sent';
$event_props = array(
'entry_permalink' => esc_url( $all_values['entry_permalink'] ),
'feedback_id' => absint( $all_values['feedback_id'] ),
);

/*
* Record event.
* We use different libs on wpcom and Jetpack.
*/
if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) {
require_lib( 'tracks/client' );
tracks_record_event( $event_user, $event_name, $event_props );
} else {
$tracking = new Automattic\Jetpack\Tracking();
$tracking->tracks_record_event( $event_user, $event_name, $event_props );
}
}
add_action( 'grunion_pre_message_sent', 'jetpack_tracks_record_grunion_pre_message_sent', 12, 3 );
33 changes: 0 additions & 33 deletions modules/contact-form/tracks-events-wpcom.php

This file was deleted.

42 changes: 0 additions & 42 deletions modules/contact-form/tracks-events.php

This file was deleted.

0 comments on commit 0894993

Please sign in to comment.