Completed
Pull Request — master (#185)
by Markus
04:55 queued 02:31
created

TimberHelper   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 3
Bugs 1 Features 1
Metric Value
c 3
b 1
f 1
dl 0
loc 29
rs 10
wmc 2
lcom 0
cbo 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getExcerpt() 0 16 1
A getTimberPostById() 0 9 1
1
<?php
2
3
namespace Flynt\Utils;
4
5
use Timber\Post;
6
7
class TimberHelper
8
{
9
    public static function getTimberPostById($postId, $moreLinkText = null, $stripTeaser = false)
10
    {
11
        global $post;
12
        $post = get_post($postId);
13
        setup_postdata($post, $moreLinkText, $stripTeaser);
14
        $timberPost = new Post($post);
15
        wp_reset_postdata($post);
16
        return $timberPost;
17
    }
18
19
    public static function getExcerpt(
20
        $postId,
21
        $len = 50,
22
        $force = false,
23
        $readmore = "Read More",
24
        $strip = true,
25
        $end = "&hellip;"
26
    ) {
27
        global $post;
28
        $post = get_post($postId);
29
        setup_postdata($post, null, false);
30
        $timberPost = new Post($post);
31
        $excerpt = $timberPost->get_preview($len, $force, $readmore, $strip, $end);
32
        wp_reset_postdata($post);
33
        return $excerpt;
34
    }
35
}
36