Repository navigation
Expand file tree
/
Copy pathTheme_Starter.php
More file actions
84 lines (70 loc) · 1.69 KB
/
Copy pathTheme_Starter.php
File metadata and controls
84 lines (70 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<?php
/**
* Theme Starter Class.
*/
namespace JustCoded\WP\Framework\Theme_Starter;
use JustCoded\WP\Framework\Autoload;
use JustCoded\WP\Framework\Objects\Singleton;
class Theme_Starter {
use Singleton;
/**
* @var bool - If theme is created.
*/
protected $theme_created = true;
/**
* @var string - Namespace of a class that needs to be autoloaded.
*/
protected $namespace = '';
/**
* Method for starting theme.
*
* @param $namespace
*/
public function start_theme( $namespace ) {
$this->set_namespace( $namespace );
try {
$this->register_autoload();
$this->create_theme_instance();
} catch ( \Exception $exception ) {
$this->theme_created = false;
echo $exception->getMessage();
wp_die();
}
}
/**
* Method registers autoload for current theme.
*
* @throws \Exception - Exception on failure
* @return bool - True on success.
*/
protected function register_autoload() {
$theme_namespace = $this->namespace . '\Theme';
if ( ! new Autoload( $theme_namespace, get_template_directory() . '/app' ) ) {
throw new \Exception( 'Could not autoload theme with ' . $theme_namespace . ' namespace' );
} else {
return true;
}
}
/**
* Creating Theme Instance.
*/
protected function create_theme_instance() {
$class_name = "{$this->namespace}\\Theme\\Theme";
if ( class_exists( $class_name ) ) {
$class_name::instance();
} else {
throw new \Exception( 'Class ' . $class_name . " could not be found" );
}
}
/**
* Setting theme namespace value.
*
* @param $namespace
*/
protected function set_namespace( $namespace ) {
$this->namespace = $namespace;
}
public function is_theme_created() {
return $this->theme_created;
}
}