forked from Codeinwp/Parallax-One
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.php
673 lines (542 loc) · 20.1 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
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
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
<?php
/**
* Functions and definitions
*
* @package parallax-one
*/
/**
* Set the content width based on the theme's design and stylesheet.
*/
if ( ! isset( $content_width ) ) {
$content_width = 730; /* pixels */
}
if ( ! function_exists( 'parallax_one_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 parallax_one_setup() {
/*
* Make theme available for translation.
* Translations can be filed in the /languages/ directory.
* If you're building a theme based on parallax-one, use a find and replace
* to change 'parallax-one' to the name of your theme in all the template files
*/
load_theme_textdomain( 'parallax-one', 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' );
// This theme uses wp_nav_menu() in one location.
register_nav_menus( array(
'primary' => esc_html__( 'Primary Menu', 'parallax-one' ),
'parallax_footer_menu' => esc_html__( 'Footer Menu', 'parallax-one' ),
) );
/*
Switch default core markup for search form, comment form, and comments
* to output valid HTML5.
*/
add_theme_support( 'html5', array(
'search-form',
'comment-form',
'comment-list',
'gallery',
'caption',
) );
/*
* Enable support for Post Formats.
* See http://codex.wordpress.org/Post_Formats
*/
add_theme_support( 'post-formats', array(
'aside',
'image',
'video',
'quote',
'link',
) );
// Set up the WordPress core custom background feature.
add_theme_support('custom-background',apply_filters( 'parallax_one_custom_background_args', array(
'default-repeat' => 'no-repeat',
'default-position-x' => 'center',
'default-attachment' => 'fixed',
)));
/*
* This feature enables Custom_Headers support for a theme as of Version 3.4.
*
* @link http://codex.wordpress.org/Function_Reference/add_theme_support#Custom_Header
*/
add_theme_support( 'custom-header',apply_filters( 'parallax_one_custom_header_args', array(
'default-image' => parallax_get_file( '/images/background-images/background.jpg' ),
'width' => 1000,
'height' => 680,
'flex-height' => true,
'flex-width' => true,
'header-text' => false,
)));
register_default_headers( array(
'parallax_one_default_header_image' => array(
'url' => parallax_get_file( '/images/background-images/background.jpg' ),
'thumbnail_url' => parallax_get_file( '/images/background-images/background_thumbnail.jpg' ),
),
));
// Theme Support for WooCommerce
add_theme_support( 'woocommerce' );
/*
* Enable support for Post Thumbnails on posts and pages.
*
* @link http://codex.wordpress.org/Function_Reference/add_theme_support#Post_Thumbnails
*/
add_theme_support( 'post-thumbnails' );
/* Set the image size by cropping the image */
add_image_size( 'parallax-one-post-thumbnail-big', 730, 340, true );
add_image_size( 'parallax-one-post-thumbnail-mobile', 500, 233, true );
// Latest news Section (homepage)
add_image_size( 'parallax-one-post-thumbnail-latest-news', 150, 150, true );
add_image_size( 'parallax_one_team', 268, 273, true );
add_image_size( 'parallax_one_services',60,62,true );
add_image_size( 'parallax_one_customers',75,75,true );
/**
* Welcome screen
*/
if ( is_admin() ) {
require get_template_directory() . '/inc/admin/welcome-screen/welcome-screen.php';
}
}
endif; // parallax_one_setup
add_action( 'after_setup_theme', 'parallax_one_setup' );
/**
* This function allows modification of the list of image sizes that are available to administrators in the WordPress.
*
* @param array $sizes Array of image sizes.
*
* @return array
*/
function parallax_one_media_uploader_custom_sizes( $sizes ) {
return array_merge( $sizes, array(
'parallax_one_team' => esc_html__( 'Parallax One Team Member','parallax-one' ),
'parallax_one_services' => esc_html__( 'Parallax One Services','parallax-one' ),
'parallax_one_customers' => esc_html__( 'Parallax One Testimonials','parallax-one' ),
) );
}
add_filter( 'image_size_names_choose', 'parallax_one_media_uploader_custom_sizes' );
/**
* Register widget area.
*
* @link http://codex.wordpress.org/Function_Reference/register_sidebar
*/
function parallax_one_widgets_init() {
register_sidebar(
array(
'name' => esc_html__( 'Sidebar', 'parallax-one' ),
'id' => 'sidebar-1',
'description' => '',
'before_widget' => '<aside id="%1$s" class="widget %2$s">',
'after_widget' => '</aside>',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2><div class="colored-line-left"></div><div class="clearfix widget-title-margin"></div>',
)
);
register_sidebars( 4,
array(
/* translators: %d is widget area id */
'name' => esc_html__( 'Footer area %d','parallax-one' ),
'id' => 'footer-area',
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>',
)
);
}
add_action( 'widgets_init', 'parallax_one_widgets_init' );
/**
* Fallback Menu
*
* If the menu doesn't exist, the fallback function to use.
*/
function parallax_one_wp_page_menu() {
echo '<ul class="nav navbar-nav navbar-right main-navigation small-text no-menu">';
wp_list_pages( array(
'title_li' => '',
'depth' => 1,
) );
echo '</ul>';
}
/**
* Enqueue scripts for customizer.
*/
function parallax_one_customizer_scripts() {
wp_enqueue_script( 'parallax_one_customizer_script', parallax_get_file( '/js/parallax_one_customizer.js' ), array( 'jquery', 'jquery-ui-draggable' ),'1.0.2', true );
}
add_action( 'customize_controls_enqueue_scripts', 'parallax_one_customizer_scripts' );
/**
* Enqueue fonts.
*
* @return string
*/
function parallax_one_fonts_url() {
$fonts_url = '';
/*
Translators: If there are characters in your language that are not
* supported by Lora, translate this to 'off'. Do not translate
* into your own language.
*/
$cabin = _x( 'on', 'Cabin font: on or off', 'parallax-one' );
/*
Translators: If there are characters in your language that are not
* supported by Open Sans, translate this to 'off'. Do not translate
* into your own language.
*/
$open_sans = _x( 'on', 'Open Sans font: on or off', 'parallax-one' );
if ( 'off' !== $cabin || 'off' !== $open_sans ) {
$font_families = array();
if ( 'off' !== $cabin ) {
$font_families[] = 'Cabin:400,600';
}
if ( 'off' !== $open_sans ) {
$font_families[] = 'Open Sans:400,300,600';
}
$parallax_one_character_cyrillic = get_theme_mod( 'parallax_one_character_cyrillic' );
$parallax_one_character_vietnamese = get_theme_mod( 'parallax_one_character_vietnamese' );
$parallax_one_character_greek = get_theme_mod( 'parallax_one_character_greek' );
$parallax_one_character_cyrillic_text = ( isset( $parallax_one_character_cyrillic ) && ($parallax_one_character_cyrillic != 1) ? '' : ',cyrillic' );
$parallax_one_character_greek_text = ( isset( $parallax_one_character_greek ) && ($parallax_one_character_greek != 1) ? '' : ',greek' );
$parallax_one_character_vietnamese_text = ( isset( $parallax_one_character_vietnamese ) && ($parallax_one_character_vietnamese != 1) ? '' : ',vietnamese' );
$query_args = array(
'family' => urlencode( implode( '|', $font_families ) ),
'subset' => urlencode( 'latin,latin-ext' . $parallax_one_character_cyrillic_text . $parallax_one_character_greek_text . $parallax_one_character_vietnamese_text ),
);
$fonts_url = add_query_arg( $query_args, 'https://fonts.googleapis.com/css' );
}
return esc_url_raw( $fonts_url );
}
/**
* Enqueue scripts and styles.
*/
function parallax_one_scripts() {
wp_enqueue_style( 'parallax-one-fonts', parallax_one_fonts_url(), array(), null );
wp_enqueue_style( 'parallax-one-bootstrap-style', parallax_get_file( '/css/bootstrap.min.css' ),array(), '3.3.1' );
wp_enqueue_style( 'parallax-one-font-awesome', parallax_get_file( '/css/font-awesome.min.css' ),'4.7' );
wp_enqueue_style( 'parallax-one-style', get_stylesheet_uri(), array( 'parallax-one-bootstrap-style' ),'1.0.0' );
wp_enqueue_script( 'parallax-one-bootstrap', parallax_get_file( '/js/bootstrap.min.js' ), array(), '3.3.5', true );
wp_enqueue_script( 'parallax-one-custom-all', parallax_get_file( '/js/custom.all.js' ), array( 'jquery' ), '2.0.2', true );
wp_localize_script( 'parallax-one-custom-all', 'screenReaderText', array(
'expand' => '<span class="screen-reader-text">' . esc_html__( 'expand child menu', 'parallax-one' ) . '</span>',
'collapse' => '<span class="screen-reader-text">' . esc_html__( 'collapse child menu', 'parallax-one' ) . '</span>',
) );
$parallax_one_enable_move = get_theme_mod( 'paralax_one_enable_move' );
if ( ! empty( $parallax_one_enable_move ) && $parallax_one_enable_move && 'posts' == get_option( 'show_on_front' ) && is_front_page() ) {
wp_enqueue_script( 'parallax-one-home-plugin', parallax_get_file( '/js/plugin.home.js' ), array( 'jquery', 'parallax-one-custom-all' ), '1.0.1', true );
}
$parallax_one_frontpage_animations = get_theme_mod( 'parallax_one_enable_animations', false );
if ( ! empty( $parallax_one_frontpage_animations ) && ( (bool) $parallax_one_frontpage_animations === true ) && 'posts' == get_option( 'show_on_front' ) && is_front_page() ) {
wp_enqueue_script( 'parallax-one-home-animations', parallax_get_file( '/js/scrollReveal.js' ), array( 'jquery' ), '1.0.0', true );
}
if ( 'posts' == get_option( 'show_on_front' ) && is_front_page() ) {
wp_enqueue_script( 'parallax-one-custom-home', parallax_get_file( '/js/custom.home.js' ), array( 'jquery' ), '1.0.0', true );
}
wp_enqueue_script( 'parallax-one-skip-link-focus-fix', parallax_get_file( '/js/skip-link-focus-fix.js' ), array(), '1.0.0', true );
if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
wp_enqueue_script( 'comment-reply' );
}
}
add_action( 'wp_enqueue_scripts', 'parallax_one_scripts' );
/**
* Custom template tags for this theme.
*/
require get_template_directory() . '/inc/template-tags.php';
/**
* Custom functions that act independently of the theme templates.
*/
require get_template_directory() . '/inc/extras.php';
/**
* Customizer additions.
*/
require get_template_directory() . '/inc/customizer.php';
/**
* Load Jetpack compatibility file.
*/
require get_template_directory() . '/inc/jetpack.php';
/**
* Enables user customization via WordPress plugin API
*/
require get_template_directory() . '/inc/hooks.php';
/**
* Customizer info
*/
require_once get_template_directory() . '/inc/customizer-info/class/class-singleton-customizer-info-section.php';
/**
* Translations
*/
require get_template_directory() . '/inc/translations/general.php';
/**
* TAV_Remote_Notification_Client.
*/
if ( ! class_exists( 'TAV_Remote_Notification_Client' ) ) {
require( get_template_directory() . '/inc/admin/class-remote-notification-client.php' );
}
$parallax_one_notification = new TAV_Remote_Notification_Client( 49, 'a0973bf1bd1fe265', 'https://themeisle.com?post_type=notification' );
/**
* Adding IE-only scripts to header.
*/
function parallax_one_ie() {
echo '<!--[if lt IE 9]>' . "\n";
echo '<script src="' . parallax_get_file( '/js/html5shiv.min.js' ) . '"></script>' . "\n";
echo '<![endif]-->' . "\n";
}
add_action( 'wp_head', 'parallax_one_ie' );
remove_action( 'woocommerce_before_main_content', 'woocommerce_output_content_wrapper', 10 );
remove_action( 'woocommerce_after_main_content', 'woocommerce_output_content_wrapper_end', 10 );
/**
* WooCommerce code before main content.
*/
function parallax_one_wrapper_start() {
echo '</div>';
parallax_hook_header_bottom();
echo '</header>';
parallax_hook_header_after();
echo '<div class="content-wrap">
<div class="container">
<div id="primary" class="content-area col-md-12">';
}
add_action( 'woocommerce_before_main_content', 'parallax_one_wrapper_start', 10 );
/**
* WooCommerce code after main content.
*/
function parallax_one_wrapper_end() {
echo '</div></div></div>';
}
add_action( 'woocommerce_after_main_content', 'parallax_one_wrapper_end', 10 );
/* add this code directly, no action needed */
remove_action( 'woocommerce_sidebar', 'woocommerce_get_sidebar', 10 );
/* tgm-plugin-activation */
require_once get_template_directory() . '/class-tgm-plugin-activation.php';
/**
* TGM Required plugins
*/
function parallax_one_register_required_plugins() {
$plugins = array(
array(
'name' => 'Intergeo Maps - Google Maps Plugin',
'slug' => 'intergeo-maps',
'required' => false,
),
array(
'name' => 'Pirate Forms',
'slug' => 'pirate-forms',
'required' => false,
),
);
$config = array(
'id' => 'parallax-one',
'default_path' => '',
'menu' => 'tgmpa-install-plugins',
'has_notices' => true,
'dismissable' => true,
'dismiss_msg' => '',
'is_automatic' => false,
'message' => '',
);
tgmpa( $plugins, $config );
}
add_action( 'tgmpa_register', 'parallax_one_register_required_plugins' );
/**
* Parallax inline style.
*/
function parallax_one_php_style() {
echo '<style type="text/css">';
$parallax_one_title_color = get_theme_mod( 'parallax_one_title_color' );
if ( ! empty( $parallax_one_title_color ) ) {
echo '.dark-text, .entry-header h1, #sidebar-secondary .widget-title { color: ' . $parallax_one_title_color . ' }';
}
$parallax_one_text_color = get_theme_mod( 'parallax_one_text_color' );
if ( ! empty( $parallax_one_text_color ) ) {
echo 'body, .entry-content p, .pirate_forms_thankyou_wrap p { color: ' . $parallax_one_text_color . '}';
}
$parallax_one_enable_move = get_theme_mod( 'paralax_one_enable_move' );
if ( ( empty( $parallax_one_enable_move ) || ! $parallax_one_enable_move) && 'posts' == get_option( 'show_on_front' ) && is_front_page() ) {
$parallax_one_header_image = get_header_image();
if ( ! empty( $parallax_one_header_image ) ) {
echo '.header{ background-image: url(' . parallax_one_make_protocol_relative_url( $parallax_one_header_image ) . ');}';
}
}
$parallax_one_bigtitle_background = get_theme_mod( 'parallax_one_bigtitle_background','rgba(0, 0, 0, 0.7)' );
if ( ! empty( $parallax_one_bigtitle_background ) ) {
echo '.overlay-layer-wrap{ background:' . $parallax_one_bigtitle_background . ';}';
}
echo '</style>';
}
add_action( 'wp_footer','parallax_one_php_style', 100 );
/**
* Get file from child-theme.
*
* @param string $file File name.
*
* @return string
*/
function parallax_get_file( $file ) {
$file_parts = pathinfo( $file );
$accepted_ext = array( 'jpg','img','png','css','js' );
if ( in_array( $file_parts['extension'], $accepted_ext ) ) {
$file_path = get_stylesheet_directory() . $file;
if ( file_exists( $file_path ) ) {
return esc_url( get_stylesheet_directory_uri() . $file );
} else {
return esc_url( get_template_directory_uri() . $file );
}
}
}
/**
* WooCommerce Extra Feature
* --------------------------
*
* Change number of related products on product page
* Set your own value for 'posts_per_page'
*/
add_filter( 'woocommerce_output_related_products_args', 'parallax_one_related_products_args' );
/**
* Change number of related products in WooCommerce.
*
* @param array $args WooCommerce settings.
*
* @return mixed
*/
function parallax_one_related_products_args( $args ) {
$args['posts_per_page'] = 4;
$args['columns'] = 4;
return $args;
}
/**
* Prevent theme from beeing updated by wordpress.org updates
*
* @param array $r Request.
* @param string $url Url.
*
* @return mixed
*/
function parallax_one_prevent_wporg_update( $r, $url ) {
if ( 0 !== strpos( $url, 'http://api.wordpress.org/themes/update-check' ) ) {
return $r; // Not a theme update request. Bail immediately.
}
$themes = unserialize( $r['body']['themes'] );
unset( $themes[ get_option( 'template' ) ] );
unset( $themes[ get_option( 'stylesheet' ) ] );
$r['body']['themes'] = serialize( $themes );
return $r;
}
add_filter( 'http_request_args', 'parallax_one_prevent_wporg_update', 5, 2 );
/**
* Adds container to embed video.
*
* @param mixed $html The cached HTML result, stored in post meta.
* @param string $url The attempted embed URL.
* @param array $attr An array of shortcode attributes.
* @param int $post_id Post ID.
*
* @return string
*/
function parallax_one_responsive_embed( $html, $url, $attr, $post_id ) {
$return = '<div class="parallax-one-video-container">' . $html . '</div>';
return $return;
}
add_filter( 'embed_oembed_html', 'parallax_one_responsive_embed', 10, 4 );
/**
* Display sections from childtheme, theme or plus plugin.
*
* @param string $template Template file name.
*/
function parallax_one_get_template_part( $template ) {
if ( locate_template( $template . '.php' ) ) {
get_template_part( $template );
} else {
if ( defined( 'PARALLAX_ONE_PLUS_PATH' ) ) {
$template = basename( $template );
if ( get_template_directory() !== get_stylesheet_directory() ) {
if ( file_exists( get_stylesheet_directory() . '/sections/' . $template . '.php' ) ) {
require_once( get_stylesheet_directory() . '/sections/' . $template . '.php' );
return;
}
}
if ( file_exists( PARALLAX_ONE_PLUS_PATH . 'public/templates/' . $template . '.php' ) ) {
require_once( PARALLAX_ONE_PLUS_PATH . 'public/templates/' . $template . '.php' );
}
}
}
}
if ( ! function_exists( 'parallax_one_make_protocol_relative_url' ) ) {
/**
* URL relative path;
*
* @param string $url URL.
*
* @return mixed
*/
function parallax_one_make_protocol_relative_url( $url ) {
return preg_replace( '(https?://)', '//', $url );
}
}
/**
* Transform Enqueued Stylesheet URLs
*/
function parallax_one_style_loader_src( $src, $handle ) {
return parallax_one_make_protocol_relative_url( $src );
}
add_filter( 'style_loader_src', 'parallax_one_style_loader_src', 10, 2 );
/**
* Transform Enqueued JavaScript URLs
*/
function parallax_one_script_loader_src( $src, $handle ) {
return parallax_one_make_protocol_relative_url( $src );
}
add_filter( 'script_loader_src', 'parallax_one_script_loader_src', 10, 2 );
/**
* Transform Enqueued Theme Files
*/
function parallax_one_template_directory_uri( $template_dir_uri, $template, $theme_root_uri ) {
return parallax_one_make_protocol_relative_url( $template_dir_uri );
}
add_filter( 'template_directory_uri', 'parallax_one_template_directory_uri', 10, 3 );
/**
* Transform Enqueued Theme Files
*/
function parallax_one_stylesheet_directory_uri( $stylesheet_dir_uri, $stylesheet, $theme_root_uri ) {
return parallax_one_make_protocol_relative_url( $stylesheet_dir_uri );
}
add_filter( 'stylesheet_directory_uri', 'parallax_one_stylesheet_directory_uri', 10, 3 );
/**
* 404 page content.
*/
function parallax_output_404_content() {
?>
<div id="primary" class="content-area col-md-8">
<main id="main" class="site-main" role="main">
<section class="error-404 not-found">
<header class="page-header">
<h2 class="page-title"><?php esc_html_e( 'Oops! That page can’t be found.', 'parallax-one' ); ?></h2>
</header><!-- .page-header -->
<div class="page-content">
<p><?php esc_html_e( 'It looks like nothing was found at this location. Maybe try one of the links below or a search?', 'parallax-one' ); ?></p>
<?php get_search_form(); ?>
</div><!-- .page-content -->
</section><!-- .error-404 -->
</main><!-- #main -->
</div><!-- #primary -->
<?php get_sidebar(); ?>
<?php
}
add_action( 'parallax_404_content', 'parallax_output_404_content' ); // Outputs a helpful message on 404 pages
/**
* Editor style
*/
function parallax_one_add_editor_styles() {
add_editor_style( array( 'css/custom-editor-style.css', parallax_one_fonts_url() ) );
}
add_action( 'after_setup_theme', 'parallax_one_add_editor_styles' );