-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.php
392 lines (313 loc) · 15.6 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
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
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
<?php
/**
* @package WordPress
* @subpackage FAU
* @since FAU 1.1
*/
global $defaultoptions, $default_fau_orga_data, $fau_used_svgs;
global $is_gutenberg_enabled;
load_theme_textdomain( 'fau', get_template_directory() . '/languages' );
// Block Editor handling
require_once( get_template_directory() . '/functions/block-editor-support.php');
require_once( get_template_directory() . '/functions/template-functions.php' );
require_once( get_template_directory() . '/functions/defaults.php' );
require_once( get_template_directory() . '/functions/constants.php' );
require_once( get_template_directory() . '/functions/Debugging.php' );
require_once( get_template_directory() . '/functions/sanitizer.php' );
require_once( get_template_directory() . '/functions/customizer.php');
$options = fau_initoptions();
$is_sidebar_active = false;
require_once( get_template_directory() . '/functions/plugin-support.php' );
require_once( get_template_directory() . '/functions/helper-functions.php' );
require_once( get_template_directory() . '/functions/embeddings.php');
require_once( get_template_directory() . '/functions/shortcodes.php');
require_once( get_template_directory() . '/functions/menu.php');
require_once( get_template_directory() . '/functions/custom-fields.php' );
require_once( get_template_directory() . '/functions/widgets.php' );
require_once( get_template_directory() . '/functions/svglib.php');
// Filter-Hooks
require_once( get_template_directory() . '/functions/filters.php');
// Comment handling
require get_template_directory() . '/functions/comments.php';
// Imagelinks
require_once( get_template_directory() . '/functions/posttype_imagelink.php' );
/*-----------------------------------------------------------------------------------*/
/* Setup theme
/*-----------------------------------------------------------------------------------*/
function fau_setup() {
global $defaultoptions;
if (!isset( $content_width ) ) {
$content_width = $defaultoptions['content-width'];
}
add_theme_support('html5', array( 'comment-list', 'comment-form', 'search-form', 'gallery', 'caption' ));
add_theme_support('caption');
add_theme_support('title-tag');
add_theme_support('automatic-feed-links');
fau_register_menus();
// Register Menus
fau_create_socialmedia_menu();
// Checkup Social Media Menu
fau_custom_logo_setup();
// Set the Logo setup and sizes
fau_set_image_sizes();
// Sets the sizes of Images
global $is_gutenberg_enabled;
if (has_filter('is_gutenberg_enabled')) {
$is_gutenberg_enabled = apply_filters('is_gutenberg_enabled', false);
} else {
$is_gutenberg_enabled = fau_is_newsletter_plugin_active();
}
}
add_action( 'after_setup_theme', 'fau_setup' );
/*-----------------------------------------------------------------------------------*/
/*Custom Loo setup
/*-----------------------------------------------------------------------------------*/
function fau_custom_logo_setup() {
global $defaultoptions;
$defaults = array(
'height' => $defaultoptions['default_logo_height'],
'width' => $defaultoptions['default_logo_width'],
'flex-height' => true,
'flex-width' => true,
'unlink-homepage-logo' => true,
);
add_theme_support( 'custom-logo', $defaults );
}
/*-----------------------------------------------------------------------------------*/
/* Set image sizes
/*-----------------------------------------------------------------------------------*/
function fau_set_image_sizes() {
global $defaultoptions;
/*
* Notice: Default Image Siztes dont neet to be defined:
* Reserved Image Size Names:
* thumb = alias for thumbnail
* thumbnail, default 150px x 150px max
* post-thumbnail,
* medium, default 300px x 300px max
* medium_large, default 768px x 0px max
* large, default 1024px x 1024px max
* full, unmodified
*/
foreach ($defaultoptions['default_image_sizes'] as $size => $value) {
switch ($size) {
case '_post_thumbnail':
add_theme_support( 'post-thumbnails' );
set_post_thumbnail_size($value[ 'width'], $value['height'], $value['crop']);
break;
case '_thumb':
case '_thumbnail':
// default values; tu nichts (derzeit)
break;
default:
add_image_size( $size, $value[ 'width'], $value['height'], $value['crop']);
}
}
}
/*-----------------------------------------------------------------------------------*/
/* Set extra init values
/*-----------------------------------------------------------------------------------*/
function fau_custom_init() {
/* Keine verwirrende Abfrage nach Kommentaren im Page-Editor */
remove_post_type_support( 'page', 'comments' );
/*
* Remove emojis
*/
remove_action( 'wp_head', 'print_emoji_detection_script', 7 );
remove_action( 'admin_print_scripts', 'print_emoji_detection_script' );
remove_action( 'wp_print_styles', 'print_emoji_styles' );
remove_action( 'admin_print_styles', 'print_emoji_styles' );
remove_filter( 'the_content_feed', 'wp_staticize_emoji' );
remove_filter( 'comment_text_rss', 'wp_staticize_emoji' );
remove_filter( 'wp_mail', 'wp_staticize_emoji_for_email' );
}
add_action( 'init', 'fau_custom_init' );
/*-----------------------------------------------------------------------------------*/
/* Enqueues scripts and styles for front end.
/*-----------------------------------------------------------------------------------*/
function fau_register_scripts() {
global $defaultoptions;
$theme_data = wp_get_theme();
$theme_version = $theme_data->Version;
wp_register_style('fau-style', get_stylesheet_uri(), array(), $theme_version);
// Global Style. Notice: Its used also for print, so dont limit it to screen output!
wp_register_style('fau-style-print', get_stylesheet_directory_uri() . '/print.css', array(), $theme_version, 'print' );
// Base style for print
wp_register_script('fau-scripts', $defaultoptions['src-scriptjs'], array('jquery'), $theme_version, true );
// Base FAU scripts
wp_register_script('fau-js-heroslider', $defaultoptions['src-sliderjs'], array('jquery'), $theme_version, true );
// Slider JS
wp_register_script('fau-js-printlinks', $defaultoptions['src-printlinks'], [], $theme_version, true );
// Print links js
}
add_action('init', 'fau_register_scripts');
/*-----------------------------------------------------------------------------------*/
/* Activate base scripts
/*-----------------------------------------------------------------------------------*/
function fau_basescripts_styles() {
wp_enqueue_style( 'fau-style');
wp_enqueue_style( 'fau-style-print' );
wp_enqueue_script( 'fau-js-printlinks' );
wp_enqueue_script( 'fau-scripts');
}
add_action( 'wp_enqueue_scripts', 'fau_basescripts_styles' );
/*-----------------------------------------------------------------------------------*/
/* Activate scripts depending on use
/*-----------------------------------------------------------------------------------*/
function fau_enqueuefootercripts() {
global $usejslibs;
if ((isset($usejslibs['heroslider']) && ($usejslibs['heroslider'] == true))) {
// wird bei Startseite Slider und auch bei gallerien verwendet
wp_enqueue_script('fau-js-heroslider');
}
}
add_action( 'wp_footer', 'fau_enqueuefootercripts' );
/*-----------------------------------------------------------------------------------*/
/* Activate scripts and style for backend use
/*-----------------------------------------------------------------------------------*/
function fau_admin_header_style() {
global $defaultoptions;
wp_register_style( 'themeadminstyle', get_fau_template_uri().'/css/fau-theme-admin.css' );
wp_enqueue_style( 'themeadminstyle' );
wp_enqueue_style( 'dashicons' );
wp_enqueue_media();
wp_enqueue_script('jquery-ui-datepicker');
// wp_enqueue_script('image-caption-editor', get_template_directory_uri() . '/js/fau-image-caption-editor.min.js', array('jquery', 'wp-editor'), '1.0', true);
// Add html atributes to image caption on post editor
// deactivated 21.06 by ww, cause js not found anymore. Backend JS should be packed
// in admin.js anyway
$theme_data = wp_get_theme();
$theme_version = $theme_data->Version;
wp_register_script('themeadminscripts', $defaultoptions['src-adminjs'], array('jquery'),$theme_version);
wp_enqueue_script('themeadminscripts');
}
add_action( 'admin_enqueue_scripts', 'fau_admin_header_style' );
/*-----------------------------------------------------------------------------------*/
/* Change default DNS prefetch
/*-----------------------------------------------------------------------------------*/
function fau_remove_default_dns_prefetch( $hints, $relation_type ) {
if ( 'dns-prefetch' === $relation_type ) {
return array_diff( wp_dependencies_unique_hosts(), $hints );
}
return $hints;
}
add_filter( 'wp_resource_hints', 'fau_remove_default_dns_prefetch', 10, 2 );
function fau_dns_prefetch() {
// List of domains to set prefetching for
$prefetchDomains = array();
$mydomain = parse_url(get_home_url());
$scheme = $mydomain['scheme'];
$prefetchDomains[] = $mydomain['host'];
// add own domain
// check if own domain is a subdomain. if so, we also add the main domain above
$host = explode('.', $mydomain['host']);
if (($host) && (count($host)>1)) {
$prefetchDomains[] = $scheme.'://'.$host[count($host)-2].'.'.$host[count($host)-1];
// check for third level
if (count($host)>2) {
$prefetchDomains[] = $scheme.'://'.$host[count($host)-3].'.'.$host[count($host)-2].'.'.$host[count($host)-1];
}
}
$prefetchDomains = array_unique($prefetchDomains);
$result = '';
foreach ($prefetchDomains as $domain) {
$domain = esc_url($domain);
$result .= '<link rel="dns-prefetch" href="' . $domain . '" crossorigin>'."\n";
// $result .= '<link rel="preconnect" href="' . $domain . '" crossorigin>'."\n";
// We do not make a preconnect to all domains:
// The preconnect hint is best used for only the most critical connections.
// For the others, just use <link rel="dns-prefetch"> to save time on
// the first step — the DNS lookup.
// see also: https://developer.mozilla.org/en-US/docs/Web/Performance/dns-prefetch
}
echo $result;
}
add_action('wp_head', 'fau_dns_prefetch', 10);
/*-----------------------------------------------------------------------------------*/
/* Change default header
/*-----------------------------------------------------------------------------------*/
function fau_addmetatags() {
$output = '';
$output .= fau_get_rel_alternate();
// get alternate urls for the website if avaible
$googleverification = get_theme_mod('google-site-verification');
if ((isset( $googleverification )) && ( !fau_empty($googleverification) )) {
$output .= '<meta name="google-site-verification" content="'.$googleverification.'">'."\n";
// if we set the Google Site Verification in the customizer, we add the html meta tag here
}
$title = sanitize_text_field(get_bloginfo( 'name','display' ));
$output .= '<link rel="alternate" type="application/rss+xml" title="'.$title.' - RSS 2.0 Feed" href="'.get_bloginfo( 'rss2_url').'">'."\n";
// Adds RSS feed links to <head> for posts and comments.
// add_theme_support( 'automatic-feed-links' );
// Will post both: feed and comment feed; To use only main rss feed, i have to add it manually in head
echo $output;
}
add_action('wp_head', 'fau_addmetatags',1);
/*-----------------------------------------------------------------------------------*/
/* create favicon metas
/*-----------------------------------------------------------------------------------*/
function fau_create_meta_favicon() {
global $defaultoptions;
$output = '';
if ( ! function_exists( 'has_site_icon' ) || ! has_site_icon() ) {
$output .= '<link rel="shortcut icon" href="'.get_fau_template_uri().'/img/socialmedia/favicon.ico">'."\n";
$output .= '<link rel="apple-touch-icon" sizes="180x180" href="'.get_fau_template_uri().'/img/socialmedia/favicon-apple-touch.png">'."\n";
$output .= '<link rel="icon" type="image/png" sizes="180x180" href="'.get_fau_template_uri().'/img/socialmedia/favicon-180x180.png">'."\n";
$output .= '<link rel="icon" type="image/svg+xml" href="'.get_fau_template_uri().'/img/socialmedia/favicon.svg" sizes="any">'."\n";
$output .= '<link rel="mask-icon" type="image/svg+xml" href="'.get_fau_template_uri().'/img/socialmedia/favicon-mask.svg" color="'.$defaultoptions['default-social-media-color'].'">'."\n";
$output .= '<meta name="msapplication-TileColor" content="'.$defaultoptions['default-social-media-color'].'">'."\n";
$output .= '<meta name="msapplication-TileImage" content="'.get_fau_template_uri().'/img/socialmedia/favicon-180x180.png">'."\n";
$output .= '<meta name="theme-color" content="'.$defaultoptions['default-social-media-color'].'">'."\n";
}
echo $output;
}
add_action('wp_head', 'fau_create_meta_favicon');
// add favicon for frontend
add_action('admin_head', 'fau_create_meta_favicon');
// add favicon for backend
/*-----------------------------------------------------------------------------------*/
/* Add FAU Jobs advertisement
/*-----------------------------------------------------------------------------------*/
function fau_addmjobsad() {
global $defaultoptions;
if ($defaultoptions['default-sourcecode-notice']) {
echo '<!-- '.$defaultoptions['default-sourcecode-notice-text'].' -->'."\n";
}
}
add_action('wp_head', 'fau_addmjobsad',10);
/*-----------------------------------------------------------------------------------*/
/* Remove something out of the head
/*-----------------------------------------------------------------------------------*/
function fau_remove_unwanted_head_actions() {
remove_action( 'wp_head', 'post_comments_feed_link ', 2 );
// Display the links to the general feeds: Post and Comment Feed
remove_action( 'wp_head', 'wlwmanifest_link' );
// Display the link to the Windows Live Writer manifest file.
remove_action( 'wp_head', 'parent_post_rel_link', 10, 0 );
// remove prev link
remove_action( 'wp_head', 'rest_output_link_wp_head');
// removes link <link rel='https://api.w.org/' ..>
remove_action( 'wp_head', 'rsd_link' );
// Display the link to the Really Simple Discovery service endpoint, EditURI link
remove_action( 'wp_head', 'adjacent_posts_rel_link', 10, 0 );
// remove Display relational links for the posts adjacent to the current post.
remove_action( 'wp_head', 'wp_oembed_add_discovery_links' );
// remove oEmbed discovery links in the website
if (!is_user_logged_in()) {
// remove admin settings in footer if not logged in
remove_action('wp_footer', 'wp_admin_bar_render', 1000 );
remove_action('wp_head', '_admin_bar_bump_cb');
remove_action('wp_head', 'wp_admin_bar_header');
}
}
add_action('wp_head', 'fau_remove_unwanted_head_actions', 0);
/*-----------------------------------------------------------------------------------*/
/* Limit Number of Posts for embedded format
/*-----------------------------------------------------------------------------------*/
add_action( 'pre_get_posts', 'fau_embedded_posts' );
function fau_embedded_posts( $query ) {
if (isset($_GET['format']) && $_GET['format'] == 'embedded') {
$query->set( 'numberposts', 3 );
$query->set( 'posts_per_page', 3 );
}
}