-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoptions.php
293 lines (271 loc) · 9.53 KB
/
options.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
<?php
/**
* Option page definition
*
* @package friendly-automate
*/
// Prevent direct access to this file.
if ( ! defined( 'ABSPATH' ) ) {
header( 'HTTP/1.0 403 Forbidden' );
echo 'This file should not be accessed directly!';
exit; // Exit if accessed directly.
}
/**
* HTML for the Friendly option page
*/
function friendlyautomate_options_page() {
?>
<div>
<h2><?php esc_html_e( 'Friendly Automate', 'friendly-automate' ); ?></h2>
<p><?php esc_html_e( 'Add Friendly Automate tracking capabilities to your website.', 'friendly-automate' ); ?></p>
<form action="options.php" method="post">
<?php settings_fields( 'friendlyautomate' ); ?>
<?php do_settings_sections( 'friendlyautomate' ); ?>
<?php submit_button(); ?>
</form>
<h3><?php esc_html_e( 'Shortcode Examples:', 'friendly-automate' ); ?></h3>
<ul>
<li><?php esc_html_e( 'Friendly Form Embed:', 'friendly-automate' ); ?> <code>[friendlyautomate type="form" id="1"]</code></li>
<li><?php esc_html_e( 'Friendly Dynamic Content:', 'friendly-automate' ); ?> <code>[friendlyautomate type="content" slot="slot_name"]<?php esc_html_e( 'Default Text', 'friendly-automate' ); ?>[/friendlyautomate]</code></li>
</ul>
<h3><?php esc_html_e( 'Quick Links', 'friendly-automate' ); ?></h3>
<ul>
<li>
<a href="https://friendly.ch/contact" target="_blank"><?php esc_html_e( 'Plugin support', 'friendly-automate' ); ?></a>
</li>
<li>
<a href="https://calendly.com/friendly-ch/automate-training" target="_blank"><?php esc_html_e( 'Book a free, individual training session', 'friendly-automate' ); ?></a>
</li>
<li>
<a href="https://mautic.org" target="_blank"><?php esc_html_e( 'We\'re based on Mautic', 'friendly-automate' ); ?></a>
</li>
<li>
<a href="https://github.com/mautic/mautic-wordpress#mautic-wordpress-plugin" target="_blank"><?php esc_html_e( 'Plugin docs', 'friendly-automate' ); ?></a>
</li>
</ul>
</div>
<?php
}
/**
* Define admin_init hook logic
*/
function friendlyautomate_admin_init() {
register_setting( 'friendlyautomate', 'friendlyautomate_options', 'friendlyautomate_options_validate' );
add_settings_section(
'friendlyautomate_main',
__( 'Main Settings', 'friendly-automate' ),
'friendlyautomate_section_text',
'friendlyautomate'
);
add_settings_field(
'friendlyautomate_base_url',
__( 'Friendly Automate URL', 'friendly-automate' ),
'friendlyautomate_base_url',
'friendlyautomate',
'friendlyautomate_main'
);
add_settings_field(
'friendlyautomate_script_location',
__( 'Tracking script location', 'friendly-automate' ),
'friendlyautomate_script_location',
'friendlyautomate',
'friendlyautomate_main'
);
add_settings_field(
'friendlyautomate_fallback_activated',
__( 'Tracking image', 'friendly-automate' ),
'friendlyautomate_fallback_activated',
'friendlyautomate',
'friendlyautomate_main'
);
add_settings_field(
'friendlyautomate_track_tags_categories',
__( 'Tags and Category tracking', 'friendly-automate' ),
'friendlyautomate_track_tags_categories',
'friendlyautomate',
'friendlyautomate_main'
);
add_settings_field(
'friendlyautomate_track_logged_user',
__( 'Logged user', 'friendly-automate' ),
'friendlyautomate_track_logged_user',
'friendlyautomate',
'friendlyautomate_main'
);
}
add_action( 'admin_init', 'friendlyautomate_admin_init' );
/**
* Section text
*/
function friendlyautomate_section_text() {
}
/**
* Define the input field for Friendly base URL
*/
function friendlyautomate_base_url() {
$url = friendlyautomate_option( 'base_url', '' );
?>
<input
id="friendlyautomate_base_url"
name="friendlyautomate_options[base_url]"
size="40"
type="text"
placeholder="https://..."
value="<?php echo esc_url_raw( $url, array( 'http', 'https' ) ); ?>"
/>
<?php
}
/**
* Define the input field for Friendly script location
*/
function friendlyautomate_script_location() {
$position = friendlyautomate_option( 'script_location', '' );
$allowed_tags = array(
'br' => array(),
'code' => array(),
);
?>
<fieldset id="friendlyautomate_script_location">
<label>
<input
type="radio"
name="friendlyautomate_options[script_location]"
value="header"
<?php
if ( 'footer' !== $position && 'disabled' !== $position ) :
?>
checked<?php endif; ?>
/>
<?php echo wp_kses( __( 'Added in the <code>wp_head</code> action.<br/>Inserts the tracking code before the <code><head></code> tag; can be slightly slower since page load is delayed until all scripts in <code><head></code> are loaded and processed.', 'friendly-automate' ), $allowed_tags ); ?>
</label>
<br/>
<label>
<input
type="radio"
name="friendlyautomate_options[script_location]"
value="footer"
<?php
if ( 'footer' === $position ) :
?>
checked<?php endif; ?>
/>
<?php echo wp_kses( __( 'Embedded within the <code>wp_footer</code> action.<br/>Inserts the tracking code before the <code></body></code> tag; slightly better for performance but may track less reliably if users close the page before the script has loaded.', 'friendly-automate' ), $allowed_tags ); ?>
</label>
<br />
<label>
<input
type="radio"
name="friendlyautomate_options[script_location]"
value="disabled"
<?php
if ( 'disabled' === $position ) :
?>
checked<?php endif; ?>
/>
<?php echo wp_kses( __( 'Visitor will not be tracked when rendering the page. Use this option to comply with GDPR regulations. If the visitor accept cookies you must execute the <code>friendlyautomate_send()</code> JavaScript function to start tracking.', 'friendly-automate' ), $allowed_tags ); ?>
<br/>
<?php echo wp_kses( __( 'However when using shortcodes, a tracking cookie will be added everytime even when tracking is disabled. This is because loading a Friendly Automate resource (javascript or image) generates that cookie.', 'friendly-automate' ), $allowed_tags ); ?>
</label>
</fieldset>
<?php
}
/**
* Define the input field for Friendly fallback flag
*/
function friendlyautomate_fallback_activated() {
$flag = friendlyautomate_option( 'fallback_activated', false );
$allowed_tags = array(
'br' => array(),
'code' => array(),
);
?>
<input
id="friendlyautomate_fallback_activated"
name="friendlyautomate_options[fallback_activated]"
type="checkbox"
value="1"
<?php
if ( true === $flag ) :
?>
checked<?php endif; ?>
/>
<label for="friendlyautomate_fallback_activated">
<?php esc_html_e( 'Activate the tracking image when JavaScript is disabled.', 'friendly-automate' ); ?>
<br/>
<?php echo wp_kses( __( 'Be warned, that the tracking image will always generate a cookie on the user browser side. If you want to control cookies and comply to GDPR, you must use JavaScript instead.', 'friendly-automate' ), $allowed_tags ); ?>
</label>
<?php
}
/**
* Define the input field for Friendly category & tag tracking
*/
function friendlyautomate_track_tags_categories() {
$flag = friendlyautomate_option( 'tag_category_tracking', false );
?>
<input
id="friendlyautomate_tag_category_tracking"
name="friendlyautomate_options[tag_category_tracking]"
type="checkbox"
value="1"
<?php
if ( true === $flag ) :
?>
checked<?php endif; ?>
/>
<label for="friendlyautomate_tag_category_tracking">
<?php esc_html_e( 'Track the tags and categories that your visitors are interested in.', 'friendly-automate' ); ?>
<br/>
<?php esc_html_e( 'This will show add WordPress categories and Tags to your website visitors as a Friendly Automate Tag. For example, if one of your posts has the category "Hosting", Friendly Automate will add this tag to the visitors who land on your post.', 'friendly-automate' ); ?>
</label>
<?php
}
/**
* Define the input field for Friendly logged user tracking flag
*/
function friendlyautomate_track_logged_user() {
$flag = friendlyautomate_option( 'track_logged_user', false );
?>
<input
id="friendlyautomate_track_logged_user"
name="friendlyautomate_options[track_logged_user]"
type="checkbox"
value="1"
<?php
if ( true === $flag ) :
?>
checked<?php endif; ?>
/>
<label for="friendlyautomate_track_logged_user">
<?php esc_html_e( 'Track user information for logged-in users', 'friendly-automate' ); ?>
</label>
<?php
}
/**
* Validate base URL input value
*
* @param array $input Input data.
* @return array
*/
function friendlyautomate_options_validate( $input ) {
$options = get_option( 'friendlyautomate_options' );
$input['base_url'] = isset( $input['base_url'] )
? trim( $input['base_url'], " \t\n\r\0\x0B/" )
: '';
$options['base_url'] = esc_url_raw( trim( $input['base_url'], " \t\n\r\0\x0B/" ) );
$options['script_location'] = isset( $input['script_location'] )
? trim( $input['script_location'] )
: 'header';
if ( ! in_array( $options['script_location'], array( 'header', 'footer', 'disabled' ), true ) ) {
$options['script_location'] = 'header';
}
$options['fallback_activated'] = isset( $input['fallback_activated'] ) && '1' === $input['fallback_activated']
? true
: false;
$options['tag_category_tracking'] = isset( $input['tag_category_tracking'] ) && '1' === $input['tag_category_tracking']
? true
: false;
$options['track_logged_user'] = isset( $input['track_logged_user'] ) && '1' === $input['track_logged_user']
? true
: false;
return $options;
}