-
Notifications
You must be signed in to change notification settings - Fork 31
/
functions.php
139 lines (123 loc) · 3.88 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
<?php
/**
* @package snow-monkey
* @author inc2734
* @license GPL-2.0+
* @version 27.3.2
*/
use Framework\Helper;
/**
* Uses composer autoloader
*/
require_once get_template_directory() . '/vendor/autoload.php';
/**
* Adjusted due to different directory structure in development and release
*/
spl_autoload_register(
function ( $class_name ) {
if ( 0 !== strpos( $class_name, 'Framework\\' ) ) {
return;
}
$class_name = str_replace( '\\', '/', $class_name );
$file = get_template_directory() . '/' . $class_name . '.php';
if ( file_exists( $file ) ) {
require_once $file;
}
}
);
/**
* Make theme available for translation
*/
add_action(
'after_setup_theme',
function () {
load_theme_textdomain( 'snow-monkey', get_template_directory() . '/languages' );
}
);
/**
* Sets the content width in pixels, based on the theme's design and stylesheet.
*/
global $content_width;
if ( ! isset( $content_width ) ) {
$content_width = apply_filters( 'snow_monkey_content_width', 1220 );
}
/**
* Loads theme constructer files
*/
require_once __DIR__ . '/app/constructor/child-pages.php';
require_once __DIR__ . '/app/constructor/compatibility.php';
require_once __DIR__ . '/app/constructor/customizer.php';
require_once __DIR__ . '/app/constructor/design-skin.php';
require_once __DIR__ . '/app/constructor/detect-page-end.php';
require_once __DIR__ . '/app/constructor/detect-page-start.php';
require_once __DIR__ . '/app/constructor/manager.php';
require_once __DIR__ . '/app/constructor/oembed.php';
require_once __DIR__ . '/app/constructor/related-posts.php';
require_once __DIR__ . '/app/constructor/trial.php';
require_once __DIR__ . '/app/constructor/view-controller.php';
require_once __DIR__ . '/app/constructor/widgets.php';
require_once __DIR__ . '/app/constructor/deprecated/template-tags.php';
$updater_filepath = __DIR__ . '/app/constructor/updater.php';
if ( file_exists( $updater_filepath ) ) {
include_once $updater_filepath;
}
/**
* Change setup files loading method.
*
* @param string $type Loading method type.
* @param string $path Full path of the file.
* @param string $directory_slug Directory slug of the file.
* @return string
*/
function snow_monkey_loading_method_callback( $type, $path, $directory_slug ) {
$setup_files_loading_method = get_theme_mod( 'setup-files-loading-method' );
$setup_files_loading_method = false === $setup_files_loading_method ? 'get_template_parts' : $setup_files_loading_method;
if ( 'concat' === $setup_files_loading_method && 'app/widget' === $directory_slug ) {
return $type;
}
return $setup_files_loading_method;
}
add_filter( 'snow_monkey_loading_method', 'snow_monkey_loading_method_callback', 10, 3 );
/**
* If return false, do not expand get_template_part().
* The various hooks that extend get_template_part added by this library will no longer be available.
*
* @return boolean
*/
add_filter(
'inc2734_wp_view_controller_expand_get_template_part',
function () {
$expand_get_template_part = wp_cache_get( 'snow-monkey-expand-get-template-part' );
if ( false === $expand_get_template_part ) {
$expand_get_template_part = get_theme_mod( 'expand-get-template-part', true );
wp_cache_set( 'snow-monkey-expand-get-template-part', $expand_get_template_part );
}
// Since the default value by WP Customizer Framework is not reflected here, it should be written in plain text.
return $expand_get_template_part;
},
9
);
/**
* Loads theme setup files
*/
Helper::load_files( 'get_template_parts', __DIR__ . '/app/setup', true );
/**
* Loads theme widget files
*/
Helper::load_files( 'get_template_parts', __DIR__ . '/app/widget', true );
/**
* Loads customizer
*/
add_action(
'init',
function () {
do_action( 'snow_monkey_pre_load_customizer' );
Helper::load_files(
'get_template_parts',
__DIR__ . '/app/customizer',
true
);
do_action( 'snow_monkey_post_load_customizer' );
},
10000
);