PluginProbe
Wp Tracking Codes / 1.4.1
Wp Tracking Codes v1.4.1
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.4.1, at includes/class-register-codes.php

251 lines 12.0 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',
74 'Google Analytics UA',
75 array( $this, 'tracking_analytics_callback_function' ),
76 'wp-tracking-codes',
77 'tracking_section'
78 );
79 add_settings_field(
80 'tracking_analytics_remarketing',
81 'Google Remarketing Conversion ID',
82 array( $this, 'tracking_analytics_remarketing_callback_function' ),
83 'wp-tracking-codes',
84 'tracking_section'
85 );
86 add_settings_field(
87 'tracking_facebook_pixel_code',
88 'Facebook Pixel ID',
89 array( $this, 'tracking_facebook_pixel_code_callback_function' ),
90 'wp-tracking-codes',
91 'tracking_section'
92 );
93 add_settings_field(
94 'tracking_google_tag_manager',
95 'Google Tag Manager ID',
96 array( $this, 'tracking_google_tag_manager_callback_function' ),
97 'wp-tracking-codes',
98 'tracking_section'
99 );
100 // settings checkbox
101 add_settings_field(
102 'data_layer_google_tag_manager',
103 'DataLayer Google Tag Manager',
104 array( $this, 'data_layer_google_tag_manager_callback_function' ),
105 'wp-tracking-codes',
106 'google_merchant_section'
107 );
108 add_settings_field(
109 'tracking_google_merchant',
110 'Google Merchant ID - Customer Reviews',
111 array( $this, 'tracking_google_merchant_callback_function' ),
112 'wp-tracking-codes',
113 'google_merchant_section'
114 );
115 add_settings_field(
116 'tracking_google_merchant_estimative_delivery_days',
117 'Google Merchant Estimative Delivery Days - Customer Reviews',
118 array( $this, 'tracking_google_merchant_estimative_delivery_days_callback_function' ),
119 'wp-tracking-codes',
120 'google_merchant_section'
121 );
122
123
124 // Register our setting so that $_POST handling is done for us and
125 // our callback function just has to echo the <input>
126 register_setting(
127 'wp-tracking-codes', // Option group
128 'tracking_option', // Option name
129 array( $this, 'sanitize' ) // Sanitize
130 );
131
132 }
133
134 /**
135 * Sanitize each setting field as needed
136 *
137 * @param array $input Contains all settings fields as array keys
138 */
139 public function sanitize( $input )
140 {
141 $new_input = array();
142 if( isset( $input['analytics'] ) )
143 $new_input['analytics'] = sanitize_text_field( $input['analytics'] );
144 if( isset( $input['analytics_remarketing'] ) )
145 $new_input['analytics_remarketing'] = sanitize_text_field( $input['analytics_remarketing'] );
146 if( isset( $input['facebook_pixel_code'] ) )
147 $new_input['facebook_pixel_code'] = sanitize_text_field( $input['facebook_pixel_code'] );
148 if( isset( $input['google_tag_manager'] ) )
149 $new_input['google_tag_manager'] = sanitize_text_field( $input['google_tag_manager'] );
150 if( isset( $input['google_merchant'] ) )
151 $new_input['google_merchant'] = sanitize_text_field( $input['google_merchant'] );
152 if( isset( $input['google_merchant_estimative_delivery_days'] ) )
153 $new_input['google_merchant_estimative_delivery_days'] = sanitize_text_field( $input['google_merchant_estimative_delivery_days'] );
154 if( isset( $input['data_layer_google_tag_manager'] ) )
155 $new_input['data_layer_google_tag_manager'] = sanitize_text_field( $input['data_layer_google_tag_manager'] );
156 return $new_input;
157 }
158 /**
159 * Print the Section text
160 */
161 public function tracking_section_callback_function()
162 {
163 // print 'For all:';
164 }
165 /**
166 * Print the Section text
167 */
168 public function google_merchant_section_callback_function()
169 {
170 print '<div class="title-section">Only Woocomerce:</div>';
171 }
172 /**
173 * Get the settings option array and print one of its values
174 */
175 public function tracking_analytics_callback_function()
176 {
177 printf(
178 '<input type="text" id="analytics" name="tracking_option[analytics]"/ value="%s">
179 <div class="status" title="Running"><span class="dashicons %s"></span></span></div>
180 <p class="description">Example: UA-XXXXXXXX-X - <a href="https://support.google.com/analytics/answer/1032385" target="_blank">Help me</a></p>',
181 isset( $this->options['analytics'] ) ? esc_attr( $this->options['analytics']) : '',
182 isset( $this->options['analytics'] ) && !empty($this->options['analytics']) ? 'dashicons-yes' : ''
183 );
184 }
185 public function tracking_analytics_remarketing_callback_function()
186 {
187 printf(
188 '<input type="text" id="analytics_remarketing" name="tracking_option[analytics_remarketing]"/ value="%s">
189 <div class="status" title="Running"><span class="dashicons %s"></span></span></div>
190 <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>',
191 isset( $this->options['analytics_remarketing'] ) ? esc_attr( $this->options['analytics_remarketing']) : '',
192 isset( $this->options['analytics_remarketing'] ) && !empty($this->options['analytics_remarketing']) ? 'dashicons-yes' : ''
193 );
194 }
195 public function tracking_facebook_pixel_code_callback_function()
196 {
197 printf(
198 '<input type="text" id="facebook_pixel_code" name="tracking_option[facebook_pixel_code]"/ value="%s">
199 <div class="status" title="Running"><span class="dashicons %s"></span></span></div>
200 <p class="description">Example: 1234567890 - <a href="https://www.facebook.com/business/help/742478679120153/?ref=u2u" target="_blank">Help me</a></p>',
201 isset( $this->options['facebook_pixel_code'] ) ? esc_attr( $this->options['facebook_pixel_code']) : '',
202 isset( $this->options['facebook_pixel_code'] ) && !empty($this->options['facebook_pixel_code']) ? 'dashicons-yes' : ''
203 );
204 }
205 public function tracking_google_tag_manager_callback_function()
206 {
207 printf(
208 '<input type="text" id="google_tag_manager" name="tracking_option[google_tag_manager]"/ value="%s">
209 <div class="status" title="Running"><span class="dashicons %s"></span></span></div>
210 <p class="description">Example: GTM-XXXXXX - <a href="https://support.google.com/tagmanager/answer/6103696" target="_blank">Help me</a></p>',
211 isset( $this->options['google_tag_manager'] ) ? esc_attr( $this->options['google_tag_manager']) : '',
212 isset( $this->options['google_tag_manager'] ) && !empty($this->options['google_tag_manager']) ? 'dashicons-yes' : ''
213 );
214 }
215 public function tracking_google_merchant_callback_function()
216 {
217 printf(
218 '<input type="text" id="google_merchant" name="tracking_option[google_merchant]"/ value="%s">
219 <div class="status" title="Running"><span class="dashicons %s"></span></span></div>
220 <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>',
221 isset( $this->options['google_merchant'] ) ? esc_attr( $this->options['google_merchant']) : '',
222 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' : ''
223 );
224 }
225 public function tracking_google_merchant_estimative_delivery_days_callback_function()
226 {
227 printf(
228 '<input type="text" id="google_merchant_estimative_delivery_days" name="tracking_option[google_merchant_estimative_delivery_days]"/ value="%s"> days
229 <div class="status" title="Running"><span class="dashicons %s"></span></span></div>
230 <p class="description">Example: 9 - The estimated average <b>number</b> of delivery days for all orders</p>
231 <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>',
232 isset( $this->options['google_merchant_estimative_delivery_days'] ) ? esc_attr( $this->options['google_merchant_estimative_delivery_days']) : '',
233 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' : ''
234 );
235 }
236 public function data_layer_google_tag_manager_callback_function($args)
237 {
238 $options = get_option('tracking_option');
239 $checked = ( isset($options['data_layer_google_tag_manager']) && $options['data_layer_google_tag_manager'] == 1) ? 1 : 0;
240 printf(
241 '<input type="checkbox" id="data_layer_google_tag_manager" name="tracking_option[data_layer_google_tag_manager]" value="1"' . checked( 1, $checked, false ) . '/>
242 <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>',
243 isset( $this->options['data_layer_google_tag_manager'] ) ? esc_attr( $this->options['data_layer_google_tag_manager']) : ''
244 );
245
246 }
247 }
248
249 if( is_admin() )
250 $RegisterCodes = new RegisterCodes();
251