-
-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathfunctions.php
More file actions
566 lines (495 loc) · 19.4 KB
/
functions.php
File metadata and controls
566 lines (495 loc) · 19.4 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
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
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
<?php
/*
* Copyright (C) 2018 p.pfeufer
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* Our Theme's namespace to keep the global namespace clear
*
* Ppfeufer\Theme\EVEOnline
*/
namespace Ppfeufer\Theme\EVEOnline;
// Define a couple of constants we might need.
// phpcs:disable
// Theme name
define(
constant_name: __NAMESPACE__ . '\THEME_NAME',
value: wp_get_theme()->get('Name')
);
// Theme version
define(
constant_name: __NAMESPACE__ . '\THEME_VERSION',
value: wp_get_theme()->get('Version')
);
// Theme directory (without trailing slash)
define(
constant_name: __NAMESPACE__ . '\THEME_DIRECTORY',
value: get_stylesheet_directory()
);
// Theme directory URI (without trailing slash)
define(
constant_name: __NAMESPACE__ . '\THEME_DIRECTORY_URI',
value: get_stylesheet_directory_uri()
);
// Theme slug
const THEME_SLUG = 'eve-online';
// Theme Sources directory (without trailing slash)
const THEME_SOURCES_DIRECTORY = THEME_DIRECTORY . '/Sources';
// Theme Library directory (without trailing slash)
const THEME_LIBRARY_DIRECTORY = THEME_SOURCES_DIRECTORY . '/Libs';
// Theme GitHub URI
const THEME_GITHUB_URI = 'https://github.com/ppfeufer/' . THEME_SLUG . '-wordpress-theme/';
// phpcs:enable
// phpcs:disable
// Include the theme autoloader
require_once THEME_SOURCES_DIRECTORY . '/autoload.php';
// Include the library autoloader
require_once THEME_LIBRARY_DIRECTORY . '/autoload.php';
// Load the themes' main class.
(new Main())->init();
// phpcs:enable
######
######
## OLD FUNCTIONS.PHP STARTS HERE
######
######
/**
* Just to make sure, if this line is not in wp-config, that our environment
* variable is still set right.
*
* This is to determine between "development/staging" and "live/production" environments.
* If you are testing this theme in your own test environment, make sure you
* set the following in your webservers vhosts config.
* SetEnv APPLICATION_ENV "development"
*/
// phpcs:disable
defined('APPLICATION_ENV') || define('APPLICATION_ENV', getenv('APPLICATION_ENV') && (str_contains(getenv('APPLICATION_ENV'), 'development') || str_contains(getenv('APPLICATION_ENV'), 'staging')) ? getenv('APPLICATION_ENV') : 'production');
// phpcs:enable
/**
* WP Filesystem API
*/
// phpcs:disable
require_once(ABSPATH . 'wp-admin/includes/class-wp-filesystem-base.php');
require_once(ABSPATH . 'wp-admin/includes/class-wp-filesystem-direct.php');
// phpcs:enable
if (!function_exists('\Ppfeufer\Theme\EVEOnline\eve_title_separator')) {
function eve_title_separator($separator): string {
$separator = '»';
return $separator;
}
}
// phpcs:disable
add_filter('document_title_separator', '\\Ppfeufer\Theme\EVEOnline\eve_title_separator');
// phpcs:enable
/**
* Remove integrated gallery styles in the content area of standard gallery shortcode.
* style in css.
*/
function eve_gallery_style_filter($a): string {
return '<div class="gallery">';
}
// phpcs:disable
add_filter('gallery_style', '\\Ppfeufer\Theme\EVEOnline\eve_gallery_style_filter');
// phpcs:enable
/**
* Return the Google font stylesheet URL, if available.
*
* The use of Source Sans Pro and Bitter by default is localized. For languages
* that use characters not supported by the font, the font can be disabled.
*
* @return string Font stylesheet or empty string if disabled.
* @since EVE Online Theme 1.0
*
*/
if (!function_exists('\Ppfeufer\Theme\EVEOnline\eve_fonts_url')) {
function eve_fonts_url(): string {
$fonts_url = '';
/**
* Translators: If there are characters in your language that are not
* supported by Source Sans Pro, translate this to 'off'. Do not translate
* into your own language.
*/
$source_sans_pro = _x('on', 'Source Sans Pro font: on or off', 'eve-online');
/**
* Translators: If there are characters in your language that are not
* supported by Bitter, translate this to 'off'. Do not translate into your
* own language.
*/
$bitter = _x('on', 'Bitter font: on or off', 'eve-online');
if ('off' !== $source_sans_pro || 'off' !== $bitter) {
$font_families = [];
if ('off' !== $source_sans_pro) {
$font_families[] = 'Source Sans Pro:300,400,700,300italic,400italic,700italic';
if ('off' !== $bitter) {
$font_families[] = 'Bitter:400,700';
$query_args = [
'family' => urlencode(implode('|', $font_families)),
'subset' => urlencode('latin,latin-ext'),
];
$fonts_url = add_query_arg($query_args, 'https://fonts.googleapis.com/css');
}
}
}
return $fonts_url;
}
} // END if(!\function_exists('\Ppfeufer\Theme\EVEOnline\eve_fonts_url'))
/**
* Adding the clearfix CSS class to every paragraph in .entry-content
*/
if (!function_exists('\Ppfeufer\Theme\EVEOnline\eve_paragraph_clearfix')) {
function eve_paragraph_clearfix($content): array|string|null {
return preg_replace('/<p([^>]+)?>/', '<p$1 class="clearfix">', $content);
}
}
// phpcs:disable
//\add_filter('the_content', '\\Ppfeufer\Theme\EVEOnline\eve_paragraph_clearfix');
// phpcs:enable
/**
* Picking up the first paragraph from the_content
*/
if (!function_exists('\Ppfeufer\Theme\EVEOnline\eve_first_paragraph')) {
function eve_first_paragraph($content): array|string|null {
return preg_replace('/<p([^>]+)?>/', '<p$1 class="intro">', $content, 1);
}
}
// phpcs:disable
//\add_filter('the_content', '\\Ppfeufer\Theme\EVEOnline\eve_first_paragraph');
// phpcs:enable
/**
* Adding a CSS class to the excerpt
* @param string $excerpt
* @return string
*/
if (!function_exists('\Ppfeufer\Theme\EVEOnline\eve_add_class_to_excerpt')) {
function eve_add_class_to_excerpt($excerpt): array|string {
return str_replace('<p', '<p class="excerpt"', $excerpt);
}
}
// phpcs:disable
add_filter('the_excerpt', '\\Ppfeufer\Theme\EVEOnline\eve_add_class_to_excerpt');
// phpcs:enable
/**
* Define theme's widget areas.
*/
function eve_widgets_init(): void {
$sidebars = [
[
'name' => __('Page Sidebar', 'eve-online'),
'id' => 'sidebar-page',
'description' => __('This sidebar will be displayed if the current is a page or your blog index.', 'eve-online'),
'before_widget' => '<aside><div id="%1$s" class="widget %2$s">',
'after_widget' => '</div></aside>',
'before_title' => '<h4 class="widget-title">',
'after_title' => '</h4>',
],
[
'name' => __('Post Sidebar', 'eve-online'),
'id' => 'sidebar-post',
'description' => __('This sidebar will always be displayed if the current is a post / blog article.', 'eve-online'),
'before_widget' => '<aside><div id="%1$s" class="widget %2$s">',
'after_widget' => '</div></aside>',
'before_title' => '<h4 class="widget-title">',
'after_title' => '</h4>',
],
[
'name' => __('General Sidebar', 'eve-online'),
'id' => 'sidebar-general',
'description' => __('General sidebar that is always right from the topic, below the side specific sidebars', 'eve-online'),
'before_widget' => '<aside><div id="%1$s" class="widget %2$s">',
'after_widget' => '</div></aside>',
'before_title' => '<h4 class="widget-title">',
'after_title' => '</h4>',
],
[
'name' => __('Home Column 1', 'eve-online'),
'id' => 'home-column-1',
'description' => __('Home Column 1', 'eve-online'),
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h2>',
'after_title' => '</h2>'
],
[
'name' => __('Home Column 2', 'eve-online'),
'id' => 'home-column-2',
'description' => __('Home Column 2', 'eve-online'),
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h2>',
'after_title' => '</h2>'
],
[
'name' => __('Home Column 3', 'eve-online'),
'id' => 'home-column-3',
'description' => __('Home Column 3', 'eve-online'),
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h2>',
'after_title' => '</h2>'
],
[
'name' => __('Home Column 4', 'eve-online'),
'id' => 'home-column-4',
'description' => __('Home Column 4', 'eve-online'),
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h2>',
'after_title' => '</h2>'
],
[
'name' => __('Footer Column 1', 'eve-online'),
'id' => 'footer-column-1',
'description' => __('Footer Column 1', 'eve-online'),
'before_widget' => '<aside><div id="%1$s" class="widget %2$s">',
'after_widget' => '</div></aside>',
'before_title' => '<h4>',
'after_title' => '</h4>'
],
[
'name' => __('Footer Column 2', 'eve-online'),
'id' => 'footer-column-2',
'description' => __('Footer Column 2', 'eve-online'),
'before_widget' => '<aside><div id="%1$s" class="widget %2$s">',
'after_widget' => '</div></aside>',
'before_title' => '<h4>',
'after_title' => '</h4>'
],
[
'name' => __('Footer Column 3', 'eve-online'),
'id' => 'footer-column-3',
'description' => __('Footer Column 3', 'eve-online'),
'before_widget' => '<aside><div id="%1$s" class="widget %2$s">',
'after_widget' => '</div></aside>',
'before_title' => '<h4>',
'after_title' => '</h4>'
],
[
'name' => __('Footer Column 4', 'eve-online'),
'id' => 'footer-column-4',
'description' => __('Footer Column 4', 'eve-online'),
'before_widget' => '<aside><div id="%1$s" class="widget %2$s">',
'after_widget' => '</div></aside>',
'before_title' => '<h4>',
'after_title' => '</h4>'
],
[
'name' => __('Header Widget Area', 'eve-online'),
'id' => 'header-widget-area',
'description' => __('Header Widget Area', 'eve-online'),
'before_widget' => '<aside><div id="%1$s" class="widget %2$s">',
'after_widget' => '</div></aside>',
'before_title' => '<h4>',
'after_title' => '</h4>'
],
];
foreach ($sidebars as $sidebar) {
register_sidebar($sidebar);
}
}
// phpcs:disable
add_action('init', '\\Ppfeufer\Theme\EVEOnline\eve_widgets_init');
// phpcs:enable
/**
* Replaces the excerpt "more" text by a link
*/
if (!function_exists('\Ppfeufer\Theme\EVEOnline\eve_excerpt_more')) {
function eve_excerpt_more($more): string {
return ' ' . $more . '<br/><a class="read-more" href="' . get_permalink(get_the_ID()) . '">' . __('Read More', 'eve-online') . '</a>';
}
}
// phpcs:disable
add_filter('excerpt_more', '\\Ppfeufer\Theme\EVEOnline\eve_excerpt_more');
// phpcs:enable
/**
* prevent scrolling when using more-tag
*/
function eve_remove_more_link_scroll($link): array|string|null {
return preg_replace('|#more-[0-9]+|', '', $link);
}
// phpcs:disable
add_filter('the_content_more_link', '\\Ppfeufer\Theme\EVEOnline\eve_remove_more_link_scroll');
// phpcs:enable
/**
* Adds custom classes to the array of body classes.
*/
if (!function_exists('\Ppfeufer\Theme\EVEOnline\eve_body_classes')) {
function eve_body_classes($classes): array {
if (!is_multi_author()) {
$classes[] = 'single-author';
}
return $classes;
}
}
// phpcs:disable
add_filter('body_class', '\\Ppfeufer\Theme\EVEOnline\eve_body_classes');
// phpcs:enable
/**
* Add post ID attribute to image attachment pages prev/next navigation.
*/
function eve_enhanced_image_navigation($url): string {
global $post;
if (wp_attachment_is_image($post->ID)) {
$url .= '#main';
} // END if(wp_attachment_is_image($post->ID))
return $url;
}
// phpcs:disable
add_filter('attachment_link', '\\Ppfeufer\Theme\EVEOnline\eve_enhanced_image_navigation');
// phpcs:enable
/**
* Define default page titles.
*/
function eve_wp_title($title, $sep): string {
global $paged, $page;
if (is_feed()) {
return $title;
}
// Add the site name.
$title .= get_bloginfo('name');
// Add the site description for the home/front page.
$site_description = get_bloginfo('description', 'display');
if ($site_description && (is_home() || is_front_page())) {
$title = "$title $sep $site_description";
}
// Add a page number if necessary.
if ($paged >= 2 || $page >= 2) {
$title .= ' ' . $sep . ' ' . sprintf(__('Page %s', 'eve-online'), max($paged, $page));
} // END if($paged >= 2 || $page >= 2)
return $title;
}
// phpcs:disable
add_filter('wp_title', '\\Ppfeufer\Theme\EVEOnline\eve_wp_title', 10, 2);
// phpcs:enable
/**
* Link Pages
* @param array $args
* @return void
* Modification of wp_link_pages() with an extra element to highlight the current page.
* @author toscho
* @link http://wordpress.stackexchange.com/questions/14406/how-to-style-current-page-number-wp-link-pages
*/
function eve_link_pages(array $args = []): void {
$arguments = apply_filters('wp_link_pages_args', wp_parse_args($args, [
'before' => '<p>' . __('Pages:', 'eve-online'),
'after' => '</p>',
'before_link' => '',
'after_link' => '',
'current_before' => '',
'current_after' => '',
'link_before' => '',
'link_after' => '',
'pagelink' => '%',
'echo' => 1
]));
global $page, $numpages, $multipage, $more;
if (!$multipage) {
return;
}
$output = $arguments['before'];
for ($i = 1; $i < ($numpages + 1); $i++) {
$j = str_replace('%', $i, $arguments['pagelink']);
$output .= ' ';
if ($i !== $page || (!$more && 1 === $page)) {
$output .= $arguments['before_link'] . _wp_link_page($i) . $arguments['link_before'] . $j . $arguments['link_after'] . '</a>' . $arguments['after_link'];
} else {
$output .= $arguments['current_before'] . $arguments['link_before'] . '<a>' . $j . '</a>' . $arguments['link_after'] . $arguments['current_after'];
}
}
echo $output . $arguments['after'];
}
/**
* Disable Smilies
*
* @todo Make it configurable
*/
// phpcs:disable
add_filter('option_use_smilies', '__return_false');
// phpcs:enable
/* comment form
* -------------------------------------------------------------------------- */
function eve_comment_form_fields($fields): array {
$commenter = wp_get_current_commenter();
$req = get_option('require_name_email');
$aria_req = ($req ? " aria-required='true' required" : '');
$html5 = current_theme_supports('html5', 'comment-form') ? 1 : 0;
$consent = empty($commenter['comment_author_email']) ? '' : ' checked="checked"';
$fields = [
'author' => '<div class="row"><div class="form-group comment-form-author col-md-4">'
. ' <input class="form-control" id="author" name="author" type="text" value="' . esc_attr($commenter['comment_author']) . '" size="30"' . $aria_req . ' placeholder="' . __('Name', 'eve-online') . ($req ? ' *' : '') . '" />'
. '</div>',
'email' => '<div class="form-group comment-form-email col-md-4">'
. ' <input class="form-control" id="email" name="email" ' . ($html5 ? 'type="email"' : 'type="text"') . ' value="' . esc_attr($commenter['comment_author_email']) . '" size="30"' . $aria_req . ' placeholder="' . __('Email', 'eve-online') . ($req ? ' *' : '') . '" />'
. '</div>',
'url' => '<div class="form-group comment-form-url col-md-4">'
. ' <input class="form-control" id="url" name="url" ' . ($html5 ? 'type="url"' : 'type="text"') . ' value="' . esc_attr($commenter['comment_author_url']) . '" size="30" placeholder="' . __('Website', 'eve-online') . '" />'
. '</div></div>',
// GPDR compliance
'cookies' => '<div class="row"><div class="form-group checkbox comment-form-cookies-consent col-lg-12">'
. '<label for="wp-comment-cookies-consent">'
. '<input id="wp-comment-cookies-consent" name="wp-comment-cookies-consent" type="checkbox" value="yes"' . $consent . ' />'
. __('Save my name, email, and website in this browser for the next time I comment.', 'eve-online') . '</label>'
. '</div></div>',
];
return $fields;
}
// phpcs:disable
add_filter('comment_form_default_fields', '\\Ppfeufer\Theme\EVEOnline\eve_comment_form_fields');
// phpcs:enable
function eve_comment_form($args): array {
$args['comment_field'] = '<div class="row"><div class="form-group comment-form-comment col-lg-12">'
. ' <textarea class="form-control" id="comment" name="comment" cols="45" rows="8" aria-required="true" required placeholder="' . _x('Comment', 'noun', 'eve-online') . '"></textarea>'
. '</div></div>';
$args['class_submit'] = 'btn btn-default';
return $args;
}
// phpcs:disable
add_filter('comment_form_defaults', '\\Ppfeufer\Theme\EVEOnline\eve_comment_form');
// phpcs:enable
function eve_move_comment_field_to_bottom($fields): array {
$comment_field = $fields['comment'];
$gpdr_field = $fields['cookies'];
unset($fields['comment'], $fields['cookies']);
$fields['comment'] = $comment_field;
$fields['cookies'] = $gpdr_field;
return $fields;
}
// phpcs:disable
add_filter('comment_form_fields', '\\Ppfeufer\Theme\EVEOnline\eve_move_comment_field_to_bottom');
// phpcs:enable
/**
* Adding some usefull parameters to the Youtube link when using oEmbed
*
* @param string $html
* @return string
*/
function eve_enable_youtube_jsapi(string $html): string {
if (str_contains($html, 'youtube.com/embed/')) {
$html = str_replace('?feature=oembed', '?feature=oembed&enablejsapi=1&origin=' . esc_url(home_url()) . '&rel=0', $html);
}
return $html;
}
// phpcs:disable
add_filter('oembed_result', '\\Ppfeufer\Theme\EVEOnline\eve_enable_youtube_jsapi');
// phpcs:enable
// phpcs:enable
/**
* Theme credits in footer
*/
function eve_theme_credits(): void {
echo sprintf(__('(%1$s design and programming by %2$s)', 'eve-online'), '<a href="https://github.com/ppfeufer/eve-online-wordpress-theme">EVE Online theme</a>', 'Rounon Dax');
}
// phpcs:disable
add_action('eve_online_theme_credits', '\\Ppfeufer\Theme\EVEOnline\eve_theme_credits');
// phpcs:enable