Completed
Push — master ( e7d63d...93c42a )
by Marin
02:17
created

Carbon_Breadcrumb_Item_Term::setup()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 17
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 3
Metric Value
dl 0
loc 17
ccs 9
cts 9
cp 1
rs 9.4286
cc 3
eloc 8
nc 3
nop 0
crap 3
1
<?php
2
/**
3
 * Breadcrumb item class for taxonomy terms.
4
 *
5
 * Used for breadcrumb items that represent a term of any taxonomy.
6
 */
7
class Carbon_Breadcrumb_Item_Term extends Carbon_Breadcrumb_Item_DB_Object {
8
9
	/**
10
	 * Term object.
11
	 *
12
	 * @access public
13
	 * @var object
14
	 */
15
	public $term_object;
16
17
	/**
18
	 * Configure the title and link URL by using the specified term ID.
19
	 *
20
	 * @access public
21
	 */
22 3
	public function setup() {
23
		// in order to continue, taxonomy term ID must be specified
24 3
		if ( ! $this->get_id() ) {
25 1
			throw new Carbon_Breadcrumb_Exception( 'The term breadcrumb items must have term ID specified.' );
26
		}
27
28
		// in order to continue, taxonomy must be specified
29 2
		if ( ! $this->get_subtype() ) {
30 1
			throw new Carbon_Breadcrumb_Exception( 'The term breadcrumb items must have taxonomy specified.' );
31
		}
32
33
		// retrieve term object
34 1
		$subtype = $this->get_subtype();
35 1
		$this->term_object = get_term_by( 'id', $this->get_id(), $subtype );
36
37 1
		parent::setup();
38 1
	}
39
40
	/**
41
	 * Setup the title of this item.
42
	 *
43
	 * @access public
44
	 */
45 1
	public function setup_title() {
46 1
		$title = apply_filters( 'the_title', $this->term_object->name );
47 1
		$this->set_title( $title );
48 1
	}
49
50
	/**
51
	 * Setup the link of this item.
52
	 *
53
	 * @access public
54
	 */
55 1
	public function setup_link() {
56 1
		$link = get_term_link( $this->term_object->term_id, $this->term_object->taxonomy );
57 1
		$this->set_link( $link );
58 1
	}
59
60
}