forked from hobbit19/polestar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathextras.php
158 lines (137 loc) · 4.53 KB
/
extras.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
<?php
/**
* Custom functions that act independently of the theme templates.
*
* Eventually, some of the functionality here could be replaced by core features.
*
* @package polestar
* @license GPL 2.0
*/
/**
* Adds custom classes to the array of body classes.
*
* @param array $classes Classes for the body element.
* @return array
*/
function polestar_body_classes( $classes ) {
// Mobile compatibility classes.
$classes[] = 'css3-animations';
$classes[] = 'no-js';
$classes[] = 'no-touch';
// Non-singlar pages.
if ( ! is_singular() ) {
$classes[] = 'hfeed';
}
// Add the page setting classes.
$page_settings = puro_page_setting();
if ( ! empty( $page_settings ) ) {
if ( ! empty( $page_settings['layout'] ) ) $classes[] = 'page-layout-' . $page_settings['layout'];
if ( ! empty( $page_settings['overlap'] ) && ( $page_settings['overlap'] != 'disabled' ) ) $classes[] = 'overlap-' . $page_settings['overlap'];
if ( empty( $page_settings['header_margin'] ) ) $classes[] = 'no-header-margin';
if ( empty( $page_settings['footer_margin'] ) ) $classes[] = 'no-footer-margin';
}
// Header margin.
if ( is_home() && polestar_has_featured_posts() ) {
$classes[] = 'no-header-margin';
}
// Sidebar.
if ( is_active_sidebar( 'sidebar-main' ) && ! is_404() && ! ( function_exists( 'is_woocommerce' ) && is_woocommerce() ) ) {
$classes[] = 'sidebar';
}
// Sidebar left.
if ( get_theme_mod( 'sidebar_position' ) == 'left' && ! is_404() && $page_settings['layout'] != "constrained" && ! ( function_exists( 'is_woocommerce' ) && is_woocommerce() ) ) {
$classes[] = 'sidebar-left';
}
// WooCommerce sidebar.
if ( is_active_sidebar( 'sidebar-shop' ) && ( function_exists( 'is_woocommerce' ) && is_woocommerce() && ! is_product() ) ) {
$classes[] = 'woocommerce-sidebar';
if ( get_theme_mod( 'woocommerce_sidebar_position' ) == 'right' ) {
$classes[] = 'woocommerce-sidebar-right';
}
}
// WooCommerce top bar.
if ( function_exists( 'is_woocommerce' ) && ! is_store_notice_showing() ) {
$classes[] = 'no-topbar';
} elseif ( ! class_exists( 'Woocommerce' ) ) {
$classes[] = 'no-topbar';
}
// WooCommerce columns.
if ( function_exists( 'is_woocommerce' ) && is_woocommerce() ) {
$classes[] = 'columns-' . get_theme_mod( 'archive_columns', 3 );
}
return $classes;
}
add_filter( 'body_class', 'polestar_body_classes' );
/**
* Add a pingback url auto-discovery header for singularly identifiable articles.
*/
function polestar_pingback_header() {
if ( is_singular() && pings_open() ) {
echo '<link rel="pingback" href="', esc_url( get_bloginfo( 'pingback_url' ) ), '">';
}
}
add_action( 'wp_head', 'polestar_pingback_header' );
if ( ! function_exists( 'polestar_unset_current_menu_class' ) ) :
/**
* Unset the current menu class.
*/
function polestar_unset_current_menu_class( $classes ) {
$disallowed_class_names = array(
'current-menu-item',
'current_page_item',
);
foreach ( $classes as $class ) {
if ( in_array( $class, $disallowed_class_names ) ) {
$key = array_search( $class, $classes );
if ( false !== $key ) {
unset( $classes[$key] );
}
}
}
return $classes;
}
endif;
add_filter( 'nav_menu_css_class', 'polestar_unset_current_menu_class', 10, 1 );
if ( ! function_exists( 'polestar_post_class_filter' ) ) :
/**
* Filter post classes.
* @link https://codex.wordpress.org/Function_Reference/post_class.
*/
function polestar_post_class_filter( $classes ) {
$classes[] = 'post';
// Resolves structured data issue in core. See https://core.trac.wordpress.org/ticket/28482.
if ( is_page() ) {
$class_key = array_search( 'hentry', $classes );
if ( $class_key !== false) {
unset( $classes[ $class_key ] );
}
}
$classes = array_unique( $classes );
return $classes;
}
endif;
add_filter( 'post_class', 'polestar_post_class_filter' );
if ( ! function_exists( 'polestar_premium_setup' ) ) :
/**
* Polestar upsell notice.
*/
function polestar_upsell_notice() {
wp_enqueue_script( 'polestar-customizer-upsell', get_template_directory_uri() . '/js/polestar-upsell.js', array(), '1.0.0', true );
wp_localize_script(
'polestar-customizer-upsell',
'polestar10n',
array(
'polestarURL' => esc_html__( 'https://purothemes.com/themes/polestar/', 'polestar' ),
'polestarLabel' => esc_html__( 'Buy Premium Version', 'polestar' ),
)
);
}
add_action( 'customize_controls_enqueue_scripts', 'polestar_upsell_notice' );
endif;
/**
* Add our SiteOrigin Premium affiliate ID.
*/
function polestar_siteorigin_premium( $id ) {
return 1;
}
add_filter( 'siteorigin_premium_affiliate_id', 'polestar_siteorigin_premium' );