Completed
Push — develop ( 94fd50...816e3b )
by Paul
02:08
created

Theme::get404Title()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace GeminiLabs\Castor\Helpers;
4
5
class Theme
6
{
7
	/**
8
	 * @param string $asset
9
	 *
10
	 * @return string
11
	 */
12
	public function assetPath( $asset )
13
	{
14
		return $this->paths( 'dir.stylesheet' ) . 'assets/' . $asset;
15
	}
16
17
	/**
18
	 * @param string $asset
19
	 *
20
	 * @return string
21
	 */
22
	public function assetUri( $asset )
23
	{
24
		return $this->paths( 'uri.stylesheet' ) . 'assets/' . $asset;
25
	}
26
27
	/**
28
	 * @param string $asset
29
	 *
30
	 * @return string
31
	 */
32
	public function imagePath( $asset )
33
	{
34
		return $this->paths( 'dir.stylesheet' ) . 'assets/img/' . $asset;
35
	}
36
37
	/**
38
	 * @param string $asset
39
	 *
40
	 * @return string
41
	 */
42
	public function imageUri( $asset )
43
	{
44
		return $this->paths( 'uri.stylesheet' ) . 'assets/img/' . $asset;
45
	}
46
47
	public function pageTitle()
48
	{
49
		foreach( ['is_404', 'is_archive', 'is_home', 'is_search'] as $bool ) {
50
			if( !$bool() )continue;
51
			$method = sprintf( 'get%sTitle', ucfirst( str_replace( 'is_', '', $bool )));
52
			return $this->$method();
53
		}
54
		return get_the_title();
55
	}
56
57
	/**
58
	 * @param null|string $path
59
	 *
60
	 * @return array|string
61
	 */
62
	public function paths( $path = null )
63
	{
64
		$paths = [
65
			'dir.stylesheet' => get_stylesheet_directory(),
66
			'dir.template'   => get_template_directory(),
67
			'dir.upload'     => wp_upload_dir()['basedir'],
68
			'uri.stylesheet' => get_stylesheet_directory_uri(),
69
			'uri.template'   => get_template_directory_uri(),
70
		];
71
72
		if( is_null( $path )) {
73
			return $paths;
74
		}
75
76
		return array_key_exists( $path, $paths )
77
			? trailingslashit( $paths[$path] )
78
			: '';
79
	}
80
81
	protected function get404Title()
82
	{
83
		return __( 'Not Found', 'castor' );
84
	}
85
86
	protected function getArchiveTitle()
87
	{
88
		return get_the_archive_title();
89
	}
90
91
	protected function getHomeTitle()
92
	{
93
		return ( $home = get_option( 'page_for_posts', true ))
94
			? get_the_title( $home )
95
			: __( 'Latest Posts', 'castor' );
96
	}
97
98
	protected function getSearchTitle()
99
	{
100
		return sprintf( __( 'Search Results for %s', 'castor' ), get_search_query() );
101
	}
102
}
103