PluginProbe
Wp Tracking Codes / trunk
Wp Tracking Codes vtrunk
trunk 1.0 1.0.1 1.0.2 1.0.3 1.0.4 1.1.0 1.1.0, 1.10.0 1.2.0 1.3.0 1.3.1 1.3.2 1.3.3 1.4.0 1.4.1 1.5.0 1.6.0 1.7.0 1.8.0 1.9.0 1.9.1 1.9.2 1.9.3
← All changes | includes/class-register-codes.php +361 -150 1.0trunk View file →
@@ -6,162 +6,373 @@
6 6 * @version 2.11.0
7 7 */
8 8
9 9 if ( ! defined( 'ABSPATH' ) ) {
10 - exit;
10 + exit;
11 11 }
12 12
13 -class RegisterCodes extends Wp_Tracking_Codes{
14 - /**
15 - * Holds the values to be used in the fields callbacks
16 - */
17 - private $options;
13 +if ( ! class_exists( 'RegisterCodes' ) ) :
14 + class RegisterCodes{
15 + /**
16 + * Holds the values to be used in the fields callbacks
17 + */
18 + private $options;
18 19
19 - /**
20 - * Start up
21 - */
22 - public function __construct()
23 - {
24 - add_action( 'admin_menu', array( $this, 'add_submenu_page' ) );
25 - add_action( 'admin_init', array( $this, 'page_init' ) );
26 - }
27 - /**
28 - * Add options page
29 - */
30 - public function add_submenu_page()
31 - {
32 - add_submenu_page(
33 - 'options-general.php', // admin page slug
34 - __( 'WP Tracking Codes', 'wptc' ), // page title
35 - __( 'WP Tracking Codes', 'wptc' ), // menu title
36 - 'manage_options', // capability required to see the page
37 - 'wp-tracking-codes', // admin page slug, e.g. options-general.php?page=wporg_options
38 - array( $this, 'create_admin_page' ) // callback function to display the options page
39 - );
40 - }
20 + /**
21 + * Instance of this class.
22 + *
23 + * @var object
24 + */
25 + protected static $instance = null;
41 26
42 - /**
43 - * Options page callback
44 - */
45 - public function create_admin_page()
46 - {
47 - $this->options = get_option( 'tracking_option' );
48 - include 'admin/views/html-admin-page.php';
49 - }
27 + /**
28 + * Start up
29 + */
30 + private function __construct()
31 + {
32 + add_action( 'admin_menu', array( $this, 'add_submenu_page' ) );
33 + add_action( 'admin_init', array( $this, 'page_init' ) );
34 + }
50 35
51 - /**
52 - * Register and add settings
53 - */
54 - public function page_init()
55 - {
56 - // Add the section to reading settings so we can add our
57 - // fields to it
58 - add_settings_section(
59 - 'tracking_section',
60 - '',
61 - array( $this, 'tracking_section_callback_function' ),
62 - 'wp-tracking-codes'
63 - );
64 - // Add the field with the names and function to use for our new
65 - // settings, put it in our new section
66 - add_settings_field(
67 - 'tracking_analytics',
68 - 'Google Analytics UA',
69 - array( $this, 'tracking_analytics_callback_function' ),
70 - 'wp-tracking-codes',
71 - 'tracking_section'
72 - );
73 - add_settings_field(
74 - 'tracking_analytics_remarketing',
75 - 'Google Remarketing Conversion ID',
76 - array( $this, 'tracking_analytics_remarketing_callback_function' ),
77 - 'wp-tracking-codes',
78 - 'tracking_section'
79 - );
80 - add_settings_field(
81 - 'tracking_facebook_pixel_code',
82 - 'Facebook Pixel ID',
83 - array( $this, 'tracking_facebook_pixel_code_callback_function' ),
84 - 'wp-tracking-codes',
85 - 'tracking_section'
86 - );
87 - add_settings_field(
88 - 'tracking_google_tag_manager',
89 - 'Google Tag Manager ID',
90 - array( $this, 'tracking_google_tag_manager_callback_function' ),
91 - 'wp-tracking-codes',
92 - 'tracking_section'
93 - );
94 - // Register our setting so that $_POST handling is done for us and
95 - // our callback function just has to echo the <input>
96 - register_setting(
97 - 'wp-tracking-codes', // Option group
98 - 'tracking_option', // Option name
99 - array( $this, 'sanitize' ) // Sanitize
100 - );
36 + /**
37 + * Return an instance of this class.
38 + *
39 + * @return object A single instance of this class.
40 + */
41 + public static function get_instance() {
42 + // If the single instance hasn't been set, set it now.
43 + if ( null === self::$instance ) {
44 + self::$instance = new self();
45 + }
101 46
102 - }
47 + return self::$instance;
48 + }
103 49
104 - /**
105 - * Sanitize each setting field as needed
106 - *
107 - * @param array $input Contains all settings fields as array keys
108 - */
109 - public function sanitize( $input )
110 - {
111 - $new_input = array();
112 - if( isset( $input['analytics'] ) )
113 - $new_input['analytics'] = sanitize_text_field( $input['analytics'] );
114 - if( isset( $input['analytics_remarketing'] ) )
115 - $new_input['analytics_remarketing'] = sanitize_text_field( $input['analytics_remarketing'] );
116 - if( isset( $input['facebook_pixel_code'] ) )
117 - $new_input['facebook_pixel_code'] = sanitize_text_field( $input['facebook_pixel_code'] );
118 - if( isset( $input['google_tag_manager'] ) )
119 - $new_input['google_tag_manager'] = sanitize_text_field( $input['google_tag_manager'] );
120 - return $new_input;
121 - }
122 - /**
123 - * Print the Section text
124 - */
125 - public function tracking_section_callback_function()
126 - {
127 - //print 'Enter your settings below:';
128 - }
129 - /**
130 - * Get the settings option array and print one of its values
131 - */
132 - public function tracking_analytics_callback_function()
133 - {
134 - printf(
135 - '<input type="text" id="analytics" name="tracking_option[analytics]"/ value="%s">
136 - <p class="description">Example: UA-XXXXXXXX-X - <a href="https://support.google.com/analytics/answer/1032385" target="_blank">Help me</a></p>',
137 - isset( $this->options['analytics'] ) ? esc_attr( $this->options['analytics']) : ''
138 - );
139 - }
140 - public function tracking_analytics_remarketing_callback_function()
141 - {
142 - printf(
143 - '<input type="text" id="analytics_remarketing" name="tracking_option[analytics_remarketing]"/ value="%s">
144 - <p class="description">Example: 123456789 - <a href="https://support.google.com/tagmanager/answer/6105160?hl=en&ref_topic=6334091" target="_blank">Help me</a></p>',
145 - isset( $this->options['analytics_remarketing'] ) ? esc_attr( $this->options['analytics_remarketing']) : ''
146 - );
147 - }
148 - public function tracking_facebook_pixel_code_callback_function()
149 - {
150 - printf(
151 - '<input type="text" id="facebook_pixel_code" name="tracking_option[facebook_pixel_code]"/ value="%s">
152 - <p class="description">Example: 1234567890 - <a href="https://www.facebook.com/business/help/742478679120153/?ref=u2u" target="_blank">Help me</a></p>',
153 - isset( $this->options['facebook_pixel_code'] ) ? esc_attr( $this->options['facebook_pixel_code']) : ''
154 - );
155 - }
156 - public function tracking_google_tag_manager_callback_function()
157 - {
158 - printf(
159 - '<input type="text" id="google_tag_manager" name="tracking_option[google_tag_manager]"/ value="%s">
160 - <p class="description">Example: GTM-XXXXXX - <a href="https://support.google.com/tagmanager/answer/6103696" target="_blanl">Help me</a></p>',
161 - isset( $this->options['google_tag_manager'] ) ? esc_attr( $this->options['google_tag_manager']) : ''
162 - );
163 - }
50 + /**
51 + * Add options page
52 + */
53 + public function add_submenu_page()
54 + {
55 + add_submenu_page(
56 + 'options-general.php', // admin page slug
57 + __( 'WP Tracking Codes', 'wp-tracking-codes' ), // page title
58 + __( 'WP Tracking Codes', 'wp-tracking-codes' ), // menu title
59 + 'manage_options', // capability required to see the page
60 + 'wp-tracking-codes', // admin page slug, e.g. options-general.php?page=wporg_options
61 + array( $this, 'create_admin_page' ) // callback function to display the options page
62 + );
63 + }
64 +
65 + /**
66 + * Options page callback
67 + */
68 + public function create_admin_page()
69 + {
70 + $this->options = get_option( 'tracking_option' );
71 + include 'admin/views/html-admin-page.php';
72 + }
73 +
74 + /**
75 + * Register and add settings
76 + */
77 + public function page_init()
78 + {
79 + // Add the section to reading settings so we can add our
80 + // fields to it
81 + add_settings_section(
82 + 'tracking_section',
83 + '',
84 + array( $this, 'tracking_section_callback_function' ),
85 + 'wp-tracking-codes'
86 + );
87 + add_settings_section(
88 + 'google_merchant_section',
89 + '',
90 + array( $this, 'google_merchant_section_callback_function' ),
91 + 'wp-tracking-codes'
92 + );
93 + // Add the field with the names and function to use for our new
94 + // settings, put it in our new section
95 + add_settings_field(
96 + 'tracking_google_tag_manager',
97 + 'Google Tag Manager ID',
98 + array( $this, 'tracking_google_tag_manager_callback_function' ),
99 + 'wp-tracking-codes',
100 + 'tracking_section'
101 + );
102 + add_settings_field(
103 + 'tracking_analytics_4',
104 + 'Google Analytics 4 (global tag)',
105 + array( $this, 'tracking_analytics4_callback_function' ),
106 + 'wp-tracking-codes',
107 + 'tracking_section'
108 + );
109 + add_settings_field(
110 + 'tracking_analytics_remarketing',
111 + 'Google ADS (global tag)',
112 + array( $this, 'tracking_analytics_remarketing_callback_function' ),
113 + 'wp-tracking-codes',
114 + 'tracking_section'
115 + );
116 + add_settings_field(
117 + 'tracking_facebook_pixel_code',
118 + 'Facebook Pixel ID',
119 + array( $this, 'tracking_facebook_pixel_code_callback_function' ),
120 + 'wp-tracking-codes',
121 + 'tracking_section'
122 + );
123 + // settings checkbox
124 + add_settings_field(
125 + 'tracking_google_merchant',
126 + 'Google Merchant ID - Customer Reviews',
127 + array( $this, 'tracking_google_merchant_callback_function' ),
128 + 'wp-tracking-codes',
129 + 'google_merchant_section'
130 + );
131 + add_settings_field(
132 + 'tracking_google_merchant_estimative_delivery_days',
133 + 'Google Merchant Estimative Delivery Days - Customer Reviews',
134 + array( $this, 'tracking_google_merchant_estimative_delivery_days_callback_function' ),
135 + 'wp-tracking-codes',
136 + 'google_merchant_section'
137 + );
138 + // Register our setting so that $_POST handling is done for us and
139 + // our callback function just has to echo the <input>
140 + register_setting(
141 + 'wp-tracking-codes', // Option group
142 + 'tracking_option', // Option name
143 + array( $this, 'sanitize' ) // Sanitize
144 + );
145 +
146 + }
147 +
148 + /**
149 + * Sanitize each setting field as needed
150 + *
151 + * @param array $input Contains all settings fields as array keys
152 + */
153 + public function sanitize( $input )
154 + {
155 + $new_input = array();
156 + if( isset( $input['analytics_4'] ) )
157 + $new_input['analytics_4'] = sanitize_text_field( $input['analytics_4'] );
158 + if( isset( $input['analytics_remarketing'] ) )
159 + $new_input['analytics_remarketing'] = sanitize_text_field( $input['analytics_remarketing'] );
160 + if( isset( $input['facebook_pixel_code'] ) )
161 + $new_input['facebook_pixel_code'] = sanitize_text_field( $input['facebook_pixel_code'] );
162 + if( isset( $input['google_tag_manager'] ) )
163 + $new_input['google_tag_manager'] = sanitize_text_field( $input['google_tag_manager'] );
164 + if( isset( $input['google_merchant'] ) )
165 + $new_input['google_merchant'] = sanitize_text_field( $input['google_merchant'] );
166 + if( isset( $input['google_merchant_estimative_delivery_days'] ) )
167 + $new_input['google_merchant_estimative_delivery_days'] = sanitize_text_field( $input['google_merchant_estimative_delivery_days'] );
168 + return $new_input;
169 + }
170 +
171 + /**
172 + * Print the Section text
173 + */
174 + public function tracking_section_callback_function()
175 + {
176 +// print 'For all:';
177 + }
178 +
179 + /**
180 + * Print the Section text
181 + */
182 + public function google_merchant_section_callback_function()
183 + {
184 + print '<div class="title-section-">'.esc_html_e( 'Only WooCommerce:', 'wp-tracking-codes' ).'</div>';
185 +
186 + }
187 +
188 + public function tracking_analytics4_callback_function()
189 + {
190 + printf(
191 + '<input type="text" id="analytics_4" name="tracking_option[analytics_4]"/ value="%s">',
192 + isset( $this->options['analytics_4'] ) ? esc_attr( $this->options['analytics_4']) : ''
193 + );
194 + printf(
195 + '<div class="status" title="Running"><span class="dashicons %s"></span></span></div>',
196 + isset( $this->options['analytics_4'] ) && !empty($this->options['analytics_4']) ? 'dashicons-yes' : ''
197 + );
198 + printf(
199 + '<p class="description">'
200 + );
201 + printf(
202 + /* translators: %1$s: search term */
203 + esc_html__( 'Example: G-XXXXXXXXXX - %1$s', 'wp-tracking-codes' ),
204 + sprintf(
205 + '<a href="%s" target="_blank">%s</a>',
206 + 'https://developers.google.com/tag-platform/devguides/install-gtagjs#google-analytics',
207 + esc_html__( 'Help me', 'wp-tracking-codes' )
208 + )
209 + );
210 + printf(
211 + '</p>'
212 + );
213 + }
214 +
215 + public function tracking_analytics_remarketing_callback_function()
216 + {
217 + printf(
218 + '<input type="text" id="analytics_remarketing" name="tracking_option[analytics_remarketing]"/ value="%s">',
219 + isset( $this->options['analytics_remarketing'] ) ? esc_attr( $this->options['analytics_remarketing']) : ''
220 + );
221 + printf(
222 + '<div class="status" title="Running"><span class="dashicons %s"></span></span></div>',
223 + isset( $this->options['analytics_remarketing'] ) && !empty($this->options['analytics_remarketing']) ? 'dashicons-yes' : ''
224 + );
225 + printf(
226 + '<p class="description">'
227 + );
228 + printf(
229 + /* translators: %1$s: search term */
230 + esc_html__( 'Example: AW-YYYYYY - %1$s', 'wp-tracking-codes' ),
231 + sprintf(
232 + '<a href="%s" target="_blank">%s</a>',
233 + 'https://developers.google.com/tag-platform/devguides/install-gtagjs#google-ads',
234 + esc_html__( 'Help me', 'wp-tracking-codes' )
235 + )
236 + );
237 + printf(
238 + '</p>'
239 + );
240 + }
241 +
242 + public function tracking_facebook_pixel_code_callback_function()
243 + {
244 + printf(
245 + '<input type="text" id="facebook_pixel_code" name="tracking_option[facebook_pixel_code]" value="%s">',
246 + isset( $this->options['facebook_pixel_code'] ) ? esc_attr( $this->options['facebook_pixel_code']) : ''
247 + );
248 + printf(
249 + '<div class="status" title="Running"><span class="dashicons %s"></span></span></div>',
250 + isset( $this->options['facebook_pixel_code'] ) && !empty($this->options['facebook_pixel_code']) ? 'dashicons-yes' : ''
251 + );
252 + printf(
253 + '<p class="description">'
254 + );
255 + printf(
256 + /* translators: %1$s: search term */
257 + esc_html__( 'Example: 1234567890 - %1$s', 'wp-tracking-codes' ),
258 + sprintf(
259 + '<a href="%s" target="_blank">%s</a>',
260 + 'https://www.facebook.com/business/help/742478679120153/',
261 + esc_html__( 'Help me', 'wp-tracking-codes' )
262 + )
263 + );
264 + printf(
265 + '</p>'
266 + );
267 + }
268 +
269 + public function tracking_google_tag_manager_callback_function()
270 + {
271 + printf(
272 + '<input type="text" id="google_tag_manager" name="tracking_option[google_tag_manager]" value="%s">',
273 + isset( $this->options['google_tag_manager'] ) ? esc_attr( $this->options['google_tag_manager']) : ''
274 + );
275 + printf(
276 + '<div class="status" title="Running"><span class="dashicons %s"></span></span></div>',
277 + isset( $this->options['google_tag_manager'] ) && !empty($this->options['google_tag_manager']) ? 'dashicons-yes' : ''
278 + );
279 + printf(
280 + '<p class="description">'
281 + );
282 + printf(
283 + /* translators: %1$s: search term */
284 + esc_html__( 'Example: GTM-XXXXXX - %1$s', 'wp-tracking-codes' ),
285 + sprintf(
286 + '<a href="%s" target="_blank">%s</a>',
287 + 'https://support.google.com/tagmanager/answer/6103696',
288 + esc_html__( 'Help me', 'wp-tracking-codes' )
289 + )
290 + );
291 + printf(
292 + '</p>'
293 + );
294 + }
295 +
296 + public function tracking_google_merchant_callback_function()
297 + {
298 + printf(
299 + '<input type="text" id="google_merchant" name="tracking_option[google_merchant]" value="%s">',
300 + isset( $this->options['google_merchant'] ) ? esc_attr( $this->options['google_merchant']) : ''
301 + );
302 + printf(
303 + '<div class="status" title="Running"><span class="dashicons %s"></span></span></div>',
304 + isset( $this->options['google_merchant'] ) && !empty($this->options['google_merchant']) && isset( $this->options['google_merchant_estimative_delivery_days'] ) && !empty($this->options['google_merchant_estimative_delivery_days']) ? 'dashicons-yes' : ''
305 + );
306 + printf(
307 + '<p class="description">'
308 + );
309 + printf(
310 + /* translators: %1$s: search term */
311 + esc_html__( 'Example: 123456789 - %1$s', 'wp-tracking-codes' ),
312 + sprintf(
313 + '<a href="%s" target="_blank">%s</a><br/>',
314 + 'https://support.google.com/paymentscenter/answer/7163092?hl=en',
315 + esc_html__( 'Help me', 'wp-tracking-codes' )
316 + )
317 + );
318 + printf(
319 + /* translators: %1$s: search term */
320 + esc_html__( 'This function activates %1$s', 'wp-tracking-codes' ),
321 + sprintf(
322 + '<a href="%s" target="_blank">%s</a>',
323 + 'https://support.google.com/merchants/answer/190657?hl=en',
324 + esc_html__( 'Seller ratings', 'wp-tracking-codes' )
325 + )
326 + );
327 + printf(
328 + /* translators: %1$s: search term */
329 + esc_html__( ' on the purchase page - %1$s', 'wp-tracking-codes' ),
330 + sprintf(
331 + '<a href="%s" target="_blank">%s</a>',
332 + 'https://support.google.com/merchants/answer/7124018?hl=en&ref_topic=7105048',
333 + esc_html__( 'Help me', 'wp-tracking-codes' )
334 + )
335 + );
336 + printf(
337 + '</p>'
338 + );
339 + }
340 +
341 + public function tracking_google_merchant_estimative_delivery_days_callback_function()
342 + {
343 + printf(
344 + '<input type="text" id="google_merchant_estimative_delivery_days" name="tracking_option[google_merchant_estimative_delivery_days]" value="%s">',
345 + isset( $this->options['google_merchant_estimative_delivery_days'] ) ? esc_attr( $this->options['google_merchant_estimative_delivery_days']) : ''
346 + );
347 + printf(
348 + esc_html__(' days','wp-tracking-codes')
349 + );
350 + printf(
351 + '<div class="status" title="Running"><span class="dashicons %s"></span></span></div>',
352 + isset( $this->options['google_merchant'] ) && !empty($this->options['google_merchant']) && isset( $this->options['google_merchant_estimative_delivery_days'] ) && !empty($this->options['google_merchant_estimative_delivery_days']) ? 'dashicons-yes' : ''
353 + );
354 + printf(
355 + '<p class="description">'.esc_html__( 'Example: 9 - The estimated average number of delivery days for all orders', 'wp-tracking-codes' ).'</p>'
356 + );
357 + printf(
358 + '<p class="description">'
359 + );
360 + printf(
361 + /* translators: %1$s: search term */
362 + esc_html__( 'This number added to the order day will be the date that Google will send the survey to the user email, if user allows - %1$s', 'wp-tracking-codes' ),
363 + sprintf(
364 + '<a href="%s" target="_blank">%s</a>',
365 + 'https://support.google.com/merchants/answer/7106244?hl=en&ref_topic=7105160&visit_id=637233659345484301-2826177191&rd=1',
366 + esc_html__( 'How it works?', 'wp-tracking-codes' )
367 + )
368 + );
369 + printf(
370 + '</p>'
371 + );
372 + }
373 + }
374 +endif;
375 +
376 +if( is_admin() ){
377 + RegisterCodes::get_instance();
164 378 }
165 -
166 -if( is_admin() )
167 - $RegisterCodes = new RegisterCodes();