You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
cosmopet-architecture/wp-content/themes/cosmopet/modules/blog/module-controller.php

87 lines
2.2 KiB

<?php
class BlogPost extends \Timber\Post
{
public function reading_time()
{
$symb_per_minute = 2280;
$symb = strlen(wp_strip_all_tags($this->content()));
$minutes = round($symb / $symb_per_minute);
return sprintf(_n('%s ' . pll__('мин.'), '%s ' . pll__('мин.'), $minutes), (int) $minutes);
}
public function get_author_name()
{
if (get_field('post_author', $this->ID)){
return get_the_title(get_field('post_author', $this->ID));
}
return false;
}
public function get_author_img()
{
$id = get_field('post_author', $this->ID);
return get_the_post_thumbnail_url( $id, 'thumbnail' );
}
public function get_author_link()
{
$id = get_field('post_author', $this->ID);
if ($id) {
return get_permalink($id);
}
return false;
}
public function get_comments_number()
{
return get_comments_number($this->ID);
}
}
add_filter('timber/post/classmap', function ($classmap) {
$custom_classmap = [
'post' => BlogPost::class,
];
return array_merge($classmap, $custom_classmap);
});
function enable_comments_for_posts() {
update_option('default_comment_status', 'open');
$posts = get_posts([
'post_type' => 'post',
'numberposts' => -1,
'post_status' => 'publish'
]);
foreach ($posts as $post) {
if (!comments_open($post->ID)) {
update_post_meta($post->ID, 'comment_status', 'open');
}
}
}
add_action('after_setup_theme', 'enable_comments_for_posts');
function enqueue_comment_scripts() {
if (is_singular() && comments_open()) {
wp_enqueue_script('comment-reply');
wp_enqueue_script(
'blog-comments-js',
get_template_directory_uri() . '/modules/blog/assets/js/comments.js',
array('jquery', 'comment-reply'),
filemtime(get_template_directory() . '/modules/blog/assets/js/comments.js'),
true
);
wp_localize_script('blog-comments-js', 'ajax_object', array(
'ajax_url' => admin_url('admin-ajax.php')
));
}
}
add_action('wp_enqueue_scripts', 'enqueue_comment_scripts');