|
1
|
|
|
<?php |
|
2
|
|
|
namespace lsx_health_plan\classes; |
|
3
|
|
|
|
|
4
|
|
|
/** |
|
5
|
|
|
* Contains the day post type |
|
6
|
|
|
* |
|
7
|
|
|
* @package lsx-health-plan |
|
8
|
|
|
*/ |
|
9
|
|
|
class Meal { |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* Holds class instance |
|
13
|
|
|
* |
|
14
|
|
|
* @since 1.0.0 |
|
15
|
|
|
* |
|
16
|
|
|
* @var object \lsx_health_plan\classes\Meal() |
|
17
|
|
|
*/ |
|
18
|
|
|
protected static $instance = null; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Holds post_type slug used as an index |
|
22
|
|
|
* |
|
23
|
|
|
* @since 1.0.0 |
|
24
|
|
|
* |
|
25
|
|
|
* @var string |
|
26
|
|
|
*/ |
|
27
|
|
|
public $slug = 'meal'; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* Contructor |
|
31
|
|
|
*/ |
|
32
|
|
|
public function __construct() { |
|
33
|
|
|
add_action( 'init', array( $this, 'register_post_type' ) ); |
|
34
|
|
|
|
|
35
|
|
|
add_filter( 'lsx_health_plan_single_template', array( $this, 'enable_post_type' ), 10, 1 ); |
|
36
|
|
|
add_filter( 'lsx_health_plan_connections', array( $this, 'enable_connections' ), 10, 1 ); |
|
37
|
|
|
add_action( 'cmb2_admin_init', array( $this, 'featured_metabox' ), 5 ); |
|
38
|
|
|
add_action( 'cmb2_admin_init', array( $this, 'details_metaboxes' ) ); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* Return an instance of this class. |
|
43
|
|
|
* |
|
44
|
|
|
* @since 1.0.0 |
|
45
|
|
|
* |
|
46
|
|
|
* @return object \lsx_health_plan\classes\Day() A single instance of this class. |
|
47
|
|
|
*/ |
|
48
|
|
|
public static function get_instance() { |
|
49
|
|
|
// If the single instance hasn't been set, set it now. |
|
50
|
|
|
if ( null === self::$instance ) { |
|
51
|
|
|
self::$instance = new self(); |
|
52
|
|
|
} |
|
53
|
|
|
return self::$instance; |
|
54
|
|
|
} |
|
55
|
|
|
/** |
|
56
|
|
|
* Register the post type. |
|
57
|
|
|
*/ |
|
58
|
|
|
public function register_post_type() { |
|
59
|
|
|
$labels = array( |
|
60
|
|
|
'name' => esc_html__( 'Meals', 'lsx-health-plan' ), |
|
61
|
|
|
'singular_name' => esc_html__( 'Meal', 'lsx-health-plan' ), |
|
62
|
|
|
'add_new' => esc_html_x( 'Add New', 'post type general name', 'lsx-health-plan' ), |
|
63
|
|
|
'add_new_item' => esc_html__( 'Add New', 'lsx-health-plan' ), |
|
64
|
|
|
'edit_item' => esc_html__( 'Edit', 'lsx-health-plan' ), |
|
65
|
|
|
'new_item' => esc_html__( 'New', 'lsx-health-plan' ), |
|
66
|
|
|
'all_items' => esc_html__( 'All Meals', 'lsx-health-plan' ), |
|
67
|
|
|
'view_item' => esc_html__( 'View', 'lsx-health-plan' ), |
|
68
|
|
|
'search_items' => esc_html__( 'Search', 'lsx-health-plan' ), |
|
69
|
|
|
'not_found' => esc_html__( 'None found', 'lsx-health-plan' ), |
|
70
|
|
|
'not_found_in_trash' => esc_html__( 'None found in Trash', 'lsx-health-plan' ), |
|
71
|
|
|
'parent_item_colon' => '', |
|
72
|
|
|
'menu_name' => esc_html__( 'Meals', 'lsx-health-plan' ), |
|
73
|
|
|
); |
|
74
|
|
|
$args = array( |
|
75
|
|
|
'labels' => $labels, |
|
76
|
|
|
'public' => true, |
|
77
|
|
|
'publicly_queryable' => true, |
|
78
|
|
|
'show_ui' => true, |
|
79
|
|
|
'show_in_menu' => true, |
|
80
|
|
|
'show_in_rest' => true, |
|
81
|
|
|
'menu_icon' => 'dashicons-carrot', |
|
82
|
|
|
'query_var' => true, |
|
83
|
|
|
'rewrite' => array( |
|
84
|
|
|
'slug' => \lsx_health_plan\functions\get_option( 'meal_single_slug', 'meal' ), |
|
85
|
|
|
), |
|
86
|
|
|
'capability_type' => 'post', |
|
87
|
|
|
'has_archive' => \lsx_health_plan\functions\get_option( 'endpoint_meal_archive', 'meals' ), |
|
88
|
|
|
'hierarchical' => true, |
|
89
|
|
|
'menu_position' => null, |
|
90
|
|
|
'supports' => array( |
|
91
|
|
|
'title', |
|
92
|
|
|
'editor', |
|
93
|
|
|
'thumbnail', |
|
94
|
|
|
'page-attributes', |
|
95
|
|
|
'custom-fields', |
|
96
|
|
|
), |
|
97
|
|
|
); |
|
98
|
|
|
register_post_type( 'meal', $args ); |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
/** |
|
102
|
|
|
* Adds the post type to the different arrays. |
|
103
|
|
|
* |
|
104
|
|
|
* @param array $post_types |
|
105
|
|
|
* @return array |
|
106
|
|
|
*/ |
|
107
|
|
|
public function enable_post_type( $post_types = array() ) { |
|
108
|
|
|
$post_types[] = $this->slug; |
|
109
|
|
|
return $post_types; |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
/** |
|
113
|
|
|
* Enables the Bi Directional relationships |
|
114
|
|
|
* |
|
115
|
|
|
* @param array $connections |
|
116
|
|
|
* @return void |
|
117
|
|
|
*/ |
|
118
|
|
|
public function enable_connections( $connections = array() ) { |
|
119
|
|
|
$connections['meal']['connected_plans'] = 'connected_meals'; |
|
120
|
|
|
$connections['plan']['connected_meals'] = 'connected_plans'; |
|
121
|
|
|
return $connections; |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
/** |
|
125
|
|
|
* Define the metabox and field configurations. |
|
126
|
|
|
*/ |
|
127
|
|
|
public function featured_metabox() { |
|
128
|
|
|
$cmb = new_cmb2_box( |
|
129
|
|
|
array( |
|
130
|
|
|
'id' => $this->slug . '_featured_metabox_meal', |
|
131
|
|
|
'title' => __( 'Featured Meal', 'lsx-health-plan' ), |
|
132
|
|
|
'object_types' => array( $this->slug ), // Post type |
|
133
|
|
|
'context' => 'side', |
|
134
|
|
|
'priority' => 'high', |
|
135
|
|
|
'show_names' => true, |
|
136
|
|
|
) |
|
137
|
|
|
); |
|
138
|
|
|
$cmb->add_field( |
|
139
|
|
|
array( |
|
140
|
|
|
'name' => __( 'Featured Meal', 'lsx-health-plan' ), |
|
141
|
|
|
'desc' => __( 'Enable a featured meal' ), |
|
142
|
|
|
'id' => $this->slug . '_featured_meal', |
|
143
|
|
|
'type' => 'checkbox', |
|
144
|
|
|
'show_on_cb' => 'cmb2_hide_if_no_cats', |
|
145
|
|
|
) |
|
146
|
|
|
); |
|
147
|
|
|
} |
|
148
|
|
|
|
|
149
|
|
|
/** |
|
150
|
|
|
* Define the metabox and field configurations. |
|
151
|
|
|
*/ |
|
152
|
|
|
public function details_metaboxes() { |
|
153
|
|
|
$cmb = new_cmb2_box( array( |
|
154
|
|
|
'id' => $this->slug . '_shopping_list_metabox', |
|
155
|
|
|
'title' => __( 'Shopping List', 'lsx-health-plan' ), |
|
156
|
|
|
'object_types' => array( $this->slug ), // Post type |
|
157
|
|
|
'context' => 'normal', |
|
158
|
|
|
'priority' => 'high', |
|
159
|
|
|
'show_names' => true, |
|
160
|
|
|
) ); |
|
161
|
|
|
$cmb->add_field( array( |
|
162
|
|
|
'name' => __( 'Shopping List', 'lsx-health-plan' ), |
|
163
|
|
|
'desc' => __( 'Connect the shopping list page that applies to this meal by entering the name of the page in the field provided.' ), |
|
164
|
|
|
'id' => $this->slug . '_shopping_list', |
|
165
|
|
|
'type' => 'post_search_ajax', |
|
166
|
|
|
// Optional : |
|
167
|
|
|
'limit' => 1, // Limit selection to X items only (default 1) |
|
168
|
|
|
'sortable' => true, // Allow selected items to be sortable (default false) |
|
169
|
|
|
'query_args' => array( |
|
170
|
|
|
'post_type' => array( 'page' ), |
|
171
|
|
|
'post_status' => array( 'publish' ), |
|
172
|
|
|
'posts_per_page' => -1, |
|
173
|
|
|
), |
|
174
|
|
|
) ); |
|
175
|
|
|
$cmb = new_cmb2_box( array( |
|
176
|
|
|
'id' => $this->slug . '_details_metabox', |
|
177
|
|
|
'title' => __( 'Meal Details', 'lsx-health-plan' ), |
|
178
|
|
|
'object_types' => array( $this->slug ), // Post type |
|
179
|
|
|
'context' => 'normal', |
|
180
|
|
|
'priority' => 'high', |
|
181
|
|
|
'show_names' => true, |
|
182
|
|
|
) ); |
|
183
|
|
|
|
|
184
|
|
|
$cmb->add_field( array( |
|
185
|
|
|
'name' => __( 'Meal Short Description', 'lsx-health-plan' ), |
|
186
|
|
|
'id' => $this->slug . '_short_description', |
|
187
|
|
|
'type' => 'textarea_small', |
|
188
|
|
|
'desc' => __( 'Add a small description for this meal (optional)', 'lsx-health-plan' ), |
|
189
|
|
|
) ); |
|
190
|
|
|
|
|
191
|
|
|
$cmb->add_field( array( |
|
192
|
|
|
'name' => __( 'Pre Breakfast Snack', 'lsx-health-plan' ), |
|
193
|
|
|
'id' => $this->slug . '_pre_breakfast_snack', |
|
194
|
|
|
'type' => 'wysiwyg', |
|
195
|
|
|
'show_on_cb' => 'cmb2_hide_if_no_cats', |
|
196
|
|
|
'options' => array( |
|
197
|
|
|
'textarea_rows' => 5, |
|
198
|
|
|
), |
|
199
|
|
|
) ); |
|
200
|
|
|
$cmb->add_field( array( |
|
201
|
|
|
'name' => __( 'Breakfast', 'lsx-health-plan' ), |
|
202
|
|
|
'id' => $this->slug . '_breakfast', |
|
203
|
|
|
'type' => 'wysiwyg', |
|
204
|
|
|
'show_on_cb' => 'cmb2_hide_if_no_cats', |
|
205
|
|
|
'options' => array( |
|
206
|
|
|
'textarea_rows' => 5, |
|
207
|
|
|
), |
|
208
|
|
|
) ); |
|
209
|
|
|
|
|
210
|
|
|
$cmb->add_field( |
|
211
|
|
|
array( |
|
212
|
|
|
'name' => __( 'Post Breakfast Snack', 'lsx-health-plan' ), |
|
213
|
|
|
'id' => $this->slug . '_breakfast_snack', |
|
214
|
|
|
'type' => 'wysiwyg', |
|
215
|
|
|
'show_on_cb' => 'cmb2_hide_if_no_cats', |
|
216
|
|
|
'options' => array( |
|
217
|
|
|
'textarea_rows' => 5, |
|
218
|
|
|
), |
|
219
|
|
|
) |
|
220
|
|
|
); |
|
221
|
|
|
|
|
222
|
|
|
if ( post_type_exists( 'recipe' ) ) { |
|
223
|
|
|
$cmb->add_field( |
|
224
|
|
|
array( |
|
225
|
|
|
'name' => __( 'Breakfast Recipes', 'lsx-health-plan' ), |
|
226
|
|
|
'desc' => __( 'Connect additional recipes options for breakfast.', 'lsx-health-plan' ), |
|
227
|
|
|
'id' => 'breakfast_recipes', |
|
228
|
|
|
'type' => 'post_search_ajax', |
|
229
|
|
|
// Optional : |
|
230
|
|
|
'limit' => 15, // Limit selection to X items only (default 1) |
|
231
|
|
|
'sortable' => true, // Allow selected items to be sortable (default false) |
|
232
|
|
|
'query_args' => array( |
|
233
|
|
|
'post_type' => array( 'recipe' ), |
|
234
|
|
|
'post_status' => array( 'publish' ), |
|
235
|
|
|
'posts_per_page' => -1, |
|
236
|
|
|
), |
|
237
|
|
|
) |
|
238
|
|
|
); |
|
239
|
|
|
} |
|
240
|
|
|
|
|
241
|
|
|
$cmb->add_field( |
|
242
|
|
|
array( |
|
243
|
|
|
'name' => __( 'Pre Lunch Snack', 'lsx-health-plan' ), |
|
244
|
|
|
'id' => $this->slug . '_pre_lunch_snack', |
|
245
|
|
|
'type' => 'wysiwyg', |
|
246
|
|
|
'show_on_cb' => 'cmb2_hide_if_no_cats', |
|
247
|
|
|
'options' => array( |
|
248
|
|
|
'textarea_rows' => 5, |
|
249
|
|
|
), |
|
250
|
|
|
) |
|
251
|
|
|
); |
|
252
|
|
|
$cmb->add_field( |
|
253
|
|
|
array( |
|
254
|
|
|
'name' => __( 'Lunch', 'lsx-health-plan' ), |
|
255
|
|
|
'id' => $this->slug . '_lunch', |
|
256
|
|
|
'type' => 'wysiwyg', |
|
257
|
|
|
'show_on_cb' => 'cmb2_hide_if_no_cats', |
|
258
|
|
|
'options' => array( |
|
259
|
|
|
'textarea_rows' => 5, |
|
260
|
|
|
), |
|
261
|
|
|
) |
|
262
|
|
|
); |
|
263
|
|
|
$cmb->add_field( |
|
264
|
|
|
array( |
|
265
|
|
|
'name' => __( 'Post Lunch Snack', 'lsx-health-plan' ), |
|
266
|
|
|
'id' => $this->slug . '_lunch_snack', |
|
267
|
|
|
'type' => 'wysiwyg', |
|
268
|
|
|
'show_on_cb' => 'cmb2_hide_if_no_cats', |
|
269
|
|
|
'options' => array( |
|
270
|
|
|
'textarea_rows' => 5, |
|
271
|
|
|
), |
|
272
|
|
|
) |
|
273
|
|
|
); |
|
274
|
|
|
|
|
275
|
|
|
if ( post_type_exists( 'recipe' ) ) { |
|
276
|
|
|
$cmb->add_field( |
|
277
|
|
|
array( |
|
278
|
|
|
'name' => __( 'Lunch Recipes', 'lsx-health-plan' ), |
|
279
|
|
|
'desc' => __( 'Connect additional recipes options for lunch.', 'lsx-health-plan' ), |
|
280
|
|
|
'id' => 'lunch_recipes', |
|
281
|
|
|
'type' => 'post_search_ajax', |
|
282
|
|
|
// Optional : |
|
283
|
|
|
'limit' => 15, // Limit selection to X items only (default 1) |
|
284
|
|
|
'sortable' => true, // Allow selected items to be sortable (default false) |
|
285
|
|
|
'query_args' => array( |
|
286
|
|
|
'post_type' => array( 'recipe' ), |
|
287
|
|
|
'post_status' => array( 'publish' ), |
|
288
|
|
|
'posts_per_page' => -1, |
|
289
|
|
|
), |
|
290
|
|
|
) |
|
291
|
|
|
); |
|
292
|
|
|
} |
|
293
|
|
|
|
|
294
|
|
|
$cmb->add_field( |
|
295
|
|
|
array( |
|
296
|
|
|
'name' => __( 'Pre Dinner Snack', 'lsx-health-plan' ), |
|
297
|
|
|
'id' => $this->slug . '_pre_dinner_snack', |
|
298
|
|
|
'type' => 'wysiwyg', |
|
299
|
|
|
'show_on_cb' => 'cmb2_hide_if_no_cats', |
|
300
|
|
|
'options' => array( |
|
301
|
|
|
'textarea_rows' => 5, |
|
302
|
|
|
), |
|
303
|
|
|
) |
|
304
|
|
|
); |
|
305
|
|
|
$cmb->add_field( |
|
306
|
|
|
array( |
|
307
|
|
|
'name' => __( 'Dinner', 'lsx-health-plan' ), |
|
308
|
|
|
'id' => $this->slug . '_dinner', |
|
309
|
|
|
'type' => 'wysiwyg', |
|
310
|
|
|
'show_on_cb' => 'cmb2_hide_if_no_cats', |
|
311
|
|
|
'options' => array( |
|
312
|
|
|
'textarea_rows' => 5, |
|
313
|
|
|
), |
|
314
|
|
|
) |
|
315
|
|
|
); |
|
316
|
|
|
$cmb->add_field( |
|
317
|
|
|
array( |
|
318
|
|
|
'name' => __( 'Post Dinner Snack', 'lsx-health-plan' ), |
|
319
|
|
|
'id' => $this->slug . '_dinner_snack', |
|
320
|
|
|
'type' => 'wysiwyg', |
|
321
|
|
|
'show_on_cb' => 'cmb2_hide_if_no_cats', |
|
322
|
|
|
'options' => array( |
|
323
|
|
|
'textarea_rows' => 5, |
|
324
|
|
|
), |
|
325
|
|
|
) |
|
326
|
|
|
); |
|
327
|
|
|
|
|
328
|
|
|
if ( post_type_exists( 'recipe' ) ) { |
|
329
|
|
|
$cmb->add_field( |
|
330
|
|
|
array( |
|
331
|
|
|
'name' => __( 'Dinner Recipes', 'lsx-health-plan' ), |
|
332
|
|
|
'desc' => __( 'Connect additional recipes options for dinner.', 'lsx-health-plan' ), |
|
333
|
|
|
'id' => 'dinner_recipes', |
|
334
|
|
|
'type' => 'post_search_ajax', |
|
335
|
|
|
// Optional : |
|
336
|
|
|
'limit' => 15, // Limit selection to X items only (default 1) |
|
337
|
|
|
'sortable' => true, // Allow selected items to be sortable (default false) |
|
338
|
|
|
'query_args' => array( |
|
339
|
|
|
'post_type' => array( 'recipe' ), |
|
340
|
|
|
'post_status' => array( 'publish' ), |
|
341
|
|
|
'posts_per_page' => -1, |
|
342
|
|
|
), |
|
343
|
|
|
) |
|
344
|
|
|
); |
|
345
|
|
|
} |
|
346
|
|
|
} |
|
347
|
|
|
} |
|
348
|
|
|
|