-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfunctions.php
More file actions
executable file
·162 lines (149 loc) · 4.21 KB
/
functions.php
File metadata and controls
executable file
·162 lines (149 loc) · 4.21 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
<?php
/**
* Include other files needed by the theme
*
* @package RH
*/
// Require Composer dependencies
$autoload_file = get_template_directory() . '/vendor/autoload.php';
if ( file_exists( $autoload_file ) ) {
require_once $autoload_file;
}
$files_to_require = array(
'debugging.php',
'class-rh-admin.php',
'class-rh-cdn.php',
'class-rh-redirects.php',
'class-rh-helpers.php',
'class-rh-svg.php',
'class-rh-pagination.php',
'class-rh-menus.php',
'class-rh-breadcrumbs.php',
'class-rh-media.php',
'class-rh-scripts-and-styles.php',
'class-rh-search.php',
'class-rh-slack.php',
'class-rh-post-type-archives.php',
'class-rh-posts.php',
'class-rh-pages.php',
'class-rh-blocks.php',
'class-rh-cli.php',
'class-rh-security.php',
);
if ( wp_get_environment_type() !== 'production' ) {
$files_to_require[] = 'class-rh-staging.php';
}
foreach ( $files_to_require as $filename ) {
$file = get_template_directory() . '/functions/' . $filename;
if ( file_exists( $file ) ) {
require_once $file;
}
}
// Autoload block classes
$path = get_template_directory() . '/blocks/';
$directory = new RecursiveDirectoryIterator( $path );
$filter = new RecursiveCallbackFilterIterator(
$directory,
function ( $current ) {
// Skip hidden files and directories.
if ( $current->getFilename()[0] === '.' ) {
return false;
}
if ( $current->getExtension() === '' || $current->getExtension() === 'php' ) {
return true;
}
return false;
}
);
$iterator = new RecursiveIteratorIterator( $filter );
foreach ( $iterator as $file ) {
$the_file = $file->getPathname();
if ( file_exists( $the_file ) ) {
require_once $the_file;
}
}
/**
* Add the styleguide directory to the known directories Sprig should look
* for Twig files to render
*
* @param array $paths Places Twig should look for Twig files
* @return array Modified paths
*/
function filter_sprig_roots( $paths = array() ) {
$paths[] = get_template_directory() . '/styleguide';
// Add every directory in the /blocks/ directory to the possible path for a Twig file
$iter = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator(
get_template_directory() . '/blocks/',
RecursiveDirectoryIterator::SKIP_DOTS
),
RecursiveIteratorIterator::SELF_FIRST,
RecursiveIteratorIterator::CATCH_GET_CHILD // Ignore "Permission denied"
);
foreach ( $iter as $path => $dir ) {
if ( $dir->isDir() ) {
$paths[] = $path;
}
}
return $paths;
}
add_filter( 'sprig/roots', 'filter_sprig_roots' );
/**
* Make additional PHP functions available as Twig filters
*
* @param array $filters The Twig filters to modify
*/
function filter_sprig_twig_filters( $filters = array() ) {
$filters['sanitize_title'] = 'sanitize_title';
return $filters;
}
add_filter( 'sprig/twig/filters', 'filter_sprig_twig_filters' );
/**
* Make additional PHP functions available as Twig functions
*
* @param array $functions The Twig functions to modify
*/
function filter_sprig_twig_functions( $functions = array() ) {
$functions['get_language_attributes'] = 'get_language_attributes';
return $functions;
}
add_filter( 'sprig/twig/functions', 'filter_sprig_twig_functions' );
/**
* Add support for the title tag as of WordPress version 4.1
*
* @link https://codex.wordpress.org/Title_Tag#Adding_Theme_Support
*/
add_action(
'init',
function() {
add_theme_support( 'title-tag' );
}
);
if ( ! function_exists( 'str_starts_with' ) ) {
/**
* Polyfill for PHP 8's str_starts_with
*
* @link https://php.watch/versions/8.0/str_starts_with-str_ends_with
*
* @param string $haystack The string to search in.
* @param string $needle The substring to search for in the haystack.
* @return boolean
*/
function str_starts_with( string $haystack, string $needle ): bool {
return \strncmp( $haystack, $needle, \strlen( $needle ) ) === 0;
}
}
if ( ! function_exists( 'str_contains' ) ) {
/**
* Polyfill for PHP8's str_contains
*
* @link https://php.watch/versions/8.0/str_contains
*
* @param string $haystack The string to search in.
* @param string $needle The substring to search for in the haystack.
* @return boolean
*/
function str_contains( string $haystack, string $needle ): bool {
return '' === $needle || false !== strpos( $haystack, $needle );
}
}