-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctions.php
More file actions
227 lines (172 loc) · 5.53 KB
/
functions.php
File metadata and controls
227 lines (172 loc) · 5.53 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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
<?php
/* Contents:
* - Includes
* - Add actions
* - Image url function
* - Register menus
* - Security edits
* - Removing emoji
* - AJAX address API */
/* INCLUDES */
include( 'inc/activity-post-type.php' );
include( 'inc/frontpage-custom-fields.php' );
include( 'inc/redirect-post-type.php' );
include( 'inc/redirect-custom-fields.php' );
include( 'inc/publication-post-type.php' );
include( 'inc/publication-custom-fields.php' );
include( 'inc/page-custom-fields.php' );
include( 'inc/send-mail.php' );
include( 'inc/administration-handling.php' );
include( 'inc/rental-handling.php' );
include( 'inc/rental-form.php' );
include( 'inc/clothes-handling.php' );
include( 'inc/clothes-form.php' );
include( 'inc/pioniers-handling.php' );
if (file_exists('inc/local-vars.php')) include( 'inc/local-vars.php' );
/* ADD ACTIONS */
add_action( 'after_setup_theme', 'custom_theme_setup' );
/* Add theme support for a few things */
function custom_theme_setup() {
add_theme_support( 'post-thumbnails' ); // Allow posts to have thumbnails
add_theme_support( 'html5', array( 'comment-list', 'comment-form', 'search-form', 'gallery', 'caption', 'style', 'script' ) ); // Make the search form input type="search"
add_theme_support( 'title-tag' ); // Fix the document title tag
}
/* Get url for image based on filename */
function image_url($filename) {
return get_bloginfo('template_directory') . '/static/img/' . $filename;
}
/* Create menus */
register_nav_menus( array(
'primary' => 'Primary Menu',
'sitemap' => 'Footer Sitemap'
) );
function menu_item_buttons( $output, $item, $depth, $args ) {
if ( in_array( 'menu-item-has-children', $item->classes, true ) ) {
$output = "<button type='button' class='menu-item-toggle' aria-expanded='false'
aria-controls='sub-menu-{$item->ID}'>
{$item->title}<svg aria-hidden='true' width='16' height='16'>
<use xlink:href='#arrow' />
</svg>
</button>";
}
return $output;
}
add_filter( 'walker_nav_menu_start_el', 'menu_item_buttons', 10, 4 );
/* Prevent some exploits and block username enum by
* - disabling XML-RPC
* - blocking unauthorized access to the JSON API
* - removing author archives
*/
// add_filter( 'xmlrpc_enabled', '__return_false' );
add_filter( 'rest_authentication_errors', function( $result ) {
if ( ! empty( $result ) ) {
return $result;
}
if ( ! is_user_logged_in() ) {
return new WP_Error( 'rest_not_logged_in', 'You are not currently logged in.', array( 'status' => 401 ) );
}
return $result;
});
function disable_author_archives() {
if (is_author()) {
global $wp_query;
$wp_query->set_404();
status_header(404);
} else {
redirect_canonical();
}
}
remove_filter('template_redirect', 'redirect_canonical');
add_action('template_redirect', 'disable_author_archives');
/* Stop loading emoji styles and scripts */
remove_action('wp_head', 'print_emoji_detection_script', 7);
remove_action('wp_print_styles', 'print_emoji_styles');
remove_action( 'admin_print_scripts', 'print_emoji_detection_script' );
remove_action( 'admin_print_styles', 'print_emoji_styles' );
/* Remove comment support */
// Removes from admin menu
add_action( 'admin_menu', 'my_remove_admin_menus' );
function my_remove_admin_menus() {
remove_menu_page( 'edit-comments.php' );
}
// Removes from post and pages
add_action('init', 'remove_comment_support', 100);
function remove_comment_support() {
remove_post_type_support( 'post', 'comments' );
remove_post_type_support( 'page', 'comments' );
}
// Removes from admin bar
function so1_admin_bar_render() {
global $wp_admin_bar;
$wp_admin_bar->remove_menu('comments');
}
add_action( 'wp_before_admin_bar_render', 'so1_admin_bar_render' );
function sort_activities( $query ) {
// do not modify queries in the admin
if( is_admin() ) return $query;
// only modify queries for 'event' post type
if( isset($query->query_vars['post_type'])
&& $query->query_vars['post_type'] == 'activiteiten' ) {
$query->set('orderby', 'meta_value');
$query->set('meta_key', 'date_upcoming');
$query->set('order', 'ASC');
}
// return
return $query;
}
add_action('pre_get_posts', 'sort_activities');
function show_publications( $query ) {
// do not modify queries in the admin
if( is_admin() ) return $query;
// only modify queries for 'event' post type
if( is_category() && $query->is_main_query() ) {
$query->set('post_type', array(
'post',
'publicaties'
));
}
// return
return $query;
}
add_action('pre_get_posts', 'show_publications');
add_action('wp_ajax_nopriv_address', 'address');
add_action('wp_ajax_address', 'address');
function address() {
$curl = curl_init();
$url = "http://json.api-postcode.nl";
$data = array(
'postcode' => $_GET['postcode'],
'number' => $_GET['number']
);
$url = sprintf("%s?%s", $url, http_build_query($data));
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
'token: ' . POSTAL_CODE_API_KEY
));
$result = curl_exec($curl);
curl_close($curl);
echo $result;
exit();
}
function dutch_strtotime($date_string) {
return strtotime(
strtr(
strtolower($date_string),
array(
'januari' => 'jan',
'februari' => 'feb',
'maart' => 'march',
'april' => 'apr',
'mei' => 'may',
'juni' => 'jun',
'juli' => 'jul',
'augustus' => 'aug',
'september' => 'sep',
'oktober' => 'oct',
'november' => 'nov',
'december' => 'dec'
)
)
);
}