Stencil_Page_Hook_Custom   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2
Metric Value
wmc 3
lcom 0
cbo 2
dl 0
loc 33
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A execute() 0 3 1
A set_template_as_first_option() 0 14 2
1
<?php
2
/**
3
 * Custom page hook
4
 *
5
 * @package Stencil\PageHook
6
 */
7
8
/**
9
 * Class Stencil_Page_Hook_Custom
10
 */
11
class Stencil_Page_Hook_Custom extends Stencil_Abstract_Page_Type {
12
13
	/**
14
	 * Exection hook
15
	 *
16
	 * @param Stencil_Interface $controller Controller that initiated this class.
17
	 */
18
	public function execute( Stencil_Interface $controller ) {
19
		add_filter( Stencil_Environment::format_filter( 'views-custom' ), array( $this, 'set_template_as_first_option' ) );
20
	}
21
22
	/**
23
	 * Prepend {page_template} on the view stack for custom page
24
	 *
25
	 * @param array $options Current options.
26
	 *
27
	 * @return mixed
28
	 */
29
	public function set_template_as_first_option( $options ) {
30
		$page_template = get_page_template();
31
32
		if ( $page_template ) {
33
			$page_template_base = basename( $page_template );
34
			$page_template_pure = str_replace( '.php', '', $page_template_base );
35
36
			// Reversed order; first look for 'custom', then 'single'.
37
			array_unshift( $options, 'single/' . $page_template_pure );
38
			array_unshift( $options, 'custom/' . $page_template_pure );
39
		}
40
41
		return $options;
42
	}
43
}
44