1 | <?php |
||
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 $notices = []; |
||
22 | public $version; |
||
23 | |||
24 | /** |
||
25 | * @return string |
||
26 | */ |
||
27 | public static function prefix() |
||
31 | |||
32 | public function __construct() |
||
47 | |||
48 | /** |
||
49 | * The Application entry point |
||
50 | * |
||
51 | * @return void |
||
52 | */ |
||
53 | public function init() |
||
54 | { |
||
55 | $basename = plugin_basename( $this->file ); |
||
56 | $controller = $this->make( 'Controller' ); |
||
57 | |||
58 | add_action( 'plugins_loaded', function() { |
||
59 | $this->bootstrap(); |
||
60 | }); |
||
61 | add_action( 'admin_enqueue_scripts', array( $controller, 'registerAssets' )); |
||
62 | add_action( 'admin_init', array( $controller, 'removeDashboardWidgets' )); |
||
63 | add_action( 'wp_before_admin_bar_render', array( $controller, 'removeWordPressMenu' )); |
||
64 | add_filter( "plugin_action_links_{$basename}", array( $controller, 'filterPluginLinks' )); |
||
65 | add_filter( 'admin_footer_text', array( $controller, 'filterWordPressFooter' )); |
||
66 | |||
67 | // Disallow indexing of the site on non-production environments |
||
68 | if( !$this->environment( 'production' ) && !is_admin() ) { |
||
69 | add_filter( 'pre_option_blog_public', '__return_zero' ); |
||
70 | } |
||
71 | } |
||
72 | |||
73 | /** |
||
74 | * @param string $checkFor |
||
75 | * @return string|bool |
||
76 | */ |
||
77 | public function environment( $checkFor = '' ) |
||
78 | { |
||
79 | $environment = defined( 'WP_ENV' ) ? WP_ENV : 'production'; |
||
80 | if( !empty( $checkFor )) { |
||
81 | return $environment == $checkFor; |
||
82 | } |
||
83 | return $environment; |
||
84 | } |
||
85 | |||
86 | /** |
||
87 | * @param string $filename |
||
88 | * @return string|null |
||
89 | */ |
||
90 | public function getFile( $filename ) |
||
91 | { |
||
92 | $theme = wp_get_theme(); |
||
93 | $filename = apply_filters( 'pollux/file', $filename ); |
||
94 | $locations = apply_filters( 'pollux/file/locations', [ |
||
95 | trailingslashit( trailingslashit( $theme->theme_root ) . $theme->stylesheet ), |
||
96 | trailingslashit( trailingslashit( $theme->theme_root ) . $theme->template ), |
||
97 | trailingslashit( WP_CONTENT_DIR ), |
||
98 | trailingslashit( ABSPATH ), |
||
99 | trailingslashit( dirname( ABSPATH )), |
||
100 | trailingslashit( dirname( dirname( ABSPATH ))), |
||
101 | ]); |
||
102 | foreach( (array) $locations as $location ) { |
||
103 | if( !file_exists( $location . $filename ))continue; |
||
104 | return $location . $filename; |
||
105 | } |
||
106 | return null; |
||
107 | } |
||
108 | |||
109 | /** |
||
110 | * @return void |
||
111 | 14 | */ |
|
112 | public function onActivation() |
||
113 | 14 | { |
|
114 | } |
||
115 | |||
116 | /** |
||
117 | * @return void |
||
118 | */ |
||
119 | public function onDeactivation() |
||
120 | { |
||
121 | } |
||
122 | |||
123 | /** |
||
124 | * @param string $file |
||
125 | * @return string |
||
126 | */ |
||
127 | public function path( $file = '' ) |
||
128 | { |
||
129 | return plugin_dir_path( $this->file ) . ltrim( trim( $file ), '/' ); |
||
130 | } |
||
131 | |||
132 | /** |
||
133 | * @param string $view |
||
134 | * @return void|null |
||
135 | */ |
||
136 | public function render( $view, array $data = [] ) |
||
137 | { |
||
138 | $file = apply_filters( 'pollux/views/file', |
||
139 | $this->path( sprintf( 'views/%s.php', str_replace( '.php', '', $view ))), |
||
140 | $view, |
||
141 | $data |
||
142 | ); |
||
143 | if( !file_exists( $file ))return; |
||
144 | extract( $data ); |
||
145 | include $file; |
||
146 | } |
||
147 | |||
148 | /** |
||
149 | * @param string $path |
||
150 | * @return string |
||
151 | */ |
||
152 | public function url( $path = '' ) |
||
153 | { |
||
154 | return esc_url( plugin_dir_url( $this->file ) . ltrim( trim( $path ), '/' )); |
||
155 | } |
||
156 | |||
157 | /** |
||
158 | * @return void |
||
159 | */ |
||
160 | protected function bootstrap() |
||
161 | { |
||
162 | Facade::clearResolvedInstances(); |
||
163 | Facade::setFacadeApplication( $this ); |
||
164 | $this->registerAliases(); |
||
165 | $this->loadTextdomain(); |
||
166 | $this->loadHooks(); |
||
167 | $this->config = $this->make( ConfigManager::class )->compile(); |
||
168 | $classNames = array( |
||
169 | 'Config\Config', |
||
170 | 'MetaBox\MetaBox', |
||
171 | 'PostType\Archive', |
||
172 | 'PostType\DisablePosts', |
||
173 | 'PostType\PostType', |
||
174 | 'Settings\Settings', |
||
175 | 'Taxonomy\Taxonomy', |
||
176 | ); |
||
177 | foreach( $classNames as $className ) { |
||
178 | $this->make( $className )->init(); |
||
179 | } |
||
180 | } |
||
181 | |||
182 | /** |
||
183 | * @return void |
||
184 | */ |
||
185 | protected function loadHooks() |
||
191 | |||
192 | /** |
||
193 | * @return void |
||
194 | */ |
||
195 | protected function loadTextdomain() |
||
196 | { |
||
197 | load_plugin_textdomain( $this->id, false, plugin_basename( $this->path() ) . '/languages/' ); |
||
198 | } |
||
199 | |||
200 | /** |
||
201 | * @return void |
||
202 | */ |
||
203 | protected function registerAliases() |
||
211 | } |
||
212 |