Skip to content

Commit

Permalink
Comply with WordPress Coding Standards - Style
Browse files Browse the repository at this point in the history
  • Loading branch information
TorbenLundsgaard committed Aug 23, 2023
1 parent c59e146 commit 936b9f2
Show file tree
Hide file tree
Showing 48 changed files with 1,260 additions and 864 deletions.
22 changes: 16 additions & 6 deletions bin/copy-images.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
var ncp = require('ncp').ncp;
/**
* GTM Kit plugin file.
*
* @package GTM Kit
*/

var ncp = require( 'ncp' ).ncp;

ncp.limit = 16;

ncp('src/images', 'assets/images', function (err) {
if (err) {
return console.error(err);
ncp(
'src/images',
'assets/images',
function (err) {
if (err) {
return console.error( err );
}
console.log( 'Images copied!' );
}
console.log('Images copied!');
});
);
6 changes: 3 additions & 3 deletions gtm-kit.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Google Tag Manager Kit.
* GTM Kit Plugin
*
* Plugin Name: GTM Kit
* Version: 1.12.2
Expand All @@ -10,17 +10,17 @@
* Author URI: https://www.tlamedia.dk/
* Text Domain: gtm-kit
* Domain Path: /languages/
* License: GPL v3
* License: GPLv3
* Requires at least: 6.1
* Requires PHP: 7.2
*
* WC requires at least: 7.1
* WC tested up to: 8.0
*
* @package GTM Kit
* @copyright Copyright (C) 2023, TLA Media ApS
*/


if ( ! function_exists( 'add_filter' ) ) {
header( 'Status: 403 Forbidden' );
header( 'HTTP/1.1 403 Forbidden' );
Expand Down
10 changes: 8 additions & 2 deletions inc/frontend-functions.php
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
<?php
/**
* Frontend template functions
*
* @package GTM Kit
*/

use TLA_Media\GTM_Kit\Options;
use TLA_Media\GTM_Kit\Frontend\Frontend;

/**
* The noscript tag
*
* @return void
*/
function gtmkit_the_noscript_tag(): void {
$noscript_implementation = (int) Options::init()->get( 'general', 'noscript_implementation' );

if ( $noscript_implementation == 2 ) {
if ( $noscript_implementation === 2 ) {
Frontend::get_body_script();
}
}

44 changes: 26 additions & 18 deletions inc/main.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
<?php
/**
* GTM Kit plugin file.
*
* @package GTM Kit
*/

namespace TLA_Media\GTM_Kit;

Expand Down Expand Up @@ -45,6 +50,7 @@ function gtmkit_plugin_activation(): void {
function gtmkit_plugin_deactivation(): void {
wp_clear_scheduled_hook( 'gtmkit_send_anonymous_data' );
}

register_deactivation_hook( GTMKIT_FILE, 'TLA_Media\GTM_Kit\gtmkit_plugin_deactivation' );

/**
Expand All @@ -56,9 +62,9 @@ function gtmkit_plugin_deactivation(): void {
*/
function gtmkit_add_plugin_action_link( array $links ): array {

/** @noinspection HtmlUnknownTarget */
$custom['settings'] = sprintf(
'<a href="%s" aria-label="%s">%s</a>',
'<!--suppress HtmlUnknownTarget -->
<a href="%s" aria-label="%s">%s</a>',
esc_url( menu_page_url( 'gtmkit_general', false ) ),
esc_attr__( 'Go to GTM Kit Settings page', 'gtm-kit' ),
esc_html__( 'Settings', 'gtm-kit' )
Expand All @@ -78,9 +84,9 @@ function gtmkit_load_text_domain(): void {
* Load frontend.
*/
function gtmkit_frontend_init(): void {
$options = new Options();
$rest_API_server = new RestAPIServer();
$util = new Util( $rest_API_server );
$options = new Options();
$rest_api_server = new RestAPIServer();
$util = new Util( $rest_api_server );

( new SetupWizard( $options, $util ) )->rest_init();

Expand All @@ -91,10 +97,10 @@ function gtmkit_frontend_init(): void {
if ( $options->get( 'integrations', 'woocommerce_integration' ) && function_exists( 'WC' ) ) {
WooCommerce::register( $options, $util );
}
if ( $options->get( 'integrations', 'cf7_integration' ) && class_exists('WPCF7') ) {
if ( $options->get( 'integrations', 'cf7_integration' ) && class_exists( 'WPCF7' ) ) {
ContactForm7::register( $options, $util );
}
if ( $options->get( 'integrations', 'edd_integration' ) && class_exists('EDD_Requirements_Check') ) {
if ( $options->get( 'integrations', 'edd_integration' ) && class_exists( 'EDD_Requirements_Check' ) ) {
EasyDigitalDownloads::register( $options, $util );
}
}
Expand All @@ -105,7 +111,6 @@ function gtmkit_frontend_init(): void {

Frontend::register( $options );
require GTMKIT_PATH . 'inc/frontend-functions.php';

}

/**
Expand All @@ -115,34 +120,37 @@ function gtmkit_admin_init(): void {

if ( version_compare( get_option( 'gtmkit_version' ), GTMKIT_VERSION, '<' ) ) {
if ( function_exists( 'opcache_reset' ) ) {
@opcache_reset();
opcache_reset();
}

new Upgrade();
}

$options = new Options();
$rest_API_server = new RestAPIServer();
$util = new Util( $rest_API_server );
$options = new Options();
$rest_api_server = new RestAPIServer();
$util = new Util( $rest_api_server );

( new SetupWizard( $options, $util ) )->hooks();
MetaBox::register( $options );
Analytics::register( $options, $util );
GeneralOptionsPage::register( $options, $util );
IntegrationsOptionsPage::register( $options, $util);
HelpOptionsPage::register( $options, $util);
IntegrationsOptionsPage::register( $options, $util );
HelpOptionsPage::register( $options, $util );
}

/**
* Load the plugin.
*/
if ( ! wp_installing() ) {

add_action( 'before_woocommerce_init', function() {
if ( class_exists( FeaturesUtil::class ) ) {
FeaturesUtil::declare_compatibility( 'custom_order_tables', GTMKIT_FILE );
add_action(
'before_woocommerce_init',
function () {
if ( class_exists( FeaturesUtil::class ) ) {
FeaturesUtil::declare_compatibility( 'custom_order_tables', GTMKIT_FILE );
}
}
} );
);

if ( is_admin() ) {
add_action( 'plugins_loaded', 'TLA_Media\GTM_Kit\gtmkit_load_text_domain' );
Expand Down
10 changes: 8 additions & 2 deletions postcss.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
/**
* GTM Kit plugin file.
*
* @package GTM Kit
*/

module.exports = {
plugins: [
require('autoprefixer'),
require('cssnano') // This will minify the result CSS
require( 'autoprefixer' ),
require( 'cssnano' ) // This will minify the result CSS.
]
}
26 changes: 17 additions & 9 deletions src/Admin/AbstractOptionsPage.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
<?php
/**
* GTM Kit plugin file.
*
* @package GTM Kit
*/

namespace TLA_Media\GTM_Kit\Admin;

use TLA_Media\GTM_Kit\Common\Util;
use TLA_Media\GTM_Kit\Options;

/**
* AbstractOptionsPage
*/
abstract class AbstractOptionsPage {

/**
Expand All @@ -15,6 +23,8 @@ abstract class AbstractOptionsPage {
protected $options;

/**
* Utilities
*
* @var Util
*/
protected $util;
Expand All @@ -29,21 +39,21 @@ abstract class AbstractOptionsPage {
/**
* Constructor.
*
* @param Options $options
* @param Util $util
* @param Options $options An instance of Options.
* @param Util $util An instance of Util.
*/
final public function __construct( Options $options, Util $util) {
final public function __construct( Options $options, Util $util ) {
$this->options = $options;
$this->util = $util;
$this->util = $util;
}

/**
* Register the options page.
*
* @param Options $options
* @param Util $util
* @param Options $options An instance of Options.
* @param Util $util An instance of Util.
*/
public static function register( Options $options, Util $util): void {
public static function register( Options $options, Util $util ): void {
$page = new static( $options, $util );

add_action( 'admin_init', [ $page, 'configure' ] );
Expand Down Expand Up @@ -157,7 +167,6 @@ public function enqueue_assets( string $hook ) {
];

wp_localize_script( 'gtmkit-admin', 'gtmkit', $script_data );

}

/**
Expand All @@ -177,5 +186,4 @@ function admin_body_class( string $classes ): string {

return $classes;
}

}
39 changes: 24 additions & 15 deletions src/Admin/Analytics.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
<?php
/**
* GTM Kit plugin file.
*
* @package GTM Kit
*/

namespace TLA_Media\GTM_Kit\Admin;

use Mixpanel;
use TLA_Media\GTM_Kit\Common\Util;
use TLA_Media\GTM_Kit\Options;

/**
* Analytics
*/
final class Analytics {

/**
Expand All @@ -23,32 +31,36 @@ final class Analytics {
protected $options;

/**
* Utility
*
* @var Util
*/
private $util;

/**
* Constructor.
*
* @param Options $options
* @param Util $util
* @param Options $options An instance of Options.
* @param Util $util An instance of Util.
*/
final public function __construct( Options $options, Util $util) {
public function __construct( Options $options, Util $util ) {
$this->options = $options;
$this->util = $util;
$this->util = $util;
}

/**
* Register analytics
*
* @param Options $options An instance of Options.
* @param Util $util An instance of Util.
*/
public static function register( Options $options, Util $util): void {
public static function register( Options $options, Util $util ): void {
self::$instance = $page = new Analytics( $options, $util );

if ( $options->get( 'general', 'analytics_active' ) ) {
add_action( 'init', [ $page, 'schedule_daily_event' ] );
add_action( 'gtmkit_send_anonymous_data', [ $page, 'send_anonymous_data' ] );
}

}

/**
Expand All @@ -69,15 +81,13 @@ function schedule_daily_event(): void {
$event = 'gtmkit_send_anonymous_data';

if ( class_exists( 'ActionScheduler' ) ) {
// Schedule event with ActionScheduler
// Schedule event with ActionScheduler.
if ( ! as_next_scheduled_action( $event ) ) {
as_schedule_single_action( strtotime( 'midnight +25 hours' ), $event, [], 'gtmkit' );
}
} else {
// Schedule event with WP-Cron
if ( ! wp_next_scheduled( $event ) ) {
wp_schedule_event( strtotime( 'midnight' ), 'daily', $event );
}
} elseif ( ! wp_next_scheduled( $event ) ) {
// Schedule event with WP-Cron.
wp_schedule_event( strtotime( 'midnight' ), 'daily', $event );
}
}

Expand All @@ -87,9 +97,8 @@ function schedule_daily_event(): void {
* @return void
*/
function send_anonymous_data(): void {
$mp = Mixpanel::getInstance( "a84d538948ddda17265f86785c80ca37" );
$mp = Mixpanel::getInstance( 'a84d538948ddda17265f86785c80ca37' );

$mp->track( "GTM Kit", $this->util->get_site_data( $this->options->get_all_raw() ) );
$mp->track( 'GTM Kit', $this->util->get_site_data( $this->options->get_all_raw() ) );
}

}
Loading

0 comments on commit 936b9f2

Please sign in to comment.