summaryrefslogtreecommitdiff
path: root/functions.php
blob: 8321d027ed3ca9721973fc3fd5a54352768b7863 (plain)
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
<?php
/**
 * Understrap functions and definitions
 *
 * @package understrap
 */

if ( ! defined( 'ABSPATH' ) ) {
	exit; // Exit if accessed directly.
}

/**
 * Initialize theme default settings
 */
require get_template_directory() . '/inc/theme-settings.php';

/**
 * Theme setup and custom theme supports.
 */
require get_template_directory() . '/inc/setup.php';

/**
 * Register widget area.
 */
require get_template_directory() . '/inc/widgets.php';

/**
 * Enqueue scripts and styles.
 */
require get_template_directory() . '/inc/enqueue.php';

/**
 * Custom template tags for this theme.
 */
require get_template_directory() . '/inc/template-tags.php';

/**
 * Custom pagination for this theme.
 */
require get_template_directory() . '/inc/pagination.php';

/**
 * Custom hooks.
 */
require get_template_directory() . '/inc/hooks.php';

/**
 * Custom functions that act independently of the theme templates.
 */
require get_template_directory() . '/inc/extras.php';

/**
 * Customizer additions.
 */
require get_template_directory() . '/inc/customizer.php';

/**
 * Custom Comments file.
 */
require get_template_directory() . '/inc/custom-comments.php';

/**
 * Load Jetpack compatibility file.
 */
require get_template_directory() . '/inc/jetpack.php';

/**
 * Load custom WordPress nav walker.
 */
require get_template_directory() . '/inc/class-wp-bootstrap-navwalker.php';

/**
 * Load WooCommerce functions.
 */
require get_template_directory() . '/inc/woocommerce.php';

/**
 * Load Editor functions.
 */
require get_template_directory() . '/inc/editor.php';

/**
 * # Modified
 */

/**
 * Load custom taxonomies.
 */
require get_template_directory() . '/taxonomy.php';

/**
 * Removes "Tag:" and "Category:" from archive pages.
 */
add_filter('get_the_archive_title', function ($title) {

	if ( is_tax('type') ) {
		$title = single_term_title( '', false );
		$title = 'Aktuelle ' . $title . "-Angebote";
	} else {
		$title = single_term_title( '', false );
	}
	return $title;
});

/**
 * Delays RSS-Feed by 60 minutes.
 */
function Delay_RSS_After_Publish($where) { 
        global $wpdb;
        if (is_feed()) {
                $now = gmdate('Y-m-d H:i:s');   
                $wait = '60'; 
                $device = 'MINUTE';             
                $where.=" AND TIMESTAMPDIFF($device, $wpdb->posts.post_date_gmt, '$now') > $wait ";
        }
        return $where;
}
add_filter('posts_where', 'Delay_RSS_After_Publish');

/**
 * Deaktiviert REST-API und entfernt die Header aus dem HTML.
 *
 * It seems it doesn't work though.
 */
add_filter('rest_enabled', '_return_false');
add_filter('rest_jsonp_enabled', '_return_false'); 
remove_action( 'wp_head', 'rest_output_link_wp_head', 10 );
remove_action( 'wp_head', 'wp_oembed_add_discovery_links', 10 );

/**
 * Entfernt wlwmanifest.xml (Microsoft Live Writer)
 */
remove_action('wp_head', 'wlwmanifest_link');
remove_action('wp_head', 'rsd_link');

/**
 * Disable W3TC footer comment for everyone but Admins (single site & network mode)
 */
if ( !current_user_can( 'activate_plugins' ) ) {
    add_filter( 'w3tc_can_print_comment', function( $w3tc_setting ) { return false; }, 10, 1 );
}

/**
 * Add short code functionality to excerpts.
 */
add_filter( 'the_excerpt', 'shortcode_unautop');
add_filter( 'the_excerpt', 'do_shortcode');

/** 
 * Adds short code: [glossar "Term"]
 */
