forked from wpzoom/inspiro
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctions.php
More file actions
308 lines (260 loc) · 9.65 KB
/
Copy pathfunctions.php
File metadata and controls
308 lines (260 loc) · 9.65 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
<?php
/**
* Inspiro functions and definitions
*
* @link https://developer.wordpress.org/themes/basics/theme-functions/
*
* @package Inspiro
* @since Inspiro 1.0.0
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
/**
* Define Constants
*/
define( 'INSPIRO_THEME_VERSION', '2.1.8' );
define( 'INSPIRO_THEME_DIR', trailingslashit( get_template_directory() ) );
define( 'INSPIRO_THEME_URI', trailingslashit( esc_url( get_template_directory_uri() ) ) );
define( 'INSPIRO_THEME_ASSETS_URI', INSPIRO_THEME_URI . 'dist' );
// Marketing
define( 'INSPIRO_MARKETING_UTM_CODE_STARTER_SITE', '?utm_source=wpadmin&utm_medium=starter-sites&utm_campaign=upgrade-premium' );
define( 'INSPIRO_MARKETING_UTM_CODE_FOOTER_MENU', '?utm_source=wpadmin&utm_medium=footer-menu&utm_campaign=upgrade-premium' );
// This theme requires WordPress 5.3 or later.
if ( version_compare( $GLOBALS['wp_version'], '5.3', '<' ) ) {
require INSPIRO_THEME_DIR . 'inc/back-compat.php';
}
/**
* Recommended Plugins
*/
require INSPIRO_THEME_DIR . 'inc/classes/class-tgm-plugin-activation.php';
/**
* Setup helper functions.
*/
require INSPIRO_THEME_DIR . 'inc/common-functions.php';
/**
* Setup theme media.
*/
require INSPIRO_THEME_DIR . 'inc/theme-media.php';
/**
* Color Palettes System
*/
require INSPIRO_THEME_DIR . 'inc/color-palettes.php';
/**
* Enqueues scripts and styles
*/
require INSPIRO_THEME_DIR . 'inc/classes/class-inspiro-enqueue-scripts.php';
/**
* Starter Content Notice
*/
require INSPIRO_THEME_DIR . 'inc/classes/class-inspiro-starter-content-notice.php';
/**
* Setup custom wp-admin options pages
*/
require INSPIRO_THEME_DIR . 'inc/classes/class-inspiro-custom-wp-admin-menu.php';
/**
* Additional features to include custom WP pointer function
*/
require INSPIRO_THEME_DIR . 'inc/classes/class-inspiro-wp-admin-menu-pointer.php';
/**
* Functions and definitions.
*/
require INSPIRO_THEME_DIR . 'inc/classes/class-inspiro-after-setup-theme.php';
/**
* Handle SVG icons.
*/
require INSPIRO_THEME_DIR . 'inc/classes/class-inspiro-svg-icons.php';
/**
* Implement the Custom Header feature.
*/
require INSPIRO_THEME_DIR . 'inc/custom-header.php';
/**
* Custom template tags for this theme.
*/
require INSPIRO_THEME_DIR . 'inc/template-tags.php';
/**
* Additional features to allow styling of the templates.
*/
require INSPIRO_THEME_DIR . 'inc/template-functions.php';
/**
* Custom Template WC functions
*/
require INSPIRO_THEME_DIR . 'inc/wc-custom-functions.php';
/**
* Editor Fonts
*/
require INSPIRO_THEME_DIR . 'inc/editor-fonts.php';
/**
* Custom template shortcode tags for this theme
*/
// require INSPIRO_THEME_DIR . 'inc/shortcodes.php';
/**
* Customizer additions.
*/
require INSPIRO_THEME_DIR . 'inc/classes/class-inspiro-font-family-manager.php';
require INSPIRO_THEME_DIR . 'inc/classes/class-inspiro-fonts-manager.php';
// Include Customizer Guided Tour
if ( is_admin() ) { // && is_customize_preview(), AJAX don't work with is_customize_preview() included
require INSPIRO_THEME_DIR . 'inc/classes/inspiro-customizer-guided-tour.php';
}
require INSPIRO_THEME_DIR . 'inc/customizer-functions.php';
require INSPIRO_THEME_DIR . 'inc/customizer/class-inspiro-customizer-control-base.php';
require INSPIRO_THEME_DIR . 'inc/customizer/class-inspiro-customizer.php';
/**
* SVG icons functions and filters.
*/
require INSPIRO_THEME_DIR . 'inc/icon-functions.php';
/**
* Theme admin notices and info page
*/
if ( is_admin() ) {
require INSPIRO_THEME_DIR . 'inc/admin-notice.php';
require INSPIRO_THEME_DIR . 'inc/admin/admin-api.php';
// temporary marketing black friday functionality
require INSPIRO_THEME_DIR . 'inc/marketing-functions.php';
if ( current_user_can( 'manage_options' ) ) {
require INSPIRO_THEME_DIR . 'inc/classes/class-inspiro-notices.php';
require INSPIRO_THEME_DIR . 'inc/classes/class-inspiro-notice-review.php';
require INSPIRO_THEME_DIR . 'inc/classes/class-inspiro-theme-deactivation.php';
}
}
/**
* Theme Upgrader
*/
require INSPIRO_THEME_DIR . 'inc/classes/class-inspiro-theme-upgrader.php';
/**
* Inline theme css generated dynamically
*/
require INSPIRO_THEME_DIR . 'inc/dynamic-css/body.php';
require INSPIRO_THEME_DIR . 'inc/dynamic-css/logo.php';
require INSPIRO_THEME_DIR . 'inc/dynamic-css/headings.php';
require INSPIRO_THEME_DIR . 'inc/dynamic-css/h1.php';
require INSPIRO_THEME_DIR . 'inc/dynamic-css/page-title.php';
require INSPIRO_THEME_DIR . 'inc/dynamic-css/h1-content.php';
require INSPIRO_THEME_DIR . 'inc/dynamic-css/content-headings.php';
require INSPIRO_THEME_DIR . 'inc/dynamic-css/hero-header-title.php';
require INSPIRO_THEME_DIR . 'inc/dynamic-css/hero-header-desc.php';
require INSPIRO_THEME_DIR . 'inc/dynamic-css/hero-header-button.php';
require INSPIRO_THEME_DIR . 'inc/dynamic-css/main-menu.php';
require INSPIRO_THEME_DIR . 'inc/dynamic-css/mobile-menu.php';
/**
* Container Width Functions
*/
/**
* Filter theme.json to make contentSize dynamic based on customizer container width
*/
if ( ! function_exists( 'inspiro_filter_theme_json_data' ) ) :
function inspiro_filter_theme_json_data( $theme_json_data ) {
$container_width = get_theme_mod( 'container_width', 1200 );
$container_width_narrow = get_theme_mod( 'container_width_narrow', 950 );
// Get the data array from the WP_Theme_JSON_Data object
$theme_json = $theme_json_data->get_data();
// Determine which width to use based on context
// Pages use default container width, single posts use narrow width
$content_size = $container_width; // Default to full width for pages
if ( is_single() || is_home() || is_archive() || is_category() || is_tag() || is_author() || is_date() ) {
$content_size = $container_width_narrow; // Use narrow width for blog contexts
}
// Update the contentSize in theme.json
if ( isset( $theme_json['settings']['layout']['contentSize'] ) ) {
$theme_json['settings']['layout']['contentSize'] = $content_size . 'px';
}
// Set wideSize to be content width + 250px to match CSS .alignwide styles
if ( isset( $theme_json['settings']['layout']['wideSize'] ) ) {
$wide_size = $content_size + 250;
$theme_json['settings']['layout']['wideSize'] = $wide_size . 'px';
}
// Update the data in the object and return it
$theme_json_data->update_with( $theme_json );
return $theme_json_data;
}
endif;
add_filter( 'wp_theme_json_data_user', 'inspiro_filter_theme_json_data' );
/**
* Also apply the container width to block editor
*/
if ( ! function_exists( 'inspiro_filter_theme_json_theme' ) ) :
function inspiro_filter_theme_json_theme( $theme_json_data ) {
return inspiro_filter_theme_json_data( $theme_json_data );
}
endif;
add_filter( 'wp_theme_json_data_theme', 'inspiro_filter_theme_json_theme' );
/**
* Update editor styles to reflect container width changes
*/
if ( ! function_exists( 'inspiro_add_editor_container_width_styles' ) ) :
function inspiro_add_editor_container_width_styles() {
$container_width = get_theme_mod( 'container_width', 1200 );
$container_width_narrow = get_theme_mod( 'container_width_narrow', 950 );
// Determine which width to use based on context
// Pages use default container width, single posts use narrow width
$content_size = $container_width; // Default to full width for pages
if ( is_single() || is_home() || is_archive() || is_category() || is_tag() || is_author() || is_date() ) {
$content_size = $container_width_narrow; // Use narrow width for blog contexts
}
$wide_size = $content_size + 250;
$editor_styles = "
.editor-styles-wrapper .wp-block {
max-width: {$content_size}px;
}
.editor-styles-wrapper .wp-block[data-align='wide'] {
max-width: {$wide_size}px;
}
";
wp_add_inline_style( 'wp-edit-blocks', $editor_styles );
}
endif;
add_action( 'enqueue_block_editor_assets', 'inspiro_add_editor_container_width_styles' );
/**
* Add dynamic CSS variables for container widths
*/
if ( ! function_exists( 'inspiro_add_container_width_css_variables' ) ) :
function inspiro_add_container_width_css_variables() {
$container_width = get_theme_mod( 'container_width', 1200 );
$container_width_narrow = get_theme_mod( 'container_width_narrow', 950 );
$container_width_elementor = get_theme_mod( 'container_width_elementor', false );
// Calculate responsive padding breakpoints
$container_padding = 30; // 30px padding
$container_width_breakpoint = $container_width + 60; // container width + 60px buffer
$container_width_narrow_breakpoint = $container_width_narrow + 60; // narrow container width + 60px buffer
$css = "
:root {
--container-width: {$container_width}px;
--container-width-narrow: {$container_width_narrow}px;
--container-padding: {$container_padding}px;
}
/* Dynamic responsive padding media queries */
@media (max-width: {$container_width_breakpoint}px) {
.wrap,
.inner-wrap,
.page .entry-content,
.page:not(.inspiro-front-page) .entry-footer,
.single .entry-wrapper,
.single.has-sidebar.page-layout-sidebar-right .entry-header .inner-wrap,
.wp-block-group > .wp-block-group__inner-container {
padding-left: {$container_padding}px;
padding-right: {$container_padding}px;
}
}
@media (max-width: {$container_width_narrow_breakpoint}px) {
.single .entry-header .inner-wrap,
.single .entry-content,
.single .entry-footer,
#comments {
padding-left: {$container_padding}px;
padding-right: {$container_padding}px;
}
}
";
// Add Elementor container width override if enabled
if ( $container_width_elementor ) {
$css .= "
.elementor-container {
max-width: {$container_width}px !important;
}
";
}
wp_add_inline_style( 'inspiro-style', $css );
}
endif;
add_action( 'wp_enqueue_scripts', 'inspiro_add_container_width_css_variables' );