-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathfunctions.php
More file actions
executable file
·213 lines (175 loc) · 5.89 KB
/
functions.php
File metadata and controls
executable file
·213 lines (175 loc) · 5.89 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
<?php
/**
* Include all function files.
*
* @package Sunflower 26
*/
/**
* Include all sub-function files.
*/
require_once __DIR__ . '/functions/s.php';
require_once __DIR__ . '/functions/options/class-sunflowerfirststepspage.php';
require_once __DIR__ . '/functions/options/class-sunflowersettingspage.php';
require_once __DIR__ . '/functions/options/class-sunflowersocialmediasettingspage.php';
require_once __DIR__ . '/functions/options/class-sunflowereventsettingspage.php';
require_once __DIR__ . '/functions/events.php';
require_once __DIR__ . '/functions/excerpts.php';
require_once __DIR__ . '/functions/admin.php';
require_once __DIR__ . '/functions/metaboxes.php';
require_once __DIR__ . '/functions/blocks.php';
require_once __DIR__ . '/functions/update.php';
require_once __DIR__ . '/functions/related-posts.php';
require_once __DIR__ . '/functions/demo-content.php';
require_once __DIR__ . '/functions/demo-setup.php';
require_once __DIR__ . '/functions/welcome-page.php';
require_once __DIR__ . '/functions/activation.php';
require_once __DIR__ . '/functions/comments.php';
require_once __DIR__ . '/functions/icalimport.php';
require_once __DIR__ . '/functions/emailscrambler.php';
require_once __DIR__ . '/functions/contact-form.php';
require_once __DIR__ . '/functions/api.php';
require_once __DIR__ . '/functions/childtheme.php';
require_once __DIR__ . '/functions/menu.php';
require_once __DIR__ . '/functions/security.php';
require_once __DIR__ . '/functions/theme.php';
require_once __DIR__ . '/functions/latest-posts.php';
require_once __DIR__ . '/functions/media.php';
require_once __DIR__ . '/functions/class-sunflower-contact-widget.php';
require_once __DIR__ . '/functions/widgets.php';
/**
* Get value of the sunflower settings.
*
* @param string $option The option key to search for.
*/
function sunflower_get_setting( $option ) {
$options = get_option( 'sunflower_options' );
if ( ! is_array( $options ) ) {
$options = array();
}
$sunflower_social_media_options = get_option( 'sunflower_social_media_options' );
if ( is_array( $sunflower_social_media_options ) ) {
$options = array_merge( $options, $sunflower_social_media_options );
}
$sunflower_events_options = get_option( 'sunflower_events_options' );
if ( is_array( $sunflower_events_options ) ) {
$options = array_merge( $options, $sunflower_events_options );
}
if ( ! isset( $options[ $option ] ) ) {
return false;
}
if ( empty( $options[ $option ] ) ) {
return 0;
}
return $options[ $option ];
}
/**
* Get the linked social media icons.
*/
function sunflower_get_social_media_profiles() {
$profiles = block_core_social_link_services();
$return = '';
$lines = explode( "\n", (string) sunflower_get_setting( 'sunflower_social_media_profiles' ) );
foreach ( $lines as $line ) {
$line = trim( $line );
$some_profile = explode( ';', $line );
$class = $some_profile[0] ?? false;
$title = $some_profile[1] ?? false;
$url = $some_profile[2] ?? false;
if ( false === $url || empty( $url ) ) {
continue;
}
$return .= sprintf(
'<a href="%1$s" target="_blank" title="%3$s" class="social-media-profile" rel="me"><i class="%2$s"></i></a>',
esc_url( $url ),
esc_attr( $class ),
esc_attr( $title )
);
}
if ( ! empty( $return ) ) {
$return = sprintf( '<div class="sunflower__socials">%s</div>', $return );
}
return $return;
}
/**
* SVG Upload
*/
/**
* SVG-MIME-Typen für Uploads erlauben.
*
* @param array<string, string> $mimes Vorhandene MIME-Typen.
* @return array<string, string> Angepasste MIME-Typen.
*/
function sunflower_allow_svg_uploads( $mimes ) {
$mimes['svg'] = 'image/svg+xml';
$mimes['svgz'] = 'image/svg+xml';
return $mimes;
}
add_filter( 'upload_mimes', 'sunflower_allow_svg_uploads' );
/**
* Fehlerhafte SVG-MIME-Typen beim Upload korrigieren.
*
* @param array<string, mixed> $data Dateidaten und MIME-Infos.
* @param string $file Dateipfad.
* @param string $filename Dateiname.
* @return array<string, mixed> Angepasste Dateidaten.
*/
function sunflower_fix_svg_mime_type( $data, $file, $filename ) {
$ext = strtolower( pathinfo( $filename, PATHINFO_EXTENSION ) );
if ( 'svg' === $ext ) {
$data['ext'] = 'svg';
$data['type'] = 'image/svg+xml';
}
return $data;
}
add_filter( 'wp_check_filetype_and_ext', 'sunflower_fix_svg_mime_type', 10, 3 );
/**
* SVG-Code bereinigen (Skripte, Event-Handler usw. entfernen).
*
* @param array<string, mixed> $file Daten der hochgeladenen Datei.
* @return array<string, mixed> Bereinigte Dateidaten.
*/
function sunflower_sanitize_svg( $file ) {
if ( isset( $file['type'] ) && 'image/svg+xml' === $file['type'] ) {
global $wp_filesystem;
if ( ! $wp_filesystem ) {
require_once ABSPATH . 'wp-admin/includes/file.php';
WP_Filesystem();
}
if ( $wp_filesystem ) {
$contents = $wp_filesystem->get_contents( $file['tmp_name'] );
if ( false !== $contents ) {
// Entfernt Skripte, Event-Handler, iframes usw.
$contents = preg_replace( '/<script.*?<\/script>/is', '', $contents );
$contents = preg_replace( '/on\w+="[^"]*"/i', '', $contents );
$contents = preg_replace( '/<iframe.*?<\/iframe>/is', '', $contents );
$wp_filesystem->put_contents( $file['tmp_name'], $contents );
}
}
}
return $file;
}
add_filter( 'wp_handle_upload_prefilter', 'sunflower_sanitize_svg' );
if ( ! function_exists( 'sunflower_filter_excerpt_more' ) ) {
/**
* Replace default excerpt more string.
*
* @param string $more Default excerpt more.
* @return string
*/
function sunflower_filter_excerpt_more( string $more ): string {
// Use parameter (PHPCS) even though we override the output.
if ( '' === $more ) {
$more = '';
}
return '...';
}
add_filter( 'excerpt_more', 'sunflower_filter_excerpt_more' );
}
// Core Block Patterns deaktivieren.
add_action(
'after_setup_theme',
function () {
remove_theme_support( 'core-block-patterns' );
},
20
);