1 | <?php |
||
12 | class Stencil_Config { |
||
13 | |||
14 | /** |
||
15 | * All installables available |
||
16 | * |
||
17 | * @var Stencil_Installables |
||
18 | */ |
||
19 | private $installables; |
||
20 | |||
21 | /** |
||
22 | * Option page |
||
23 | * |
||
24 | * @var string |
||
25 | */ |
||
26 | private $option_page = 'stencil-options'; |
||
27 | |||
28 | /** |
||
29 | * Option group |
||
30 | * |
||
31 | * @var string |
||
32 | */ |
||
33 | private $option_group = 'stencil-installables'; |
||
34 | |||
35 | /** |
||
36 | * The name of the option |
||
37 | * |
||
38 | * @var string |
||
39 | */ |
||
40 | private $option_name = 'install'; |
||
41 | |||
42 | /** |
||
43 | * Stencil_Config constructor. |
||
44 | */ |
||
45 | public function __construct() { |
||
51 | |||
52 | /** |
||
53 | * Create the menu item |
||
54 | */ |
||
55 | public function create_admin_menu() { |
||
65 | |||
66 | /** |
||
67 | * Register settings |
||
68 | */ |
||
69 | public function register_options() { |
||
96 | |||
97 | /** |
||
98 | * Register installables. |
||
99 | */ |
||
100 | public function register_installables() { |
||
103 | |||
104 | /** |
||
105 | * Show the settings |
||
106 | */ |
||
107 | public function settings_page() { |
||
133 | |||
134 | /** |
||
135 | * Show plugins that are not installed yet (but tracked) |
||
136 | * Check to install; installed plugins are grayed out and checked |
||
137 | * but are ignored on save. |
||
138 | */ |
||
139 | public function option_plugins() { |
||
140 | $plugins = $this->installables->get_plugins(); |
||
141 | foreach ( $plugins as $plugin ) { |
||
142 | |||
143 | $attributes = array(); |
||
144 | $available = true; |
||
145 | $base = $this->option_name; |
||
146 | $upgrade = $plugin->has_upgrade(); |
||
147 | $exists = $plugin->is_installed(); |
||
148 | $message = ''; |
||
149 | |||
150 | $passed = $plugin->passed_requirements(); |
||
151 | if ( is_array( $passed ) ) { |
||
152 | $message = implode( '<br>', $passed ); |
||
153 | $available = false; |
||
154 | } |
||
155 | |||
156 | if ( $available && $exists && $upgrade ) { |
||
157 | $message = __( 'Upgrade available!', 'stencil' ); |
||
158 | } |
||
159 | |||
160 | /** |
||
161 | * Check if installed. |
||
162 | */ |
||
163 | if ( $exists ) { |
||
164 | $attributes[] = 'checked="checked"'; |
||
165 | } |
||
166 | |||
167 | /** |
||
168 | * Disable input if plugin is installed. |
||
169 | * Disable if not available for installation. |
||
170 | */ |
||
171 | if ( ( $exists && ! $upgrade ) || ! $available ) { |
||
172 | $attributes[] = 'disabled="disabled"'; |
||
173 | $base = 'dummy'; |
||
174 | } |
||
175 | |||
176 | printf( |
||
177 | '<label><input type="checkbox" name="%s"%s>%s%s</label><br>', |
||
178 | esc_attr( sprintf( '%s[plugin][%s]', $base, $plugin->get_slug() ) ), |
||
179 | implode( ' ', $attributes ), |
||
180 | esc_html( $plugin ), |
||
181 | ! empty( $message ) ? sprintf( ' <small><strong>(%s)</strong></small>', $message ) : '' |
||
182 | ); |
||
183 | } |
||
184 | } |
||
185 | |||
186 | /** |
||
187 | * Show plugins that are not installed yet (but tracked) |
||
188 | * Check to install; installed plugins are grayed out and checked |
||
189 | * but are ignored on save. |
||
190 | */ |
||
191 | public function option_themes() { |
||
219 | |||
220 | /** |
||
221 | * Install selected plugins |
||
222 | */ |
||
223 | private function maybe_install_plugins() { |
||
268 | |||
269 | /** |
||
270 | * Install selected themes |
||
271 | */ |
||
272 | private function maybe_install_themes() { |
||
321 | } |
||
322 |