Carbon_Breadcrumb_Item_Term::setup_title()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.9
c 0
b 0
f 0
cc 3
nc 3
nop 0
1
<?php
2
/**
3
 * Term breadcrumb item
4
 *
5
 * @package carbon-breadcrumbs
6
 */
7
8
/**
9
 * Breadcrumb item class for taxonomy terms.
10
 *
11
 * Used for breadcrumb items that represent a term of any taxonomy.
12
 */
13
class Carbon_Breadcrumb_Item_Term extends Carbon_Breadcrumb_Item_DB_Object {
14
15
	/**
16
	 * Term object.
17
	 *
18
	 * @access public
19
	 * @var object
20
	 */
21
	public $term_object;
22
23
	/**
24
	 * Configure the title and link URL by using the specified term ID.
25
	 *
26
	 * @access public
27
	 * @throws Carbon_Breadcrumb_Exception When term ID or taxonomy isn't specified.
28
	 */
29
	public function setup() {
30
		// In order to continue, taxonomy term ID must be specified.
31
		if ( ! $this->get_id() ) {
32
			throw new Carbon_Breadcrumb_Exception( 'The term breadcrumb items must have term ID specified.' );
33
		}
34
35
		// In order to continue, taxonomy must be specified.
36
		if ( ! $this->get_subtype() ) {
37
			throw new Carbon_Breadcrumb_Exception( 'The term breadcrumb items must have taxonomy specified.' );
38
		}
39
40
		// Retrieve term object.
41
		$subtype           = $this->get_subtype();
42
		$this->term_object = get_term_by( 'id', $this->get_id(), $subtype );
43
44
		parent::setup();
45
	}
46
47
	/**
48
	 * Setup the title of this item.
49
	 *
50
	 * @access public
51
	 */
52
	public function setup_title() {
53
		$filter_name = 'single_term_title';
54
		if ( 'category' === $this->term_object->taxonomy ) {
55
			$filter_name = 'single_cat_title';
56
		} elseif ( 'post_tag' === $this->term_object->taxonomy ) {
57
			$filter_name = 'single_tag_title';
58
		}
59
60
		$title = apply_filters( $filter_name, $this->term_object->name );
61
		$this->set_title( $title );
62
	}
63
64
	/**
65
	 * Setup the link of this item.
66
	 *
67
	 * @access public
68
	 */
69
	public function setup_link() {
70
		$link = get_term_link( $this->term_object->term_id, $this->term_object->taxonomy );
71
		$this->set_link( $link );
72
	}
73
74
}
75