-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.php
465 lines (369 loc) · 12 KB
/
functions.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
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
<?php
// Add a new menu item under the Settings page
function snn_add_submenu_page()
{
add_submenu_page(
'options-general.php',
'SNN Settings',
'SNN Settings',
'manage_options',
'snn-settings',
'snn_settings_page_callback'
);
}
add_action('admin_menu', 'snn_add_submenu_page');
// Callback function for the SNN Settings page
function snn_settings_page_callback()
{
?>
<div class="wrap">
<h1>SNN Bricks Builder Child Theme Settings</h1>
<form method="post" action="options.php">
<?php
settings_fields('snn_settings_group');
do_settings_sections('snn-settings');
submit_button();
?>
</form>
</div>
<?php
}
// Register settings and add settings sections and fields
function snn_register_settings()
{
register_setting('snn_settings_group', 'snn_settings');
add_settings_section(
'snn_general_section',
'Enable or Disable Settings Depending on Your Project Needs and Requirements',
'snn_general_section_callback',
'snn-settings'
);
add_settings_field(
'snn_remove_wp_version',
'Remove WP Version',
'snn_remove_wp_version_callback',
'snn-settings',
'snn_general_section'
);
add_settings_field(
'snn_remove_wp_version_description',
'',
'snn_remove_wp_version_description_callback',
'snn-settings',
'snn_general_section'
);
add_settings_field(
'snn_disable_xmlrpc',
'Disable XML-RPC',
'snn_disable_xmlrpc_callback',
'snn-settings',
'snn_general_section'
);
add_settings_field(
'snn_disable_xmlrpc_description',
'',
'snn_disable_xmlrpc_description_callback',
'snn-settings',
'snn_general_section'
);
add_settings_field(
'snn_remove_rss',
'Remove RSS',
'snn_remove_rss_callback',
'snn-settings',
'snn_general_section'
);
add_settings_field(
'snn_remove_rss_description',
'',
'snn_remove_rss_description_callback',
'snn-settings',
'snn_general_section'
);
add_settings_field(
'snn_login_error_message',
'Login Error Message',
'snn_login_error_message_callback',
'snn-settings',
'snn_general_section'
);
add_settings_field(
'snn_login_error_message_description',
'',
'snn_login_error_message_description_callback',
'snn-settings',
'snn_general_section'
);
add_settings_field(
'snn_auto_update_bricks',
'Auto Update Bricks Theme',
'snn_auto_update_bricks_callback',
'snn-settings',
'snn_general_section'
);
add_settings_field(
'snn_auto_update_bricks_description',
'',
'snn_auto_update_bricks_description_callback',
'snn-settings',
'snn_general_section'
);
add_settings_field(
'snn_enqueue_gsap',
'Enable GSAP',
'snn_enqueue_gsap_callback',
'snn-settings',
'snn_general_section'
);
add_settings_field(
'snn_enqueue_gsap_description',
'',
'snn_enqueue_gsap_description_callback',
'snn-settings',
'snn_general_section'
);
}
add_action('admin_init', 'snn_register_settings');
// Callback functions for settings sections and fields
function snn_general_section_callback()
{
echo ' <br><br>';
}
function snn_remove_wp_version_callback()
{
$options = get_option('snn_settings');
?>
<input type="checkbox" name="snn_settings[remove_wp_version]" value="1" <?php checked(isset($options['remove_wp_version']), 1); ?>>
<?php
}
function snn_remove_wp_version_description_callback()
{
?>
<p>Enabling this setting will remove the WordPress version number from your website's HTML source code. This can help improve security by making it more difficult for potential attackers to determine which version of WordPress your site is running.</p>
<style>
/*
CUSTOM STYLES for PAGE
*/
.form-table td {
padding: 0;
}
.form-table th {
padding: 0;
}
p {
padding-bottom: 20px;
}
.wrap {
max-width: 1000px;
}
</style>
<?php
}
function snn_disable_xmlrpc_callback()
{
$options = get_option('snn_settings');
?>
<input type="checkbox" name="snn_settings[disable_xmlrpc]" value="1" <?php checked(isset($options['disable_xmlrpc']), 1); ?>>
<?php
}
function snn_disable_xmlrpc_description_callback()
{
?>
<p>Enabling this setting will disable the XML-RPC functionality in WordPress. XML-RPC is a remote procedure call protocol that allows external services to interact with your WordPress site. Disabling it can help improve security by preventing unauthorized access.</p>
<?php
}
function snn_remove_rss_callback()
{
$options = get_option('snn_settings');
?>
<input type="checkbox" name="snn_settings[remove_rss]" value="1" <?php checked(isset($options['remove_rss']), 1); ?>>
<?php
}
function snn_remove_rss_description_callback()
{
?>
<p>Enabling this setting will remove the RSS feed links from your website's HTML source code. If you don't plan to use RSS feeds on your site, removing these links can help reduce clutter and improve performance.</p>
<?php
}
function snn_login_error_message_callback()
{
$options = get_option('snn_settings');
?>
<input type="text" name="snn_settings[login_error_message]" value="<?php echo esc_attr($options['login_error_message'] ?? ''); ?>">
<?php
}
function snn_login_error_message_description_callback()
{
?>
<p>This setting allows you to customize the error message displayed when a user enters incorrect login credentials. By default, WordPress provides a generic error message. Customizing this message can help improve security by making it more difficult for potential attackers to determine valid usernames.</p>
<?php
}
function snn_auto_update_bricks_callback()
{
$options = get_option('snn_settings');
?>
<input type="checkbox" name="snn_settings[auto_update_bricks]" value="1" <?php checked(isset($options['auto_update_bricks']), 1); ?>>
<?php
}
function snn_auto_update_bricks_description_callback()
{
?>
<p>Enabling this setting will automatically update the Bricks theme whenever a new version is available. Keeping your theme up to date is important for security and functionality. However, it's recommended to test updates on a staging site before applying them to your live site.</p>
<?php
}
function snn_enqueue_gsap_callback()
{
$options = get_option('snn_settings');
?>
<input type="checkbox" name="snn_settings[enqueue_gsap]" value="1" <?php checked(isset($options['enqueue_gsap']), 1); ?>>
<?php
}
function snn_enqueue_gsap_description_callback()
{
?>
<h2>GSAP</h2>
<p>Enabling this setting will enqueue the GSAP library and its associated scripts on your website. GSAP is a powerful JavaScript animation library that allows you to create complex and interactive animations.</p>
<ul>
<li><code>gsap.min.js</code>: The core GSAP library.</li>
<li><code>ScrollTrigger.min.js</code>: A GSAP plugin that enables scroll-based animations.</li>
<li><code>gsap-data-animate.js</code>: A custom script that utilizes GSAP and ScrollTrigger for animating elements based on data attributes.</li>
</ul>
<style>
.tt1 {
width: 880px;
height: 60px
}
</style>
<br><br>
<p>This example will animate the element by fading it in from the left. The element will start with an x-offset of -50 pixels and an opacity of 0.</p>
<textarea class="tt1"><h1 data-animate="x:-50, o:0, start:top 80%, end:bottom 20%">Welcome to my website!</h1></textarea>
<br><br>
<p>In this example, the div element will scale up from 0.5 to 1 and rotate by 180 degrees. The animation will start when the element is 60% from the top of the viewport and end when it reaches 40% from the bottom.</p>
<textarea class="tt1"><div data-animate="s:0.5, r:180, start:top 60%, end:bottom 40%, scrub:true">Lorem ipsum dolor sit amet.</div></textarea>
<br><br>
<ul>
<li><b>x</b>: Horizontal position (e.g., <b>x: 100</b>).</li>
<li><b>y</b>: Vertical position (e.g., <b>y: -50</b>).</li>
<li><b>o</b>: Opacity (e.g., <b>o: 0.5</b>).</li>
<li><b>r</b>: Rotation angle (e.g., <b>r: 45</b>).</li>
<li><b>s</b>: Scale (e.g., <b>s: 0.8</b>).</li>
<li><b>start</b>: Scroll trigger start position (e.g., <b>start: top 20%</b>).</li>
<li><b>end</b>: Scroll trigger end position (e.g., <b>end: bottom 80%</b>).</li>
<li><b>scrub</b>: Scrubbing behavior (e.g., <b>scrub: true</b>).</li>
<li><b>pin</b>: Pin element during scroll (e.g., <b>pin: true</b>).</li>
<li><b>markers</b>: Display scroll trigger markers (e.g., <b>markers: true</b>).</li>
<li><b>toggleClass</b>: Toggle CSS class (e.g., <b>toggleClass: active</b>).</li>
<li><b>pinSpacing</b>: Spacing behavior when pinning (e.g., <b>pinSpacing: margin</b>).</li>
<li><b>splittext</b>: Split text into characters (e.g., <b>splittext: true</b>).</li>
<li><b>stagger</b>: Stagger delay between characters (e.g., <b>stagger: 0.05</b>).</li>
</ul>
<br><br>
<?php
}
// Functions to handle the settings
function remove_wp_version()
{
$options = get_option('snn_settings');
if (isset($options['remove_wp_version'])) {
return '';
}
}
add_filter('the_generator', 'remove_wp_version');
function disable_xmlrpc($enabled)
{
$options = get_option('snn_settings');
if (isset($options['disable_xmlrpc'])) {
return false;
}
return $enabled;
}
add_filter('xmlrpc_enabled', 'disable_xmlrpc');
function remove_rss()
{
$options = get_option('snn_settings');
if (isset($options['remove_rss'])) {
remove_action('wp_head', 'rsd_link');
remove_action('wp_head', 'feed_links', 2);
remove_action('wp_head', 'feed_links_extra', 3);
remove_action('wp_head', 'wlwmanifest_link');
}
}
add_action('init', 'remove_rss');
function failed_login_message()
{
$options = get_option('snn_settings');
$message = $options['login_error_message'] ?? 'Incorrect, please try again';
return $message;
}
add_filter('login_errors', 'failed_login_message');
// Auto Update Bricks Theme
function auto_update_bricks_theme($update, $item)
{
$options = get_option('snn_settings');
if (isset($options['auto_update_bricks']) && $item->theme == 'bricks') {
return true;
}
return $update;
}
add_filter('auto_update_theme', 'auto_update_bricks_theme', 10, 2);
// Enqueue GSAP scripts
function enqueue_gsap_scripts()
{
$options = get_option('snn_settings');
if (isset($options['enqueue_gsap'])) {
wp_enqueue_script('gsap-js', get_stylesheet_directory_uri() . '/js/gsap.min.js', array(), false, true);
wp_enqueue_script('gsap-st-js', get_stylesheet_directory_uri() . '/js/ScrollTrigger.min.js', array('gsap-js'), false, true);
wp_enqueue_script('gsap-data-js', get_stylesheet_directory_uri() . '/js/gsap-data-animate.js?v0.01', array(), false, true);
}
}
add_action('wp_enqueue_scripts', 'enqueue_gsap_scripts');
// Move Bricks Menu to End of the wp-admin menu list
function custom_menu_order($menu_ord)
{
if (!$menu_ord) return true;
// Identify the index of 'bricks'
foreach ($menu_ord as $index => $item) {
if ($item == 'bricks') {
$bricks_menu = $item;
unset($menu_ord[$index]);
break;
}
}
// Append 'bricks' to the end
if (isset($bricks_menu)) {
$menu_ord[] = $bricks_menu;
}
return $menu_ord;
}
add_filter('menu_order', 'custom_menu_order');
add_filter('custom_menu_order', function () {
return true;
}); // Activate custom_menu_order
/**
* Register/enqueue custom scripts and styles
*/
add_action('wp_enqueue_scripts', function () {
// Enqueue your files on the canvas & frontend, not the builder panel. Otherwise custom CSS might affect builder)
if (!bricks_is_builder_main()) {
wp_enqueue_style('bricks-child', get_stylesheet_uri(), ['bricks-frontend'], filemtime(get_stylesheet_directory() . '/style.css'));
}
});
/**
* Register custom elements
*/
add_action('init', function () {
$element_files = [
__DIR__ . '/elements/title.php',
];
foreach ($element_files as $file) {
\Bricks\Elements::register_element($file);
}
}, 11);
/**
* Add text strings to builder
*/
add_filter('bricks/builder/i18n', function ($i18n) {
// For element category 'custom'
$i18n['custom'] = esc_html__('Custom', 'bricks');
return $i18n;
});