-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathfunctions.php
More file actions
534 lines (451 loc) · 19.9 KB
/
functions.php
File metadata and controls
534 lines (451 loc) · 19.9 KB
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
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
<?php
/**
* Anima functions and definitions
*
* @package Anima
*/
if ( ! function_exists( 'anima_setup' ) ) {
/**
* Sets up theme defaults and registers support for various WordPress features.
*
* Note that this function is hooked into the after_setup_theme hook, which
* runs before the init hook. The init hook is too late for some features, such
* as indicating support for post thumbnails.
*/
function anima_setup() {
/**
* Make theme available for translation.
* Translations can be filed in the /languages/ directory.
* If you're building a theme based on Nova, use a find and replace
* to change '__theme_txtd' to the name of your theme in all the template files.
*/
load_theme_textdomain( '__theme_txtd', get_template_directory() . '/languages' );
// Add default posts and comments RSS feed links to head.
add_theme_support( 'automatic-feed-links' );
/**
* Let WordPress manage the document title.
* By adding theme support, we declare that this theme does not use a
* hard-coded <title> tag in the document head, and expect WordPress to
* provide it for us.
*/
add_theme_support( 'title-tag' );
/**
* Enable support for Post Thumbnails.
*
* @link https://developer.wordpress.org/themes/functionality/featured-images-post-thumbnails/
*/
add_theme_support( 'post-thumbnails' );
// TODO: Re-enable gallery, link, audio, and video once LT ships their blueprint cards and single-template routing.
add_theme_support( 'post-formats', [ 'quote', 'image' ] );
/**
* Switch default core markup for search form, comment form, and comments
* to output valid HTML5.
*/
add_theme_support( 'html5', [
'search-form',
'comment-form',
'comment-list',
'gallery',
'caption',
] );
// This theme uses wp_nav_menu() in one location.
register_nav_menus( [
'primary' => esc_html__( 'Primary Menu', '__theme_txtd' ),
'secondary' => esc_html__( 'Secondary Menu', '__theme_txtd' ),
'tertiary' => esc_html__( 'Tertiary Menu', '__theme_txtd' ),
'site-frame' => esc_html__( 'Site Frame', '__theme_txtd' ),
'search-suggestions' => esc_html__( 'Search Suggestions', '__theme_txtd' ),
] );
// Add theme support for selective refresh for widgets.
add_theme_support( 'customize-selective-refresh-widgets' );
/**
* Add support for core custom logo.
*
* @link https://codex.wordpress.org/Theme_Logo
*/
add_theme_support( 'custom-logo', [
'height' => 250,
'width' => 250,
'flex-width' => true,
'flex-height' => true,
'header-text' => [
'site-title',
'site-description',
]
] );
add_image_size( 'anima-site-logo', 250, 250, false );
add_theme_support( 'align-wide' );
/**
* Enable editor styles so the Post Editor uses an iframe
* (matching the Site Editor) for proper CSS isolation.
*/
add_theme_support( 'editor-styles' );
/**
* Add theme support for responsive embeds
*/
add_theme_support( 'responsive-embeds' );
/**
* Enable support for the Style Manager Customizer section.
*/
add_theme_support( 'customizer_style_manager' );
add_theme_support( 'style_manager_font_palettes' );
add_theme_support( 'style_manager_advanced_dark_mode' );
/**
* Remove Theme support for Core Block Patterns.
*/
remove_theme_support( 'core-block-patterns' );
/**
* Use 'wp_template' posts instead of theme template files.
*
* This support is automatically added by wp_enable_block_templates() but we add it also to be more upfront.
*/
add_theme_support( 'block-templates' );
}
}
add_action( 'after_setup_theme', 'anima_setup', 10 );
/**
* Register widget area.
*
* @since Anima 1.10.0
*
* @link https://developer.wordpress.org/themes/functionality/sidebars/#registering-a-sidebar
*
* @return void
*/
function anima_widgets_init() {
register_sidebar(
[
'name' => esc_html__( 'Article Sidebar', '__theme_txtd' ),
'id' => 'sidebar-1',
'description' => esc_html__( 'Add widgets here to appear next to your articles.', '__theme_txtd' ),
'before_widget' => '<section id="%1$s" class="widget %2$s">',
'after_widget' => '</section>',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
]
);
}
add_action( 'widgets_init', 'anima_widgets_init' );
function anima_register_assets() {
$theme = wp_get_theme( get_template() );
$suffix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min';
wp_register_style( 'anima-custom-properties', trailingslashit( get_template_directory_uri() ) . 'dist/css/custom-properties.css', [], $theme->get( 'Version' ) );
wp_register_style( 'anima-social-links', trailingslashit( get_template_directory_uri() ) . 'dist/css/social-links.css', [], $theme->get( 'Version' ) );
wp_register_style( 'anima-theme', trailingslashit( get_template_directory_uri() ) . 'dist/css/theme/style.css', [], $theme->get( 'Version' ) );
wp_register_style( 'anima-theme-components', trailingslashit( get_template_directory_uri() ) . 'dist/css/theme/components.css', [], $theme->get( 'Version' ) );
wp_register_style( 'anima-utility', trailingslashit( get_template_directory_uri() ) . 'dist/css/utility.css', [], $theme->get( 'Version' ) );
wp_register_style('anima-novablocks-conversations', trailingslashit( get_template_directory_uri() ) . 'dist/css/blocks/nova-blocks/conversations.css', [], '1.8.0');
wp_register_style( 'anima-blocks-common', trailingslashit( get_template_directory_uri() ) . 'dist/css/blocks/common.css', [], $theme->get( 'Version' ) );
wp_register_style( 'anima-blocks-editor', trailingslashit( get_template_directory_uri() ) . 'dist/css/blocks/editor.css', [ 'anima-blocks-common' ], $theme->get( 'Version' ) );
wp_register_style( 'anima-blocks-style', trailingslashit( get_template_directory_uri() ) . 'dist/css/blocks/style.css', [ 'anima-blocks-common' ], $theme->get( 'Version' ) );
wp_register_style( 'anima-block-editor-styles', trailingslashit( get_template_directory_uri() ) . 'dist/css/block-editor.css', [
'anima-custom-properties',
'anima-theme-components',
'anima-blocks-editor',
'anima-utility',
], $theme->get( 'Version' ) );
wp_style_add_data( 'anima-theme', 'rtl', 'replace' );
wp_style_add_data( 'anima-theme-components', 'rtl', 'replace' );
// Use the public CDN for better performance
// (high likelihood the file is already cached in the browser from other sites).
wp_register_script( 'gsap', 'https://cdnjs.cloudflare.com/ajax/libs/gsap/3.9.1/gsap.min.js', [], null, true );
// Add the SRI (Subresource Integrity) hash data.
// Generated with https://www.srihash.org/
wp_script_add_data( 'gsap', 'integrity', 'sha384-lI86CGWNchoT9leGBpVR41iGrRTRbHRDsPI4Zo/atPOIodjl8YyDaVefcpgkCg4u');
wp_script_add_data( 'gsap', 'crossorigin', 'anonymous');
// Use our private CDN since GSAP premium plugins can't be distributed in the bundle.
wp_register_script( 'gsap-split-text', '//pxgcdn.com/js/gsap/3.9.1/SplitText.min.js', [], null, true );
// Add the SRI (Subresource Integrity) hash data.
// Generated with https://www.srihash.org/
wp_script_add_data( 'gsap-split-text', 'integrity', 'sha384-KoviLFAFGG+n+c3BxM58Gr/poK7WAtzed6kU8Kzr2fvjp3Q8gttOWY+XvpTjShW3');
wp_script_add_data( 'gsap-split-text', 'crossorigin', 'anonymous');
// Snap.svg — required for Slide Wipe transition's SVG pattern fills.
wp_register_script( 'snapsvg', 'https://cdnjs.cloudflare.com/ajax/libs/snap.svg/0.5.1/snap.svg-min.js', [], '0.5.1', true );
wp_register_script( 'anima-app', trailingslashit( get_template_directory_uri() ) . 'dist/js/scripts' . $suffix . '.js', [ 'jquery', 'gsap', 'gsap-split-text', 'hoverIntent', 'imagesloaded' ], $theme->get( 'Version' ), true );
$page_transitions_deps = [ 'jquery', 'gsap', 'anima-app' ];
$logo_loading_style = get_option( 'sm_logo_loading_style', 'progress_bar' );
if ( 'cycling_images' === $logo_loading_style ) {
$page_transitions_deps[] = 'snapsvg';
}
wp_register_script( 'anima-page-transitions', trailingslashit( get_template_directory_uri() ) . 'dist/js/page-transitions' . $suffix . '.js', $page_transitions_deps, $theme->get( 'Version' ), true );
}
add_action( 'init', 'anima_register_assets', 10 );
function anima_enqueue_theme_block_editor_assets() {
$theme = wp_get_theme( get_template() );
$suffix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min';
wp_enqueue_style( 'anima-block-editor-styles' );
wp_enqueue_script(
'anima-editor-js',
trailingslashit( get_template_directory_uri() ) . 'dist/js/editor' . $suffix . '.js',
[ 'wp-hooks' ],
$theme->get( 'Version' ),
true
);
}
add_action( 'enqueue_block_editor_assets', 'anima_enqueue_theme_block_editor_assets', 10 );
function anima_enqueue_assets() {
$theme = wp_get_theme( get_template() );
$used_blocks = [ 'media' ];
foreach( $used_blocks as $block ) {
if ( ! anima_is_using_block( $block, true ) ) {
wp_enqueue_style('novablocks/' . $block );
}
}
wp_enqueue_style( 'anima-style', get_template_directory_uri() . '/style.css', [
'anima-social-links',
'anima-custom-properties',
'anima-theme',
'anima-theme-components',
'anima-blocks-style',
'anima-utility',
], $theme->get( 'Version' ) );
wp_style_add_data( 'anima-style', 'rtl', 'replace' );
wp_localize_script( 'anima-app', 'style_manager_values', [
'sm_site_color_variation' => pixelgrade_option( 'sm_site_color_variation', 1 )
] );
wp_enqueue_script( 'anima-app' );
// Load Conversation CSS only when we need it:
// 1. Comments are open.
// 2. When there are comments on a post and the conversation has been closed.
if ( is_singular() && ( comments_open() || ! comments_open() && get_comments_number() > 0 ) ) {
wp_enqueue_style('anima-novablocks-conversations');
if ( get_option( 'thread_comments' ) ) {
wp_enqueue_script( 'comment-reply' );
}
}
}
add_action( 'wp_enqueue_scripts', 'anima_enqueue_assets', 20 );
/**
* Provide fallback webfonts for when the Style Manager plugin is not active.
*
* @return void
*/
function anima_webfonts_fallback() {
if ( class_exists( 'PixCustomifyPlugin' ) || function_exists( '\Pixelgrade\StyleManager\plugin') ) {
return;
}
ob_start(); ?>
var config = {
classes: true,
events: true,
custom: {
families: [
'Reforma1969',
'Reforma2018',
'Billy Ohio',
],
urls: [
'//pxgcdn.com/fonts/reforma1969/stylesheet.css',
'//pxgcdn.com/fonts/reforma2018/stylesheet.css',
'//pxgcdn.com/fonts/billy-ohio/stylesheet.css',
],
},
loading: function() {
jQuery( window ).trigger( 'wf-loading' );
},
active: function() {
jQuery( window ).trigger( 'wf-active' );
},
inactive: function() {
jQuery( window ).trigger( 'wf-inactive' );
},
};
WebFont.load( config );
<?php $webfontloader_inline_script = ob_get_clean();
wp_register_script( 'webfontloader', '//ajax.googleapis.com/ajax/libs/webfont/1.6.26/webfont.js', [ 'jquery' ], null, true );
wp_add_inline_script( 'webfontloader', $webfontloader_inline_script );
wp_enqueue_script( 'webfontloader' );
}
add_action( 'wp_enqueue_scripts', 'anima_webfonts_fallback', 10 );
function anima_print_scripts() {
// The `beforeunload` handler below fades the body out to opacity 0 by
// re-adding the `.is-loading` class on every navigation. With Page
// Transitions ENABLED this only kicks in on hard refreshes and external
// links — Barba intercepts normal link clicks, so beforeunload doesn't
// fire. With Page Transitions DISABLED every link click fades the page
// out, which reads as an implicit page transition the user didn't opt
// into. Gate the handler on the PT toggle: keep the FOUT-preventing
// fade-in on DOMContentLoaded unconditionally (universally useful),
// skip the fade-out when PT is off so navigation feels crisp.
$page_transitions_enabled = function_exists( 'anima_page_transitions_enabled' )
? anima_page_transitions_enabled()
: (bool) get_option( 'sm_page_transitions_enable', false );
ob_start(); ?>
<script>
window.addEventListener( "DOMContentLoaded", function( event ) {
document.body.classList.remove( "is-loading" );
document.body.classList.add( "has-loaded" );
} );
<?php if ( $page_transitions_enabled ) : ?>
function animaIsUndefined( target ) {
return typeof target === "undefined" || target === null;
}
function animaShouldCancelFadeOut( e ) {
if ( animaIsUndefined( e.target ) ||
animaIsUndefined( e.target.activeElement ) ||
animaIsUndefined( e.target.activeElement ) ||
animaIsUndefined( e.target.activeElement.getAttribute( 'href' ) ) ) {
return false;
}
var href = e.target.activeElement.getAttribute( 'href' );
var isMail = typeof href === 'string' && href.indexOf( 'mailto:' ) === 0;
var isTel = typeof href === 'string' && href.indexOf( 'tel:' ) === 0;
return isMail || isTel;
}
window.addEventListener( "beforeunload", function( event ) {
if ( ! animaShouldCancelFadeOut( event ) ) {
document.body.classList.add( "is-loading" );
}
} );
<?php endif; ?>
// Fix Safari bfcache: page stays invisible on back/swipe-back navigation.
// Safari's Back-Forward Cache restores the DOM state (with "is-loading" class
// applied by the beforeunload handler) but does not re-fire DOMContentLoaded,
// so the page remains at opacity: 0. The pageshow event with persisted=true
// fires only on bfcache restore — not on initial load — so the reveal
// animation is preserved for first visits.
window.addEventListener( "pageshow", function( event ) {
if ( event.persisted ) {
// Restore body visibility (undo the beforeunload fade-out).
document.body.classList.remove( "is-loading" );
document.body.classList.add( "has-loaded" );
// Force hero elements visible. CSS sets opacity: 0 on hero content
// by default — GSAP overrides this with inline opacity: 1 during
// the intro animation. We must SET opacity to 1 (not remove it),
// otherwise elements fall back to the CSS opacity: 0.
var heroes = document.querySelectorAll(
'.nb-supernova--card-layout-stacked.nb-supernova--1-columns.nb-supernova--align-full,' +
'.novablocks-hero'
);
heroes.forEach( function( hero ) {
var containers = hero.querySelectorAll(
'.novablocks-hero__inner-container,' +
'.nb-supernova-item__inner-container'
);
containers.forEach( function( container ) {
var els = container.querySelectorAll( '*' );
els.forEach( function( el ) {
el.style.opacity = '1';
el.style.removeProperty( 'transform' );
} );
} );
var mediaWrappers = hero.querySelectorAll( '.nb-supernova-item__media-wrapper' );
mediaWrappers.forEach( function( el ) {
el.style.opacity = '1';
} );
} );
// Trigger scroll recalculation so GSAP hero animations
// sync to the current scroll position.
window.dispatchEvent( new Event( "scroll" ) );
}
} );
</script>
<?php echo ob_get_clean();
}
add_action( 'wp_print_scripts', 'anima_print_scripts', 10 );
/* Automagical updates */
function wupdates_check_QBAXY( $transient ) {
// First get the theme directory name (the theme slug - unique)
$slug = basename( get_template_directory() );
// Nothing to do here if the checked transient entry is empty or if we have already checked
if ( empty( $transient->checked ) || empty( $transient->checked[ $slug ] ) || ! empty( $transient->response[ $slug ] ) ) {
return $transient;
}
// Let's start gathering data about the theme
// Then WordPress version
include( ABSPATH . WPINC . '/version.php' );
$http_args = [
'body' => [
'slug' => $slug,
'url' => home_url( '/' ), //the site's home URL
'version' => 0,
'locale' => get_locale(),
'phpv' => phpversion(),
'child_theme' => is_child_theme(),
'data' => null, //no optional data is sent by default
],
'user-agent' => 'WordPress/' . $wp_version . '; ' . home_url( '/' )
];
// If the theme has been checked for updates before, get the checked version
if ( isset( $transient->checked[ $slug ] ) && $transient->checked[ $slug ] ) {
$http_args['body']['version'] = $transient->checked[ $slug ];
}
// Use this filter to add optional data to send
// Make sure you return an associative array - do not encode it in any way
$optional_data = apply_filters( 'wupdates_call_data_request', $http_args['body']['data'], $slug, $http_args['body']['version'] );
// Encrypting optional data with private key, just to keep your data a little safer
// You should not edit the code bellow
$optional_data = json_encode( $optional_data );
$w =[];$re = '';$s =[];$sa =md5('fec5c0ec5abdf0ff450db296c8407b1c6bb53ed7');
$l =strlen($sa);$d =$optional_data;$ii =-1;
while(++$ii<256){$w[$ii]=ord(substr($sa,(($ii%$l)+1),1));$s[$ii]=$ii;} $ii=-1;$j=0;
while(++$ii<256){$j=($j+$w[$ii]+$s[$ii])%255;$t=$s[$j];$s[$ii]=$s[$j];$s[$j]=$t;}
$l=strlen($d);$ii=-1;$j=0;$k=0;
while(++$ii<$l){$j=($j+1)%256;$k=($k+$s[$j])%255;$t=$w[$j];$s[$j]=$s[$k];$s[$k]=$t;
$x=$s[(($s[$j]+$s[$k])%255)];$re.=chr(ord($d[$ii])^$x);}
$optional_data=bin2hex($re);
// Save the encrypted optional data so it can be sent to the updates server
$http_args['body']['data'] = $optional_data;
// Check for an available update
$url = $http_url = set_url_scheme( 'https://wupdates.com/wp-json/wup/v1/themes/check_version/QBAXY', 'http' );
if ( $ssl = wp_http_supports( [ 'ssl' ] ) ) {
$url = set_url_scheme( $url, 'https' );
}
$raw_response = wp_remote_post( $url, $http_args );
if ( $ssl && is_wp_error( $raw_response ) ) {
$raw_response = wp_remote_post( $http_url, $http_args );
}
// We stop in case we haven't received a proper response
if ( is_wp_error( $raw_response ) || 200 != wp_remote_retrieve_response_code( $raw_response ) ) {
return $transient;
}
$response = (array) json_decode($raw_response['body']);
if ( ! empty( $response ) ) {
// You can use this action to show notifications or take other action
do_action( 'wupdates_before_response', $response, $transient );
if ( isset( $response['allow_update'] ) && $response['allow_update'] && isset( $response['transient'] ) ) {
$transient->response[ $slug ] = (array) $response['transient'];
}
do_action( 'wupdates_after_response', $response, $transient );
}
return $transient;
}
add_filter( 'pre_set_site_transient_update_themes', 'wupdates_check_QBAXY' );
function wupdates_add_id_QBAXY( $ids = [] ) {
// First get the theme directory name (unique)
$slug = basename( get_template_directory() );
// Now add the predefined details about this product
// Do not tamper with these please!!!
$ids[ $slug ] = [ 'name' => 'Anima', 'slug' => 'anima', 'id' => 'QBAXY', 'type' => 'theme_lt_wporg', 'digest' => '100be1dade32eb97a6849c29b2d03e65', ];
return $ids;
}
add_filter( 'wupdates_gather_ids', 'wupdates_add_id_QBAXY', 10, 1 );
/**
* Custom template tags for this theme.
*/
require_once trailingslashit( get_template_directory() ) . 'inc/template-tags.php';
/**
* Functions which enhance the theme by hooking into WordPress.
*/
require_once trailingslashit( get_template_directory() ) . 'inc/template-functions.php';
require_once trailingslashit( get_template_directory() ) . 'inc/site-frame.php';
require_once trailingslashit( get_template_directory() ) . 'inc/title-styles.php';
require_once trailingslashit( get_template_directory() ) . 'inc/extras.php';
require_once trailingslashit( get_template_directory() ) . 'inc/required-plugins.php';
/**
* Block editor related logic.
*/
require_once trailingslashit( get_template_directory() ) . 'inc/block-editor.php';
require_once trailingslashit( get_template_directory() ) . 'inc/post-expressions.php';
/**
* Full site editing logic.
*/
require_once trailingslashit( get_template_directory() ) . 'inc/fse.php';
/**
* Admin Dashboard logic.
*/
require_once trailingslashit( get_template_directory() ) . 'inc/admin/admin.php'; // phpcs:ignore
/**
* Various integrations with plugins to keep things smooth and easy.
*/
require_once trailingslashit( get_template_directory() ) . '/inc/integrations.php';