forked from Piratenpartei/Pirate-Rogue
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.php
482 lines (406 loc) · 20.3 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
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
<?php
/*-----------------------------------------------------------------------------------*/
/* Pirate Rogue Theme
* Based on Uku Theme by Elmastudio
*/
/*-----------------------------------------------------------------------------------*/
/*-----------------------------------------------------------------------------------*/
/* Sets up theme defaults and registers support for various WordPress features.
/*-----------------------------------------------------------------------------------*/
function pirate_rogue_setup() {
// Translations
load_theme_textdomain( 'pirate-rogue', get_template_directory() . '/languages' );
// Add default posts and comments RSS feed links to head
add_theme_support( 'automatic-feed-links' );
// Let WordPress manage the document title.
add_theme_support( 'title-tag' );
// This theme uses wp_nav_menu().
register_nav_menus( array (
'primary' => esc_html__( 'Main Menu', 'pirate-rogue'),
'social' => esc_html__( 'Social Icons', 'pirate-rogue'),
'social-front' => esc_html__( 'Social Icons (in About section)', 'pirate-rogue'),
'social-footer' => esc_html__( 'Social Icons (in Footer)', 'pirate-rogue'),
'footer-one' => esc_html__( 'Footer 1', 'pirate-rogue'),
'footer-two' => esc_html__( 'Footer 2', 'pirate-rogue'),
'footer-three' => esc_html__( 'Footer 3', 'pirate-rogue'),
'footer-four' => esc_html__( 'Footer 4', 'pirate-rogue'),
) );
// Switch default core markup to output valid HTML5.
add_theme_support( 'html5', array(
'gallery',
'caption',
) );
// Implement the Custom Header feature
require get_template_directory() . '/inc/custom-header.php';
// Enable support for Video Post Formats.
add_theme_support( 'post-formats', array (
'video',
) );
// Enable support for custom logo.
add_theme_support( 'custom-logo', array(
'height' => 236,
'width' => 520,
'flex-height' => true,
'flex-width' => true,
) );
/* Excerpts für Seiten */
add_post_type_support('page', 'excerpt');
// This theme uses post thumbnails.
add_theme_support( 'post-thumbnails' );
// Adding several sizes for Post Thumbnails
add_image_size( 'pirate-rogue-standard-blog', 1024, 576, true );
add_image_size( 'pirate-rogue-featured', 1440, 530, true );
add_image_size( 'pirate-rogue-featured-big', 1440, 690, true );
add_image_size( 'pirate-rogue-bigthumb', 1440, 580, true );
add_image_size( 'pirate-rogue-front-big', 1260, 709, true );
add_image_size( 'pirate-rogue-gallery', 600, 600, true );
add_image_size( 'pirate-rogue-front-small', 800, 450, true );
add_image_size( 'pirate-rogue-featured-bottom', 800, 450, true );
}
add_action( 'init', 'pirate_rogue_setup' );
/*-----------------------------------------------------------------------------------*/
/* Sets up the content width value based on the theme's design.
/*-----------------------------------------------------------------------------------*/
if ( ! isset( $content_width ) ) {
$content_width = 900;
}
function pirate_rogue_content_width() {
if ( is_page_template('full-width.php') ) {
$GLOBALS['content_width'] = 1500;
}
}
add_action( 'template_redirect', 'pirate_rogue_content_width' );
/*-----------------------------------------------------------------------------------*/
/* JavaScript detection.
/* Adds a `js` class to the root `<html>` element when JavaScript is detected.
/*-----------------------------------------------------------------------------------*/
function pirate_rogue_javascript_detection() {
echo "<script>(function(html){html.className = html.className.replace(/\bno-js\b/,'js')})(document.documentElement);</script>\n";
}
add_action( 'wp_head', 'pirate_rogue_javascript_detection', 0 );
/*-----------------------------------------------------------------------------------*/
/* Registre Scripts
/*-----------------------------------------------------------------------------------*/
function pirate_rogue_register_scripts() {
// Register Slick
wp_register_script('pirate-rogue-slick', get_template_directory_uri() . '/js/slick/slick-1.8.1.min.js', array('jquery') );
// Misc jQuery Plugins
wp_register_script( 'pirate-rogue-jquery-misc', get_template_directory_uri() . '/js/jquery.misc.js', array( 'jquery' ), '1.1' );
}
add_action('init', 'pirate_rogue_register_scripts');
/*-----------------------------------------------------------------------------------*/
/* Enqueue scripts and styles that are beeing used always
/*-----------------------------------------------------------------------------------*/
function pirate_rogue_base_scripts() {
global $wp_styles;
// Loads JavaScript to pages with the comment form to support sites with threaded comments (when in use)
if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
wp_enqueue_script( 'comment-reply' );
}
$theme_data = wp_get_theme();
$theme_version = $theme_data->Version;
// Loads stylesheets.
wp_enqueue_style( 'pirate-rogue-style', get_stylesheet_uri(), array(), $theme_version );
// Loads Custom JavaScript functionality
wp_enqueue_script( 'pirate-rogue-script', get_template_directory_uri() . '/js/functions.min.js', array( 'jquery' ), $theme_version, true );
wp_localize_script( 'pirate-rogue-script', 'screenReaderText', array(
'expand' => '<span class="screen-reader-text">' . esc_html__( 'Expand Child Menu', 'pirate-rogue') . '</span>',
'collapse' => '<span class="screen-reader-text">' . esc_html__( 'Collapse Child Menu', 'pirate-rogue') . '</span>',
) );
if (is_home() &&
( '' != get_theme_mod( 'pirate_rogue_featuredtag' ) || '' != get_theme_mod( 'pirate_rogue_featuredcat' ) )) {
wp_enqueue_script( 'pirate-rogue-slick' );
}
wp_enqueue_script( 'pirate-rogue-jquery-misc' );
}
add_action( 'wp_enqueue_scripts', 'pirate_rogue_base_scripts' );
/*-----------------------------------------------------------------------------------*/
/* Admin Styles
/*-----------------------------------------------------------------------------------*/
function pirate_rogue_admin_style() {
$theme_data = wp_get_theme();
$theme_version = $theme_data->Version;
// This theme styles the visual editor to resemble the theme style.
// add_editor_style( array( '/css/admin.css') );
wp_register_style( 'themeadminstyle', get_template_directory_uri().'/css/admin.css',array(), $theme_version );
wp_enqueue_style( 'themeadminstyle' );
wp_enqueue_media();
}
add_action( 'admin_enqueue_scripts', 'pirate_rogue_admin_style' );
/*-----------------------------------------------------------------------------------*/
/* Get our wp_nav_menu() fallback, wp_page_menu(), to show a home link.
/*-----------------------------------------------------------------------------------*/
function pirate_rogue_page_menu_args( $args ) {
$args['show_home'] = true;
return $args;
}
add_filter( 'wp_page_menu_args', 'pirate_rogue_page_menu_args' );
/*-----------------------------------------------------------------------------------*/
/* Sets the authordata global when viewing an author archive.
/*-----------------------------------------------------------------------------------*/
function pirate_rogue_setup_author() {
global $wp_query;
if ( $wp_query->is_author() && isset( $wp_query->post ) ) {
$GLOBALS['authordata'] = get_userdata( $wp_query->post->post_author );
}
}
add_action( 'wp', 'pirate_rogue_setup_author' );
/*-----------------------------------------------------------------------------------*/
/* Add title to custom menu
/*-----------------------------------------------------------------------------------*/
function pirate_rogue_get_menu_by_location( $location ) {
if( empty($location) ) return false;
$locations = get_nav_menu_locations();
if( ! isset( $locations[$location] ) ) return false;
$menu_obj = get_term( $locations[$location], 'nav_menu' );
return $menu_obj;
}
/*-----------------------------------------------------------------------------------*/
/* Add custom max excerpt lengths.
/*-----------------------------------------------------------------------------------*/
function pirate_rogue_custom_excerpt_length( $length ) {
return 23;
}
add_filter( 'excerpt_length', 'pirate_rogue_custom_excerpt_length', 999 );
/*-----------------------------------------------------------------------------------*/
/* Replace "[...]" with custom read more in excerpts.
/*-----------------------------------------------------------------------------------*/
function pirate_rogue_excerpt_more( $more ) {
global $post;
return '…';
}
add_filter( 'excerpt_more', 'pirate_rogue_excerpt_more' );
/*-----------------------------------------------------------------------------------*/
/* Featured Slider Function
/*-----------------------------------------------------------------------------------*/
function pirate_rogue_has_featured_posts( $minimum = 1 ) {
if ( is_paged() )
return false;
$minimum = absint( $minimum );
$featured_posts = apply_filters( 'uku_get_featured_posts', array() );
if ( ! is_array( $featured_posts ) )
return false;
if ( $minimum > count( $featured_posts ) )
return false;
return true;
}
/*-----------------------------------------------------------------------------------*/
/* Add Twitter Username to User Profile
/*-----------------------------------------------------------------------------------*/
function add_twitter_contactmethod( $contactmethods ) {
// Add Twitter
if ( !isset( $contactmethods['twitter'] ) )
$contactmethods['twitter'] = 'Twitter Name';
return $contactmethods;
}
add_filter( 'user_contactmethods', 'add_twitter_contactmethod', 10, 1 );
/*-----------------------------------------------------------------------------------*/
/* Add Theme Customizer CSS
/*-----------------------------------------------------------------------------------
function pirate_rogue_customize_css() {
$customcss = '';
if ('' != get_theme_mod( 'pirate_rogue_custom_css' ) ) {
$customcss .= get_theme_mod('pirate_rogue_custom_css');
}
if (!empty($customcss)) {
echo '<style type="text/css">';
echo $customcss;
echo '</style>'."\n";
}
}
add_action( 'wp_head', 'pirate_rogue_customize_css');
*/
/*-----------------------------------------------------------------------------------*/
/* Add Google Webmaster Tools Verification
/*-----------------------------------------------------------------------------------*/
function pirate_rogue_google_verification() {
$customcss = '';
if ('' != get_theme_mod( 'pirate_rogue_google_wmt_verification_text' ) ) {
$verificationcode = get_theme_mod('pirate_rogue_google_wmt_verification_text');
}
if (!empty($verificationcode)) {
echo '<meta name="google-site-verification" content="'.$verificationcode.'" />'."\n";
}
}
add_action( 'wp_head', 'pirate_rogue_google_verification');
/*-----------------------------------------------------------------------------------*/
/* Add Canonical URL if need
/*-----------------------------------------------------------------------------------*/
function pirate_rogue_add_canonical() {
if (is_single()) {
$canonical = get_post_meta( get_the_ID(), 'pirate_rogue_canonical', true );
if ($canonical) {
$canonical = esc_url( $canonical );
if ($canonical) {
echo '<link rel="canonical" href="'.$canonical.'" />'."\n";
}
}
}
}
add_action( 'wp_head', 'pirate_rogue_add_canonical');
/*-----------------------------------------------------------------------------------*/
/* Remove inline styles printed when the gallery shortcode is used.
/*-----------------------------------------------------------------------------------*/
add_filter('use_default_gallery_style', '__return_false');
if ( ! function_exists( 'pirate_rogue_comment' ) ) :
/*-----------------------------------------------------------------------------------*/
/* Comments template pirate_rogue_comment
/*-----------------------------------------------------------------------------------*/
function pirate_rogue_comment( $comment, $args, $depth ) {
$GLOBALS['comment'] = $comment;
switch ( $comment->comment_type ) :
case '' :
?>
<li <?php comment_class(); ?> id="li-comment-<?php comment_ID(); ?>">
<div id="comment-<?php comment_ID(); ?>" class="comment">
<div class="comment-avatar">
<?php echo get_avatar( $comment, 140 ); ?>
</div>
<div class="comment-wrap">
<div class="comment-details">
<div class="comment-author">
<?php printf( ( '%s' ), wp_kses_post( sprintf( '%s', get_comment_author_link() ) ) ); ?>
</div><!-- end .comment-author -->
<div class="comment-meta">
<span class="comment-time"><a href="<?php echo esc_url( get_comment_link( $comment->comment_ID ) ); ?>">
<?php
/* translators: 1: date */
printf( esc_html__( '%1$s', 'pirate-rogue'),
get_comment_date());
?></a>
</span>
<?php edit_comment_link( esc_html__(' Edit', 'pirate-rogue'), '<span class="comment-edit">', '</span>'); ?>
</div><!-- end .comment-meta -->
</div><!-- end .comment-details -->
<div class="comment-text">
<?php comment_text(); ?>
<?php if ( $comment->comment_approved == '0' ) : ?>
<p class="comment-awaiting-moderation"><?php esc_html_e( 'Your comment is awaiting moderation.', 'pirate-rogue'); ?></p>
<?php endif; ?>
</div><!-- end .comment-text -->
<?php if ( comments_open () ) : ?>
<div class="comment-reply"><?php comment_reply_link( array_merge( $args, array( 'reply_text' => esc_html__( 'Reply', 'pirate-rogue'), 'depth' => $depth, 'max_depth' => $args['max_depth'] ) ) ); ?></div>
<?php endif; ?>
</div><!-- end .comment-wrap -->
</div><!-- end .comment -->
<?php
break;
case 'pingback' :
case 'trackback' :
?>
<li class="pingback">
<p><?php esc_html_e( 'Pingback:', 'pirate-rogue'); ?> <?php comment_author_link(); ?></p>
<p class="pingback-edit"><?php edit_comment_link(); ?></p>
<?php
break;
endswitch;
}
endif;
/*-----------------------------------------------------------------------------------*/
/* Remove recent comments default css
/*-----------------------------------------------------------------------------------*/
function remove_recent_comments_style() {
global $wp_widget_factory;
remove_action('wp_head', array($wp_widget_factory->widgets['WP_Widget_Recent_Comments'], 'recent_comments_style'));
}
add_action('widgets_init', 'remove_recent_comments_style');
/*-----------------------------------------------------------------------------------*/
/* Register widgetized areas
/*-----------------------------------------------------------------------------------*/
function pirate_rogue_widgets_init() {
register_sidebar( array (
'name' => esc_html__( 'Blog Sidebar', 'pirate-rogue'),
'id' => 'sidebar-1',
'description' => esc_html__( 'Widgets appear in the default sidebar.', 'pirate-rogue'),
'before_widget' => '<section id="%1$s" class="widget %2$s">',
'after_widget' => "</section>",
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
) );
register_sidebar( array (
'name' => esc_html__( 'Page Sidebar', 'pirate-rogue'),
'id' => 'sidebar-2',
'description' => esc_html__( 'Widgets appear in the sidebar on pages.', 'pirate-rogue'),
'before_widget' => '<section id="%1$s" class="widget %2$s">',
'after_widget' => "</section>",
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
) );
register_sidebar( array (
'name' => esc_html__( 'Off Canvas Widget Area', 'pirate-rogue'),
'id' => 'sidebar-offcanvas',
'description' => esc_html__( 'Widgets appear in the off canvas area.', 'pirate-rogue'),
'before_widget' => '<section id="%1$s" class="widget %2$s">',
'after_widget' => "</section>",
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
) );
register_sidebar( array (
'name' => esc_html__( 'Big Footer Instagram Widget Area', 'pirate-rogue'),
'id' => 'sidebar-instagram',
'description' => esc_html__( 'Widget area to show fotos from Instagram in a big one-column footer area.', 'pirate-rogue'),
'before_widget' => '<section id="%1$s" class="widget %2$s">',
'after_widget' => "</section>",
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
) );
}
add_action( 'widgets_init', 'pirate_rogue_widgets_init' );
/*-----------------------------------------------------------------------------------*/
/* Admin Init functions
/*-----------------------------------------------------------------------------------*/
function pirate_rogue_admin_init() {
remove_post_type_support( 'page', 'comments' );
// Keine Kommentar/Dkussionsmetabox auf Seiten
}
add_action('admin_init', 'pirate_rogue_admin_init');
/*-----------------------------------------------------------------------------------*/
/* No comments on attachments please
/*-----------------------------------------------------------------------------------*/
function pirate_rogue_filter_media_comment_status( $open, $post_id ) {
$post = get_post( $post_id );
if( $post->post_type == 'attachment' ) {
return false;
}
return $open;
}
add_filter( 'comments_open', 'pirate_rogue_filter_media_comment_status', 10 , 2 );
/*-----------------------------------------------------------------------------------*/
/* Load defaults
/*-----------------------------------------------------------------------------------*/
require_once( get_template_directory() . '/inc/defaults.php' );
/*-----------------------------------------------------------------------------------*/
/* Load helper functions
/*-----------------------------------------------------------------------------------*/
require_once( get_template_directory() . '/inc/helper-functions.php' );
/*-----------------------------------------------------------------------------------*/
/* Custom Fields and metaboxes belonging to them
/*-----------------------------------------------------------------------------------*/
require get_template_directory() . '/inc/custom-fields.php';
/*-----------------------------------------------------------------------------------*/
/* Customizer changes to uku
/*-----------------------------------------------------------------------------------*/
require get_template_directory() . '/inc/xwolf-customizer.php';
/*-----------------------------------------------------------------------------------*/
/* Additional features to allow styling of the templates.
/*-----------------------------------------------------------------------------------*/
require get_template_directory(). '/inc/template-functions.php' ;
/*-----------------------------------------------------------------------------------*/
/* Custom template tags for this theme.
/*-----------------------------------------------------------------------------------*/
require get_template_directory() . '/inc/template-tags.php';
/*-----------------------------------------------------------------------------------*/
/* Grab the Theme Custom shortcodes.
/*-----------------------------------------------------------------------------------*/
require( get_template_directory() . '/inc/shortcodes.php' );
/*-----------------------------------------------------------------------------------*/
/* Load Plugin Specials
/*-----------------------------------------------------------------------------------*/
require get_template_directory() . '/inc/pluginsupport.php';
/*-----------------------------------------------------------------------------------*/
/* Load Jetpack compatibility file.
/*-----------------------------------------------------------------------------------*/
require get_template_directory() . '/inc/jetpack.php';
/*-----------------------------------------------------------------------------------*/
/* This is the end of the code as we know it
/*-----------------------------------------------------------------------------------*/