1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace GeminiLabs\Pollux; |
4
|
|
|
|
5
|
|
|
use GeminiLabs\Pollux\AliasLoader; |
6
|
|
|
use GeminiLabs\Pollux\Config\Config; |
7
|
|
|
use GeminiLabs\Pollux\Container; |
8
|
|
|
use GeminiLabs\Pollux\Facade; |
9
|
|
|
use GeminiLabs\Pollux\GateKeeper; |
10
|
|
|
use GeminiLabs\Pollux\PostType\PostType; |
11
|
|
|
|
12
|
|
|
final class Application extends Container |
13
|
|
|
{ |
14
|
|
|
const PREFIX = 'pollux_'; |
15
|
|
|
|
16
|
|
|
public $config; |
17
|
|
|
public $file; |
18
|
|
|
public $gatekeeper; |
19
|
|
|
public $id; |
20
|
|
|
public $name; |
21
|
|
|
public $version; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @return string |
25
|
|
|
*/ |
26
|
|
|
public static function prefix() |
27
|
|
|
{ |
28
|
|
|
return apply_filters( 'pollux/prefix', self::PREFIX ); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
public function __construct() |
32
|
|
|
{ |
33
|
|
|
$this->file = realpath( dirname( dirname( __FILE__ )) . '/pollux.php' ); |
34
|
|
|
$this->gatekeeper = new GateKeeper( plugin_basename( $this->file )); |
35
|
|
|
|
36
|
|
|
$data = get_file_data( $this->file, array( |
37
|
|
|
'id' => 'Text Domain', |
38
|
|
|
'name' => 'Plugin Name', |
39
|
|
|
'version' => 'Version', |
40
|
|
|
), 'plugin' ); |
41
|
|
|
array_walk( $data, function( $value, $key ) { |
42
|
|
|
$this->$key = $value; |
43
|
|
|
}); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* The Application entry point |
48
|
|
|
* |
49
|
|
|
* @return void |
50
|
|
|
*/ |
51
|
|
|
public function init() |
52
|
|
|
{ |
53
|
|
|
$this->bootstrap(); |
54
|
|
|
|
55
|
|
|
$controller = $this->make( 'Controller' ); |
56
|
|
|
|
57
|
|
|
add_action( 'admin_enqueue_scripts', array( $controller, 'registerAssets' )); |
58
|
|
|
add_action( 'admin_init', array( $controller, 'removeDashboardWidgets' )); |
59
|
|
|
add_action( 'wp_before_admin_bar_render', array( $controller, 'removeWordPressMenu' )); |
60
|
|
|
add_filter( 'admin_footer_text', array( $controller, 'filterWordPressFooter' )); |
61
|
|
|
|
62
|
|
|
// Disallow indexing of the site on non-production environments |
63
|
|
|
if( !$this->environment( 'production' ) && !is_admin() ) { |
64
|
|
|
add_filter( 'pre_option_blog_public', '__return_zero' ); |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @param string $checkFor |
70
|
|
|
* @return string|bool |
71
|
|
|
*/ |
72
|
|
|
public function environment( $checkFor = '' ) |
73
|
|
|
{ |
74
|
|
|
$environment = defined( 'WP_ENV' ) ? WP_ENV : 'production'; |
75
|
|
|
if( !empty( $checkFor )) { |
76
|
|
|
return $environment == $checkFor; |
77
|
|
|
} |
78
|
|
|
return $environment; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @return void |
83
|
|
|
*/ |
84
|
|
|
public function onActivation() |
85
|
|
|
{ |
86
|
|
|
if( !get_option( Settings::id() )) { |
87
|
|
|
update_option( Settings::id(), [] ); |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* @return void |
93
|
|
|
*/ |
94
|
|
|
public function onDeactivation() |
95
|
|
|
{ |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* @param string $file |
100
|
|
|
* @return string |
101
|
|
|
*/ |
102
|
|
|
public function path( $file = '' ) |
103
|
|
|
{ |
104
|
|
|
return plugin_dir_path( $this->file ) . ltrim( trim( $file ), '/' ); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* @param string $path |
109
|
|
|
* @return string |
110
|
|
|
*/ |
111
|
|
|
public function url( $path = '' ) |
112
|
|
|
{ |
113
|
|
|
return esc_url( plugin_dir_url( $this->file ) . ltrim( trim( $path ), '/' )); |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* @return void |
118
|
|
|
*/ |
119
|
|
|
protected function bootstrap() |
120
|
|
|
{ |
121
|
|
|
Facade::clearResolvedInstances(); |
122
|
|
|
Facade::setFacadeApplication( $this ); |
123
|
|
|
$this->config = ( new Config( $this ))->get(); |
124
|
|
|
$this->registerAliases(); |
125
|
|
|
$classNames = array( |
126
|
|
|
'MetaBox\MetaBox', |
127
|
|
|
'PostType\Archive', |
128
|
|
|
'PostType\DisablePosts', |
129
|
|
|
'PostType\PostType', |
130
|
|
|
'Settings\Settings', |
131
|
|
|
'Taxonomy\Taxonomy', |
132
|
|
|
); |
133
|
|
|
foreach( $classNames as $className ) { |
134
|
|
|
$this->make( $className )->init(); |
135
|
|
|
} |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
/** |
139
|
|
|
* @return void |
140
|
|
|
*/ |
141
|
|
|
protected function registerAliases() |
142
|
|
|
{ |
143
|
|
|
$aliases = array( |
144
|
|
|
'ArchiveMeta' => 'GeminiLabs\Pollux\Facades\ArchiveMeta', |
145
|
|
|
'PostMeta' => 'GeminiLabs\Pollux\Facades\PostMeta', |
146
|
|
|
'SiteMeta' => 'GeminiLabs\Pollux\Facades\SiteMeta', |
147
|
|
|
); |
148
|
|
|
AliasLoader::getInstance( $aliases )->register(); |
149
|
|
|
} |
150
|
|
|
} |
151
|
|
|
|