-
Notifications
You must be signed in to change notification settings - Fork 3
/
functions.php
297 lines (255 loc) · 8.57 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
<?php
/**
* Special PHP functions.
* @copyright Copyright (C) 2020 Ondrej Golasowski, Petr Kucera and contributors
* @license GPL(GPLv3)
*/
?>
<?php
/**
* Remove empty paragraphs created by wpautop()
* @author Ryan Hamilton
* @link https://gist.github.com/Fantikerz/5557617
*/
function remove_empty_p( $content ) {
$content = force_balance_tags( $content );
$content = preg_replace( '#<p>\s*+(<br\s*/*>)?\s*</p>#i', '', $content );
$content = preg_replace( '~\s?<p>(\s| )+</p>\s?~', '', $content );
return $content;
}
//Attach filter to the contents of articles.
add_filter('the_content', 'remove_empty_p', 0, 1);
//Allow post thumbnails.
add_theme_support( 'post-thumbnails' );
/**
* Attach a version suffix to the url of the style.css to force browsers to refresh CSS.
* @author Ondrej Golasowski
*/
function get_css_name(){
$version = 33;
return "/style.css?rnd=" . $version;
}
/**
* Attach a version suffix to the url of the main.js to force browsers to refresh JS.
* @author Ondrej Golasowski
*/
function get_js_name(){
$version = 2;
return "/assets/js/main.js?rnd=" . $version;
}
/**
* Create multiple socials icons.
* @param int Count of icons.
* @author Ondrej Golasowski
*/
function stcblog_add_socials($count, $customizer){
for($id = 1; $id <= $count; $id++){
// Adding a template setting for a logo.
$customizer->add_setting('settings_footer_logo' . $id, [
'default' => ''
]);
// Adding a template setting for a link.
$customizer->add_setting('settings_footer_link' . $id, [
'default' => ''
]);
//Adding an image upload control to the Customizer.
$customizer->add_control(new WP_Customize_Image_Control($customizer, 'control_footer_logo' . $id, [
'label' => __('Socials ' . $id . ' - logo', 'stcblog'),
'section' => 'section_footer',
'settings' => 'settings_footer_logo' . $id
]));
//Adding an url input control to the Customizer.
$customizer->add_control(new WP_Customize_Control($customizer, 'control_footer_link' . $id, [
'label' => __( 'Socials ' . $id . ' - link', 'stcblog' ),
'section' => 'section_footer',
'settings' => 'settings_footer_link' . $id,
'type' => 'url'
]));
}
}
/**
* Add GDPR link to footer.
* @author Ondrej Golasowski
*/
function stcblog_add_gdpr($customizer){
// Adding a template setting for a text.
$customizer->add_setting('settings_footer_gdpr_text', [
'default' => ''
]);
// Adding a template setting for a link.
$customizer->add_setting('settings_footer_gdpr_link', [
'default' => ''
]);
//Adding an text input upload control to the Customizer.
$customizer->add_control(new WP_Customize_Control($customizer, 'control_footer_gdpr_text', [
'label' => __('GDPR text', 'stcblog'),
'section' => 'section_footer',
'settings' => 'settings_footer_gdpr_text'
]));
//Adding an url input control to the Customizer.
$customizer->add_control(new WP_Customize_Control($customizer, 'control_footer_gdpr_link', [
'label' => __('GDPR link', 'stcblog' ),
'section' => 'section_footer',
'settings' => 'settings_footer_gdpr_link',
'type' => 'url'
]));
}
/**
* Add MarCom mail to footer.
* @author Petr Kučera
*/
function stcblog_add_MarCommail($customizer){
//Adding a template setting for a MarCom mail.
$customizer->add_setting('settings_footer_MarCommail', [
'default' => ''
]);
//Adding an text input upload control to the Customizer.
$customizer->add_control(new WP_Customize_Control($customizer, 'settings_footer_MarCommail', [
'label' => __('MarCom mail', 'stcblog'),
'section' => 'section_footer',
'description'=> 'Contact email for MarCom AG.',
'settings' => 'settings_footer_MarCommail'
]));
}
//Adding functions to the Customizer.
function stcblog_customize_register($wp_customize){
// ***********************************
// Footer section
// ***********************************
// Adding a section to the Customizer.
$wp_customize->add_section('section_footer', [
'title' => __( 'Footer', 'stcblog' ),
'priority' => 30,
]);
// ===================================
// Custom copyright text
// ===================================
// Adding the template setting.
$wp_customize->add_setting('settings_footer_copyright', [
'default' => '© 2020 STC, Všechna práva vyhrazena'
]);
//Adding a control to the Customizer.
$wp_customize->add_control(new WP_Customize_Control($wp_customize, 'control_footer_copyright', [
'label' => __( 'Copyright text', 'stcblog' ),
'section' => 'section_footer',
'settings' => 'settings_footer_copyright'
]));
// ===================================
// Custom GDPR link
// ===================================
stcblog_add_gdpr($wp_customize);
// ===================================
// Custom MarCom mail
// ===================================
stcblog_add_MarCommail($wp_customize);
// ===================================
// Custom socials icons
// ===================================
stcblog_add_socials(3, $wp_customize);
}
add_action('customize_register', 'stcblog_customize_register');
/**
* Calculates reading time according to the article word count.
* @return int Reading time.
* @author Ondrej Golasowski
*/
function reading_time() {
//Get contents of the current article.
$content = get_post_field( 'post_content', $post->ID );
$word_count = str_word_count( strip_tags( $content ) );
$readingtime = ceil($word_count / 200);
//Chooses correct word for specified interval.
switch($readingtime){
case 1:
$timer = " minuta";
break;
case 2:
case 3:
case 4:
$timer = " minuty";
break;
default:
$timer = " minut";
break;
}
$totalreadingtime = $readingtime . $timer;
return $totalreadingtime;
}
/**
* Exporting posts to csv file
* @author Petr Kučera
*/
/*
add_action( 'manage_posts_extra_tablenav', 'admin_post_list_top_export_button', 20, 1 );
function admin_post_list_top_export_button( $which ) {
global $typenow;
if ( 'post' === $typenow && 'top' === $which ) {
?>
<input type="submit" name="export_all_posts" id="export_all_posts" class="button button-primary" value="Exportovat do csv" />
<?php
}
}
add_action( 'init', 'func_export_all_posts' );
function func_export_all_posts() {
if(isset($_GET['export_all_posts'])) {
$arg = array(
'post_type' => 'post',
'post_status' => 'publish',
'posts_per_page' => -1,
);
global $post;
$arr_post = get_posts($arg);
if ($arr_post) {
header('Content-type: text/csv');
header('Content-Disposition: attachment; filename="wp.csv"');
header('Pragma: no-cache');
header('Expires: 0');
$file = fopen('php://output', 'w');
fputcsv($file, array('Post Title', 'URL'));
foreach ($arr_post as $post) {
setup_postdata($post);
fputcsv($file, array(get_the_title(), get_the_permalink()));
}
exit();
}
}
}
*/
/**
* Remove core update notifications for common users
* @author Petr Kučera
*/
function show_updated_only_to_admins()
{
if (!current_user_can('update_core')) {
remove_action( 'admin_notices', 'update_nag', 3 );
remove_action( 'network_admin_notices', 'update_nag', 3 );
}
}
add_action( 'admin_head', 'show_updated_only_to_admins', 1 );
/**
* Add multiple authors
* using Co-Author Plus plugin
* @author Petr Kučera
*/
if ( function_exists( 'coauthors_posts_links' ) ) {
coauthors_posts_links();
} else {
the_author_posts_link();
}
/**
* Desible admin bar on website, becouse cashing
* @author Petr Kucera, Matyas Koc
*/
show_admin_bar(false);
/**
* Remove info about wordpress for better security
* @author Petr Kucera, Matyas Koc
*/
remove_action('wp_head', 'wp_generator');
remove_action ('wp_head', 'rsd_link');
remove_action('wp_head', 'wlwmanifest_link');
if(is_user_logged_in()==false){
remove_action('wp_head', 'rest_output_link_wp_head', 10);
}
?>