-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathalnp-facebook-pixel-tracking.php
210 lines (191 loc) · 5.85 KB
/
alnp-facebook-pixel-tracking.php
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
<?php
/*
* Plugin Name: Auto Load Next Post: Pixel Tracking
* Plugin URI: https://wordpress.org/plugins/alnp-facebook-pixel-tracking/
* Description: Track your page views using Facebook Pixel with Auto Load Next Post.
* Author: Auto Load Next Post
* Author URI: https://autoloadnextpost.com
* Version: 2.0.1
* Developer: Sébastien Dumont
* Developer URI: https://sebastiendumont.com
* Text Domain: alnp-facebook-pixel-tracking
* Domain Path: /languages/
*
* Auto Load Next Post: Pixel Tracking is free software: you
* can redistribute it and/or modify it under the terms of the
* GNU General Public License as published by the Free Software
* Foundation, either version 2 of the License, or any later version.
*
* You should have received a copy of the GNU General Public License
* along with Auto Load Next Post: Pixel Tracking.
* If not, see <http://www.gnu.org/licenses/>.
*
* @package Auto Load Next Post: Pixel Tracking
* @author Auto Load Next Post
* @link https://autoloadnextpost.com
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
*/
if ( ! class_exists( 'ALNP_FB_Pixel_Tracking' ) ) {
class ALNP_FB_Pixel_Tracking {
/**
* @var ALNP_FB_Pixel_Tracking - The single instance of the class.
*
* @access protected
* @static
* @since 1.0.0
*/
protected static $_instance = null;
/**
* Plugin Version
*
* @access public
* @static
* @since 1.0.0
*/
public static $version = '2.0.1';
/**
* Required Auto Load Next Post Version
*
* @access public
* @static
* @since 1.0.0
*/
public static $required_alnp = '1.4.10';
/**
* Main ALNP_FB_Pixel_Tracking Instance.
*
* Ensures only one instance of ALNP_FB_Pixel_Tracking is loaded or can be loaded.
*
* @access public
* @static
* @since 1.0.0
* @see ALNP_FB_Pixel_Tracking()
* @return ALNP_FB_Pixel_Tracking - Main instance
*/
public static function instance() {
if ( is_null( self::$_instance ) ) {
self::$_instance = new self();
}
return self::$_instance;
}
/**
* Throw error on object clone.
*
* The whole idea of the singleton design pattern is that there is a single
* object therefore, we don't want the object to be cloned.
*
* @access public
* @since 1.0.0
* @return void
*/
public function __clone() {
// Cloning instances of the class is forbidden.
_doing_it_wrong( __FUNCTION__, __( 'Cloning this object is forbidden.', 'alnp-facebook-pixel-tracking' ), self::$version );
}
/**
* Disable unserializing of the class.
*
* @access public
* @since 1.0.0
* @return void
*/
public function __wakeup() {
// Unserializing instances of the class is forbidden.
_doing_it_wrong( __FUNCTION__, __( 'Unserializing instances of this class is forbidden.', 'alnp-facebook-pixel-tracking' ), self::$version );
}
/**
* The Constructor.
*
* @access public
* @since 1.0.0
* @version 2.0.0
*/
public function __construct() {
$this->constants();
$this->includes();
add_action( 'plugins_loaded', array( $this, 'load_textdomain' ), 99 );
add_action( 'wp_enqueue_scripts', array( $this, 'alnp_enqueue_scripts' ) );
}
/**
* Setup plugin constants.
*
* @access private
* @since 2.0.0
* @return void
*/
private function constants() {
$this->define( 'ALNP_FB_PIXEL_VERSION', self::$version );
$this->define( 'ALNP_FB_PIXEL_ALNP_REQUIRED', self::$required_alnp );
$this->define( 'ALNP_FB_PIXEL_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
$this->define( 'ALNP_FB_PIXEL_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
$this->define( 'ALNP_FB_PIXEL_PLUGIN_FILE', __FILE__ );
$this->define( 'ALNP_FB_PIXEL_PLUGIN_BASE', plugin_basename( __FILE__ ) );
$this->define( 'ALNP_FB_PIXEL_SUPPORT_URL', 'https://wordpress.org/support/plugin/alnp-facebook-pixel-tracking' );
$this->define( 'ALNP_FB_PIXEL_REVIEW_URL', 'https://wordpress.org/support/plugin/alnp-facebook-pixel-tracking/reviews/' );
}
/**
* Define constant if not already set.
*
* @access private
* @since 2.0.0
* @param string|string $name Name of the definition.
* @param string|bool $value Default value.
*/
private function define( $name, $value ) {
if ( ! defined( $name ) ) {
define( $name, $value );
}
}
/**
* Include required files.
*
* @access private
* @since 2.0.0
* @return void
*/
private function includes() {
if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) {
require_once( ALNP_FB_PIXEL_PLUGIN_DIR . 'includes/admin/alnp-facebook-pixel-tracking-admin.php' );
}
}
/**
* Load the plugin text domain once the plugin has initialized.
*
* @access public
* @since 1.0.0
* @version 2.0.0
* @return void
*/
public function load_textdomain() {
load_plugin_textdomain( 'alnp-facebook-pixel-tracking', false, dirname( plugin_basename( ALNP_FB_PIXEL_PLUGIN_DIR ) ) . '/languages/' );
}
/**
* Load JS only on the front end for a single post.
*
* @access public
* @since 1.0.0
* @return void
*/
public function alnp_enqueue_scripts() {
if ( is_singular() && in_array( get_post_type(), $this->allowed_post_types() ) ) {
wp_register_script( 'alnp-facebook-pixel-tracking', ALNP_FB_PIXEL_PLUGIN_URL . '/assets/js/alnp-facebook-pixel-tracking.js', array( 'jquery' ), self::$version );
wp_enqueue_script( 'alnp-facebook-pixel-tracking' );
wp_localize_script( 'alnp-facebook-pixel-tracking', 'alnp_fb_pixel', array(
'alnpVersion' => AUTO_LOAD_NEXT_POST_VERSION,
'pluginVersion' => self::$version,
));
}
}
/**
* Returns allowed post types to track page views.
*
* @access public
* @since 1.0.0
* @return array
*/
public function allowed_post_types() {
return array( 'post' );
}
} // END class
} // END if class exists
return ALNP_FB_Pixel_Tracking::instance();