Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
65 committed Oct 6, 2022
2 parents 2bbcbd6 + 71e0a35 commit 67278e2
Show file tree
Hide file tree
Showing 11 changed files with 109 additions and 65 deletions.
5 changes: 4 additions & 1 deletion README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Donate link: https://www.fathomconversions.com
Tags: analytics, events, conversions, fathom
Requires at least: 5.9
Tested up to: 6.0
Stable tag: 1.0.7
Stable tag: 1.0.8
Requires PHP: 7.0
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
Expand Down Expand Up @@ -141,6 +141,9 @@ Please create a thread in the [WordPress plugin support](https://wordpress.org/s

== Changelog ==

= 1.0.8 =
* Allowing custom fathom code option, and removal of reliance on official Fathom Plugin

= 1.0.7 =
* Removed check of site name

Expand Down
42 changes: 31 additions & 11 deletions admin/class-fathom-analytics-conversions-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public function enqueue_styles() {
* class.
*/

wp_enqueue_style( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'css/fathom-analytics-conversions-admin.css', array(), $this->version, 'all' );
wp_enqueue_style( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'css/fathom-analytics-conversions-admin.css', array(), $this->version );

}

Expand All @@ -96,7 +96,7 @@ public function enqueue_scripts() {
* class.
*/

wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/fathom-analytics-conversions-admin.js', array( 'jquery' ), '1.2', false );
wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/fathom-analytics-conversions-admin.js', array( 'jquery' ), '1.0.7', false );

}

Expand All @@ -120,7 +120,8 @@ public function fac4wp_admin_output_section( $args ) {
// admin output field
public function fac4wp_admin_output_field( $args ) {
global $fac4wp_options;
$_site_id = $fac4wp_options[ FAC_OPTION_SITE_ID ];
$_site_id = $fac4wp_options[ FAC_OPTION_SITE_ID ];
$installed_tc = $fac4wp_options[ FAC_OPTION_INSTALLED_TC ];

switch ( $args['label_for'] ) {
case FAC4WP_ADMIN_GROUP_API_KEY:
Expand All @@ -130,11 +131,11 @@ public function fac4wp_admin_output_field( $args ) {

echo '<input type="text" id="' . esc_attr( FAC4WP_OPTIONS . '[' . FAC4WP_OPTION_API_KEY_CODE . ']' ) . '" name="' . esc_attr( FAC4WP_OPTIONS . '[' . FAC4WP_OPTION_API_KEY_CODE . ']' ) . '" value="' . esc_attr( $_api_key ) . '" ' . esc_html( $_input_readonly ) . ' class="regular-text" />';
$result = fac_api_key();
//echo '<pre>';print_r($result);echo '</pre>';
//echo '<pre>';print_r($fac4wp_options);echo '</pre>';
if ( isset( $result['code'] ) && $result['code'] === 200 ) {
$body = isset( $result['body'] ) ? json_decode( $result['body'], true ) : array();
//echo '<pre>';print_r($body);echo '</pre>';
$r_site_id = isset( $body['id'] ) ? $body['id'] : '';
$r_site_id = isset( $body['id'] ) ? $body['id'] : '';
/*$r_site_name = isset( $body['name'] ) ? $body['name'] : '';
$site_name = get_site_url();
$site_name = preg_replace( '#^https?://#i', '', $site_name );
Expand Down Expand Up @@ -178,9 +179,22 @@ public function fac4wp_admin_output_field( $args ) {

case FAC4WP_ADMIN_GROUP_SITE_ID:
{
$_input_readonly = ' readonly="readonly"';
if ( empty( $installed_tc ) ) {
$_input_readonly = ' readonly="readonly"';
}
else {
$_input_readonly = '';
}

echo '<input type="text" id="' . esc_attr( FAC4WP_OPTIONS . '_' . FAC_OPTION_SITE_ID ) . '" name="' . esc_attr( FAC4WP_OPTIONS . '[' . FAC_OPTION_SITE_ID . ']' ) . '" value="' . esc_attr( $_site_id ) . '" ' . esc_html( $_input_readonly ) . ' class="regular-text" />';

echo '<label for="' . esc_attr( FAC4WP_OPTIONS . '_' . FAC_OPTION_INSTALLED_TC ) . '" class="installed_tc_elsewhere">';
echo '<input type="checkbox" id="' . esc_attr( FAC4WP_OPTIONS . '_' . FAC_OPTION_INSTALLED_TC ) . '" name="' . esc_attr( FAC4WP_OPTIONS . '[' . FAC_OPTION_INSTALLED_TC . ']' ) . '" value="1" ' . checked( 1, $installed_tc, false ) . ' >';
echo '<span>';
echo esc_html( __( 'I installed my tracking code elsewhere.', 'fathom-analytics-conversions' ) );
echo '</span></label>';

echo '<input type="text" id="' . esc_attr( FAC4WP_OPTIONS . '[' . FAC_OPTION_SITE_ID . ']' ) . '" name="' . esc_attr( FAC4WP_OPTIONS . '[' . FAC_OPTION_SITE_ID . ']' ) . '" value="' . esc_attr( $_site_id ) . '" ' . esc_html( $_input_readonly ) . ' class="regular-text" /><br />' . esc_html( $args['description'] );
echo '<br />' . esc_html( $args['description'] );
if ( empty( $_site_id ) ) {
echo '<p class="fac_error">' .
sprintf(
Expand Down Expand Up @@ -300,9 +314,13 @@ public function fac4wp_sanitize_options( $options ) {

// site ID
if ( $optionname === FAC_OPTION_SITE_ID ) {
//$output[ $optionname ] = '';
unset( $output[ $optionname ] );
// integrations

if ( empty( $output[ FAC_OPTION_INSTALLED_TC ] ) ) {
unset( $output[ $optionname ] );
}
else {
$output[ $optionname ] = $newoptionvalue;
}
}
elseif ( substr( $optionname, 0, 10 ) == 'integrate-' ) {
$output[ $optionname ] = (bool) $newoptionvalue;
Expand Down Expand Up @@ -472,6 +490,8 @@ public function fac4wp_show_admin_page() {
}

public function fac_admin_notices() {
$fac4wp_options = fac4wp_reload_options();

if ( ! file_exists( WP_PLUGIN_DIR . '/fathom-analytics/fathom-analytics.php' ) ) {

$notice = '<div class="error" id="messages"><p>';
Expand Down Expand Up @@ -507,7 +527,7 @@ public function fac_admin_notices() {
);

}
elseif ( ! is_plugin_active( 'fathom-analytics/fathom-analytics.php' ) ) {
elseif ( ! is_plugin_active( 'fathom-analytics/fathom-analytics.php' ) && empty( $fac4wp_options[ FAC_OPTION_INSTALLED_TC ] ) ) {
$notice = '<div class="error" id="messages"><p>';
$notice .= wp_kses( __( '<b>Please activate Fathom Analytics</b> below for the <b>Fathom Analytics Conversions</b> to work.', 'fathom-analytics-conversions' ),
array(
Expand Down
2 changes: 1 addition & 1 deletion admin/class-fathom-analytics-conversions-fluentform.php
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ function fac_fluentform_form_element_start( $form ) {
*/
public function enqueue_scripts() {
global $fac4wp_options, $fac4wp_plugin_url;
if ( $fac4wp_options[ FAC4WP_OPTION_INTEGRATE_FLUENTFORMS ] && $fac4wp_options['fac_fathom_analytics_is_active'] ) {
if ( $fac4wp_options[ FAC4WP_OPTION_INTEGRATE_FLUENTFORMS ] && ( $fac4wp_options['fac_fathom_analytics_is_active'] || ! empty( $fac_options[ FAC_OPTION_INSTALLED_TC ] ) ) ) {
if ( ! ( empty( $fac4wp_options[ FAC_FATHOM_TRACK_ADMIN ] ) && current_user_can( 'manage_options' ) ) ) { // track visits by administrators!

$in_footer = apply_filters( 'fac4wp_' . FAC4WP_OPTION_INTEGRATE_FLUENTFORMS, true );
Expand Down
2 changes: 1 addition & 1 deletion admin/class-fathom-analytics-conversions-gravityforms.php
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ public function fac_gform_ajax_only( $form_args ) {
return $form_args;
}

if ( $fac4wp_options[ FAC4WP_OPTION_INTEGRATE_GRAVIRYFORMS ] && $fac4wp_options['fac_fathom_analytics_is_active'] ) {
if ( $fac4wp_options[ FAC4WP_OPTION_INTEGRATE_GRAVIRYFORMS ] && ( $fac4wp_options['fac_fathom_analytics_is_active'] || ! empty( $fac_options[ FAC_OPTION_INSTALLED_TC ] ) ) ) {
$form_args['ajax'] = true;
}

Expand Down
2 changes: 1 addition & 1 deletion admin/class-fathom-analytics-conversions-ninja-forms.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public function fac_ninja_forms_save_form( $form_id ) {
*/
public function enqueue_scripts() {
global $fac4wp_options, $fac4wp_plugin_url;
if ( $fac4wp_options[ FAC4WP_OPTION_INTEGRATE_NINJAFORMS ] && $fac4wp_options['fac_fathom_analytics_is_active'] ) {
if ( $fac4wp_options[ FAC4WP_OPTION_INTEGRATE_NINJAFORMS ] && ( $fac4wp_options['fac_fathom_analytics_is_active'] || ! empty( $fac_options[ FAC_OPTION_INSTALLED_TC ] ) ) ) {
if ( ! ( empty( $fac4wp_options[ FAC_FATHOM_TRACK_ADMIN ] ) && current_user_can( 'manage_options' ) ) ) { // track visits by administrators!

$in_footer = apply_filters( 'fac4wp_' . FAC4WP_OPTION_INTEGRATE_NINJAFORMS, true );
Expand Down
7 changes: 7 additions & 0 deletions admin/css/fathom-analytics-conversions-admin.css
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,24 @@
color: #c00;
font-weight: bold;
}

.fac4wp-plugin-not-active {
color: #c00;
}

.fac4wp-plugin-active {
color: #008000;
}

.fac_connected {
color: #008000;
display: inline-block;
border: 2px solid #008000;
padding: 4px 6px;
margin-left: 8px;
border-radius: 4px;
}

input[name='fac4wp-options[fac-site-id]'] {
margin-right: 12px;
}
79 changes: 44 additions & 35 deletions admin/js/fathom-analytics-conversions-admin.js
Original file line number Diff line number Diff line change
@@ -1,37 +1,46 @@
(function( $ ) {
'use strict';
(function ($) {
'use strict';

/**
* All of the code for your admin-facing JavaScript source
* should reside in this file.
*
* Note: It has been assumed you will write jQuery code here, so the
* $ function reference has been prepared for usage within the scope
* of this function.
*
* This enables you to define handlers, for when the DOM is ready:
*
* $(function() {
*
* });
*
* When the window is loaded:
*
* $( window ).load(function() {
*
* });
*
* ...and/or other possibilities.
*
* Ideally, it is not considered best practise to attach more than a
* single DOM-ready or window-load handler for a particular page.
* Although scripts in the WordPress core, Plugins and Themes may be
* practising this, we should strive to set a better example in our own work.
*/
/**
* All of the code for your admin-facing JavaScript source
* should reside in this file.
*
* Note: It has been assumed you will write jQuery code here, so the
* $ function reference has been prepared for usage within the scope
* of this function.
*
* This enables you to define handlers, for when the DOM is ready:
*
* $(function() {
*
* });
*
* When the window is loaded:
*
* $( window ).load(function() {
*
* });
*
* ...and/or other possibilities.
*
* Ideally, it is not considered best practise to attach more than a
* single DOM-ready or window-load handler for a particular page.
* Although scripts in the WordPress core, Plugins and Themes may be
* practising this, we should strive to set a better example in our own work.
*/

$( window ).load(function() {
$('#nf-drawer-content').on('DOMSubtreeModified', function(){
$("input#fathom_analytics").prop("readonly", true);
});
});
})( jQuery );
$(window).load(function () {
$('#nf-drawer-content').on('DOMSubtreeModified', function () {
$("input#fathom_analytics").prop("readonly", true);
});
});

$(function () {
let _site_id = $('#fac4wp-options_fac-site-id');
$('.installed_tc_elsewhere input').on('change', function () {
if (this.checked) {
_site_id.prop('readonly', false);
} else _site_id.prop('readonly', true);
});
});
})(jQuery);
4 changes: 2 additions & 2 deletions fathom-analytics-conversions.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* Plugin Name: Fathom Analytics Conversions
* Plugin URI: https://www.fathomconversions.com
* Description: Easily add event conversions in WordPress plugins to Fathom Analytics
* Version: 1.0.7
* Version: 1.0.8
* Author: SixFive Pty Ltd
* Author URI: https://www.sixfive.com.au
* License: GPL-2.0+
Expand All @@ -35,7 +35,7 @@
* Start at version 1.0.0 and use SemVer - https://semver.org
* Rename this for your plugin and update it as you release new versions.
*/
define( 'FATHOM_ANALYTICS_CONVERSIONS_VERSION', '1.0.7' );
define( 'FATHOM_ANALYTICS_CONVERSIONS_VERSION', '1.0.8' );
define( 'FAC4WP_PATH', plugin_dir_path( __FILE__ ) );

global $fac4wp_plugin_url, $fac4wp_plugin_basename;
Expand Down
3 changes: 2 additions & 1 deletion includes/class-fathom-analytics-conversions.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,14 @@ public function __construct() {
$this->version = FATHOM_ANALYTICS_CONVERSIONS_VERSION;
}
else {
$this->version = '1.0.0';
$this->version = '1.0.7';
}
$this->plugin_name = 'fathom-analytics-conversions';

define( 'FAC4WP_OPTIONS', 'fac4wp-options' );
define( 'FAC4WP_OPTION_API_KEY_CODE', 'fac-api-key-code' );
define( 'FAC_OPTION_SITE_ID', 'fac-site-id' );
define( 'FAC_OPTION_INSTALLED_TC', 'installed-tracking-code-elsewhere' );
define( 'FAC_FATHOM_TRACK_ADMIN', 'fac-fathom-track-admin' );

define( 'FAC4WP_OPTION_INTEGRATE_WPCF7', 'integrate-wpcf7' );
Expand Down
22 changes: 13 additions & 9 deletions includes/fac-core-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

$fac4wp_default_options = array(
FAC4WP_OPTION_API_KEY_CODE => '',
FAC_OPTION_INSTALLED_TC => '',
FAC4WP_OPTION_INTEGRATE_WPCF7 => false,
FAC4WP_OPTION_INTEGRATE_WPFORMS => false,
FAC4WP_OPTION_INTEGRATE_GRAVIRYFORMS => false,
Expand Down Expand Up @@ -56,10 +57,13 @@ function fac_fathom_get_admin_tracking() {

// get Site ID from Fathom Analytics.
function fac_fathom_get_site_id() {
//if(!defined('FATHOM_SITE_ID_OPTION_NAME')) define('FATHOM_SITE_ID_OPTION_NAME', 'fathom_site_id');

//return get_option(FATHOM_SITE_ID_OPTION_NAME, '');
return get_option( 'fathom_site_id', '' );
$fac_options = (array) get_option( FAC4WP_OPTIONS );
if ( ! empty( $fac_options[ FAC_OPTION_INSTALLED_TC ] ) ) {
return $fac_options[ FAC_OPTION_SITE_ID ];
}
else { // If not 'installed tracking code elsewhere', get site id from FA plugin.
return get_option( 'fathom_site_id', '' );
}
}

// is Fathom Analytics active.
Expand Down Expand Up @@ -280,7 +284,7 @@ function fac_is_json( $string ) {
function fac_check_cf7_forms() {
global $fac4wp_options;
//echo '<pre>';print_r($fac4wp_options);echo '</pre>';
if ( $fac4wp_options[ FAC4WP_OPTION_INTEGRATE_WPCF7 ] && $fac4wp_options['fac_fathom_analytics_is_active'] ) {
if ( $fac4wp_options[ FAC4WP_OPTION_INTEGRATE_WPCF7 ] && ( $fac4wp_options['fac_fathom_analytics_is_active'] || ! empty( $fac_options[ FAC_OPTION_INSTALLED_TC ] ) ) ) {
$args = [
'post_type' => 'wpcf7_contact_form',
'post_status' => 'publish',
Expand Down Expand Up @@ -399,7 +403,7 @@ function fa_add_event_id_to_gf( $form_id = 0, $title = '' ) {
function fac_check_wpforms_forms() {
global $fac4wp_options;
//echo '<pre>';print_r($fac4wp_options);echo '</pre>';
if ( $fac4wp_options[ FAC4WP_OPTION_INTEGRATE_WPFORMS ] && $fac4wp_options['fac_fathom_analytics_is_active'] ) {
if ( $fac4wp_options[ FAC4WP_OPTION_INTEGRATE_WPFORMS ] && ( $fac4wp_options['fac_fathom_analytics_is_active'] || ! empty( $fac_options[ FAC_OPTION_INSTALLED_TC ] ) ) ) {
$args = [
'post_type' => 'wpforms',
'post_status' => 'publish',
Expand Down Expand Up @@ -441,7 +445,7 @@ function fac_check_wpforms_forms() {
function fac_check_gf_forms() {
global $fac4wp_options;
//echo '<pre>';print_r($fac4wp_options);echo '</pre>';
if ( $fac4wp_options[ FAC4WP_OPTION_INTEGRATE_GRAVIRYFORMS ] && $fac4wp_options['fac_fathom_analytics_is_active'] && class_exists( 'GFAPI' ) ) {
if ( $fac4wp_options[ FAC4WP_OPTION_INTEGRATE_GRAVIRYFORMS ] && ( $fac4wp_options['fac_fathom_analytics_is_active'] || ! empty( $fac_options[ FAC_OPTION_INSTALLED_TC ] ) ) && class_exists( 'GFAPI' ) ) {
$gf_forms = GFAPI::get_forms( true, false ); // get all gforms.

if ( $gf_forms ) {
Expand All @@ -466,7 +470,7 @@ function fac_check_gf_forms() {
*/
function fac_check_ff_forms() {
global $fac4wp_options, $wpdb;
if ( $fac4wp_options[ FAC4WP_OPTION_INTEGRATE_FLUENTFORMS ] && $fac4wp_options['fac_fathom_analytics_is_active'] ) {
if ( $fac4wp_options[ FAC4WP_OPTION_INTEGRATE_FLUENTFORMS ] && ( $fac4wp_options['fac_fathom_analytics_is_active'] || ! empty( $fac_options[ FAC_OPTION_INSTALLED_TC ] ) ) ) {
$formsTable = $wpdb->prefix . 'fluentform_forms';
$fForms = $wpdb->get_results( "SELECT * FROM " . $formsTable, ARRAY_A );
//echo '<pre>';print_r( $firstForm );echo '</pre>';
Expand Down Expand Up @@ -595,7 +599,7 @@ function fac_update_event_id_to_nj( $form_id, $title = '' ) {
*/
function fac_check_nj_forms() {
global $fac4wp_options, $wpdb;
if ( $fac4wp_options[ FAC4WP_OPTION_INTEGRATE_NINJAFORMS ] && $fac4wp_options['fac_fathom_analytics_is_active'] ) {
if ( $fac4wp_options[ FAC4WP_OPTION_INTEGRATE_NINJAFORMS ] && ( $fac4wp_options['fac_fathom_analytics_is_active'] || ! empty( $fac_options[ FAC_OPTION_INSTALLED_TC ] ) ) ) {
$formsTable = $wpdb->prefix . 'nf3_forms';
$fForms = $wpdb->get_results( "SELECT * FROM " . $formsTable, ARRAY_A );
//echo '<pre>';print_r( $firstForm );echo '</pre>';
Expand Down
6 changes: 3 additions & 3 deletions public/class-fathom-analytics-conversions-public.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,23 +99,23 @@ public function enqueue_scripts() {

wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/fathom-analytics-conversions-public.js', array( 'jquery' ), $this->version, false );

if ( $fac4wp_options[ FAC4WP_OPTION_INTEGRATE_WPCF7 ] && $fac4wp_options['fac_fathom_analytics_is_active'] ) {
if ( $fac4wp_options[ FAC4WP_OPTION_INTEGRATE_WPCF7 ] && ( $fac4wp_options['fac_fathom_analytics_is_active'] || ! empty( $fac_options[ FAC_OPTION_INSTALLED_TC ] ) ) ) {
if ( ! ( empty( $fac4wp_options[ FAC_FATHOM_TRACK_ADMIN ] ) && current_user_can( 'manage_options' ) ) ) { // track visits by administrators!

$in_footer = apply_filters( 'fac4wp_' . FAC4WP_OPTION_INTEGRATE_WPCF7, true );
wp_enqueue_script( 'fac-contact-form-7-tracker', $fac4wp_plugin_url . 'public/js/fac-contact-form-7-tracker.js', array(), FATHOM_ANALYTICS_CONVERSIONS_VERSION, $in_footer );
}
}

if ( $fac4wp_options[ FAC4WP_OPTION_INTEGRATE_WPFORMS ] && $fac4wp_options['fac_fathom_analytics_is_active'] ) {
if ( $fac4wp_options[ FAC4WP_OPTION_INTEGRATE_WPFORMS ] && ( $fac4wp_options['fac_fathom_analytics_is_active'] || ! empty( $fac_options[ FAC_OPTION_INSTALLED_TC ] ) ) ) {
if ( ! ( empty( $fac4wp_options[ FAC_FATHOM_TRACK_ADMIN ] ) && current_user_can( 'manage_options' ) ) ) { // track visits by administrators!

$in_footer = apply_filters( 'fac4wp_' . FAC4WP_OPTION_INTEGRATE_WPFORMS, true );
wp_enqueue_script( 'fac-wpforms-tracker', $fac4wp_plugin_url . 'public/js/fac-wpforms-tracker.js', array(), FATHOM_ANALYTICS_CONVERSIONS_VERSION, $in_footer );
}
}

if ( $fac4wp_options[ FAC4WP_OPTION_INTEGRATE_GRAVIRYFORMS ] && $fac4wp_options['fac_fathom_analytics_is_active'] ) {
if ( $fac4wp_options[ FAC4WP_OPTION_INTEGRATE_GRAVIRYFORMS ] && ( $fac4wp_options['fac_fathom_analytics_is_active'] || ! empty( $fac_options[ FAC_OPTION_INSTALLED_TC ] ) ) ) {
if ( ! ( empty( $fac4wp_options[ FAC_FATHOM_TRACK_ADMIN ] ) && current_user_can( 'manage_options' ) ) ) { // track visits by administrators!

$in_footer = apply_filters( 'fac4wp_' . FAC4WP_OPTION_INTEGRATE_GRAVIRYFORMS, true );
Expand Down

0 comments on commit 67278e2

Please sign in to comment.