Stencil_Hierarchy_Single::__construct()   B
last analyzed

Complexity

Conditions 6
Paths 10

Size

Total Lines 50
Code Lines 32

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 50
rs 8.6316
cc 6
eloc 32
nc 10
nop 0
1
<?php
2
/**
3
 * Single hierarchy tree
4
 *
5
 * @package Stencil\Hierarchy
6
 */
7
8
/**
9
 * Class Stencil_Hierarchy_Single
10
 */
11
class Stencil_Hierarchy_Single extends Stencil_Abstract_Hierarchy {
12
	/**
13
	 * Stencil_Hierarchy_Single constructor.
14
	 */
15
	public function __construct() {
16
		$post_type = get_post_type();
17
18
		$options = array();
19
20
		switch ( $post_type ) {
21
			case 'attachment':
22
				$attachment = get_queried_object();
23
24
				if ( ! empty( $attachment->post_mime_type ) ) {
25
					$mime_type = $attachment->post_mime_type;
26
					$types     = explode( '/', $mime_type, 2 );
27
28
					$options[] = 'single/' . $types[0];
29
					$options[] = $types[0];
30
31
					if ( ! empty( $types[1] ) ) {
32
						$options[] = 'single/' . $types[1];
33
						$options[] = $types[1];
34
35
						$options[] = 'single/' . $types[0] . '-' . $types[1];
36
						$options[] = $types[0] . '-' . $types[1];
37
					}
38
				}
39
40
				$options[] = 'single/attachment';
41
				$options[] = 'attachment';
42
				break;
43
44
			default:
45
				$post = get_queried_object();
46
				if ( ! empty( $post->post_name ) ) {
47
					$options[] = 'single/' . $post->post_name;
48
					$options[] = $post->post_name;
49
				}
50
51
				$options[] = 'single/' . $post->ID;
52
				$options[] = $post->ID;
53
54
				$options[] = 'single/' . $post_type;
55
				$options[] = $post_type;
56
				break;
57
		}
58
59
		if ( 'page' !== $post_type ) {
60
			$options[] = 'single';
61
		}
62
63
		$this->set_options( $options );
64
	}
65
}
66