@@ -12,711 +12,711 @@ |
||
12 | 12 | */ |
13 | 13 | class Settings { |
14 | 14 | |
15 | - /** |
|
16 | - * Holds class instance |
|
17 | - * |
|
18 | - * @since 1.0.0 |
|
19 | - * |
|
20 | - * @var object \lsx_health_plan\classes\admin\Settings() |
|
21 | - */ |
|
22 | - protected static $instance = null; |
|
23 | - |
|
24 | - /** |
|
25 | - * Option key, and option page slug |
|
26 | - * |
|
27 | - * @var string |
|
28 | - */ |
|
29 | - protected $screen_id = 'lsx_health_plan_settings'; |
|
30 | - |
|
31 | - /** |
|
32 | - * An array of the post types for the Global Downloads field. |
|
33 | - * |
|
34 | - * @var array |
|
35 | - */ |
|
36 | - public $download_types = array(); |
|
37 | - |
|
38 | - /** |
|
39 | - * An array of the post types for the Global Defaults field. |
|
40 | - * |
|
41 | - * @var array |
|
42 | - */ |
|
43 | - public $default_types = array(); |
|
44 | - |
|
45 | - /** |
|
46 | - * An array of the endpoints for the Endpoint Translation field. |
|
47 | - * |
|
48 | - * @var array |
|
49 | - */ |
|
50 | - public $endpoints = array(); |
|
51 | - |
|
52 | - /** |
|
53 | - * Constructor |
|
54 | - */ |
|
55 | - public function __construct() { |
|
56 | - $this->load_classes(); |
|
57 | - add_action( 'cmb2_admin_init', array( $this, 'register_settings_page' ) ); |
|
58 | - add_action( 'lsx_hp_settings_page', array( $this, 'generate_tabs' ), 1, 1 ); |
|
59 | - |
|
60 | - add_action( 'lsx_hp_settings_page_general_top', array( $this, 'general_settings' ), 1, 1 ); |
|
61 | - add_action( 'lsx_hp_settings_page', array( $this, 'global_defaults' ), 3, 1 ); |
|
62 | - add_action( 'lsx_hp_settings_page', array( $this, 'global_downloads' ), 5, 1 ); |
|
63 | - add_action( 'lsx_hp_settings_page', array( $this, 'stat_disable' ), 6, 1 ); |
|
64 | - add_action( 'lsx_hp_settings_page', array( $this, 'endpoint_translations' ), 7, 1 ); |
|
65 | - add_action( 'lsx_hp_settings_page', array( $this, 'exercise_translations' ), 7, 1 ); |
|
66 | - add_action( 'lsx_hp_settings_page', array( $this, 'post_type_toggles' ), 9, 1 ); |
|
67 | - } |
|
68 | - |
|
69 | - /** |
|
70 | - * Return an instance of this class. |
|
71 | - * |
|
72 | - * @since 1.0.0 |
|
73 | - * |
|
74 | - * @return object \lsx_health_plan\classes\admin\Settings() A single instance of this class. |
|
75 | - */ |
|
76 | - public static function get_instance() { |
|
77 | - // If the single instance hasn't been set, set it now. |
|
78 | - if ( null === self::$instance ) { |
|
79 | - self::$instance = new self(); |
|
80 | - } |
|
81 | - return self::$instance; |
|
82 | - } |
|
83 | - |
|
84 | - /** |
|
85 | - * Loads the variable classes and the static classes. |
|
86 | - */ |
|
87 | - private function load_classes() { |
|
88 | - |
|
89 | - $this->post_types = array( |
|
90 | - 'plan', |
|
91 | - 'workout', |
|
92 | - 'exercise', |
|
93 | - //'meal', |
|
94 | - 'recipe', |
|
95 | - //'tip', |
|
96 | - ); |
|
97 | - |
|
98 | - foreach ( $this->post_types as $post_type ) { |
|
99 | - $this->$post_type = require_once LSX_HEALTH_PLAN_PATH . 'classes/admin/settings/class-' . $post_type . '.php'; |
|
100 | - } |
|
101 | - } |
|
102 | - |
|
103 | - /** |
|
104 | - * Sets the variables needed for the fields. |
|
105 | - * |
|
106 | - * @return void |
|
107 | - */ |
|
108 | - public function set_vars() { |
|
109 | - |
|
110 | - $this->default_types = array( |
|
111 | - 'page' => array( |
|
112 | - 'title' => __( 'Warm Up', 'lsx-health-plan' ), |
|
113 | - 'description' => __( 'Set a default warm up routine.', 'lsx-health-plan' ), |
|
114 | - 'limit' => 1, |
|
115 | - 'id' => 'plan_warmup', |
|
116 | - ), |
|
117 | - ); |
|
118 | - $this->download_types = array( |
|
119 | - 'page' => array( |
|
120 | - 'title' => __( 'Warm Up', 'lsx-health-plan' ), |
|
121 | - 'description' => __( 'Set a default warm up routine.', 'lsx-health-plan' ), |
|
122 | - 'limit' => 1, |
|
123 | - ), |
|
124 | - ); |
|
125 | - $this->endpoints = array( |
|
126 | - 'endpoint_warm_up' => array( |
|
127 | - 'title' => __( 'Warm Up Endpoint', 'lsx-health-plan' ), |
|
128 | - 'default' => 'warm-up', |
|
129 | - ), |
|
130 | - ); |
|
131 | - |
|
132 | - if ( post_type_exists( 'meal' ) ) { |
|
133 | - $this->download_types['meal'] = array( |
|
134 | - 'title' => __( 'Meal Plan', 'lsx-health-plan' ), |
|
135 | - 'description' => __( 'Set a default meal plan.', 'lsx-health-plan' ), |
|
136 | - ); |
|
137 | - $this->default_types['meal'] = array( |
|
138 | - 'title' => __( 'Meal Plan', 'lsx-health-plan' ), |
|
139 | - 'description' => __( 'Set a default meal plan.', 'lsx-health-plan' ), |
|
140 | - 'id' => 'connected_meals', |
|
141 | - ); |
|
142 | - $this->endpoints['endpoint_meal'] = array( |
|
143 | - 'title' => __( 'Meal Endpoint', 'lsx-health-plan' ), |
|
144 | - 'default' => 'meal', |
|
145 | - 'description' => __( 'Define the tab slug which shows on the single plan page.', 'lsx-health-plan' ), |
|
146 | - ); |
|
147 | - $this->endpoints['endpoint_meal_archive'] = array( |
|
148 | - 'title' => __( 'Meals Archive Endpoint', 'lsx-health-plan' ), |
|
149 | - 'default' => 'meals', |
|
150 | - ); |
|
151 | - $this->endpoints['meal_single_slug'] = array( |
|
152 | - 'title' => __( 'Single Meal Slug', 'lsx-health-plan' ), |
|
153 | - 'default' => 'meal', |
|
154 | - ); |
|
155 | - } |
|
156 | - if ( post_type_exists( 'recipe' ) ) { |
|
157 | - $this->download_types['recipe'] = array( |
|
158 | - 'title' => __( 'Recipe', 'lsx-health-plan' ), |
|
159 | - 'description' => __( 'Set a default recipe.', 'lsx-health-plan' ), |
|
160 | - ); |
|
161 | - $this->default_types['recipe'] = array( |
|
162 | - 'title' => __( 'Recipe', 'lsx-health-plan' ), |
|
163 | - 'description' => __( 'Set a default recipe.', 'lsx-health-plan' ), |
|
164 | - 'id' => 'connected_recipes', |
|
165 | - ); |
|
166 | - $this->endpoints['endpoint_recipe'] = array( |
|
167 | - 'title' => __( 'Recipes Endpoint', 'lsx-health-plan' ), |
|
168 | - 'default' => 'recipe', |
|
169 | - ); |
|
170 | - } |
|
171 | - if ( post_type_exists( 'workout' ) ) { |
|
172 | - $this->download_types['workout'] = array( |
|
173 | - 'title' => __( 'Workout', 'lsx-health-plan' ), |
|
174 | - 'description' => __( 'Set a default workout routine PDF.', 'lsx-health-plan' ), |
|
175 | - ); |
|
176 | - $this->default_types['workout'] = array( |
|
177 | - 'title' => __( 'Workout', 'lsx-health-plan' ), |
|
178 | - 'description' => __( 'Set a default workout routine.', 'lsx-health-plan' ), |
|
179 | - 'id' => 'connected_workouts', |
|
180 | - ); |
|
181 | - $this->endpoints['endpoint_workout_archive'] = array( |
|
182 | - 'title' => __( 'Workouts Archive Endpoint', 'lsx-health-plan' ), |
|
183 | - 'default' => '', |
|
184 | - ); |
|
185 | - $this->endpoints['endpoint_workout'] = array( |
|
186 | - 'title' => __( 'Single Workout Endpoint', 'lsx-health-plan' ), |
|
187 | - 'default' => 'workout', |
|
188 | - ); |
|
189 | - } |
|
190 | - |
|
191 | - $this->endpoints['login_slug'] = array( |
|
192 | - 'title' => __( 'Login Slug', 'lsx-health-plan' ), |
|
193 | - 'default' => 'login', |
|
194 | - ); |
|
195 | - $this->endpoints['my_plan_slug'] = array( |
|
196 | - 'title' => __( 'My Plan Slug', 'lsx-health-plan' ), |
|
197 | - 'default' => 'my-plan', |
|
198 | - ); |
|
199 | - $this->endpoints['plan_single_slug'] = array( |
|
200 | - 'title' => __( 'Single Plan Slug', 'lsx-health-plan' ), |
|
201 | - 'default' => 'plan', |
|
202 | - ); |
|
203 | - $this->endpoints['endpoint_plan_archive'] = array( |
|
204 | - 'title' => __( 'Plans Archive Endpoint', 'lsx-health-plan' ), |
|
205 | - 'default' => 'plans', |
|
206 | - ); |
|
207 | - |
|
208 | - if ( false !== \lsx_health_plan\functions\get_option( 'exercise_enabled', false ) ) { |
|
209 | - $this->endpoints['exercise'] = array( |
|
210 | - 'exercise_single' => array( |
|
211 | - 'title' => __( 'Single Exercise Slug', 'lsx-health-plan' ), |
|
212 | - 'default' => 'exercise', |
|
213 | - ), |
|
214 | - 'exercise_archive' => array( |
|
215 | - 'title' => __( 'Archive Exercise Slug', 'lsx-health-plan' ), |
|
216 | - 'default' => 'exercises', |
|
217 | - ), |
|
218 | - 'exercise_type' => array( |
|
219 | - 'title' => __( 'Exercise Type Slug', 'lsx-health-plan' ), |
|
220 | - 'default' => 'exercise-type', |
|
221 | - ), |
|
222 | - 'exercise_equipment' => array( |
|
223 | - 'title' => __( 'Equipment Slug', 'lsx-health-plan' ), |
|
224 | - 'default' => 'equipment', |
|
225 | - ), |
|
226 | - 'exercise_musclegroup' => array( |
|
227 | - 'title' => __( 'Muscle Group Slug', 'lsx-health-plan' ), |
|
228 | - 'default' => 'muscle-group', |
|
229 | - ), |
|
230 | - ); |
|
231 | - } |
|
232 | - } |
|
233 | - |
|
234 | - /** |
|
235 | - * Hook in and register a submenu options page for the Page post-type menu. |
|
236 | - */ |
|
237 | - public function register_settings_page() { |
|
238 | - $this->set_vars(); |
|
239 | - $cmb = new_cmb2_box( |
|
240 | - array( |
|
241 | - 'id' => $this->screen_id, |
|
242 | - 'title' => esc_html__( 'Settings', 'lsx-health-plan' ), |
|
243 | - 'object_types' => array( 'options-page' ), |
|
244 | - 'option_key' => 'lsx_health_plan_options', // The option key and admin menu page slug. |
|
245 | - 'parent_slug' => 'edit.php?post_type=plan', // Make options page a submenu item of the themes menu. |
|
246 | - 'capability' => 'manage_options', // Cap required to view options-page. |
|
247 | - ) |
|
248 | - ); |
|
249 | - do_action( 'lsx_hp_settings_page', $cmb ); |
|
250 | - } |
|
251 | - |
|
252 | - /** |
|
253 | - * Registers the general settings. |
|
254 | - * |
|
255 | - * @param object $cmb new_cmb2_box(). |
|
256 | - * @return void |
|
257 | - */ |
|
258 | - public function general_settings( $cmb ) { |
|
259 | - $cmb->add_field( |
|
260 | - array( |
|
261 | - 'name' => __( 'Membership Product', 'lsx-health-plan' ), |
|
262 | - 'id' => 'membership_product', |
|
263 | - 'type' => 'post_search_ajax', |
|
264 | - 'limit' => 1, |
|
265 | - 'sortable' => false, |
|
266 | - 'query_args' => array( |
|
267 | - 'post_type' => array( 'product' ), |
|
268 | - 'post_status' => array( 'publish' ), |
|
269 | - 'posts_per_page' => -1, |
|
270 | - ), |
|
271 | - ) |
|
272 | - ); |
|
273 | - |
|
274 | - $cmb->add_field( |
|
275 | - array( |
|
276 | - 'name' => __( 'Your Warm-up Intro', 'lsx-health-plan' ), |
|
277 | - 'id' => 'warmup_intro', |
|
278 | - 'type' => 'textarea_small', |
|
279 | - 'value' => '', |
|
280 | - 'default' => __( "Don't forget your warm-up! It's a vital part of your daily workout routine.", 'lsx-health-plan' ), |
|
281 | - ) |
|
282 | - ); |
|
283 | - if ( post_type_exists( 'workout' ) ) { |
|
284 | - $cmb->add_field( |
|
285 | - array( |
|
286 | - 'name' => __( 'Your Workout Intro', 'lsx-health-plan' ), |
|
287 | - 'id' => 'workout_intro', |
|
288 | - 'type' => 'textarea_small', |
|
289 | - 'value' => '', |
|
290 | - 'default' => __( "Let's do this! Smash your daily workout and reach your fitness goals.", 'lsx-health-plan' ), |
|
291 | - ) |
|
292 | - ); |
|
293 | - } |
|
294 | - if ( post_type_exists( 'meal' ) ) { |
|
295 | - $cmb->add_field( |
|
296 | - array( |
|
297 | - 'name' => __( 'Your Meal Plan Intro', 'lsx-health-plan' ), |
|
298 | - 'id' => 'meal_plan_intro', |
|
299 | - 'type' => 'textarea_small', |
|
300 | - 'value' => '', |
|
301 | - 'default' => __( 'Get the right mix of nutrients to keep muscles strong & healthy.', 'lsx-health-plan' ), |
|
302 | - ) |
|
303 | - ); |
|
304 | - } |
|
305 | - if ( post_type_exists( 'recipe' ) ) { |
|
306 | - $cmb->add_field( |
|
307 | - array( |
|
308 | - 'name' => __( 'Recipes Intro', 'lsx-health-plan' ), |
|
309 | - 'id' => 'recipes_intro', |
|
310 | - 'type' => 'textarea_small', |
|
311 | - 'value' => '', |
|
312 | - 'default' => __( "Let's get cooking! Delicious and easy to follow recipes.", 'lsx-health-plan' ), |
|
313 | - ) |
|
314 | - ); |
|
315 | - } |
|
316 | - } |
|
317 | - |
|
318 | - /** |
|
319 | - * Registers the global default settings. |
|
320 | - * |
|
321 | - * @param object $cmb new_cmb2_box(). |
|
322 | - * @return void |
|
323 | - */ |
|
324 | - public function global_defaults( $cmb ) { |
|
325 | - $cmb->add_field( |
|
326 | - array( |
|
327 | - 'id' => 'global_defaults_title', |
|
328 | - 'type' => 'title', |
|
329 | - 'name' => __( 'Global Defaults', 'lsx-health-plan' ), |
|
330 | - 'default' => __( 'Global Defaults', 'lsx-health-plan' ), |
|
331 | - 'description' => __( 'If you have not connected a specific post to your day plan, set a default option below.', 'lsx-health-plan' ), |
|
332 | - ) |
|
333 | - ); |
|
334 | - |
|
335 | - foreach ( $this->default_types as $type => $default_type ) { |
|
336 | - $limit = 5; |
|
337 | - $sortable = false; |
|
338 | - if ( isset( $default_type['limit'] ) ) { |
|
339 | - $limit = $default_type['limit']; |
|
340 | - $sortable = true; |
|
341 | - } |
|
342 | - |
|
343 | - if ( 'page' === $type && false !== \lsx_health_plan\functions\get_option( 'exercise_enabled', false ) ) { |
|
344 | - $type = array( 'page', 'workout' ); |
|
345 | - } |
|
346 | - |
|
347 | - $cmb->add_field( |
|
348 | - array( |
|
349 | - 'name' => $default_type['title'], |
|
350 | - 'desc' => $default_type['description'], |
|
351 | - 'id' => $default_type['id'], |
|
352 | - 'type' => 'post_search_ajax', |
|
353 | - 'limit' => $limit, |
|
354 | - 'sortable' => $sortable, |
|
355 | - 'query_args' => array( |
|
356 | - 'post_type' => $type, |
|
357 | - 'post_status' => array( 'publish' ), |
|
358 | - 'posts_per_page' => -1, |
|
359 | - ), |
|
360 | - ) |
|
361 | - ); |
|
362 | - } |
|
363 | - |
|
364 | - $cmb->add_field( |
|
365 | - array( |
|
366 | - 'id' => 'settings_global_defaults_closing', |
|
367 | - 'type' => 'tab_closing', |
|
368 | - ) |
|
369 | - ); |
|
370 | - } |
|
371 | - |
|
372 | - /** |
|
373 | - * Registers the global dowloads settings |
|
374 | - * |
|
375 | - * @param object $cmb new_cmb2_box(). |
|
376 | - * @return void |
|
377 | - */ |
|
378 | - public function global_downloads( $cmb ) { |
|
379 | - if ( ! function_exists( 'download_monitor' ) ) { |
|
380 | - return; |
|
381 | - } |
|
382 | - $page_url = 'https://wordpress.org/plugins/download-monitor/'; |
|
383 | - $plugin_name = 'Download Monitor'; |
|
384 | - $description = sprintf( |
|
385 | - /* translators: %s: The subscription info */ |
|
386 | - __( 'If you are using <a target="_blank" href="%1$s">%2$s</a> you can set a default download file for your plan here.', 'lsx-search' ), |
|
387 | - $page_url, |
|
388 | - $plugin_name |
|
389 | - ); |
|
390 | - $cmb->add_field( |
|
391 | - array( |
|
392 | - 'id' => 'global_downloads_title', |
|
393 | - 'type' => 'title', |
|
394 | - 'name' => __( 'Global Downloads', 'lsx-health-plan' ), |
|
395 | - 'default' => __( 'Global Downloads', 'lsx-health-plan' ), |
|
396 | - 'description' => $description, |
|
397 | - ) |
|
398 | - ); |
|
399 | - |
|
400 | - foreach ( $this->download_types as $type => $download_type ) { |
|
401 | - $limit = 5; |
|
402 | - $sortable = false; |
|
403 | - if ( isset( $download_type['limit'] ) ) { |
|
404 | - $limit = $download_type['limit']; |
|
405 | - $sortable = true; |
|
406 | - } |
|
407 | - |
|
408 | - $cmb->add_field( |
|
409 | - array( |
|
410 | - 'name' => $download_type['title'], |
|
411 | - 'id' => 'download_' . $type, |
|
412 | - 'type' => 'post_search_ajax', |
|
413 | - 'limit' => $limit, |
|
414 | - 'sortable' => $sortable, |
|
415 | - 'query_args' => array( |
|
416 | - 'post_type' => array( 'dlm_download' ), |
|
417 | - 'post_status' => array( 'publish' ), |
|
418 | - 'posts_per_page' => -1, |
|
419 | - ), |
|
420 | - ) |
|
421 | - ); |
|
422 | - } |
|
423 | - $cmb->add_field( |
|
424 | - array( |
|
425 | - 'id' => 'settings_global_downloads_closing', |
|
426 | - 'type' => 'tab_closing', |
|
427 | - ) |
|
428 | - ); |
|
429 | - } |
|
430 | - |
|
431 | - /** |
|
432 | - * Registers the endpoint translation settings. |
|
433 | - * |
|
434 | - * @param object $cmb new_cmb2_box(). |
|
435 | - * @return void |
|
436 | - */ |
|
437 | - public function endpoint_translations( $cmb ) { |
|
438 | - $cmb->add_field( |
|
439 | - array( |
|
440 | - 'id' => 'endpoints_title', |
|
441 | - 'type' => 'title', |
|
442 | - 'name' => __( 'Set Endpoint Translations', 'lsx-health-plan' ), |
|
443 | - 'default' => __( 'Set Endpoint Translations', 'lsx-health-plan' ), |
|
444 | - ) |
|
445 | - ); |
|
446 | - foreach ( $this->endpoints as $slug => $endpoint_vars ) { |
|
447 | - if ( 'exercise' === $slug ) { |
|
448 | - continue; |
|
449 | - } |
|
450 | - |
|
451 | - $cmb->add_field( |
|
452 | - array( |
|
453 | - 'name' => $endpoint_vars['title'], |
|
454 | - 'id' => $slug, |
|
455 | - 'type' => 'input', |
|
456 | - 'value' => '', |
|
457 | - 'default' => $endpoint_vars['default'], |
|
458 | - ) |
|
459 | - ); |
|
460 | - } |
|
461 | - $cmb->add_field( |
|
462 | - array( |
|
463 | - 'id' => 'settings_endpoints_closing', |
|
464 | - 'type' => 'tab_closing', |
|
465 | - 'before_row' => '<p style="margin-top:20px; font-style: italic;">Endpoint is a web address (URL) at which the user can gain access to it. You need to resave your permalinks after changing the endpoint settings.</p>', |
|
466 | - ) |
|
467 | - ); |
|
468 | - } |
|
469 | - |
|
470 | - /** |
|
471 | - * Registers the endpoint translation settings. |
|
472 | - * |
|
473 | - * @param object $cmb new_cmb2_box(). |
|
474 | - * @return void |
|
475 | - */ |
|
476 | - public function exercise_translations( $cmb ) { |
|
477 | - if ( isset( $this->endpoints['exercise'] ) && '' !== $this->endpoints['exercise'] && ! empty( $this->endpoints['exercise'] ) ) { |
|
478 | - $cmb->add_field( |
|
479 | - array( |
|
480 | - 'id' => 'exercise_endpoints_title', |
|
481 | - 'type' => 'title', |
|
482 | - 'name' => __( 'Set Exercise Translations', 'lsx-health-plan' ), |
|
483 | - 'default' => __( 'Set Exercise Translations', 'lsx-health-plan' ), |
|
484 | - 'description' => __( 'Change the exercise endpoints.', 'lsx-health-plan' ), |
|
485 | - ) |
|
486 | - ); |
|
487 | - |
|
488 | - foreach ( $this->endpoints['exercise'] as $slug => $endpoint_vars ) { |
|
489 | - $cmb->add_field( |
|
490 | - array( |
|
491 | - 'name' => $endpoint_vars['title'], |
|
492 | - 'id' => 'endpoint_' . $slug, |
|
493 | - 'type' => 'input', |
|
494 | - 'value' => '', |
|
495 | - 'default' => $endpoint_vars['default'], |
|
496 | - ) |
|
497 | - ); |
|
498 | - } |
|
499 | - |
|
500 | - $cmb->add_field( |
|
501 | - array( |
|
502 | - 'id' => 'settings_exercise_endpoints_closing', |
|
503 | - 'type' => 'tab_closing', |
|
504 | - 'before_row' => '<p style="margin-top:20px; font-style: italic;">If you need to translate the exercise URL endpoints, do so below.</p>', |
|
505 | - ) |
|
506 | - ); |
|
507 | - } |
|
508 | - } |
|
509 | - |
|
510 | - /** |
|
511 | - * Registers the post type toggle settings |
|
512 | - * |
|
513 | - * @param object $cmb new_cmb2_box(). |
|
514 | - * @return void |
|
515 | - */ |
|
516 | - public function post_type_toggles( $cmb ) { |
|
517 | - $post_types = apply_filters( 'lsx_health_plan_post_types', isset( $this->post_types ) ); |
|
518 | - |
|
519 | - $cmb->add_field( |
|
520 | - array( |
|
521 | - 'id' => 'post_type_toggles_title', |
|
522 | - 'type' => 'title', |
|
523 | - 'name' => __( 'Disable Post Types', 'lsx-health-plan' ), |
|
524 | - 'default' => __( 'Disable Post Types', 'lsx-health-plan' ), |
|
525 | - 'description' => __( 'Disable post types if you are wanting a minimal site.', 'lsx-health-plan' ), |
|
526 | - ) |
|
527 | - ); |
|
528 | - |
|
529 | - foreach ( $post_types as $post_type ) { |
|
530 | - if ( 'plan' === $post_type || 'exercise' === $post_type || ( 'video' === $post_type && false !== \lsx_health_plan\functions\get_option( 'exercise_enabled', false ) ) ) { |
|
531 | - continue; |
|
532 | - } |
|
533 | - |
|
534 | - $cmb->add_field( |
|
535 | - array( |
|
536 | - 'name' => ucwords( $post_type ), |
|
537 | - 'id' => $post_type . '_disabled', |
|
538 | - 'type' => 'checkbox', |
|
539 | - 'value' => 1, |
|
540 | - 'default' => 0, |
|
541 | - ) |
|
542 | - ); |
|
543 | - } |
|
544 | - |
|
545 | - $cmb->add_field( |
|
546 | - array( |
|
547 | - 'id' => 'settings_post_type_toggles_closing', |
|
548 | - 'type' => 'tab_closing', |
|
549 | - ) |
|
550 | - ); |
|
551 | - |
|
552 | - $cmb->add_field( |
|
553 | - array( |
|
554 | - 'id' => 'post_type_toggles_enable_title', |
|
555 | - 'type' => 'title', |
|
556 | - 'name' => __( 'Enable Post Types', 'lsx-health-plan' ), |
|
557 | - 'default' => __( 'Enable Post Types', 'lsx-health-plan' ), |
|
558 | - 'description' => __( 'Enable new functionality like the "exercise" post type.', 'lsx-health-plan' ), |
|
559 | - ) |
|
560 | - ); |
|
561 | - $cmb->add_field( |
|
562 | - array( |
|
563 | - 'name' => __( 'Exercises', 'lsx-health-plan' ), |
|
564 | - 'id' => 'exercise_enabled', |
|
565 | - 'type' => 'checkbox', |
|
566 | - 'value' => 1, |
|
567 | - 'default' => 0, |
|
568 | - 'description' => __( 'Enabling the exercise post type will automatically replace the Video post type.', 'lsx-health-plan' ), |
|
569 | - ) |
|
570 | - ); |
|
571 | - $cmb->add_field( |
|
572 | - array( |
|
573 | - 'id' => 'settings_post_type_toggles_enable_closing', |
|
574 | - 'type' => 'tab_closing', |
|
575 | - ) |
|
576 | - ); |
|
577 | - } |
|
578 | - /** |
|
579 | - * Registers the Profile Stat Toggle settings |
|
580 | - * |
|
581 | - * @param object $cmb new_cmb2_box(). |
|
582 | - * @return void |
|
583 | - */ |
|
584 | - |
|
585 | - public function stat_disable( $cmb ) { |
|
586 | - $cmb->add_field( |
|
587 | - array( |
|
588 | - 'id' => 'stat_disable_title', |
|
589 | - 'type' => 'title', |
|
590 | - 'name' => __( 'Disable Profile Stats', 'lsx-health-plan' ), |
|
591 | - 'default' => __( 'Disable Profile Stats', 'lsx-health-plan' ), |
|
592 | - ) |
|
593 | - ); |
|
594 | - $cmb->add_field( |
|
595 | - array( |
|
596 | - 'name' => __( 'Disable All Stats', 'lsx-health-plan' ), |
|
597 | - 'desc' => 'Disable All Stats', |
|
598 | - 'id' => 'disable_all_stats', |
|
599 | - 'type' => 'checkbox', |
|
600 | - 'value' => 1, |
|
601 | - 'default' => 0, |
|
602 | - ) |
|
603 | - ); |
|
604 | - $cmb->add_field( |
|
605 | - array( |
|
606 | - 'name' => __( 'Disable Weight', 'lsx-health-plan' ), |
|
607 | - 'id' => 'disable_weight_checkbox', |
|
608 | - 'type' => 'checkbox', |
|
609 | - 'value' => 1, |
|
610 | - 'default' => 0, |
|
611 | - ) |
|
612 | - ); |
|
613 | - $cmb->add_field( |
|
614 | - array( |
|
615 | - 'name' => __( 'Disable Height', 'lsx-health-plan' ), |
|
616 | - 'id' => 'disable_height_checkbox', |
|
617 | - 'type' => 'checkbox', |
|
618 | - 'value' => 1, |
|
619 | - 'default' => 0, |
|
620 | - ) |
|
621 | - ); |
|
622 | - $cmb->add_field( |
|
623 | - array( |
|
624 | - 'name' => __( 'Disable Waist', 'lsx-health-plan' ), |
|
625 | - 'id' => 'disable_waist_checkbox', |
|
626 | - 'type' => 'checkbox', |
|
627 | - 'value' => 1, |
|
628 | - 'default' => 0, |
|
629 | - ) |
|
630 | - ); |
|
631 | - $cmb->add_field( |
|
632 | - array( |
|
633 | - 'name' => __( 'Disable BMI', 'lsx-health-plan' ), |
|
634 | - 'id' => 'disable_bmi_checkbox', |
|
635 | - 'type' => 'checkbox', |
|
636 | - 'value' => 1, |
|
637 | - 'default' => 0, |
|
638 | - ) |
|
639 | - ); |
|
640 | - $cmb->add_field( |
|
641 | - array( |
|
642 | - 'id' => 'settings_stat_disable_closing', |
|
643 | - 'type' => 'tab_closing', |
|
644 | - ) |
|
645 | - ); |
|
646 | - } |
|
647 | - |
|
648 | - /** |
|
649 | - * Enable Business Directory Search settings only if LSX Search plugin is enabled. |
|
650 | - * |
|
651 | - * @param object $cmb The CMB2() class. |
|
652 | - * @param string $section either engine,archive or single. |
|
653 | - * @return void |
|
654 | - */ |
|
655 | - public function generate_tabs( $cmb ) { |
|
656 | - $tabs = $this->get_settings_tabs(); |
|
657 | - |
|
658 | - foreach ( $tabs as $tab_key => $tab ) { |
|
659 | - $cmb->add_field( |
|
660 | - array( |
|
661 | - 'id' => 'settings_' . $tab_key . '_title', |
|
662 | - 'type' => 'title', |
|
663 | - 'name' => $tab['title'], |
|
664 | - 'default' => $tab['title'], |
|
665 | - 'description' => $tab['desc'], |
|
666 | - ) |
|
667 | - ); |
|
668 | - do_action( 'lsx_hp_settings_page_' . $tab_key . '_top', $cmb ); |
|
669 | - |
|
670 | - do_action( 'lsx_hp_settings_page_' . $tab_key . '_middle', $cmb ); |
|
671 | - |
|
672 | - do_action( 'lsx_hp_settings_page_' . $tab_key . '_bottom', $cmb ); |
|
673 | - |
|
674 | - $cmb->add_field( |
|
675 | - array( |
|
676 | - 'id' => 'settings_' . $tab_key . '_closing', |
|
677 | - 'type' => 'tab_closing', |
|
678 | - ) |
|
679 | - ); |
|
680 | - } |
|
681 | - } |
|
682 | - |
|
683 | - |
|
684 | - /** |
|
685 | - * Returns the tabs and their descriptions. |
|
686 | - * |
|
687 | - * @return array |
|
688 | - */ |
|
689 | - public function get_settings_tabs() { |
|
690 | - $tabs = array( |
|
691 | - 'general' => array( |
|
692 | - 'title' => __( 'General', 'lsx-health-plan' ), |
|
693 | - 'desc' => __( 'Control the sitewide settings for the LSX HP site.', 'lsx-health-plan' ), |
|
694 | - ), |
|
695 | - ); |
|
696 | - |
|
697 | - foreach ( $this->post_types as $post_type ) { |
|
698 | - switch ( $post_type ) { |
|
699 | - default: |
|
700 | - //if ( ! in_array( $post_type, \lsx\search\includes\get_restricted_post_types() ) ) { |
|
701 | - $temp_post_type = get_post_type_object( $post_type ); |
|
702 | - if ( ! is_wp_error( $temp_post_type ) ) { |
|
703 | - $page_url = get_post_type_archive_link( $temp_post_type->name ); |
|
704 | - $description = sprintf( |
|
705 | - /* translators: %s: The subscription info */ |
|
706 | - __( 'Control the settings for your <a target="_blank" href="%1$s">%2$s</a> archive.', 'lsx-search' ), |
|
707 | - $page_url, |
|
708 | - $temp_post_type->label |
|
709 | - ); |
|
710 | - |
|
711 | - $tabs[ $post_type ] = array( |
|
712 | - 'title' => $temp_post_type->label, |
|
713 | - 'desc' => $description, |
|
714 | - ); |
|
715 | - } |
|
716 | - //} |
|
717 | - break; |
|
718 | - } |
|
719 | - } |
|
720 | - return $tabs; |
|
721 | - } |
|
15 | + /** |
|
16 | + * Holds class instance |
|
17 | + * |
|
18 | + * @since 1.0.0 |
|
19 | + * |
|
20 | + * @var object \lsx_health_plan\classes\admin\Settings() |
|
21 | + */ |
|
22 | + protected static $instance = null; |
|
23 | + |
|
24 | + /** |
|
25 | + * Option key, and option page slug |
|
26 | + * |
|
27 | + * @var string |
|
28 | + */ |
|
29 | + protected $screen_id = 'lsx_health_plan_settings'; |
|
30 | + |
|
31 | + /** |
|
32 | + * An array of the post types for the Global Downloads field. |
|
33 | + * |
|
34 | + * @var array |
|
35 | + */ |
|
36 | + public $download_types = array(); |
|
37 | + |
|
38 | + /** |
|
39 | + * An array of the post types for the Global Defaults field. |
|
40 | + * |
|
41 | + * @var array |
|
42 | + */ |
|
43 | + public $default_types = array(); |
|
44 | + |
|
45 | + /** |
|
46 | + * An array of the endpoints for the Endpoint Translation field. |
|
47 | + * |
|
48 | + * @var array |
|
49 | + */ |
|
50 | + public $endpoints = array(); |
|
51 | + |
|
52 | + /** |
|
53 | + * Constructor |
|
54 | + */ |
|
55 | + public function __construct() { |
|
56 | + $this->load_classes(); |
|
57 | + add_action( 'cmb2_admin_init', array( $this, 'register_settings_page' ) ); |
|
58 | + add_action( 'lsx_hp_settings_page', array( $this, 'generate_tabs' ), 1, 1 ); |
|
59 | + |
|
60 | + add_action( 'lsx_hp_settings_page_general_top', array( $this, 'general_settings' ), 1, 1 ); |
|
61 | + add_action( 'lsx_hp_settings_page', array( $this, 'global_defaults' ), 3, 1 ); |
|
62 | + add_action( 'lsx_hp_settings_page', array( $this, 'global_downloads' ), 5, 1 ); |
|
63 | + add_action( 'lsx_hp_settings_page', array( $this, 'stat_disable' ), 6, 1 ); |
|
64 | + add_action( 'lsx_hp_settings_page', array( $this, 'endpoint_translations' ), 7, 1 ); |
|
65 | + add_action( 'lsx_hp_settings_page', array( $this, 'exercise_translations' ), 7, 1 ); |
|
66 | + add_action( 'lsx_hp_settings_page', array( $this, 'post_type_toggles' ), 9, 1 ); |
|
67 | + } |
|
68 | + |
|
69 | + /** |
|
70 | + * Return an instance of this class. |
|
71 | + * |
|
72 | + * @since 1.0.0 |
|
73 | + * |
|
74 | + * @return object \lsx_health_plan\classes\admin\Settings() A single instance of this class. |
|
75 | + */ |
|
76 | + public static function get_instance() { |
|
77 | + // If the single instance hasn't been set, set it now. |
|
78 | + if ( null === self::$instance ) { |
|
79 | + self::$instance = new self(); |
|
80 | + } |
|
81 | + return self::$instance; |
|
82 | + } |
|
83 | + |
|
84 | + /** |
|
85 | + * Loads the variable classes and the static classes. |
|
86 | + */ |
|
87 | + private function load_classes() { |
|
88 | + |
|
89 | + $this->post_types = array( |
|
90 | + 'plan', |
|
91 | + 'workout', |
|
92 | + 'exercise', |
|
93 | + //'meal', |
|
94 | + 'recipe', |
|
95 | + //'tip', |
|
96 | + ); |
|
97 | + |
|
98 | + foreach ( $this->post_types as $post_type ) { |
|
99 | + $this->$post_type = require_once LSX_HEALTH_PLAN_PATH . 'classes/admin/settings/class-' . $post_type . '.php'; |
|
100 | + } |
|
101 | + } |
|
102 | + |
|
103 | + /** |
|
104 | + * Sets the variables needed for the fields. |
|
105 | + * |
|
106 | + * @return void |
|
107 | + */ |
|
108 | + public function set_vars() { |
|
109 | + |
|
110 | + $this->default_types = array( |
|
111 | + 'page' => array( |
|
112 | + 'title' => __( 'Warm Up', 'lsx-health-plan' ), |
|
113 | + 'description' => __( 'Set a default warm up routine.', 'lsx-health-plan' ), |
|
114 | + 'limit' => 1, |
|
115 | + 'id' => 'plan_warmup', |
|
116 | + ), |
|
117 | + ); |
|
118 | + $this->download_types = array( |
|
119 | + 'page' => array( |
|
120 | + 'title' => __( 'Warm Up', 'lsx-health-plan' ), |
|
121 | + 'description' => __( 'Set a default warm up routine.', 'lsx-health-plan' ), |
|
122 | + 'limit' => 1, |
|
123 | + ), |
|
124 | + ); |
|
125 | + $this->endpoints = array( |
|
126 | + 'endpoint_warm_up' => array( |
|
127 | + 'title' => __( 'Warm Up Endpoint', 'lsx-health-plan' ), |
|
128 | + 'default' => 'warm-up', |
|
129 | + ), |
|
130 | + ); |
|
131 | + |
|
132 | + if ( post_type_exists( 'meal' ) ) { |
|
133 | + $this->download_types['meal'] = array( |
|
134 | + 'title' => __( 'Meal Plan', 'lsx-health-plan' ), |
|
135 | + 'description' => __( 'Set a default meal plan.', 'lsx-health-plan' ), |
|
136 | + ); |
|
137 | + $this->default_types['meal'] = array( |
|
138 | + 'title' => __( 'Meal Plan', 'lsx-health-plan' ), |
|
139 | + 'description' => __( 'Set a default meal plan.', 'lsx-health-plan' ), |
|
140 | + 'id' => 'connected_meals', |
|
141 | + ); |
|
142 | + $this->endpoints['endpoint_meal'] = array( |
|
143 | + 'title' => __( 'Meal Endpoint', 'lsx-health-plan' ), |
|
144 | + 'default' => 'meal', |
|
145 | + 'description' => __( 'Define the tab slug which shows on the single plan page.', 'lsx-health-plan' ), |
|
146 | + ); |
|
147 | + $this->endpoints['endpoint_meal_archive'] = array( |
|
148 | + 'title' => __( 'Meals Archive Endpoint', 'lsx-health-plan' ), |
|
149 | + 'default' => 'meals', |
|
150 | + ); |
|
151 | + $this->endpoints['meal_single_slug'] = array( |
|
152 | + 'title' => __( 'Single Meal Slug', 'lsx-health-plan' ), |
|
153 | + 'default' => 'meal', |
|
154 | + ); |
|
155 | + } |
|
156 | + if ( post_type_exists( 'recipe' ) ) { |
|
157 | + $this->download_types['recipe'] = array( |
|
158 | + 'title' => __( 'Recipe', 'lsx-health-plan' ), |
|
159 | + 'description' => __( 'Set a default recipe.', 'lsx-health-plan' ), |
|
160 | + ); |
|
161 | + $this->default_types['recipe'] = array( |
|
162 | + 'title' => __( 'Recipe', 'lsx-health-plan' ), |
|
163 | + 'description' => __( 'Set a default recipe.', 'lsx-health-plan' ), |
|
164 | + 'id' => 'connected_recipes', |
|
165 | + ); |
|
166 | + $this->endpoints['endpoint_recipe'] = array( |
|
167 | + 'title' => __( 'Recipes Endpoint', 'lsx-health-plan' ), |
|
168 | + 'default' => 'recipe', |
|
169 | + ); |
|
170 | + } |
|
171 | + if ( post_type_exists( 'workout' ) ) { |
|
172 | + $this->download_types['workout'] = array( |
|
173 | + 'title' => __( 'Workout', 'lsx-health-plan' ), |
|
174 | + 'description' => __( 'Set a default workout routine PDF.', 'lsx-health-plan' ), |
|
175 | + ); |
|
176 | + $this->default_types['workout'] = array( |
|
177 | + 'title' => __( 'Workout', 'lsx-health-plan' ), |
|
178 | + 'description' => __( 'Set a default workout routine.', 'lsx-health-plan' ), |
|
179 | + 'id' => 'connected_workouts', |
|
180 | + ); |
|
181 | + $this->endpoints['endpoint_workout_archive'] = array( |
|
182 | + 'title' => __( 'Workouts Archive Endpoint', 'lsx-health-plan' ), |
|
183 | + 'default' => '', |
|
184 | + ); |
|
185 | + $this->endpoints['endpoint_workout'] = array( |
|
186 | + 'title' => __( 'Single Workout Endpoint', 'lsx-health-plan' ), |
|
187 | + 'default' => 'workout', |
|
188 | + ); |
|
189 | + } |
|
190 | + |
|
191 | + $this->endpoints['login_slug'] = array( |
|
192 | + 'title' => __( 'Login Slug', 'lsx-health-plan' ), |
|
193 | + 'default' => 'login', |
|
194 | + ); |
|
195 | + $this->endpoints['my_plan_slug'] = array( |
|
196 | + 'title' => __( 'My Plan Slug', 'lsx-health-plan' ), |
|
197 | + 'default' => 'my-plan', |
|
198 | + ); |
|
199 | + $this->endpoints['plan_single_slug'] = array( |
|
200 | + 'title' => __( 'Single Plan Slug', 'lsx-health-plan' ), |
|
201 | + 'default' => 'plan', |
|
202 | + ); |
|
203 | + $this->endpoints['endpoint_plan_archive'] = array( |
|
204 | + 'title' => __( 'Plans Archive Endpoint', 'lsx-health-plan' ), |
|
205 | + 'default' => 'plans', |
|
206 | + ); |
|
207 | + |
|
208 | + if ( false !== \lsx_health_plan\functions\get_option( 'exercise_enabled', false ) ) { |
|
209 | + $this->endpoints['exercise'] = array( |
|
210 | + 'exercise_single' => array( |
|
211 | + 'title' => __( 'Single Exercise Slug', 'lsx-health-plan' ), |
|
212 | + 'default' => 'exercise', |
|
213 | + ), |
|
214 | + 'exercise_archive' => array( |
|
215 | + 'title' => __( 'Archive Exercise Slug', 'lsx-health-plan' ), |
|
216 | + 'default' => 'exercises', |
|
217 | + ), |
|
218 | + 'exercise_type' => array( |
|
219 | + 'title' => __( 'Exercise Type Slug', 'lsx-health-plan' ), |
|
220 | + 'default' => 'exercise-type', |
|
221 | + ), |
|
222 | + 'exercise_equipment' => array( |
|
223 | + 'title' => __( 'Equipment Slug', 'lsx-health-plan' ), |
|
224 | + 'default' => 'equipment', |
|
225 | + ), |
|
226 | + 'exercise_musclegroup' => array( |
|
227 | + 'title' => __( 'Muscle Group Slug', 'lsx-health-plan' ), |
|
228 | + 'default' => 'muscle-group', |
|
229 | + ), |
|
230 | + ); |
|
231 | + } |
|
232 | + } |
|
233 | + |
|
234 | + /** |
|
235 | + * Hook in and register a submenu options page for the Page post-type menu. |
|
236 | + */ |
|
237 | + public function register_settings_page() { |
|
238 | + $this->set_vars(); |
|
239 | + $cmb = new_cmb2_box( |
|
240 | + array( |
|
241 | + 'id' => $this->screen_id, |
|
242 | + 'title' => esc_html__( 'Settings', 'lsx-health-plan' ), |
|
243 | + 'object_types' => array( 'options-page' ), |
|
244 | + 'option_key' => 'lsx_health_plan_options', // The option key and admin menu page slug. |
|
245 | + 'parent_slug' => 'edit.php?post_type=plan', // Make options page a submenu item of the themes menu. |
|
246 | + 'capability' => 'manage_options', // Cap required to view options-page. |
|
247 | + ) |
|
248 | + ); |
|
249 | + do_action( 'lsx_hp_settings_page', $cmb ); |
|
250 | + } |
|
251 | + |
|
252 | + /** |
|
253 | + * Registers the general settings. |
|
254 | + * |
|
255 | + * @param object $cmb new_cmb2_box(). |
|
256 | + * @return void |
|
257 | + */ |
|
258 | + public function general_settings( $cmb ) { |
|
259 | + $cmb->add_field( |
|
260 | + array( |
|
261 | + 'name' => __( 'Membership Product', 'lsx-health-plan' ), |
|
262 | + 'id' => 'membership_product', |
|
263 | + 'type' => 'post_search_ajax', |
|
264 | + 'limit' => 1, |
|
265 | + 'sortable' => false, |
|
266 | + 'query_args' => array( |
|
267 | + 'post_type' => array( 'product' ), |
|
268 | + 'post_status' => array( 'publish' ), |
|
269 | + 'posts_per_page' => -1, |
|
270 | + ), |
|
271 | + ) |
|
272 | + ); |
|
273 | + |
|
274 | + $cmb->add_field( |
|
275 | + array( |
|
276 | + 'name' => __( 'Your Warm-up Intro', 'lsx-health-plan' ), |
|
277 | + 'id' => 'warmup_intro', |
|
278 | + 'type' => 'textarea_small', |
|
279 | + 'value' => '', |
|
280 | + 'default' => __( "Don't forget your warm-up! It's a vital part of your daily workout routine.", 'lsx-health-plan' ), |
|
281 | + ) |
|
282 | + ); |
|
283 | + if ( post_type_exists( 'workout' ) ) { |
|
284 | + $cmb->add_field( |
|
285 | + array( |
|
286 | + 'name' => __( 'Your Workout Intro', 'lsx-health-plan' ), |
|
287 | + 'id' => 'workout_intro', |
|
288 | + 'type' => 'textarea_small', |
|
289 | + 'value' => '', |
|
290 | + 'default' => __( "Let's do this! Smash your daily workout and reach your fitness goals.", 'lsx-health-plan' ), |
|
291 | + ) |
|
292 | + ); |
|
293 | + } |
|
294 | + if ( post_type_exists( 'meal' ) ) { |
|
295 | + $cmb->add_field( |
|
296 | + array( |
|
297 | + 'name' => __( 'Your Meal Plan Intro', 'lsx-health-plan' ), |
|
298 | + 'id' => 'meal_plan_intro', |
|
299 | + 'type' => 'textarea_small', |
|
300 | + 'value' => '', |
|
301 | + 'default' => __( 'Get the right mix of nutrients to keep muscles strong & healthy.', 'lsx-health-plan' ), |
|
302 | + ) |
|
303 | + ); |
|
304 | + } |
|
305 | + if ( post_type_exists( 'recipe' ) ) { |
|
306 | + $cmb->add_field( |
|
307 | + array( |
|
308 | + 'name' => __( 'Recipes Intro', 'lsx-health-plan' ), |
|
309 | + 'id' => 'recipes_intro', |
|
310 | + 'type' => 'textarea_small', |
|
311 | + 'value' => '', |
|
312 | + 'default' => __( "Let's get cooking! Delicious and easy to follow recipes.", 'lsx-health-plan' ), |
|
313 | + ) |
|
314 | + ); |
|
315 | + } |
|
316 | + } |
|
317 | + |
|
318 | + /** |
|
319 | + * Registers the global default settings. |
|
320 | + * |
|
321 | + * @param object $cmb new_cmb2_box(). |
|
322 | + * @return void |
|
323 | + */ |
|
324 | + public function global_defaults( $cmb ) { |
|
325 | + $cmb->add_field( |
|
326 | + array( |
|
327 | + 'id' => 'global_defaults_title', |
|
328 | + 'type' => 'title', |
|
329 | + 'name' => __( 'Global Defaults', 'lsx-health-plan' ), |
|
330 | + 'default' => __( 'Global Defaults', 'lsx-health-plan' ), |
|
331 | + 'description' => __( 'If you have not connected a specific post to your day plan, set a default option below.', 'lsx-health-plan' ), |
|
332 | + ) |
|
333 | + ); |
|
334 | + |
|
335 | + foreach ( $this->default_types as $type => $default_type ) { |
|
336 | + $limit = 5; |
|
337 | + $sortable = false; |
|
338 | + if ( isset( $default_type['limit'] ) ) { |
|
339 | + $limit = $default_type['limit']; |
|
340 | + $sortable = true; |
|
341 | + } |
|
342 | + |
|
343 | + if ( 'page' === $type && false !== \lsx_health_plan\functions\get_option( 'exercise_enabled', false ) ) { |
|
344 | + $type = array( 'page', 'workout' ); |
|
345 | + } |
|
346 | + |
|
347 | + $cmb->add_field( |
|
348 | + array( |
|
349 | + 'name' => $default_type['title'], |
|
350 | + 'desc' => $default_type['description'], |
|
351 | + 'id' => $default_type['id'], |
|
352 | + 'type' => 'post_search_ajax', |
|
353 | + 'limit' => $limit, |
|
354 | + 'sortable' => $sortable, |
|
355 | + 'query_args' => array( |
|
356 | + 'post_type' => $type, |
|
357 | + 'post_status' => array( 'publish' ), |
|
358 | + 'posts_per_page' => -1, |
|
359 | + ), |
|
360 | + ) |
|
361 | + ); |
|
362 | + } |
|
363 | + |
|
364 | + $cmb->add_field( |
|
365 | + array( |
|
366 | + 'id' => 'settings_global_defaults_closing', |
|
367 | + 'type' => 'tab_closing', |
|
368 | + ) |
|
369 | + ); |
|
370 | + } |
|
371 | + |
|
372 | + /** |
|
373 | + * Registers the global dowloads settings |
|
374 | + * |
|
375 | + * @param object $cmb new_cmb2_box(). |
|
376 | + * @return void |
|
377 | + */ |
|
378 | + public function global_downloads( $cmb ) { |
|
379 | + if ( ! function_exists( 'download_monitor' ) ) { |
|
380 | + return; |
|
381 | + } |
|
382 | + $page_url = 'https://wordpress.org/plugins/download-monitor/'; |
|
383 | + $plugin_name = 'Download Monitor'; |
|
384 | + $description = sprintf( |
|
385 | + /* translators: %s: The subscription info */ |
|
386 | + __( 'If you are using <a target="_blank" href="%1$s">%2$s</a> you can set a default download file for your plan here.', 'lsx-search' ), |
|
387 | + $page_url, |
|
388 | + $plugin_name |
|
389 | + ); |
|
390 | + $cmb->add_field( |
|
391 | + array( |
|
392 | + 'id' => 'global_downloads_title', |
|
393 | + 'type' => 'title', |
|
394 | + 'name' => __( 'Global Downloads', 'lsx-health-plan' ), |
|
395 | + 'default' => __( 'Global Downloads', 'lsx-health-plan' ), |
|
396 | + 'description' => $description, |
|
397 | + ) |
|
398 | + ); |
|
399 | + |
|
400 | + foreach ( $this->download_types as $type => $download_type ) { |
|
401 | + $limit = 5; |
|
402 | + $sortable = false; |
|
403 | + if ( isset( $download_type['limit'] ) ) { |
|
404 | + $limit = $download_type['limit']; |
|
405 | + $sortable = true; |
|
406 | + } |
|
407 | + |
|
408 | + $cmb->add_field( |
|
409 | + array( |
|
410 | + 'name' => $download_type['title'], |
|
411 | + 'id' => 'download_' . $type, |
|
412 | + 'type' => 'post_search_ajax', |
|
413 | + 'limit' => $limit, |
|
414 | + 'sortable' => $sortable, |
|
415 | + 'query_args' => array( |
|
416 | + 'post_type' => array( 'dlm_download' ), |
|
417 | + 'post_status' => array( 'publish' ), |
|
418 | + 'posts_per_page' => -1, |
|
419 | + ), |
|
420 | + ) |
|
421 | + ); |
|
422 | + } |
|
423 | + $cmb->add_field( |
|
424 | + array( |
|
425 | + 'id' => 'settings_global_downloads_closing', |
|
426 | + 'type' => 'tab_closing', |
|
427 | + ) |
|
428 | + ); |
|
429 | + } |
|
430 | + |
|
431 | + /** |
|
432 | + * Registers the endpoint translation settings. |
|
433 | + * |
|
434 | + * @param object $cmb new_cmb2_box(). |
|
435 | + * @return void |
|
436 | + */ |
|
437 | + public function endpoint_translations( $cmb ) { |
|
438 | + $cmb->add_field( |
|
439 | + array( |
|
440 | + 'id' => 'endpoints_title', |
|
441 | + 'type' => 'title', |
|
442 | + 'name' => __( 'Set Endpoint Translations', 'lsx-health-plan' ), |
|
443 | + 'default' => __( 'Set Endpoint Translations', 'lsx-health-plan' ), |
|
444 | + ) |
|
445 | + ); |
|
446 | + foreach ( $this->endpoints as $slug => $endpoint_vars ) { |
|
447 | + if ( 'exercise' === $slug ) { |
|
448 | + continue; |
|
449 | + } |
|
450 | + |
|
451 | + $cmb->add_field( |
|
452 | + array( |
|
453 | + 'name' => $endpoint_vars['title'], |
|
454 | + 'id' => $slug, |
|
455 | + 'type' => 'input', |
|
456 | + 'value' => '', |
|
457 | + 'default' => $endpoint_vars['default'], |
|
458 | + ) |
|
459 | + ); |
|
460 | + } |
|
461 | + $cmb->add_field( |
|
462 | + array( |
|
463 | + 'id' => 'settings_endpoints_closing', |
|
464 | + 'type' => 'tab_closing', |
|
465 | + 'before_row' => '<p style="margin-top:20px; font-style: italic;">Endpoint is a web address (URL) at which the user can gain access to it. You need to resave your permalinks after changing the endpoint settings.</p>', |
|
466 | + ) |
|
467 | + ); |
|
468 | + } |
|
469 | + |
|
470 | + /** |
|
471 | + * Registers the endpoint translation settings. |
|
472 | + * |
|
473 | + * @param object $cmb new_cmb2_box(). |
|
474 | + * @return void |
|
475 | + */ |
|
476 | + public function exercise_translations( $cmb ) { |
|
477 | + if ( isset( $this->endpoints['exercise'] ) && '' !== $this->endpoints['exercise'] && ! empty( $this->endpoints['exercise'] ) ) { |
|
478 | + $cmb->add_field( |
|
479 | + array( |
|
480 | + 'id' => 'exercise_endpoints_title', |
|
481 | + 'type' => 'title', |
|
482 | + 'name' => __( 'Set Exercise Translations', 'lsx-health-plan' ), |
|
483 | + 'default' => __( 'Set Exercise Translations', 'lsx-health-plan' ), |
|
484 | + 'description' => __( 'Change the exercise endpoints.', 'lsx-health-plan' ), |
|
485 | + ) |
|
486 | + ); |
|
487 | + |
|
488 | + foreach ( $this->endpoints['exercise'] as $slug => $endpoint_vars ) { |
|
489 | + $cmb->add_field( |
|
490 | + array( |
|
491 | + 'name' => $endpoint_vars['title'], |
|
492 | + 'id' => 'endpoint_' . $slug, |
|
493 | + 'type' => 'input', |
|
494 | + 'value' => '', |
|
495 | + 'default' => $endpoint_vars['default'], |
|
496 | + ) |
|
497 | + ); |
|
498 | + } |
|
499 | + |
|
500 | + $cmb->add_field( |
|
501 | + array( |
|
502 | + 'id' => 'settings_exercise_endpoints_closing', |
|
503 | + 'type' => 'tab_closing', |
|
504 | + 'before_row' => '<p style="margin-top:20px; font-style: italic;">If you need to translate the exercise URL endpoints, do so below.</p>', |
|
505 | + ) |
|
506 | + ); |
|
507 | + } |
|
508 | + } |
|
509 | + |
|
510 | + /** |
|
511 | + * Registers the post type toggle settings |
|
512 | + * |
|
513 | + * @param object $cmb new_cmb2_box(). |
|
514 | + * @return void |
|
515 | + */ |
|
516 | + public function post_type_toggles( $cmb ) { |
|
517 | + $post_types = apply_filters( 'lsx_health_plan_post_types', isset( $this->post_types ) ); |
|
518 | + |
|
519 | + $cmb->add_field( |
|
520 | + array( |
|
521 | + 'id' => 'post_type_toggles_title', |
|
522 | + 'type' => 'title', |
|
523 | + 'name' => __( 'Disable Post Types', 'lsx-health-plan' ), |
|
524 | + 'default' => __( 'Disable Post Types', 'lsx-health-plan' ), |
|
525 | + 'description' => __( 'Disable post types if you are wanting a minimal site.', 'lsx-health-plan' ), |
|
526 | + ) |
|
527 | + ); |
|
528 | + |
|
529 | + foreach ( $post_types as $post_type ) { |
|
530 | + if ( 'plan' === $post_type || 'exercise' === $post_type || ( 'video' === $post_type && false !== \lsx_health_plan\functions\get_option( 'exercise_enabled', false ) ) ) { |
|
531 | + continue; |
|
532 | + } |
|
533 | + |
|
534 | + $cmb->add_field( |
|
535 | + array( |
|
536 | + 'name' => ucwords( $post_type ), |
|
537 | + 'id' => $post_type . '_disabled', |
|
538 | + 'type' => 'checkbox', |
|
539 | + 'value' => 1, |
|
540 | + 'default' => 0, |
|
541 | + ) |
|
542 | + ); |
|
543 | + } |
|
544 | + |
|
545 | + $cmb->add_field( |
|
546 | + array( |
|
547 | + 'id' => 'settings_post_type_toggles_closing', |
|
548 | + 'type' => 'tab_closing', |
|
549 | + ) |
|
550 | + ); |
|
551 | + |
|
552 | + $cmb->add_field( |
|
553 | + array( |
|
554 | + 'id' => 'post_type_toggles_enable_title', |
|
555 | + 'type' => 'title', |
|
556 | + 'name' => __( 'Enable Post Types', 'lsx-health-plan' ), |
|
557 | + 'default' => __( 'Enable Post Types', 'lsx-health-plan' ), |
|
558 | + 'description' => __( 'Enable new functionality like the "exercise" post type.', 'lsx-health-plan' ), |
|
559 | + ) |
|
560 | + ); |
|
561 | + $cmb->add_field( |
|
562 | + array( |
|
563 | + 'name' => __( 'Exercises', 'lsx-health-plan' ), |
|
564 | + 'id' => 'exercise_enabled', |
|
565 | + 'type' => 'checkbox', |
|
566 | + 'value' => 1, |
|
567 | + 'default' => 0, |
|
568 | + 'description' => __( 'Enabling the exercise post type will automatically replace the Video post type.', 'lsx-health-plan' ), |
|
569 | + ) |
|
570 | + ); |
|
571 | + $cmb->add_field( |
|
572 | + array( |
|
573 | + 'id' => 'settings_post_type_toggles_enable_closing', |
|
574 | + 'type' => 'tab_closing', |
|
575 | + ) |
|
576 | + ); |
|
577 | + } |
|
578 | + /** |
|
579 | + * Registers the Profile Stat Toggle settings |
|
580 | + * |
|
581 | + * @param object $cmb new_cmb2_box(). |
|
582 | + * @return void |
|
583 | + */ |
|
584 | + |
|
585 | + public function stat_disable( $cmb ) { |
|
586 | + $cmb->add_field( |
|
587 | + array( |
|
588 | + 'id' => 'stat_disable_title', |
|
589 | + 'type' => 'title', |
|
590 | + 'name' => __( 'Disable Profile Stats', 'lsx-health-plan' ), |
|
591 | + 'default' => __( 'Disable Profile Stats', 'lsx-health-plan' ), |
|
592 | + ) |
|
593 | + ); |
|
594 | + $cmb->add_field( |
|
595 | + array( |
|
596 | + 'name' => __( 'Disable All Stats', 'lsx-health-plan' ), |
|
597 | + 'desc' => 'Disable All Stats', |
|
598 | + 'id' => 'disable_all_stats', |
|
599 | + 'type' => 'checkbox', |
|
600 | + 'value' => 1, |
|
601 | + 'default' => 0, |
|
602 | + ) |
|
603 | + ); |
|
604 | + $cmb->add_field( |
|
605 | + array( |
|
606 | + 'name' => __( 'Disable Weight', 'lsx-health-plan' ), |
|
607 | + 'id' => 'disable_weight_checkbox', |
|
608 | + 'type' => 'checkbox', |
|
609 | + 'value' => 1, |
|
610 | + 'default' => 0, |
|
611 | + ) |
|
612 | + ); |
|
613 | + $cmb->add_field( |
|
614 | + array( |
|
615 | + 'name' => __( 'Disable Height', 'lsx-health-plan' ), |
|
616 | + 'id' => 'disable_height_checkbox', |
|
617 | + 'type' => 'checkbox', |
|
618 | + 'value' => 1, |
|
619 | + 'default' => 0, |
|
620 | + ) |
|
621 | + ); |
|
622 | + $cmb->add_field( |
|
623 | + array( |
|
624 | + 'name' => __( 'Disable Waist', 'lsx-health-plan' ), |
|
625 | + 'id' => 'disable_waist_checkbox', |
|
626 | + 'type' => 'checkbox', |
|
627 | + 'value' => 1, |
|
628 | + 'default' => 0, |
|
629 | + ) |
|
630 | + ); |
|
631 | + $cmb->add_field( |
|
632 | + array( |
|
633 | + 'name' => __( 'Disable BMI', 'lsx-health-plan' ), |
|
634 | + 'id' => 'disable_bmi_checkbox', |
|
635 | + 'type' => 'checkbox', |
|
636 | + 'value' => 1, |
|
637 | + 'default' => 0, |
|
638 | + ) |
|
639 | + ); |
|
640 | + $cmb->add_field( |
|
641 | + array( |
|
642 | + 'id' => 'settings_stat_disable_closing', |
|
643 | + 'type' => 'tab_closing', |
|
644 | + ) |
|
645 | + ); |
|
646 | + } |
|
647 | + |
|
648 | + /** |
|
649 | + * Enable Business Directory Search settings only if LSX Search plugin is enabled. |
|
650 | + * |
|
651 | + * @param object $cmb The CMB2() class. |
|
652 | + * @param string $section either engine,archive or single. |
|
653 | + * @return void |
|
654 | + */ |
|
655 | + public function generate_tabs( $cmb ) { |
|
656 | + $tabs = $this->get_settings_tabs(); |
|
657 | + |
|
658 | + foreach ( $tabs as $tab_key => $tab ) { |
|
659 | + $cmb->add_field( |
|
660 | + array( |
|
661 | + 'id' => 'settings_' . $tab_key . '_title', |
|
662 | + 'type' => 'title', |
|
663 | + 'name' => $tab['title'], |
|
664 | + 'default' => $tab['title'], |
|
665 | + 'description' => $tab['desc'], |
|
666 | + ) |
|
667 | + ); |
|
668 | + do_action( 'lsx_hp_settings_page_' . $tab_key . '_top', $cmb ); |
|
669 | + |
|
670 | + do_action( 'lsx_hp_settings_page_' . $tab_key . '_middle', $cmb ); |
|
671 | + |
|
672 | + do_action( 'lsx_hp_settings_page_' . $tab_key . '_bottom', $cmb ); |
|
673 | + |
|
674 | + $cmb->add_field( |
|
675 | + array( |
|
676 | + 'id' => 'settings_' . $tab_key . '_closing', |
|
677 | + 'type' => 'tab_closing', |
|
678 | + ) |
|
679 | + ); |
|
680 | + } |
|
681 | + } |
|
682 | + |
|
683 | + |
|
684 | + /** |
|
685 | + * Returns the tabs and their descriptions. |
|
686 | + * |
|
687 | + * @return array |
|
688 | + */ |
|
689 | + public function get_settings_tabs() { |
|
690 | + $tabs = array( |
|
691 | + 'general' => array( |
|
692 | + 'title' => __( 'General', 'lsx-health-plan' ), |
|
693 | + 'desc' => __( 'Control the sitewide settings for the LSX HP site.', 'lsx-health-plan' ), |
|
694 | + ), |
|
695 | + ); |
|
696 | + |
|
697 | + foreach ( $this->post_types as $post_type ) { |
|
698 | + switch ( $post_type ) { |
|
699 | + default: |
|
700 | + //if ( ! in_array( $post_type, \lsx\search\includes\get_restricted_post_types() ) ) { |
|
701 | + $temp_post_type = get_post_type_object( $post_type ); |
|
702 | + if ( ! is_wp_error( $temp_post_type ) ) { |
|
703 | + $page_url = get_post_type_archive_link( $temp_post_type->name ); |
|
704 | + $description = sprintf( |
|
705 | + /* translators: %s: The subscription info */ |
|
706 | + __( 'Control the settings for your <a target="_blank" href="%1$s">%2$s</a> archive.', 'lsx-search' ), |
|
707 | + $page_url, |
|
708 | + $temp_post_type->label |
|
709 | + ); |
|
710 | + |
|
711 | + $tabs[ $post_type ] = array( |
|
712 | + 'title' => $temp_post_type->label, |
|
713 | + 'desc' => $description, |
|
714 | + ); |
|
715 | + } |
|
716 | + //} |
|
717 | + break; |
|
718 | + } |
|
719 | + } |
|
720 | + return $tabs; |
|
721 | + } |
|
722 | 722 | } |