forked from Lightweb-Media/gp_childtheme
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfunctions.php
executable file
·269 lines (212 loc) · 8.12 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
<?php
/**
* GeneratePress child theme functions and definitions.
*
* Add your custom PHP in this file.
* Only edit this file if you have direct access to it on your server (to fix errors if they happen).
*/
/*
KOMPAKT == 360Kompakt
*/
define( 'KOMPAKT_THEME_URL', get_stylesheet_directory_uri() );
define( 'KOMPAKT_THEME_PATH', get_stylesheet_directory() );
define( 'KOMPAKT_VERSION', '1.0.0' );
function kompakt_enqueue_child_theme_styles() {
wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
wp_enqueue_style( 'kompakt-style', KOMPAKT_THEME_URL . '/build/main.css', ['parent-style'], filemtime( KOMPAKT_THEME_PATH . '/build/main.css' ) );
wp_enqueue_script( 'kompakt-slider', KOMPAKT_THEME_URL . '/build/slider.js', [], filemtime( KOMPAKT_THEME_PATH . '/build/slider.js' ), true );
}
add_action( 'wp_enqueue_scripts', 'kompakt_enqueue_child_theme_styles' );
function backend_assets() {
wp_enqueue_script(
'kompakt-be-js',
KOMPAKT_THEME_URL . '/build/backend.js',
['wp-block-editor', 'wp-blocks', 'wp-i18n', 'wp-element', 'wp-editor', 'wp-api', 'wp-polyfill','media-upload', 'thickbox'],,
filemtime( KOMPAKT_THEME_PATH . '/build/backend.js' ),
true
);
}
add_action('admin_enqueue_scripts', 'backend_assets');
add_image_size( 'widget-slider-770', 770, 450, true );
add_image_size( 'widget-slider-450', 450, 263, true );
function add_custom_sizes_to_gutenberg( $sizes ) {
return array_merge( $sizes, [
'widget-slider-770' => __('Slider 770', 'kompakt'),
'widget-slider-450' => __('Slider 450', 'kompakt'),
] );
}
add_filter( 'image_size_names_choose', 'add_custom_sizes_to_gutenberg' );
// includes
require_once KOMPAKT_THEME_PATH . '/classes/CheckedBy.php';
add_action( 'init', function() {
new \Threek\CheckedBy;
} );
require_once KOMPAKT_THEME_PATH . '/shortcodes.php';
// Change 404 Page Title
add_filter( 'generate_404_title','generate_custom_404_title' );
function generate_custom_404_title()
{
return __('<center>Nichts gefunden</center>', 'kompakt');
}
// Change 404 Page Text
add_filter( 'generate_404_text','generate_custom_404_text' );
function generate_custom_404_text()
{
return __('<center>Haben Sie sich verirrt? Nutzen Sie unsere Suche oder klicken Sie auf einen unserer neuesten Beiträge.</center>', 'kompakt');
}
// Change 404 Page Search Form
function wpdocs_my_search_form( $form ) {
$form = '<form role="search" method="get" action="/" class="wp-block-search__button-inside wp-block-search__text-button wp-block-search"><label for="wp-block-search__input-1" class="wp-block-search__label screen-reader-text">Suchen</label><div class="wp-block-search__inside-wrapper " ><input type="search" id="wp-block-search__input-1" class="wp-block-search__input wp-block-search__input " name="s" value="" placeholder="Suchen..." required /><button type="submit" class="wp-block-search__button wp-element-button">Suchen</button></div></form>';
return $form;
}
add_filter( 'get_search_form', 'wpdocs_my_search_form' );
// Author Box
function show_author_box(){
global $post;
$author_id = get_post_field('post_author' , $post->ID);
// Check if is not 404 Page
if(!is_404() && is_single()){
?>
<div class="author-box">
<div class="author-box-avatar">
<img alt=<?php _e("Autorenfoto", "kompakt"); ?> title=<?php _e("Autorenfoto", "kompakt"); ?>
src=<?php echo get_avatar_url($author_id); ?> />
</div>
<div class="author-box-meta">
<div class="author-box_name"><?php echo '<span>'. get_the_author() . '</span>'; ?></div>
<div class="author-box_bio">
<?php echo get_the_author_meta("description", $author_id); ?>
</div>
</div>
</div>
<?php
}
}
add_action('generate_after_content', 'show_author_box', 10);
// Headline on home page
add_action( 'generate_before_main_content', function() {
if ( is_front_page() && is_home() ) {
?>
<div class="home-headline">
<div class="wp-block-group__inner-container">
<h2><?php _e('Aktuelle Beiträge', 'kompakt'); ?></h2>
</div>
</div>
<?php
}
} );
// Featured posts on home page
add_action( 'generate_after_header', function() {
if ( is_front_page() && is_home() ) {
$sticky = get_option('sticky_posts');
if (!empty($sticky)) {
$args = array(
'post__in' => $sticky,
'posts_per_page' => '3',
'ignore_sticky_posts' => 1
);
$featuredPosts = new WP_Query($args);
?> <section class="posts-list featured">
<?php
if($featuredPosts->have_posts()){
while ($featuredPosts->have_posts()) : $featuredPosts->the_post();
get_template_part('template-parts/custom-post-loop');
endwhile;
}
?>
</section> <?php
}
}
});
function target_main_category_query_with_conditional_tags( $query ) {
if ( ! is_admin() && $query->is_main_query() ) {
if ( is_home() ) {
$sticky = get_option('sticky_posts');
$query->set( 'post__not_in', $sticky);
}
}
}
add_action( 'pre_get_posts', 'target_main_category_query_with_conditional_tags' );
/* Get categories of Post
Output (string): "Cat1, Cat2"
*/
function show_all_categories_of_post(){
$post_categories = wp_get_post_categories( get_the_ID(), array( 'fields' => 'names' ) );
if( $post_categories ){
echo '<span class="category-list">'. implode(',',$post_categories) .'</span>';
}
}
/**
*
* Add custom user profile information
*
*/
// Add custom user meta fields
function add_custom_user_profile_fields($user) {
wp_enqueue_media();
?>
<h3><?php _e('Profile Picture', 'kompakt'); ?></h3>
<table class="form-table">
<tr>
<th><label for="profile_picture"><?php _e('Please upload your profile picture.', 'kompakt'); ?></label></th>
<td>
<?php
$profile_picture = get_the_author_meta('profile_picture', $user->ID);
if (!empty($profile_picture)) {
echo '<img src="' . esc_url($profile_picture) . '" width="100" /><br />';
}
?>
<input type="text" style="display:none;" name="profile_picture" id="profile_picture"
value="<?php echo esc_attr($profile_picture); ?>" class="regular-text" /><br />
<input type="button" class="button" value="<?php _e('Upload Image', 'kompakt'); ?>"
id="upload_profile_picture_button" />
</td>
</tr>
</table>
<?php
}
add_action('show_user_profile', 'add_custom_user_profile_fields');
add_action('edit_user_profile', 'add_custom_user_profile_fields');
// Save custom user meta fields
function save_custom_user_profile_fields($user_id) {
if (!current_user_can('edit_user', $user_id)) {
return false;
}
update_user_meta($user_id, 'profile_picture', $_POST['profile_picture']);
}
add_action('personal_options_update', 'save_custom_user_profile_fields');
add_action('edit_user_profile_update', 'save_custom_user_profile_fields');
function modify_get_avatar_url_defaults($url, $id) {
if(get_the_author_meta('profile_picture', $id)){
return get_the_author_meta('profile_picture', $id);
}
return $url;
}
// add the filter
add_filter( "get_avatar_url", "modify_get_avatar_url_defaults", 10, 3 );
// Recommended posts on post single
add_action( 'generate_after_content', function() {
$categories = get_the_category();
if ( ! $categories ) {
return;
}
$category_id = get_cat_ID($categories[0]->name);
$args = array(
'cat' => $category_id,
'posts_per_page' => '3'
);
$featuredPosts = new WP_Query($args);
if($featuredPosts->have_posts() && is_single()){
?>
<h3 class="recommended-headline">
<?php _e('Weitere Beiträge dieser Kategorie', 'kompakt'); ?>
</h3>
<section class="posts-list recommended">
<?php
while ($featuredPosts->have_posts()) : $featuredPosts->the_post();
get_template_part('template-parts/custom-post-loop');
endwhile;
?>
</section> <?php
}
}, 20);