Completed
Push — baseComponentsListPosts ( 2a73c9 )
by Markus
02:48
created

TimberHelper   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

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

2 Methods

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