Skip to content

Commit

Permalink
fix: Perform fixes required for getting the plugin to pass through th…
Browse files Browse the repository at this point in the history
…e review
  • Loading branch information
itssimple committed Nov 20, 2023
1 parent 95f1ef9 commit 2546a1d
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 44 deletions.
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Contributors: mnchga
Tags: booking, participants, courses, events, eduadmin, lega online, google, analytics, tag manager
Requires at least: 5.8
Tested up to: 6.0
Tested up to: 6.4
Stable tag: 1.0.0
Requires PHP: 7.0
License: GPL3
Expand All @@ -14,3 +14,10 @@ This plugin adds support for Google Analytics / Tag Manager to your EduAdmin plu
# EduAdmin - Google Analytics / Tag Manager WordPress

This plugin adds support for Google Analytics / Tag Manager to your [EduAdmin-Wordpress plugin](https://github.com/MultinetInteractive/EduAdmin-WordPress).

The plugin will add javascript to your website that will send events to Google Analytics / Tag Manager when a user interacts with the booking form.

The domain of the javascript will be from https://www.googletagmanager.com, and you can find their terms of service here:
https://www.google.com/analytics/terms/tag-manager/

This plugin requires that you're using the [EduAdmin-Wordpress plugin](https://wordpress.org/plugins/eduadmin-booking/)
18 changes: 9 additions & 9 deletions class/class-edu-google.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php
defined( 'ABSPATH' ) or die( 'This plugin must be run within the scope of WordPress.' );

if ( ! class_exists( 'EDU_Google' ) ) {
class EDU_Google extends EDU_Integration {
if ( ! class_exists( 'EDUGTAG_Google' ) ) {
class EDUGTAG_Google extends EDU_Integration {
/**
* Constructor
*/
Expand Down Expand Up @@ -136,7 +136,7 @@ public function track_list_course_view( $courses ) {
<script type="text/javascript">gtag('event', 'view_item_list', {
'item_list_id': 'course_list',
'item_list_name': 'Course list',
'items': <?php echo json_encode( $gtag_items, JSON_PRETTY_PRINT ); ?> });</script>
'items': <?php echo wp_json_encode( $gtag_items, JSON_PRETTY_PRINT ); ?> });</script>
<?php
}
}
Expand All @@ -161,7 +161,7 @@ public function track_list_event_view( $events ) {
<script type="text/javascript">gtag('event', 'view_item_list', {
'item_list_id': 'event_list',
'item_list_name': 'Event list',
'items': <?php echo json_encode( $gtag_items, JSON_PRETTY_PRINT ); ?> });</script>
'items': <?php echo wp_json_encode( $gtag_items, JSON_PRETTY_PRINT ); ?> });</script>
<?php
}
}
Expand All @@ -183,7 +183,7 @@ public function track_detail_view( $course_template ) {
if ( count( $gtag_items ) > 0 ) {
?>
<script type="text/javascript">gtag('event', 'view_item', {
'items': <?php echo json_encode( $gtag_items, JSON_PRETTY_PRINT ); ?> });</script>
'items': <?php echo wp_json_encode( $gtag_items, JSON_PRETTY_PRINT ); ?> });</script>
<?php
}
}
Expand All @@ -203,7 +203,7 @@ public function track_programme_detail_view( $programme ) {
if ( count( $gtag_items ) > 0 ) {
?>
<script type="text/javascript">gtag('event', 'view_item', {
'items': <?php echo json_encode( $gtag_items, JSON_PRETTY_PRINT ); ?> });</script>
'items': <?php echo wp_json_encode( $gtag_items, JSON_PRETTY_PRINT ); ?> });</script>
<?php
}
}
Expand All @@ -225,7 +225,7 @@ public function track_booking_view( $course_template ) {
if ( count( $gtag_items ) > 0 ) {
?>
<script type="text/javascript">gtag('event', 'begin_checkout', {
'items': <?php echo json_encode( $gtag_items, JSON_PRETTY_PRINT ); ?> });</script>
'items': <?php echo wp_json_encode( $gtag_items, JSON_PRETTY_PRINT ); ?> });</script>
<?php
}
}
Expand All @@ -245,7 +245,7 @@ public function track_programme_booking_view( $programme ) {
if ( count( $gtag_items ) > 0 ) {
?>
<script type="text/javascript">gtag('event', 'begin_checkout', {
'items': <?php echo json_encode( $gtag_items, JSON_PRETTY_PRINT ); ?> });</script>
'items': <?php echo wp_json_encode( $gtag_items, JSON_PRETTY_PRINT ); ?> });</script>
<?php
}
}
Expand Down Expand Up @@ -313,7 +313,7 @@ public function track_booking_completed( $booking_info ) {
'currency': '<?php echo esc_js( $currency ); ?>',
'value': <?php echo esc_js( $booking_info["TotalPriceExVat"] ); ?>,
'tax': <?php echo esc_js( $booking_info["VatSum"] ); ?>,
'items': <?php echo json_encode( $order_rows, JSON_PRETTY_PRINT ); ?>
'items': <?php echo wp_json_encode( $order_rows, JSON_PRETTY_PRINT ); ?>
});</script>
<?php
}
Expand Down
36 changes: 19 additions & 17 deletions eduadmin-google.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* GitHub Plugin URI: multinetinteractive/eduadmin-google
* GitHub Plugin URI: https://github.com/multinetinteractive/eduadmin-google
* Requires at least: 5.8
* Tested up to: 6.0
* Tested up to: 6.4
* Author: Chris Gårdenberg, MultiNet Interactive AB
* Author URI: https://www.multinet.com
* License: GPL3
Expand All @@ -35,26 +35,28 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

