Skip to content

Commit

Permalink
uncool copy from _360kompakt-1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
christopher1 committed Apr 24, 2023
1 parent 9fbdb4c commit d3b251c
Showing 1 changed file with 104 additions and 31 deletions.
135 changes: 104 additions & 31 deletions functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* Only edit this file if you have direct access to it on your server (to fix errors if they happen).
*/
/*
KOMPAKT == 360Kompakt
*/

Expand All @@ -24,7 +25,7 @@ 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'],
['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
);
Expand Down Expand Up @@ -56,15 +57,15 @@ function add_custom_sizes_to_gutenberg( $sizes ) {
add_filter( 'generate_404_title','generate_custom_404_title' );
function generate_custom_404_title()
{
return __('<center>Nichts gefunden</center>', 'kompakt');
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');
return __('<center>Haben Sie sich verirrt? Nutzen Sie unsere Suche oder klicken Sie auf einen unserer neuesten Beiträge.</center>', 'kompakt');
}


Expand All @@ -84,7 +85,7 @@ function show_author_box(){
$author_id = get_post_field('post_author' , $post->ID);

// Check if is not 404 Page
if(!is_404()){
if(!is_404() && is_single()){
?>
<div class="author-box">
<div class="author-box-avatar">
Expand All @@ -97,8 +98,8 @@ function show_author_box(){
<?php echo get_the_author_meta("description", $author_id); ?>
</div>
</div>
</div>
<?php
</div>
<?php
}
}

Expand All @@ -108,39 +109,56 @@ function show_author_box(){
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 class="home-headline">
<div class="wp-block-group__inner-container">
<h2><?php _e('Aktuelle Beiträge', 'kompakt'); ?></h2>

</div>
<?php
</div>
<?php
}
} );


// Featured posts on home page
add_action( 'generate_after_header', function() {
if ( is_front_page() && is_home() ) {
$sticky = get_option('sticky_posts');

$args = array(
'cat' => '224',
'posts_per_page' => '3'
);

$featuredPosts = new WP_Query($args);

?> <section class="posts-list featured"> <?php
if (!empty($sticky)) {
$args = array(
'post__in' => $sticky,
'posts_per_page' => '3',
'ignore_sticky_posts' => 1
);

if($featuredPosts->have_posts()){
while ($featuredPosts->have_posts()) : $featuredPosts->the_post();
get_template_part('template-parts/custom-post-loop');
endwhile;
}
$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
</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"
*/
Expand All @@ -152,6 +170,62 @@ function show_all_categories_of_post(){
}
}

/**
*
* 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() {
Expand All @@ -174,23 +248,22 @@ function show_all_categories_of_post(){
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


<section class="posts-list recommended">
<?php

while ($featuredPosts->have_posts()) : $featuredPosts->the_post();

get_template_part('template-parts/custom-post-loop');

endwhile;


?>
</section> <?php
</section> <?php
}
}, 20);
}, 20);

0 comments on commit d3b251c

Please sign in to comment.