function print_glossar_link( $atts ) {
        if ( count($atts) == 2 ) {
                $linktext = $atts[1];
        } else {
                $linktext = $atts[0];
        }
        return '<a class="glossar-link" href="https://www.fuselkoenig.de/glossar/#' . htmlentities($atts[0]) . '" title="Im Glossar zu ' . htmlentities($atts[0]) . '">' . htmlentities($linktext) . '</a>';
}
add_shortcode( "glossar", "print_glossar_link" );

/**
 * Redirects from the gallery to the actual post.
 */
function wpsites_attachment_redirect(){
        global $post;
        if ( is_attachment() && isset($post->post_parent) && is_numeric($post->post_parent) && ($post->post_parent != 0) ) {

            wp_redirect( get_permalink( $post->post_parent ), 301 );
            exit();
            wp_reset_postdata();
        }
}
add_action( 'template_redirect', 'wpsites_attachment_redirect' );

/**
 * Remove tags from tag cloud with zero entries.
 */
function set_widget_tag_cloud_excluded_tags($args){
        $min_count = 1;
        if ( "brennerei" == $args['taxonomy'] ) {
                $min_count+=1;
        }
        $excluded_tags=get_tags_termid_to_exclude($args['taxonomy'], $min_count);
        $my_args = array( 'exclude'=>$excluded_tags );
        $args = wp_parse_args( $args, $my_args );
        return $args;
}
function get_tags_termid_to_exclude($taxonomy, $max_excluded_count_value){
        $term_ids = array();
        foreach (
		get_terms( array(
			'taxonomy' => $taxonomy,
			'hide_empty' => true) )
		as $category )
	{
		if ($category->count < $max_excluded_count_value ){
			$term_ids[]=$category->term_id;
		}
        }
        return $term_ids;
}
add_filter( 'widget_tag_cloud_args', 'set_widget_tag_cloud_excluded_tags' );

/**
 * Add Matomo support to tag cloud links.
 */
function modify_tag_cloud_add_piwik_class($args) {                                                                                                                                                                   
        $start_s = '<a href="https://www.fuselkoenig.de/brennerei/';
        if ( $start_s  === substr( $args, 0, strlen($start_s) ) ) {
                $args = str_replace('class="', 'class="pwk-tc-brennerei ', $args);
        } else {
                $args = str_replace('class="', 'class="pwk-tc-category ', $args);
        }
        #file_put_contents("/tmp/wp.tagcloud.txt", ($args) );
        return $args;
}
add_filter( 'wp_tag_cloud', 'modify_tag_cloud_add_piwik_class' );

/**
 * Hides the checkbox to save name and email when someone comments.
 */
function comment_form_hide_cookies_consent( $fields ) {
	unset( $fields['cookies'] );
	return $fields;
}
add_filter( 'comment_form_default_fields', 'comment_form_hide_cookies_consent' );

/**
 * Allows to pass the parameter 'sort' and 'order' to WP pages.
 */
add_filter('query_vars', function ( $qvars ) {
        $qvars[] = '_sort';
        $qvars[] = '_order';
        return $qvars;
 } );

/**
 * Function to get the clean title of a blog post.
 */
if ( ! function_exists("get_my_clean_title")) {

	function get_my_clean_title( $title ) {
		$orig_title = str_replace('Im Test: ', '', $title);
		/*
		 * Entfernt alles, was in den Klammern steht.
		 */
		$my_title = preg_replace("/\(.+\)/i", "", $orig_title);

		if ( is_null($my_title) ) {
			return trim($orig_title);
		} else {
			return trim($my_title);
		}
	}

}

/**
 * Support for special offer pages.
 */
require_once __DIR__ . '/angebote/inc/functions.php';
require_once __DIR__ . '/angebote/inc/template.php';

/**
 * Removes emoji support.
 */
/*
remove_action( 'wp_head', 'print_emoji_detection_script', 7 );
remove_action( 'wp_print_styles', 'print_emoji_styles' );
 */

require_once get_template_directory() . '/api/api.php';