add_action( 'admin_init', 'checkForEduAdminPlugin' );
function checkForEduAdminPlugin() {
if ( is_admin() && current_user_can( 'activate_plugins' ) && ( ! is_plugin_active( 'eduadmin-booking/eduadmin.php' ) && ! is_plugin_active( 'eduadmin/eduadmin.php' ) ) ) {
add_action( 'admin_notices', function () {
?>
<div class="error">
<p><?php _e( 'This plugin requires the EduAdmin-WordPress-plugin to be installed and activated.', 'eduadmin-google' ); ?></p>
</div><?php
} );
deactivate_plugins( plugin_basename( __FILE__ ) );
if ( ! function_exists( 'EDUGTAG_checkForEduAdminPlugin' ) ) {
add_action( 'admin_init', 'EDUGTAG_checkForEduAdminPlugin' );
function EDUGTAG_checkForEduAdminPlugin() {
if ( is_admin() && current_user_can( 'activate_plugins' ) && ( ! is_plugin_active( 'eduadmin-booking/eduadmin.php' ) && ! is_plugin_active( 'eduadmin/eduadmin.php' ) ) ) {
add_action( 'admin_notices', function () {
?>
<div class="error">
<p><?php esc_html_e( 'This plugin requires the EduAdmin-WordPress-plugin to be installed and activated.', 'eduadmin-google' ); ?></p>
</div><?php
} );
deactivate_plugins( plugin_basename( __FILE__ ) );

if ( isset( $_GET['activate'] ) ) {
unset( $_GET['activate'] );
if ( isset( $_GET['activate'] ) ) {
unset( $_GET['activate'] );
}
}
}
}

if ( ! class_exists( 'EDU_Google_Loader' ) ):
if ( ! class_exists( 'EDUGTAG_Google_Loader' ) ):

final class EDU_Google_Loader {
final class EDUGTAG_Google_Loader {
public function __construct() {
add_action( 'plugins_loaded', array( $this, 'init' ) );
}
Expand All @@ -68,11 +70,11 @@ public function init() {
}

public function add_integration( $integrations ) {
$integrations[] = 'EDU_Google';
$integrations[] = 'EDUGTAG_Google';

return $integrations;
}
}

$edu_sveawebpay_loader = new EDU_Google_Loader( __FILE__ );
$edu_google_loader = new EDUGTAG_Google_Loader( __FILE__ );
endif;
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
},
"config": {
"eduadmin": {
"testedUpTo": "6.0",
"testedUpTo": "6.4",
"requiresAtLeast": "5.8",
"minimumPhpVersion": "7.0"
}
Expand Down
7 changes: 7 additions & 0 deletions src/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,10 @@ This plugin adds support for Google Analytics / Tag Manager to your EduAdmin plu
# EduAdmin - Google Analytics / Tag Manager WordPress

This plugin adds support for Google Analytics / Tag Manager to your [EduAdmin-Wordpress plugin](https://github.com/MultinetInteractive/EduAdmin-WordPress).

The plugin will add javascript to your website that will send events to Google Analytics / Tag Manager when a user interacts with the booking form.

The domain of the javascript will be from https://www.googletagmanager.com, and you can find their terms of service here:
https://www.google.com/analytics/terms/tag-manager/

This plugin requires that you're using the [EduAdmin-Wordpress plugin](https://wordpress.org/plugins/eduadmin-booking/)
34 changes: 18 additions & 16 deletions src/eduadmin-google.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,26 +35,28 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

add_action( 'admin_init', 'checkForEduAdminPlugin' );
function checkForEduAdminPlugin() {
if ( is_admin() && current_user_can( 'activate_plugins' ) && ( ! is_plugin_active( 'eduadmin-booking/eduadmin.php' ) && ! is_plugin_active( 'eduadmin/eduadmin.php' ) ) ) {
add_action( 'admin_notices', function () {
?>
<div class="error">
<p><?php _e( 'This plugin requires the EduAdmin-WordPress-plugin to be installed and activated.', 'eduadmin-google' ); ?></p>
</div><?php
} );
deactivate_plugins( plugin_basename( __FILE__ ) );
if ( ! function_exists( 'EDUGTAG_checkForEduAdminPlugin' ) ) {
add_action( 'admin_init', 'EDUGTAG_checkForEduAdminPlugin' );
function EDUGTAG_checkForEduAdminPlugin() {
if ( is_admin() && current_user_can( 'activate_plugins' ) && ( ! is_plugin_active( 'eduadmin-booking/eduadmin.php' ) && ! is_plugin_active( 'eduadmin/eduadmin.php' ) ) ) {
add_action( 'admin_notices', function () {
?>
<div class="error">
<p><?php esc_html_e( 'This plugin requires the EduAdmin-WordPress-plugin to be installed and activated.', 'eduadmin-google' ); ?></p>
</div><?php
} );
deactivate_plugins( plugin_basename( __FILE__ ) );

if ( isset( $_GET['activate'] ) ) {
unset( $_GET['activate'] );
if ( isset( $_GET['activate'] ) ) {
unset( $_GET['activate'] );
}
}
}
}

if ( ! class_exists( 'EDU_Google_Loader' ) ):
if ( ! class_exists( 'EDUGTAG_Google_Loader' ) ):

final class EDU_Google_Loader {
final class EDUGTAG_Google_Loader {
public function __construct() {
add_action( 'plugins_loaded', array( $this, 'init' ) );
}
Expand All @@ -68,11 +70,11 @@ public function init() {
}

public function add_integration( $integrations ) {
$integrations[] = 'EDU_Google';
$integrations[] = 'EDUGTAG_Google';

return $integrations;
}
}

$edu_sveawebpay_loader = new EDU_Google_Loader( __FILE__ );
$edu_google_loader = new EDUGTAG_Google_Loader( __FILE__ );
endif;

0 comments on commit 2546a1d

Please sign in to comment.