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

191 lines 7.5 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 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 // settings checkbox
95 add_settings_field(
96 'data_layer_google_tag_manager',
97 'DataLayer Google Tag Manager for Woocommerce',
98 array( $this, 'data_layer_google_tag_manager_callback_function' ),
99 'wp-tracking-codes',
100 'tracking_section'
101 );
102
103
104 // Register our setting so that $_POST handling is done for us and
105 // our callback function just has to echo the <input>
106 register_setting(
107 'wp-tracking-codes', // Option group
108 'tracking_option', // Option name
109 array( $this, 'sanitize' ) // Sanitize
110 );
111
112 }
113
114 /**
115 * Sanitize each setting field as needed
116 *
117 * @param array $input Contains all settings fields as array keys
118 */
119 public function sanitize( $input )
120 {
121 $new_input = array();
122 if( isset( $input['analytics'] ) )
123 $new_input['analytics'] = sanitize_text_field( $input['analytics'] );
124 if( isset( $input['analytics_remarketing'] ) )
125 $new_input['analytics_remarketing'] = sanitize_text_field( $input['analytics_remarketing'] );
126 if( isset( $input['facebook_pixel_code'] ) )
127 $new_input['facebook_pixel_code'] = sanitize_text_field( $input['facebook_pixel_code'] );
128 if( isset( $input['google_tag_manager'] ) )
129 $new_input['google_tag_manager'] = sanitize_text_field( $input['google_tag_manager'] );
130 if( isset( $input['data_layer_google_tag_manager'] ) )
131 $new_input['data_layer_google_tag_manager'] = sanitize_text_field( $input['data_layer_google_tag_manager'] );
132 return $new_input;
133 }
134 /**
135 * Print the Section text
136 */
137 public function tracking_section_callback_function()
138 {
139 //print 'Enter your settings below:';
140 }
141 /**
142 * Get the settings option array and print one of its values
143 */
144 public function tracking_analytics_callback_function()
145 {
146 printf(
147 '<input type="text" id="analytics" name="tracking_option[analytics]"/ value="%s">
148 <p class="description">Example: UA-XXXXXXXX-X - <a href="https://support.google.com/analytics/answer/1032385" target="_blank">Help me</a></p>',
149 isset( $this->options['analytics'] ) ? esc_attr( $this->options['analytics']) : ''
150 );
151 }
152 public function tracking_analytics_remarketing_callback_function()
153 {
154 printf(
155 '<input type="text" id="analytics_remarketing" name="tracking_option[analytics_remarketing]"/ value="%s">
156 <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>',
157 isset( $this->options['analytics_remarketing'] ) ? esc_attr( $this->options['analytics_remarketing']) : ''
158 );
159 }
160 public function tracking_facebook_pixel_code_callback_function()
161 {
162 printf(
163 '<input type="text" id="facebook_pixel_code" name="tracking_option[facebook_pixel_code]"/ value="%s">
164 <p class="description">Example: 1234567890 - <a href="https://www.facebook.com/business/help/742478679120153/?ref=u2u" target="_blank">Help me</a></p>',
165 isset( $this->options['facebook_pixel_code'] ) ? esc_attr( $this->options['facebook_pixel_code']) : ''
166 );
167 }
168 public function tracking_google_tag_manager_callback_function()
169 {
170 printf(
171 '<input type="text" id="google_tag_manager" name="tracking_option[google_tag_manager]"/ value="%s">
172 <p class="description">Example: GTM-XXXXXX - <a href="https://support.google.com/tagmanager/answer/6103696" target="_blanl">Help me</a></p>',
173 isset( $this->options['google_tag_manager'] ) ? esc_attr( $this->options['google_tag_manager']) : ''
174 );
175 }
176 public function data_layer_google_tag_manager_callback_function($args)
177 {
178 $options = get_option('tracking_option');
179 $checked = ( isset($options['data_layer_google_tag_manager']) && $options['data_layer_google_tag_manager'] == 1) ? 1 : 0;
180 printf(
181 '<input type="checkbox" id="data_layer_google_tag_manager" name="tracking_option[data_layer_google_tag_manager]" value="1"' . checked( 1, $checked, false ) . '/>
182 <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="_blanl">Help me</a></p>',
183 isset( $this->options['data_layer_google_tag_manager'] ) ? esc_attr( $this->options['data_layer_google_tag_manager']) : ''
184 );
185
186 }
187 }
188
189 if( is_admin() )
190 $RegisterCodes = new RegisterCodes();
191