PluginProbe
Wp Tracking Codes / 1.5.0
Wp Tracking Codes v1.5.0
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
wp-tracking-codes / includes / class-register-codes.php

class-register-codes.php in Wp Tracking Codes 1.5.0, at includes/class-register-codes.php

273 lines 13.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Wp Tracking Register Codes class
4 *
5 * @package WooCommerc/Classes/API
6 * @version 2.11.0
7 */
8
9 if ( ! defined( 'ABSPATH' ) ) {
10 exit;
11 }
12
13 class RegisterCodes extends Wp_Tracking_Codes{
14 /**
15 * Holds the values to be used in the fields callbacks
16 */
17 private $options;
18
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 }
41
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 }
50
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_settings_section(
65 'google_merchant_section',
66 '',
67 array( $this, 'google_merchant_section_callback_function' ),
68 'wp-tracking-codes'
69 );
70 // Add the field with the names and function to use for our new
71 // settings, put it in our new section
72 add_settings_field(
73 'tracking_analytics_4',
74 'Google Analytics 4 <div class="title-section"></div>',
75 array( $this, 'tracking_analytics4_callback_function' ),
76 'wp-tracking-codes',
77 'tracking_section'
78 );
79 add_settings_field(
80 'tracking_analytics',
81 'Google Analytics UA',
82 array( $this, 'tracking_analytics_callback_function' ),
83 'wp-tracking-codes',
84 'tracking_section'
85 );
86 add_settings_field(
87 'tracking_analytics_remarketing',
88 'Google ADS Remarketing Conversion ID',
89 array( $this, 'tracking_analytics_remarketing_callback_function' ),
90 'wp-tracking-codes',
91 'tracking_section'
92 );
93 add_settings_field(
94 'tracking_facebook_pixel_code',
95 'Facebook Pixel ID',
96 array( $this, 'tracking_facebook_pixel_code_callback_function' ),
97 'wp-tracking-codes',
98 'tracking_section'
99 );
100 add_settings_field(
101 'tracking_google_tag_manager',
102 'Google Tag Manager ID',
103 array( $this, 'tracking_google_tag_manager_callback_function' ),
104 'wp-tracking-codes',
105 'tracking_section'
106 );
107 // settings checkbox
108 add_settings_field(
109 'data_layer_google_tag_manager',
110 'DataLayer Google Tag Manager',
111 array( $this, 'data_layer_google_tag_manager_callback_function' ),
112 'wp-tracking-codes',
113 'google_merchant_section'
114 );
115 add_settings_field(
116 'tracking_google_merchant',
117 'Google Merchant ID - Customer Reviews',
118 array( $this, 'tracking_google_merchant_callback_function' ),
119 'wp-tracking-codes',
120 'google_merchant_section'
121 );
122 add_settings_field(
123 'tracking_google_merchant_estimative_delivery_days',
124 'Google Merchant Estimative Delivery Days - Customer Reviews',
125 array( $this, 'tracking_google_merchant_estimative_delivery_days_callback_function' ),
126 'wp-tracking-codes',
127 'google_merchant_section'
128 );
129
130
131 // Register our setting so that $_POST handling is done for us and
132 // our callback function just has to echo the <input>
133 register_setting(
134 'wp-tracking-codes', // Option group
135 'tracking_option', // Option name
136 array( $this, 'sanitize' ) // Sanitize
137 );
138
139 }
140
141 /**
142 * Sanitize each setting field as needed
143 *
144 * @param array $input Contains all settings fields as array keys
145 */
146 public function sanitize( $input )
147 {
148 $new_input = array();
149 if( isset( $input['analytics'] ) )
150 $new_input['analytics'] = sanitize_text_field( $input['analytics'] );
151 if( isset( $input['analytics_4'] ) )
152 $new_input['analytics_4'] = sanitize_text_field( $input['analytics_4'] );
153 if( isset( $input['analytics_remarketing'] ) )
154 $new_input['analytics_remarketing'] = sanitize_text_field( $input['analytics_remarketing'] );
155 if( isset( $input['facebook_pixel_code'] ) )
156 $new_input['facebook_pixel_code'] = sanitize_text_field( $input['facebook_pixel_code'] );
157 if( isset( $input['google_tag_manager'] ) )
158 $new_input['google_tag_manager'] = sanitize_text_field( $input['google_tag_manager'] );
159 if( isset( $input['google_merchant'] ) )
160 $new_input['google_merchant'] = sanitize_text_field( $input['google_merchant'] );
161 if( isset( $input['google_merchant_estimative_delivery_days'] ) )
162 $new_input['google_merchant_estimative_delivery_days'] = sanitize_text_field( $input['google_merchant_estimative_delivery_days'] );
163 if( isset( $input['data_layer_google_tag_manager'] ) )
164 $new_input['data_layer_google_tag_manager'] = sanitize_text_field( $input['data_layer_google_tag_manager'] );
165 return $new_input;
166 }
167 /**
168 * Print the Section text
169 */
170 public function tracking_section_callback_function()
171 {
172 // print 'For all:';
173 }
174 /**
175 * Print the Section text
176 */
177 public function google_merchant_section_callback_function()
178 {
179 print '<div class="title-section-">Only Woocomerce:</div>';
180 }
181 /**
182 * Get the settings option array and print one of its values
183 */
184 public function tracking_analytics_callback_function()
185 {
186 printf(
187 '<input type="text" id="analytics" name="tracking_option[analytics]"/ value="%s">
188 <div class="status" title="Running"><span class="dashicons %s"></span></span></div>
189 <p class="description">Example: UA-XXXXXXXX-X - <a href="https://support.google.com/analytics/answer/1032385" target="_blank">Help me</a></p>',
190 isset( $this->options['analytics'] ) ? esc_attr( $this->options['analytics']) : '',
191 isset( $this->options['analytics'] ) && !empty($this->options['analytics']) ? 'dashicons-yes' : ''
192 );
193 }
194
195 public function tracking_analytics4_callback_function()
196 {
197 printf(
198 '<input type="text" id="analytics_4" name="tracking_option[analytics_4]"/ value="%s">
199 <div class="status" title="Running"><span class="dashicons %s"></span></span></div>
200 <p class="description">Example: G-XXXXXXXXXX - <a href="https://support.google.com/analytics/answer/10089681" target="_blank">Help me</a></p>',
201 isset( $this->options['analytics_4'] ) ? esc_attr( $this->options['analytics_4']) : '',
202 isset( $this->options['analytics_4'] ) && !empty($this->options['analytics_4']) ? 'dashicons-yes' : ''
203 );
204 }
205
206
207 public function tracking_analytics_remarketing_callback_function()
208 {
209 printf(
210 '<input type="text" id="analytics_remarketing" name="tracking_option[analytics_remarketing]"/ value="%s">
211 <div class="status" title="Running"><span class="dashicons %s"></span></span></div>
212 <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>',
213 isset( $this->options['analytics_remarketing'] ) ? esc_attr( $this->options['analytics_remarketing']) : '',
214 isset( $this->options['analytics_remarketing'] ) && !empty($this->options['analytics_remarketing']) ? 'dashicons-yes' : ''
215 );
216 }
217 public function tracking_facebook_pixel_code_callback_function()
218 {
219 printf(
220 '<input type="text" id="facebook_pixel_code" name="tracking_option[facebook_pixel_code]"/ value="%s">
221 <div class="status" title="Running"><span class="dashicons %s"></span></span></div>
222 <p class="description">Example: 1234567890 - <a href="https://www.facebook.com/business/help/742478679120153/?ref=u2u" target="_blank">Help me</a></p>',
223 isset( $this->options['facebook_pixel_code'] ) ? esc_attr( $this->options['facebook_pixel_code']) : '',
224 isset( $this->options['facebook_pixel_code'] ) && !empty($this->options['facebook_pixel_code']) ? 'dashicons-yes' : ''
225 );
226 }
227 public function tracking_google_tag_manager_callback_function()
228 {
229 printf(
230 '<input type="text" id="google_tag_manager" name="tracking_option[google_tag_manager]"/ value="%s">
231 <div class="status" title="Running"><span class="dashicons %s"></span></span></div>
232 <p class="description">Example: GTM-XXXXXX - <a href="https://support.google.com/tagmanager/answer/6103696" target="_blank">Help me</a></p>',
233 isset( $this->options['google_tag_manager'] ) ? esc_attr( $this->options['google_tag_manager']) : '',
234 isset( $this->options['google_tag_manager'] ) && !empty($this->options['google_tag_manager']) ? 'dashicons-yes' : ''
235 );
236 }
237 public function tracking_google_merchant_callback_function()
238 {
239 printf(
240 '<input type="text" id="google_merchant" name="tracking_option[google_merchant]"/ value="%s">
241 <div class="status" title="Running"><span class="dashicons %s"></span></span></div>
242 <p class="description">Example: 123456789 - <a href="https://support.google.com/paymentscenter/answer/7163092?hl=en" target="_blank">Help me</a> <br/> This function activates <a href="https://support.google.com/merchants/answer/190657?hl=en" target="_blank">Seller ratings</a> on the purchase page. <a href="https://support.google.com/merchants/answer/7124018?hl=en&ref_topic=7105048" target="_blank">How it works?</a></p>',
243 isset( $this->options['google_merchant'] ) ? esc_attr( $this->options['google_merchant']) : '',
244 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' : ''
245 );
246 }
247 public function tracking_google_merchant_estimative_delivery_days_callback_function()
248 {
249 printf(
250 '<input type="text" id="google_merchant_estimative_delivery_days" name="tracking_option[google_merchant_estimative_delivery_days]"/ value="%s"> days
251 <div class="status" title="Running"><span class="dashicons %s"></span></span></div>
252 <p class="description">Example: 9 - The estimated average <b>number</b> of delivery days for all orders</p>
253 <p class="description">This number added to the order day will be the date that Google will send the survey to the user\'s email, if user allows. <a href="https://support.google.com/merchants/answer/7106244?hl=en&ref_topic=7105160&visit_id=637233659345484301-2826177191&rd=1" target="_blank">How it works?</a></p>',
254 isset( $this->options['google_merchant_estimative_delivery_days'] ) ? esc_attr( $this->options['google_merchant_estimative_delivery_days']) : '',
255 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' : ''
256 );
257 }
258 public function data_layer_google_tag_manager_callback_function($args)
259 {
260 $options = get_option('tracking_option');
261 $checked = ( isset($options['data_layer_google_tag_manager']) && $options['data_layer_google_tag_manager'] == 1) ? 1 : 0;
262 printf(
263 '<input type="checkbox" id="data_layer_google_tag_manager" name="tracking_option[data_layer_google_tag_manager]" value="1"' . checked( 1, $checked, false ) . '/>
264 <p class="description">Activate to use datalayer with <a href="https://support.google.com/tagmanager/answer/6107169?hl=en#standard-ecommerce" target="_blank">Standard Ecommerce (UA)</a> - <a href="https://support.google.com/tagmanager/answer/6164391?hl=en" target="_blank">Help me</a></p>',
265 isset( $this->options['data_layer_google_tag_manager'] ) ? esc_attr( $this->options['data_layer_google_tag_manager']) : ''
266 );
267
268 }
269 }
270
271 if( is_admin() )
272 $RegisterCodes = new RegisterCodes();
273