-
Notifications
You must be signed in to change notification settings - Fork 111
Expand file tree
/
Copy pathduracelltomi-google-tag-manager-for-wordpress.php
More file actions
122 lines (112 loc) · 4.05 KB
/
Copy pathduracelltomi-google-tag-manager-for-wordpress.php
File metadata and controls
122 lines (112 loc) · 4.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
<?php
/**
* Google Tag Manager for WordPress
*
* @package GTM4WP
* @author Thomas Geiger
* @copyright 2013- Geiger Tamás e.v. (Thomas Geiger s.e.)
* @license GNU General Public License, version 3
*
* @wordpress-plugin
* Plugin Name: GTM4WP - A Google Tag Manager (GTM) plugin for WordPress
* Plugin URI: https://gtm4wp.com/
* Description: The first Google Tag Manager plugin for WordPress with business goals in mind
* Version: 2.0.0-rc1
* Requires at least: 6.3
* Requires PHP: 8.0
* Author: Thomas Geiger
* Author URI: https://gtm4wp.com/
* License: GPLv3
* License URI: https://www.gnu.org/licenses/gpl-3.0.html
* Text Domain: duracelltomi-google-tag-manager
*
* WC requires at least: 5.0
* WC tested up to: 11.0.0
*/
// This file must stay parseable on outdated PHP versions so that the
// requirements notice below can render instead of a fatal error.
// Do not use PHP 8+ syntax here.
defined( 'ABSPATH' ) || exit;
define( 'GTM4WP_VERSION', '2.0.0-rc1' );
define( 'GTM4WP_PATH', plugin_dir_path( __FILE__ ) );
define( 'GTM4WP_PLUGIN_FILE', __FILE__ );
/*
* Deprecated in 2.0, to be removed in 2.1.
*
* These three globals carry a 1.x typo in their prefix: gtp4wp_, not gtm4wp_.
* Nothing inside the plugin reads them. They are set only for third-party code
* written against 1.x, which is why the typo was never worth correcting.
*
* A global variable cannot raise a deprecation notice the way a function can, so
* this comment and the changelog entry are the only warning a consumer gets.
*
* Replacements, available on both admin and frontend requests and defined at the
* same point in the load order:
*
* $gtp4wp_plugin_url -> plugin_dir_url( GTM4WP_PLUGIN_FILE )
* $gtp4wp_plugin_basename -> plugin_basename( GTM4WP_PLUGIN_FILE )
* $gtp4wp_script_path -> plugin_dir_url( GTM4WP_PLUGIN_FILE ) . 'build/'
*/
global $gtp4wp_plugin_url, $gtp4wp_plugin_basename, $gtp4wp_script_path;
$gtp4wp_plugin_url = plugin_dir_url( __FILE__ );
$gtp4wp_plugin_basename = plugin_basename( __FILE__ );
$gtp4wp_script_path = $gtp4wp_plugin_url . 'build/';
/**
* Outputs an admin notice when the site does not fulfill the minimum
* PHP or WordPress version requirements of GTM4WP 2.x.
*
* @return void
*/
function gtm4wp_requirements_notice() {
echo '<div class="notice notice-error"><p>';
printf(
/* translators: 1: required PHP version, 2: required WordPress version, 3: current PHP version, 4: current WordPress version. */
esc_html__(
'GTM4WP 2.x requires PHP %1$s and WordPress %2$s or newer. Your site runs PHP %3$s and WordPress %4$s, therefore the plugin is currently inactive. Please update your environment or downgrade to GTM4WP 1.x.',
'duracelltomi-google-tag-manager'
),
'8.0',
'6.3',
esc_html( PHP_VERSION ),
esc_html( $GLOBALS['wp_version'] )
);
echo '</p></div>';
}
if (
version_compare( PHP_VERSION, '8.0', '<' ) ||
version_compare( $GLOBALS['wp_version'], '6.3', '<' )
) {
add_action( 'admin_notices', 'gtm4wp_requirements_notice' );
return;
}
require_once GTM4WP_PATH . 'src/Autoloader.php';
\GTM4WP\Autoloader::register();
require_once GTM4WP_PATH . 'compat/constants.php';
/**
* WordPress hook function run after plugins have been loaded.
* Boots the plugin core which routes between admin and frontend code paths.
*
* @see https://developer.wordpress.org/reference/hooks/plugins_loaded/
*
* @return void
*/
function gtm4wp_bootstrap() {
\GTM4WP\Plugin::instance()->boot();
}
add_action( 'plugins_loaded', 'gtm4wp_bootstrap' );
/**
* Adds an action to declare compatibility with High Performance Order Storage (HPOS)
* before WooCommerce initialization.
*
* @since 1.17
*/
add_action(
'before_woocommerce_init',
function () {
// Check if the FeaturesUtil class exists in the \Automattic\WooCommerce\Utilities namespace.
if ( class_exists( \Automattic\WooCommerce\Utilities\FeaturesUtil::class ) ) {
// Declare compatibility with custom order tables using the FeaturesUtil class.
\Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility( 'custom_order_tables', __FILE__, true );
}
}
);