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

168 lines 6.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 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 );
101
102 }
103
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 }
164 }
165
166 if( is_admin() )
167 $RegisterCodes = new RegisterCodes();
168