@@ -8,483 +8,483 @@ |
||
8 | 8 | */ |
9 | 9 | class Exercise { |
10 | 10 | |
11 | - /** |
|
12 | - * Holds class instance |
|
13 | - * |
|
14 | - * @since 1.0.0 |
|
15 | - * |
|
16 | - * @var object \lsx_health_plan\classes\Exercise() |
|
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 = 'exercise'; |
|
28 | - |
|
29 | - /** |
|
30 | - * Constructor |
|
31 | - */ |
|
32 | - public function __construct() { |
|
33 | - |
|
34 | - if ( false !== \lsx_health_plan\functions\get_option( 'exercise_enabled', false ) ) { |
|
35 | - // Post Type and Taxonomies. |
|
36 | - add_action( 'init', array( $this, 'register_post_type' ) ); |
|
37 | - add_action( 'init', array( $this, 'exercise_type_taxonomy_setup' ) ); |
|
38 | - add_action( 'init', array( $this, 'equipment_taxonomy_setup' ) ); |
|
39 | - add_action( 'init', array( $this, 'muscle_group_taxonomy_setup' ) ); |
|
40 | - add_action( 'admin_menu', array( $this, 'register_menus' ) ); |
|
41 | - |
|
42 | - // Custom Fields. |
|
43 | - add_action( 'cmb2_admin_init', array( $this, 'exercise_details' ), 8 ); |
|
44 | - add_action( 'cmb2_admin_init', array( $this, 'gallery_metabox' ), 9 ); |
|
45 | - add_filter( 'lsx_health_plan_connections', array( $this, 'enable_connections' ), 10, 1 ); |
|
46 | - |
|
47 | - // Template Redirects. |
|
48 | - add_filter( 'lsx_health_plan_archive_template', array( $this, 'enable_post_type' ), 10, 1 ); |
|
49 | - add_filter( 'lsx_health_plan_single_template', array( $this, 'enable_post_type' ), 10, 1 ); |
|
50 | - |
|
51 | - //Breadcrumbs |
|
52 | - add_filter( 'wpseo_breadcrumb_links', array( $this, 'exercise_breadcrumb_filter' ), 30, 1 ); |
|
53 | - add_filter( 'woocommerce_get_breadcrumb', array( $this, 'exercise_breadcrumb_filter' ), 30, 1 ); |
|
54 | - |
|
55 | - } |
|
56 | - |
|
57 | - } |
|
58 | - |
|
59 | - |
|
60 | - /** |
|
61 | - * Return an instance of this class. |
|
62 | - * |
|
63 | - * @since 1.0.0 |
|
64 | - * |
|
65 | - * @return object \lsx_health_plan\classes\Exercise() A single instance of this class. |
|
66 | - */ |
|
67 | - public static function get_instance() { |
|
68 | - // If the single instance hasn't been set, set it now. |
|
69 | - if ( null === self::$instance ) { |
|
70 | - self::$instance = new self(); |
|
71 | - } |
|
72 | - return self::$instance; |
|
73 | - } |
|
74 | - /** |
|
75 | - * Register the post type. |
|
76 | - */ |
|
77 | - public function register_post_type() { |
|
78 | - $labels = array( |
|
79 | - 'name' => esc_html__( 'Exercises', 'lsx-health-plan' ), |
|
80 | - 'singular_name' => esc_html__( 'Exercise', 'lsx-health-plan' ), |
|
81 | - 'add_new' => esc_html_x( 'Add New', 'post type general name', 'lsx-health-plan' ), |
|
82 | - 'add_new_item' => esc_html__( 'Add New', 'lsx-health-plan' ), |
|
83 | - 'edit_item' => esc_html__( 'Edit', 'lsx-health-plan' ), |
|
84 | - 'new_item' => esc_html__( 'New', 'lsx-health-plan' ), |
|
85 | - 'all_items' => esc_html__( 'All Exercises', 'lsx-health-plan' ), |
|
86 | - 'view_item' => esc_html__( 'View', 'lsx-health-plan' ), |
|
87 | - 'search_items' => esc_html__( 'Search', 'lsx-health-plan' ), |
|
88 | - 'not_found' => esc_html__( 'None found', 'lsx-health-plan' ), |
|
89 | - 'not_found_in_trash' => esc_html__( 'None found in Trash', 'lsx-health-plan' ), |
|
90 | - 'parent_item_colon' => '', |
|
91 | - 'menu_name' => esc_html__( 'Exercises', 'lsx-health-plan' ), |
|
92 | - ); |
|
93 | - $args = array( |
|
94 | - 'labels' => $labels, |
|
95 | - 'public' => true, |
|
96 | - 'publicly_queryable' => true, |
|
97 | - 'show_ui' => true, |
|
98 | - 'show_in_menu' => 'edit.php?post_type=workout-pseudo', |
|
99 | - 'show_in_rest' => true, |
|
100 | - 'menu_icon' => 'dashicons-universal-access', |
|
101 | - 'query_var' => true, |
|
102 | - 'rewrite' => array( |
|
103 | - 'slug' => \lsx_health_plan\functions\get_option( 'endpoint_exercise_single', 'exercise' ), |
|
104 | - ), |
|
105 | - 'capability_type' => 'page', |
|
106 | - 'has_archive' => \lsx_health_plan\functions\get_option( 'endpoint_exercise_archive', 'exercises' ), |
|
107 | - 'hierarchical' => false, |
|
108 | - 'menu_position' => null, |
|
109 | - 'supports' => array( |
|
110 | - 'title', |
|
111 | - 'thumbnail', |
|
112 | - 'editor', |
|
113 | - 'excerpt', |
|
114 | - 'custom-fields', |
|
115 | - ), |
|
116 | - ); |
|
117 | - register_post_type( 'exercise', $args ); |
|
118 | - } |
|
119 | - |
|
120 | - /** |
|
121 | - * Register the Exercise taxonomy. |
|
122 | - * |
|
123 | - * @return void |
|
124 | - */ |
|
125 | - public function exercise_type_taxonomy_setup() { |
|
126 | - $labels = array( |
|
127 | - 'name' => esc_html_x( 'Exercise Type', 'taxonomy general name', 'lsx-health-plan' ), |
|
128 | - 'singular_name' => esc_html_x( 'Exercise Type', 'taxonomy singular name', 'lsx-health-plan' ), |
|
129 | - 'search_items' => esc_html__( 'Search', 'lsx-health-plan' ), |
|
130 | - 'all_items' => esc_html__( 'All', 'lsx-health-plan' ), |
|
131 | - 'parent_item' => esc_html__( 'Parent', 'lsx-health-plan' ), |
|
132 | - 'parent_item_colon' => esc_html__( 'Parent:', 'lsx-health-plan' ), |
|
133 | - 'edit_item' => esc_html__( 'Edit', 'lsx-health-plan' ), |
|
134 | - 'update_item' => esc_html__( 'Update', 'lsx-health-plan' ), |
|
135 | - 'add_new_item' => esc_html__( 'Add New', 'lsx-health-plan' ), |
|
136 | - 'new_item_name' => esc_html__( 'New Name', 'lsx-health-plan' ), |
|
137 | - 'menu_name' => esc_html__( 'Exercise Types', 'lsx-health-plan' ), |
|
138 | - ); |
|
139 | - |
|
140 | - $args = array( |
|
141 | - 'hierarchical' => true, |
|
142 | - 'labels' => $labels, |
|
143 | - 'show_ui' => true, |
|
144 | - 'show_admin_column' => true, |
|
145 | - 'query_var' => true, |
|
146 | - 'rewrite' => array( |
|
147 | - 'slug' => \lsx_health_plan\functions\get_option( 'endpoint_exercise_type', 'exercise-type' ), |
|
148 | - ), |
|
149 | - 'show_in_rest' => true, |
|
150 | - ); |
|
151 | - |
|
152 | - register_taxonomy( 'exercise-type', array( 'exercise' ), $args ); |
|
153 | - } |
|
154 | - |
|
155 | - /** |
|
156 | - * Register the Exercise taxonomy. |
|
157 | - * |
|
158 | - * @return void |
|
159 | - */ |
|
160 | - public function equipment_taxonomy_setup() { |
|
161 | - $labels = array( |
|
162 | - 'name' => esc_html_x( 'Equipment', 'taxonomy general name', 'lsx-health-plan' ), |
|
163 | - 'singular_name' => esc_html_x( 'Equipment', 'taxonomy singular name', 'lsx-health-plan' ), |
|
164 | - 'search_items' => esc_html__( 'Search', 'lsx-health-plan' ), |
|
165 | - 'all_items' => esc_html__( 'All', 'lsx-health-plan' ), |
|
166 | - 'parent_item' => esc_html__( 'Parent', 'lsx-health-plan' ), |
|
167 | - 'parent_item_colon' => esc_html__( 'Parent:', 'lsx-health-plan' ), |
|
168 | - 'edit_item' => esc_html__( 'Edit', 'lsx-health-plan' ), |
|
169 | - 'update_item' => esc_html__( 'Update', 'lsx-health-plan' ), |
|
170 | - 'add_new_item' => esc_html__( 'Add New', 'lsx-health-plan' ), |
|
171 | - 'new_item_name' => esc_html__( 'New Name', 'lsx-health-plan' ), |
|
172 | - 'menu_name' => esc_html__( 'Equipment', 'lsx-health-plan' ), |
|
173 | - ); |
|
174 | - |
|
175 | - $args = array( |
|
176 | - 'hierarchical' => true, |
|
177 | - 'labels' => $labels, |
|
178 | - 'show_ui' => true, |
|
179 | - 'show_admin_column' => true, |
|
180 | - 'query_var' => true, |
|
181 | - 'rewrite' => array( |
|
182 | - 'slug' => \lsx_health_plan\functions\get_option( 'endpoint_exercise_equipment', 'equipment' ), |
|
183 | - ), |
|
184 | - 'show_in_rest' => true, |
|
185 | - ); |
|
186 | - |
|
187 | - register_taxonomy( 'equipment', array( 'exercise' ), $args ); |
|
188 | - } |
|
189 | - |
|
190 | - /** |
|
191 | - * Register the Muscle Group taxonomy. |
|
192 | - * |
|
193 | - * @return void |
|
194 | - */ |
|
195 | - public function muscle_group_taxonomy_setup() { |
|
196 | - $labels = array( |
|
197 | - 'name' => esc_html_x( 'Muscle Groups', 'taxonomy general name', 'lsx-health-plan' ), |
|
198 | - 'singular_name' => esc_html_x( 'Muscle Group', 'taxonomy singular name', 'lsx-health-plan' ), |
|
199 | - 'search_items' => esc_html__( 'Search', 'lsx-health-plan' ), |
|
200 | - 'all_items' => esc_html__( 'All', 'lsx-health-plan' ), |
|
201 | - 'parent_item' => esc_html__( 'Parent', 'lsx-health-plan' ), |
|
202 | - 'parent_item_colon' => esc_html__( 'Parent:', 'lsx-health-plan' ), |
|
203 | - 'edit_item' => esc_html__( 'Edit', 'lsx-health-plan' ), |
|
204 | - 'update_item' => esc_html__( 'Update', 'lsx-health-plan' ), |
|
205 | - 'add_new_item' => esc_html__( 'Add New', 'lsx-health-plan' ), |
|
206 | - 'new_item_name' => esc_html__( 'New Name', 'lsx-health-plan' ), |
|
207 | - 'menu_name' => esc_html__( 'Muscle Groups', 'lsx-health-plan' ), |
|
208 | - ); |
|
209 | - |
|
210 | - $args = array( |
|
211 | - 'hierarchical' => true, |
|
212 | - 'labels' => $labels, |
|
213 | - 'show_ui' => true, |
|
214 | - 'show_admin_column' => true, |
|
215 | - 'query_var' => true, |
|
216 | - 'rewrite' => array( |
|
217 | - 'slug' => \lsx_health_plan\functions\get_option( 'endpoint_exercise_musclegroup', 'muscle-group' ), |
|
218 | - ), |
|
219 | - 'show_in_rest' => true, |
|
220 | - ); |
|
221 | - |
|
222 | - register_taxonomy( 'muscle-group', array( 'exercise' ), $args ); |
|
223 | - } |
|
224 | - |
|
225 | - /** |
|
226 | - * Registers the Recipes under the Meals Post type menu. |
|
227 | - * |
|
228 | - * @return void |
|
229 | - */ |
|
230 | - public function register_menus() { |
|
231 | - add_submenu_page( 'edit.php?post_type=workout', esc_html__( 'Exercises', 'lsx-health-plan' ), esc_html__( 'Exercises', 'lsx-health-plan' ), 'edit_posts', 'edit.php?post_type=exercise' ); |
|
232 | - add_submenu_page( 'edit.php?post_type=workout', esc_html__( 'Exercise Types', 'lsx-health-plan' ), esc_html__( 'Exercise Types', 'lsx-health-plan' ), 'edit_posts', 'edit-tags.php?taxonomy=exercise-type&post_type=exercise' ); |
|
233 | - add_submenu_page( 'edit.php?post_type=workout', esc_html__( 'Equipment', 'lsx-health-plan' ), esc_html__( 'Equipment', 'lsx-health-plan' ), 'edit_posts', 'edit-tags.php?taxonomy=equipment&post_type=exercise' ); |
|
234 | - add_submenu_page( 'edit.php?post_type=workout', esc_html__( 'Muscle Groups', 'lsx-health-plan' ), esc_html__( 'Muscle Groups', 'lsx-health-plan' ), 'edit_posts', 'edit-tags.php?taxonomy=muscle-group&post_type=exercise' ); |
|
235 | - } |
|
236 | - |
|
237 | - /** |
|
238 | - * Adds the post type to the different arrays. |
|
239 | - * |
|
240 | - * @param array $post_types |
|
241 | - * @return array |
|
242 | - */ |
|
243 | - public function enable_post_type( $post_types = array() ) { |
|
244 | - $post_types[] = $this->slug; |
|
245 | - return $post_types; |
|
246 | - } |
|
247 | - |
|
248 | - /** |
|
249 | - * Enables the Bi Directional relationships |
|
250 | - * |
|
251 | - * @param array $connections |
|
252 | - * @return void |
|
253 | - */ |
|
254 | - public function enable_connections( $connections = array() ) { |
|
255 | - $connections['exercise']['connected_workouts'] = 'connected_exercises'; |
|
256 | - $connections['workout']['connected_exercises'] = 'connected_workouts'; |
|
257 | - return $connections; |
|
258 | - } |
|
259 | - |
|
260 | - /** |
|
261 | - * Define the metabox and field configurations. |
|
262 | - */ |
|
263 | - public function gallery_metabox() { |
|
264 | - $cmb = new_cmb2_box( |
|
265 | - array( |
|
266 | - 'id' => $this->slug . '_gallery_details_metabox', |
|
267 | - 'title' => __( 'Exercise Gallery', 'lsx-health-plan' ), |
|
268 | - 'object_types' => array( $this->slug ), |
|
269 | - 'context' => 'normal', |
|
270 | - 'priority' => 'low', |
|
271 | - 'show_names' => true, |
|
272 | - ) |
|
273 | - ); |
|
274 | - |
|
275 | - $cmb->add_field( |
|
276 | - array( |
|
277 | - 'name' => __( 'Layout', 'lsx-health-plan' ), |
|
278 | - 'id' => $this->slug . '_gallery_layout', |
|
279 | - 'type' => 'radio', |
|
280 | - 'options' => array( |
|
281 | - 'slider' => __( 'Slider', 'lsx-health-plan' ) . ' {#}', // {#} gets replaced by row number |
|
282 | - 'grid' => __( 'Grid', 'lsx-health-plan' ), |
|
283 | - ), |
|
284 | - 'default' => 'grid', |
|
285 | - ) |
|
286 | - ); |
|
287 | - |
|
288 | - $cmb->add_field( |
|
289 | - array( |
|
290 | - 'name' => __( 'Grid Columns', 'lsx-health-plan' ), |
|
291 | - 'id' => $this->slug . '_gallery_columns', |
|
292 | - 'type' => 'select', |
|
293 | - 'options' => array( |
|
294 | - '3' => __( '2 Columns', 'lsx-health-plan' ), |
|
295 | - '4' => __( '3 Columns', 'lsx-health-plan' ), |
|
296 | - ), |
|
297 | - 'default' => '1', |
|
298 | - ) |
|
299 | - ); |
|
300 | - |
|
301 | - // Repeatable group. |
|
302 | - $gallery_group = $cmb->add_field( |
|
303 | - array( |
|
304 | - 'id' => $this->slug . '_gallery', |
|
305 | - 'type' => 'group', |
|
306 | - 'options' => array( |
|
307 | - 'group_title' => __( 'Gallery', 'lsx-health-plan' ) . ' {#}', // {#} gets replaced by row number |
|
308 | - 'add_button' => __( 'Add Item', 'lsx-health-plan' ), |
|
309 | - 'remove_button' => __( 'Remove Item', 'lsx-health-plan' ), |
|
310 | - 'sortable' => true, |
|
311 | - ), |
|
312 | - 'desc' => __( 'Upload only one image, video or gif per gallery group, each group will only display 1 item.', 'lsx-health-plan' ), |
|
313 | - 'classes' => 'lsx-admin-row', |
|
314 | - ) |
|
315 | - ); |
|
316 | - |
|
317 | - // Title. |
|
318 | - $cmb->add_group_field( |
|
319 | - $gallery_group, |
|
320 | - array( |
|
321 | - 'name' => __( 'Image', 'lsx-health-plan' ), |
|
322 | - 'id' => $this->slug . '_gallery_image', |
|
323 | - 'type' => 'file', |
|
324 | - 'text' => array( |
|
325 | - 'add_upload_file_text' => __( 'Add File', 'lsx-health-plan' ), |
|
326 | - ), |
|
327 | - 'desc' => __( 'Upload an image a minimum of 800px x 600px in size.', 'lsx-health-plan' ), |
|
328 | - 'query_args' => array( |
|
329 | - 'type' => array( |
|
330 | - 'image/gif', |
|
331 | - 'image/jpeg', |
|
332 | - 'image/png', |
|
333 | - ), |
|
334 | - ), |
|
335 | - 'preview_size' => 'lsx-thumbnail-wide', |
|
336 | - 'classes' => 'lsx-field-col lsx-field-col-80', |
|
337 | - ) |
|
338 | - ); |
|
339 | - |
|
340 | - // Title. |
|
341 | - $cmb->add_group_field( |
|
342 | - $gallery_group, |
|
343 | - array( |
|
344 | - 'name' => __( 'oEmbed', 'lsx-health-plan' ), |
|
345 | - 'id' => $this->slug . '_gallery_embed', |
|
346 | - 'type' => 'text', |
|
347 | - 'desc' => __( 'Drop in the embed url for your video from YouTube, Vimeo or DailyMotion, e.g: "https://www.youtube.com/watch?v=9xwazD5SyVg". A full list of supports formats can be found at <a href="https://make.wordpress.org/support/user-manual/content/media/adding-media-to-your-pages-and-posts/embedding-media-from-other-sites/">WordPress</a>', 'lsx-health-plan' ), |
|
348 | - 'classes' => 'test-apply-form lsx-field-col lsx-field-col-50', |
|
349 | - ) |
|
350 | - ); |
|
351 | - |
|
352 | - $cmb->add_group_field( |
|
353 | - $gallery_group, |
|
354 | - array( |
|
355 | - 'name' => __( 'External Media', 'lsx-health-plan' ), |
|
356 | - 'id' => $this->slug . '_gallery_external', |
|
357 | - 'type' => 'textarea_code', |
|
358 | - 'desc' => __( 'Drop in the iFrame embed code from Giphy in this field, i.e: <iframe src="https://giphy.com/embed/3o7527Rn1HxXWqgxuo" width="480" height="270" frameborder="0" class="giphy-embed" allowfullscreen></iframe>', 'lsx-health-plan' ), |
|
359 | - 'classes' => 'lsx-field-col lsx-field-col-50', |
|
360 | - ) |
|
361 | - ); |
|
362 | - } |
|
363 | - |
|
364 | - /** |
|
365 | - * Registers the general settings for the exercise. |
|
366 | - * |
|
367 | - * @return void |
|
368 | - */ |
|
369 | - public function exercise_details() { |
|
370 | - $cmb = new_cmb2_box( |
|
371 | - array( |
|
372 | - 'id' => $this->slug . '_general_details_metabox', |
|
373 | - 'title' => __( 'Details', 'lsx-health-plan' ), |
|
374 | - 'object_types' => array( $this->slug ), |
|
375 | - 'context' => 'normal', |
|
376 | - 'priority' => 'high', |
|
377 | - 'show_names' => true, |
|
378 | - ) |
|
379 | - ); |
|
380 | - |
|
381 | - $cmb->add_field( |
|
382 | - array( |
|
383 | - 'name' => __( 'Side', 'lsx-health-plan' ), |
|
384 | - 'id' => $this->slug . '_side', |
|
385 | - 'type' => 'select', |
|
386 | - 'options' => array( |
|
387 | - '' => __( 'Select', 'lsx-health-plan' ), |
|
388 | - 'left' => __( 'Left', 'lsx-health-plan' ), |
|
389 | - 'right' => __( 'Right', 'lsx-health-plan' ), |
|
390 | - ), |
|
391 | - 'desc' => __( 'Select which side this exercise uses. ', 'lsx-health-plan' ), |
|
392 | - ) |
|
393 | - ); |
|
394 | - } |
|
395 | - |
|
396 | - /** |
|
397 | - * Holds the array for the single exercise breadcrumbs. |
|
398 | - * |
|
399 | - * @var array $crumbs |
|
400 | - * @return array |
|
401 | - */ |
|
402 | - public function exercise_breadcrumb_filter( $crumbs ) { |
|
403 | - $exercise = \lsx_health_plan\functions\get_option( 'endpoint_exercise', 'exercise' ); |
|
404 | - $exercises = \lsx_health_plan\functions\get_option( 'endpoint_exercise_archive', 'exercise' ); |
|
405 | - $url = get_post_type_archive_link( $exercise ); |
|
406 | - |
|
407 | - if ( is_singular( 'exercise' ) ) { |
|
408 | - $exercise_name = get_the_title(); |
|
409 | - $term_obj_list = get_the_terms( get_the_ID(), 'exercise-type' ); |
|
410 | - $exercise_type = $term_obj_list[0]->name; |
|
411 | - $exercise_type_url = get_term_link( $term_obj_list[0]->term_id ); |
|
412 | - |
|
413 | - $new_crumbs = array(); |
|
414 | - $new_crumbs[0] = $crumbs[0]; |
|
415 | - |
|
416 | - if ( function_exists( 'woocommerce_breadcrumb' ) ) { |
|
417 | - $new_crumbs[1] = array( |
|
418 | - 0 => $exercises, |
|
419 | - 1 => $url, |
|
420 | - ); |
|
421 | - $new_crumbs[2] = array( |
|
422 | - 0 => $exercise_type, |
|
423 | - 1 => $exercise_type_url, |
|
424 | - ); |
|
425 | - $new_crumbs[3] = array( |
|
426 | - 0 => $exercise_name, |
|
427 | - ); |
|
428 | - } else { |
|
429 | - $new_crumbs[1] = array( |
|
430 | - 'text' => $exercises, |
|
431 | - 'url' => $url, |
|
432 | - ); |
|
433 | - $new_crumbs[2] = array( |
|
434 | - 'text' => $exercise_type, |
|
435 | - 'url' => $exercise_type_url, |
|
436 | - ); |
|
437 | - $new_crumbs[3] = array( |
|
438 | - 'text' => $exercise_name, |
|
439 | - ); |
|
440 | - } |
|
441 | - $crumbs = $new_crumbs; |
|
11 | + /** |
|
12 | + * Holds class instance |
|
13 | + * |
|
14 | + * @since 1.0.0 |
|
15 | + * |
|
16 | + * @var object \lsx_health_plan\classes\Exercise() |
|
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 = 'exercise'; |
|
28 | + |
|
29 | + /** |
|
30 | + * Constructor |
|
31 | + */ |
|
32 | + public function __construct() { |
|
33 | + |
|
34 | + if ( false !== \lsx_health_plan\functions\get_option( 'exercise_enabled', false ) ) { |
|
35 | + // Post Type and Taxonomies. |
|
36 | + add_action( 'init', array( $this, 'register_post_type' ) ); |
|
37 | + add_action( 'init', array( $this, 'exercise_type_taxonomy_setup' ) ); |
|
38 | + add_action( 'init', array( $this, 'equipment_taxonomy_setup' ) ); |
|
39 | + add_action( 'init', array( $this, 'muscle_group_taxonomy_setup' ) ); |
|
40 | + add_action( 'admin_menu', array( $this, 'register_menus' ) ); |
|
41 | + |
|
42 | + // Custom Fields. |
|
43 | + add_action( 'cmb2_admin_init', array( $this, 'exercise_details' ), 8 ); |
|
44 | + add_action( 'cmb2_admin_init', array( $this, 'gallery_metabox' ), 9 ); |
|
45 | + add_filter( 'lsx_health_plan_connections', array( $this, 'enable_connections' ), 10, 1 ); |
|
46 | + |
|
47 | + // Template Redirects. |
|
48 | + add_filter( 'lsx_health_plan_archive_template', array( $this, 'enable_post_type' ), 10, 1 ); |
|
49 | + add_filter( 'lsx_health_plan_single_template', array( $this, 'enable_post_type' ), 10, 1 ); |
|
50 | + |
|
51 | + //Breadcrumbs |
|
52 | + add_filter( 'wpseo_breadcrumb_links', array( $this, 'exercise_breadcrumb_filter' ), 30, 1 ); |
|
53 | + add_filter( 'woocommerce_get_breadcrumb', array( $this, 'exercise_breadcrumb_filter' ), 30, 1 ); |
|
54 | + |
|
55 | + } |
|
56 | + |
|
57 | + } |
|
58 | + |
|
59 | + |
|
60 | + /** |
|
61 | + * Return an instance of this class. |
|
62 | + * |
|
63 | + * @since 1.0.0 |
|
64 | + * |
|
65 | + * @return object \lsx_health_plan\classes\Exercise() A single instance of this class. |
|
66 | + */ |
|
67 | + public static function get_instance() { |
|
68 | + // If the single instance hasn't been set, set it now. |
|
69 | + if ( null === self::$instance ) { |
|
70 | + self::$instance = new self(); |
|
71 | + } |
|
72 | + return self::$instance; |
|
73 | + } |
|
74 | + /** |
|
75 | + * Register the post type. |
|
76 | + */ |
|
77 | + public function register_post_type() { |
|
78 | + $labels = array( |
|
79 | + 'name' => esc_html__( 'Exercises', 'lsx-health-plan' ), |
|
80 | + 'singular_name' => esc_html__( 'Exercise', 'lsx-health-plan' ), |
|
81 | + 'add_new' => esc_html_x( 'Add New', 'post type general name', 'lsx-health-plan' ), |
|
82 | + 'add_new_item' => esc_html__( 'Add New', 'lsx-health-plan' ), |
|
83 | + 'edit_item' => esc_html__( 'Edit', 'lsx-health-plan' ), |
|
84 | + 'new_item' => esc_html__( 'New', 'lsx-health-plan' ), |
|
85 | + 'all_items' => esc_html__( 'All Exercises', 'lsx-health-plan' ), |
|
86 | + 'view_item' => esc_html__( 'View', 'lsx-health-plan' ), |
|
87 | + 'search_items' => esc_html__( 'Search', 'lsx-health-plan' ), |
|
88 | + 'not_found' => esc_html__( 'None found', 'lsx-health-plan' ), |
|
89 | + 'not_found_in_trash' => esc_html__( 'None found in Trash', 'lsx-health-plan' ), |
|
90 | + 'parent_item_colon' => '', |
|
91 | + 'menu_name' => esc_html__( 'Exercises', 'lsx-health-plan' ), |
|
92 | + ); |
|
93 | + $args = array( |
|
94 | + 'labels' => $labels, |
|
95 | + 'public' => true, |
|
96 | + 'publicly_queryable' => true, |
|
97 | + 'show_ui' => true, |
|
98 | + 'show_in_menu' => 'edit.php?post_type=workout-pseudo', |
|
99 | + 'show_in_rest' => true, |
|
100 | + 'menu_icon' => 'dashicons-universal-access', |
|
101 | + 'query_var' => true, |
|
102 | + 'rewrite' => array( |
|
103 | + 'slug' => \lsx_health_plan\functions\get_option( 'endpoint_exercise_single', 'exercise' ), |
|
104 | + ), |
|
105 | + 'capability_type' => 'page', |
|
106 | + 'has_archive' => \lsx_health_plan\functions\get_option( 'endpoint_exercise_archive', 'exercises' ), |
|
107 | + 'hierarchical' => false, |
|
108 | + 'menu_position' => null, |
|
109 | + 'supports' => array( |
|
110 | + 'title', |
|
111 | + 'thumbnail', |
|
112 | + 'editor', |
|
113 | + 'excerpt', |
|
114 | + 'custom-fields', |
|
115 | + ), |
|
116 | + ); |
|
117 | + register_post_type( 'exercise', $args ); |
|
118 | + } |
|
119 | + |
|
120 | + /** |
|
121 | + * Register the Exercise taxonomy. |
|
122 | + * |
|
123 | + * @return void |
|
124 | + */ |
|
125 | + public function exercise_type_taxonomy_setup() { |
|
126 | + $labels = array( |
|
127 | + 'name' => esc_html_x( 'Exercise Type', 'taxonomy general name', 'lsx-health-plan' ), |
|
128 | + 'singular_name' => esc_html_x( 'Exercise Type', 'taxonomy singular name', 'lsx-health-plan' ), |
|
129 | + 'search_items' => esc_html__( 'Search', 'lsx-health-plan' ), |
|
130 | + 'all_items' => esc_html__( 'All', 'lsx-health-plan' ), |
|
131 | + 'parent_item' => esc_html__( 'Parent', 'lsx-health-plan' ), |
|
132 | + 'parent_item_colon' => esc_html__( 'Parent:', 'lsx-health-plan' ), |
|
133 | + 'edit_item' => esc_html__( 'Edit', 'lsx-health-plan' ), |
|
134 | + 'update_item' => esc_html__( 'Update', 'lsx-health-plan' ), |
|
135 | + 'add_new_item' => esc_html__( 'Add New', 'lsx-health-plan' ), |
|
136 | + 'new_item_name' => esc_html__( 'New Name', 'lsx-health-plan' ), |
|
137 | + 'menu_name' => esc_html__( 'Exercise Types', 'lsx-health-plan' ), |
|
138 | + ); |
|
139 | + |
|
140 | + $args = array( |
|
141 | + 'hierarchical' => true, |
|
142 | + 'labels' => $labels, |
|
143 | + 'show_ui' => true, |
|
144 | + 'show_admin_column' => true, |
|
145 | + 'query_var' => true, |
|
146 | + 'rewrite' => array( |
|
147 | + 'slug' => \lsx_health_plan\functions\get_option( 'endpoint_exercise_type', 'exercise-type' ), |
|
148 | + ), |
|
149 | + 'show_in_rest' => true, |
|
150 | + ); |
|
151 | + |
|
152 | + register_taxonomy( 'exercise-type', array( 'exercise' ), $args ); |
|
153 | + } |
|
154 | + |
|
155 | + /** |
|
156 | + * Register the Exercise taxonomy. |
|
157 | + * |
|
158 | + * @return void |
|
159 | + */ |
|
160 | + public function equipment_taxonomy_setup() { |
|
161 | + $labels = array( |
|
162 | + 'name' => esc_html_x( 'Equipment', 'taxonomy general name', 'lsx-health-plan' ), |
|
163 | + 'singular_name' => esc_html_x( 'Equipment', 'taxonomy singular name', 'lsx-health-plan' ), |
|
164 | + 'search_items' => esc_html__( 'Search', 'lsx-health-plan' ), |
|
165 | + 'all_items' => esc_html__( 'All', 'lsx-health-plan' ), |
|
166 | + 'parent_item' => esc_html__( 'Parent', 'lsx-health-plan' ), |
|
167 | + 'parent_item_colon' => esc_html__( 'Parent:', 'lsx-health-plan' ), |
|
168 | + 'edit_item' => esc_html__( 'Edit', 'lsx-health-plan' ), |
|
169 | + 'update_item' => esc_html__( 'Update', 'lsx-health-plan' ), |
|
170 | + 'add_new_item' => esc_html__( 'Add New', 'lsx-health-plan' ), |
|
171 | + 'new_item_name' => esc_html__( 'New Name', 'lsx-health-plan' ), |
|
172 | + 'menu_name' => esc_html__( 'Equipment', 'lsx-health-plan' ), |
|
173 | + ); |
|
174 | + |
|
175 | + $args = array( |
|
176 | + 'hierarchical' => true, |
|
177 | + 'labels' => $labels, |
|
178 | + 'show_ui' => true, |
|
179 | + 'show_admin_column' => true, |
|
180 | + 'query_var' => true, |
|
181 | + 'rewrite' => array( |
|
182 | + 'slug' => \lsx_health_plan\functions\get_option( 'endpoint_exercise_equipment', 'equipment' ), |
|
183 | + ), |
|
184 | + 'show_in_rest' => true, |
|
185 | + ); |
|
186 | + |
|
187 | + register_taxonomy( 'equipment', array( 'exercise' ), $args ); |
|
188 | + } |
|
189 | + |
|
190 | + /** |
|
191 | + * Register the Muscle Group taxonomy. |
|
192 | + * |
|
193 | + * @return void |
|
194 | + */ |
|
195 | + public function muscle_group_taxonomy_setup() { |
|
196 | + $labels = array( |
|
197 | + 'name' => esc_html_x( 'Muscle Groups', 'taxonomy general name', 'lsx-health-plan' ), |
|
198 | + 'singular_name' => esc_html_x( 'Muscle Group', 'taxonomy singular name', 'lsx-health-plan' ), |
|
199 | + 'search_items' => esc_html__( 'Search', 'lsx-health-plan' ), |
|
200 | + 'all_items' => esc_html__( 'All', 'lsx-health-plan' ), |
|
201 | + 'parent_item' => esc_html__( 'Parent', 'lsx-health-plan' ), |
|
202 | + 'parent_item_colon' => esc_html__( 'Parent:', 'lsx-health-plan' ), |
|
203 | + 'edit_item' => esc_html__( 'Edit', 'lsx-health-plan' ), |
|
204 | + 'update_item' => esc_html__( 'Update', 'lsx-health-plan' ), |
|
205 | + 'add_new_item' => esc_html__( 'Add New', 'lsx-health-plan' ), |
|
206 | + 'new_item_name' => esc_html__( 'New Name', 'lsx-health-plan' ), |
|
207 | + 'menu_name' => esc_html__( 'Muscle Groups', 'lsx-health-plan' ), |
|
208 | + ); |
|
209 | + |
|
210 | + $args = array( |
|
211 | + 'hierarchical' => true, |
|
212 | + 'labels' => $labels, |
|
213 | + 'show_ui' => true, |
|
214 | + 'show_admin_column' => true, |
|
215 | + 'query_var' => true, |
|
216 | + 'rewrite' => array( |
|
217 | + 'slug' => \lsx_health_plan\functions\get_option( 'endpoint_exercise_musclegroup', 'muscle-group' ), |
|
218 | + ), |
|
219 | + 'show_in_rest' => true, |
|
220 | + ); |
|
221 | + |
|
222 | + register_taxonomy( 'muscle-group', array( 'exercise' ), $args ); |
|
223 | + } |
|
224 | + |
|
225 | + /** |
|
226 | + * Registers the Recipes under the Meals Post type menu. |
|
227 | + * |
|
228 | + * @return void |
|
229 | + */ |
|
230 | + public function register_menus() { |
|
231 | + add_submenu_page( 'edit.php?post_type=workout', esc_html__( 'Exercises', 'lsx-health-plan' ), esc_html__( 'Exercises', 'lsx-health-plan' ), 'edit_posts', 'edit.php?post_type=exercise' ); |
|
232 | + add_submenu_page( 'edit.php?post_type=workout', esc_html__( 'Exercise Types', 'lsx-health-plan' ), esc_html__( 'Exercise Types', 'lsx-health-plan' ), 'edit_posts', 'edit-tags.php?taxonomy=exercise-type&post_type=exercise' ); |
|
233 | + add_submenu_page( 'edit.php?post_type=workout', esc_html__( 'Equipment', 'lsx-health-plan' ), esc_html__( 'Equipment', 'lsx-health-plan' ), 'edit_posts', 'edit-tags.php?taxonomy=equipment&post_type=exercise' ); |
|
234 | + add_submenu_page( 'edit.php?post_type=workout', esc_html__( 'Muscle Groups', 'lsx-health-plan' ), esc_html__( 'Muscle Groups', 'lsx-health-plan' ), 'edit_posts', 'edit-tags.php?taxonomy=muscle-group&post_type=exercise' ); |
|
235 | + } |
|
236 | + |
|
237 | + /** |
|
238 | + * Adds the post type to the different arrays. |
|
239 | + * |
|
240 | + * @param array $post_types |
|
241 | + * @return array |
|
242 | + */ |
|
243 | + public function enable_post_type( $post_types = array() ) { |
|
244 | + $post_types[] = $this->slug; |
|
245 | + return $post_types; |
|
246 | + } |
|
247 | + |
|
248 | + /** |
|
249 | + * Enables the Bi Directional relationships |
|
250 | + * |
|
251 | + * @param array $connections |
|
252 | + * @return void |
|
253 | + */ |
|
254 | + public function enable_connections( $connections = array() ) { |
|
255 | + $connections['exercise']['connected_workouts'] = 'connected_exercises'; |
|
256 | + $connections['workout']['connected_exercises'] = 'connected_workouts'; |
|
257 | + return $connections; |
|
258 | + } |
|
259 | + |
|
260 | + /** |
|
261 | + * Define the metabox and field configurations. |
|
262 | + */ |
|
263 | + public function gallery_metabox() { |
|
264 | + $cmb = new_cmb2_box( |
|
265 | + array( |
|
266 | + 'id' => $this->slug . '_gallery_details_metabox', |
|
267 | + 'title' => __( 'Exercise Gallery', 'lsx-health-plan' ), |
|
268 | + 'object_types' => array( $this->slug ), |
|
269 | + 'context' => 'normal', |
|
270 | + 'priority' => 'low', |
|
271 | + 'show_names' => true, |
|
272 | + ) |
|
273 | + ); |
|
274 | + |
|
275 | + $cmb->add_field( |
|
276 | + array( |
|
277 | + 'name' => __( 'Layout', 'lsx-health-plan' ), |
|
278 | + 'id' => $this->slug . '_gallery_layout', |
|
279 | + 'type' => 'radio', |
|
280 | + 'options' => array( |
|
281 | + 'slider' => __( 'Slider', 'lsx-health-plan' ) . ' {#}', // {#} gets replaced by row number |
|
282 | + 'grid' => __( 'Grid', 'lsx-health-plan' ), |
|
283 | + ), |
|
284 | + 'default' => 'grid', |
|
285 | + ) |
|
286 | + ); |
|
287 | + |
|
288 | + $cmb->add_field( |
|
289 | + array( |
|
290 | + 'name' => __( 'Grid Columns', 'lsx-health-plan' ), |
|
291 | + 'id' => $this->slug . '_gallery_columns', |
|
292 | + 'type' => 'select', |
|
293 | + 'options' => array( |
|
294 | + '3' => __( '2 Columns', 'lsx-health-plan' ), |
|
295 | + '4' => __( '3 Columns', 'lsx-health-plan' ), |
|
296 | + ), |
|
297 | + 'default' => '1', |
|
298 | + ) |
|
299 | + ); |
|
300 | + |
|
301 | + // Repeatable group. |
|
302 | + $gallery_group = $cmb->add_field( |
|
303 | + array( |
|
304 | + 'id' => $this->slug . '_gallery', |
|
305 | + 'type' => 'group', |
|
306 | + 'options' => array( |
|
307 | + 'group_title' => __( 'Gallery', 'lsx-health-plan' ) . ' {#}', // {#} gets replaced by row number |
|
308 | + 'add_button' => __( 'Add Item', 'lsx-health-plan' ), |
|
309 | + 'remove_button' => __( 'Remove Item', 'lsx-health-plan' ), |
|
310 | + 'sortable' => true, |
|
311 | + ), |
|
312 | + 'desc' => __( 'Upload only one image, video or gif per gallery group, each group will only display 1 item.', 'lsx-health-plan' ), |
|
313 | + 'classes' => 'lsx-admin-row', |
|
314 | + ) |
|
315 | + ); |
|
316 | + |
|
317 | + // Title. |
|
318 | + $cmb->add_group_field( |
|
319 | + $gallery_group, |
|
320 | + array( |
|
321 | + 'name' => __( 'Image', 'lsx-health-plan' ), |
|
322 | + 'id' => $this->slug . '_gallery_image', |
|
323 | + 'type' => 'file', |
|
324 | + 'text' => array( |
|
325 | + 'add_upload_file_text' => __( 'Add File', 'lsx-health-plan' ), |
|
326 | + ), |
|
327 | + 'desc' => __( 'Upload an image a minimum of 800px x 600px in size.', 'lsx-health-plan' ), |
|
328 | + 'query_args' => array( |
|
329 | + 'type' => array( |
|
330 | + 'image/gif', |
|
331 | + 'image/jpeg', |
|
332 | + 'image/png', |
|
333 | + ), |
|
334 | + ), |
|
335 | + 'preview_size' => 'lsx-thumbnail-wide', |
|
336 | + 'classes' => 'lsx-field-col lsx-field-col-80', |
|
337 | + ) |
|
338 | + ); |
|
339 | + |
|
340 | + // Title. |
|
341 | + $cmb->add_group_field( |
|
342 | + $gallery_group, |
|
343 | + array( |
|
344 | + 'name' => __( 'oEmbed', 'lsx-health-plan' ), |
|
345 | + 'id' => $this->slug . '_gallery_embed', |
|
346 | + 'type' => 'text', |
|
347 | + 'desc' => __( 'Drop in the embed url for your video from YouTube, Vimeo or DailyMotion, e.g: "https://www.youtube.com/watch?v=9xwazD5SyVg". A full list of supports formats can be found at <a href="https://make.wordpress.org/support/user-manual/content/media/adding-media-to-your-pages-and-posts/embedding-media-from-other-sites/">WordPress</a>', 'lsx-health-plan' ), |
|
348 | + 'classes' => 'test-apply-form lsx-field-col lsx-field-col-50', |
|
349 | + ) |
|
350 | + ); |
|
351 | + |
|
352 | + $cmb->add_group_field( |
|
353 | + $gallery_group, |
|
354 | + array( |
|
355 | + 'name' => __( 'External Media', 'lsx-health-plan' ), |
|
356 | + 'id' => $this->slug . '_gallery_external', |
|
357 | + 'type' => 'textarea_code', |
|
358 | + 'desc' => __( 'Drop in the iFrame embed code from Giphy in this field, i.e: <iframe src="https://giphy.com/embed/3o7527Rn1HxXWqgxuo" width="480" height="270" frameborder="0" class="giphy-embed" allowfullscreen></iframe>', 'lsx-health-plan' ), |
|
359 | + 'classes' => 'lsx-field-col lsx-field-col-50', |
|
360 | + ) |
|
361 | + ); |
|
362 | + } |
|
363 | + |
|
364 | + /** |
|
365 | + * Registers the general settings for the exercise. |
|
366 | + * |
|
367 | + * @return void |
|
368 | + */ |
|
369 | + public function exercise_details() { |
|
370 | + $cmb = new_cmb2_box( |
|
371 | + array( |
|
372 | + 'id' => $this->slug . '_general_details_metabox', |
|
373 | + 'title' => __( 'Details', 'lsx-health-plan' ), |
|
374 | + 'object_types' => array( $this->slug ), |
|
375 | + 'context' => 'normal', |
|
376 | + 'priority' => 'high', |
|
377 | + 'show_names' => true, |
|
378 | + ) |
|
379 | + ); |
|
380 | + |
|
381 | + $cmb->add_field( |
|
382 | + array( |
|
383 | + 'name' => __( 'Side', 'lsx-health-plan' ), |
|
384 | + 'id' => $this->slug . '_side', |
|
385 | + 'type' => 'select', |
|
386 | + 'options' => array( |
|
387 | + '' => __( 'Select', 'lsx-health-plan' ), |
|
388 | + 'left' => __( 'Left', 'lsx-health-plan' ), |
|
389 | + 'right' => __( 'Right', 'lsx-health-plan' ), |
|
390 | + ), |
|
391 | + 'desc' => __( 'Select which side this exercise uses. ', 'lsx-health-plan' ), |
|
392 | + ) |
|
393 | + ); |
|
394 | + } |
|
395 | + |
|
396 | + /** |
|
397 | + * Holds the array for the single exercise breadcrumbs. |
|
398 | + * |
|
399 | + * @var array $crumbs |
|
400 | + * @return array |
|
401 | + */ |
|
402 | + public function exercise_breadcrumb_filter( $crumbs ) { |
|
403 | + $exercise = \lsx_health_plan\functions\get_option( 'endpoint_exercise', 'exercise' ); |
|
404 | + $exercises = \lsx_health_plan\functions\get_option( 'endpoint_exercise_archive', 'exercise' ); |
|
405 | + $url = get_post_type_archive_link( $exercise ); |
|
406 | + |
|
407 | + if ( is_singular( 'exercise' ) ) { |
|
408 | + $exercise_name = get_the_title(); |
|
409 | + $term_obj_list = get_the_terms( get_the_ID(), 'exercise-type' ); |
|
410 | + $exercise_type = $term_obj_list[0]->name; |
|
411 | + $exercise_type_url = get_term_link( $term_obj_list[0]->term_id ); |
|
412 | + |
|
413 | + $new_crumbs = array(); |
|
414 | + $new_crumbs[0] = $crumbs[0]; |
|
415 | + |
|
416 | + if ( function_exists( 'woocommerce_breadcrumb' ) ) { |
|
417 | + $new_crumbs[1] = array( |
|
418 | + 0 => $exercises, |
|
419 | + 1 => $url, |
|
420 | + ); |
|
421 | + $new_crumbs[2] = array( |
|
422 | + 0 => $exercise_type, |
|
423 | + 1 => $exercise_type_url, |
|
424 | + ); |
|
425 | + $new_crumbs[3] = array( |
|
426 | + 0 => $exercise_name, |
|
427 | + ); |
|
428 | + } else { |
|
429 | + $new_crumbs[1] = array( |
|
430 | + 'text' => $exercises, |
|
431 | + 'url' => $url, |
|
432 | + ); |
|
433 | + $new_crumbs[2] = array( |
|
434 | + 'text' => $exercise_type, |
|
435 | + 'url' => $exercise_type_url, |
|
436 | + ); |
|
437 | + $new_crumbs[3] = array( |
|
438 | + 'text' => $exercise_name, |
|
439 | + ); |
|
440 | + } |
|
441 | + $crumbs = $new_crumbs; |
|
442 | 442 | |
443 | - } |
|
444 | - if ( is_tax( 'exercise-type' ) || is_tax( 'muscle-group' ) || is_tax( 'equipment' ) ) { |
|
445 | - $term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) ); |
|
446 | - |
|
447 | - $single_term_title = str_replace( '-', ' ', $term->taxonomy ) . ': ' . $term->name; |
|
448 | - |
|
449 | - $new_crumbs = array(); |
|
450 | - $new_crumbs[0] = $crumbs[0]; |
|
451 | - |
|
452 | - if ( function_exists( 'woocommerce_breadcrumb' ) ) { |
|
453 | - $new_crumbs[1] = array( |
|
454 | - 0 => $exercises, |
|
455 | - 1 => $url, |
|
456 | - ); |
|
457 | - $new_crumbs[2] = array( |
|
458 | - 0 => $single_term_title, |
|
459 | - ); |
|
460 | - } else { |
|
461 | - $new_crumbs[1] = array( |
|
462 | - 'text' => $exercises, |
|
463 | - 'url' => $url, |
|
464 | - ); |
|
465 | - $new_crumbs[2] = array( |
|
466 | - 'text' => $single_term_title, |
|
467 | - ); |
|
468 | - } |
|
469 | - $crumbs = $new_crumbs; |
|
470 | - |
|
471 | - } |
|
472 | - if ( is_post_type_archive( 'exercise' ) ) { |
|
473 | - |
|
474 | - $new_crumbs = array(); |
|
475 | - $new_crumbs[0] = $crumbs[0]; |
|
476 | - |
|
477 | - if ( function_exists( 'woocommerce_breadcrumb' ) ) { |
|
478 | - $new_crumbs[1] = array( |
|
479 | - 0 => $exercises, |
|
480 | - ); |
|
481 | - } else { |
|
482 | - $new_crumbs[1] = array( |
|
483 | - 'text' => $exercises, |
|
484 | - ); |
|
485 | - } |
|
486 | - $crumbs = $new_crumbs; |
|
487 | - } |
|
488 | - return $crumbs; |
|
489 | - } |
|
443 | + } |
|
444 | + if ( is_tax( 'exercise-type' ) || is_tax( 'muscle-group' ) || is_tax( 'equipment' ) ) { |
|
445 | + $term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) ); |
|
446 | + |
|
447 | + $single_term_title = str_replace( '-', ' ', $term->taxonomy ) . ': ' . $term->name; |
|
448 | + |
|
449 | + $new_crumbs = array(); |
|
450 | + $new_crumbs[0] = $crumbs[0]; |
|
451 | + |
|
452 | + if ( function_exists( 'woocommerce_breadcrumb' ) ) { |
|
453 | + $new_crumbs[1] = array( |
|
454 | + 0 => $exercises, |
|
455 | + 1 => $url, |
|
456 | + ); |
|
457 | + $new_crumbs[2] = array( |
|
458 | + 0 => $single_term_title, |
|
459 | + ); |
|
460 | + } else { |
|
461 | + $new_crumbs[1] = array( |
|
462 | + 'text' => $exercises, |
|
463 | + 'url' => $url, |
|
464 | + ); |
|
465 | + $new_crumbs[2] = array( |
|
466 | + 'text' => $single_term_title, |
|
467 | + ); |
|
468 | + } |
|
469 | + $crumbs = $new_crumbs; |
|
470 | + |
|
471 | + } |
|
472 | + if ( is_post_type_archive( 'exercise' ) ) { |
|
473 | + |
|
474 | + $new_crumbs = array(); |
|
475 | + $new_crumbs[0] = $crumbs[0]; |
|
476 | + |
|
477 | + if ( function_exists( 'woocommerce_breadcrumb' ) ) { |
|
478 | + $new_crumbs[1] = array( |
|
479 | + 0 => $exercises, |
|
480 | + ); |
|
481 | + } else { |
|
482 | + $new_crumbs[1] = array( |
|
483 | + 'text' => $exercises, |
|
484 | + ); |
|
485 | + } |
|
486 | + $crumbs = $new_crumbs; |
|
487 | + } |
|
488 | + return $crumbs; |
|
489 | + } |
|
490 | 490 | } |
@@ -31,26 +31,26 @@ discard block |
||
31 | 31 | */ |
32 | 32 | public function __construct() { |
33 | 33 | |
34 | - if ( false !== \lsx_health_plan\functions\get_option( 'exercise_enabled', false ) ) { |
|
34 | + if (false !== \lsx_health_plan\functions\get_option('exercise_enabled', false)) { |
|
35 | 35 | // Post Type and Taxonomies. |
36 | - add_action( 'init', array( $this, 'register_post_type' ) ); |
|
37 | - add_action( 'init', array( $this, 'exercise_type_taxonomy_setup' ) ); |
|
38 | - add_action( 'init', array( $this, 'equipment_taxonomy_setup' ) ); |
|
39 | - add_action( 'init', array( $this, 'muscle_group_taxonomy_setup' ) ); |
|
40 | - add_action( 'admin_menu', array( $this, 'register_menus' ) ); |
|
36 | + add_action('init', array($this, 'register_post_type')); |
|
37 | + add_action('init', array($this, 'exercise_type_taxonomy_setup')); |
|
38 | + add_action('init', array($this, 'equipment_taxonomy_setup')); |
|
39 | + add_action('init', array($this, 'muscle_group_taxonomy_setup')); |
|
40 | + add_action('admin_menu', array($this, 'register_menus')); |
|
41 | 41 | |
42 | 42 | // Custom Fields. |
43 | - add_action( 'cmb2_admin_init', array( $this, 'exercise_details' ), 8 ); |
|
44 | - add_action( 'cmb2_admin_init', array( $this, 'gallery_metabox' ), 9 ); |
|
45 | - add_filter( 'lsx_health_plan_connections', array( $this, 'enable_connections' ), 10, 1 ); |
|
43 | + add_action('cmb2_admin_init', array($this, 'exercise_details'), 8); |
|
44 | + add_action('cmb2_admin_init', array($this, 'gallery_metabox'), 9); |
|
45 | + add_filter('lsx_health_plan_connections', array($this, 'enable_connections'), 10, 1); |
|
46 | 46 | |
47 | 47 | // Template Redirects. |
48 | - add_filter( 'lsx_health_plan_archive_template', array( $this, 'enable_post_type' ), 10, 1 ); |
|
49 | - add_filter( 'lsx_health_plan_single_template', array( $this, 'enable_post_type' ), 10, 1 ); |
|
48 | + add_filter('lsx_health_plan_archive_template', array($this, 'enable_post_type'), 10, 1); |
|
49 | + add_filter('lsx_health_plan_single_template', array($this, 'enable_post_type'), 10, 1); |
|
50 | 50 | |
51 | 51 | //Breadcrumbs |
52 | - add_filter( 'wpseo_breadcrumb_links', array( $this, 'exercise_breadcrumb_filter' ), 30, 1 ); |
|
53 | - add_filter( 'woocommerce_get_breadcrumb', array( $this, 'exercise_breadcrumb_filter' ), 30, 1 ); |
|
52 | + add_filter('wpseo_breadcrumb_links', array($this, 'exercise_breadcrumb_filter'), 30, 1); |
|
53 | + add_filter('woocommerce_get_breadcrumb', array($this, 'exercise_breadcrumb_filter'), 30, 1); |
|
54 | 54 | |
55 | 55 | } |
56 | 56 | |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | */ |
67 | 67 | public static function get_instance() { |
68 | 68 | // If the single instance hasn't been set, set it now. |
69 | - if ( null === self::$instance ) { |
|
69 | + if (null === self::$instance) { |
|
70 | 70 | self::$instance = new self(); |
71 | 71 | } |
72 | 72 | return self::$instance; |
@@ -76,21 +76,21 @@ discard block |
||
76 | 76 | */ |
77 | 77 | public function register_post_type() { |
78 | 78 | $labels = array( |
79 | - 'name' => esc_html__( 'Exercises', 'lsx-health-plan' ), |
|
80 | - 'singular_name' => esc_html__( 'Exercise', 'lsx-health-plan' ), |
|
81 | - 'add_new' => esc_html_x( 'Add New', 'post type general name', 'lsx-health-plan' ), |
|
82 | - 'add_new_item' => esc_html__( 'Add New', 'lsx-health-plan' ), |
|
83 | - 'edit_item' => esc_html__( 'Edit', 'lsx-health-plan' ), |
|
84 | - 'new_item' => esc_html__( 'New', 'lsx-health-plan' ), |
|
85 | - 'all_items' => esc_html__( 'All Exercises', 'lsx-health-plan' ), |
|
86 | - 'view_item' => esc_html__( 'View', 'lsx-health-plan' ), |
|
87 | - 'search_items' => esc_html__( 'Search', 'lsx-health-plan' ), |
|
88 | - 'not_found' => esc_html__( 'None found', 'lsx-health-plan' ), |
|
89 | - 'not_found_in_trash' => esc_html__( 'None found in Trash', 'lsx-health-plan' ), |
|
79 | + 'name' => esc_html__('Exercises', 'lsx-health-plan'), |
|
80 | + 'singular_name' => esc_html__('Exercise', 'lsx-health-plan'), |
|
81 | + 'add_new' => esc_html_x('Add New', 'post type general name', 'lsx-health-plan'), |
|
82 | + 'add_new_item' => esc_html__('Add New', 'lsx-health-plan'), |
|
83 | + 'edit_item' => esc_html__('Edit', 'lsx-health-plan'), |
|
84 | + 'new_item' => esc_html__('New', 'lsx-health-plan'), |
|
85 | + 'all_items' => esc_html__('All Exercises', 'lsx-health-plan'), |
|
86 | + 'view_item' => esc_html__('View', 'lsx-health-plan'), |
|
87 | + 'search_items' => esc_html__('Search', 'lsx-health-plan'), |
|
88 | + 'not_found' => esc_html__('None found', 'lsx-health-plan'), |
|
89 | + 'not_found_in_trash' => esc_html__('None found in Trash', 'lsx-health-plan'), |
|
90 | 90 | 'parent_item_colon' => '', |
91 | - 'menu_name' => esc_html__( 'Exercises', 'lsx-health-plan' ), |
|
91 | + 'menu_name' => esc_html__('Exercises', 'lsx-health-plan'), |
|
92 | 92 | ); |
93 | - $args = array( |
|
93 | + $args = array( |
|
94 | 94 | 'labels' => $labels, |
95 | 95 | 'public' => true, |
96 | 96 | 'publicly_queryable' => true, |
@@ -100,10 +100,10 @@ discard block |
||
100 | 100 | 'menu_icon' => 'dashicons-universal-access', |
101 | 101 | 'query_var' => true, |
102 | 102 | 'rewrite' => array( |
103 | - 'slug' => \lsx_health_plan\functions\get_option( 'endpoint_exercise_single', 'exercise' ), |
|
103 | + 'slug' => \lsx_health_plan\functions\get_option('endpoint_exercise_single', 'exercise'), |
|
104 | 104 | ), |
105 | 105 | 'capability_type' => 'page', |
106 | - 'has_archive' => \lsx_health_plan\functions\get_option( 'endpoint_exercise_archive', 'exercises' ), |
|
106 | + 'has_archive' => \lsx_health_plan\functions\get_option('endpoint_exercise_archive', 'exercises'), |
|
107 | 107 | 'hierarchical' => false, |
108 | 108 | 'menu_position' => null, |
109 | 109 | 'supports' => array( |
@@ -114,7 +114,7 @@ discard block |
||
114 | 114 | 'custom-fields', |
115 | 115 | ), |
116 | 116 | ); |
117 | - register_post_type( 'exercise', $args ); |
|
117 | + register_post_type('exercise', $args); |
|
118 | 118 | } |
119 | 119 | |
120 | 120 | /** |
@@ -124,17 +124,17 @@ discard block |
||
124 | 124 | */ |
125 | 125 | public function exercise_type_taxonomy_setup() { |
126 | 126 | $labels = array( |
127 | - 'name' => esc_html_x( 'Exercise Type', 'taxonomy general name', 'lsx-health-plan' ), |
|
128 | - 'singular_name' => esc_html_x( 'Exercise Type', 'taxonomy singular name', 'lsx-health-plan' ), |
|
129 | - 'search_items' => esc_html__( 'Search', 'lsx-health-plan' ), |
|
130 | - 'all_items' => esc_html__( 'All', 'lsx-health-plan' ), |
|
131 | - 'parent_item' => esc_html__( 'Parent', 'lsx-health-plan' ), |
|
132 | - 'parent_item_colon' => esc_html__( 'Parent:', 'lsx-health-plan' ), |
|
133 | - 'edit_item' => esc_html__( 'Edit', 'lsx-health-plan' ), |
|
134 | - 'update_item' => esc_html__( 'Update', 'lsx-health-plan' ), |
|
135 | - 'add_new_item' => esc_html__( 'Add New', 'lsx-health-plan' ), |
|
136 | - 'new_item_name' => esc_html__( 'New Name', 'lsx-health-plan' ), |
|
137 | - 'menu_name' => esc_html__( 'Exercise Types', 'lsx-health-plan' ), |
|
127 | + 'name' => esc_html_x('Exercise Type', 'taxonomy general name', 'lsx-health-plan'), |
|
128 | + 'singular_name' => esc_html_x('Exercise Type', 'taxonomy singular name', 'lsx-health-plan'), |
|
129 | + 'search_items' => esc_html__('Search', 'lsx-health-plan'), |
|
130 | + 'all_items' => esc_html__('All', 'lsx-health-plan'), |
|
131 | + 'parent_item' => esc_html__('Parent', 'lsx-health-plan'), |
|
132 | + 'parent_item_colon' => esc_html__('Parent:', 'lsx-health-plan'), |
|
133 | + 'edit_item' => esc_html__('Edit', 'lsx-health-plan'), |
|
134 | + 'update_item' => esc_html__('Update', 'lsx-health-plan'), |
|
135 | + 'add_new_item' => esc_html__('Add New', 'lsx-health-plan'), |
|
136 | + 'new_item_name' => esc_html__('New Name', 'lsx-health-plan'), |
|
137 | + 'menu_name' => esc_html__('Exercise Types', 'lsx-health-plan'), |
|
138 | 138 | ); |
139 | 139 | |
140 | 140 | $args = array( |
@@ -144,12 +144,12 @@ discard block |
||
144 | 144 | 'show_admin_column' => true, |
145 | 145 | 'query_var' => true, |
146 | 146 | 'rewrite' => array( |
147 | - 'slug' => \lsx_health_plan\functions\get_option( 'endpoint_exercise_type', 'exercise-type' ), |
|
147 | + 'slug' => \lsx_health_plan\functions\get_option('endpoint_exercise_type', 'exercise-type'), |
|
148 | 148 | ), |
149 | 149 | 'show_in_rest' => true, |
150 | 150 | ); |
151 | 151 | |
152 | - register_taxonomy( 'exercise-type', array( 'exercise' ), $args ); |
|
152 | + register_taxonomy('exercise-type', array('exercise'), $args); |
|
153 | 153 | } |
154 | 154 | |
155 | 155 | /** |
@@ -159,17 +159,17 @@ discard block |
||
159 | 159 | */ |
160 | 160 | public function equipment_taxonomy_setup() { |
161 | 161 | $labels = array( |
162 | - 'name' => esc_html_x( 'Equipment', 'taxonomy general name', 'lsx-health-plan' ), |
|
163 | - 'singular_name' => esc_html_x( 'Equipment', 'taxonomy singular name', 'lsx-health-plan' ), |
|
164 | - 'search_items' => esc_html__( 'Search', 'lsx-health-plan' ), |
|
165 | - 'all_items' => esc_html__( 'All', 'lsx-health-plan' ), |
|
166 | - 'parent_item' => esc_html__( 'Parent', 'lsx-health-plan' ), |
|
167 | - 'parent_item_colon' => esc_html__( 'Parent:', 'lsx-health-plan' ), |
|
168 | - 'edit_item' => esc_html__( 'Edit', 'lsx-health-plan' ), |
|
169 | - 'update_item' => esc_html__( 'Update', 'lsx-health-plan' ), |
|
170 | - 'add_new_item' => esc_html__( 'Add New', 'lsx-health-plan' ), |
|
171 | - 'new_item_name' => esc_html__( 'New Name', 'lsx-health-plan' ), |
|
172 | - 'menu_name' => esc_html__( 'Equipment', 'lsx-health-plan' ), |
|
162 | + 'name' => esc_html_x('Equipment', 'taxonomy general name', 'lsx-health-plan'), |
|
163 | + 'singular_name' => esc_html_x('Equipment', 'taxonomy singular name', 'lsx-health-plan'), |
|
164 | + 'search_items' => esc_html__('Search', 'lsx-health-plan'), |
|
165 | + 'all_items' => esc_html__('All', 'lsx-health-plan'), |
|
166 | + 'parent_item' => esc_html__('Parent', 'lsx-health-plan'), |
|
167 | + 'parent_item_colon' => esc_html__('Parent:', 'lsx-health-plan'), |
|
168 | + 'edit_item' => esc_html__('Edit', 'lsx-health-plan'), |
|
169 | + 'update_item' => esc_html__('Update', 'lsx-health-plan'), |
|
170 | + 'add_new_item' => esc_html__('Add New', 'lsx-health-plan'), |
|
171 | + 'new_item_name' => esc_html__('New Name', 'lsx-health-plan'), |
|
172 | + 'menu_name' => esc_html__('Equipment', 'lsx-health-plan'), |
|
173 | 173 | ); |
174 | 174 | |
175 | 175 | $args = array( |
@@ -179,12 +179,12 @@ discard block |
||
179 | 179 | 'show_admin_column' => true, |
180 | 180 | 'query_var' => true, |
181 | 181 | 'rewrite' => array( |
182 | - 'slug' => \lsx_health_plan\functions\get_option( 'endpoint_exercise_equipment', 'equipment' ), |
|
182 | + 'slug' => \lsx_health_plan\functions\get_option('endpoint_exercise_equipment', 'equipment'), |
|
183 | 183 | ), |
184 | 184 | 'show_in_rest' => true, |
185 | 185 | ); |
186 | 186 | |
187 | - register_taxonomy( 'equipment', array( 'exercise' ), $args ); |
|
187 | + register_taxonomy('equipment', array('exercise'), $args); |
|
188 | 188 | } |
189 | 189 | |
190 | 190 | /** |
@@ -194,17 +194,17 @@ discard block |
||
194 | 194 | */ |
195 | 195 | public function muscle_group_taxonomy_setup() { |
196 | 196 | $labels = array( |
197 | - 'name' => esc_html_x( 'Muscle Groups', 'taxonomy general name', 'lsx-health-plan' ), |
|
198 | - 'singular_name' => esc_html_x( 'Muscle Group', 'taxonomy singular name', 'lsx-health-plan' ), |
|
199 | - 'search_items' => esc_html__( 'Search', 'lsx-health-plan' ), |
|
200 | - 'all_items' => esc_html__( 'All', 'lsx-health-plan' ), |
|
201 | - 'parent_item' => esc_html__( 'Parent', 'lsx-health-plan' ), |
|
202 | - 'parent_item_colon' => esc_html__( 'Parent:', 'lsx-health-plan' ), |
|
203 | - 'edit_item' => esc_html__( 'Edit', 'lsx-health-plan' ), |
|
204 | - 'update_item' => esc_html__( 'Update', 'lsx-health-plan' ), |
|
205 | - 'add_new_item' => esc_html__( 'Add New', 'lsx-health-plan' ), |
|
206 | - 'new_item_name' => esc_html__( 'New Name', 'lsx-health-plan' ), |
|
207 | - 'menu_name' => esc_html__( 'Muscle Groups', 'lsx-health-plan' ), |
|
197 | + 'name' => esc_html_x('Muscle Groups', 'taxonomy general name', 'lsx-health-plan'), |
|
198 | + 'singular_name' => esc_html_x('Muscle Group', 'taxonomy singular name', 'lsx-health-plan'), |
|
199 | + 'search_items' => esc_html__('Search', 'lsx-health-plan'), |
|
200 | + 'all_items' => esc_html__('All', 'lsx-health-plan'), |
|
201 | + 'parent_item' => esc_html__('Parent', 'lsx-health-plan'), |
|
202 | + 'parent_item_colon' => esc_html__('Parent:', 'lsx-health-plan'), |
|
203 | + 'edit_item' => esc_html__('Edit', 'lsx-health-plan'), |
|
204 | + 'update_item' => esc_html__('Update', 'lsx-health-plan'), |
|
205 | + 'add_new_item' => esc_html__('Add New', 'lsx-health-plan'), |
|
206 | + 'new_item_name' => esc_html__('New Name', 'lsx-health-plan'), |
|
207 | + 'menu_name' => esc_html__('Muscle Groups', 'lsx-health-plan'), |
|
208 | 208 | ); |
209 | 209 | |
210 | 210 | $args = array( |
@@ -214,12 +214,12 @@ discard block |
||
214 | 214 | 'show_admin_column' => true, |
215 | 215 | 'query_var' => true, |
216 | 216 | 'rewrite' => array( |
217 | - 'slug' => \lsx_health_plan\functions\get_option( 'endpoint_exercise_musclegroup', 'muscle-group' ), |
|
217 | + 'slug' => \lsx_health_plan\functions\get_option('endpoint_exercise_musclegroup', 'muscle-group'), |
|
218 | 218 | ), |
219 | 219 | 'show_in_rest' => true, |
220 | 220 | ); |
221 | 221 | |
222 | - register_taxonomy( 'muscle-group', array( 'exercise' ), $args ); |
|
222 | + register_taxonomy('muscle-group', array('exercise'), $args); |
|
223 | 223 | } |
224 | 224 | |
225 | 225 | /** |
@@ -228,10 +228,10 @@ discard block |
||
228 | 228 | * @return void |
229 | 229 | */ |
230 | 230 | public function register_menus() { |
231 | - add_submenu_page( 'edit.php?post_type=workout', esc_html__( 'Exercises', 'lsx-health-plan' ), esc_html__( 'Exercises', 'lsx-health-plan' ), 'edit_posts', 'edit.php?post_type=exercise' ); |
|
232 | - add_submenu_page( 'edit.php?post_type=workout', esc_html__( 'Exercise Types', 'lsx-health-plan' ), esc_html__( 'Exercise Types', 'lsx-health-plan' ), 'edit_posts', 'edit-tags.php?taxonomy=exercise-type&post_type=exercise' ); |
|
233 | - add_submenu_page( 'edit.php?post_type=workout', esc_html__( 'Equipment', 'lsx-health-plan' ), esc_html__( 'Equipment', 'lsx-health-plan' ), 'edit_posts', 'edit-tags.php?taxonomy=equipment&post_type=exercise' ); |
|
234 | - add_submenu_page( 'edit.php?post_type=workout', esc_html__( 'Muscle Groups', 'lsx-health-plan' ), esc_html__( 'Muscle Groups', 'lsx-health-plan' ), 'edit_posts', 'edit-tags.php?taxonomy=muscle-group&post_type=exercise' ); |
|
231 | + add_submenu_page('edit.php?post_type=workout', esc_html__('Exercises', 'lsx-health-plan'), esc_html__('Exercises', 'lsx-health-plan'), 'edit_posts', 'edit.php?post_type=exercise'); |
|
232 | + add_submenu_page('edit.php?post_type=workout', esc_html__('Exercise Types', 'lsx-health-plan'), esc_html__('Exercise Types', 'lsx-health-plan'), 'edit_posts', 'edit-tags.php?taxonomy=exercise-type&post_type=exercise'); |
|
233 | + add_submenu_page('edit.php?post_type=workout', esc_html__('Equipment', 'lsx-health-plan'), esc_html__('Equipment', 'lsx-health-plan'), 'edit_posts', 'edit-tags.php?taxonomy=equipment&post_type=exercise'); |
|
234 | + add_submenu_page('edit.php?post_type=workout', esc_html__('Muscle Groups', 'lsx-health-plan'), esc_html__('Muscle Groups', 'lsx-health-plan'), 'edit_posts', 'edit-tags.php?taxonomy=muscle-group&post_type=exercise'); |
|
235 | 235 | } |
236 | 236 | |
237 | 237 | /** |
@@ -240,7 +240,7 @@ discard block |
||
240 | 240 | * @param array $post_types |
241 | 241 | * @return array |
242 | 242 | */ |
243 | - public function enable_post_type( $post_types = array() ) { |
|
243 | + public function enable_post_type($post_types = array()) { |
|
244 | 244 | $post_types[] = $this->slug; |
245 | 245 | return $post_types; |
246 | 246 | } |
@@ -251,7 +251,7 @@ discard block |
||
251 | 251 | * @param array $connections |
252 | 252 | * @return void |
253 | 253 | */ |
254 | - public function enable_connections( $connections = array() ) { |
|
254 | + public function enable_connections($connections = array()) { |
|
255 | 255 | $connections['exercise']['connected_workouts'] = 'connected_exercises'; |
256 | 256 | $connections['workout']['connected_exercises'] = 'connected_workouts'; |
257 | 257 | return $connections; |
@@ -264,8 +264,8 @@ discard block |
||
264 | 264 | $cmb = new_cmb2_box( |
265 | 265 | array( |
266 | 266 | 'id' => $this->slug . '_gallery_details_metabox', |
267 | - 'title' => __( 'Exercise Gallery', 'lsx-health-plan' ), |
|
268 | - 'object_types' => array( $this->slug ), |
|
267 | + 'title' => __('Exercise Gallery', 'lsx-health-plan'), |
|
268 | + 'object_types' => array($this->slug), |
|
269 | 269 | 'context' => 'normal', |
270 | 270 | 'priority' => 'low', |
271 | 271 | 'show_names' => true, |
@@ -274,12 +274,12 @@ discard block |
||
274 | 274 | |
275 | 275 | $cmb->add_field( |
276 | 276 | array( |
277 | - 'name' => __( 'Layout', 'lsx-health-plan' ), |
|
277 | + 'name' => __('Layout', 'lsx-health-plan'), |
|
278 | 278 | 'id' => $this->slug . '_gallery_layout', |
279 | 279 | 'type' => 'radio', |
280 | 280 | 'options' => array( |
281 | - 'slider' => __( 'Slider', 'lsx-health-plan' ) . ' {#}', // {#} gets replaced by row number |
|
282 | - 'grid' => __( 'Grid', 'lsx-health-plan' ), |
|
281 | + 'slider' => __('Slider', 'lsx-health-plan') . ' {#}', // {#} gets replaced by row number |
|
282 | + 'grid' => __('Grid', 'lsx-health-plan'), |
|
283 | 283 | ), |
284 | 284 | 'default' => 'grid', |
285 | 285 | ) |
@@ -287,12 +287,12 @@ discard block |
||
287 | 287 | |
288 | 288 | $cmb->add_field( |
289 | 289 | array( |
290 | - 'name' => __( 'Grid Columns', 'lsx-health-plan' ), |
|
290 | + 'name' => __('Grid Columns', 'lsx-health-plan'), |
|
291 | 291 | 'id' => $this->slug . '_gallery_columns', |
292 | 292 | 'type' => 'select', |
293 | 293 | 'options' => array( |
294 | - '3' => __( '2 Columns', 'lsx-health-plan' ), |
|
295 | - '4' => __( '3 Columns', 'lsx-health-plan' ), |
|
294 | + '3' => __('2 Columns', 'lsx-health-plan'), |
|
295 | + '4' => __('3 Columns', 'lsx-health-plan'), |
|
296 | 296 | ), |
297 | 297 | 'default' => '1', |
298 | 298 | ) |
@@ -304,12 +304,12 @@ discard block |
||
304 | 304 | 'id' => $this->slug . '_gallery', |
305 | 305 | 'type' => 'group', |
306 | 306 | 'options' => array( |
307 | - 'group_title' => __( 'Gallery', 'lsx-health-plan' ) . ' {#}', // {#} gets replaced by row number |
|
308 | - 'add_button' => __( 'Add Item', 'lsx-health-plan' ), |
|
309 | - 'remove_button' => __( 'Remove Item', 'lsx-health-plan' ), |
|
307 | + 'group_title' => __('Gallery', 'lsx-health-plan') . ' {#}', // {#} gets replaced by row number |
|
308 | + 'add_button' => __('Add Item', 'lsx-health-plan'), |
|
309 | + 'remove_button' => __('Remove Item', 'lsx-health-plan'), |
|
310 | 310 | 'sortable' => true, |
311 | 311 | ), |
312 | - 'desc' => __( 'Upload only one image, video or gif per gallery group, each group will only display 1 item.', 'lsx-health-plan' ), |
|
312 | + 'desc' => __('Upload only one image, video or gif per gallery group, each group will only display 1 item.', 'lsx-health-plan'), |
|
313 | 313 | 'classes' => 'lsx-admin-row', |
314 | 314 | ) |
315 | 315 | ); |
@@ -318,13 +318,13 @@ discard block |
||
318 | 318 | $cmb->add_group_field( |
319 | 319 | $gallery_group, |
320 | 320 | array( |
321 | - 'name' => __( 'Image', 'lsx-health-plan' ), |
|
321 | + 'name' => __('Image', 'lsx-health-plan'), |
|
322 | 322 | 'id' => $this->slug . '_gallery_image', |
323 | 323 | 'type' => 'file', |
324 | 324 | 'text' => array( |
325 | - 'add_upload_file_text' => __( 'Add File', 'lsx-health-plan' ), |
|
325 | + 'add_upload_file_text' => __('Add File', 'lsx-health-plan'), |
|
326 | 326 | ), |
327 | - 'desc' => __( 'Upload an image a minimum of 800px x 600px in size.', 'lsx-health-plan' ), |
|
327 | + 'desc' => __('Upload an image a minimum of 800px x 600px in size.', 'lsx-health-plan'), |
|
328 | 328 | 'query_args' => array( |
329 | 329 | 'type' => array( |
330 | 330 | 'image/gif', |
@@ -341,10 +341,10 @@ discard block |
||
341 | 341 | $cmb->add_group_field( |
342 | 342 | $gallery_group, |
343 | 343 | array( |
344 | - 'name' => __( 'oEmbed', 'lsx-health-plan' ), |
|
344 | + 'name' => __('oEmbed', 'lsx-health-plan'), |
|
345 | 345 | 'id' => $this->slug . '_gallery_embed', |
346 | 346 | 'type' => 'text', |
347 | - 'desc' => __( 'Drop in the embed url for your video from YouTube, Vimeo or DailyMotion, e.g: "https://www.youtube.com/watch?v=9xwazD5SyVg". A full list of supports formats can be found at <a href="https://make.wordpress.org/support/user-manual/content/media/adding-media-to-your-pages-and-posts/embedding-media-from-other-sites/">WordPress</a>', 'lsx-health-plan' ), |
|
347 | + 'desc' => __('Drop in the embed url for your video from YouTube, Vimeo or DailyMotion, e.g: "https://www.youtube.com/watch?v=9xwazD5SyVg". A full list of supports formats can be found at <a href="https://make.wordpress.org/support/user-manual/content/media/adding-media-to-your-pages-and-posts/embedding-media-from-other-sites/">WordPress</a>', 'lsx-health-plan'), |
|
348 | 348 | 'classes' => 'test-apply-form lsx-field-col lsx-field-col-50', |
349 | 349 | ) |
350 | 350 | ); |
@@ -352,10 +352,10 @@ discard block |
||
352 | 352 | $cmb->add_group_field( |
353 | 353 | $gallery_group, |
354 | 354 | array( |
355 | - 'name' => __( 'External Media', 'lsx-health-plan' ), |
|
355 | + 'name' => __('External Media', 'lsx-health-plan'), |
|
356 | 356 | 'id' => $this->slug . '_gallery_external', |
357 | 357 | 'type' => 'textarea_code', |
358 | - 'desc' => __( 'Drop in the iFrame embed code from Giphy in this field, i.e: <iframe src="https://giphy.com/embed/3o7527Rn1HxXWqgxuo" width="480" height="270" frameborder="0" class="giphy-embed" allowfullscreen></iframe>', 'lsx-health-plan' ), |
|
358 | + 'desc' => __('Drop in the iFrame embed code from Giphy in this field, i.e: <iframe src="https://giphy.com/embed/3o7527Rn1HxXWqgxuo" width="480" height="270" frameborder="0" class="giphy-embed" allowfullscreen></iframe>', 'lsx-health-plan'), |
|
359 | 359 | 'classes' => 'lsx-field-col lsx-field-col-50', |
360 | 360 | ) |
361 | 361 | ); |
@@ -370,8 +370,8 @@ discard block |
||
370 | 370 | $cmb = new_cmb2_box( |
371 | 371 | array( |
372 | 372 | 'id' => $this->slug . '_general_details_metabox', |
373 | - 'title' => __( 'Details', 'lsx-health-plan' ), |
|
374 | - 'object_types' => array( $this->slug ), |
|
373 | + 'title' => __('Details', 'lsx-health-plan'), |
|
374 | + 'object_types' => array($this->slug), |
|
375 | 375 | 'context' => 'normal', |
376 | 376 | 'priority' => 'high', |
377 | 377 | 'show_names' => true, |
@@ -380,15 +380,15 @@ discard block |
||
380 | 380 | |
381 | 381 | $cmb->add_field( |
382 | 382 | array( |
383 | - 'name' => __( 'Side', 'lsx-health-plan' ), |
|
383 | + 'name' => __('Side', 'lsx-health-plan'), |
|
384 | 384 | 'id' => $this->slug . '_side', |
385 | 385 | 'type' => 'select', |
386 | 386 | 'options' => array( |
387 | - '' => __( 'Select', 'lsx-health-plan' ), |
|
388 | - 'left' => __( 'Left', 'lsx-health-plan' ), |
|
389 | - 'right' => __( 'Right', 'lsx-health-plan' ), |
|
387 | + '' => __('Select', 'lsx-health-plan'), |
|
388 | + 'left' => __('Left', 'lsx-health-plan'), |
|
389 | + 'right' => __('Right', 'lsx-health-plan'), |
|
390 | 390 | ), |
391 | - 'desc' => __( 'Select which side this exercise uses. ', 'lsx-health-plan' ), |
|
391 | + 'desc' => __('Select which side this exercise uses. ', 'lsx-health-plan'), |
|
392 | 392 | ) |
393 | 393 | ); |
394 | 394 | } |
@@ -399,21 +399,21 @@ discard block |
||
399 | 399 | * @var array $crumbs |
400 | 400 | * @return array |
401 | 401 | */ |
402 | - public function exercise_breadcrumb_filter( $crumbs ) { |
|
403 | - $exercise = \lsx_health_plan\functions\get_option( 'endpoint_exercise', 'exercise' ); |
|
404 | - $exercises = \lsx_health_plan\functions\get_option( 'endpoint_exercise_archive', 'exercise' ); |
|
405 | - $url = get_post_type_archive_link( $exercise ); |
|
402 | + public function exercise_breadcrumb_filter($crumbs) { |
|
403 | + $exercise = \lsx_health_plan\functions\get_option('endpoint_exercise', 'exercise'); |
|
404 | + $exercises = \lsx_health_plan\functions\get_option('endpoint_exercise_archive', 'exercise'); |
|
405 | + $url = get_post_type_archive_link($exercise); |
|
406 | 406 | |
407 | - if ( is_singular( 'exercise' ) ) { |
|
407 | + if (is_singular('exercise')) { |
|
408 | 408 | $exercise_name = get_the_title(); |
409 | - $term_obj_list = get_the_terms( get_the_ID(), 'exercise-type' ); |
|
409 | + $term_obj_list = get_the_terms(get_the_ID(), 'exercise-type'); |
|
410 | 410 | $exercise_type = $term_obj_list[0]->name; |
411 | - $exercise_type_url = get_term_link( $term_obj_list[0]->term_id ); |
|
411 | + $exercise_type_url = get_term_link($term_obj_list[0]->term_id); |
|
412 | 412 | |
413 | 413 | $new_crumbs = array(); |
414 | 414 | $new_crumbs[0] = $crumbs[0]; |
415 | 415 | |
416 | - if ( function_exists( 'woocommerce_breadcrumb' ) ) { |
|
416 | + if (function_exists('woocommerce_breadcrumb')) { |
|
417 | 417 | $new_crumbs[1] = array( |
418 | 418 | 0 => $exercises, |
419 | 419 | 1 => $url, |
@@ -441,15 +441,15 @@ discard block |
||
441 | 441 | $crumbs = $new_crumbs; |
442 | 442 | |
443 | 443 | } |
444 | - if ( is_tax( 'exercise-type' ) || is_tax( 'muscle-group' ) || is_tax( 'equipment' ) ) { |
|
445 | - $term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) ); |
|
444 | + if (is_tax('exercise-type') || is_tax('muscle-group') || is_tax('equipment')) { |
|
445 | + $term = get_term_by('slug', get_query_var('term'), get_query_var('taxonomy')); |
|
446 | 446 | |
447 | - $single_term_title = str_replace( '-', ' ', $term->taxonomy ) . ': ' . $term->name; |
|
447 | + $single_term_title = str_replace('-', ' ', $term->taxonomy) . ': ' . $term->name; |
|
448 | 448 | |
449 | 449 | $new_crumbs = array(); |
450 | 450 | $new_crumbs[0] = $crumbs[0]; |
451 | 451 | |
452 | - if ( function_exists( 'woocommerce_breadcrumb' ) ) { |
|
452 | + if (function_exists('woocommerce_breadcrumb')) { |
|
453 | 453 | $new_crumbs[1] = array( |
454 | 454 | 0 => $exercises, |
455 | 455 | 1 => $url, |
@@ -469,12 +469,12 @@ discard block |
||
469 | 469 | $crumbs = $new_crumbs; |
470 | 470 | |
471 | 471 | } |
472 | - if ( is_post_type_archive( 'exercise' ) ) { |
|
472 | + if (is_post_type_archive('exercise')) { |
|
473 | 473 | |
474 | 474 | $new_crumbs = array(); |
475 | 475 | $new_crumbs[0] = $crumbs[0]; |
476 | 476 | |
477 | - if ( function_exists( 'woocommerce_breadcrumb' ) ) { |
|
477 | + if (function_exists('woocommerce_breadcrumb')) { |
|
478 | 478 | $new_crumbs[1] = array( |
479 | 479 | 0 => $exercises, |
480 | 480 | ); |
@@ -10,461 +10,461 @@ |
||
10 | 10 | */ |
11 | 11 | class Workout { |
12 | 12 | |
13 | - /** |
|
14 | - * Holds class instance |
|
15 | - * |
|
16 | - * @since 1.0.0 |
|
17 | - * |
|
18 | - * @var object \lsx_health_plan\classes\Workout() |
|
19 | - */ |
|
20 | - protected static $instance = null; |
|
21 | - |
|
22 | - /** |
|
23 | - * Holds post_type slug used as an index |
|
24 | - * |
|
25 | - * @since 1.0.0 |
|
26 | - * |
|
27 | - * @var string |
|
28 | - */ |
|
29 | - public $slug = 'workout'; |
|
30 | - |
|
31 | - /** |
|
32 | - * Constructor |
|
33 | - */ |
|
34 | - public function __construct() { |
|
35 | - add_action( 'init', array( $this, 'register_post_type' ) ); |
|
36 | - add_filter( 'lsx_health_plan_single_template', array( $this, 'enable_post_type' ), 10, 1 ); |
|
37 | - add_action( 'init', array( $this, 'workout_type_taxonomy_setup' ) ); |
|
38 | - add_filter( 'lsx_health_plan_connections', array( $this, 'enable_connections' ), 10, 1 ); |
|
39 | - add_action( 'cmb2_admin_init', array( $this, 'featured_metabox' ), 5 ); |
|
40 | - add_action( 'cmb2_admin_init', array( $this, 'details_metaboxes' ) ); |
|
41 | - add_filter( 'get_the_archive_title', array( $this, 'get_the_archive_title' ), 100 ); |
|
42 | - |
|
43 | - // Template Redirects. |
|
44 | - add_action( 'pre_get_posts', array( $this, 'set_parent_only' ), 10, 1 ); |
|
45 | - add_filter( 'lsx_health_plan_archive_template', array( $this, 'enable_post_type' ), 10, 1 ); |
|
46 | - |
|
47 | - //Breadcrumbs |
|
48 | - add_filter( 'wpseo_breadcrumb_links', array( $this, 'workout_breadcrumb_filter' ), 30, 1 ); |
|
49 | - add_filter( 'woocommerce_get_breadcrumb', array( $this, 'workout_breadcrumb_filter' ), 30, 1 ); |
|
50 | - } |
|
51 | - |
|
52 | - /** |
|
53 | - * Return an instance of this class. |
|
54 | - * |
|
55 | - * @since 1.0.0 |
|
56 | - * |
|
57 | - * @return object \lsx_health_plan\classes\Workout() A single instance of this class. |
|
58 | - */ |
|
59 | - public static function get_instance() { |
|
60 | - // If the single instance hasn't been set, set it now. |
|
61 | - if ( null === self::$instance ) { |
|
62 | - self::$instance = new self(); |
|
63 | - } |
|
64 | - return self::$instance; |
|
65 | - } |
|
66 | - /** |
|
67 | - * Register the post type. |
|
68 | - */ |
|
69 | - public function register_post_type() { |
|
70 | - $labels = array( |
|
71 | - 'name' => esc_html__( 'Workouts', 'lsx-health-plan' ), |
|
72 | - 'singular_name' => esc_html__( 'Workout', 'lsx-health-plan' ), |
|
73 | - 'add_new' => esc_html_x( 'Add New', 'post type general name', 'lsx-health-plan' ), |
|
74 | - 'add_new_item' => esc_html__( 'Add New', 'lsx-health-plan' ), |
|
75 | - 'edit_item' => esc_html__( 'Edit', 'lsx-health-plan' ), |
|
76 | - 'new_item' => esc_html__( 'New', 'lsx-health-plan' ), |
|
77 | - 'all_items' => esc_html__( 'All Workouts', 'lsx-health-plan' ), |
|
78 | - 'view_item' => esc_html__( 'View', 'lsx-health-plan' ), |
|
79 | - 'search_items' => esc_html__( 'Search', 'lsx-health-plan' ), |
|
80 | - 'not_found' => esc_html__( 'None found', 'lsx-health-plan' ), |
|
81 | - 'not_found_in_trash' => esc_html__( 'None found in Trash', 'lsx-health-plan' ), |
|
82 | - 'parent_item_colon' => esc_html__( 'Parent:', 'lsx-health-plan' ), |
|
83 | - 'menu_name' => esc_html__( 'Workouts', 'lsx-health-plan' ), |
|
84 | - ); |
|
85 | - $args = array( |
|
86 | - 'labels' => $labels, |
|
87 | - 'public' => true, |
|
88 | - 'publicly_queryable' => true, |
|
89 | - 'show_ui' => true, |
|
90 | - 'show_in_menu' => true, |
|
91 | - 'show_in_rest' => true, |
|
92 | - 'menu_icon' => 'dashicons-universal-access', |
|
93 | - 'query_var' => true, |
|
94 | - 'rewrite' => array( |
|
95 | - 'slug' => \lsx_health_plan\functions\get_option( 'endpoint_workout', 'workout' ), |
|
96 | - ), |
|
97 | - 'capability_type' => 'page', |
|
98 | - 'has_archive' => \lsx_health_plan\functions\get_option( 'endpoint_workout_archive', 'workouts' ), |
|
99 | - 'hierarchical' => true, |
|
100 | - 'menu_position' => null, |
|
101 | - 'supports' => array( |
|
102 | - 'title', |
|
103 | - 'thumbnail', |
|
104 | - 'editor', |
|
105 | - 'excerpt', |
|
106 | - 'page-attributes', |
|
107 | - 'custom-fields', |
|
108 | - ), |
|
109 | - ); |
|
110 | - register_post_type( 'workout', $args ); |
|
111 | - } |
|
112 | - |
|
113 | - /** |
|
114 | - * Register the Type taxonomy. |
|
115 | - */ |
|
116 | - public function workout_type_taxonomy_setup() { |
|
117 | - $labels = array( |
|
118 | - 'name' => esc_html_x( 'Workout Type', 'taxonomy general name', 'lsx-health-plan' ), |
|
119 | - 'singular_name' => esc_html_x( 'Workout Type', 'taxonomy singular name', 'lsx-health-plan' ), |
|
120 | - 'search_items' => esc_html__( 'Search', 'lsx-health-plan' ), |
|
121 | - 'all_items' => esc_html__( 'All', 'lsx-health-plan' ), |
|
122 | - 'parent_item' => esc_html__( 'Parent', 'lsx-health-plan' ), |
|
123 | - 'parent_item_colon' => esc_html__( 'Parent:', 'lsx-health-plan' ), |
|
124 | - 'edit_item' => esc_html__( 'Edit', 'lsx-health-plan' ), |
|
125 | - 'update_item' => esc_html__( 'Update', 'lsx-health-plan' ), |
|
126 | - 'add_new_item' => esc_html__( 'Add New', 'lsx-health-plan' ), |
|
127 | - 'new_item_name' => esc_html__( 'New Name', 'lsx-health-plan' ), |
|
128 | - 'menu_name' => esc_html__( 'Workout Types', 'lsx-health-plan' ), |
|
129 | - ); |
|
130 | - |
|
131 | - $args = array( |
|
132 | - 'hierarchical' => true, |
|
133 | - 'labels' => $labels, |
|
134 | - 'show_ui' => true, |
|
135 | - 'show_admin_column' => true, |
|
136 | - 'query_var' => true, |
|
137 | - 'rewrite' => array( |
|
138 | - 'slug' => 'workout-type', |
|
139 | - ), |
|
140 | - ); |
|
141 | - |
|
142 | - register_taxonomy( 'workout-type', array( 'workout' ), $args ); |
|
143 | - } |
|
144 | - |
|
145 | - /** |
|
146 | - * Adds the post type to the different arrays. |
|
147 | - * |
|
148 | - * @param array $post_types |
|
149 | - * @return array |
|
150 | - */ |
|
151 | - public function enable_post_type( $post_types = array() ) { |
|
152 | - $post_types[] = $this->slug; |
|
153 | - return $post_types; |
|
154 | - } |
|
155 | - |
|
156 | - /** |
|
157 | - * Enables the Bi Directional relationships |
|
158 | - * |
|
159 | - * @param array $connections |
|
160 | - * @return void |
|
161 | - */ |
|
162 | - public function enable_connections( $connections = array() ) { |
|
163 | - $connections['workout']['connected_plans'] = 'connected_workouts'; |
|
164 | - $connections['plan']['connected_workouts'] = 'connected_plans'; |
|
165 | - |
|
166 | - $connections['workout']['connected_videos'] = 'connected_workouts'; |
|
167 | - $connections['video']['connected_workouts'] = 'connected_videos'; |
|
168 | - |
|
169 | - $connections['workout']['connected_posts'] = 'connected_workouts'; |
|
170 | - $connections['post']['connected_workouts'] = 'connected_posts'; |
|
171 | - return $connections; |
|
172 | - } |
|
173 | - |
|
174 | - /** |
|
175 | - * Remove the "Archives:" from the post type workouts. |
|
176 | - * |
|
177 | - * @param string $title the term title. |
|
178 | - * @return string |
|
179 | - */ |
|
180 | - public function get_the_archive_title( $title ) { |
|
181 | - if ( is_post_type_archive( 'workout' ) ) { |
|
182 | - $title = __( 'Workouts', 'lsx-health-plan' ); |
|
183 | - } |
|
184 | - return $title; |
|
185 | - } |
|
186 | - |
|
187 | - /** |
|
188 | - * Define the metabox and field configurations. |
|
189 | - */ |
|
190 | - public function featured_metabox() { |
|
191 | - $cmb = new_cmb2_box( |
|
192 | - array( |
|
193 | - 'id' => $this->slug . '_featured_metabox_workout', |
|
194 | - 'title' => __( 'Featured Workout', 'lsx-health-plan' ), |
|
195 | - 'object_types' => array( $this->slug ), // Post type |
|
196 | - 'context' => 'side', |
|
197 | - 'priority' => 'high', |
|
198 | - 'show_names' => true, |
|
199 | - ) |
|
200 | - ); |
|
201 | - $cmb->add_field( |
|
202 | - array( |
|
203 | - 'name' => __( 'Featured Workout', 'lsx-health-plan' ), |
|
204 | - 'desc' => __( 'Enable a featured workout' ), |
|
205 | - 'id' => $this->slug . '_featured_workout', |
|
206 | - 'type' => 'checkbox', |
|
207 | - 'show_on_cb' => 'cmb2_hide_if_no_cats', |
|
208 | - ) |
|
209 | - ); |
|
210 | - } |
|
211 | - |
|
212 | - /** |
|
213 | - * Define the metabox and field configurations. |
|
214 | - */ |
|
215 | - public function details_metaboxes() { |
|
216 | - |
|
217 | - $cmb = new_cmb2_box( array( |
|
218 | - 'id' => $this->slug . '_details_metabox', |
|
219 | - 'title' => __( 'Workout Details', 'lsx-health-plan' ), |
|
220 | - 'object_types' => array( $this->slug ), // Post type |
|
221 | - 'context' => 'normal', |
|
222 | - 'priority' => 'high', |
|
223 | - 'show_names' => true, |
|
224 | - ) ); |
|
225 | - |
|
226 | - $cmb->add_field( array( |
|
227 | - 'name' => __( 'Workout Short Description', 'lsx-health-plan' ), |
|
228 | - 'id' => $this->slug . '_short_description', |
|
229 | - 'type' => 'textarea_small', |
|
230 | - 'desc' => __( 'Add a small description for this workout (optional)', 'lsx-health-plan' ), |
|
231 | - ) ); |
|
232 | - |
|
233 | - $workout_sections = apply_filters( 'lsx_health_plan_workout_sections_amount', 6 ); |
|
234 | - if ( false !== $workout_sections && null !== $workout_sections ) { |
|
235 | - $i = 1; |
|
236 | - while ( $i <= $workout_sections ) { |
|
237 | - |
|
238 | - $cmb_group = new_cmb2_box( array( |
|
239 | - 'id' => $this->slug . '_section_' . $i . '_metabox', |
|
240 | - 'title' => esc_html__( 'Exercise Group ', 'lsx-health-plan' ) . $i, |
|
241 | - 'object_types' => array( $this->slug ), |
|
242 | - ) ); |
|
243 | - |
|
244 | - $cmb_group->add_field( array( |
|
245 | - 'name' => __( 'Title', 'lsx-health-plan' ), |
|
246 | - 'id' => $this->slug . '_section_' . $i . '_title', |
|
247 | - 'type' => 'text', |
|
248 | - 'show_on_cb' => 'cmb2_hide_if_no_cats', |
|
249 | - ) ); |
|
250 | - |
|
251 | - $cmb_group->add_field( |
|
252 | - array( |
|
253 | - 'name' => __( 'Description', 'lsx-health-plan' ), |
|
254 | - 'id' => $this->slug . '_section_' . $i . '_description', |
|
255 | - 'type' => 'wysiwyg', |
|
256 | - 'show_on_cb' => 'cmb2_hide_if_no_cats', |
|
257 | - 'options' => array( |
|
258 | - 'textarea_rows' => 5, |
|
259 | - ), |
|
260 | - ) |
|
261 | - ); |
|
262 | - |
|
263 | - /** |
|
264 | - * Repeatable Field Groups |
|
265 | - */ |
|
266 | - // $group_field_id is the field id string, so in this case: $prefix . 'demo' |
|
267 | - $group_field_id = $cmb_group->add_field( |
|
268 | - array( |
|
269 | - 'id' => $this->slug . '_section_' . $i, |
|
270 | - 'type' => 'group', |
|
271 | - 'options' => array( |
|
272 | - 'group_title' => esc_html__( 'Exercise {#}', 'lsx-health-plan' ), // {#} gets replaced by row number |
|
273 | - 'add_button' => esc_html__( 'Add New', 'lsx-health-plan' ), |
|
274 | - 'remove_button' => esc_html__( 'Delete', 'lsx-health-plan' ), |
|
275 | - 'sortable' => true, |
|
276 | - 'closed' => true, // true to have the groups closed by default |
|
277 | - ), |
|
278 | - ) |
|
279 | - ); |
|
280 | - |
|
281 | - if ( false !== \lsx_health_plan\functions\get_option( 'exercise_enabled', false ) ) { |
|
282 | - $cmb_group->add_group_field( |
|
283 | - $group_field_id, |
|
284 | - array( |
|
285 | - 'name' => __( 'Exercise related to this workout', 'lsx-health-plan' ), |
|
286 | - 'id' => 'connected_exercises', |
|
287 | - 'type' => 'post_search_ajax', |
|
288 | - // Optional : |
|
289 | - 'limit' => 1, // Limit selection to X items only (default 1) |
|
290 | - 'sortable' => true, // Allow selected items to be sortable (default false) |
|
291 | - 'query_args' => array( |
|
292 | - 'post_type' => array( 'exercise' ), |
|
293 | - 'post_status' => array( 'publish' ), |
|
294 | - 'posts_per_page' => -1, |
|
295 | - ), |
|
296 | - ) |
|
297 | - ); |
|
298 | - } else { |
|
299 | - $cmb_group->add_group_field( |
|
300 | - $group_field_id, |
|
301 | - array( |
|
302 | - 'name' => __( 'Video related to this workout', 'lsx-health-plan' ), |
|
303 | - 'id' => 'connected_videos', |
|
304 | - 'type' => 'post_search_ajax', |
|
305 | - // Optional : |
|
306 | - 'limit' => 1, // Limit selection to X items only (default 1) |
|
307 | - 'sortable' => true, // Allow selected items to be sortable (default false) |
|
308 | - 'query_args' => array( |
|
309 | - 'post_type' => array( 'video' ), |
|
310 | - 'post_status' => array( 'publish' ), |
|
311 | - 'posts_per_page' => -1, |
|
312 | - ), |
|
313 | - ) |
|
314 | - ); |
|
315 | - $cmb_group->add_group_field( |
|
316 | - $group_field_id, |
|
317 | - array( |
|
318 | - 'name' => esc_html__( 'Workout Name', 'lsx-health-plan' ), |
|
319 | - 'id' => 'name', |
|
320 | - 'type' => 'text', |
|
321 | - // 'repeatable' => true, // Repeatable fields are supported w/in repeatable groups (for most types) |
|
322 | - ) |
|
323 | - ); |
|
324 | - |
|
325 | - $cmb_group->add_group_field( |
|
326 | - $group_field_id, |
|
327 | - array( |
|
328 | - 'name' => __( 'Description', 'lsx-health-plan' ), |
|
329 | - 'id' => 'description', |
|
330 | - 'type' => 'wysiwyg', |
|
331 | - 'options' => array( |
|
332 | - 'textarea_rows' => 2, |
|
333 | - ), |
|
334 | - ) |
|
335 | - ); |
|
336 | - } |
|
337 | - |
|
338 | - $cmb_group->add_group_field( |
|
339 | - $group_field_id, |
|
340 | - array( |
|
341 | - 'name' => esc_html__( 'Exercise title (Optional)', 'lsx-health-plan' ), |
|
342 | - 'id' => 'alt_title', |
|
343 | - 'type' => 'text', |
|
344 | - ) |
|
345 | - ); |
|
346 | - $cmb_group->add_group_field( |
|
347 | - $group_field_id, |
|
348 | - array( |
|
349 | - 'name' => esc_html__( 'Exercise Description (Optional)', 'lsx-health-plan' ), |
|
350 | - 'id' => 'alt_description', |
|
351 | - 'type' => 'textarea_small', |
|
352 | - ) |
|
353 | - ); |
|
354 | - $cmb_group->add_group_field( |
|
355 | - $group_field_id, |
|
356 | - array( |
|
357 | - 'name' => esc_html__( 'Reps / Time / Distance', 'lsx-health-plan' ), |
|
358 | - 'id' => 'reps', |
|
359 | - 'type' => 'text', |
|
360 | - // 'repeatable' => true, // Repeatable fields are supported w/in repeatable groups (for most types) |
|
361 | - ) |
|
362 | - ); |
|
363 | - $cmb_group->add_group_field( |
|
364 | - $group_field_id, |
|
365 | - array( |
|
366 | - 'name' => __( 'Exercise Image (Optional)', 'lsx-health-plan' ), |
|
367 | - 'id' => 'exercise_alt_thumbnail', |
|
368 | - 'type' => 'file', |
|
369 | - 'text' => array( |
|
370 | - 'add_upload_file_text' => __( 'Add File', 'lsx-health-plan' ), |
|
371 | - ), |
|
372 | - 'desc' => __( 'Upload an image 300px x 300px in size.', 'lsx-health-plan' ), |
|
373 | - 'query_args' => array( |
|
374 | - 'type' => array( |
|
375 | - 'image/gif', |
|
376 | - 'image/jpeg', |
|
377 | - 'image/png', |
|
378 | - ), |
|
379 | - ), |
|
380 | - 'preview_size' => 'thumbnail', |
|
381 | - 'classes' => 'lsx-field-col lsx-field-add-field lsx-field-col-25', |
|
382 | - ) |
|
383 | - ); |
|
384 | - |
|
385 | - $i++; |
|
386 | - }; |
|
387 | - } |
|
388 | - } |
|
389 | - /** |
|
390 | - * Set the post type archive to show the parent plans only. |
|
391 | - * |
|
392 | - * @param object $wp_query |
|
393 | - * @return array |
|
394 | - */ |
|
395 | - public function set_parent_only( $wp_query ) { |
|
396 | - if ( ! is_admin() && $wp_query->is_main_query() && ( $wp_query->is_post_type_archive( 'workout' ) || $wp_query->is_tax( array( 'workout-type' ) ) ) ) { |
|
397 | - $wp_query->set( 'post_parent', '0' ); |
|
398 | - } |
|
399 | - } |
|
400 | - |
|
401 | - /** |
|
402 | - * Holds the array for the single workout breadcrumbs. |
|
403 | - * |
|
404 | - * @var array $crumbs |
|
405 | - * @return array |
|
406 | - */ |
|
407 | - public function workout_breadcrumb_filter( $crumbs ) { |
|
408 | - $workout = \lsx_health_plan\functions\get_option( 'endpoint_workout', 'workout' ); |
|
409 | - $workouts = \lsx_health_plan\functions\get_option( 'endpoint_workout_archive', 'workout' ); |
|
410 | - |
|
411 | - if ( is_singular( 'workout' ) ) { |
|
412 | - $workout_name = get_the_title(); |
|
413 | - $url = get_post_type_archive_link( $workout ); |
|
414 | - $term_obj_list = get_the_terms( get_the_ID(), 'workout-type' ); |
|
415 | - $workout_type = $term_obj_list[0]->name; |
|
416 | - if ( empty( $workout_type ) ) { |
|
417 | - $workout_type = __( 'Workout', 'lsx-health-plan' ); |
|
418 | - } |
|
419 | - $workout_type_url = get_term_link( $term_obj_list[0]->term_id ); |
|
420 | - |
|
421 | - $new_crumbs = array(); |
|
422 | - $new_crumbs[0] = $crumbs[0]; |
|
423 | - |
|
424 | - if ( function_exists( 'woocommerce_breadcrumb' ) ) { |
|
425 | - $new_crumbs[1] = array( |
|
426 | - 0 => $workouts, |
|
427 | - 1 => $url, |
|
428 | - ); |
|
429 | - $new_crumbs[2] = array( |
|
430 | - 0 => $workout_type, |
|
431 | - 1 => $workout_type_url, |
|
432 | - ); |
|
433 | - $new_crumbs[3] = array( |
|
434 | - 0 => $workout_name, |
|
435 | - ); |
|
436 | - } else { |
|
437 | - $new_crumbs[1] = array( |
|
438 | - 'text' => $workouts, |
|
439 | - 'url' => $url, |
|
440 | - ); |
|
441 | - $new_crumbs[2] = array( |
|
442 | - 'text' => $workout_type, |
|
443 | - 'url' => $workout_type_url, |
|
444 | - ); |
|
445 | - $new_crumbs[3] = array( |
|
446 | - 'text' => $workout_name, |
|
447 | - ); |
|
448 | - } |
|
449 | - $crumbs = $new_crumbs; |
|
450 | - |
|
451 | - } |
|
452 | - if ( is_post_type_archive( 'workout' ) ) { |
|
453 | - |
|
454 | - $new_crumbs = array(); |
|
455 | - $new_crumbs[0] = $crumbs[0]; |
|
456 | - |
|
457 | - if ( function_exists( 'woocommerce_breadcrumb' ) ) { |
|
458 | - $new_crumbs[1] = array( |
|
459 | - 0 => $workouts, |
|
460 | - ); |
|
461 | - } else { |
|
462 | - $new_crumbs[1] = array( |
|
463 | - 'text' => $workouts, |
|
464 | - ); |
|
465 | - } |
|
466 | - $crumbs = $new_crumbs; |
|
467 | - } |
|
468 | - return $crumbs; |
|
469 | - } |
|
13 | + /** |
|
14 | + * Holds class instance |
|
15 | + * |
|
16 | + * @since 1.0.0 |
|
17 | + * |
|
18 | + * @var object \lsx_health_plan\classes\Workout() |
|
19 | + */ |
|
20 | + protected static $instance = null; |
|
21 | + |
|
22 | + /** |
|
23 | + * Holds post_type slug used as an index |
|
24 | + * |
|
25 | + * @since 1.0.0 |
|
26 | + * |
|
27 | + * @var string |
|
28 | + */ |
|
29 | + public $slug = 'workout'; |
|
30 | + |
|
31 | + /** |
|
32 | + * Constructor |
|
33 | + */ |
|
34 | + public function __construct() { |
|
35 | + add_action( 'init', array( $this, 'register_post_type' ) ); |
|
36 | + add_filter( 'lsx_health_plan_single_template', array( $this, 'enable_post_type' ), 10, 1 ); |
|
37 | + add_action( 'init', array( $this, 'workout_type_taxonomy_setup' ) ); |
|
38 | + add_filter( 'lsx_health_plan_connections', array( $this, 'enable_connections' ), 10, 1 ); |
|
39 | + add_action( 'cmb2_admin_init', array( $this, 'featured_metabox' ), 5 ); |
|
40 | + add_action( 'cmb2_admin_init', array( $this, 'details_metaboxes' ) ); |
|
41 | + add_filter( 'get_the_archive_title', array( $this, 'get_the_archive_title' ), 100 ); |
|
42 | + |
|
43 | + // Template Redirects. |
|
44 | + add_action( 'pre_get_posts', array( $this, 'set_parent_only' ), 10, 1 ); |
|
45 | + add_filter( 'lsx_health_plan_archive_template', array( $this, 'enable_post_type' ), 10, 1 ); |
|
46 | + |
|
47 | + //Breadcrumbs |
|
48 | + add_filter( 'wpseo_breadcrumb_links', array( $this, 'workout_breadcrumb_filter' ), 30, 1 ); |
|
49 | + add_filter( 'woocommerce_get_breadcrumb', array( $this, 'workout_breadcrumb_filter' ), 30, 1 ); |
|
50 | + } |
|
51 | + |
|
52 | + /** |
|
53 | + * Return an instance of this class. |
|
54 | + * |
|
55 | + * @since 1.0.0 |
|
56 | + * |
|
57 | + * @return object \lsx_health_plan\classes\Workout() A single instance of this class. |
|
58 | + */ |
|
59 | + public static function get_instance() { |
|
60 | + // If the single instance hasn't been set, set it now. |
|
61 | + if ( null === self::$instance ) { |
|
62 | + self::$instance = new self(); |
|
63 | + } |
|
64 | + return self::$instance; |
|
65 | + } |
|
66 | + /** |
|
67 | + * Register the post type. |
|
68 | + */ |
|
69 | + public function register_post_type() { |
|
70 | + $labels = array( |
|
71 | + 'name' => esc_html__( 'Workouts', 'lsx-health-plan' ), |
|
72 | + 'singular_name' => esc_html__( 'Workout', 'lsx-health-plan' ), |
|
73 | + 'add_new' => esc_html_x( 'Add New', 'post type general name', 'lsx-health-plan' ), |
|
74 | + 'add_new_item' => esc_html__( 'Add New', 'lsx-health-plan' ), |
|
75 | + 'edit_item' => esc_html__( 'Edit', 'lsx-health-plan' ), |
|
76 | + 'new_item' => esc_html__( 'New', 'lsx-health-plan' ), |
|
77 | + 'all_items' => esc_html__( 'All Workouts', 'lsx-health-plan' ), |
|
78 | + 'view_item' => esc_html__( 'View', 'lsx-health-plan' ), |
|
79 | + 'search_items' => esc_html__( 'Search', 'lsx-health-plan' ), |
|
80 | + 'not_found' => esc_html__( 'None found', 'lsx-health-plan' ), |
|
81 | + 'not_found_in_trash' => esc_html__( 'None found in Trash', 'lsx-health-plan' ), |
|
82 | + 'parent_item_colon' => esc_html__( 'Parent:', 'lsx-health-plan' ), |
|
83 | + 'menu_name' => esc_html__( 'Workouts', 'lsx-health-plan' ), |
|
84 | + ); |
|
85 | + $args = array( |
|
86 | + 'labels' => $labels, |
|
87 | + 'public' => true, |
|
88 | + 'publicly_queryable' => true, |
|
89 | + 'show_ui' => true, |
|
90 | + 'show_in_menu' => true, |
|
91 | + 'show_in_rest' => true, |
|
92 | + 'menu_icon' => 'dashicons-universal-access', |
|
93 | + 'query_var' => true, |
|
94 | + 'rewrite' => array( |
|
95 | + 'slug' => \lsx_health_plan\functions\get_option( 'endpoint_workout', 'workout' ), |
|
96 | + ), |
|
97 | + 'capability_type' => 'page', |
|
98 | + 'has_archive' => \lsx_health_plan\functions\get_option( 'endpoint_workout_archive', 'workouts' ), |
|
99 | + 'hierarchical' => true, |
|
100 | + 'menu_position' => null, |
|
101 | + 'supports' => array( |
|
102 | + 'title', |
|
103 | + 'thumbnail', |
|
104 | + 'editor', |
|
105 | + 'excerpt', |
|
106 | + 'page-attributes', |
|
107 | + 'custom-fields', |
|
108 | + ), |
|
109 | + ); |
|
110 | + register_post_type( 'workout', $args ); |
|
111 | + } |
|
112 | + |
|
113 | + /** |
|
114 | + * Register the Type taxonomy. |
|
115 | + */ |
|
116 | + public function workout_type_taxonomy_setup() { |
|
117 | + $labels = array( |
|
118 | + 'name' => esc_html_x( 'Workout Type', 'taxonomy general name', 'lsx-health-plan' ), |
|
119 | + 'singular_name' => esc_html_x( 'Workout Type', 'taxonomy singular name', 'lsx-health-plan' ), |
|
120 | + 'search_items' => esc_html__( 'Search', 'lsx-health-plan' ), |
|
121 | + 'all_items' => esc_html__( 'All', 'lsx-health-plan' ), |
|
122 | + 'parent_item' => esc_html__( 'Parent', 'lsx-health-plan' ), |
|
123 | + 'parent_item_colon' => esc_html__( 'Parent:', 'lsx-health-plan' ), |
|
124 | + 'edit_item' => esc_html__( 'Edit', 'lsx-health-plan' ), |
|
125 | + 'update_item' => esc_html__( 'Update', 'lsx-health-plan' ), |
|
126 | + 'add_new_item' => esc_html__( 'Add New', 'lsx-health-plan' ), |
|
127 | + 'new_item_name' => esc_html__( 'New Name', 'lsx-health-plan' ), |
|
128 | + 'menu_name' => esc_html__( 'Workout Types', 'lsx-health-plan' ), |
|
129 | + ); |
|
130 | + |
|
131 | + $args = array( |
|
132 | + 'hierarchical' => true, |
|
133 | + 'labels' => $labels, |
|
134 | + 'show_ui' => true, |
|
135 | + 'show_admin_column' => true, |
|
136 | + 'query_var' => true, |
|
137 | + 'rewrite' => array( |
|
138 | + 'slug' => 'workout-type', |
|
139 | + ), |
|
140 | + ); |
|
141 | + |
|
142 | + register_taxonomy( 'workout-type', array( 'workout' ), $args ); |
|
143 | + } |
|
144 | + |
|
145 | + /** |
|
146 | + * Adds the post type to the different arrays. |
|
147 | + * |
|
148 | + * @param array $post_types |
|
149 | + * @return array |
|
150 | + */ |
|
151 | + public function enable_post_type( $post_types = array() ) { |
|
152 | + $post_types[] = $this->slug; |
|
153 | + return $post_types; |
|
154 | + } |
|
155 | + |
|
156 | + /** |
|
157 | + * Enables the Bi Directional relationships |
|
158 | + * |
|
159 | + * @param array $connections |
|
160 | + * @return void |
|
161 | + */ |
|
162 | + public function enable_connections( $connections = array() ) { |
|
163 | + $connections['workout']['connected_plans'] = 'connected_workouts'; |
|
164 | + $connections['plan']['connected_workouts'] = 'connected_plans'; |
|
165 | + |
|
166 | + $connections['workout']['connected_videos'] = 'connected_workouts'; |
|
167 | + $connections['video']['connected_workouts'] = 'connected_videos'; |
|
168 | + |
|
169 | + $connections['workout']['connected_posts'] = 'connected_workouts'; |
|
170 | + $connections['post']['connected_workouts'] = 'connected_posts'; |
|
171 | + return $connections; |
|
172 | + } |
|
173 | + |
|
174 | + /** |
|
175 | + * Remove the "Archives:" from the post type workouts. |
|
176 | + * |
|
177 | + * @param string $title the term title. |
|
178 | + * @return string |
|
179 | + */ |
|
180 | + public function get_the_archive_title( $title ) { |
|
181 | + if ( is_post_type_archive( 'workout' ) ) { |
|
182 | + $title = __( 'Workouts', 'lsx-health-plan' ); |
|
183 | + } |
|
184 | + return $title; |
|
185 | + } |
|
186 | + |
|
187 | + /** |
|
188 | + * Define the metabox and field configurations. |
|
189 | + */ |
|
190 | + public function featured_metabox() { |
|
191 | + $cmb = new_cmb2_box( |
|
192 | + array( |
|
193 | + 'id' => $this->slug . '_featured_metabox_workout', |
|
194 | + 'title' => __( 'Featured Workout', 'lsx-health-plan' ), |
|
195 | + 'object_types' => array( $this->slug ), // Post type |
|
196 | + 'context' => 'side', |
|
197 | + 'priority' => 'high', |
|
198 | + 'show_names' => true, |
|
199 | + ) |
|
200 | + ); |
|
201 | + $cmb->add_field( |
|
202 | + array( |
|
203 | + 'name' => __( 'Featured Workout', 'lsx-health-plan' ), |
|
204 | + 'desc' => __( 'Enable a featured workout' ), |
|
205 | + 'id' => $this->slug . '_featured_workout', |
|
206 | + 'type' => 'checkbox', |
|
207 | + 'show_on_cb' => 'cmb2_hide_if_no_cats', |
|
208 | + ) |
|
209 | + ); |
|
210 | + } |
|
211 | + |
|
212 | + /** |
|
213 | + * Define the metabox and field configurations. |
|
214 | + */ |
|
215 | + public function details_metaboxes() { |
|
216 | + |
|
217 | + $cmb = new_cmb2_box( array( |
|
218 | + 'id' => $this->slug . '_details_metabox', |
|
219 | + 'title' => __( 'Workout Details', 'lsx-health-plan' ), |
|
220 | + 'object_types' => array( $this->slug ), // Post type |
|
221 | + 'context' => 'normal', |
|
222 | + 'priority' => 'high', |
|
223 | + 'show_names' => true, |
|
224 | + ) ); |
|
225 | + |
|
226 | + $cmb->add_field( array( |
|
227 | + 'name' => __( 'Workout Short Description', 'lsx-health-plan' ), |
|
228 | + 'id' => $this->slug . '_short_description', |
|
229 | + 'type' => 'textarea_small', |
|
230 | + 'desc' => __( 'Add a small description for this workout (optional)', 'lsx-health-plan' ), |
|
231 | + ) ); |
|
232 | + |
|
233 | + $workout_sections = apply_filters( 'lsx_health_plan_workout_sections_amount', 6 ); |
|
234 | + if ( false !== $workout_sections && null !== $workout_sections ) { |
|
235 | + $i = 1; |
|
236 | + while ( $i <= $workout_sections ) { |
|
237 | + |
|
238 | + $cmb_group = new_cmb2_box( array( |
|
239 | + 'id' => $this->slug . '_section_' . $i . '_metabox', |
|
240 | + 'title' => esc_html__( 'Exercise Group ', 'lsx-health-plan' ) . $i, |
|
241 | + 'object_types' => array( $this->slug ), |
|
242 | + ) ); |
|
243 | + |
|
244 | + $cmb_group->add_field( array( |
|
245 | + 'name' => __( 'Title', 'lsx-health-plan' ), |
|
246 | + 'id' => $this->slug . '_section_' . $i . '_title', |
|
247 | + 'type' => 'text', |
|
248 | + 'show_on_cb' => 'cmb2_hide_if_no_cats', |
|
249 | + ) ); |
|
250 | + |
|
251 | + $cmb_group->add_field( |
|
252 | + array( |
|
253 | + 'name' => __( 'Description', 'lsx-health-plan' ), |
|
254 | + 'id' => $this->slug . '_section_' . $i . '_description', |
|
255 | + 'type' => 'wysiwyg', |
|
256 | + 'show_on_cb' => 'cmb2_hide_if_no_cats', |
|
257 | + 'options' => array( |
|
258 | + 'textarea_rows' => 5, |
|
259 | + ), |
|
260 | + ) |
|
261 | + ); |
|
262 | + |
|
263 | + /** |
|
264 | + * Repeatable Field Groups |
|
265 | + */ |
|
266 | + // $group_field_id is the field id string, so in this case: $prefix . 'demo' |
|
267 | + $group_field_id = $cmb_group->add_field( |
|
268 | + array( |
|
269 | + 'id' => $this->slug . '_section_' . $i, |
|
270 | + 'type' => 'group', |
|
271 | + 'options' => array( |
|
272 | + 'group_title' => esc_html__( 'Exercise {#}', 'lsx-health-plan' ), // {#} gets replaced by row number |
|
273 | + 'add_button' => esc_html__( 'Add New', 'lsx-health-plan' ), |
|
274 | + 'remove_button' => esc_html__( 'Delete', 'lsx-health-plan' ), |
|
275 | + 'sortable' => true, |
|
276 | + 'closed' => true, // true to have the groups closed by default |
|
277 | + ), |
|
278 | + ) |
|
279 | + ); |
|
280 | + |
|
281 | + if ( false !== \lsx_health_plan\functions\get_option( 'exercise_enabled', false ) ) { |
|
282 | + $cmb_group->add_group_field( |
|
283 | + $group_field_id, |
|
284 | + array( |
|
285 | + 'name' => __( 'Exercise related to this workout', 'lsx-health-plan' ), |
|
286 | + 'id' => 'connected_exercises', |
|
287 | + 'type' => 'post_search_ajax', |
|
288 | + // Optional : |
|
289 | + 'limit' => 1, // Limit selection to X items only (default 1) |
|
290 | + 'sortable' => true, // Allow selected items to be sortable (default false) |
|
291 | + 'query_args' => array( |
|
292 | + 'post_type' => array( 'exercise' ), |
|
293 | + 'post_status' => array( 'publish' ), |
|
294 | + 'posts_per_page' => -1, |
|
295 | + ), |
|
296 | + ) |
|
297 | + ); |
|
298 | + } else { |
|
299 | + $cmb_group->add_group_field( |
|
300 | + $group_field_id, |
|
301 | + array( |
|
302 | + 'name' => __( 'Video related to this workout', 'lsx-health-plan' ), |
|
303 | + 'id' => 'connected_videos', |
|
304 | + 'type' => 'post_search_ajax', |
|
305 | + // Optional : |
|
306 | + 'limit' => 1, // Limit selection to X items only (default 1) |
|
307 | + 'sortable' => true, // Allow selected items to be sortable (default false) |
|
308 | + 'query_args' => array( |
|
309 | + 'post_type' => array( 'video' ), |
|
310 | + 'post_status' => array( 'publish' ), |
|
311 | + 'posts_per_page' => -1, |
|
312 | + ), |
|
313 | + ) |
|
314 | + ); |
|
315 | + $cmb_group->add_group_field( |
|
316 | + $group_field_id, |
|
317 | + array( |
|
318 | + 'name' => esc_html__( 'Workout Name', 'lsx-health-plan' ), |
|
319 | + 'id' => 'name', |
|
320 | + 'type' => 'text', |
|
321 | + // 'repeatable' => true, // Repeatable fields are supported w/in repeatable groups (for most types) |
|
322 | + ) |
|
323 | + ); |
|
324 | + |
|
325 | + $cmb_group->add_group_field( |
|
326 | + $group_field_id, |
|
327 | + array( |
|
328 | + 'name' => __( 'Description', 'lsx-health-plan' ), |
|
329 | + 'id' => 'description', |
|
330 | + 'type' => 'wysiwyg', |
|
331 | + 'options' => array( |
|
332 | + 'textarea_rows' => 2, |
|
333 | + ), |
|
334 | + ) |
|
335 | + ); |
|
336 | + } |
|
337 | + |
|
338 | + $cmb_group->add_group_field( |
|
339 | + $group_field_id, |
|
340 | + array( |
|
341 | + 'name' => esc_html__( 'Exercise title (Optional)', 'lsx-health-plan' ), |
|
342 | + 'id' => 'alt_title', |
|
343 | + 'type' => 'text', |
|
344 | + ) |
|
345 | + ); |
|
346 | + $cmb_group->add_group_field( |
|
347 | + $group_field_id, |
|
348 | + array( |
|
349 | + 'name' => esc_html__( 'Exercise Description (Optional)', 'lsx-health-plan' ), |
|
350 | + 'id' => 'alt_description', |
|
351 | + 'type' => 'textarea_small', |
|
352 | + ) |
|
353 | + ); |
|
354 | + $cmb_group->add_group_field( |
|
355 | + $group_field_id, |
|
356 | + array( |
|
357 | + 'name' => esc_html__( 'Reps / Time / Distance', 'lsx-health-plan' ), |
|
358 | + 'id' => 'reps', |
|
359 | + 'type' => 'text', |
|
360 | + // 'repeatable' => true, // Repeatable fields are supported w/in repeatable groups (for most types) |
|
361 | + ) |
|
362 | + ); |
|
363 | + $cmb_group->add_group_field( |
|
364 | + $group_field_id, |
|
365 | + array( |
|
366 | + 'name' => __( 'Exercise Image (Optional)', 'lsx-health-plan' ), |
|
367 | + 'id' => 'exercise_alt_thumbnail', |
|
368 | + 'type' => 'file', |
|
369 | + 'text' => array( |
|
370 | + 'add_upload_file_text' => __( 'Add File', 'lsx-health-plan' ), |
|
371 | + ), |
|
372 | + 'desc' => __( 'Upload an image 300px x 300px in size.', 'lsx-health-plan' ), |
|
373 | + 'query_args' => array( |
|
374 | + 'type' => array( |
|
375 | + 'image/gif', |
|
376 | + 'image/jpeg', |
|
377 | + 'image/png', |
|
378 | + ), |
|
379 | + ), |
|
380 | + 'preview_size' => 'thumbnail', |
|
381 | + 'classes' => 'lsx-field-col lsx-field-add-field lsx-field-col-25', |
|
382 | + ) |
|
383 | + ); |
|
384 | + |
|
385 | + $i++; |
|
386 | + }; |
|
387 | + } |
|
388 | + } |
|
389 | + /** |
|
390 | + * Set the post type archive to show the parent plans only. |
|
391 | + * |
|
392 | + * @param object $wp_query |
|
393 | + * @return array |
|
394 | + */ |
|
395 | + public function set_parent_only( $wp_query ) { |
|
396 | + if ( ! is_admin() && $wp_query->is_main_query() && ( $wp_query->is_post_type_archive( 'workout' ) || $wp_query->is_tax( array( 'workout-type' ) ) ) ) { |
|
397 | + $wp_query->set( 'post_parent', '0' ); |
|
398 | + } |
|
399 | + } |
|
400 | + |
|
401 | + /** |
|
402 | + * Holds the array for the single workout breadcrumbs. |
|
403 | + * |
|
404 | + * @var array $crumbs |
|
405 | + * @return array |
|
406 | + */ |
|
407 | + public function workout_breadcrumb_filter( $crumbs ) { |
|
408 | + $workout = \lsx_health_plan\functions\get_option( 'endpoint_workout', 'workout' ); |
|
409 | + $workouts = \lsx_health_plan\functions\get_option( 'endpoint_workout_archive', 'workout' ); |
|
410 | + |
|
411 | + if ( is_singular( 'workout' ) ) { |
|
412 | + $workout_name = get_the_title(); |
|
413 | + $url = get_post_type_archive_link( $workout ); |
|
414 | + $term_obj_list = get_the_terms( get_the_ID(), 'workout-type' ); |
|
415 | + $workout_type = $term_obj_list[0]->name; |
|
416 | + if ( empty( $workout_type ) ) { |
|
417 | + $workout_type = __( 'Workout', 'lsx-health-plan' ); |
|
418 | + } |
|
419 | + $workout_type_url = get_term_link( $term_obj_list[0]->term_id ); |
|
420 | + |
|
421 | + $new_crumbs = array(); |
|
422 | + $new_crumbs[0] = $crumbs[0]; |
|
423 | + |
|
424 | + if ( function_exists( 'woocommerce_breadcrumb' ) ) { |
|
425 | + $new_crumbs[1] = array( |
|
426 | + 0 => $workouts, |
|
427 | + 1 => $url, |
|
428 | + ); |
|
429 | + $new_crumbs[2] = array( |
|
430 | + 0 => $workout_type, |
|
431 | + 1 => $workout_type_url, |
|
432 | + ); |
|
433 | + $new_crumbs[3] = array( |
|
434 | + 0 => $workout_name, |
|
435 | + ); |
|
436 | + } else { |
|
437 | + $new_crumbs[1] = array( |
|
438 | + 'text' => $workouts, |
|
439 | + 'url' => $url, |
|
440 | + ); |
|
441 | + $new_crumbs[2] = array( |
|
442 | + 'text' => $workout_type, |
|
443 | + 'url' => $workout_type_url, |
|
444 | + ); |
|
445 | + $new_crumbs[3] = array( |
|
446 | + 'text' => $workout_name, |
|
447 | + ); |
|
448 | + } |
|
449 | + $crumbs = $new_crumbs; |
|
450 | + |
|
451 | + } |
|
452 | + if ( is_post_type_archive( 'workout' ) ) { |
|
453 | + |
|
454 | + $new_crumbs = array(); |
|
455 | + $new_crumbs[0] = $crumbs[0]; |
|
456 | + |
|
457 | + if ( function_exists( 'woocommerce_breadcrumb' ) ) { |
|
458 | + $new_crumbs[1] = array( |
|
459 | + 0 => $workouts, |
|
460 | + ); |
|
461 | + } else { |
|
462 | + $new_crumbs[1] = array( |
|
463 | + 'text' => $workouts, |
|
464 | + ); |
|
465 | + } |
|
466 | + $crumbs = $new_crumbs; |
|
467 | + } |
|
468 | + return $crumbs; |
|
469 | + } |
|
470 | 470 | } |
@@ -32,21 +32,21 @@ discard block |
||
32 | 32 | * Constructor |
33 | 33 | */ |
34 | 34 | public function __construct() { |
35 | - add_action( 'init', array( $this, 'register_post_type' ) ); |
|
36 | - add_filter( 'lsx_health_plan_single_template', array( $this, 'enable_post_type' ), 10, 1 ); |
|
37 | - add_action( 'init', array( $this, 'workout_type_taxonomy_setup' ) ); |
|
38 | - add_filter( 'lsx_health_plan_connections', array( $this, 'enable_connections' ), 10, 1 ); |
|
39 | - add_action( 'cmb2_admin_init', array( $this, 'featured_metabox' ), 5 ); |
|
40 | - add_action( 'cmb2_admin_init', array( $this, 'details_metaboxes' ) ); |
|
41 | - add_filter( 'get_the_archive_title', array( $this, 'get_the_archive_title' ), 100 ); |
|
35 | + add_action('init', array($this, 'register_post_type')); |
|
36 | + add_filter('lsx_health_plan_single_template', array($this, 'enable_post_type'), 10, 1); |
|
37 | + add_action('init', array($this, 'workout_type_taxonomy_setup')); |
|
38 | + add_filter('lsx_health_plan_connections', array($this, 'enable_connections'), 10, 1); |
|
39 | + add_action('cmb2_admin_init', array($this, 'featured_metabox'), 5); |
|
40 | + add_action('cmb2_admin_init', array($this, 'details_metaboxes')); |
|
41 | + add_filter('get_the_archive_title', array($this, 'get_the_archive_title'), 100); |
|
42 | 42 | |
43 | 43 | // Template Redirects. |
44 | - add_action( 'pre_get_posts', array( $this, 'set_parent_only' ), 10, 1 ); |
|
45 | - add_filter( 'lsx_health_plan_archive_template', array( $this, 'enable_post_type' ), 10, 1 ); |
|
44 | + add_action('pre_get_posts', array($this, 'set_parent_only'), 10, 1); |
|
45 | + add_filter('lsx_health_plan_archive_template', array($this, 'enable_post_type'), 10, 1); |
|
46 | 46 | |
47 | 47 | //Breadcrumbs |
48 | - add_filter( 'wpseo_breadcrumb_links', array( $this, 'workout_breadcrumb_filter' ), 30, 1 ); |
|
49 | - add_filter( 'woocommerce_get_breadcrumb', array( $this, 'workout_breadcrumb_filter' ), 30, 1 ); |
|
48 | + add_filter('wpseo_breadcrumb_links', array($this, 'workout_breadcrumb_filter'), 30, 1); |
|
49 | + add_filter('woocommerce_get_breadcrumb', array($this, 'workout_breadcrumb_filter'), 30, 1); |
|
50 | 50 | } |
51 | 51 | |
52 | 52 | /** |
@@ -58,7 +58,7 @@ discard block |
||
58 | 58 | */ |
59 | 59 | public static function get_instance() { |
60 | 60 | // If the single instance hasn't been set, set it now. |
61 | - if ( null === self::$instance ) { |
|
61 | + if (null === self::$instance) { |
|
62 | 62 | self::$instance = new self(); |
63 | 63 | } |
64 | 64 | return self::$instance; |
@@ -68,19 +68,19 @@ discard block |
||
68 | 68 | */ |
69 | 69 | public function register_post_type() { |
70 | 70 | $labels = array( |
71 | - 'name' => esc_html__( 'Workouts', 'lsx-health-plan' ), |
|
72 | - 'singular_name' => esc_html__( 'Workout', 'lsx-health-plan' ), |
|
73 | - 'add_new' => esc_html_x( 'Add New', 'post type general name', 'lsx-health-plan' ), |
|
74 | - 'add_new_item' => esc_html__( 'Add New', 'lsx-health-plan' ), |
|
75 | - 'edit_item' => esc_html__( 'Edit', 'lsx-health-plan' ), |
|
76 | - 'new_item' => esc_html__( 'New', 'lsx-health-plan' ), |
|
77 | - 'all_items' => esc_html__( 'All Workouts', 'lsx-health-plan' ), |
|
78 | - 'view_item' => esc_html__( 'View', 'lsx-health-plan' ), |
|
79 | - 'search_items' => esc_html__( 'Search', 'lsx-health-plan' ), |
|
80 | - 'not_found' => esc_html__( 'None found', 'lsx-health-plan' ), |
|
81 | - 'not_found_in_trash' => esc_html__( 'None found in Trash', 'lsx-health-plan' ), |
|
82 | - 'parent_item_colon' => esc_html__( 'Parent:', 'lsx-health-plan' ), |
|
83 | - 'menu_name' => esc_html__( 'Workouts', 'lsx-health-plan' ), |
|
71 | + 'name' => esc_html__('Workouts', 'lsx-health-plan'), |
|
72 | + 'singular_name' => esc_html__('Workout', 'lsx-health-plan'), |
|
73 | + 'add_new' => esc_html_x('Add New', 'post type general name', 'lsx-health-plan'), |
|
74 | + 'add_new_item' => esc_html__('Add New', 'lsx-health-plan'), |
|
75 | + 'edit_item' => esc_html__('Edit', 'lsx-health-plan'), |
|
76 | + 'new_item' => esc_html__('New', 'lsx-health-plan'), |
|
77 | + 'all_items' => esc_html__('All Workouts', 'lsx-health-plan'), |
|
78 | + 'view_item' => esc_html__('View', 'lsx-health-plan'), |
|
79 | + 'search_items' => esc_html__('Search', 'lsx-health-plan'), |
|
80 | + 'not_found' => esc_html__('None found', 'lsx-health-plan'), |
|
81 | + 'not_found_in_trash' => esc_html__('None found in Trash', 'lsx-health-plan'), |
|
82 | + 'parent_item_colon' => esc_html__('Parent:', 'lsx-health-plan'), |
|
83 | + 'menu_name' => esc_html__('Workouts', 'lsx-health-plan'), |
|
84 | 84 | ); |
85 | 85 | $args = array( |
86 | 86 | 'labels' => $labels, |
@@ -92,10 +92,10 @@ discard block |
||
92 | 92 | 'menu_icon' => 'dashicons-universal-access', |
93 | 93 | 'query_var' => true, |
94 | 94 | 'rewrite' => array( |
95 | - 'slug' => \lsx_health_plan\functions\get_option( 'endpoint_workout', 'workout' ), |
|
95 | + 'slug' => \lsx_health_plan\functions\get_option('endpoint_workout', 'workout'), |
|
96 | 96 | ), |
97 | 97 | 'capability_type' => 'page', |
98 | - 'has_archive' => \lsx_health_plan\functions\get_option( 'endpoint_workout_archive', 'workouts' ), |
|
98 | + 'has_archive' => \lsx_health_plan\functions\get_option('endpoint_workout_archive', 'workouts'), |
|
99 | 99 | 'hierarchical' => true, |
100 | 100 | 'menu_position' => null, |
101 | 101 | 'supports' => array( |
@@ -107,7 +107,7 @@ discard block |
||
107 | 107 | 'custom-fields', |
108 | 108 | ), |
109 | 109 | ); |
110 | - register_post_type( 'workout', $args ); |
|
110 | + register_post_type('workout', $args); |
|
111 | 111 | } |
112 | 112 | |
113 | 113 | /** |
@@ -115,17 +115,17 @@ discard block |
||
115 | 115 | */ |
116 | 116 | public function workout_type_taxonomy_setup() { |
117 | 117 | $labels = array( |
118 | - 'name' => esc_html_x( 'Workout Type', 'taxonomy general name', 'lsx-health-plan' ), |
|
119 | - 'singular_name' => esc_html_x( 'Workout Type', 'taxonomy singular name', 'lsx-health-plan' ), |
|
120 | - 'search_items' => esc_html__( 'Search', 'lsx-health-plan' ), |
|
121 | - 'all_items' => esc_html__( 'All', 'lsx-health-plan' ), |
|
122 | - 'parent_item' => esc_html__( 'Parent', 'lsx-health-plan' ), |
|
123 | - 'parent_item_colon' => esc_html__( 'Parent:', 'lsx-health-plan' ), |
|
124 | - 'edit_item' => esc_html__( 'Edit', 'lsx-health-plan' ), |
|
125 | - 'update_item' => esc_html__( 'Update', 'lsx-health-plan' ), |
|
126 | - 'add_new_item' => esc_html__( 'Add New', 'lsx-health-plan' ), |
|
127 | - 'new_item_name' => esc_html__( 'New Name', 'lsx-health-plan' ), |
|
128 | - 'menu_name' => esc_html__( 'Workout Types', 'lsx-health-plan' ), |
|
118 | + 'name' => esc_html_x('Workout Type', 'taxonomy general name', 'lsx-health-plan'), |
|
119 | + 'singular_name' => esc_html_x('Workout Type', 'taxonomy singular name', 'lsx-health-plan'), |
|
120 | + 'search_items' => esc_html__('Search', 'lsx-health-plan'), |
|
121 | + 'all_items' => esc_html__('All', 'lsx-health-plan'), |
|
122 | + 'parent_item' => esc_html__('Parent', 'lsx-health-plan'), |
|
123 | + 'parent_item_colon' => esc_html__('Parent:', 'lsx-health-plan'), |
|
124 | + 'edit_item' => esc_html__('Edit', 'lsx-health-plan'), |
|
125 | + 'update_item' => esc_html__('Update', 'lsx-health-plan'), |
|
126 | + 'add_new_item' => esc_html__('Add New', 'lsx-health-plan'), |
|
127 | + 'new_item_name' => esc_html__('New Name', 'lsx-health-plan'), |
|
128 | + 'menu_name' => esc_html__('Workout Types', 'lsx-health-plan'), |
|
129 | 129 | ); |
130 | 130 | |
131 | 131 | $args = array( |
@@ -139,7 +139,7 @@ discard block |
||
139 | 139 | ), |
140 | 140 | ); |
141 | 141 | |
142 | - register_taxonomy( 'workout-type', array( 'workout' ), $args ); |
|
142 | + register_taxonomy('workout-type', array('workout'), $args); |
|
143 | 143 | } |
144 | 144 | |
145 | 145 | /** |
@@ -148,7 +148,7 @@ discard block |
||
148 | 148 | * @param array $post_types |
149 | 149 | * @return array |
150 | 150 | */ |
151 | - public function enable_post_type( $post_types = array() ) { |
|
151 | + public function enable_post_type($post_types = array()) { |
|
152 | 152 | $post_types[] = $this->slug; |
153 | 153 | return $post_types; |
154 | 154 | } |
@@ -159,7 +159,7 @@ discard block |
||
159 | 159 | * @param array $connections |
160 | 160 | * @return void |
161 | 161 | */ |
162 | - public function enable_connections( $connections = array() ) { |
|
162 | + public function enable_connections($connections = array()) { |
|
163 | 163 | $connections['workout']['connected_plans'] = 'connected_workouts'; |
164 | 164 | $connections['plan']['connected_workouts'] = 'connected_plans'; |
165 | 165 | |
@@ -177,9 +177,9 @@ discard block |
||
177 | 177 | * @param string $title the term title. |
178 | 178 | * @return string |
179 | 179 | */ |
180 | - public function get_the_archive_title( $title ) { |
|
181 | - if ( is_post_type_archive( 'workout' ) ) { |
|
182 | - $title = __( 'Workouts', 'lsx-health-plan' ); |
|
180 | + public function get_the_archive_title($title) { |
|
181 | + if (is_post_type_archive('workout')) { |
|
182 | + $title = __('Workouts', 'lsx-health-plan'); |
|
183 | 183 | } |
184 | 184 | return $title; |
185 | 185 | } |
@@ -191,8 +191,8 @@ discard block |
||
191 | 191 | $cmb = new_cmb2_box( |
192 | 192 | array( |
193 | 193 | 'id' => $this->slug . '_featured_metabox_workout', |
194 | - 'title' => __( 'Featured Workout', 'lsx-health-plan' ), |
|
195 | - 'object_types' => array( $this->slug ), // Post type |
|
194 | + 'title' => __('Featured Workout', 'lsx-health-plan'), |
|
195 | + 'object_types' => array($this->slug), // Post type |
|
196 | 196 | 'context' => 'side', |
197 | 197 | 'priority' => 'high', |
198 | 198 | 'show_names' => true, |
@@ -200,8 +200,8 @@ discard block |
||
200 | 200 | ); |
201 | 201 | $cmb->add_field( |
202 | 202 | array( |
203 | - 'name' => __( 'Featured Workout', 'lsx-health-plan' ), |
|
204 | - 'desc' => __( 'Enable a featured workout' ), |
|
203 | + 'name' => __('Featured Workout', 'lsx-health-plan'), |
|
204 | + 'desc' => __('Enable a featured workout'), |
|
205 | 205 | 'id' => $this->slug . '_featured_workout', |
206 | 206 | 'type' => 'checkbox', |
207 | 207 | 'show_on_cb' => 'cmb2_hide_if_no_cats', |
@@ -214,43 +214,43 @@ discard block |
||
214 | 214 | */ |
215 | 215 | public function details_metaboxes() { |
216 | 216 | |
217 | - $cmb = new_cmb2_box( array( |
|
217 | + $cmb = new_cmb2_box(array( |
|
218 | 218 | 'id' => $this->slug . '_details_metabox', |
219 | - 'title' => __( 'Workout Details', 'lsx-health-plan' ), |
|
220 | - 'object_types' => array( $this->slug ), // Post type |
|
219 | + 'title' => __('Workout Details', 'lsx-health-plan'), |
|
220 | + 'object_types' => array($this->slug), // Post type |
|
221 | 221 | 'context' => 'normal', |
222 | 222 | 'priority' => 'high', |
223 | 223 | 'show_names' => true, |
224 | - ) ); |
|
224 | + )); |
|
225 | 225 | |
226 | - $cmb->add_field( array( |
|
227 | - 'name' => __( 'Workout Short Description', 'lsx-health-plan' ), |
|
226 | + $cmb->add_field(array( |
|
227 | + 'name' => __('Workout Short Description', 'lsx-health-plan'), |
|
228 | 228 | 'id' => $this->slug . '_short_description', |
229 | 229 | 'type' => 'textarea_small', |
230 | - 'desc' => __( 'Add a small description for this workout (optional)', 'lsx-health-plan' ), |
|
231 | - ) ); |
|
230 | + 'desc' => __('Add a small description for this workout (optional)', 'lsx-health-plan'), |
|
231 | + )); |
|
232 | 232 | |
233 | - $workout_sections = apply_filters( 'lsx_health_plan_workout_sections_amount', 6 ); |
|
234 | - if ( false !== $workout_sections && null !== $workout_sections ) { |
|
233 | + $workout_sections = apply_filters('lsx_health_plan_workout_sections_amount', 6); |
|
234 | + if (false !== $workout_sections && null !== $workout_sections) { |
|
235 | 235 | $i = 1; |
236 | - while ( $i <= $workout_sections ) { |
|
236 | + while ($i <= $workout_sections) { |
|
237 | 237 | |
238 | - $cmb_group = new_cmb2_box( array( |
|
238 | + $cmb_group = new_cmb2_box(array( |
|
239 | 239 | 'id' => $this->slug . '_section_' . $i . '_metabox', |
240 | - 'title' => esc_html__( 'Exercise Group ', 'lsx-health-plan' ) . $i, |
|
241 | - 'object_types' => array( $this->slug ), |
|
242 | - ) ); |
|
240 | + 'title' => esc_html__('Exercise Group ', 'lsx-health-plan') . $i, |
|
241 | + 'object_types' => array($this->slug), |
|
242 | + )); |
|
243 | 243 | |
244 | - $cmb_group->add_field( array( |
|
245 | - 'name' => __( 'Title', 'lsx-health-plan' ), |
|
244 | + $cmb_group->add_field(array( |
|
245 | + 'name' => __('Title', 'lsx-health-plan'), |
|
246 | 246 | 'id' => $this->slug . '_section_' . $i . '_title', |
247 | 247 | 'type' => 'text', |
248 | 248 | 'show_on_cb' => 'cmb2_hide_if_no_cats', |
249 | - ) ); |
|
249 | + )); |
|
250 | 250 | |
251 | 251 | $cmb_group->add_field( |
252 | 252 | array( |
253 | - 'name' => __( 'Description', 'lsx-health-plan' ), |
|
253 | + 'name' => __('Description', 'lsx-health-plan'), |
|
254 | 254 | 'id' => $this->slug . '_section_' . $i . '_description', |
255 | 255 | 'type' => 'wysiwyg', |
256 | 256 | 'show_on_cb' => 'cmb2_hide_if_no_cats', |
@@ -269,28 +269,28 @@ discard block |
||
269 | 269 | 'id' => $this->slug . '_section_' . $i, |
270 | 270 | 'type' => 'group', |
271 | 271 | 'options' => array( |
272 | - 'group_title' => esc_html__( 'Exercise {#}', 'lsx-health-plan' ), // {#} gets replaced by row number |
|
273 | - 'add_button' => esc_html__( 'Add New', 'lsx-health-plan' ), |
|
274 | - 'remove_button' => esc_html__( 'Delete', 'lsx-health-plan' ), |
|
272 | + 'group_title' => esc_html__('Exercise {#}', 'lsx-health-plan'), // {#} gets replaced by row number |
|
273 | + 'add_button' => esc_html__('Add New', 'lsx-health-plan'), |
|
274 | + 'remove_button' => esc_html__('Delete', 'lsx-health-plan'), |
|
275 | 275 | 'sortable' => true, |
276 | 276 | 'closed' => true, // true to have the groups closed by default |
277 | 277 | ), |
278 | 278 | ) |
279 | 279 | ); |
280 | 280 | |
281 | - if ( false !== \lsx_health_plan\functions\get_option( 'exercise_enabled', false ) ) { |
|
281 | + if (false !== \lsx_health_plan\functions\get_option('exercise_enabled', false)) { |
|
282 | 282 | $cmb_group->add_group_field( |
283 | 283 | $group_field_id, |
284 | 284 | array( |
285 | - 'name' => __( 'Exercise related to this workout', 'lsx-health-plan' ), |
|
285 | + 'name' => __('Exercise related to this workout', 'lsx-health-plan'), |
|
286 | 286 | 'id' => 'connected_exercises', |
287 | 287 | 'type' => 'post_search_ajax', |
288 | 288 | // Optional : |
289 | 289 | 'limit' => 1, // Limit selection to X items only (default 1) |
290 | - 'sortable' => true, // Allow selected items to be sortable (default false) |
|
290 | + 'sortable' => true, // Allow selected items to be sortable (default false) |
|
291 | 291 | 'query_args' => array( |
292 | - 'post_type' => array( 'exercise' ), |
|
293 | - 'post_status' => array( 'publish' ), |
|
292 | + 'post_type' => array('exercise'), |
|
293 | + 'post_status' => array('publish'), |
|
294 | 294 | 'posts_per_page' => -1, |
295 | 295 | ), |
296 | 296 | ) |
@@ -299,15 +299,15 @@ discard block |
||
299 | 299 | $cmb_group->add_group_field( |
300 | 300 | $group_field_id, |
301 | 301 | array( |
302 | - 'name' => __( 'Video related to this workout', 'lsx-health-plan' ), |
|
302 | + 'name' => __('Video related to this workout', 'lsx-health-plan'), |
|
303 | 303 | 'id' => 'connected_videos', |
304 | 304 | 'type' => 'post_search_ajax', |
305 | 305 | // Optional : |
306 | 306 | 'limit' => 1, // Limit selection to X items only (default 1) |
307 | - 'sortable' => true, // Allow selected items to be sortable (default false) |
|
307 | + 'sortable' => true, // Allow selected items to be sortable (default false) |
|
308 | 308 | 'query_args' => array( |
309 | - 'post_type' => array( 'video' ), |
|
310 | - 'post_status' => array( 'publish' ), |
|
309 | + 'post_type' => array('video'), |
|
310 | + 'post_status' => array('publish'), |
|
311 | 311 | 'posts_per_page' => -1, |
312 | 312 | ), |
313 | 313 | ) |
@@ -315,7 +315,7 @@ discard block |
||
315 | 315 | $cmb_group->add_group_field( |
316 | 316 | $group_field_id, |
317 | 317 | array( |
318 | - 'name' => esc_html__( 'Workout Name', 'lsx-health-plan' ), |
|
318 | + 'name' => esc_html__('Workout Name', 'lsx-health-plan'), |
|
319 | 319 | 'id' => 'name', |
320 | 320 | 'type' => 'text', |
321 | 321 | // 'repeatable' => true, // Repeatable fields are supported w/in repeatable groups (for most types) |
@@ -325,7 +325,7 @@ discard block |
||
325 | 325 | $cmb_group->add_group_field( |
326 | 326 | $group_field_id, |
327 | 327 | array( |
328 | - 'name' => __( 'Description', 'lsx-health-plan' ), |
|
328 | + 'name' => __('Description', 'lsx-health-plan'), |
|
329 | 329 | 'id' => 'description', |
330 | 330 | 'type' => 'wysiwyg', |
331 | 331 | 'options' => array( |
@@ -338,7 +338,7 @@ discard block |
||
338 | 338 | $cmb_group->add_group_field( |
339 | 339 | $group_field_id, |
340 | 340 | array( |
341 | - 'name' => esc_html__( 'Exercise title (Optional)', 'lsx-health-plan' ), |
|
341 | + 'name' => esc_html__('Exercise title (Optional)', 'lsx-health-plan'), |
|
342 | 342 | 'id' => 'alt_title', |
343 | 343 | 'type' => 'text', |
344 | 344 | ) |
@@ -346,7 +346,7 @@ discard block |
||
346 | 346 | $cmb_group->add_group_field( |
347 | 347 | $group_field_id, |
348 | 348 | array( |
349 | - 'name' => esc_html__( 'Exercise Description (Optional)', 'lsx-health-plan' ), |
|
349 | + 'name' => esc_html__('Exercise Description (Optional)', 'lsx-health-plan'), |
|
350 | 350 | 'id' => 'alt_description', |
351 | 351 | 'type' => 'textarea_small', |
352 | 352 | ) |
@@ -354,7 +354,7 @@ discard block |
||
354 | 354 | $cmb_group->add_group_field( |
355 | 355 | $group_field_id, |
356 | 356 | array( |
357 | - 'name' => esc_html__( 'Reps / Time / Distance', 'lsx-health-plan' ), |
|
357 | + 'name' => esc_html__('Reps / Time / Distance', 'lsx-health-plan'), |
|
358 | 358 | 'id' => 'reps', |
359 | 359 | 'type' => 'text', |
360 | 360 | // 'repeatable' => true, // Repeatable fields are supported w/in repeatable groups (for most types) |
@@ -363,13 +363,13 @@ discard block |
||
363 | 363 | $cmb_group->add_group_field( |
364 | 364 | $group_field_id, |
365 | 365 | array( |
366 | - 'name' => __( 'Exercise Image (Optional)', 'lsx-health-plan' ), |
|
366 | + 'name' => __('Exercise Image (Optional)', 'lsx-health-plan'), |
|
367 | 367 | 'id' => 'exercise_alt_thumbnail', |
368 | 368 | 'type' => 'file', |
369 | 369 | 'text' => array( |
370 | - 'add_upload_file_text' => __( 'Add File', 'lsx-health-plan' ), |
|
370 | + 'add_upload_file_text' => __('Add File', 'lsx-health-plan'), |
|
371 | 371 | ), |
372 | - 'desc' => __( 'Upload an image 300px x 300px in size.', 'lsx-health-plan' ), |
|
372 | + 'desc' => __('Upload an image 300px x 300px in size.', 'lsx-health-plan'), |
|
373 | 373 | 'query_args' => array( |
374 | 374 | 'type' => array( |
375 | 375 | 'image/gif', |
@@ -392,9 +392,9 @@ discard block |
||
392 | 392 | * @param object $wp_query |
393 | 393 | * @return array |
394 | 394 | */ |
395 | - public function set_parent_only( $wp_query ) { |
|
396 | - if ( ! is_admin() && $wp_query->is_main_query() && ( $wp_query->is_post_type_archive( 'workout' ) || $wp_query->is_tax( array( 'workout-type' ) ) ) ) { |
|
397 | - $wp_query->set( 'post_parent', '0' ); |
|
395 | + public function set_parent_only($wp_query) { |
|
396 | + if ( ! is_admin() && $wp_query->is_main_query() && ($wp_query->is_post_type_archive('workout') || $wp_query->is_tax(array('workout-type')))) { |
|
397 | + $wp_query->set('post_parent', '0'); |
|
398 | 398 | } |
399 | 399 | } |
400 | 400 | |
@@ -404,24 +404,24 @@ discard block |
||
404 | 404 | * @var array $crumbs |
405 | 405 | * @return array |
406 | 406 | */ |
407 | - public function workout_breadcrumb_filter( $crumbs ) { |
|
408 | - $workout = \lsx_health_plan\functions\get_option( 'endpoint_workout', 'workout' ); |
|
409 | - $workouts = \lsx_health_plan\functions\get_option( 'endpoint_workout_archive', 'workout' ); |
|
407 | + public function workout_breadcrumb_filter($crumbs) { |
|
408 | + $workout = \lsx_health_plan\functions\get_option('endpoint_workout', 'workout'); |
|
409 | + $workouts = \lsx_health_plan\functions\get_option('endpoint_workout_archive', 'workout'); |
|
410 | 410 | |
411 | - if ( is_singular( 'workout' ) ) { |
|
411 | + if (is_singular('workout')) { |
|
412 | 412 | $workout_name = get_the_title(); |
413 | - $url = get_post_type_archive_link( $workout ); |
|
414 | - $term_obj_list = get_the_terms( get_the_ID(), 'workout-type' ); |
|
413 | + $url = get_post_type_archive_link($workout); |
|
414 | + $term_obj_list = get_the_terms(get_the_ID(), 'workout-type'); |
|
415 | 415 | $workout_type = $term_obj_list[0]->name; |
416 | - if ( empty( $workout_type ) ) { |
|
417 | - $workout_type = __( 'Workout', 'lsx-health-plan' ); |
|
416 | + if (empty($workout_type)) { |
|
417 | + $workout_type = __('Workout', 'lsx-health-plan'); |
|
418 | 418 | } |
419 | - $workout_type_url = get_term_link( $term_obj_list[0]->term_id ); |
|
419 | + $workout_type_url = get_term_link($term_obj_list[0]->term_id); |
|
420 | 420 | |
421 | 421 | $new_crumbs = array(); |
422 | 422 | $new_crumbs[0] = $crumbs[0]; |
423 | 423 | |
424 | - if ( function_exists( 'woocommerce_breadcrumb' ) ) { |
|
424 | + if (function_exists('woocommerce_breadcrumb')) { |
|
425 | 425 | $new_crumbs[1] = array( |
426 | 426 | 0 => $workouts, |
427 | 427 | 1 => $url, |
@@ -449,12 +449,12 @@ discard block |
||
449 | 449 | $crumbs = $new_crumbs; |
450 | 450 | |
451 | 451 | } |
452 | - if ( is_post_type_archive( 'workout' ) ) { |
|
452 | + if (is_post_type_archive('workout')) { |
|
453 | 453 | |
454 | 454 | $new_crumbs = array(); |
455 | 455 | $new_crumbs[0] = $crumbs[0]; |
456 | 456 | |
457 | - if ( function_exists( 'woocommerce_breadcrumb' ) ) { |
|
457 | + if (function_exists('woocommerce_breadcrumb')) { |
|
458 | 458 | $new_crumbs[1] = array( |
459 | 459 | 0 => $workouts, |
460 | 460 | ); |
@@ -8,251 +8,251 @@ discard block |
||
8 | 8 | */ |
9 | 9 | class Recipe { |
10 | 10 | |
11 | - /** |
|
12 | - * Holds class instance |
|
13 | - * |
|
14 | - * @since 1.0.0 |
|
15 | - * |
|
16 | - * @var object \lsx_health_plan\classes\Recipe() |
|
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 = 'recipe'; |
|
28 | - |
|
29 | - /** |
|
30 | - * Holds post_type labels |
|
31 | - * |
|
32 | - * @since 1.0.0 |
|
33 | - * |
|
34 | - * @var string |
|
35 | - */ |
|
36 | - public $labels = array(); |
|
37 | - |
|
38 | - /** |
|
39 | - * Constructor |
|
40 | - */ |
|
41 | - public function __construct() { |
|
42 | - add_action( 'init', array( $this, 'register_post_type' ) ); |
|
43 | - add_action( 'init', array( $this, 'taxonomy_setup' ) ); |
|
44 | - add_action( 'admin_menu', array( $this, 'register_menus' ) ); |
|
45 | - |
|
46 | - // Frontend Actions and Filters. |
|
47 | - add_action( 'wp_head', array( $this, 'remove_archive_original_header' ), 99 ); |
|
48 | - add_action( 'lsx_content_wrap_before', array( $this, 'hp_lsx_archive_header' ) ); |
|
49 | - |
|
50 | - add_filter( 'lsx_health_plan_archive_template', array( $this, 'enable_post_type' ), 10, 1 ); |
|
51 | - add_filter( 'lsx_health_plan_single_template', array( $this, 'enable_post_type' ), 10, 1 ); |
|
52 | - add_filter( 'lsx_health_plan_connections', array( $this, 'enable_connections' ), 10, 1 ); |
|
53 | - add_filter( 'get_the_archive_title', array( $this, 'get_the_archive_title' ), 100 ); |
|
54 | - add_filter( 'lsx_display_global_header_description', array( $this, 'disable_global_header_description' ), 100 ); |
|
55 | - |
|
56 | - //Breadcrumbs |
|
57 | - add_filter( 'wpseo_breadcrumb_links', array( $this, 'recipes_breadcrumb_filter' ), 30, 1 ); |
|
58 | - add_filter( 'woocommerce_get_breadcrumb', array( $this, 'recipes_breadcrumb_filter' ), 30, 1 ); |
|
59 | - |
|
60 | - // Backend Actions and Filters. |
|
61 | - add_action( 'cmb2_admin_init', array( $this, 'featured_metabox' ) ); |
|
62 | - add_action( 'cmb2_admin_init', array( $this, 'details_metaboxes' ) ); |
|
63 | - } |
|
64 | - |
|
65 | - /** |
|
66 | - * Return an instance of this class. |
|
67 | - * |
|
68 | - * @since 1.0.0 |
|
69 | - * |
|
70 | - * @return object \lsx_health_plan\classes\Recipe() A single instance of this class. |
|
71 | - */ |
|
72 | - public static function get_instance() { |
|
73 | - |
|
74 | - // If the single instance hasn't been set, set it now. |
|
75 | - if ( null === self::$instance ) { |
|
76 | - self::$instance = new self(); |
|
77 | - } |
|
78 | - |
|
79 | - return self::$instance; |
|
80 | - |
|
81 | - } |
|
82 | - |
|
83 | - /** |
|
84 | - * Register the post type. |
|
85 | - */ |
|
86 | - public function register_post_type() { |
|
87 | - $this->labels = array( |
|
88 | - 'name' => esc_html__( 'Recipes', 'lsx-health-plan' ), |
|
89 | - 'singular_name' => esc_html__( 'Recipe', 'lsx-health-plan' ), |
|
90 | - 'add_new' => esc_html_x( 'Add New', 'post type general name', 'lsx-health-plan' ), |
|
91 | - 'add_new_item' => esc_html__( 'Add New', 'lsx-health-plan' ), |
|
92 | - 'edit_item' => esc_html__( 'Edit', 'lsx-health-plan' ), |
|
93 | - 'new_item' => esc_html__( 'New', 'lsx-health-plan' ), |
|
94 | - 'all_items' => esc_html__( 'All Recipes', 'lsx-health-plan' ), |
|
95 | - 'view_item' => esc_html__( 'View', 'lsx-health-plan' ), |
|
96 | - 'search_items' => esc_html__( 'Search', 'lsx-health-plan' ), |
|
97 | - 'not_found' => esc_html__( 'None found', 'lsx-health-plan' ), |
|
98 | - 'not_found_in_trash' => esc_html__( 'None found in Trash', 'lsx-health-plan' ), |
|
99 | - 'parent_item_colon' => '', |
|
100 | - 'menu_name' => esc_html__( 'Recipes', 'lsx-health-plan' ), |
|
101 | - ); |
|
102 | - $args = array( |
|
103 | - 'labels' => $this->labels, |
|
104 | - 'public' => true, |
|
105 | - 'publicly_queryable' => true, |
|
106 | - 'show_ui' => true, |
|
107 | - 'show_in_menu' => 'edit.php?post_type=meal-pseudo', |
|
108 | - 'show_in_rest' => true, |
|
109 | - 'menu_icon' => 'dashicons-editor-ul', |
|
110 | - 'query_var' => true, |
|
111 | - 'rewrite' => array( |
|
112 | - 'slug' => 'recipe', |
|
113 | - ), |
|
114 | - 'capability_type' => 'post', |
|
115 | - 'has_archive' => 'recipes', |
|
116 | - 'hierarchical' => false, |
|
117 | - 'menu_position' => null, |
|
118 | - 'supports' => array( |
|
119 | - 'title', |
|
120 | - 'editor', |
|
121 | - 'thumbnail', |
|
122 | - 'custom-fields', |
|
123 | - ), |
|
124 | - ); |
|
125 | - register_post_type( 'recipe', $args ); |
|
126 | - } |
|
127 | - |
|
128 | - /** |
|
129 | - * Registers the Recipes under the Meals Post type menu. |
|
130 | - * |
|
131 | - * @return void |
|
132 | - */ |
|
133 | - public function register_menus() { |
|
134 | - add_submenu_page( 'edit.php?post_type=meal', esc_html__( 'Recipes', 'lsx-health-plan' ), esc_html__( 'Recipes', 'lsx-health-plan' ), 'edit_posts', 'edit.php?post_type=recipe' ); |
|
135 | - add_submenu_page( 'edit.php?post_type=meal', esc_html__( 'Recipe Types', 'lsx-health-plan' ), esc_html__( 'Recipe Types', 'lsx-health-plan' ), 'edit_posts', 'edit-tags.php?taxonomy=recipe-type&post_type=recipe' ); |
|
136 | - add_submenu_page( 'edit.php?post_type=meal', esc_html__( 'Cuisines', 'lsx-health-plan' ), esc_html__( 'Cuisines', 'lsx-health-plan' ), 'edit_posts', 'edit-tags.php?taxonomy=recipe-cuisine&post_type=recipe' ); |
|
137 | - } |
|
138 | - |
|
139 | - /** |
|
140 | - * Register the Cuisine taxonomy. |
|
141 | - */ |
|
142 | - public function taxonomy_setup() { |
|
143 | - $labels = array( |
|
144 | - 'name' => esc_html_x( 'Cuisine', 'taxonomy general name', 'lsx-health-plan' ), |
|
145 | - 'singular_name' => esc_html_x( 'Cuisines', 'taxonomy singular name', 'lsx-health-plan' ), |
|
146 | - 'search_items' => esc_html__( 'Search', 'lsx-health-plan' ), |
|
147 | - 'all_items' => esc_html__( 'All', 'lsx-health-plan' ), |
|
148 | - 'parent_item' => esc_html__( 'Parent', 'lsx-health-plan' ), |
|
149 | - 'parent_item_colon' => esc_html__( 'Parent:', 'lsx-health-plan' ), |
|
150 | - 'edit_item' => esc_html__( 'Edit', 'lsx-health-plan' ), |
|
151 | - 'update_item' => esc_html__( 'Update', 'lsx-health-plan' ), |
|
152 | - 'add_new_item' => esc_html__( 'Add New', 'lsx-health-plan' ), |
|
153 | - 'new_item_name' => esc_html__( 'New Name', 'lsx-health-plan' ), |
|
154 | - 'menu_name' => esc_html__( 'Cuisines', 'lsx-health-plan' ), |
|
155 | - ); |
|
156 | - $args = array( |
|
157 | - 'hierarchical' => true, |
|
158 | - 'labels' => $labels, |
|
159 | - 'show_ui' => true, |
|
160 | - 'show_admin_column' => true, |
|
161 | - 'show_in_menu' => 'edit.php?post_type=meal', |
|
162 | - 'query_var' => true, |
|
163 | - 'rewrite' => array( |
|
164 | - 'slug' => 'recipe-cuisine', |
|
165 | - ), |
|
166 | - ); |
|
167 | - register_taxonomy( 'recipe-cuisine', array( $this->slug ), $args ); |
|
168 | - |
|
169 | - $labels = array( |
|
170 | - 'name' => esc_html_x( 'Recipe Type', 'taxonomy general name', 'lsx-health-plan' ), |
|
171 | - 'singular_name' => esc_html_x( 'Recipe Types', 'taxonomy singular name', 'lsx-health-plan' ), |
|
172 | - 'search_items' => esc_html__( 'Search', 'lsx-health-plan' ), |
|
173 | - 'all_items' => esc_html__( 'All', 'lsx-health-plan' ), |
|
174 | - 'parent_item' => esc_html__( 'Parent', 'lsx-health-plan' ), |
|
175 | - 'parent_item_colon' => esc_html__( 'Parent:', 'lsx-health-plan' ), |
|
176 | - 'edit_item' => esc_html__( 'Edit', 'lsx-health-plan' ), |
|
177 | - 'update_item' => esc_html__( 'Update', 'lsx-health-plan' ), |
|
178 | - 'add_new_item' => esc_html__( 'Add New', 'lsx-health-plan' ), |
|
179 | - 'new_item_name' => esc_html__( 'New Name', 'lsx-health-plan' ), |
|
180 | - 'menu_name' => esc_html__( 'Types', 'lsx-health-plan' ), |
|
181 | - ); |
|
182 | - $args = array( |
|
183 | - 'hierarchical' => true, |
|
184 | - 'labels' => $labels, |
|
185 | - 'show_ui' => true, |
|
186 | - 'show_in_menu' => 'edit.php?post_type=meal', |
|
187 | - 'show_admin_column' => true, |
|
188 | - 'query_var' => true, |
|
189 | - 'rewrite' => array( |
|
190 | - 'slug' => 'recipe-type', |
|
191 | - ), |
|
192 | - ); |
|
193 | - register_taxonomy( 'recipe-type', array( $this->slug ), $args ); |
|
194 | - } |
|
195 | - |
|
196 | - /** |
|
197 | - * Adds the post type to the different arrays. |
|
198 | - * |
|
199 | - * @param array $post_types |
|
200 | - * @return array |
|
201 | - */ |
|
202 | - public function enable_post_type( $post_types = array() ) { |
|
203 | - $post_types[] = $this->slug; |
|
204 | - return $post_types; |
|
205 | - } |
|
206 | - |
|
207 | - /** |
|
208 | - * Enables the Bi Directional relationships |
|
209 | - * |
|
210 | - * @param array $connections |
|
211 | - * @return void |
|
212 | - */ |
|
213 | - public function enable_connections( $connections = array() ) { |
|
214 | - $connections['recipe']['connected_plans'] = 'connected_recipes'; |
|
215 | - $connections['plan']['connected_recipes'] = 'connected_plans'; |
|
216 | - return $connections; |
|
217 | - } |
|
218 | - |
|
219 | - /** |
|
220 | - * Remove the "Archives:" from the post type recipes. |
|
221 | - * |
|
222 | - * @param string $title the term title. |
|
223 | - * @return string |
|
224 | - */ |
|
225 | - public function get_the_archive_title( $title ) { |
|
226 | - if ( is_post_type_archive( 'recipe' ) ) { |
|
227 | - $title = __( 'Recipes', 'lsx-health-plan' ); |
|
228 | - } |
|
229 | - if ( is_post_type_archive( 'exercise' ) ) { |
|
230 | - $title = __( 'Exercises', 'lsx-health-plan' ); |
|
231 | - } |
|
232 | - if ( is_tax( 'recipe-type' ) ) { |
|
233 | - $queried_object = get_queried_object(); |
|
234 | - if ( isset( $queried_object->name ) ) { |
|
235 | - $title = $queried_object->name . ' ' . __( 'Recipes', 'lsx-health-plan' ); |
|
236 | - } |
|
237 | - } |
|
238 | - return $title; |
|
239 | - } |
|
240 | - |
|
241 | - public function remove_archive_original_header() { |
|
242 | - if ( is_post_type_archive( 'recipe' ) || is_post_type_archive( 'exercise' ) ) { |
|
243 | - remove_action( 'lsx_content_wrap_before', 'lsx_global_header' ); |
|
244 | - } |
|
245 | - if ( is_singular( 'recipe' ) || is_singular( 'exercise' ) ) { |
|
246 | - remove_action( 'lsx_content_wrap_before', 'lsx_global_header' ); |
|
247 | - } |
|
248 | - if ( ! is_post_type_archive() ) { |
|
249 | - add_action( 'lsx_content_wrap_before', 'lsx_health_plan_recipe_archive_description', 11 ); |
|
250 | - } |
|
251 | - } |
|
252 | - |
|
253 | - public function hp_lsx_archive_header() { |
|
254 | - if ( is_post_type_archive( 'recipe' ) || is_post_type_archive( 'exercise' ) ) { |
|
255 | - ?> |
|
11 | + /** |
|
12 | + * Holds class instance |
|
13 | + * |
|
14 | + * @since 1.0.0 |
|
15 | + * |
|
16 | + * @var object \lsx_health_plan\classes\Recipe() |
|
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 = 'recipe'; |
|
28 | + |
|
29 | + /** |
|
30 | + * Holds post_type labels |
|
31 | + * |
|
32 | + * @since 1.0.0 |
|
33 | + * |
|
34 | + * @var string |
|
35 | + */ |
|
36 | + public $labels = array(); |
|
37 | + |
|
38 | + /** |
|
39 | + * Constructor |
|
40 | + */ |
|
41 | + public function __construct() { |
|
42 | + add_action( 'init', array( $this, 'register_post_type' ) ); |
|
43 | + add_action( 'init', array( $this, 'taxonomy_setup' ) ); |
|
44 | + add_action( 'admin_menu', array( $this, 'register_menus' ) ); |
|
45 | + |
|
46 | + // Frontend Actions and Filters. |
|
47 | + add_action( 'wp_head', array( $this, 'remove_archive_original_header' ), 99 ); |
|
48 | + add_action( 'lsx_content_wrap_before', array( $this, 'hp_lsx_archive_header' ) ); |
|
49 | + |
|
50 | + add_filter( 'lsx_health_plan_archive_template', array( $this, 'enable_post_type' ), 10, 1 ); |
|
51 | + add_filter( 'lsx_health_plan_single_template', array( $this, 'enable_post_type' ), 10, 1 ); |
|
52 | + add_filter( 'lsx_health_plan_connections', array( $this, 'enable_connections' ), 10, 1 ); |
|
53 | + add_filter( 'get_the_archive_title', array( $this, 'get_the_archive_title' ), 100 ); |
|
54 | + add_filter( 'lsx_display_global_header_description', array( $this, 'disable_global_header_description' ), 100 ); |
|
55 | + |
|
56 | + //Breadcrumbs |
|
57 | + add_filter( 'wpseo_breadcrumb_links', array( $this, 'recipes_breadcrumb_filter' ), 30, 1 ); |
|
58 | + add_filter( 'woocommerce_get_breadcrumb', array( $this, 'recipes_breadcrumb_filter' ), 30, 1 ); |
|
59 | + |
|
60 | + // Backend Actions and Filters. |
|
61 | + add_action( 'cmb2_admin_init', array( $this, 'featured_metabox' ) ); |
|
62 | + add_action( 'cmb2_admin_init', array( $this, 'details_metaboxes' ) ); |
|
63 | + } |
|
64 | + |
|
65 | + /** |
|
66 | + * Return an instance of this class. |
|
67 | + * |
|
68 | + * @since 1.0.0 |
|
69 | + * |
|
70 | + * @return object \lsx_health_plan\classes\Recipe() A single instance of this class. |
|
71 | + */ |
|
72 | + public static function get_instance() { |
|
73 | + |
|
74 | + // If the single instance hasn't been set, set it now. |
|
75 | + if ( null === self::$instance ) { |
|
76 | + self::$instance = new self(); |
|
77 | + } |
|
78 | + |
|
79 | + return self::$instance; |
|
80 | + |
|
81 | + } |
|
82 | + |
|
83 | + /** |
|
84 | + * Register the post type. |
|
85 | + */ |
|
86 | + public function register_post_type() { |
|
87 | + $this->labels = array( |
|
88 | + 'name' => esc_html__( 'Recipes', 'lsx-health-plan' ), |
|
89 | + 'singular_name' => esc_html__( 'Recipe', 'lsx-health-plan' ), |
|
90 | + 'add_new' => esc_html_x( 'Add New', 'post type general name', 'lsx-health-plan' ), |
|
91 | + 'add_new_item' => esc_html__( 'Add New', 'lsx-health-plan' ), |
|
92 | + 'edit_item' => esc_html__( 'Edit', 'lsx-health-plan' ), |
|
93 | + 'new_item' => esc_html__( 'New', 'lsx-health-plan' ), |
|
94 | + 'all_items' => esc_html__( 'All Recipes', 'lsx-health-plan' ), |
|
95 | + 'view_item' => esc_html__( 'View', 'lsx-health-plan' ), |
|
96 | + 'search_items' => esc_html__( 'Search', 'lsx-health-plan' ), |
|
97 | + 'not_found' => esc_html__( 'None found', 'lsx-health-plan' ), |
|
98 | + 'not_found_in_trash' => esc_html__( 'None found in Trash', 'lsx-health-plan' ), |
|
99 | + 'parent_item_colon' => '', |
|
100 | + 'menu_name' => esc_html__( 'Recipes', 'lsx-health-plan' ), |
|
101 | + ); |
|
102 | + $args = array( |
|
103 | + 'labels' => $this->labels, |
|
104 | + 'public' => true, |
|
105 | + 'publicly_queryable' => true, |
|
106 | + 'show_ui' => true, |
|
107 | + 'show_in_menu' => 'edit.php?post_type=meal-pseudo', |
|
108 | + 'show_in_rest' => true, |
|
109 | + 'menu_icon' => 'dashicons-editor-ul', |
|
110 | + 'query_var' => true, |
|
111 | + 'rewrite' => array( |
|
112 | + 'slug' => 'recipe', |
|
113 | + ), |
|
114 | + 'capability_type' => 'post', |
|
115 | + 'has_archive' => 'recipes', |
|
116 | + 'hierarchical' => false, |
|
117 | + 'menu_position' => null, |
|
118 | + 'supports' => array( |
|
119 | + 'title', |
|
120 | + 'editor', |
|
121 | + 'thumbnail', |
|
122 | + 'custom-fields', |
|
123 | + ), |
|
124 | + ); |
|
125 | + register_post_type( 'recipe', $args ); |
|
126 | + } |
|
127 | + |
|
128 | + /** |
|
129 | + * Registers the Recipes under the Meals Post type menu. |
|
130 | + * |
|
131 | + * @return void |
|
132 | + */ |
|
133 | + public function register_menus() { |
|
134 | + add_submenu_page( 'edit.php?post_type=meal', esc_html__( 'Recipes', 'lsx-health-plan' ), esc_html__( 'Recipes', 'lsx-health-plan' ), 'edit_posts', 'edit.php?post_type=recipe' ); |
|
135 | + add_submenu_page( 'edit.php?post_type=meal', esc_html__( 'Recipe Types', 'lsx-health-plan' ), esc_html__( 'Recipe Types', 'lsx-health-plan' ), 'edit_posts', 'edit-tags.php?taxonomy=recipe-type&post_type=recipe' ); |
|
136 | + add_submenu_page( 'edit.php?post_type=meal', esc_html__( 'Cuisines', 'lsx-health-plan' ), esc_html__( 'Cuisines', 'lsx-health-plan' ), 'edit_posts', 'edit-tags.php?taxonomy=recipe-cuisine&post_type=recipe' ); |
|
137 | + } |
|
138 | + |
|
139 | + /** |
|
140 | + * Register the Cuisine taxonomy. |
|
141 | + */ |
|
142 | + public function taxonomy_setup() { |
|
143 | + $labels = array( |
|
144 | + 'name' => esc_html_x( 'Cuisine', 'taxonomy general name', 'lsx-health-plan' ), |
|
145 | + 'singular_name' => esc_html_x( 'Cuisines', 'taxonomy singular name', 'lsx-health-plan' ), |
|
146 | + 'search_items' => esc_html__( 'Search', 'lsx-health-plan' ), |
|
147 | + 'all_items' => esc_html__( 'All', 'lsx-health-plan' ), |
|
148 | + 'parent_item' => esc_html__( 'Parent', 'lsx-health-plan' ), |
|
149 | + 'parent_item_colon' => esc_html__( 'Parent:', 'lsx-health-plan' ), |
|
150 | + 'edit_item' => esc_html__( 'Edit', 'lsx-health-plan' ), |
|
151 | + 'update_item' => esc_html__( 'Update', 'lsx-health-plan' ), |
|
152 | + 'add_new_item' => esc_html__( 'Add New', 'lsx-health-plan' ), |
|
153 | + 'new_item_name' => esc_html__( 'New Name', 'lsx-health-plan' ), |
|
154 | + 'menu_name' => esc_html__( 'Cuisines', 'lsx-health-plan' ), |
|
155 | + ); |
|
156 | + $args = array( |
|
157 | + 'hierarchical' => true, |
|
158 | + 'labels' => $labels, |
|
159 | + 'show_ui' => true, |
|
160 | + 'show_admin_column' => true, |
|
161 | + 'show_in_menu' => 'edit.php?post_type=meal', |
|
162 | + 'query_var' => true, |
|
163 | + 'rewrite' => array( |
|
164 | + 'slug' => 'recipe-cuisine', |
|
165 | + ), |
|
166 | + ); |
|
167 | + register_taxonomy( 'recipe-cuisine', array( $this->slug ), $args ); |
|
168 | + |
|
169 | + $labels = array( |
|
170 | + 'name' => esc_html_x( 'Recipe Type', 'taxonomy general name', 'lsx-health-plan' ), |
|
171 | + 'singular_name' => esc_html_x( 'Recipe Types', 'taxonomy singular name', 'lsx-health-plan' ), |
|
172 | + 'search_items' => esc_html__( 'Search', 'lsx-health-plan' ), |
|
173 | + 'all_items' => esc_html__( 'All', 'lsx-health-plan' ), |
|
174 | + 'parent_item' => esc_html__( 'Parent', 'lsx-health-plan' ), |
|
175 | + 'parent_item_colon' => esc_html__( 'Parent:', 'lsx-health-plan' ), |
|
176 | + 'edit_item' => esc_html__( 'Edit', 'lsx-health-plan' ), |
|
177 | + 'update_item' => esc_html__( 'Update', 'lsx-health-plan' ), |
|
178 | + 'add_new_item' => esc_html__( 'Add New', 'lsx-health-plan' ), |
|
179 | + 'new_item_name' => esc_html__( 'New Name', 'lsx-health-plan' ), |
|
180 | + 'menu_name' => esc_html__( 'Types', 'lsx-health-plan' ), |
|
181 | + ); |
|
182 | + $args = array( |
|
183 | + 'hierarchical' => true, |
|
184 | + 'labels' => $labels, |
|
185 | + 'show_ui' => true, |
|
186 | + 'show_in_menu' => 'edit.php?post_type=meal', |
|
187 | + 'show_admin_column' => true, |
|
188 | + 'query_var' => true, |
|
189 | + 'rewrite' => array( |
|
190 | + 'slug' => 'recipe-type', |
|
191 | + ), |
|
192 | + ); |
|
193 | + register_taxonomy( 'recipe-type', array( $this->slug ), $args ); |
|
194 | + } |
|
195 | + |
|
196 | + /** |
|
197 | + * Adds the post type to the different arrays. |
|
198 | + * |
|
199 | + * @param array $post_types |
|
200 | + * @return array |
|
201 | + */ |
|
202 | + public function enable_post_type( $post_types = array() ) { |
|
203 | + $post_types[] = $this->slug; |
|
204 | + return $post_types; |
|
205 | + } |
|
206 | + |
|
207 | + /** |
|
208 | + * Enables the Bi Directional relationships |
|
209 | + * |
|
210 | + * @param array $connections |
|
211 | + * @return void |
|
212 | + */ |
|
213 | + public function enable_connections( $connections = array() ) { |
|
214 | + $connections['recipe']['connected_plans'] = 'connected_recipes'; |
|
215 | + $connections['plan']['connected_recipes'] = 'connected_plans'; |
|
216 | + return $connections; |
|
217 | + } |
|
218 | + |
|
219 | + /** |
|
220 | + * Remove the "Archives:" from the post type recipes. |
|
221 | + * |
|
222 | + * @param string $title the term title. |
|
223 | + * @return string |
|
224 | + */ |
|
225 | + public function get_the_archive_title( $title ) { |
|
226 | + if ( is_post_type_archive( 'recipe' ) ) { |
|
227 | + $title = __( 'Recipes', 'lsx-health-plan' ); |
|
228 | + } |
|
229 | + if ( is_post_type_archive( 'exercise' ) ) { |
|
230 | + $title = __( 'Exercises', 'lsx-health-plan' ); |
|
231 | + } |
|
232 | + if ( is_tax( 'recipe-type' ) ) { |
|
233 | + $queried_object = get_queried_object(); |
|
234 | + if ( isset( $queried_object->name ) ) { |
|
235 | + $title = $queried_object->name . ' ' . __( 'Recipes', 'lsx-health-plan' ); |
|
236 | + } |
|
237 | + } |
|
238 | + return $title; |
|
239 | + } |
|
240 | + |
|
241 | + public function remove_archive_original_header() { |
|
242 | + if ( is_post_type_archive( 'recipe' ) || is_post_type_archive( 'exercise' ) ) { |
|
243 | + remove_action( 'lsx_content_wrap_before', 'lsx_global_header' ); |
|
244 | + } |
|
245 | + if ( is_singular( 'recipe' ) || is_singular( 'exercise' ) ) { |
|
246 | + remove_action( 'lsx_content_wrap_before', 'lsx_global_header' ); |
|
247 | + } |
|
248 | + if ( ! is_post_type_archive() ) { |
|
249 | + add_action( 'lsx_content_wrap_before', 'lsx_health_plan_recipe_archive_description', 11 ); |
|
250 | + } |
|
251 | + } |
|
252 | + |
|
253 | + public function hp_lsx_archive_header() { |
|
254 | + if ( is_post_type_archive( 'recipe' ) || is_post_type_archive( 'exercise' ) ) { |
|
255 | + ?> |
|
256 | 256 | <div class="archive-header-wrapper banner-archive"> |
257 | 257 | <?php lsx_global_header_inner_bottom(); ?> |
258 | 258 | <header class="archive-header"> |
@@ -265,253 +265,253 @@ discard block |
||
265 | 265 | </h1> |
266 | 266 | |
267 | 267 | <?php |
268 | - lsx_health_plan_recipe_archive_description(); |
|
269 | - ?> |
|
268 | + lsx_health_plan_recipe_archive_description(); |
|
269 | + ?> |
|
270 | 270 | </header> |
271 | 271 | </div> |
272 | 272 | <?php |
273 | - } |
|
274 | - } |
|
275 | - |
|
276 | - /** |
|
277 | - * Disables the global header description |
|
278 | - * |
|
279 | - * @param boolean $disable |
|
280 | - * @return boolean |
|
281 | - */ |
|
282 | - public function disable_global_header_description( $disable ) { |
|
283 | - if ( is_tax( 'recipe-type' ) ) { |
|
284 | - $disable = true; |
|
285 | - } |
|
286 | - return $disable; |
|
287 | - } |
|
288 | - |
|
289 | - /** |
|
290 | - * Holds the array for the breadcrumbs. |
|
291 | - * |
|
292 | - * @var array $crumbs |
|
293 | - * @return array |
|
294 | - */ |
|
295 | - public function recipes_breadcrumb_filter( $crumbs ) { |
|
296 | - $recipe = \lsx_health_plan\functions\get_option( 'endpoint_recipe', 'recipe' ); |
|
297 | - $recipes = \lsx_health_plan\functions\get_option( 'endpoint_recipe_archive', 'recipes' ); |
|
298 | - $url = get_post_type_archive_link( 'recipe' ); |
|
299 | - |
|
300 | - if ( is_singular( 'recipe' ) ) { |
|
301 | - $recipe_name = get_the_title(); |
|
302 | - $term_obj_list = get_the_terms( get_the_ID(), 'recipe-type' ); |
|
303 | - $recipe_type = $term_obj_list[0]->name; |
|
304 | - $recipe_type_url = get_term_link( $term_obj_list[0]->term_id ); |
|
305 | - |
|
306 | - $new_crumbs = array(); |
|
307 | - $new_crumbs[0] = $crumbs[0]; |
|
308 | - |
|
309 | - if ( function_exists( 'woocommerce_breadcrumb' ) ) { |
|
310 | - $new_crumbs[1] = array( |
|
311 | - 0 => $recipes, |
|
312 | - 1 => $url, |
|
313 | - ); |
|
314 | - $new_crumbs[2] = array( |
|
315 | - 0 => $recipe_type, |
|
316 | - 1 => $recipe_type_url, |
|
317 | - ); |
|
318 | - $new_crumbs[3] = array( |
|
319 | - 0 => $recipe_name, |
|
320 | - ); |
|
321 | - } else { |
|
322 | - $new_crumbs[1] = array( |
|
323 | - 'text' => $recipes, |
|
324 | - 'url' => $url, |
|
325 | - ); |
|
326 | - $new_crumbs[2] = array( |
|
327 | - 'text' => $recipe_type, |
|
328 | - 'url' => $recipe_type_url, |
|
329 | - ); |
|
330 | - $new_crumbs[3] = array( |
|
331 | - 'text' => $recipe_name, |
|
332 | - ); |
|
333 | - } |
|
334 | - $crumbs = $new_crumbs; |
|
335 | - } |
|
336 | - if ( is_tax( 'recipe-type' ) || is_tax( 'recipe-cuisine' ) ) { |
|
337 | - $term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) ); |
|
338 | - |
|
339 | - $single_term_title = str_replace( '-', ' ', $term->taxonomy ) . ': ' . $term->name; |
|
340 | - |
|
341 | - $new_crumbs = array(); |
|
342 | - $new_crumbs[0] = $crumbs[0]; |
|
343 | - |
|
344 | - if ( function_exists( 'woocommerce_breadcrumb' ) ) { |
|
345 | - $new_crumbs[1] = array( |
|
346 | - 0 => $recipes, |
|
347 | - 1 => $url, |
|
348 | - ); |
|
349 | - $new_crumbs[2] = array( |
|
350 | - 0 => $single_term_title, |
|
351 | - ); |
|
352 | - } else { |
|
353 | - $new_crumbs[1] = array( |
|
354 | - 'text' => $recipes, |
|
355 | - 'url' => $url, |
|
356 | - ); |
|
357 | - $new_crumbs[2] = array( |
|
358 | - 'text' => $single_term_title, |
|
359 | - ); |
|
360 | - } |
|
361 | - $crumbs = $new_crumbs; |
|
362 | - } |
|
363 | - if ( is_post_type_archive( 'recipe' ) ) { |
|
364 | - |
|
365 | - $new_crumbs = array(); |
|
366 | - $new_crumbs[0] = $crumbs[0]; |
|
367 | - |
|
368 | - if ( function_exists( 'woocommerce_breadcrumb' ) ) { |
|
369 | - $new_crumbs[1] = array( |
|
370 | - 0 => $recipes, |
|
371 | - ); |
|
372 | - } else { |
|
373 | - $new_crumbs[1] = array( |
|
374 | - 'text' => $recipes, |
|
375 | - ); |
|
376 | - } |
|
377 | - $crumbs = $new_crumbs; |
|
378 | - } |
|
379 | - return $crumbs; |
|
380 | - } |
|
381 | - |
|
382 | - /** |
|
383 | - * Define the metabox and field configurations. |
|
384 | - */ |
|
385 | - public function featured_metabox() { |
|
386 | - $cmb = new_cmb2_box( |
|
387 | - array( |
|
388 | - 'id' => $this->slug . '_featured_metabox', |
|
389 | - 'title' => __( 'Featured', 'lsx-health-plan' ), |
|
390 | - 'object_types' => array( $this->slug ), |
|
391 | - 'context' => 'side', |
|
392 | - 'priority' => 'high', |
|
393 | - 'show_names' => true, |
|
394 | - ) |
|
395 | - ); |
|
396 | - $cmb->add_field( |
|
397 | - array( |
|
398 | - 'name' => __( 'Featured', 'lsx-health-plan' ), |
|
399 | - 'desc' => __( 'Enable the checkbox to feature this recipe, featured recipes display in any page that has the recipe shortcode: [lsx_health_plan_featured_recipes_block]', 'lsx-health-plan' ), |
|
400 | - 'id' => $this->slug . '_featured', |
|
401 | - 'type' => 'checkbox', |
|
402 | - 'show_on_cb' => 'cmb2_hide_if_no_cats', |
|
403 | - ) |
|
404 | - ); |
|
405 | - } |
|
406 | - |
|
407 | - /** |
|
408 | - * Define the metabox and field configurations. |
|
409 | - */ |
|
410 | - public function details_metaboxes() { |
|
411 | - $cmb = new_cmb2_box( |
|
412 | - array( |
|
413 | - 'id' => $this->slug . '_details_metabox', |
|
414 | - 'title' => __( 'Cooking Info', 'lsx-health-plan' ), |
|
415 | - 'object_types' => array( $this->slug ), // Post type |
|
416 | - 'context' => 'normal', |
|
417 | - 'priority' => 'high', |
|
418 | - 'show_names' => true, |
|
419 | - ) |
|
420 | - ); |
|
421 | - $cmb->add_field( |
|
422 | - array( |
|
423 | - 'name' => __( 'Prep Time', 'lsx-health-plan' ), |
|
424 | - 'id' => $this->slug . '_prep_time', |
|
425 | - 'desc' => __( 'Add the preparation time for the entire meal i.e: 25 mins', 'lsx-health-plan' ), |
|
426 | - 'type' => 'text', |
|
427 | - 'show_on_cb' => 'cmb2_hide_if_no_cats', |
|
428 | - ) |
|
429 | - ); |
|
430 | - $cmb->add_field( |
|
431 | - array( |
|
432 | - 'name' => __( 'Cooking Time', 'lsx-health-plan' ), |
|
433 | - 'id' => $this->slug . '_cooking_time', |
|
434 | - 'desc' => __( 'Add the cooking time i.e: 15 mins', 'lsx-health-plan' ), |
|
435 | - 'type' => 'text', |
|
436 | - 'show_on_cb' => 'cmb2_hide_if_no_cats', |
|
437 | - ) |
|
438 | - ); |
|
439 | - $cmb->add_field( |
|
440 | - array( |
|
441 | - 'name' => __( 'Serves', 'lsx-health-plan' ), |
|
442 | - 'id' => $this->slug . '_serves', |
|
443 | - 'desc' => __( 'Add the recommended serving size i.e: 6', 'lsx-health-plan' ), |
|
444 | - 'type' => 'text', |
|
445 | - 'show_on_cb' => 'cmb2_hide_if_no_cats', |
|
446 | - 'attributes' => array( |
|
447 | - 'type' => 'number', |
|
448 | - 'pattern' => '\d*', |
|
449 | - ), |
|
450 | - ) |
|
451 | - ); |
|
452 | - $cmb->add_field( |
|
453 | - array( |
|
454 | - 'name' => __( 'Portion', 'lsx-health-plan' ), |
|
455 | - 'desc' => __( 'Add the recommended portion size i.e: 200mg', 'lsx-health-plan' ), |
|
456 | - 'id' => $this->slug . '_portion', |
|
457 | - 'type' => 'text', |
|
458 | - 'show_on_cb' => 'cmb2_hide_if_no_cats', |
|
459 | - ) |
|
460 | - ); |
|
461 | - $cmb = new_cmb2_box( |
|
462 | - array( |
|
463 | - 'id' => $this->slug . '_nutritional_metabox', |
|
464 | - 'title' => __( 'Nutritional Info', 'lsx-health-plan' ), |
|
465 | - 'object_types' => array( $this->slug ), // Post type |
|
466 | - 'context' => 'normal', |
|
467 | - 'priority' => 'high', |
|
468 | - 'show_names' => true, |
|
469 | - ) |
|
470 | - ); |
|
471 | - $cmb->add_field( |
|
472 | - array( |
|
473 | - 'name' => __( 'Energy', 'lsx-health-plan' ), |
|
474 | - 'id' => $this->slug . '_energy', |
|
475 | - 'desc' => __( 'Add the energy amount for the entire meal i.e: 700 kj', 'lsx-health-plan' ), |
|
476 | - 'type' => 'text', |
|
477 | - 'show_on_cb' => 'cmb2_hide_if_no_cats', |
|
478 | - ) |
|
479 | - ); |
|
480 | - $cmb->add_field( |
|
481 | - array( |
|
482 | - 'name' => __( 'Protein', 'lsx-health-plan' ), |
|
483 | - 'id' => $this->slug . '_protein', |
|
484 | - 'desc' => __( 'Add the protein amount for the entire meal i.e: 50 g', 'lsx-health-plan' ), |
|
485 | - 'type' => 'text', |
|
486 | - 'show_on_cb' => 'cmb2_hide_if_no_cats', |
|
487 | - ) |
|
488 | - ); |
|
489 | - $cmb->add_field( |
|
490 | - array( |
|
491 | - 'name' => __( 'Carbohydrates', 'lsx-health-plan' ), |
|
492 | - 'id' => $this->slug . '_carbohydrates', |
|
493 | - 'desc' => __( 'Add the carbohydrates amount for the entire meal i.e: 5 g', 'lsx-health-plan' ), |
|
494 | - 'type' => 'text', |
|
495 | - 'show_on_cb' => 'cmb2_hide_if_no_cats', |
|
496 | - ) |
|
497 | - ); |
|
498 | - $cmb->add_field( |
|
499 | - array( |
|
500 | - 'name' => __( 'Fibre', 'lsx-health-plan' ), |
|
501 | - 'id' => $this->slug . '_fibre', |
|
502 | - 'desc' => __( 'Add the fibre amount for the entire meal i.e: 5 g', 'lsx-health-plan' ), |
|
503 | - 'type' => 'text', |
|
504 | - 'show_on_cb' => 'cmb2_hide_if_no_cats', |
|
505 | - ) |
|
506 | - ); |
|
507 | - $cmb->add_field( |
|
508 | - array( |
|
509 | - 'name' => __( 'Fat', 'lsx-health-plan' ), |
|
510 | - 'id' => $this->slug . '_fat', |
|
511 | - 'desc' => __( 'Add the fat amount for the entire meal i.e: 20 g', 'lsx-health-plan' ), |
|
512 | - 'type' => 'text', |
|
513 | - 'show_on_cb' => 'cmb2_hide_if_no_cats', |
|
514 | - ) |
|
515 | - ); |
|
516 | - } |
|
273 | + } |
|
274 | + } |
|
275 | + |
|
276 | + /** |
|
277 | + * Disables the global header description |
|
278 | + * |
|
279 | + * @param boolean $disable |
|
280 | + * @return boolean |
|
281 | + */ |
|
282 | + public function disable_global_header_description( $disable ) { |
|
283 | + if ( is_tax( 'recipe-type' ) ) { |
|
284 | + $disable = true; |
|
285 | + } |
|
286 | + return $disable; |
|
287 | + } |
|
288 | + |
|
289 | + /** |
|
290 | + * Holds the array for the breadcrumbs. |
|
291 | + * |
|
292 | + * @var array $crumbs |
|
293 | + * @return array |
|
294 | + */ |
|
295 | + public function recipes_breadcrumb_filter( $crumbs ) { |
|
296 | + $recipe = \lsx_health_plan\functions\get_option( 'endpoint_recipe', 'recipe' ); |
|
297 | + $recipes = \lsx_health_plan\functions\get_option( 'endpoint_recipe_archive', 'recipes' ); |
|
298 | + $url = get_post_type_archive_link( 'recipe' ); |
|
299 | + |
|
300 | + if ( is_singular( 'recipe' ) ) { |
|
301 | + $recipe_name = get_the_title(); |
|
302 | + $term_obj_list = get_the_terms( get_the_ID(), 'recipe-type' ); |
|
303 | + $recipe_type = $term_obj_list[0]->name; |
|
304 | + $recipe_type_url = get_term_link( $term_obj_list[0]->term_id ); |
|
305 | + |
|
306 | + $new_crumbs = array(); |
|
307 | + $new_crumbs[0] = $crumbs[0]; |
|
308 | + |
|
309 | + if ( function_exists( 'woocommerce_breadcrumb' ) ) { |
|
310 | + $new_crumbs[1] = array( |
|
311 | + 0 => $recipes, |
|
312 | + 1 => $url, |
|
313 | + ); |
|
314 | + $new_crumbs[2] = array( |
|
315 | + 0 => $recipe_type, |
|
316 | + 1 => $recipe_type_url, |
|
317 | + ); |
|
318 | + $new_crumbs[3] = array( |
|
319 | + 0 => $recipe_name, |
|
320 | + ); |
|
321 | + } else { |
|
322 | + $new_crumbs[1] = array( |
|
323 | + 'text' => $recipes, |
|
324 | + 'url' => $url, |
|
325 | + ); |
|
326 | + $new_crumbs[2] = array( |
|
327 | + 'text' => $recipe_type, |
|
328 | + 'url' => $recipe_type_url, |
|
329 | + ); |
|
330 | + $new_crumbs[3] = array( |
|
331 | + 'text' => $recipe_name, |
|
332 | + ); |
|
333 | + } |
|
334 | + $crumbs = $new_crumbs; |
|
335 | + } |
|
336 | + if ( is_tax( 'recipe-type' ) || is_tax( 'recipe-cuisine' ) ) { |
|
337 | + $term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) ); |
|
338 | + |
|
339 | + $single_term_title = str_replace( '-', ' ', $term->taxonomy ) . ': ' . $term->name; |
|
340 | + |
|
341 | + $new_crumbs = array(); |
|
342 | + $new_crumbs[0] = $crumbs[0]; |
|
343 | + |
|
344 | + if ( function_exists( 'woocommerce_breadcrumb' ) ) { |
|
345 | + $new_crumbs[1] = array( |
|
346 | + 0 => $recipes, |
|
347 | + 1 => $url, |
|
348 | + ); |
|
349 | + $new_crumbs[2] = array( |
|
350 | + 0 => $single_term_title, |
|
351 | + ); |
|
352 | + } else { |
|
353 | + $new_crumbs[1] = array( |
|
354 | + 'text' => $recipes, |
|
355 | + 'url' => $url, |
|
356 | + ); |
|
357 | + $new_crumbs[2] = array( |
|
358 | + 'text' => $single_term_title, |
|
359 | + ); |
|
360 | + } |
|
361 | + $crumbs = $new_crumbs; |
|
362 | + } |
|
363 | + if ( is_post_type_archive( 'recipe' ) ) { |
|
364 | + |
|
365 | + $new_crumbs = array(); |
|
366 | + $new_crumbs[0] = $crumbs[0]; |
|
367 | + |
|
368 | + if ( function_exists( 'woocommerce_breadcrumb' ) ) { |
|
369 | + $new_crumbs[1] = array( |
|
370 | + 0 => $recipes, |
|
371 | + ); |
|
372 | + } else { |
|
373 | + $new_crumbs[1] = array( |
|
374 | + 'text' => $recipes, |
|
375 | + ); |
|
376 | + } |
|
377 | + $crumbs = $new_crumbs; |
|
378 | + } |
|
379 | + return $crumbs; |
|
380 | + } |
|
381 | + |
|
382 | + /** |
|
383 | + * Define the metabox and field configurations. |
|
384 | + */ |
|
385 | + public function featured_metabox() { |
|
386 | + $cmb = new_cmb2_box( |
|
387 | + array( |
|
388 | + 'id' => $this->slug . '_featured_metabox', |
|
389 | + 'title' => __( 'Featured', 'lsx-health-plan' ), |
|
390 | + 'object_types' => array( $this->slug ), |
|
391 | + 'context' => 'side', |
|
392 | + 'priority' => 'high', |
|
393 | + 'show_names' => true, |
|
394 | + ) |
|
395 | + ); |
|
396 | + $cmb->add_field( |
|
397 | + array( |
|
398 | + 'name' => __( 'Featured', 'lsx-health-plan' ), |
|
399 | + 'desc' => __( 'Enable the checkbox to feature this recipe, featured recipes display in any page that has the recipe shortcode: [lsx_health_plan_featured_recipes_block]', 'lsx-health-plan' ), |
|
400 | + 'id' => $this->slug . '_featured', |
|
401 | + 'type' => 'checkbox', |
|
402 | + 'show_on_cb' => 'cmb2_hide_if_no_cats', |
|
403 | + ) |
|
404 | + ); |
|
405 | + } |
|
406 | + |
|
407 | + /** |
|
408 | + * Define the metabox and field configurations. |
|
409 | + */ |
|
410 | + public function details_metaboxes() { |
|
411 | + $cmb = new_cmb2_box( |
|
412 | + array( |
|
413 | + 'id' => $this->slug . '_details_metabox', |
|
414 | + 'title' => __( 'Cooking Info', 'lsx-health-plan' ), |
|
415 | + 'object_types' => array( $this->slug ), // Post type |
|
416 | + 'context' => 'normal', |
|
417 | + 'priority' => 'high', |
|
418 | + 'show_names' => true, |
|
419 | + ) |
|
420 | + ); |
|
421 | + $cmb->add_field( |
|
422 | + array( |
|
423 | + 'name' => __( 'Prep Time', 'lsx-health-plan' ), |
|
424 | + 'id' => $this->slug . '_prep_time', |
|
425 | + 'desc' => __( 'Add the preparation time for the entire meal i.e: 25 mins', 'lsx-health-plan' ), |
|
426 | + 'type' => 'text', |
|
427 | + 'show_on_cb' => 'cmb2_hide_if_no_cats', |
|
428 | + ) |
|
429 | + ); |
|
430 | + $cmb->add_field( |
|
431 | + array( |
|
432 | + 'name' => __( 'Cooking Time', 'lsx-health-plan' ), |
|
433 | + 'id' => $this->slug . '_cooking_time', |
|
434 | + 'desc' => __( 'Add the cooking time i.e: 15 mins', 'lsx-health-plan' ), |
|
435 | + 'type' => 'text', |
|
436 | + 'show_on_cb' => 'cmb2_hide_if_no_cats', |
|
437 | + ) |
|
438 | + ); |
|
439 | + $cmb->add_field( |
|
440 | + array( |
|
441 | + 'name' => __( 'Serves', 'lsx-health-plan' ), |
|
442 | + 'id' => $this->slug . '_serves', |
|
443 | + 'desc' => __( 'Add the recommended serving size i.e: 6', 'lsx-health-plan' ), |
|
444 | + 'type' => 'text', |
|
445 | + 'show_on_cb' => 'cmb2_hide_if_no_cats', |
|
446 | + 'attributes' => array( |
|
447 | + 'type' => 'number', |
|
448 | + 'pattern' => '\d*', |
|
449 | + ), |
|
450 | + ) |
|
451 | + ); |
|
452 | + $cmb->add_field( |
|
453 | + array( |
|
454 | + 'name' => __( 'Portion', 'lsx-health-plan' ), |
|
455 | + 'desc' => __( 'Add the recommended portion size i.e: 200mg', 'lsx-health-plan' ), |
|
456 | + 'id' => $this->slug . '_portion', |
|
457 | + 'type' => 'text', |
|
458 | + 'show_on_cb' => 'cmb2_hide_if_no_cats', |
|
459 | + ) |
|
460 | + ); |
|
461 | + $cmb = new_cmb2_box( |
|
462 | + array( |
|
463 | + 'id' => $this->slug . '_nutritional_metabox', |
|
464 | + 'title' => __( 'Nutritional Info', 'lsx-health-plan' ), |
|
465 | + 'object_types' => array( $this->slug ), // Post type |
|
466 | + 'context' => 'normal', |
|
467 | + 'priority' => 'high', |
|
468 | + 'show_names' => true, |
|
469 | + ) |
|
470 | + ); |
|
471 | + $cmb->add_field( |
|
472 | + array( |
|
473 | + 'name' => __( 'Energy', 'lsx-health-plan' ), |
|
474 | + 'id' => $this->slug . '_energy', |
|
475 | + 'desc' => __( 'Add the energy amount for the entire meal i.e: 700 kj', 'lsx-health-plan' ), |
|
476 | + 'type' => 'text', |
|
477 | + 'show_on_cb' => 'cmb2_hide_if_no_cats', |
|
478 | + ) |
|
479 | + ); |
|
480 | + $cmb->add_field( |
|
481 | + array( |
|
482 | + 'name' => __( 'Protein', 'lsx-health-plan' ), |
|
483 | + 'id' => $this->slug . '_protein', |
|
484 | + 'desc' => __( 'Add the protein amount for the entire meal i.e: 50 g', 'lsx-health-plan' ), |
|
485 | + 'type' => 'text', |
|
486 | + 'show_on_cb' => 'cmb2_hide_if_no_cats', |
|
487 | + ) |
|
488 | + ); |
|
489 | + $cmb->add_field( |
|
490 | + array( |
|
491 | + 'name' => __( 'Carbohydrates', 'lsx-health-plan' ), |
|
492 | + 'id' => $this->slug . '_carbohydrates', |
|
493 | + 'desc' => __( 'Add the carbohydrates amount for the entire meal i.e: 5 g', 'lsx-health-plan' ), |
|
494 | + 'type' => 'text', |
|
495 | + 'show_on_cb' => 'cmb2_hide_if_no_cats', |
|
496 | + ) |
|
497 | + ); |
|
498 | + $cmb->add_field( |
|
499 | + array( |
|
500 | + 'name' => __( 'Fibre', 'lsx-health-plan' ), |
|
501 | + 'id' => $this->slug . '_fibre', |
|
502 | + 'desc' => __( 'Add the fibre amount for the entire meal i.e: 5 g', 'lsx-health-plan' ), |
|
503 | + 'type' => 'text', |
|
504 | + 'show_on_cb' => 'cmb2_hide_if_no_cats', |
|
505 | + ) |
|
506 | + ); |
|
507 | + $cmb->add_field( |
|
508 | + array( |
|
509 | + 'name' => __( 'Fat', 'lsx-health-plan' ), |
|
510 | + 'id' => $this->slug . '_fat', |
|
511 | + 'desc' => __( 'Add the fat amount for the entire meal i.e: 20 g', 'lsx-health-plan' ), |
|
512 | + 'type' => 'text', |
|
513 | + 'show_on_cb' => 'cmb2_hide_if_no_cats', |
|
514 | + ) |
|
515 | + ); |
|
516 | + } |
|
517 | 517 | } |
@@ -39,27 +39,27 @@ discard block |
||
39 | 39 | * Constructor |
40 | 40 | */ |
41 | 41 | public function __construct() { |
42 | - add_action( 'init', array( $this, 'register_post_type' ) ); |
|
43 | - add_action( 'init', array( $this, 'taxonomy_setup' ) ); |
|
44 | - add_action( 'admin_menu', array( $this, 'register_menus' ) ); |
|
42 | + add_action('init', array($this, 'register_post_type')); |
|
43 | + add_action('init', array($this, 'taxonomy_setup')); |
|
44 | + add_action('admin_menu', array($this, 'register_menus')); |
|
45 | 45 | |
46 | 46 | // Frontend Actions and Filters. |
47 | - add_action( 'wp_head', array( $this, 'remove_archive_original_header' ), 99 ); |
|
48 | - add_action( 'lsx_content_wrap_before', array( $this, 'hp_lsx_archive_header' ) ); |
|
47 | + add_action('wp_head', array($this, 'remove_archive_original_header'), 99); |
|
48 | + add_action('lsx_content_wrap_before', array($this, 'hp_lsx_archive_header')); |
|
49 | 49 | |
50 | - add_filter( 'lsx_health_plan_archive_template', array( $this, 'enable_post_type' ), 10, 1 ); |
|
51 | - add_filter( 'lsx_health_plan_single_template', array( $this, 'enable_post_type' ), 10, 1 ); |
|
52 | - add_filter( 'lsx_health_plan_connections', array( $this, 'enable_connections' ), 10, 1 ); |
|
53 | - add_filter( 'get_the_archive_title', array( $this, 'get_the_archive_title' ), 100 ); |
|
54 | - add_filter( 'lsx_display_global_header_description', array( $this, 'disable_global_header_description' ), 100 ); |
|
50 | + add_filter('lsx_health_plan_archive_template', array($this, 'enable_post_type'), 10, 1); |
|
51 | + add_filter('lsx_health_plan_single_template', array($this, 'enable_post_type'), 10, 1); |
|
52 | + add_filter('lsx_health_plan_connections', array($this, 'enable_connections'), 10, 1); |
|
53 | + add_filter('get_the_archive_title', array($this, 'get_the_archive_title'), 100); |
|
54 | + add_filter('lsx_display_global_header_description', array($this, 'disable_global_header_description'), 100); |
|
55 | 55 | |
56 | 56 | //Breadcrumbs |
57 | - add_filter( 'wpseo_breadcrumb_links', array( $this, 'recipes_breadcrumb_filter' ), 30, 1 ); |
|
58 | - add_filter( 'woocommerce_get_breadcrumb', array( $this, 'recipes_breadcrumb_filter' ), 30, 1 ); |
|
57 | + add_filter('wpseo_breadcrumb_links', array($this, 'recipes_breadcrumb_filter'), 30, 1); |
|
58 | + add_filter('woocommerce_get_breadcrumb', array($this, 'recipes_breadcrumb_filter'), 30, 1); |
|
59 | 59 | |
60 | 60 | // Backend Actions and Filters. |
61 | - add_action( 'cmb2_admin_init', array( $this, 'featured_metabox' ) ); |
|
62 | - add_action( 'cmb2_admin_init', array( $this, 'details_metaboxes' ) ); |
|
61 | + add_action('cmb2_admin_init', array($this, 'featured_metabox')); |
|
62 | + add_action('cmb2_admin_init', array($this, 'details_metaboxes')); |
|
63 | 63 | } |
64 | 64 | |
65 | 65 | /** |
@@ -72,7 +72,7 @@ discard block |
||
72 | 72 | public static function get_instance() { |
73 | 73 | |
74 | 74 | // If the single instance hasn't been set, set it now. |
75 | - if ( null === self::$instance ) { |
|
75 | + if (null === self::$instance) { |
|
76 | 76 | self::$instance = new self(); |
77 | 77 | } |
78 | 78 | |
@@ -85,21 +85,21 @@ discard block |
||
85 | 85 | */ |
86 | 86 | public function register_post_type() { |
87 | 87 | $this->labels = array( |
88 | - 'name' => esc_html__( 'Recipes', 'lsx-health-plan' ), |
|
89 | - 'singular_name' => esc_html__( 'Recipe', 'lsx-health-plan' ), |
|
90 | - 'add_new' => esc_html_x( 'Add New', 'post type general name', 'lsx-health-plan' ), |
|
91 | - 'add_new_item' => esc_html__( 'Add New', 'lsx-health-plan' ), |
|
92 | - 'edit_item' => esc_html__( 'Edit', 'lsx-health-plan' ), |
|
93 | - 'new_item' => esc_html__( 'New', 'lsx-health-plan' ), |
|
94 | - 'all_items' => esc_html__( 'All Recipes', 'lsx-health-plan' ), |
|
95 | - 'view_item' => esc_html__( 'View', 'lsx-health-plan' ), |
|
96 | - 'search_items' => esc_html__( 'Search', 'lsx-health-plan' ), |
|
97 | - 'not_found' => esc_html__( 'None found', 'lsx-health-plan' ), |
|
98 | - 'not_found_in_trash' => esc_html__( 'None found in Trash', 'lsx-health-plan' ), |
|
88 | + 'name' => esc_html__('Recipes', 'lsx-health-plan'), |
|
89 | + 'singular_name' => esc_html__('Recipe', 'lsx-health-plan'), |
|
90 | + 'add_new' => esc_html_x('Add New', 'post type general name', 'lsx-health-plan'), |
|
91 | + 'add_new_item' => esc_html__('Add New', 'lsx-health-plan'), |
|
92 | + 'edit_item' => esc_html__('Edit', 'lsx-health-plan'), |
|
93 | + 'new_item' => esc_html__('New', 'lsx-health-plan'), |
|
94 | + 'all_items' => esc_html__('All Recipes', 'lsx-health-plan'), |
|
95 | + 'view_item' => esc_html__('View', 'lsx-health-plan'), |
|
96 | + 'search_items' => esc_html__('Search', 'lsx-health-plan'), |
|
97 | + 'not_found' => esc_html__('None found', 'lsx-health-plan'), |
|
98 | + 'not_found_in_trash' => esc_html__('None found in Trash', 'lsx-health-plan'), |
|
99 | 99 | 'parent_item_colon' => '', |
100 | - 'menu_name' => esc_html__( 'Recipes', 'lsx-health-plan' ), |
|
100 | + 'menu_name' => esc_html__('Recipes', 'lsx-health-plan'), |
|
101 | 101 | ); |
102 | - $args = array( |
|
102 | + $args = array( |
|
103 | 103 | 'labels' => $this->labels, |
104 | 104 | 'public' => true, |
105 | 105 | 'publicly_queryable' => true, |
@@ -122,7 +122,7 @@ discard block |
||
122 | 122 | 'custom-fields', |
123 | 123 | ), |
124 | 124 | ); |
125 | - register_post_type( 'recipe', $args ); |
|
125 | + register_post_type('recipe', $args); |
|
126 | 126 | } |
127 | 127 | |
128 | 128 | /** |
@@ -131,9 +131,9 @@ discard block |
||
131 | 131 | * @return void |
132 | 132 | */ |
133 | 133 | public function register_menus() { |
134 | - add_submenu_page( 'edit.php?post_type=meal', esc_html__( 'Recipes', 'lsx-health-plan' ), esc_html__( 'Recipes', 'lsx-health-plan' ), 'edit_posts', 'edit.php?post_type=recipe' ); |
|
135 | - add_submenu_page( 'edit.php?post_type=meal', esc_html__( 'Recipe Types', 'lsx-health-plan' ), esc_html__( 'Recipe Types', 'lsx-health-plan' ), 'edit_posts', 'edit-tags.php?taxonomy=recipe-type&post_type=recipe' ); |
|
136 | - add_submenu_page( 'edit.php?post_type=meal', esc_html__( 'Cuisines', 'lsx-health-plan' ), esc_html__( 'Cuisines', 'lsx-health-plan' ), 'edit_posts', 'edit-tags.php?taxonomy=recipe-cuisine&post_type=recipe' ); |
|
134 | + add_submenu_page('edit.php?post_type=meal', esc_html__('Recipes', 'lsx-health-plan'), esc_html__('Recipes', 'lsx-health-plan'), 'edit_posts', 'edit.php?post_type=recipe'); |
|
135 | + add_submenu_page('edit.php?post_type=meal', esc_html__('Recipe Types', 'lsx-health-plan'), esc_html__('Recipe Types', 'lsx-health-plan'), 'edit_posts', 'edit-tags.php?taxonomy=recipe-type&post_type=recipe'); |
|
136 | + add_submenu_page('edit.php?post_type=meal', esc_html__('Cuisines', 'lsx-health-plan'), esc_html__('Cuisines', 'lsx-health-plan'), 'edit_posts', 'edit-tags.php?taxonomy=recipe-cuisine&post_type=recipe'); |
|
137 | 137 | } |
138 | 138 | |
139 | 139 | /** |
@@ -141,19 +141,19 @@ discard block |
||
141 | 141 | */ |
142 | 142 | public function taxonomy_setup() { |
143 | 143 | $labels = array( |
144 | - 'name' => esc_html_x( 'Cuisine', 'taxonomy general name', 'lsx-health-plan' ), |
|
145 | - 'singular_name' => esc_html_x( 'Cuisines', 'taxonomy singular name', 'lsx-health-plan' ), |
|
146 | - 'search_items' => esc_html__( 'Search', 'lsx-health-plan' ), |
|
147 | - 'all_items' => esc_html__( 'All', 'lsx-health-plan' ), |
|
148 | - 'parent_item' => esc_html__( 'Parent', 'lsx-health-plan' ), |
|
149 | - 'parent_item_colon' => esc_html__( 'Parent:', 'lsx-health-plan' ), |
|
150 | - 'edit_item' => esc_html__( 'Edit', 'lsx-health-plan' ), |
|
151 | - 'update_item' => esc_html__( 'Update', 'lsx-health-plan' ), |
|
152 | - 'add_new_item' => esc_html__( 'Add New', 'lsx-health-plan' ), |
|
153 | - 'new_item_name' => esc_html__( 'New Name', 'lsx-health-plan' ), |
|
154 | - 'menu_name' => esc_html__( 'Cuisines', 'lsx-health-plan' ), |
|
144 | + 'name' => esc_html_x('Cuisine', 'taxonomy general name', 'lsx-health-plan'), |
|
145 | + 'singular_name' => esc_html_x('Cuisines', 'taxonomy singular name', 'lsx-health-plan'), |
|
146 | + 'search_items' => esc_html__('Search', 'lsx-health-plan'), |
|
147 | + 'all_items' => esc_html__('All', 'lsx-health-plan'), |
|
148 | + 'parent_item' => esc_html__('Parent', 'lsx-health-plan'), |
|
149 | + 'parent_item_colon' => esc_html__('Parent:', 'lsx-health-plan'), |
|
150 | + 'edit_item' => esc_html__('Edit', 'lsx-health-plan'), |
|
151 | + 'update_item' => esc_html__('Update', 'lsx-health-plan'), |
|
152 | + 'add_new_item' => esc_html__('Add New', 'lsx-health-plan'), |
|
153 | + 'new_item_name' => esc_html__('New Name', 'lsx-health-plan'), |
|
154 | + 'menu_name' => esc_html__('Cuisines', 'lsx-health-plan'), |
|
155 | 155 | ); |
156 | - $args = array( |
|
156 | + $args = array( |
|
157 | 157 | 'hierarchical' => true, |
158 | 158 | 'labels' => $labels, |
159 | 159 | 'show_ui' => true, |
@@ -164,22 +164,22 @@ discard block |
||
164 | 164 | 'slug' => 'recipe-cuisine', |
165 | 165 | ), |
166 | 166 | ); |
167 | - register_taxonomy( 'recipe-cuisine', array( $this->slug ), $args ); |
|
167 | + register_taxonomy('recipe-cuisine', array($this->slug), $args); |
|
168 | 168 | |
169 | 169 | $labels = array( |
170 | - 'name' => esc_html_x( 'Recipe Type', 'taxonomy general name', 'lsx-health-plan' ), |
|
171 | - 'singular_name' => esc_html_x( 'Recipe Types', 'taxonomy singular name', 'lsx-health-plan' ), |
|
172 | - 'search_items' => esc_html__( 'Search', 'lsx-health-plan' ), |
|
173 | - 'all_items' => esc_html__( 'All', 'lsx-health-plan' ), |
|
174 | - 'parent_item' => esc_html__( 'Parent', 'lsx-health-plan' ), |
|
175 | - 'parent_item_colon' => esc_html__( 'Parent:', 'lsx-health-plan' ), |
|
176 | - 'edit_item' => esc_html__( 'Edit', 'lsx-health-plan' ), |
|
177 | - 'update_item' => esc_html__( 'Update', 'lsx-health-plan' ), |
|
178 | - 'add_new_item' => esc_html__( 'Add New', 'lsx-health-plan' ), |
|
179 | - 'new_item_name' => esc_html__( 'New Name', 'lsx-health-plan' ), |
|
180 | - 'menu_name' => esc_html__( 'Types', 'lsx-health-plan' ), |
|
170 | + 'name' => esc_html_x('Recipe Type', 'taxonomy general name', 'lsx-health-plan'), |
|
171 | + 'singular_name' => esc_html_x('Recipe Types', 'taxonomy singular name', 'lsx-health-plan'), |
|
172 | + 'search_items' => esc_html__('Search', 'lsx-health-plan'), |
|
173 | + 'all_items' => esc_html__('All', 'lsx-health-plan'), |
|
174 | + 'parent_item' => esc_html__('Parent', 'lsx-health-plan'), |
|
175 | + 'parent_item_colon' => esc_html__('Parent:', 'lsx-health-plan'), |
|
176 | + 'edit_item' => esc_html__('Edit', 'lsx-health-plan'), |
|
177 | + 'update_item' => esc_html__('Update', 'lsx-health-plan'), |
|
178 | + 'add_new_item' => esc_html__('Add New', 'lsx-health-plan'), |
|
179 | + 'new_item_name' => esc_html__('New Name', 'lsx-health-plan'), |
|
180 | + 'menu_name' => esc_html__('Types', 'lsx-health-plan'), |
|
181 | 181 | ); |
182 | - $args = array( |
|
182 | + $args = array( |
|
183 | 183 | 'hierarchical' => true, |
184 | 184 | 'labels' => $labels, |
185 | 185 | 'show_ui' => true, |
@@ -190,7 +190,7 @@ discard block |
||
190 | 190 | 'slug' => 'recipe-type', |
191 | 191 | ), |
192 | 192 | ); |
193 | - register_taxonomy( 'recipe-type', array( $this->slug ), $args ); |
|
193 | + register_taxonomy('recipe-type', array($this->slug), $args); |
|
194 | 194 | } |
195 | 195 | |
196 | 196 | /** |
@@ -199,7 +199,7 @@ discard block |
||
199 | 199 | * @param array $post_types |
200 | 200 | * @return array |
201 | 201 | */ |
202 | - public function enable_post_type( $post_types = array() ) { |
|
202 | + public function enable_post_type($post_types = array()) { |
|
203 | 203 | $post_types[] = $this->slug; |
204 | 204 | return $post_types; |
205 | 205 | } |
@@ -210,7 +210,7 @@ discard block |
||
210 | 210 | * @param array $connections |
211 | 211 | * @return void |
212 | 212 | */ |
213 | - public function enable_connections( $connections = array() ) { |
|
213 | + public function enable_connections($connections = array()) { |
|
214 | 214 | $connections['recipe']['connected_plans'] = 'connected_recipes'; |
215 | 215 | $connections['plan']['connected_recipes'] = 'connected_plans'; |
216 | 216 | return $connections; |
@@ -222,45 +222,45 @@ discard block |
||
222 | 222 | * @param string $title the term title. |
223 | 223 | * @return string |
224 | 224 | */ |
225 | - public function get_the_archive_title( $title ) { |
|
226 | - if ( is_post_type_archive( 'recipe' ) ) { |
|
227 | - $title = __( 'Recipes', 'lsx-health-plan' ); |
|
225 | + public function get_the_archive_title($title) { |
|
226 | + if (is_post_type_archive('recipe')) { |
|
227 | + $title = __('Recipes', 'lsx-health-plan'); |
|
228 | 228 | } |
229 | - if ( is_post_type_archive( 'exercise' ) ) { |
|
230 | - $title = __( 'Exercises', 'lsx-health-plan' ); |
|
229 | + if (is_post_type_archive('exercise')) { |
|
230 | + $title = __('Exercises', 'lsx-health-plan'); |
|
231 | 231 | } |
232 | - if ( is_tax( 'recipe-type' ) ) { |
|
232 | + if (is_tax('recipe-type')) { |
|
233 | 233 | $queried_object = get_queried_object(); |
234 | - if ( isset( $queried_object->name ) ) { |
|
235 | - $title = $queried_object->name . ' ' . __( 'Recipes', 'lsx-health-plan' ); |
|
234 | + if (isset($queried_object->name)) { |
|
235 | + $title = $queried_object->name . ' ' . __('Recipes', 'lsx-health-plan'); |
|
236 | 236 | } |
237 | 237 | } |
238 | 238 | return $title; |
239 | 239 | } |
240 | 240 | |
241 | 241 | public function remove_archive_original_header() { |
242 | - if ( is_post_type_archive( 'recipe' ) || is_post_type_archive( 'exercise' ) ) { |
|
243 | - remove_action( 'lsx_content_wrap_before', 'lsx_global_header' ); |
|
242 | + if (is_post_type_archive('recipe') || is_post_type_archive('exercise')) { |
|
243 | + remove_action('lsx_content_wrap_before', 'lsx_global_header'); |
|
244 | 244 | } |
245 | - if ( is_singular( 'recipe' ) || is_singular( 'exercise' ) ) { |
|
246 | - remove_action( 'lsx_content_wrap_before', 'lsx_global_header' ); |
|
245 | + if (is_singular('recipe') || is_singular('exercise')) { |
|
246 | + remove_action('lsx_content_wrap_before', 'lsx_global_header'); |
|
247 | 247 | } |
248 | - if ( ! is_post_type_archive() ) { |
|
249 | - add_action( 'lsx_content_wrap_before', 'lsx_health_plan_recipe_archive_description', 11 ); |
|
248 | + if ( ! is_post_type_archive()) { |
|
249 | + add_action('lsx_content_wrap_before', 'lsx_health_plan_recipe_archive_description', 11); |
|
250 | 250 | } |
251 | 251 | } |
252 | 252 | |
253 | 253 | public function hp_lsx_archive_header() { |
254 | - if ( is_post_type_archive( 'recipe' ) || is_post_type_archive( 'exercise' ) ) { |
|
254 | + if (is_post_type_archive('recipe') || is_post_type_archive('exercise')) { |
|
255 | 255 | ?> |
256 | 256 | <div class="archive-header-wrapper banner-archive"> |
257 | 257 | <?php lsx_global_header_inner_bottom(); ?> |
258 | 258 | <header class="archive-header"> |
259 | 259 | <h1 class="archive-title"> |
260 | - <?php if ( has_post_format() && ! is_category() && ! is_tag() && ! is_date() && ! is_tax( 'post_format' ) ) { ?> |
|
261 | - <?php the_archive_title( esc_html__( 'Type:', 'lsx' ) ); ?> |
|
260 | + <?php if (has_post_format() && ! is_category() && ! is_tag() && ! is_date() && ! is_tax('post_format')) { ?> |
|
261 | + <?php the_archive_title(esc_html__('Type:', 'lsx')); ?> |
|
262 | 262 | <?php } else { ?> |
263 | - <?php echo wp_kses_post( apply_filters( 'lsx_global_header_title', get_the_archive_title() ) ); ?> |
|
263 | + <?php echo wp_kses_post(apply_filters('lsx_global_header_title', get_the_archive_title())); ?> |
|
264 | 264 | <?php } ?> |
265 | 265 | </h1> |
266 | 266 | |
@@ -279,8 +279,8 @@ discard block |
||
279 | 279 | * @param boolean $disable |
280 | 280 | * @return boolean |
281 | 281 | */ |
282 | - public function disable_global_header_description( $disable ) { |
|
283 | - if ( is_tax( 'recipe-type' ) ) { |
|
282 | + public function disable_global_header_description($disable) { |
|
283 | + if (is_tax('recipe-type')) { |
|
284 | 284 | $disable = true; |
285 | 285 | } |
286 | 286 | return $disable; |
@@ -292,21 +292,21 @@ discard block |
||
292 | 292 | * @var array $crumbs |
293 | 293 | * @return array |
294 | 294 | */ |
295 | - public function recipes_breadcrumb_filter( $crumbs ) { |
|
296 | - $recipe = \lsx_health_plan\functions\get_option( 'endpoint_recipe', 'recipe' ); |
|
297 | - $recipes = \lsx_health_plan\functions\get_option( 'endpoint_recipe_archive', 'recipes' ); |
|
298 | - $url = get_post_type_archive_link( 'recipe' ); |
|
295 | + public function recipes_breadcrumb_filter($crumbs) { |
|
296 | + $recipe = \lsx_health_plan\functions\get_option('endpoint_recipe', 'recipe'); |
|
297 | + $recipes = \lsx_health_plan\functions\get_option('endpoint_recipe_archive', 'recipes'); |
|
298 | + $url = get_post_type_archive_link('recipe'); |
|
299 | 299 | |
300 | - if ( is_singular( 'recipe' ) ) { |
|
300 | + if (is_singular('recipe')) { |
|
301 | 301 | $recipe_name = get_the_title(); |
302 | - $term_obj_list = get_the_terms( get_the_ID(), 'recipe-type' ); |
|
302 | + $term_obj_list = get_the_terms(get_the_ID(), 'recipe-type'); |
|
303 | 303 | $recipe_type = $term_obj_list[0]->name; |
304 | - $recipe_type_url = get_term_link( $term_obj_list[0]->term_id ); |
|
304 | + $recipe_type_url = get_term_link($term_obj_list[0]->term_id); |
|
305 | 305 | |
306 | 306 | $new_crumbs = array(); |
307 | 307 | $new_crumbs[0] = $crumbs[0]; |
308 | 308 | |
309 | - if ( function_exists( 'woocommerce_breadcrumb' ) ) { |
|
309 | + if (function_exists('woocommerce_breadcrumb')) { |
|
310 | 310 | $new_crumbs[1] = array( |
311 | 311 | 0 => $recipes, |
312 | 312 | 1 => $url, |
@@ -333,15 +333,15 @@ discard block |
||
333 | 333 | } |
334 | 334 | $crumbs = $new_crumbs; |
335 | 335 | } |
336 | - if ( is_tax( 'recipe-type' ) || is_tax( 'recipe-cuisine' ) ) { |
|
337 | - $term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) ); |
|
336 | + if (is_tax('recipe-type') || is_tax('recipe-cuisine')) { |
|
337 | + $term = get_term_by('slug', get_query_var('term'), get_query_var('taxonomy')); |
|
338 | 338 | |
339 | - $single_term_title = str_replace( '-', ' ', $term->taxonomy ) . ': ' . $term->name; |
|
339 | + $single_term_title = str_replace('-', ' ', $term->taxonomy) . ': ' . $term->name; |
|
340 | 340 | |
341 | 341 | $new_crumbs = array(); |
342 | 342 | $new_crumbs[0] = $crumbs[0]; |
343 | 343 | |
344 | - if ( function_exists( 'woocommerce_breadcrumb' ) ) { |
|
344 | + if (function_exists('woocommerce_breadcrumb')) { |
|
345 | 345 | $new_crumbs[1] = array( |
346 | 346 | 0 => $recipes, |
347 | 347 | 1 => $url, |
@@ -360,12 +360,12 @@ discard block |
||
360 | 360 | } |
361 | 361 | $crumbs = $new_crumbs; |
362 | 362 | } |
363 | - if ( is_post_type_archive( 'recipe' ) ) { |
|
363 | + if (is_post_type_archive('recipe')) { |
|
364 | 364 | |
365 | 365 | $new_crumbs = array(); |
366 | 366 | $new_crumbs[0] = $crumbs[0]; |
367 | 367 | |
368 | - if ( function_exists( 'woocommerce_breadcrumb' ) ) { |
|
368 | + if (function_exists('woocommerce_breadcrumb')) { |
|
369 | 369 | $new_crumbs[1] = array( |
370 | 370 | 0 => $recipes, |
371 | 371 | ); |
@@ -386,8 +386,8 @@ discard block |
||
386 | 386 | $cmb = new_cmb2_box( |
387 | 387 | array( |
388 | 388 | 'id' => $this->slug . '_featured_metabox', |
389 | - 'title' => __( 'Featured', 'lsx-health-plan' ), |
|
390 | - 'object_types' => array( $this->slug ), |
|
389 | + 'title' => __('Featured', 'lsx-health-plan'), |
|
390 | + 'object_types' => array($this->slug), |
|
391 | 391 | 'context' => 'side', |
392 | 392 | 'priority' => 'high', |
393 | 393 | 'show_names' => true, |
@@ -395,8 +395,8 @@ discard block |
||
395 | 395 | ); |
396 | 396 | $cmb->add_field( |
397 | 397 | array( |
398 | - 'name' => __( 'Featured', 'lsx-health-plan' ), |
|
399 | - 'desc' => __( 'Enable the checkbox to feature this recipe, featured recipes display in any page that has the recipe shortcode: [lsx_health_plan_featured_recipes_block]', 'lsx-health-plan' ), |
|
398 | + 'name' => __('Featured', 'lsx-health-plan'), |
|
399 | + 'desc' => __('Enable the checkbox to feature this recipe, featured recipes display in any page that has the recipe shortcode: [lsx_health_plan_featured_recipes_block]', 'lsx-health-plan'), |
|
400 | 400 | 'id' => $this->slug . '_featured', |
401 | 401 | 'type' => 'checkbox', |
402 | 402 | 'show_on_cb' => 'cmb2_hide_if_no_cats', |
@@ -411,8 +411,8 @@ discard block |
||
411 | 411 | $cmb = new_cmb2_box( |
412 | 412 | array( |
413 | 413 | 'id' => $this->slug . '_details_metabox', |
414 | - 'title' => __( 'Cooking Info', 'lsx-health-plan' ), |
|
415 | - 'object_types' => array( $this->slug ), // Post type |
|
414 | + 'title' => __('Cooking Info', 'lsx-health-plan'), |
|
415 | + 'object_types' => array($this->slug), // Post type |
|
416 | 416 | 'context' => 'normal', |
417 | 417 | 'priority' => 'high', |
418 | 418 | 'show_names' => true, |
@@ -420,27 +420,27 @@ discard block |
||
420 | 420 | ); |
421 | 421 | $cmb->add_field( |
422 | 422 | array( |
423 | - 'name' => __( 'Prep Time', 'lsx-health-plan' ), |
|
423 | + 'name' => __('Prep Time', 'lsx-health-plan'), |
|
424 | 424 | 'id' => $this->slug . '_prep_time', |
425 | - 'desc' => __( 'Add the preparation time for the entire meal i.e: 25 mins', 'lsx-health-plan' ), |
|
425 | + 'desc' => __('Add the preparation time for the entire meal i.e: 25 mins', 'lsx-health-plan'), |
|
426 | 426 | 'type' => 'text', |
427 | 427 | 'show_on_cb' => 'cmb2_hide_if_no_cats', |
428 | 428 | ) |
429 | 429 | ); |
430 | 430 | $cmb->add_field( |
431 | 431 | array( |
432 | - 'name' => __( 'Cooking Time', 'lsx-health-plan' ), |
|
432 | + 'name' => __('Cooking Time', 'lsx-health-plan'), |
|
433 | 433 | 'id' => $this->slug . '_cooking_time', |
434 | - 'desc' => __( 'Add the cooking time i.e: 15 mins', 'lsx-health-plan' ), |
|
434 | + 'desc' => __('Add the cooking time i.e: 15 mins', 'lsx-health-plan'), |
|
435 | 435 | 'type' => 'text', |
436 | 436 | 'show_on_cb' => 'cmb2_hide_if_no_cats', |
437 | 437 | ) |
438 | 438 | ); |
439 | 439 | $cmb->add_field( |
440 | 440 | array( |
441 | - 'name' => __( 'Serves', 'lsx-health-plan' ), |
|
441 | + 'name' => __('Serves', 'lsx-health-plan'), |
|
442 | 442 | 'id' => $this->slug . '_serves', |
443 | - 'desc' => __( 'Add the recommended serving size i.e: 6', 'lsx-health-plan' ), |
|
443 | + 'desc' => __('Add the recommended serving size i.e: 6', 'lsx-health-plan'), |
|
444 | 444 | 'type' => 'text', |
445 | 445 | 'show_on_cb' => 'cmb2_hide_if_no_cats', |
446 | 446 | 'attributes' => array( |
@@ -451,8 +451,8 @@ discard block |
||
451 | 451 | ); |
452 | 452 | $cmb->add_field( |
453 | 453 | array( |
454 | - 'name' => __( 'Portion', 'lsx-health-plan' ), |
|
455 | - 'desc' => __( 'Add the recommended portion size i.e: 200mg', 'lsx-health-plan' ), |
|
454 | + 'name' => __('Portion', 'lsx-health-plan'), |
|
455 | + 'desc' => __('Add the recommended portion size i.e: 200mg', 'lsx-health-plan'), |
|
456 | 456 | 'id' => $this->slug . '_portion', |
457 | 457 | 'type' => 'text', |
458 | 458 | 'show_on_cb' => 'cmb2_hide_if_no_cats', |
@@ -461,8 +461,8 @@ discard block |
||
461 | 461 | $cmb = new_cmb2_box( |
462 | 462 | array( |
463 | 463 | 'id' => $this->slug . '_nutritional_metabox', |
464 | - 'title' => __( 'Nutritional Info', 'lsx-health-plan' ), |
|
465 | - 'object_types' => array( $this->slug ), // Post type |
|
464 | + 'title' => __('Nutritional Info', 'lsx-health-plan'), |
|
465 | + 'object_types' => array($this->slug), // Post type |
|
466 | 466 | 'context' => 'normal', |
467 | 467 | 'priority' => 'high', |
468 | 468 | 'show_names' => true, |
@@ -470,45 +470,45 @@ discard block |
||
470 | 470 | ); |
471 | 471 | $cmb->add_field( |
472 | 472 | array( |
473 | - 'name' => __( 'Energy', 'lsx-health-plan' ), |
|
473 | + 'name' => __('Energy', 'lsx-health-plan'), |
|
474 | 474 | 'id' => $this->slug . '_energy', |
475 | - 'desc' => __( 'Add the energy amount for the entire meal i.e: 700 kj', 'lsx-health-plan' ), |
|
475 | + 'desc' => __('Add the energy amount for the entire meal i.e: 700 kj', 'lsx-health-plan'), |
|
476 | 476 | 'type' => 'text', |
477 | 477 | 'show_on_cb' => 'cmb2_hide_if_no_cats', |
478 | 478 | ) |
479 | 479 | ); |
480 | 480 | $cmb->add_field( |
481 | 481 | array( |
482 | - 'name' => __( 'Protein', 'lsx-health-plan' ), |
|
482 | + 'name' => __('Protein', 'lsx-health-plan'), |
|
483 | 483 | 'id' => $this->slug . '_protein', |
484 | - 'desc' => __( 'Add the protein amount for the entire meal i.e: 50 g', 'lsx-health-plan' ), |
|
484 | + 'desc' => __('Add the protein amount for the entire meal i.e: 50 g', 'lsx-health-plan'), |
|
485 | 485 | 'type' => 'text', |
486 | 486 | 'show_on_cb' => 'cmb2_hide_if_no_cats', |
487 | 487 | ) |
488 | 488 | ); |
489 | 489 | $cmb->add_field( |
490 | 490 | array( |
491 | - 'name' => __( 'Carbohydrates', 'lsx-health-plan' ), |
|
491 | + 'name' => __('Carbohydrates', 'lsx-health-plan'), |
|
492 | 492 | 'id' => $this->slug . '_carbohydrates', |
493 | - 'desc' => __( 'Add the carbohydrates amount for the entire meal i.e: 5 g', 'lsx-health-plan' ), |
|
493 | + 'desc' => __('Add the carbohydrates amount for the entire meal i.e: 5 g', 'lsx-health-plan'), |
|
494 | 494 | 'type' => 'text', |
495 | 495 | 'show_on_cb' => 'cmb2_hide_if_no_cats', |
496 | 496 | ) |
497 | 497 | ); |
498 | 498 | $cmb->add_field( |
499 | 499 | array( |
500 | - 'name' => __( 'Fibre', 'lsx-health-plan' ), |
|
500 | + 'name' => __('Fibre', 'lsx-health-plan'), |
|
501 | 501 | 'id' => $this->slug . '_fibre', |
502 | - 'desc' => __( 'Add the fibre amount for the entire meal i.e: 5 g', 'lsx-health-plan' ), |
|
502 | + 'desc' => __('Add the fibre amount for the entire meal i.e: 5 g', 'lsx-health-plan'), |
|
503 | 503 | 'type' => 'text', |
504 | 504 | 'show_on_cb' => 'cmb2_hide_if_no_cats', |
505 | 505 | ) |
506 | 506 | ); |
507 | 507 | $cmb->add_field( |
508 | 508 | array( |
509 | - 'name' => __( 'Fat', 'lsx-health-plan' ), |
|
509 | + 'name' => __('Fat', 'lsx-health-plan'), |
|
510 | 510 | 'id' => $this->slug . '_fat', |
511 | - 'desc' => __( 'Add the fat amount for the entire meal i.e: 20 g', 'lsx-health-plan' ), |
|
511 | + 'desc' => __('Add the fat amount for the entire meal i.e: 20 g', 'lsx-health-plan'), |
|
512 | 512 | 'type' => 'text', |
513 | 513 | 'show_on_cb' => 'cmb2_hide_if_no_cats', |
514 | 514 | ) |
@@ -10,208 +10,208 @@ discard block |
||
10 | 10 | */ |
11 | 11 | class Plan { |
12 | 12 | |
13 | - /** |
|
14 | - * Holds class instance |
|
15 | - * |
|
16 | - * @since 1.0.0 |
|
17 | - * |
|
18 | - * @var object \lsx_health_plan\classes\Plan() |
|
19 | - */ |
|
20 | - protected static $instance = null; |
|
21 | - |
|
22 | - /** |
|
23 | - * Holds post_type slug used as an index |
|
24 | - * |
|
25 | - * @since 1.0.0 |
|
26 | - * |
|
27 | - * @var string |
|
28 | - */ |
|
29 | - public $slug = 'plan'; |
|
30 | - |
|
31 | - /** |
|
32 | - * Constructor |
|
33 | - */ |
|
34 | - public function __construct() { |
|
35 | - |
|
36 | - add_action( 'init', array( $this, 'register_post_type' ) ); |
|
37 | - add_action( 'init', array( $this, 'plan_type_taxonomy_setup' ) ); |
|
38 | - add_action( 'init', array( $this, 'week_taxonomy_setup' ) ); |
|
39 | - |
|
40 | - // Icons for the plan types. |
|
41 | - add_action( 'create_term', array( $this, 'save_meta' ), 10, 2 ); |
|
42 | - add_action( 'edit_term', array( $this, 'save_meta' ), 10, 2 ); |
|
43 | - $prefix_taxonomy = 'plan-type'; |
|
44 | - add_action( sprintf( '%s_edit_form_fields', $prefix_taxonomy ), array( $this, 'add_thumbnail_form_field' ), 3, 1 ); |
|
45 | - |
|
46 | - // Register the Metaboxes. |
|
47 | - add_action( 'cmb2_admin_init', array( $this, 'featured_metabox' ), 5 ); |
|
48 | - add_action( 'cmb2_admin_init', array( $this, 'details_metaboxes' ), 5 ); |
|
49 | - add_action( 'cmb2_admin_init', array( $this, 'plan_connections' ), 5 ); |
|
50 | - add_action( 'cmb2_admin_init', array( $this, 'sections_metabox_loop' ), 1 ); |
|
51 | - |
|
52 | - add_filter( 'get_the_archive_title', array( $this, 'get_the_archive_title' ), 100 ); |
|
53 | - //add_filter( 'lsx_global_header_title', array( $this, 'hp_recipe_header_title' ), 200, 1 ); |
|
54 | - |
|
55 | - // Template Redirects. |
|
56 | - add_filter( 'lsx_health_plan_archive_template', array( $this, 'enable_post_type' ), 10, 1 ); |
|
57 | - add_filter( 'lsx_health_plan_single_template', array( $this, 'enable_post_type' ), 10, 1 ); |
|
58 | - |
|
59 | - // Plan Archive Actions. |
|
60 | - add_action( 'pre_get_posts', array( $this, 'set_parent_only' ), 10, 1 ); |
|
61 | - add_filter( 'get_the_archive_title', array( $this, 'get_the_archive_title' ), 100 ); |
|
62 | - add_action( 'lsx_content_top', 'lsx_hp_plan_archive_filters', 10, 1 ); |
|
63 | - add_filter( 'lsx_hp_disable_plan_archive_filters', '\lsx_health_plan\functions\plan\is_search_enabled', 10, 1 ); |
|
64 | - add_filter( 'lsx_hp_disable_plan_archive_filters', '\lsx_health_plan\functions\plan\is_filters_disabled', 10, 1 ); |
|
65 | - |
|
66 | - //Breadcrumbs |
|
67 | - add_filter( 'wpseo_breadcrumb_links', array( $this, 'plan_breadcrumb_filter' ), 30, 1 ); |
|
68 | - add_filter( 'woocommerce_get_breadcrumb', array( $this, 'plan_breadcrumb_filter' ), 30, 1 ); |
|
13 | + /** |
|
14 | + * Holds class instance |
|
15 | + * |
|
16 | + * @since 1.0.0 |
|
17 | + * |
|
18 | + * @var object \lsx_health_plan\classes\Plan() |
|
19 | + */ |
|
20 | + protected static $instance = null; |
|
21 | + |
|
22 | + /** |
|
23 | + * Holds post_type slug used as an index |
|
24 | + * |
|
25 | + * @since 1.0.0 |
|
26 | + * |
|
27 | + * @var string |
|
28 | + */ |
|
29 | + public $slug = 'plan'; |
|
30 | + |
|
31 | + /** |
|
32 | + * Constructor |
|
33 | + */ |
|
34 | + public function __construct() { |
|
35 | + |
|
36 | + add_action( 'init', array( $this, 'register_post_type' ) ); |
|
37 | + add_action( 'init', array( $this, 'plan_type_taxonomy_setup' ) ); |
|
38 | + add_action( 'init', array( $this, 'week_taxonomy_setup' ) ); |
|
39 | + |
|
40 | + // Icons for the plan types. |
|
41 | + add_action( 'create_term', array( $this, 'save_meta' ), 10, 2 ); |
|
42 | + add_action( 'edit_term', array( $this, 'save_meta' ), 10, 2 ); |
|
43 | + $prefix_taxonomy = 'plan-type'; |
|
44 | + add_action( sprintf( '%s_edit_form_fields', $prefix_taxonomy ), array( $this, 'add_thumbnail_form_field' ), 3, 1 ); |
|
45 | + |
|
46 | + // Register the Metaboxes. |
|
47 | + add_action( 'cmb2_admin_init', array( $this, 'featured_metabox' ), 5 ); |
|
48 | + add_action( 'cmb2_admin_init', array( $this, 'details_metaboxes' ), 5 ); |
|
49 | + add_action( 'cmb2_admin_init', array( $this, 'plan_connections' ), 5 ); |
|
50 | + add_action( 'cmb2_admin_init', array( $this, 'sections_metabox_loop' ), 1 ); |
|
51 | + |
|
52 | + add_filter( 'get_the_archive_title', array( $this, 'get_the_archive_title' ), 100 ); |
|
53 | + //add_filter( 'lsx_global_header_title', array( $this, 'hp_recipe_header_title' ), 200, 1 ); |
|
54 | + |
|
55 | + // Template Redirects. |
|
56 | + add_filter( 'lsx_health_plan_archive_template', array( $this, 'enable_post_type' ), 10, 1 ); |
|
57 | + add_filter( 'lsx_health_plan_single_template', array( $this, 'enable_post_type' ), 10, 1 ); |
|
58 | + |
|
59 | + // Plan Archive Actions. |
|
60 | + add_action( 'pre_get_posts', array( $this, 'set_parent_only' ), 10, 1 ); |
|
61 | + add_filter( 'get_the_archive_title', array( $this, 'get_the_archive_title' ), 100 ); |
|
62 | + add_action( 'lsx_content_top', 'lsx_hp_plan_archive_filters', 10, 1 ); |
|
63 | + add_filter( 'lsx_hp_disable_plan_archive_filters', '\lsx_health_plan\functions\plan\is_search_enabled', 10, 1 ); |
|
64 | + add_filter( 'lsx_hp_disable_plan_archive_filters', '\lsx_health_plan\functions\plan\is_filters_disabled', 10, 1 ); |
|
65 | + |
|
66 | + //Breadcrumbs |
|
67 | + add_filter( 'wpseo_breadcrumb_links', array( $this, 'plan_breadcrumb_filter' ), 30, 1 ); |
|
68 | + add_filter( 'woocommerce_get_breadcrumb', array( $this, 'plan_breadcrumb_filter' ), 30, 1 ); |
|
69 | 69 | |
70 | - } |
|
71 | - |
|
72 | - /** |
|
73 | - * Return an instance of this class. |
|
74 | - * |
|
75 | - * @since 1.0.0 |
|
76 | - * |
|
77 | - * @return object \lsx_health_plan\classes\Meal_Plan() A single instance of this class. |
|
78 | - */ |
|
79 | - public static function get_instance() { |
|
80 | - // If the single instance hasn't been set, set it now. |
|
81 | - if ( null === self::$instance ) { |
|
82 | - self::$instance = new self(); |
|
83 | - } |
|
84 | - return self::$instance; |
|
85 | - } |
|
86 | - /** |
|
87 | - * Register the post type. |
|
88 | - */ |
|
89 | - public function register_post_type() { |
|
90 | - $labels = array( |
|
91 | - 'name' => esc_html__( 'Plans', 'lsx-health-plan' ), |
|
92 | - 'singular_name' => esc_html__( 'Plan', 'lsx-health-plan' ), |
|
93 | - 'add_new' => esc_html_x( 'Add New', 'post type general name', 'lsx-health-plan' ), |
|
94 | - 'add_new_item' => esc_html__( 'Add New', 'lsx-health-plan' ), |
|
95 | - 'edit_item' => esc_html__( 'Edit', 'lsx-health-plan' ), |
|
96 | - 'new_item' => esc_html__( 'New', 'lsx-health-plan' ), |
|
97 | - 'all_items' => esc_html__( 'All Plans', 'lsx-health-plan' ), |
|
98 | - 'view_item' => esc_html__( 'View', 'lsx-health-plan' ), |
|
99 | - 'search_items' => esc_html__( 'Search', 'lsx-health-plan' ), |
|
100 | - 'not_found' => esc_html__( 'None found', 'lsx-health-plan' ), |
|
101 | - 'not_found_in_trash' => esc_html__( 'None found in Trash', 'lsx-health-plan' ), |
|
102 | - 'parent_item_colon' => esc_html__( 'Parent:', 'lsx-health-plan' ), |
|
103 | - 'menu_name' => esc_html__( 'Plans', 'lsx-health-plan' ), |
|
104 | - ); |
|
105 | - $args = array( |
|
106 | - 'labels' => $labels, |
|
107 | - 'public' => true, |
|
108 | - 'publicly_queryable' => true, |
|
109 | - 'show_ui' => true, |
|
110 | - 'show_in_menu' => true, |
|
111 | - 'show_in_rest' => true, |
|
112 | - 'menu_icon' => 'dashicons-welcome-write-blog', |
|
113 | - 'query_var' => true, |
|
114 | - 'rewrite' => array( |
|
115 | - 'slug' => \lsx_health_plan\functions\get_option( 'plan_single_slug', 'plan' ), |
|
116 | - ), |
|
117 | - 'capability_type' => 'page', |
|
118 | - 'has_archive' => \lsx_health_plan\functions\get_option( 'endpoint_plan_archive', 'plans' ), |
|
119 | - 'hierarchical' => false, |
|
120 | - 'menu_position' => null, |
|
121 | - 'supports' => array( |
|
122 | - 'title', |
|
123 | - 'editor', |
|
124 | - 'thumbnail', |
|
125 | - 'page-attributes', |
|
126 | - 'custom-fields', |
|
127 | - ), |
|
128 | - ); |
|
129 | - register_post_type( 'plan', $args ); |
|
130 | - } |
|
131 | - |
|
132 | - /** |
|
133 | - * Register the Type taxonomy. |
|
134 | - */ |
|
135 | - public function plan_type_taxonomy_setup() { |
|
136 | - $labels = array( |
|
137 | - 'name' => esc_html_x( 'Plan Type', 'taxonomy general name', 'lsx-health-plan' ), |
|
138 | - 'singular_name' => esc_html_x( 'Plan Type', 'taxonomy singular name', 'lsx-health-plan' ), |
|
139 | - 'search_items' => esc_html__( 'Search', 'lsx-health-plan' ), |
|
140 | - 'all_items' => esc_html__( 'All', 'lsx-health-plan' ), |
|
141 | - 'parent_item' => esc_html__( 'Parent', 'lsx-health-plan' ), |
|
142 | - 'parent_item_colon' => esc_html__( 'Parent:', 'lsx-health-plan' ), |
|
143 | - 'edit_item' => esc_html__( 'Edit', 'lsx-health-plan' ), |
|
144 | - 'update_item' => esc_html__( 'Update', 'lsx-health-plan' ), |
|
145 | - 'add_new_item' => esc_html__( 'Add New', 'lsx-health-plan' ), |
|
146 | - 'new_item_name' => esc_html__( 'New Name', 'lsx-health-plan' ), |
|
147 | - 'menu_name' => esc_html__( 'Plan Types', 'lsx-health-plan' ), |
|
148 | - ); |
|
149 | - |
|
150 | - $args = array( |
|
151 | - 'hierarchical' => true, |
|
152 | - 'labels' => $labels, |
|
153 | - 'show_ui' => true, |
|
154 | - 'show_admin_column' => true, |
|
155 | - 'query_var' => true, |
|
156 | - 'rewrite' => array( |
|
157 | - 'slug' => 'plan-type', |
|
158 | - ), |
|
159 | - ); |
|
160 | - |
|
161 | - register_taxonomy( 'plan-type', array( 'plan' ), $args ); |
|
162 | - } |
|
163 | - |
|
164 | - /** |
|
165 | - * Register the Week taxonomy. |
|
166 | - */ |
|
167 | - public function week_taxonomy_setup() { |
|
168 | - $labels = array( |
|
169 | - 'name' => esc_html_x( 'Week', 'taxonomy general name', 'lsx-health-plan' ), |
|
170 | - 'singular_name' => esc_html_x( 'Week', 'taxonomy singular name', 'lsx-health-plan' ), |
|
171 | - 'search_items' => esc_html__( 'Search', 'lsx-health-plan' ), |
|
172 | - 'all_items' => esc_html__( 'All', 'lsx-health-plan' ), |
|
173 | - 'parent_item' => esc_html__( 'Parent', 'lsx-health-plan' ), |
|
174 | - 'parent_item_colon' => esc_html__( 'Parent:', 'lsx-health-plan' ), |
|
175 | - 'edit_item' => esc_html__( 'Edit', 'lsx-health-plan' ), |
|
176 | - 'update_item' => esc_html__( 'Update', 'lsx-health-plan' ), |
|
177 | - 'add_new_item' => esc_html__( 'Add New', 'lsx-health-plan' ), |
|
178 | - 'new_item_name' => esc_html__( 'New Name', 'lsx-health-plan' ), |
|
179 | - 'menu_name' => esc_html__( 'Weeks', 'lsx-health-plan' ), |
|
180 | - ); |
|
181 | - |
|
182 | - $args = array( |
|
183 | - 'hierarchical' => true, |
|
184 | - 'labels' => $labels, |
|
185 | - 'show_ui' => true, |
|
186 | - 'show_admin_column' => true, |
|
187 | - 'query_var' => true, |
|
188 | - 'show_in_rest' => true, |
|
189 | - 'rewrite' => array( |
|
190 | - 'slug' => 'week', |
|
191 | - ), |
|
192 | - ); |
|
193 | - |
|
194 | - register_taxonomy( 'week', array( 'plan' ), $args ); |
|
195 | - } |
|
196 | - |
|
197 | - /** |
|
198 | - * Output the form field for this metadata when adding a new term |
|
199 | - * |
|
200 | - * @since 0.1.0 |
|
201 | - */ |
|
202 | - public function add_thumbnail_form_field( $term = false ) { |
|
203 | - if ( is_object( $term ) ) { |
|
204 | - $value = get_term_meta( $term->term_id, 'thumbnail', true ); |
|
205 | - $image_preview = wp_get_attachment_image_src( $value, 'thumbnail' ); |
|
206 | - |
|
207 | - if ( is_array( $image_preview ) ) { |
|
208 | - $image_preview = '<img style="height: 50px; width: 50px;" src="' . esc_url( $image_preview[0] ) . '" width="' . $image_preview[1] . '" height="' . $image_preview[2] . '" class="alignnone size-thumbnail d wp-image-' . $value . '" />'; |
|
209 | - } |
|
210 | - } else { |
|
211 | - $image_preview = false; |
|
212 | - $value = false; |
|
213 | - } |
|
214 | - ?> |
|
70 | + } |
|
71 | + |
|
72 | + /** |
|
73 | + * Return an instance of this class. |
|
74 | + * |
|
75 | + * @since 1.0.0 |
|
76 | + * |
|
77 | + * @return object \lsx_health_plan\classes\Meal_Plan() A single instance of this class. |
|
78 | + */ |
|
79 | + public static function get_instance() { |
|
80 | + // If the single instance hasn't been set, set it now. |
|
81 | + if ( null === self::$instance ) { |
|
82 | + self::$instance = new self(); |
|
83 | + } |
|
84 | + return self::$instance; |
|
85 | + } |
|
86 | + /** |
|
87 | + * Register the post type. |
|
88 | + */ |
|
89 | + public function register_post_type() { |
|
90 | + $labels = array( |
|
91 | + 'name' => esc_html__( 'Plans', 'lsx-health-plan' ), |
|
92 | + 'singular_name' => esc_html__( 'Plan', 'lsx-health-plan' ), |
|
93 | + 'add_new' => esc_html_x( 'Add New', 'post type general name', 'lsx-health-plan' ), |
|
94 | + 'add_new_item' => esc_html__( 'Add New', 'lsx-health-plan' ), |
|
95 | + 'edit_item' => esc_html__( 'Edit', 'lsx-health-plan' ), |
|
96 | + 'new_item' => esc_html__( 'New', 'lsx-health-plan' ), |
|
97 | + 'all_items' => esc_html__( 'All Plans', 'lsx-health-plan' ), |
|
98 | + 'view_item' => esc_html__( 'View', 'lsx-health-plan' ), |
|
99 | + 'search_items' => esc_html__( 'Search', 'lsx-health-plan' ), |
|
100 | + 'not_found' => esc_html__( 'None found', 'lsx-health-plan' ), |
|
101 | + 'not_found_in_trash' => esc_html__( 'None found in Trash', 'lsx-health-plan' ), |
|
102 | + 'parent_item_colon' => esc_html__( 'Parent:', 'lsx-health-plan' ), |
|
103 | + 'menu_name' => esc_html__( 'Plans', 'lsx-health-plan' ), |
|
104 | + ); |
|
105 | + $args = array( |
|
106 | + 'labels' => $labels, |
|
107 | + 'public' => true, |
|
108 | + 'publicly_queryable' => true, |
|
109 | + 'show_ui' => true, |
|
110 | + 'show_in_menu' => true, |
|
111 | + 'show_in_rest' => true, |
|
112 | + 'menu_icon' => 'dashicons-welcome-write-blog', |
|
113 | + 'query_var' => true, |
|
114 | + 'rewrite' => array( |
|
115 | + 'slug' => \lsx_health_plan\functions\get_option( 'plan_single_slug', 'plan' ), |
|
116 | + ), |
|
117 | + 'capability_type' => 'page', |
|
118 | + 'has_archive' => \lsx_health_plan\functions\get_option( 'endpoint_plan_archive', 'plans' ), |
|
119 | + 'hierarchical' => false, |
|
120 | + 'menu_position' => null, |
|
121 | + 'supports' => array( |
|
122 | + 'title', |
|
123 | + 'editor', |
|
124 | + 'thumbnail', |
|
125 | + 'page-attributes', |
|
126 | + 'custom-fields', |
|
127 | + ), |
|
128 | + ); |
|
129 | + register_post_type( 'plan', $args ); |
|
130 | + } |
|
131 | + |
|
132 | + /** |
|
133 | + * Register the Type taxonomy. |
|
134 | + */ |
|
135 | + public function plan_type_taxonomy_setup() { |
|
136 | + $labels = array( |
|
137 | + 'name' => esc_html_x( 'Plan Type', 'taxonomy general name', 'lsx-health-plan' ), |
|
138 | + 'singular_name' => esc_html_x( 'Plan Type', 'taxonomy singular name', 'lsx-health-plan' ), |
|
139 | + 'search_items' => esc_html__( 'Search', 'lsx-health-plan' ), |
|
140 | + 'all_items' => esc_html__( 'All', 'lsx-health-plan' ), |
|
141 | + 'parent_item' => esc_html__( 'Parent', 'lsx-health-plan' ), |
|
142 | + 'parent_item_colon' => esc_html__( 'Parent:', 'lsx-health-plan' ), |
|
143 | + 'edit_item' => esc_html__( 'Edit', 'lsx-health-plan' ), |
|
144 | + 'update_item' => esc_html__( 'Update', 'lsx-health-plan' ), |
|
145 | + 'add_new_item' => esc_html__( 'Add New', 'lsx-health-plan' ), |
|
146 | + 'new_item_name' => esc_html__( 'New Name', 'lsx-health-plan' ), |
|
147 | + 'menu_name' => esc_html__( 'Plan Types', 'lsx-health-plan' ), |
|
148 | + ); |
|
149 | + |
|
150 | + $args = array( |
|
151 | + 'hierarchical' => true, |
|
152 | + 'labels' => $labels, |
|
153 | + 'show_ui' => true, |
|
154 | + 'show_admin_column' => true, |
|
155 | + 'query_var' => true, |
|
156 | + 'rewrite' => array( |
|
157 | + 'slug' => 'plan-type', |
|
158 | + ), |
|
159 | + ); |
|
160 | + |
|
161 | + register_taxonomy( 'plan-type', array( 'plan' ), $args ); |
|
162 | + } |
|
163 | + |
|
164 | + /** |
|
165 | + * Register the Week taxonomy. |
|
166 | + */ |
|
167 | + public function week_taxonomy_setup() { |
|
168 | + $labels = array( |
|
169 | + 'name' => esc_html_x( 'Week', 'taxonomy general name', 'lsx-health-plan' ), |
|
170 | + 'singular_name' => esc_html_x( 'Week', 'taxonomy singular name', 'lsx-health-plan' ), |
|
171 | + 'search_items' => esc_html__( 'Search', 'lsx-health-plan' ), |
|
172 | + 'all_items' => esc_html__( 'All', 'lsx-health-plan' ), |
|
173 | + 'parent_item' => esc_html__( 'Parent', 'lsx-health-plan' ), |
|
174 | + 'parent_item_colon' => esc_html__( 'Parent:', 'lsx-health-plan' ), |
|
175 | + 'edit_item' => esc_html__( 'Edit', 'lsx-health-plan' ), |
|
176 | + 'update_item' => esc_html__( 'Update', 'lsx-health-plan' ), |
|
177 | + 'add_new_item' => esc_html__( 'Add New', 'lsx-health-plan' ), |
|
178 | + 'new_item_name' => esc_html__( 'New Name', 'lsx-health-plan' ), |
|
179 | + 'menu_name' => esc_html__( 'Weeks', 'lsx-health-plan' ), |
|
180 | + ); |
|
181 | + |
|
182 | + $args = array( |
|
183 | + 'hierarchical' => true, |
|
184 | + 'labels' => $labels, |
|
185 | + 'show_ui' => true, |
|
186 | + 'show_admin_column' => true, |
|
187 | + 'query_var' => true, |
|
188 | + 'show_in_rest' => true, |
|
189 | + 'rewrite' => array( |
|
190 | + 'slug' => 'week', |
|
191 | + ), |
|
192 | + ); |
|
193 | + |
|
194 | + register_taxonomy( 'week', array( 'plan' ), $args ); |
|
195 | + } |
|
196 | + |
|
197 | + /** |
|
198 | + * Output the form field for this metadata when adding a new term |
|
199 | + * |
|
200 | + * @since 0.1.0 |
|
201 | + */ |
|
202 | + public function add_thumbnail_form_field( $term = false ) { |
|
203 | + if ( is_object( $term ) ) { |
|
204 | + $value = get_term_meta( $term->term_id, 'thumbnail', true ); |
|
205 | + $image_preview = wp_get_attachment_image_src( $value, 'thumbnail' ); |
|
206 | + |
|
207 | + if ( is_array( $image_preview ) ) { |
|
208 | + $image_preview = '<img style="height: 50px; width: 50px;" src="' . esc_url( $image_preview[0] ) . '" width="' . $image_preview[1] . '" height="' . $image_preview[2] . '" class="alignnone size-thumbnail d wp-image-' . $value . '" />'; |
|
209 | + } |
|
210 | + } else { |
|
211 | + $image_preview = false; |
|
212 | + $value = false; |
|
213 | + } |
|
214 | + ?> |
|
215 | 215 | <tr class="form-field form-required term-thumbnail-wrap"> |
216 | 216 | <th scope="row"><label for="thumbnail"><?php esc_html_e( 'Icon Image', 'lsx-health-plan' ); ?></label></th> |
217 | 217 | <td> |
@@ -225,379 +225,379 @@ discard block |
||
225 | 225 | </td> |
226 | 226 | </tr> |
227 | 227 | <?php |
228 | - } |
|
229 | - |
|
230 | - /** |
|
231 | - * Saves the Taxonomy term icon image |
|
232 | - * |
|
233 | - * @since 0.1.0 |
|
234 | - * |
|
235 | - * @param int $term_id |
|
236 | - * @param string $taxonomy |
|
237 | - */ |
|
238 | - public function save_meta( $term_id = 0, $taxonomy = '' ) { |
|
239 | - if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) { |
|
240 | - return; |
|
241 | - } |
|
242 | - |
|
243 | - if ( ! isset( $_POST['thumbnail'] ) ) { |
|
244 | - return; |
|
245 | - } |
|
246 | - |
|
247 | - if ( check_admin_referer( 'lsx_hp_term_thumbnail_nonce', 'lsx_hp_term_thumbnail_nonce' ) ) { |
|
248 | - if ( ! isset( $_POST['thumbnail'] ) ) { |
|
249 | - return; |
|
250 | - } |
|
251 | - |
|
252 | - $thumbnail_meta = sanitize_text_field( $_POST['thumbnail'] ); |
|
253 | - $thumbnail_meta = ! empty( $thumbnail_meta ) ? $thumbnail_meta : ''; |
|
254 | - |
|
255 | - if ( empty( $thumbnail_meta ) ) { |
|
256 | - delete_term_meta( $term_id, 'thumbnail' ); |
|
257 | - } else { |
|
258 | - update_term_meta( $term_id, 'thumbnail', $thumbnail_meta ); |
|
259 | - } |
|
260 | - } |
|
261 | - } |
|
262 | - |
|
263 | - /** |
|
264 | - * Define the metabox and field configurations. |
|
265 | - */ |
|
266 | - public function details_metaboxes() { |
|
267 | - $cmb = new_cmb2_box( array( |
|
268 | - 'id' => $this->slug . '_details_metabox', |
|
269 | - 'title' => __( 'Details', 'lsx-health-plan' ), |
|
270 | - 'object_types' => array( $this->slug ), // Post type |
|
271 | - 'context' => 'normal', |
|
272 | - 'priority' => 'high', |
|
273 | - 'show_names' => true, |
|
274 | - ) ); |
|
275 | - |
|
276 | - $cmb->add_field( array( |
|
277 | - 'name' => __( 'Plan Short Description', 'lsx-health-plan' ), |
|
278 | - 'id' => $this->slug . '_short_description', |
|
279 | - 'type' => 'textarea_small', |
|
280 | - 'desc' => __( 'Add a small description for this plan (optional)', 'lsx-health-plan' ), |
|
281 | - ) ); |
|
282 | - |
|
283 | - $warmup_type = 'page'; |
|
284 | - if ( false !== \lsx_health_plan\functions\get_option( 'exercise_enabled', false ) ) { |
|
285 | - $warmup_type = array( 'page', 'workout' ); |
|
286 | - } |
|
287 | - $cmb->add_field( array( |
|
288 | - 'name' => __( 'Warmup', 'lsx-health-plan' ), |
|
289 | - 'desc' => __( 'Connect the warm up page that applies to this day plan using the field provided.', 'lsx-health-plan' ), |
|
290 | - 'id' => $this->slug . '_warmup', |
|
291 | - 'type' => 'post_search_ajax', |
|
292 | - // Optional : |
|
293 | - 'limit' => 3, // Limit selection to X items only (default 1) |
|
294 | - 'sortable' => true, // Allow selected items to be sortable (default false) |
|
295 | - 'query_args' => array( |
|
296 | - 'post_type' => $warmup_type, |
|
297 | - 'post_status' => array( 'publish' ), |
|
298 | - 'posts_per_page' => -1, |
|
299 | - ), |
|
300 | - ) ); |
|
301 | - } |
|
302 | - |
|
303 | - /** |
|
304 | - * Adds the post type to the different arrays. |
|
305 | - * |
|
306 | - * @param array $post_types |
|
307 | - * @return array |
|
308 | - */ |
|
309 | - public function enable_post_type( $post_types = array() ) { |
|
310 | - $post_types[] = $this->slug; |
|
311 | - return $post_types; |
|
312 | - } |
|
313 | - |
|
314 | - /** |
|
315 | - * Registers the workout connections on the plan post type. |
|
316 | - * |
|
317 | - * @return void |
|
318 | - */ |
|
319 | - public function plan_connections() { |
|
320 | - $cmb = new_cmb2_box( |
|
321 | - array( |
|
322 | - 'id' => $this->slug . '_connections_metabox', |
|
323 | - 'title' => __( 'Plans', 'lsx-health-plan' ), |
|
324 | - 'object_types' => array( 'workout', 'meal', 'tip', 'recipe' ), |
|
325 | - 'context' => 'normal', |
|
326 | - 'priority' => 'high', |
|
327 | - 'show_names' => true, |
|
328 | - ) |
|
329 | - ); |
|
330 | - $cmb->add_field( |
|
331 | - array( |
|
332 | - 'name' => __( 'Plan', 'lsx-health-plan' ), |
|
333 | - 'id' => 'connected_plans', |
|
334 | - 'desc' => __( 'Connect this to the day plan it applies to, using the field provided.', 'lsx-health-plan' ), |
|
335 | - 'type' => 'post_search_ajax', |
|
336 | - 'limit' => 15, |
|
337 | - 'sortable' => true, |
|
338 | - 'query_args' => array( |
|
339 | - 'post_type' => array( 'plan' ), |
|
340 | - 'post_status' => array( 'publish' ), |
|
341 | - 'posts_per_page' => -1, |
|
342 | - ), |
|
343 | - ) |
|
344 | - ); |
|
345 | - } |
|
346 | - |
|
347 | - /** |
|
348 | - * Remove the "Archives:" from the post type. |
|
349 | - * |
|
350 | - * @param string $title the term title. |
|
351 | - * @return string |
|
352 | - */ |
|
353 | - public function get_the_archive_title( $title ) { |
|
354 | - if ( is_post_type_archive( 'plan' ) ) { |
|
355 | - $title = __( 'Our health plans', 'lsx-health-plan' ); |
|
356 | - } |
|
357 | - return $title; |
|
358 | - } |
|
359 | - |
|
360 | - /** |
|
361 | - * Set the post type archive to show the parent plans only. |
|
362 | - * |
|
363 | - * @param object $wp_query |
|
364 | - * @return array |
|
365 | - */ |
|
366 | - public function set_parent_only( $wp_query ) { |
|
367 | - if ( ! is_admin() && $wp_query->is_main_query() && ( $wp_query->is_post_type_archive( 'plan' ) || $wp_query->is_tax( 'plan-type' ) ) ) { |
|
368 | - $wp_query->set( 'post_parent', '0' ); |
|
369 | - } |
|
370 | - } |
|
371 | - |
|
372 | - /** |
|
373 | - * Define the metabox and field configurations. |
|
374 | - */ |
|
375 | - public function featured_metabox() { |
|
376 | - $cmb = new_cmb2_box( |
|
377 | - array( |
|
378 | - 'id' => $this->slug . '_featured_metabox_plan', |
|
379 | - 'title' => __( 'Featured Plan', 'lsx-health-plan' ), |
|
380 | - 'object_types' => array( $this->slug ), // Post type |
|
381 | - 'context' => 'side', |
|
382 | - 'priority' => 'high', |
|
383 | - 'show_names' => true, |
|
384 | - ) |
|
385 | - ); |
|
386 | - $cmb->add_field( |
|
387 | - array( |
|
388 | - 'name' => __( 'Featured Plan', 'lsx-health-plan' ), |
|
389 | - 'desc' => __( 'Enable a featured plan' ), |
|
390 | - 'id' => $this->slug . '_featured_plan', |
|
391 | - 'type' => 'checkbox', |
|
392 | - 'show_on_cb' => 'cmb2_hide_if_no_cats', |
|
393 | - ) |
|
394 | - ); |
|
395 | - } |
|
396 | - |
|
397 | - /** |
|
398 | - * Define the metabox and field configurations. |
|
399 | - */ |
|
400 | - public function sections_metabox_loop() { |
|
401 | - $cmb = new_cmb2_box( |
|
402 | - array( |
|
403 | - 'id' => $this->slug . '_sections_metabox', |
|
404 | - 'title' => __( 'Sections', 'lsx-health-plan' ), |
|
405 | - 'object_types' => array( $this->slug ), // Post type. |
|
406 | - 'context' => 'normal', |
|
407 | - 'priority' => 'low', |
|
408 | - 'show_names' => true, |
|
409 | - ) |
|
410 | - ); |
|
411 | - |
|
412 | - /* |
|
228 | + } |
|
229 | + |
|
230 | + /** |
|
231 | + * Saves the Taxonomy term icon image |
|
232 | + * |
|
233 | + * @since 0.1.0 |
|
234 | + * |
|
235 | + * @param int $term_id |
|
236 | + * @param string $taxonomy |
|
237 | + */ |
|
238 | + public function save_meta( $term_id = 0, $taxonomy = '' ) { |
|
239 | + if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) { |
|
240 | + return; |
|
241 | + } |
|
242 | + |
|
243 | + if ( ! isset( $_POST['thumbnail'] ) ) { |
|
244 | + return; |
|
245 | + } |
|
246 | + |
|
247 | + if ( check_admin_referer( 'lsx_hp_term_thumbnail_nonce', 'lsx_hp_term_thumbnail_nonce' ) ) { |
|
248 | + if ( ! isset( $_POST['thumbnail'] ) ) { |
|
249 | + return; |
|
250 | + } |
|
251 | + |
|
252 | + $thumbnail_meta = sanitize_text_field( $_POST['thumbnail'] ); |
|
253 | + $thumbnail_meta = ! empty( $thumbnail_meta ) ? $thumbnail_meta : ''; |
|
254 | + |
|
255 | + if ( empty( $thumbnail_meta ) ) { |
|
256 | + delete_term_meta( $term_id, 'thumbnail' ); |
|
257 | + } else { |
|
258 | + update_term_meta( $term_id, 'thumbnail', $thumbnail_meta ); |
|
259 | + } |
|
260 | + } |
|
261 | + } |
|
262 | + |
|
263 | + /** |
|
264 | + * Define the metabox and field configurations. |
|
265 | + */ |
|
266 | + public function details_metaboxes() { |
|
267 | + $cmb = new_cmb2_box( array( |
|
268 | + 'id' => $this->slug . '_details_metabox', |
|
269 | + 'title' => __( 'Details', 'lsx-health-plan' ), |
|
270 | + 'object_types' => array( $this->slug ), // Post type |
|
271 | + 'context' => 'normal', |
|
272 | + 'priority' => 'high', |
|
273 | + 'show_names' => true, |
|
274 | + ) ); |
|
275 | + |
|
276 | + $cmb->add_field( array( |
|
277 | + 'name' => __( 'Plan Short Description', 'lsx-health-plan' ), |
|
278 | + 'id' => $this->slug . '_short_description', |
|
279 | + 'type' => 'textarea_small', |
|
280 | + 'desc' => __( 'Add a small description for this plan (optional)', 'lsx-health-plan' ), |
|
281 | + ) ); |
|
282 | + |
|
283 | + $warmup_type = 'page'; |
|
284 | + if ( false !== \lsx_health_plan\functions\get_option( 'exercise_enabled', false ) ) { |
|
285 | + $warmup_type = array( 'page', 'workout' ); |
|
286 | + } |
|
287 | + $cmb->add_field( array( |
|
288 | + 'name' => __( 'Warmup', 'lsx-health-plan' ), |
|
289 | + 'desc' => __( 'Connect the warm up page that applies to this day plan using the field provided.', 'lsx-health-plan' ), |
|
290 | + 'id' => $this->slug . '_warmup', |
|
291 | + 'type' => 'post_search_ajax', |
|
292 | + // Optional : |
|
293 | + 'limit' => 3, // Limit selection to X items only (default 1) |
|
294 | + 'sortable' => true, // Allow selected items to be sortable (default false) |
|
295 | + 'query_args' => array( |
|
296 | + 'post_type' => $warmup_type, |
|
297 | + 'post_status' => array( 'publish' ), |
|
298 | + 'posts_per_page' => -1, |
|
299 | + ), |
|
300 | + ) ); |
|
301 | + } |
|
302 | + |
|
303 | + /** |
|
304 | + * Adds the post type to the different arrays. |
|
305 | + * |
|
306 | + * @param array $post_types |
|
307 | + * @return array |
|
308 | + */ |
|
309 | + public function enable_post_type( $post_types = array() ) { |
|
310 | + $post_types[] = $this->slug; |
|
311 | + return $post_types; |
|
312 | + } |
|
313 | + |
|
314 | + /** |
|
315 | + * Registers the workout connections on the plan post type. |
|
316 | + * |
|
317 | + * @return void |
|
318 | + */ |
|
319 | + public function plan_connections() { |
|
320 | + $cmb = new_cmb2_box( |
|
321 | + array( |
|
322 | + 'id' => $this->slug . '_connections_metabox', |
|
323 | + 'title' => __( 'Plans', 'lsx-health-plan' ), |
|
324 | + 'object_types' => array( 'workout', 'meal', 'tip', 'recipe' ), |
|
325 | + 'context' => 'normal', |
|
326 | + 'priority' => 'high', |
|
327 | + 'show_names' => true, |
|
328 | + ) |
|
329 | + ); |
|
330 | + $cmb->add_field( |
|
331 | + array( |
|
332 | + 'name' => __( 'Plan', 'lsx-health-plan' ), |
|
333 | + 'id' => 'connected_plans', |
|
334 | + 'desc' => __( 'Connect this to the day plan it applies to, using the field provided.', 'lsx-health-plan' ), |
|
335 | + 'type' => 'post_search_ajax', |
|
336 | + 'limit' => 15, |
|
337 | + 'sortable' => true, |
|
338 | + 'query_args' => array( |
|
339 | + 'post_type' => array( 'plan' ), |
|
340 | + 'post_status' => array( 'publish' ), |
|
341 | + 'posts_per_page' => -1, |
|
342 | + ), |
|
343 | + ) |
|
344 | + ); |
|
345 | + } |
|
346 | + |
|
347 | + /** |
|
348 | + * Remove the "Archives:" from the post type. |
|
349 | + * |
|
350 | + * @param string $title the term title. |
|
351 | + * @return string |
|
352 | + */ |
|
353 | + public function get_the_archive_title( $title ) { |
|
354 | + if ( is_post_type_archive( 'plan' ) ) { |
|
355 | + $title = __( 'Our health plans', 'lsx-health-plan' ); |
|
356 | + } |
|
357 | + return $title; |
|
358 | + } |
|
359 | + |
|
360 | + /** |
|
361 | + * Set the post type archive to show the parent plans only. |
|
362 | + * |
|
363 | + * @param object $wp_query |
|
364 | + * @return array |
|
365 | + */ |
|
366 | + public function set_parent_only( $wp_query ) { |
|
367 | + if ( ! is_admin() && $wp_query->is_main_query() && ( $wp_query->is_post_type_archive( 'plan' ) || $wp_query->is_tax( 'plan-type' ) ) ) { |
|
368 | + $wp_query->set( 'post_parent', '0' ); |
|
369 | + } |
|
370 | + } |
|
371 | + |
|
372 | + /** |
|
373 | + * Define the metabox and field configurations. |
|
374 | + */ |
|
375 | + public function featured_metabox() { |
|
376 | + $cmb = new_cmb2_box( |
|
377 | + array( |
|
378 | + 'id' => $this->slug . '_featured_metabox_plan', |
|
379 | + 'title' => __( 'Featured Plan', 'lsx-health-plan' ), |
|
380 | + 'object_types' => array( $this->slug ), // Post type |
|
381 | + 'context' => 'side', |
|
382 | + 'priority' => 'high', |
|
383 | + 'show_names' => true, |
|
384 | + ) |
|
385 | + ); |
|
386 | + $cmb->add_field( |
|
387 | + array( |
|
388 | + 'name' => __( 'Featured Plan', 'lsx-health-plan' ), |
|
389 | + 'desc' => __( 'Enable a featured plan' ), |
|
390 | + 'id' => $this->slug . '_featured_plan', |
|
391 | + 'type' => 'checkbox', |
|
392 | + 'show_on_cb' => 'cmb2_hide_if_no_cats', |
|
393 | + ) |
|
394 | + ); |
|
395 | + } |
|
396 | + |
|
397 | + /** |
|
398 | + * Define the metabox and field configurations. |
|
399 | + */ |
|
400 | + public function sections_metabox_loop() { |
|
401 | + $cmb = new_cmb2_box( |
|
402 | + array( |
|
403 | + 'id' => $this->slug . '_sections_metabox', |
|
404 | + 'title' => __( 'Sections', 'lsx-health-plan' ), |
|
405 | + 'object_types' => array( $this->slug ), // Post type. |
|
406 | + 'context' => 'normal', |
|
407 | + 'priority' => 'low', |
|
408 | + 'show_names' => true, |
|
409 | + ) |
|
410 | + ); |
|
411 | + |
|
412 | + /* |
|
413 | 413 | This is where the repeatable group is defined, each field has the same ID as the legacy field. |
414 | 414 | There is a function which runs and adds to looped fields to individual fields for WP Query compatability. |
415 | 415 | */ |
416 | - $group = $cmb->add_field( |
|
417 | - array( |
|
418 | - 'id' => $this->slug . '_sections', |
|
419 | - 'type' => 'group', |
|
420 | - 'options' => array( |
|
421 | - 'group_title' => __( 'Section', 'lsx-health-plan' ) . ' {#}', // {#} gets replaced by row number |
|
422 | - 'add_button' => __( 'Add section', 'lsx-health-plan' ), |
|
423 | - 'remove_button' => __( 'Remove section', 'lsx-health-plan' ), |
|
424 | - 'sortable' => true, |
|
425 | - 'closed' => true, // true to have the groups closed by default |
|
426 | - ), |
|
427 | - 'classes' => 'lsx-admin-row', |
|
416 | + $group = $cmb->add_field( |
|
417 | + array( |
|
418 | + 'id' => $this->slug . '_sections', |
|
419 | + 'type' => 'group', |
|
420 | + 'options' => array( |
|
421 | + 'group_title' => __( 'Section', 'lsx-health-plan' ) . ' {#}', // {#} gets replaced by row number |
|
422 | + 'add_button' => __( 'Add section', 'lsx-health-plan' ), |
|
423 | + 'remove_button' => __( 'Remove section', 'lsx-health-plan' ), |
|
424 | + 'sortable' => true, |
|
425 | + 'closed' => true, // true to have the groups closed by default |
|
426 | + ), |
|
427 | + 'classes' => 'lsx-admin-row', |
|
428 | 428 | |
429 | - ) |
|
430 | - ); |
|
431 | - |
|
432 | - $cmb->add_group_field( |
|
433 | - $group, |
|
434 | - array( |
|
435 | - 'name' => __( 'Title', 'lsx-health-plan' ), |
|
436 | - 'id' => 'title', |
|
437 | - 'type' => 'text', |
|
438 | - 'desc' => __( 'e.g Day 1 / Week 1', 'lsx-health-plan' ), |
|
439 | - 'classes' => 'lsx-field-col lsx-field-col-50', |
|
440 | - ) |
|
441 | - ); |
|
442 | - |
|
443 | - $cmb->add_group_field( |
|
444 | - $group, |
|
445 | - array( |
|
446 | - 'name' => __( 'Group', 'lsx-health-plan' ), |
|
447 | - 'id' => 'group', |
|
448 | - 'type' => 'text', |
|
449 | - 'desc' => __( 'e.g Week 1 / January', 'lsx-health-plan' ), |
|
450 | - 'classes' => 'lsx-field-col lsx-field-col-50', |
|
451 | - ) |
|
452 | - ); |
|
453 | - |
|
454 | - $cmb->add_group_field( |
|
455 | - $group, |
|
456 | - array( |
|
457 | - 'name' => __( 'Overview', 'lsx-health-plan' ), |
|
458 | - 'id' => 'description', |
|
459 | - 'type' => 'wysiwyg', |
|
460 | - ) |
|
461 | - ); |
|
462 | - |
|
463 | - if ( post_type_exists( 'workout' ) ) { |
|
464 | - $cmb->add_group_field( |
|
465 | - $group, |
|
466 | - array( |
|
467 | - 'name' => __( 'Workouts', 'lsx-health-plan' ), |
|
468 | - 'id' => 'connected_workouts', |
|
469 | - 'desc' => __( 'Connect the workout(s) that apply to this section.', 'lsx-health-plan' ), |
|
470 | - 'type' => 'post_search_ajax', |
|
471 | - 'limit' => 15, |
|
472 | - 'sortable' => true, |
|
473 | - 'query_args' => array( |
|
474 | - 'post_type' => array( 'workout' ), |
|
475 | - 'post_status' => array( 'publish' ), |
|
476 | - 'posts_per_page' => -1, |
|
477 | - ), |
|
478 | - 'classes' => 'lsx-field-col lsx-field-add-field lsx-field-col-50', |
|
479 | - ) |
|
480 | - ); |
|
481 | - $cmb->add_group_field( |
|
482 | - $group, |
|
483 | - array( |
|
484 | - 'name' => __( 'Rest day', 'lsx-health-plan' ), |
|
485 | - 'id' => 'rest_day_enabled', |
|
486 | - 'type' => 'checkbox', |
|
487 | - 'value' => 1, |
|
488 | - 'default' => 0, |
|
489 | - 'description' => __( 'Enabling the rest day will add an item called "Rest" with no links.', 'lsx-health-plan' ), |
|
490 | - 'classes' => 'lsx-field-col lsx-field-add-field lsx-field-col-50', |
|
491 | - ) |
|
492 | - ); |
|
493 | - } |
|
494 | - |
|
495 | - if ( post_type_exists( 'meal' ) ) { |
|
496 | - $cmb->add_group_field( |
|
497 | - $group, |
|
498 | - array( |
|
499 | - 'name' => __( 'Meals', 'lsx-health-plan' ), |
|
500 | - 'desc' => __( 'Connect the meal(s) that apply to this section.', 'lsx-health-plan' ), |
|
501 | - 'id' => 'connected_meals', |
|
502 | - 'type' => 'post_search_ajax', |
|
503 | - // Optional : |
|
504 | - 'limit' => 15, // Limit selection to X items only (default 1) |
|
505 | - 'sortable' => true, // Allow selected items to be sortable (default false) |
|
506 | - 'query_args' => array( |
|
507 | - 'post_type' => array( 'meal' ), |
|
508 | - 'post_status' => array( 'publish' ), |
|
509 | - 'posts_per_page' => -1, |
|
510 | - ), |
|
511 | - 'classes' => 'lsx-field-col lsx-field-add-field lsx-field-col-50', |
|
512 | - ) |
|
513 | - ); |
|
514 | - } |
|
515 | - if ( post_type_exists( 'tip' ) ) { |
|
516 | - $cmb->add_group_field( |
|
517 | - $group, |
|
518 | - array( |
|
519 | - 'name' => __( 'Tips', 'lsx-health-plan' ), |
|
520 | - 'id' => 'connected_tips', |
|
521 | - 'desc' => __( 'Connect the tip(s) that apply to this section.', 'lsx-health-plan' ), |
|
522 | - 'type' => 'post_search_ajax', |
|
523 | - // Optional : |
|
524 | - 'limit' => 15, // Limit selection to X items only (default 1) |
|
525 | - 'sortable' => true, // Allow selected items to be sortable (default false) |
|
526 | - 'query_args' => array( |
|
527 | - 'post_type' => array( 'tip' ), |
|
528 | - 'post_status' => array( 'publish' ), |
|
529 | - 'posts_per_page' => -1, |
|
530 | - ), |
|
531 | - 'classes' => 'lsx-field-col lsx-field-add-field lsx-field-col-50', |
|
532 | - ) |
|
533 | - ); |
|
534 | - } |
|
535 | - } |
|
536 | - |
|
537 | - /** |
|
538 | - * Holds the array for the single plan breadcrumbs. |
|
539 | - * |
|
540 | - * @var array $crumbs |
|
541 | - * @return array |
|
542 | - */ |
|
543 | - public function plan_breadcrumb_filter( $crumbs ) { |
|
544 | - $plan = \lsx_health_plan\functions\get_option( 'endpoint_plan', 'plan' ); |
|
545 | - $plans = \lsx_health_plan\functions\get_option( 'endpoint_plan_archive', 'plan' ); |
|
546 | - |
|
547 | - if ( is_singular( 'plan' ) ) { |
|
548 | - $plan_name = get_the_title(); |
|
549 | - $url = get_post_type_archive_link( $plan ); |
|
550 | - $term_obj_list = get_the_terms( get_the_ID(), 'plan-type' ); |
|
551 | - $plan_type = $term_obj_list[0]->name; |
|
552 | - $plan_type_url = get_term_link( $term_obj_list[0]->term_id ); |
|
553 | - |
|
554 | - $new_crumbs = array(); |
|
555 | - $new_crumbs[0] = $crumbs[0]; |
|
556 | - |
|
557 | - if ( function_exists( 'woocommerce_breadcrumb' ) ) { |
|
558 | - $new_crumbs[1] = array( |
|
559 | - 0 => $plans, |
|
560 | - 1 => $url, |
|
561 | - ); |
|
562 | - $new_crumbs[2] = array( |
|
563 | - 0 => $plan_type, |
|
564 | - 1 => $plan_type_url, |
|
565 | - ); |
|
566 | - $new_crumbs[3] = array( |
|
567 | - 0 => $plan_name, |
|
568 | - ); |
|
569 | - } else { |
|
570 | - $new_crumbs[1] = array( |
|
571 | - 'text' => $plans, |
|
572 | - 'url' => $url, |
|
573 | - ); |
|
574 | - $new_crumbs[2] = array( |
|
575 | - 'text' => $plan_type, |
|
576 | - 'url' => $plan_type_url, |
|
577 | - ); |
|
578 | - $new_crumbs[3] = array( |
|
579 | - 'text' => $plan_name, |
|
580 | - ); |
|
581 | - } |
|
582 | - $crumbs = $new_crumbs; |
|
583 | - |
|
584 | - } |
|
585 | - if ( is_post_type_archive( 'plan' ) ) { |
|
586 | - |
|
587 | - $new_crumbs = array(); |
|
588 | - $new_crumbs[0] = $crumbs[0]; |
|
589 | - |
|
590 | - if ( function_exists( 'woocommerce_breadcrumb' ) ) { |
|
591 | - $new_crumbs[1] = array( |
|
592 | - 0 => $plans, |
|
593 | - ); |
|
594 | - } else { |
|
595 | - $new_crumbs[1] = array( |
|
596 | - 'text' => $plans, |
|
597 | - ); |
|
598 | - } |
|
599 | - $crumbs = $new_crumbs; |
|
600 | - } |
|
601 | - return $crumbs; |
|
602 | - } |
|
429 | + ) |
|
430 | + ); |
|
431 | + |
|
432 | + $cmb->add_group_field( |
|
433 | + $group, |
|
434 | + array( |
|
435 | + 'name' => __( 'Title', 'lsx-health-plan' ), |
|
436 | + 'id' => 'title', |
|
437 | + 'type' => 'text', |
|
438 | + 'desc' => __( 'e.g Day 1 / Week 1', 'lsx-health-plan' ), |
|
439 | + 'classes' => 'lsx-field-col lsx-field-col-50', |
|
440 | + ) |
|
441 | + ); |
|
442 | + |
|
443 | + $cmb->add_group_field( |
|
444 | + $group, |
|
445 | + array( |
|
446 | + 'name' => __( 'Group', 'lsx-health-plan' ), |
|
447 | + 'id' => 'group', |
|
448 | + 'type' => 'text', |
|
449 | + 'desc' => __( 'e.g Week 1 / January', 'lsx-health-plan' ), |
|
450 | + 'classes' => 'lsx-field-col lsx-field-col-50', |
|
451 | + ) |
|
452 | + ); |
|
453 | + |
|
454 | + $cmb->add_group_field( |
|
455 | + $group, |
|
456 | + array( |
|
457 | + 'name' => __( 'Overview', 'lsx-health-plan' ), |
|
458 | + 'id' => 'description', |
|
459 | + 'type' => 'wysiwyg', |
|
460 | + ) |
|
461 | + ); |
|
462 | + |
|
463 | + if ( post_type_exists( 'workout' ) ) { |
|
464 | + $cmb->add_group_field( |
|
465 | + $group, |
|
466 | + array( |
|
467 | + 'name' => __( 'Workouts', 'lsx-health-plan' ), |
|
468 | + 'id' => 'connected_workouts', |
|
469 | + 'desc' => __( 'Connect the workout(s) that apply to this section.', 'lsx-health-plan' ), |
|
470 | + 'type' => 'post_search_ajax', |
|
471 | + 'limit' => 15, |
|
472 | + 'sortable' => true, |
|
473 | + 'query_args' => array( |
|
474 | + 'post_type' => array( 'workout' ), |
|
475 | + 'post_status' => array( 'publish' ), |
|
476 | + 'posts_per_page' => -1, |
|
477 | + ), |
|
478 | + 'classes' => 'lsx-field-col lsx-field-add-field lsx-field-col-50', |
|
479 | + ) |
|
480 | + ); |
|
481 | + $cmb->add_group_field( |
|
482 | + $group, |
|
483 | + array( |
|
484 | + 'name' => __( 'Rest day', 'lsx-health-plan' ), |
|
485 | + 'id' => 'rest_day_enabled', |
|
486 | + 'type' => 'checkbox', |
|
487 | + 'value' => 1, |
|
488 | + 'default' => 0, |
|
489 | + 'description' => __( 'Enabling the rest day will add an item called "Rest" with no links.', 'lsx-health-plan' ), |
|
490 | + 'classes' => 'lsx-field-col lsx-field-add-field lsx-field-col-50', |
|
491 | + ) |
|
492 | + ); |
|
493 | + } |
|
494 | + |
|
495 | + if ( post_type_exists( 'meal' ) ) { |
|
496 | + $cmb->add_group_field( |
|
497 | + $group, |
|
498 | + array( |
|
499 | + 'name' => __( 'Meals', 'lsx-health-plan' ), |
|
500 | + 'desc' => __( 'Connect the meal(s) that apply to this section.', 'lsx-health-plan' ), |
|
501 | + 'id' => 'connected_meals', |
|
502 | + 'type' => 'post_search_ajax', |
|
503 | + // Optional : |
|
504 | + 'limit' => 15, // Limit selection to X items only (default 1) |
|
505 | + 'sortable' => true, // Allow selected items to be sortable (default false) |
|
506 | + 'query_args' => array( |
|
507 | + 'post_type' => array( 'meal' ), |
|
508 | + 'post_status' => array( 'publish' ), |
|
509 | + 'posts_per_page' => -1, |
|
510 | + ), |
|
511 | + 'classes' => 'lsx-field-col lsx-field-add-field lsx-field-col-50', |
|
512 | + ) |
|
513 | + ); |
|
514 | + } |
|
515 | + if ( post_type_exists( 'tip' ) ) { |
|
516 | + $cmb->add_group_field( |
|
517 | + $group, |
|
518 | + array( |
|
519 | + 'name' => __( 'Tips', 'lsx-health-plan' ), |
|
520 | + 'id' => 'connected_tips', |
|
521 | + 'desc' => __( 'Connect the tip(s) that apply to this section.', 'lsx-health-plan' ), |
|
522 | + 'type' => 'post_search_ajax', |
|
523 | + // Optional : |
|
524 | + 'limit' => 15, // Limit selection to X items only (default 1) |
|
525 | + 'sortable' => true, // Allow selected items to be sortable (default false) |
|
526 | + 'query_args' => array( |
|
527 | + 'post_type' => array( 'tip' ), |
|
528 | + 'post_status' => array( 'publish' ), |
|
529 | + 'posts_per_page' => -1, |
|
530 | + ), |
|
531 | + 'classes' => 'lsx-field-col lsx-field-add-field lsx-field-col-50', |
|
532 | + ) |
|
533 | + ); |
|
534 | + } |
|
535 | + } |
|
536 | + |
|
537 | + /** |
|
538 | + * Holds the array for the single plan breadcrumbs. |
|
539 | + * |
|
540 | + * @var array $crumbs |
|
541 | + * @return array |
|
542 | + */ |
|
543 | + public function plan_breadcrumb_filter( $crumbs ) { |
|
544 | + $plan = \lsx_health_plan\functions\get_option( 'endpoint_plan', 'plan' ); |
|
545 | + $plans = \lsx_health_plan\functions\get_option( 'endpoint_plan_archive', 'plan' ); |
|
546 | + |
|
547 | + if ( is_singular( 'plan' ) ) { |
|
548 | + $plan_name = get_the_title(); |
|
549 | + $url = get_post_type_archive_link( $plan ); |
|
550 | + $term_obj_list = get_the_terms( get_the_ID(), 'plan-type' ); |
|
551 | + $plan_type = $term_obj_list[0]->name; |
|
552 | + $plan_type_url = get_term_link( $term_obj_list[0]->term_id ); |
|
553 | + |
|
554 | + $new_crumbs = array(); |
|
555 | + $new_crumbs[0] = $crumbs[0]; |
|
556 | + |
|
557 | + if ( function_exists( 'woocommerce_breadcrumb' ) ) { |
|
558 | + $new_crumbs[1] = array( |
|
559 | + 0 => $plans, |
|
560 | + 1 => $url, |
|
561 | + ); |
|
562 | + $new_crumbs[2] = array( |
|
563 | + 0 => $plan_type, |
|
564 | + 1 => $plan_type_url, |
|
565 | + ); |
|
566 | + $new_crumbs[3] = array( |
|
567 | + 0 => $plan_name, |
|
568 | + ); |
|
569 | + } else { |
|
570 | + $new_crumbs[1] = array( |
|
571 | + 'text' => $plans, |
|
572 | + 'url' => $url, |
|
573 | + ); |
|
574 | + $new_crumbs[2] = array( |
|
575 | + 'text' => $plan_type, |
|
576 | + 'url' => $plan_type_url, |
|
577 | + ); |
|
578 | + $new_crumbs[3] = array( |
|
579 | + 'text' => $plan_name, |
|
580 | + ); |
|
581 | + } |
|
582 | + $crumbs = $new_crumbs; |
|
583 | + |
|
584 | + } |
|
585 | + if ( is_post_type_archive( 'plan' ) ) { |
|
586 | + |
|
587 | + $new_crumbs = array(); |
|
588 | + $new_crumbs[0] = $crumbs[0]; |
|
589 | + |
|
590 | + if ( function_exists( 'woocommerce_breadcrumb' ) ) { |
|
591 | + $new_crumbs[1] = array( |
|
592 | + 0 => $plans, |
|
593 | + ); |
|
594 | + } else { |
|
595 | + $new_crumbs[1] = array( |
|
596 | + 'text' => $plans, |
|
597 | + ); |
|
598 | + } |
|
599 | + $crumbs = $new_crumbs; |
|
600 | + } |
|
601 | + return $crumbs; |
|
602 | + } |
|
603 | 603 | } |
@@ -33,39 +33,39 @@ discard block |
||
33 | 33 | */ |
34 | 34 | public function __construct() { |
35 | 35 | |
36 | - add_action( 'init', array( $this, 'register_post_type' ) ); |
|
37 | - add_action( 'init', array( $this, 'plan_type_taxonomy_setup' ) ); |
|
38 | - add_action( 'init', array( $this, 'week_taxonomy_setup' ) ); |
|
36 | + add_action('init', array($this, 'register_post_type')); |
|
37 | + add_action('init', array($this, 'plan_type_taxonomy_setup')); |
|
38 | + add_action('init', array($this, 'week_taxonomy_setup')); |
|
39 | 39 | |
40 | 40 | // Icons for the plan types. |
41 | - add_action( 'create_term', array( $this, 'save_meta' ), 10, 2 ); |
|
42 | - add_action( 'edit_term', array( $this, 'save_meta' ), 10, 2 ); |
|
41 | + add_action('create_term', array($this, 'save_meta'), 10, 2); |
|
42 | + add_action('edit_term', array($this, 'save_meta'), 10, 2); |
|
43 | 43 | $prefix_taxonomy = 'plan-type'; |
44 | - add_action( sprintf( '%s_edit_form_fields', $prefix_taxonomy ), array( $this, 'add_thumbnail_form_field' ), 3, 1 ); |
|
44 | + add_action(sprintf('%s_edit_form_fields', $prefix_taxonomy), array($this, 'add_thumbnail_form_field'), 3, 1); |
|
45 | 45 | |
46 | 46 | // Register the Metaboxes. |
47 | - add_action( 'cmb2_admin_init', array( $this, 'featured_metabox' ), 5 ); |
|
48 | - add_action( 'cmb2_admin_init', array( $this, 'details_metaboxes' ), 5 ); |
|
49 | - add_action( 'cmb2_admin_init', array( $this, 'plan_connections' ), 5 ); |
|
50 | - add_action( 'cmb2_admin_init', array( $this, 'sections_metabox_loop' ), 1 ); |
|
47 | + add_action('cmb2_admin_init', array($this, 'featured_metabox'), 5); |
|
48 | + add_action('cmb2_admin_init', array($this, 'details_metaboxes'), 5); |
|
49 | + add_action('cmb2_admin_init', array($this, 'plan_connections'), 5); |
|
50 | + add_action('cmb2_admin_init', array($this, 'sections_metabox_loop'), 1); |
|
51 | 51 | |
52 | - add_filter( 'get_the_archive_title', array( $this, 'get_the_archive_title' ), 100 ); |
|
52 | + add_filter('get_the_archive_title', array($this, 'get_the_archive_title'), 100); |
|
53 | 53 | //add_filter( 'lsx_global_header_title', array( $this, 'hp_recipe_header_title' ), 200, 1 ); |
54 | 54 | |
55 | 55 | // Template Redirects. |
56 | - add_filter( 'lsx_health_plan_archive_template', array( $this, 'enable_post_type' ), 10, 1 ); |
|
57 | - add_filter( 'lsx_health_plan_single_template', array( $this, 'enable_post_type' ), 10, 1 ); |
|
56 | + add_filter('lsx_health_plan_archive_template', array($this, 'enable_post_type'), 10, 1); |
|
57 | + add_filter('lsx_health_plan_single_template', array($this, 'enable_post_type'), 10, 1); |
|
58 | 58 | |
59 | 59 | // Plan Archive Actions. |
60 | - add_action( 'pre_get_posts', array( $this, 'set_parent_only' ), 10, 1 ); |
|
61 | - add_filter( 'get_the_archive_title', array( $this, 'get_the_archive_title' ), 100 ); |
|
62 | - add_action( 'lsx_content_top', 'lsx_hp_plan_archive_filters', 10, 1 ); |
|
63 | - add_filter( 'lsx_hp_disable_plan_archive_filters', '\lsx_health_plan\functions\plan\is_search_enabled', 10, 1 ); |
|
64 | - add_filter( 'lsx_hp_disable_plan_archive_filters', '\lsx_health_plan\functions\plan\is_filters_disabled', 10, 1 ); |
|
60 | + add_action('pre_get_posts', array($this, 'set_parent_only'), 10, 1); |
|
61 | + add_filter('get_the_archive_title', array($this, 'get_the_archive_title'), 100); |
|
62 | + add_action('lsx_content_top', 'lsx_hp_plan_archive_filters', 10, 1); |
|
63 | + add_filter('lsx_hp_disable_plan_archive_filters', '\lsx_health_plan\functions\plan\is_search_enabled', 10, 1); |
|
64 | + add_filter('lsx_hp_disable_plan_archive_filters', '\lsx_health_plan\functions\plan\is_filters_disabled', 10, 1); |
|
65 | 65 | |
66 | 66 | //Breadcrumbs |
67 | - add_filter( 'wpseo_breadcrumb_links', array( $this, 'plan_breadcrumb_filter' ), 30, 1 ); |
|
68 | - add_filter( 'woocommerce_get_breadcrumb', array( $this, 'plan_breadcrumb_filter' ), 30, 1 ); |
|
67 | + add_filter('wpseo_breadcrumb_links', array($this, 'plan_breadcrumb_filter'), 30, 1); |
|
68 | + add_filter('woocommerce_get_breadcrumb', array($this, 'plan_breadcrumb_filter'), 30, 1); |
|
69 | 69 | |
70 | 70 | } |
71 | 71 | |
@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | */ |
79 | 79 | public static function get_instance() { |
80 | 80 | // If the single instance hasn't been set, set it now. |
81 | - if ( null === self::$instance ) { |
|
81 | + if (null === self::$instance) { |
|
82 | 82 | self::$instance = new self(); |
83 | 83 | } |
84 | 84 | return self::$instance; |
@@ -88,21 +88,21 @@ discard block |
||
88 | 88 | */ |
89 | 89 | public function register_post_type() { |
90 | 90 | $labels = array( |
91 | - 'name' => esc_html__( 'Plans', 'lsx-health-plan' ), |
|
92 | - 'singular_name' => esc_html__( 'Plan', 'lsx-health-plan' ), |
|
93 | - 'add_new' => esc_html_x( 'Add New', 'post type general name', 'lsx-health-plan' ), |
|
94 | - 'add_new_item' => esc_html__( 'Add New', 'lsx-health-plan' ), |
|
95 | - 'edit_item' => esc_html__( 'Edit', 'lsx-health-plan' ), |
|
96 | - 'new_item' => esc_html__( 'New', 'lsx-health-plan' ), |
|
97 | - 'all_items' => esc_html__( 'All Plans', 'lsx-health-plan' ), |
|
98 | - 'view_item' => esc_html__( 'View', 'lsx-health-plan' ), |
|
99 | - 'search_items' => esc_html__( 'Search', 'lsx-health-plan' ), |
|
100 | - 'not_found' => esc_html__( 'None found', 'lsx-health-plan' ), |
|
101 | - 'not_found_in_trash' => esc_html__( 'None found in Trash', 'lsx-health-plan' ), |
|
102 | - 'parent_item_colon' => esc_html__( 'Parent:', 'lsx-health-plan' ), |
|
103 | - 'menu_name' => esc_html__( 'Plans', 'lsx-health-plan' ), |
|
91 | + 'name' => esc_html__('Plans', 'lsx-health-plan'), |
|
92 | + 'singular_name' => esc_html__('Plan', 'lsx-health-plan'), |
|
93 | + 'add_new' => esc_html_x('Add New', 'post type general name', 'lsx-health-plan'), |
|
94 | + 'add_new_item' => esc_html__('Add New', 'lsx-health-plan'), |
|
95 | + 'edit_item' => esc_html__('Edit', 'lsx-health-plan'), |
|
96 | + 'new_item' => esc_html__('New', 'lsx-health-plan'), |
|
97 | + 'all_items' => esc_html__('All Plans', 'lsx-health-plan'), |
|
98 | + 'view_item' => esc_html__('View', 'lsx-health-plan'), |
|
99 | + 'search_items' => esc_html__('Search', 'lsx-health-plan'), |
|
100 | + 'not_found' => esc_html__('None found', 'lsx-health-plan'), |
|
101 | + 'not_found_in_trash' => esc_html__('None found in Trash', 'lsx-health-plan'), |
|
102 | + 'parent_item_colon' => esc_html__('Parent:', 'lsx-health-plan'), |
|
103 | + 'menu_name' => esc_html__('Plans', 'lsx-health-plan'), |
|
104 | 104 | ); |
105 | - $args = array( |
|
105 | + $args = array( |
|
106 | 106 | 'labels' => $labels, |
107 | 107 | 'public' => true, |
108 | 108 | 'publicly_queryable' => true, |
@@ -112,10 +112,10 @@ discard block |
||
112 | 112 | 'menu_icon' => 'dashicons-welcome-write-blog', |
113 | 113 | 'query_var' => true, |
114 | 114 | 'rewrite' => array( |
115 | - 'slug' => \lsx_health_plan\functions\get_option( 'plan_single_slug', 'plan' ), |
|
115 | + 'slug' => \lsx_health_plan\functions\get_option('plan_single_slug', 'plan'), |
|
116 | 116 | ), |
117 | 117 | 'capability_type' => 'page', |
118 | - 'has_archive' => \lsx_health_plan\functions\get_option( 'endpoint_plan_archive', 'plans' ), |
|
118 | + 'has_archive' => \lsx_health_plan\functions\get_option('endpoint_plan_archive', 'plans'), |
|
119 | 119 | 'hierarchical' => false, |
120 | 120 | 'menu_position' => null, |
121 | 121 | 'supports' => array( |
@@ -126,7 +126,7 @@ discard block |
||
126 | 126 | 'custom-fields', |
127 | 127 | ), |
128 | 128 | ); |
129 | - register_post_type( 'plan', $args ); |
|
129 | + register_post_type('plan', $args); |
|
130 | 130 | } |
131 | 131 | |
132 | 132 | /** |
@@ -134,17 +134,17 @@ discard block |
||
134 | 134 | */ |
135 | 135 | public function plan_type_taxonomy_setup() { |
136 | 136 | $labels = array( |
137 | - 'name' => esc_html_x( 'Plan Type', 'taxonomy general name', 'lsx-health-plan' ), |
|
138 | - 'singular_name' => esc_html_x( 'Plan Type', 'taxonomy singular name', 'lsx-health-plan' ), |
|
139 | - 'search_items' => esc_html__( 'Search', 'lsx-health-plan' ), |
|
140 | - 'all_items' => esc_html__( 'All', 'lsx-health-plan' ), |
|
141 | - 'parent_item' => esc_html__( 'Parent', 'lsx-health-plan' ), |
|
142 | - 'parent_item_colon' => esc_html__( 'Parent:', 'lsx-health-plan' ), |
|
143 | - 'edit_item' => esc_html__( 'Edit', 'lsx-health-plan' ), |
|
144 | - 'update_item' => esc_html__( 'Update', 'lsx-health-plan' ), |
|
145 | - 'add_new_item' => esc_html__( 'Add New', 'lsx-health-plan' ), |
|
146 | - 'new_item_name' => esc_html__( 'New Name', 'lsx-health-plan' ), |
|
147 | - 'menu_name' => esc_html__( 'Plan Types', 'lsx-health-plan' ), |
|
137 | + 'name' => esc_html_x('Plan Type', 'taxonomy general name', 'lsx-health-plan'), |
|
138 | + 'singular_name' => esc_html_x('Plan Type', 'taxonomy singular name', 'lsx-health-plan'), |
|
139 | + 'search_items' => esc_html__('Search', 'lsx-health-plan'), |
|
140 | + 'all_items' => esc_html__('All', 'lsx-health-plan'), |
|
141 | + 'parent_item' => esc_html__('Parent', 'lsx-health-plan'), |
|
142 | + 'parent_item_colon' => esc_html__('Parent:', 'lsx-health-plan'), |
|
143 | + 'edit_item' => esc_html__('Edit', 'lsx-health-plan'), |
|
144 | + 'update_item' => esc_html__('Update', 'lsx-health-plan'), |
|
145 | + 'add_new_item' => esc_html__('Add New', 'lsx-health-plan'), |
|
146 | + 'new_item_name' => esc_html__('New Name', 'lsx-health-plan'), |
|
147 | + 'menu_name' => esc_html__('Plan Types', 'lsx-health-plan'), |
|
148 | 148 | ); |
149 | 149 | |
150 | 150 | $args = array( |
@@ -158,7 +158,7 @@ discard block |
||
158 | 158 | ), |
159 | 159 | ); |
160 | 160 | |
161 | - register_taxonomy( 'plan-type', array( 'plan' ), $args ); |
|
161 | + register_taxonomy('plan-type', array('plan'), $args); |
|
162 | 162 | } |
163 | 163 | |
164 | 164 | /** |
@@ -166,17 +166,17 @@ discard block |
||
166 | 166 | */ |
167 | 167 | public function week_taxonomy_setup() { |
168 | 168 | $labels = array( |
169 | - 'name' => esc_html_x( 'Week', 'taxonomy general name', 'lsx-health-plan' ), |
|
170 | - 'singular_name' => esc_html_x( 'Week', 'taxonomy singular name', 'lsx-health-plan' ), |
|
171 | - 'search_items' => esc_html__( 'Search', 'lsx-health-plan' ), |
|
172 | - 'all_items' => esc_html__( 'All', 'lsx-health-plan' ), |
|
173 | - 'parent_item' => esc_html__( 'Parent', 'lsx-health-plan' ), |
|
174 | - 'parent_item_colon' => esc_html__( 'Parent:', 'lsx-health-plan' ), |
|
175 | - 'edit_item' => esc_html__( 'Edit', 'lsx-health-plan' ), |
|
176 | - 'update_item' => esc_html__( 'Update', 'lsx-health-plan' ), |
|
177 | - 'add_new_item' => esc_html__( 'Add New', 'lsx-health-plan' ), |
|
178 | - 'new_item_name' => esc_html__( 'New Name', 'lsx-health-plan' ), |
|
179 | - 'menu_name' => esc_html__( 'Weeks', 'lsx-health-plan' ), |
|
169 | + 'name' => esc_html_x('Week', 'taxonomy general name', 'lsx-health-plan'), |
|
170 | + 'singular_name' => esc_html_x('Week', 'taxonomy singular name', 'lsx-health-plan'), |
|
171 | + 'search_items' => esc_html__('Search', 'lsx-health-plan'), |
|
172 | + 'all_items' => esc_html__('All', 'lsx-health-plan'), |
|
173 | + 'parent_item' => esc_html__('Parent', 'lsx-health-plan'), |
|
174 | + 'parent_item_colon' => esc_html__('Parent:', 'lsx-health-plan'), |
|
175 | + 'edit_item' => esc_html__('Edit', 'lsx-health-plan'), |
|
176 | + 'update_item' => esc_html__('Update', 'lsx-health-plan'), |
|
177 | + 'add_new_item' => esc_html__('Add New', 'lsx-health-plan'), |
|
178 | + 'new_item_name' => esc_html__('New Name', 'lsx-health-plan'), |
|
179 | + 'menu_name' => esc_html__('Weeks', 'lsx-health-plan'), |
|
180 | 180 | ); |
181 | 181 | |
182 | 182 | $args = array( |
@@ -191,7 +191,7 @@ discard block |
||
191 | 191 | ), |
192 | 192 | ); |
193 | 193 | |
194 | - register_taxonomy( 'week', array( 'plan' ), $args ); |
|
194 | + register_taxonomy('week', array('plan'), $args); |
|
195 | 195 | } |
196 | 196 | |
197 | 197 | /** |
@@ -199,13 +199,13 @@ discard block |
||
199 | 199 | * |
200 | 200 | * @since 0.1.0 |
201 | 201 | */ |
202 | - public function add_thumbnail_form_field( $term = false ) { |
|
203 | - if ( is_object( $term ) ) { |
|
204 | - $value = get_term_meta( $term->term_id, 'thumbnail', true ); |
|
205 | - $image_preview = wp_get_attachment_image_src( $value, 'thumbnail' ); |
|
202 | + public function add_thumbnail_form_field($term = false) { |
|
203 | + if (is_object($term)) { |
|
204 | + $value = get_term_meta($term->term_id, 'thumbnail', true); |
|
205 | + $image_preview = wp_get_attachment_image_src($value, 'thumbnail'); |
|
206 | 206 | |
207 | - if ( is_array( $image_preview ) ) { |
|
208 | - $image_preview = '<img style="height: 50px; width: 50px;" src="' . esc_url( $image_preview[0] ) . '" width="' . $image_preview[1] . '" height="' . $image_preview[2] . '" class="alignnone size-thumbnail d wp-image-' . $value . '" />'; |
|
207 | + if (is_array($image_preview)) { |
|
208 | + $image_preview = '<img style="height: 50px; width: 50px;" src="' . esc_url($image_preview[0]) . '" width="' . $image_preview[1] . '" height="' . $image_preview[2] . '" class="alignnone size-thumbnail d wp-image-' . $value . '" />'; |
|
209 | 209 | } |
210 | 210 | } else { |
211 | 211 | $image_preview = false; |
@@ -213,15 +213,15 @@ discard block |
||
213 | 213 | } |
214 | 214 | ?> |
215 | 215 | <tr class="form-field form-required term-thumbnail-wrap"> |
216 | - <th scope="row"><label for="thumbnail"><?php esc_html_e( 'Icon Image', 'lsx-health-plan' ); ?></label></th> |
|
216 | + <th scope="row"><label for="thumbnail"><?php esc_html_e('Icon Image', 'lsx-health-plan'); ?></label></th> |
|
217 | 217 | <td> |
218 | - <input class="input_image_id" type="hidden" name="thumbnail" value="<?php echo wp_kses_post( $value ); ?>"> |
|
218 | + <input class="input_image_id" type="hidden" name="thumbnail" value="<?php echo wp_kses_post($value); ?>"> |
|
219 | 219 | <div class="thumbnail-preview"> |
220 | - <?php echo wp_kses_post( $image_preview ); ?> |
|
220 | + <?php echo wp_kses_post($image_preview); ?> |
|
221 | 221 | </div> |
222 | - <a style="<?php if ( '' !== $value && false !== $value ) { ?>display:none;<?php } ?>" class="button-secondary lsx-thumbnail-image-add"><?php esc_html_e( 'Choose Image', 'lsx-health-plan' ); ?></a> |
|
223 | - <a style="<?php if ( '' === $value || false === $value ) { ?>display:none;<?php } ?>" class="button-secondary lsx-thumbnail-image-remove"><?php esc_html_e( 'Remove Image', 'lsx-health-plan' ); ?></a> |
|
224 | - <?php wp_nonce_field( 'lsx_hp_term_thumbnail_nonce', 'lsx_hp_term_thumbnail_nonce' ); ?> |
|
222 | + <a style="<?php if ('' !== $value && false !== $value) { ?>display:none;<?php } ?>" class="button-secondary lsx-thumbnail-image-add"><?php esc_html_e('Choose Image', 'lsx-health-plan'); ?></a> |
|
223 | + <a style="<?php if ('' === $value || false === $value) { ?>display:none;<?php } ?>" class="button-secondary lsx-thumbnail-image-remove"><?php esc_html_e('Remove Image', 'lsx-health-plan'); ?></a> |
|
224 | + <?php wp_nonce_field('lsx_hp_term_thumbnail_nonce', 'lsx_hp_term_thumbnail_nonce'); ?> |
|
225 | 225 | </td> |
226 | 226 | </tr> |
227 | 227 | <?php |
@@ -235,27 +235,27 @@ discard block |
||
235 | 235 | * @param int $term_id |
236 | 236 | * @param string $taxonomy |
237 | 237 | */ |
238 | - public function save_meta( $term_id = 0, $taxonomy = '' ) { |
|
239 | - if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) { |
|
238 | + public function save_meta($term_id = 0, $taxonomy = '') { |
|
239 | + if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) { |
|
240 | 240 | return; |
241 | 241 | } |
242 | 242 | |
243 | - if ( ! isset( $_POST['thumbnail'] ) ) { |
|
243 | + if ( ! isset($_POST['thumbnail'])) { |
|
244 | 244 | return; |
245 | 245 | } |
246 | 246 | |
247 | - if ( check_admin_referer( 'lsx_hp_term_thumbnail_nonce', 'lsx_hp_term_thumbnail_nonce' ) ) { |
|
248 | - if ( ! isset( $_POST['thumbnail'] ) ) { |
|
247 | + if (check_admin_referer('lsx_hp_term_thumbnail_nonce', 'lsx_hp_term_thumbnail_nonce')) { |
|
248 | + if ( ! isset($_POST['thumbnail'])) { |
|
249 | 249 | return; |
250 | 250 | } |
251 | 251 | |
252 | - $thumbnail_meta = sanitize_text_field( $_POST['thumbnail'] ); |
|
253 | - $thumbnail_meta = ! empty( $thumbnail_meta ) ? $thumbnail_meta : ''; |
|
252 | + $thumbnail_meta = sanitize_text_field($_POST['thumbnail']); |
|
253 | + $thumbnail_meta = ! empty($thumbnail_meta) ? $thumbnail_meta : ''; |
|
254 | 254 | |
255 | - if ( empty( $thumbnail_meta ) ) { |
|
256 | - delete_term_meta( $term_id, 'thumbnail' ); |
|
255 | + if (empty($thumbnail_meta)) { |
|
256 | + delete_term_meta($term_id, 'thumbnail'); |
|
257 | 257 | } else { |
258 | - update_term_meta( $term_id, 'thumbnail', $thumbnail_meta ); |
|
258 | + update_term_meta($term_id, 'thumbnail', $thumbnail_meta); |
|
259 | 259 | } |
260 | 260 | } |
261 | 261 | } |
@@ -264,40 +264,40 @@ discard block |
||
264 | 264 | * Define the metabox and field configurations. |
265 | 265 | */ |
266 | 266 | public function details_metaboxes() { |
267 | - $cmb = new_cmb2_box( array( |
|
267 | + $cmb = new_cmb2_box(array( |
|
268 | 268 | 'id' => $this->slug . '_details_metabox', |
269 | - 'title' => __( 'Details', 'lsx-health-plan' ), |
|
270 | - 'object_types' => array( $this->slug ), // Post type |
|
269 | + 'title' => __('Details', 'lsx-health-plan'), |
|
270 | + 'object_types' => array($this->slug), // Post type |
|
271 | 271 | 'context' => 'normal', |
272 | 272 | 'priority' => 'high', |
273 | 273 | 'show_names' => true, |
274 | - ) ); |
|
274 | + )); |
|
275 | 275 | |
276 | - $cmb->add_field( array( |
|
277 | - 'name' => __( 'Plan Short Description', 'lsx-health-plan' ), |
|
276 | + $cmb->add_field(array( |
|
277 | + 'name' => __('Plan Short Description', 'lsx-health-plan'), |
|
278 | 278 | 'id' => $this->slug . '_short_description', |
279 | 279 | 'type' => 'textarea_small', |
280 | - 'desc' => __( 'Add a small description for this plan (optional)', 'lsx-health-plan' ), |
|
281 | - ) ); |
|
280 | + 'desc' => __('Add a small description for this plan (optional)', 'lsx-health-plan'), |
|
281 | + )); |
|
282 | 282 | |
283 | 283 | $warmup_type = 'page'; |
284 | - if ( false !== \lsx_health_plan\functions\get_option( 'exercise_enabled', false ) ) { |
|
285 | - $warmup_type = array( 'page', 'workout' ); |
|
284 | + if (false !== \lsx_health_plan\functions\get_option('exercise_enabled', false)) { |
|
285 | + $warmup_type = array('page', 'workout'); |
|
286 | 286 | } |
287 | - $cmb->add_field( array( |
|
288 | - 'name' => __( 'Warmup', 'lsx-health-plan' ), |
|
289 | - 'desc' => __( 'Connect the warm up page that applies to this day plan using the field provided.', 'lsx-health-plan' ), |
|
287 | + $cmb->add_field(array( |
|
288 | + 'name' => __('Warmup', 'lsx-health-plan'), |
|
289 | + 'desc' => __('Connect the warm up page that applies to this day plan using the field provided.', 'lsx-health-plan'), |
|
290 | 290 | 'id' => $this->slug . '_warmup', |
291 | 291 | 'type' => 'post_search_ajax', |
292 | 292 | // Optional : |
293 | - 'limit' => 3, // Limit selection to X items only (default 1) |
|
293 | + 'limit' => 3, // Limit selection to X items only (default 1) |
|
294 | 294 | 'sortable' => true, // Allow selected items to be sortable (default false) |
295 | 295 | 'query_args' => array( |
296 | 296 | 'post_type' => $warmup_type, |
297 | - 'post_status' => array( 'publish' ), |
|
297 | + 'post_status' => array('publish'), |
|
298 | 298 | 'posts_per_page' => -1, |
299 | 299 | ), |
300 | - ) ); |
|
300 | + )); |
|
301 | 301 | } |
302 | 302 | |
303 | 303 | /** |
@@ -306,7 +306,7 @@ discard block |
||
306 | 306 | * @param array $post_types |
307 | 307 | * @return array |
308 | 308 | */ |
309 | - public function enable_post_type( $post_types = array() ) { |
|
309 | + public function enable_post_type($post_types = array()) { |
|
310 | 310 | $post_types[] = $this->slug; |
311 | 311 | return $post_types; |
312 | 312 | } |
@@ -320,8 +320,8 @@ discard block |
||
320 | 320 | $cmb = new_cmb2_box( |
321 | 321 | array( |
322 | 322 | 'id' => $this->slug . '_connections_metabox', |
323 | - 'title' => __( 'Plans', 'lsx-health-plan' ), |
|
324 | - 'object_types' => array( 'workout', 'meal', 'tip', 'recipe' ), |
|
323 | + 'title' => __('Plans', 'lsx-health-plan'), |
|
324 | + 'object_types' => array('workout', 'meal', 'tip', 'recipe'), |
|
325 | 325 | 'context' => 'normal', |
326 | 326 | 'priority' => 'high', |
327 | 327 | 'show_names' => true, |
@@ -329,15 +329,15 @@ discard block |
||
329 | 329 | ); |
330 | 330 | $cmb->add_field( |
331 | 331 | array( |
332 | - 'name' => __( 'Plan', 'lsx-health-plan' ), |
|
332 | + 'name' => __('Plan', 'lsx-health-plan'), |
|
333 | 333 | 'id' => 'connected_plans', |
334 | - 'desc' => __( 'Connect this to the day plan it applies to, using the field provided.', 'lsx-health-plan' ), |
|
334 | + 'desc' => __('Connect this to the day plan it applies to, using the field provided.', 'lsx-health-plan'), |
|
335 | 335 | 'type' => 'post_search_ajax', |
336 | 336 | 'limit' => 15, |
337 | 337 | 'sortable' => true, |
338 | 338 | 'query_args' => array( |
339 | - 'post_type' => array( 'plan' ), |
|
340 | - 'post_status' => array( 'publish' ), |
|
339 | + 'post_type' => array('plan'), |
|
340 | + 'post_status' => array('publish'), |
|
341 | 341 | 'posts_per_page' => -1, |
342 | 342 | ), |
343 | 343 | ) |
@@ -350,9 +350,9 @@ discard block |
||
350 | 350 | * @param string $title the term title. |
351 | 351 | * @return string |
352 | 352 | */ |
353 | - public function get_the_archive_title( $title ) { |
|
354 | - if ( is_post_type_archive( 'plan' ) ) { |
|
355 | - $title = __( 'Our health plans', 'lsx-health-plan' ); |
|
353 | + public function get_the_archive_title($title) { |
|
354 | + if (is_post_type_archive('plan')) { |
|
355 | + $title = __('Our health plans', 'lsx-health-plan'); |
|
356 | 356 | } |
357 | 357 | return $title; |
358 | 358 | } |
@@ -363,9 +363,9 @@ discard block |
||
363 | 363 | * @param object $wp_query |
364 | 364 | * @return array |
365 | 365 | */ |
366 | - public function set_parent_only( $wp_query ) { |
|
367 | - if ( ! is_admin() && $wp_query->is_main_query() && ( $wp_query->is_post_type_archive( 'plan' ) || $wp_query->is_tax( 'plan-type' ) ) ) { |
|
368 | - $wp_query->set( 'post_parent', '0' ); |
|
366 | + public function set_parent_only($wp_query) { |
|
367 | + if ( ! is_admin() && $wp_query->is_main_query() && ($wp_query->is_post_type_archive('plan') || $wp_query->is_tax('plan-type'))) { |
|
368 | + $wp_query->set('post_parent', '0'); |
|
369 | 369 | } |
370 | 370 | } |
371 | 371 | |
@@ -376,8 +376,8 @@ discard block |
||
376 | 376 | $cmb = new_cmb2_box( |
377 | 377 | array( |
378 | 378 | 'id' => $this->slug . '_featured_metabox_plan', |
379 | - 'title' => __( 'Featured Plan', 'lsx-health-plan' ), |
|
380 | - 'object_types' => array( $this->slug ), // Post type |
|
379 | + 'title' => __('Featured Plan', 'lsx-health-plan'), |
|
380 | + 'object_types' => array($this->slug), // Post type |
|
381 | 381 | 'context' => 'side', |
382 | 382 | 'priority' => 'high', |
383 | 383 | 'show_names' => true, |
@@ -385,8 +385,8 @@ discard block |
||
385 | 385 | ); |
386 | 386 | $cmb->add_field( |
387 | 387 | array( |
388 | - 'name' => __( 'Featured Plan', 'lsx-health-plan' ), |
|
389 | - 'desc' => __( 'Enable a featured plan' ), |
|
388 | + 'name' => __('Featured Plan', 'lsx-health-plan'), |
|
389 | + 'desc' => __('Enable a featured plan'), |
|
390 | 390 | 'id' => $this->slug . '_featured_plan', |
391 | 391 | 'type' => 'checkbox', |
392 | 392 | 'show_on_cb' => 'cmb2_hide_if_no_cats', |
@@ -401,8 +401,8 @@ discard block |
||
401 | 401 | $cmb = new_cmb2_box( |
402 | 402 | array( |
403 | 403 | 'id' => $this->slug . '_sections_metabox', |
404 | - 'title' => __( 'Sections', 'lsx-health-plan' ), |
|
405 | - 'object_types' => array( $this->slug ), // Post type. |
|
404 | + 'title' => __('Sections', 'lsx-health-plan'), |
|
405 | + 'object_types' => array($this->slug), // Post type. |
|
406 | 406 | 'context' => 'normal', |
407 | 407 | 'priority' => 'low', |
408 | 408 | 'show_names' => true, |
@@ -418,9 +418,9 @@ discard block |
||
418 | 418 | 'id' => $this->slug . '_sections', |
419 | 419 | 'type' => 'group', |
420 | 420 | 'options' => array( |
421 | - 'group_title' => __( 'Section', 'lsx-health-plan' ) . ' {#}', // {#} gets replaced by row number |
|
422 | - 'add_button' => __( 'Add section', 'lsx-health-plan' ), |
|
423 | - 'remove_button' => __( 'Remove section', 'lsx-health-plan' ), |
|
421 | + 'group_title' => __('Section', 'lsx-health-plan') . ' {#}', // {#} gets replaced by row number |
|
422 | + 'add_button' => __('Add section', 'lsx-health-plan'), |
|
423 | + 'remove_button' => __('Remove section', 'lsx-health-plan'), |
|
424 | 424 | 'sortable' => true, |
425 | 425 | 'closed' => true, // true to have the groups closed by default |
426 | 426 | ), |
@@ -432,10 +432,10 @@ discard block |
||
432 | 432 | $cmb->add_group_field( |
433 | 433 | $group, |
434 | 434 | array( |
435 | - 'name' => __( 'Title', 'lsx-health-plan' ), |
|
435 | + 'name' => __('Title', 'lsx-health-plan'), |
|
436 | 436 | 'id' => 'title', |
437 | 437 | 'type' => 'text', |
438 | - 'desc' => __( 'e.g Day 1 / Week 1', 'lsx-health-plan' ), |
|
438 | + 'desc' => __('e.g Day 1 / Week 1', 'lsx-health-plan'), |
|
439 | 439 | 'classes' => 'lsx-field-col lsx-field-col-50', |
440 | 440 | ) |
441 | 441 | ); |
@@ -443,10 +443,10 @@ discard block |
||
443 | 443 | $cmb->add_group_field( |
444 | 444 | $group, |
445 | 445 | array( |
446 | - 'name' => __( 'Group', 'lsx-health-plan' ), |
|
446 | + 'name' => __('Group', 'lsx-health-plan'), |
|
447 | 447 | 'id' => 'group', |
448 | 448 | 'type' => 'text', |
449 | - 'desc' => __( 'e.g Week 1 / January', 'lsx-health-plan' ), |
|
449 | + 'desc' => __('e.g Week 1 / January', 'lsx-health-plan'), |
|
450 | 450 | 'classes' => 'lsx-field-col lsx-field-col-50', |
451 | 451 | ) |
452 | 452 | ); |
@@ -454,25 +454,25 @@ discard block |
||
454 | 454 | $cmb->add_group_field( |
455 | 455 | $group, |
456 | 456 | array( |
457 | - 'name' => __( 'Overview', 'lsx-health-plan' ), |
|
457 | + 'name' => __('Overview', 'lsx-health-plan'), |
|
458 | 458 | 'id' => 'description', |
459 | 459 | 'type' => 'wysiwyg', |
460 | 460 | ) |
461 | 461 | ); |
462 | 462 | |
463 | - if ( post_type_exists( 'workout' ) ) { |
|
463 | + if (post_type_exists('workout')) { |
|
464 | 464 | $cmb->add_group_field( |
465 | 465 | $group, |
466 | 466 | array( |
467 | - 'name' => __( 'Workouts', 'lsx-health-plan' ), |
|
467 | + 'name' => __('Workouts', 'lsx-health-plan'), |
|
468 | 468 | 'id' => 'connected_workouts', |
469 | - 'desc' => __( 'Connect the workout(s) that apply to this section.', 'lsx-health-plan' ), |
|
469 | + 'desc' => __('Connect the workout(s) that apply to this section.', 'lsx-health-plan'), |
|
470 | 470 | 'type' => 'post_search_ajax', |
471 | 471 | 'limit' => 15, |
472 | 472 | 'sortable' => true, |
473 | 473 | 'query_args' => array( |
474 | - 'post_type' => array( 'workout' ), |
|
475 | - 'post_status' => array( 'publish' ), |
|
474 | + 'post_type' => array('workout'), |
|
475 | + 'post_status' => array('publish'), |
|
476 | 476 | 'posts_per_page' => -1, |
477 | 477 | ), |
478 | 478 | 'classes' => 'lsx-field-col lsx-field-add-field lsx-field-col-50', |
@@ -481,51 +481,51 @@ discard block |
||
481 | 481 | $cmb->add_group_field( |
482 | 482 | $group, |
483 | 483 | array( |
484 | - 'name' => __( 'Rest day', 'lsx-health-plan' ), |
|
484 | + 'name' => __('Rest day', 'lsx-health-plan'), |
|
485 | 485 | 'id' => 'rest_day_enabled', |
486 | 486 | 'type' => 'checkbox', |
487 | 487 | 'value' => 1, |
488 | 488 | 'default' => 0, |
489 | - 'description' => __( 'Enabling the rest day will add an item called "Rest" with no links.', 'lsx-health-plan' ), |
|
489 | + 'description' => __('Enabling the rest day will add an item called "Rest" with no links.', 'lsx-health-plan'), |
|
490 | 490 | 'classes' => 'lsx-field-col lsx-field-add-field lsx-field-col-50', |
491 | 491 | ) |
492 | 492 | ); |
493 | 493 | } |
494 | 494 | |
495 | - if ( post_type_exists( 'meal' ) ) { |
|
495 | + if (post_type_exists('meal')) { |
|
496 | 496 | $cmb->add_group_field( |
497 | 497 | $group, |
498 | 498 | array( |
499 | - 'name' => __( 'Meals', 'lsx-health-plan' ), |
|
500 | - 'desc' => __( 'Connect the meal(s) that apply to this section.', 'lsx-health-plan' ), |
|
499 | + 'name' => __('Meals', 'lsx-health-plan'), |
|
500 | + 'desc' => __('Connect the meal(s) that apply to this section.', 'lsx-health-plan'), |
|
501 | 501 | 'id' => 'connected_meals', |
502 | 502 | 'type' => 'post_search_ajax', |
503 | 503 | // Optional : |
504 | 504 | 'limit' => 15, // Limit selection to X items only (default 1) |
505 | 505 | 'sortable' => true, // Allow selected items to be sortable (default false) |
506 | 506 | 'query_args' => array( |
507 | - 'post_type' => array( 'meal' ), |
|
508 | - 'post_status' => array( 'publish' ), |
|
507 | + 'post_type' => array('meal'), |
|
508 | + 'post_status' => array('publish'), |
|
509 | 509 | 'posts_per_page' => -1, |
510 | 510 | ), |
511 | 511 | 'classes' => 'lsx-field-col lsx-field-add-field lsx-field-col-50', |
512 | 512 | ) |
513 | 513 | ); |
514 | 514 | } |
515 | - if ( post_type_exists( 'tip' ) ) { |
|
515 | + if (post_type_exists('tip')) { |
|
516 | 516 | $cmb->add_group_field( |
517 | 517 | $group, |
518 | 518 | array( |
519 | - 'name' => __( 'Tips', 'lsx-health-plan' ), |
|
519 | + 'name' => __('Tips', 'lsx-health-plan'), |
|
520 | 520 | 'id' => 'connected_tips', |
521 | - 'desc' => __( 'Connect the tip(s) that apply to this section.', 'lsx-health-plan' ), |
|
521 | + 'desc' => __('Connect the tip(s) that apply to this section.', 'lsx-health-plan'), |
|
522 | 522 | 'type' => 'post_search_ajax', |
523 | 523 | // Optional : |
524 | - 'limit' => 15, // Limit selection to X items only (default 1) |
|
525 | - 'sortable' => true, // Allow selected items to be sortable (default false) |
|
524 | + 'limit' => 15, // Limit selection to X items only (default 1) |
|
525 | + 'sortable' => true, // Allow selected items to be sortable (default false) |
|
526 | 526 | 'query_args' => array( |
527 | - 'post_type' => array( 'tip' ), |
|
528 | - 'post_status' => array( 'publish' ), |
|
527 | + 'post_type' => array('tip'), |
|
528 | + 'post_status' => array('publish'), |
|
529 | 529 | 'posts_per_page' => -1, |
530 | 530 | ), |
531 | 531 | 'classes' => 'lsx-field-col lsx-field-add-field lsx-field-col-50', |
@@ -540,21 +540,21 @@ discard block |
||
540 | 540 | * @var array $crumbs |
541 | 541 | * @return array |
542 | 542 | */ |
543 | - public function plan_breadcrumb_filter( $crumbs ) { |
|
544 | - $plan = \lsx_health_plan\functions\get_option( 'endpoint_plan', 'plan' ); |
|
545 | - $plans = \lsx_health_plan\functions\get_option( 'endpoint_plan_archive', 'plan' ); |
|
543 | + public function plan_breadcrumb_filter($crumbs) { |
|
544 | + $plan = \lsx_health_plan\functions\get_option('endpoint_plan', 'plan'); |
|
545 | + $plans = \lsx_health_plan\functions\get_option('endpoint_plan_archive', 'plan'); |
|
546 | 546 | |
547 | - if ( is_singular( 'plan' ) ) { |
|
547 | + if (is_singular('plan')) { |
|
548 | 548 | $plan_name = get_the_title(); |
549 | - $url = get_post_type_archive_link( $plan ); |
|
550 | - $term_obj_list = get_the_terms( get_the_ID(), 'plan-type' ); |
|
549 | + $url = get_post_type_archive_link($plan); |
|
550 | + $term_obj_list = get_the_terms(get_the_ID(), 'plan-type'); |
|
551 | 551 | $plan_type = $term_obj_list[0]->name; |
552 | - $plan_type_url = get_term_link( $term_obj_list[0]->term_id ); |
|
552 | + $plan_type_url = get_term_link($term_obj_list[0]->term_id); |
|
553 | 553 | |
554 | 554 | $new_crumbs = array(); |
555 | 555 | $new_crumbs[0] = $crumbs[0]; |
556 | 556 | |
557 | - if ( function_exists( 'woocommerce_breadcrumb' ) ) { |
|
557 | + if (function_exists('woocommerce_breadcrumb')) { |
|
558 | 558 | $new_crumbs[1] = array( |
559 | 559 | 0 => $plans, |
560 | 560 | 1 => $url, |
@@ -582,12 +582,12 @@ discard block |
||
582 | 582 | $crumbs = $new_crumbs; |
583 | 583 | |
584 | 584 | } |
585 | - if ( is_post_type_archive( 'plan' ) ) { |
|
585 | + if (is_post_type_archive('plan')) { |
|
586 | 586 | |
587 | 587 | $new_crumbs = array(); |
588 | 588 | $new_crumbs[0] = $crumbs[0]; |
589 | 589 | |
590 | - if ( function_exists( 'woocommerce_breadcrumb' ) ) { |
|
590 | + if (function_exists('woocommerce_breadcrumb')) { |
|
591 | 591 | $new_crumbs[1] = array( |
592 | 592 | 0 => $plans, |
593 | 593 | ); |
@@ -8,146 +8,146 @@ |
||
8 | 8 | */ |
9 | 9 | class Plans { |
10 | 10 | |
11 | - /** |
|
12 | - * Holds class instance |
|
13 | - * |
|
14 | - * @since 1.0.0 |
|
15 | - * |
|
16 | - * @var object \lsx_health_plan\classes\integrations\woocommerce\Plans() |
|
17 | - */ |
|
18 | - protected static $instance = null; |
|
11 | + /** |
|
12 | + * Holds class instance |
|
13 | + * |
|
14 | + * @since 1.0.0 |
|
15 | + * |
|
16 | + * @var object \lsx_health_plan\classes\integrations\woocommerce\Plans() |
|
17 | + */ |
|
18 | + protected static $instance = null; |
|
19 | 19 | |
20 | - /** |
|
21 | - * Holds the current screen var if it is active. |
|
22 | - * |
|
23 | - * @var string |
|
24 | - */ |
|
25 | - public $screen = ''; |
|
20 | + /** |
|
21 | + * Holds the current screen var if it is active. |
|
22 | + * |
|
23 | + * @var string |
|
24 | + */ |
|
25 | + public $screen = ''; |
|
26 | 26 | |
27 | - /** |
|
28 | - * Holds the current array of product IDS. |
|
29 | - * |
|
30 | - * @var array |
|
31 | - */ |
|
32 | - public $product_ids = array(); |
|
27 | + /** |
|
28 | + * Holds the current array of product IDS. |
|
29 | + * |
|
30 | + * @var array |
|
31 | + */ |
|
32 | + public $product_ids = array(); |
|
33 | 33 | |
34 | - /** |
|
35 | - * Holds the curret parent ID. |
|
36 | - * |
|
37 | - * @var int |
|
38 | - */ |
|
39 | - public $parent_id = 0; |
|
34 | + /** |
|
35 | + * Holds the curret parent ID. |
|
36 | + * |
|
37 | + * @var int |
|
38 | + */ |
|
39 | + public $parent_id = 0; |
|
40 | 40 | |
41 | - /** |
|
42 | - * Constructor |
|
43 | - */ |
|
44 | - public function __construct() { |
|
45 | - // Remove the default restrictions, as we will add our own. |
|
46 | - add_action( 'wp', array( $this, 'set_screen' ), 1 ); |
|
47 | - add_action( 'wp', array( $this, 'disable_parent_plan_restrictions' ), 2 ); |
|
48 | - add_action( 'wp', array( $this, 'child_plan_redirect_restrictions' ), 2 ); |
|
41 | + /** |
|
42 | + * Constructor |
|
43 | + */ |
|
44 | + public function __construct() { |
|
45 | + // Remove the default restrictions, as we will add our own. |
|
46 | + add_action( 'wp', array( $this, 'set_screen' ), 1 ); |
|
47 | + add_action( 'wp', array( $this, 'disable_parent_plan_restrictions' ), 2 ); |
|
48 | + add_action( 'wp', array( $this, 'child_plan_redirect_restrictions' ), 2 ); |
|
49 | 49 | |
50 | - // Initiate the WP Head functions. |
|
51 | - add_action( 'wp_head', array( $this, 'set_screen' ) ); |
|
52 | - add_action( 'lsx_content_top', 'lsx_hp_single_plan_products' ); |
|
50 | + // Initiate the WP Head functions. |
|
51 | + add_action( 'wp_head', array( $this, 'set_screen' ) ); |
|
52 | + add_action( 'lsx_content_top', 'lsx_hp_single_plan_products' ); |
|
53 | 53 | |
54 | - // Plan Archive Actions. |
|
55 | - add_action( 'lsx_entry_before', array( $this, 'set_product_ids' ) ); |
|
56 | - } |
|
54 | + // Plan Archive Actions. |
|
55 | + add_action( 'lsx_entry_before', array( $this, 'set_product_ids' ) ); |
|
56 | + } |
|
57 | 57 | |
58 | - /** |
|
59 | - * Return an instance of this class. |
|
60 | - * |
|
61 | - * @since 1.0.0 |
|
62 | - * |
|
63 | - * @return object \lsx_health_plan\classes\integrations\woocommerce\Plans() A single instance of this class. |
|
64 | - */ |
|
65 | - public static function get_instance() { |
|
66 | - // If the single instance hasn't been set, set it now. |
|
67 | - if ( null === self::$instance ) { |
|
68 | - self::$instance = new self(); |
|
69 | - } |
|
70 | - return self::$instance; |
|
71 | - } |
|
58 | + /** |
|
59 | + * Return an instance of this class. |
|
60 | + * |
|
61 | + * @since 1.0.0 |
|
62 | + * |
|
63 | + * @return object \lsx_health_plan\classes\integrations\woocommerce\Plans() A single instance of this class. |
|
64 | + */ |
|
65 | + public static function get_instance() { |
|
66 | + // If the single instance hasn't been set, set it now. |
|
67 | + if ( null === self::$instance ) { |
|
68 | + self::$instance = new self(); |
|
69 | + } |
|
70 | + return self::$instance; |
|
71 | + } |
|
72 | 72 | |
73 | - /** |
|
74 | - * Define the product metabox on the plan post type |
|
75 | - */ |
|
76 | - public function set_screen() { |
|
77 | - if ( is_singular( array( 'plan' ) ) ) { |
|
78 | - $section = get_query_var( 'section' ); |
|
79 | - if ( ! empty( $section ) ) { |
|
80 | - $this->screen = 'child_plan'; |
|
81 | - } else { |
|
82 | - $this->screen = 'parent_plan'; |
|
83 | - } |
|
84 | - $product_ids = get_post_meta( get_the_ID(), 'plan_product', true ); |
|
85 | - if ( false !== $product_ids && ! empty( $product_ids ) ) { |
|
86 | - $this->product_ids = $product_ids; |
|
87 | - } |
|
88 | - } |
|
89 | - if ( is_singular( array( 'workout', 'meal' ) ) ) { |
|
90 | - $parent_id = wp_get_post_parent_id( get_the_ID() ); |
|
91 | - if ( 0 === $parent_id || false === $parent_id ) { |
|
92 | - $this->screen = 'parent_plan'; |
|
93 | - } else { |
|
94 | - $this->screen = 'child_plan'; |
|
95 | - } |
|
96 | - } |
|
97 | - if ( is_post_type_archive( array( 'plan', 'workout', 'meal' ) ) || is_tax( array( 'plan-type', 'workout-type', 'meal-type' ) ) ) { |
|
98 | - $this->screen = 'plan_archive'; |
|
99 | - } |
|
100 | - } |
|
73 | + /** |
|
74 | + * Define the product metabox on the plan post type |
|
75 | + */ |
|
76 | + public function set_screen() { |
|
77 | + if ( is_singular( array( 'plan' ) ) ) { |
|
78 | + $section = get_query_var( 'section' ); |
|
79 | + if ( ! empty( $section ) ) { |
|
80 | + $this->screen = 'child_plan'; |
|
81 | + } else { |
|
82 | + $this->screen = 'parent_plan'; |
|
83 | + } |
|
84 | + $product_ids = get_post_meta( get_the_ID(), 'plan_product', true ); |
|
85 | + if ( false !== $product_ids && ! empty( $product_ids ) ) { |
|
86 | + $this->product_ids = $product_ids; |
|
87 | + } |
|
88 | + } |
|
89 | + if ( is_singular( array( 'workout', 'meal' ) ) ) { |
|
90 | + $parent_id = wp_get_post_parent_id( get_the_ID() ); |
|
91 | + if ( 0 === $parent_id || false === $parent_id ) { |
|
92 | + $this->screen = 'parent_plan'; |
|
93 | + } else { |
|
94 | + $this->screen = 'child_plan'; |
|
95 | + } |
|
96 | + } |
|
97 | + if ( is_post_type_archive( array( 'plan', 'workout', 'meal' ) ) || is_tax( array( 'plan-type', 'workout-type', 'meal-type' ) ) ) { |
|
98 | + $this->screen = 'plan_archive'; |
|
99 | + } |
|
100 | + } |
|
101 | 101 | |
102 | - /** |
|
103 | - * Sets the post type archive product ids. |
|
104 | - * |
|
105 | - * @return void |
|
106 | - */ |
|
107 | - public function set_product_ids() { |
|
108 | - $this->product_ids = false; |
|
109 | - if ( 'plan' === get_post_type() ) { |
|
110 | - $product_ids = get_post_meta( get_the_ID(), 'plan_product', true ); |
|
111 | - if ( false !== $product_ids && ! empty( $product_ids ) ) { |
|
112 | - $this->product_ids = $product_ids; |
|
113 | - } |
|
114 | - } |
|
115 | - } |
|
102 | + /** |
|
103 | + * Sets the post type archive product ids. |
|
104 | + * |
|
105 | + * @return void |
|
106 | + */ |
|
107 | + public function set_product_ids() { |
|
108 | + $this->product_ids = false; |
|
109 | + if ( 'plan' === get_post_type() ) { |
|
110 | + $product_ids = get_post_meta( get_the_ID(), 'plan_product', true ); |
|
111 | + if ( false !== $product_ids && ! empty( $product_ids ) ) { |
|
112 | + $this->product_ids = $product_ids; |
|
113 | + } |
|
114 | + } |
|
115 | + } |
|
116 | 116 | |
117 | - /** |
|
118 | - * Disable WC Memberships restrictions for plan parents. We add our own custom |
|
119 | - * restriction functionality elsewhere. |
|
120 | - */ |
|
121 | - public function disable_parent_plan_restrictions() { |
|
122 | - if ( '' === $this->screen || ! function_exists( 'wc_memberships' ) ) { |
|
123 | - return; |
|
124 | - } |
|
117 | + /** |
|
118 | + * Disable WC Memberships restrictions for plan parents. We add our own custom |
|
119 | + * restriction functionality elsewhere. |
|
120 | + */ |
|
121 | + public function disable_parent_plan_restrictions() { |
|
122 | + if ( '' === $this->screen || ! function_exists( 'wc_memberships' ) ) { |
|
123 | + return; |
|
124 | + } |
|
125 | 125 | |
126 | - $restrictions = wc_memberships()->get_restrictions_instance()->get_posts_restrictions_instance(); |
|
127 | - remove_action( 'wp', array( $restrictions, 'handle_restriction_modes' ) ); |
|
128 | - } |
|
126 | + $restrictions = wc_memberships()->get_restrictions_instance()->get_posts_restrictions_instance(); |
|
127 | + remove_action( 'wp', array( $restrictions, 'handle_restriction_modes' ) ); |
|
128 | + } |
|
129 | 129 | |
130 | - /** |
|
131 | - * Disable WC Memberships restrictions for plan parents. We add our own custom |
|
132 | - * restriction functionality elsewhere. |
|
133 | - */ |
|
134 | - public function child_plan_redirect_restrictions() { |
|
135 | - if ( ! function_exists( 'wc_memberships' ) || ! is_singular( 'plan' ) || 'child_plan' !== $this->screen || ! function_exists( 'wc_memberships_is_post_content_restricted' ) ) { |
|
136 | - return; |
|
137 | - } |
|
138 | - $restricted = wc_memberships_is_post_content_restricted() && ! current_user_can( 'wc_memberships_view_restricted_post_content', get_the_ID() ); |
|
139 | - if ( true === $restricted ) { |
|
140 | - wp_redirect( get_permalink( get_the_ID() ) ); |
|
141 | - exit; |
|
142 | - } |
|
143 | - } |
|
130 | + /** |
|
131 | + * Disable WC Memberships restrictions for plan parents. We add our own custom |
|
132 | + * restriction functionality elsewhere. |
|
133 | + */ |
|
134 | + public function child_plan_redirect_restrictions() { |
|
135 | + if ( ! function_exists( 'wc_memberships' ) || ! is_singular( 'plan' ) || 'child_plan' !== $this->screen || ! function_exists( 'wc_memberships_is_post_content_restricted' ) ) { |
|
136 | + return; |
|
137 | + } |
|
138 | + $restricted = wc_memberships_is_post_content_restricted() && ! current_user_can( 'wc_memberships_view_restricted_post_content', get_the_ID() ); |
|
139 | + if ( true === $restricted ) { |
|
140 | + wp_redirect( get_permalink( get_the_ID() ) ); |
|
141 | + exit; |
|
142 | + } |
|
143 | + } |
|
144 | 144 | |
145 | - /** |
|
146 | - * Returns the ids of the attached products. |
|
147 | - * |
|
148 | - * @return array |
|
149 | - */ |
|
150 | - public function get_products() { |
|
151 | - return $this->product_ids; |
|
152 | - } |
|
145 | + /** |
|
146 | + * Returns the ids of the attached products. |
|
147 | + * |
|
148 | + * @return array |
|
149 | + */ |
|
150 | + public function get_products() { |
|
151 | + return $this->product_ids; |
|
152 | + } |
|
153 | 153 | } |
@@ -43,16 +43,16 @@ discard block |
||
43 | 43 | */ |
44 | 44 | public function __construct() { |
45 | 45 | // Remove the default restrictions, as we will add our own. |
46 | - add_action( 'wp', array( $this, 'set_screen' ), 1 ); |
|
47 | - add_action( 'wp', array( $this, 'disable_parent_plan_restrictions' ), 2 ); |
|
48 | - add_action( 'wp', array( $this, 'child_plan_redirect_restrictions' ), 2 ); |
|
46 | + add_action('wp', array($this, 'set_screen'), 1); |
|
47 | + add_action('wp', array($this, 'disable_parent_plan_restrictions'), 2); |
|
48 | + add_action('wp', array($this, 'child_plan_redirect_restrictions'), 2); |
|
49 | 49 | |
50 | 50 | // Initiate the WP Head functions. |
51 | - add_action( 'wp_head', array( $this, 'set_screen' ) ); |
|
52 | - add_action( 'lsx_content_top', 'lsx_hp_single_plan_products' ); |
|
51 | + add_action('wp_head', array($this, 'set_screen')); |
|
52 | + add_action('lsx_content_top', 'lsx_hp_single_plan_products'); |
|
53 | 53 | |
54 | 54 | // Plan Archive Actions. |
55 | - add_action( 'lsx_entry_before', array( $this, 'set_product_ids' ) ); |
|
55 | + add_action('lsx_entry_before', array($this, 'set_product_ids')); |
|
56 | 56 | } |
57 | 57 | |
58 | 58 | /** |
@@ -64,7 +64,7 @@ discard block |
||
64 | 64 | */ |
65 | 65 | public static function get_instance() { |
66 | 66 | // If the single instance hasn't been set, set it now. |
67 | - if ( null === self::$instance ) { |
|
67 | + if (null === self::$instance) { |
|
68 | 68 | self::$instance = new self(); |
69 | 69 | } |
70 | 70 | return self::$instance; |
@@ -74,27 +74,27 @@ discard block |
||
74 | 74 | * Define the product metabox on the plan post type |
75 | 75 | */ |
76 | 76 | public function set_screen() { |
77 | - if ( is_singular( array( 'plan' ) ) ) { |
|
78 | - $section = get_query_var( 'section' ); |
|
79 | - if ( ! empty( $section ) ) { |
|
77 | + if (is_singular(array('plan'))) { |
|
78 | + $section = get_query_var('section'); |
|
79 | + if ( ! empty($section)) { |
|
80 | 80 | $this->screen = 'child_plan'; |
81 | 81 | } else { |
82 | 82 | $this->screen = 'parent_plan'; |
83 | 83 | } |
84 | - $product_ids = get_post_meta( get_the_ID(), 'plan_product', true ); |
|
85 | - if ( false !== $product_ids && ! empty( $product_ids ) ) { |
|
84 | + $product_ids = get_post_meta(get_the_ID(), 'plan_product', true); |
|
85 | + if (false !== $product_ids && ! empty($product_ids)) { |
|
86 | 86 | $this->product_ids = $product_ids; |
87 | 87 | } |
88 | 88 | } |
89 | - if ( is_singular( array( 'workout', 'meal' ) ) ) { |
|
90 | - $parent_id = wp_get_post_parent_id( get_the_ID() ); |
|
91 | - if ( 0 === $parent_id || false === $parent_id ) { |
|
89 | + if (is_singular(array('workout', 'meal'))) { |
|
90 | + $parent_id = wp_get_post_parent_id(get_the_ID()); |
|
91 | + if (0 === $parent_id || false === $parent_id) { |
|
92 | 92 | $this->screen = 'parent_plan'; |
93 | 93 | } else { |
94 | 94 | $this->screen = 'child_plan'; |
95 | 95 | } |
96 | 96 | } |
97 | - if ( is_post_type_archive( array( 'plan', 'workout', 'meal' ) ) || is_tax( array( 'plan-type', 'workout-type', 'meal-type' ) ) ) { |
|
97 | + if (is_post_type_archive(array('plan', 'workout', 'meal')) || is_tax(array('plan-type', 'workout-type', 'meal-type'))) { |
|
98 | 98 | $this->screen = 'plan_archive'; |
99 | 99 | } |
100 | 100 | } |
@@ -106,9 +106,9 @@ discard block |
||
106 | 106 | */ |
107 | 107 | public function set_product_ids() { |
108 | 108 | $this->product_ids = false; |
109 | - if ( 'plan' === get_post_type() ) { |
|
110 | - $product_ids = get_post_meta( get_the_ID(), 'plan_product', true ); |
|
111 | - if ( false !== $product_ids && ! empty( $product_ids ) ) { |
|
109 | + if ('plan' === get_post_type()) { |
|
110 | + $product_ids = get_post_meta(get_the_ID(), 'plan_product', true); |
|
111 | + if (false !== $product_ids && ! empty($product_ids)) { |
|
112 | 112 | $this->product_ids = $product_ids; |
113 | 113 | } |
114 | 114 | } |
@@ -119,12 +119,12 @@ discard block |
||
119 | 119 | * restriction functionality elsewhere. |
120 | 120 | */ |
121 | 121 | public function disable_parent_plan_restrictions() { |
122 | - if ( '' === $this->screen || ! function_exists( 'wc_memberships' ) ) { |
|
122 | + if ('' === $this->screen || ! function_exists('wc_memberships')) { |
|
123 | 123 | return; |
124 | 124 | } |
125 | 125 | |
126 | 126 | $restrictions = wc_memberships()->get_restrictions_instance()->get_posts_restrictions_instance(); |
127 | - remove_action( 'wp', array( $restrictions, 'handle_restriction_modes' ) ); |
|
127 | + remove_action('wp', array($restrictions, 'handle_restriction_modes')); |
|
128 | 128 | } |
129 | 129 | |
130 | 130 | /** |
@@ -132,12 +132,12 @@ discard block |
||
132 | 132 | * restriction functionality elsewhere. |
133 | 133 | */ |
134 | 134 | public function child_plan_redirect_restrictions() { |
135 | - if ( ! function_exists( 'wc_memberships' ) || ! is_singular( 'plan' ) || 'child_plan' !== $this->screen || ! function_exists( 'wc_memberships_is_post_content_restricted' ) ) { |
|
135 | + if ( ! function_exists('wc_memberships') || ! is_singular('plan') || 'child_plan' !== $this->screen || ! function_exists('wc_memberships_is_post_content_restricted')) { |
|
136 | 136 | return; |
137 | 137 | } |
138 | - $restricted = wc_memberships_is_post_content_restricted() && ! current_user_can( 'wc_memberships_view_restricted_post_content', get_the_ID() ); |
|
139 | - if ( true === $restricted ) { |
|
140 | - wp_redirect( get_permalink( get_the_ID() ) ); |
|
138 | + $restricted = wc_memberships_is_post_content_restricted() && ! current_user_can('wc_memberships_view_restricted_post_content', get_the_ID()); |
|
139 | + if (true === $restricted) { |
|
140 | + wp_redirect(get_permalink(get_the_ID())); |
|
141 | 141 | exit; |
142 | 142 | } |
143 | 143 | } |
@@ -21,9 +21,9 @@ |
||
21 | 21 | <div class="row"> |
22 | 22 | <?php if ( have_posts() ) : ?> |
23 | 23 | <?php |
24 | - while ( have_posts() ) : |
|
25 | - the_post(); |
|
26 | - ?> |
|
24 | + while ( have_posts() ) : |
|
25 | + the_post(); |
|
26 | + ?> |
|
27 | 27 | |
28 | 28 | <?php include LSX_HEALTH_PLAN_PATH . '/templates/content-archive-recipe.php'; ?> |
29 | 29 |
@@ -9,7 +9,7 @@ discard block |
||
9 | 9 | |
10 | 10 | <?php lsx_content_wrap_before(); ?> |
11 | 11 | |
12 | - <div id="primary" class="content-area <?php echo esc_attr( lsx_main_class() ); ?>"> |
|
12 | + <div id="primary" class="content-area <?php echo esc_attr(lsx_main_class()); ?>"> |
|
13 | 13 | |
14 | 14 | <?php lsx_content_before(); ?> |
15 | 15 | |
@@ -19,9 +19,9 @@ discard block |
||
19 | 19 | |
20 | 20 | <div class="post-wrapper archive-plan"> |
21 | 21 | <div class="row"> |
22 | - <?php if ( have_posts() ) : ?> |
|
22 | + <?php if (have_posts()) : ?> |
|
23 | 23 | <?php |
24 | - while ( have_posts() ) : |
|
24 | + while (have_posts()) : |
|
25 | 25 | the_post(); |
26 | 26 | ?> |
27 | 27 | |
@@ -31,7 +31,7 @@ discard block |
||
31 | 31 | |
32 | 32 | <?php else : ?> |
33 | 33 | |
34 | - <?php get_template_part( 'partials/content', 'none' ); ?> |
|
34 | + <?php get_template_part('partials/content', 'none'); ?> |
|
35 | 35 | |
36 | 36 | <?php endif; ?> |
37 | 37 | </div> |
@@ -33,9 +33,12 @@ |
||
33 | 33 | |
34 | 34 | <?php endwhile; ?> |
35 | 35 | |
36 | - <?php else : ?> |
|
36 | + <?php else { |
|
37 | + : ?> |
|
37 | 38 | |
38 | - <?php get_template_part( 'partials/content', 'none' ); ?> |
|
39 | + <?php get_template_part( 'partials/content', 'none' ); |
|
40 | +} |
|
41 | +?> |
|
39 | 42 | |
40 | 43 | <?php endif; ?> |
41 | 44 | </div> |
@@ -33,9 +33,12 @@ |
||
33 | 33 | |
34 | 34 | <?php endwhile; ?> |
35 | 35 | |
36 | - <?php else : ?> |
|
36 | + <?php else { |
|
37 | + : ?> |
|
37 | 38 | |
38 | - <?php get_template_part( 'partials/content', 'none' ); ?> |
|
39 | + <?php get_template_part( 'partials/content', 'none' ); |
|
40 | +} |
|
41 | +?> |
|
39 | 42 | |
40 | 43 | <?php endif; ?> |
41 | 44 | </div> |
@@ -21,9 +21,9 @@ |
||
21 | 21 | <div class="row"> |
22 | 22 | <?php if ( have_posts() ) : ?> |
23 | 23 | <?php |
24 | - while ( have_posts() ) : |
|
25 | - the_post(); |
|
26 | - ?> |
|
24 | + while ( have_posts() ) : |
|
25 | + the_post(); |
|
26 | + ?> |
|
27 | 27 | |
28 | 28 | <?php include LSX_HEALTH_PLAN_PATH . '/templates/content-archive-recipe.php'; ?> |
29 | 29 |
@@ -9,7 +9,7 @@ discard block |
||
9 | 9 | |
10 | 10 | <?php lsx_content_wrap_before(); ?> |
11 | 11 | |
12 | - <div id="primary" class="content-area <?php echo esc_attr( lsx_main_class() ); ?>"> |
|
12 | + <div id="primary" class="content-area <?php echo esc_attr(lsx_main_class()); ?>"> |
|
13 | 13 | |
14 | 14 | <?php lsx_content_before(); ?> |
15 | 15 | |
@@ -19,9 +19,9 @@ discard block |
||
19 | 19 | |
20 | 20 | <div class="post-wrapper archive-plan"> |
21 | 21 | <div class="row"> |
22 | - <?php if ( have_posts() ) : ?> |
|
22 | + <?php if (have_posts()) : ?> |
|
23 | 23 | <?php |
24 | - while ( have_posts() ) : |
|
24 | + while (have_posts()) : |
|
25 | 25 | the_post(); |
26 | 26 | ?> |
27 | 27 | |
@@ -31,7 +31,7 @@ discard block |
||
31 | 31 | |
32 | 32 | <?php else : ?> |
33 | 33 | |
34 | - <?php get_template_part( 'partials/content', 'none' ); ?> |
|
34 | + <?php get_template_part('partials/content', 'none'); ?> |
|
35 | 35 | |
36 | 36 | <?php endif; ?> |
37 | 37 | </div> |
@@ -33,9 +33,12 @@ |
||
33 | 33 | |
34 | 34 | <?php endwhile; ?> |
35 | 35 | |
36 | - <?php else : ?> |
|
36 | + <?php else { |
|
37 | + : ?> |
|
37 | 38 | |
38 | - <?php get_template_part( 'partials/content', 'none' ); ?> |
|
39 | + <?php get_template_part( 'partials/content', 'none' ); |
|
40 | +} |
|
41 | +?> |
|
39 | 42 | |
40 | 43 | <?php endif; ?> |
41 | 44 | </div> |
@@ -21,9 +21,9 @@ |
||
21 | 21 | <div class="row"> |
22 | 22 | <?php if ( have_posts() ) : ?> |
23 | 23 | <?php |
24 | - while ( have_posts() ) : |
|
25 | - the_post(); |
|
26 | - ?> |
|
24 | + while ( have_posts() ) : |
|
25 | + the_post(); |
|
26 | + ?> |
|
27 | 27 | |
28 | 28 | <?php include LSX_HEALTH_PLAN_PATH . '/templates/content-archive-recipe.php'; ?> |
29 | 29 |
@@ -9,7 +9,7 @@ discard block |
||
9 | 9 | |
10 | 10 | <?php lsx_content_wrap_before(); ?> |
11 | 11 | |
12 | - <div id="primary" class="content-area <?php echo esc_attr( lsx_main_class() ); ?>"> |
|
12 | + <div id="primary" class="content-area <?php echo esc_attr(lsx_main_class()); ?>"> |
|
13 | 13 | |
14 | 14 | <?php lsx_content_before(); ?> |
15 | 15 | |
@@ -19,9 +19,9 @@ discard block |
||
19 | 19 | |
20 | 20 | <div class="post-wrapper archive-plan"> |
21 | 21 | <div class="row"> |
22 | - <?php if ( have_posts() ) : ?> |
|
22 | + <?php if (have_posts()) : ?> |
|
23 | 23 | <?php |
24 | - while ( have_posts() ) : |
|
24 | + while (have_posts()) : |
|
25 | 25 | the_post(); |
26 | 26 | ?> |
27 | 27 | |
@@ -31,7 +31,7 @@ discard block |
||
31 | 31 | |
32 | 32 | <?php else : ?> |
33 | 33 | |
34 | - <?php get_template_part( 'partials/content', 'none' ); ?> |
|
34 | + <?php get_template_part('partials/content', 'none'); ?> |
|
35 | 35 | |
36 | 36 | <?php endif; ?> |
37 | 37 | </div> |
@@ -8,107 +8,107 @@ |
||
8 | 8 | */ |
9 | 9 | class Template_Redirects { |
10 | 10 | |
11 | - /** |
|
12 | - * Holds class instance |
|
13 | - * |
|
14 | - * @since 1.0.0 |
|
15 | - * |
|
16 | - * @var object \lsx_health_plan\classes\frontend\Template_Redirects() |
|
17 | - */ |
|
18 | - protected static $instance = null; |
|
11 | + /** |
|
12 | + * Holds class instance |
|
13 | + * |
|
14 | + * @since 1.0.0 |
|
15 | + * |
|
16 | + * @var object \lsx_health_plan\classes\frontend\Template_Redirects() |
|
17 | + */ |
|
18 | + protected static $instance = null; |
|
19 | 19 | |
20 | - /** |
|
21 | - * Constructor |
|
22 | - */ |
|
23 | - public function __construct() { |
|
24 | - add_filter( 'template_include', array( $this, 'archive_template_include' ), 99 ); |
|
25 | - add_filter( 'template_include', array( $this, 'single_template_include' ), 99 ); |
|
26 | - add_filter( 'template_include', array( $this, 'taxonomy_template_include' ), 99 ); |
|
27 | - add_action( 'wp', array( $this, 'redirect_restrictions' ), 99 ); |
|
28 | - } |
|
20 | + /** |
|
21 | + * Constructor |
|
22 | + */ |
|
23 | + public function __construct() { |
|
24 | + add_filter( 'template_include', array( $this, 'archive_template_include' ), 99 ); |
|
25 | + add_filter( 'template_include', array( $this, 'single_template_include' ), 99 ); |
|
26 | + add_filter( 'template_include', array( $this, 'taxonomy_template_include' ), 99 ); |
|
27 | + add_action( 'wp', array( $this, 'redirect_restrictions' ), 99 ); |
|
28 | + } |
|
29 | 29 | |
30 | - /** |
|
31 | - * Return an instance of this class. |
|
32 | - * |
|
33 | - * @since 1.0.0 |
|
34 | - * |
|
35 | - * @return object \lsx_health_plan\classes\frontend\Template_Redirects() A single instance of this class. |
|
36 | - */ |
|
37 | - public static function get_instance() { |
|
38 | - // If the single instance hasn't been set, set it now. |
|
39 | - if ( null === self::$instance ) { |
|
40 | - self::$instance = new self(); |
|
41 | - } |
|
42 | - return self::$instance; |
|
43 | - } |
|
30 | + /** |
|
31 | + * Return an instance of this class. |
|
32 | + * |
|
33 | + * @since 1.0.0 |
|
34 | + * |
|
35 | + * @return object \lsx_health_plan\classes\frontend\Template_Redirects() A single instance of this class. |
|
36 | + */ |
|
37 | + public static function get_instance() { |
|
38 | + // If the single instance hasn't been set, set it now. |
|
39 | + if ( null === self::$instance ) { |
|
40 | + self::$instance = new self(); |
|
41 | + } |
|
42 | + return self::$instance; |
|
43 | + } |
|
44 | 44 | |
45 | - /** |
|
46 | - * Archive template. |
|
47 | - */ |
|
48 | - public function archive_template_include( $template ) { |
|
49 | - $applicable_post_types = apply_filters( 'lsx_health_plan_archive_template', array() ); |
|
50 | - if ( ! empty( $applicable_post_types ) && is_main_query() && is_post_type_archive( $applicable_post_types ) ) { |
|
51 | - $post_type = get_post_type(); |
|
52 | - if ( empty( locate_template( array( 'archive-' . $post_type . '.php' ) ) ) && file_exists( LSX_HEALTH_PLAN_PATH . 'templates/archive-' . $post_type . '.php' ) ) { |
|
53 | - $template = LSX_HEALTH_PLAN_PATH . 'templates/archive-' . $post_type . '.php'; |
|
54 | - } |
|
55 | - } |
|
56 | - return $template; |
|
57 | - } |
|
45 | + /** |
|
46 | + * Archive template. |
|
47 | + */ |
|
48 | + public function archive_template_include( $template ) { |
|
49 | + $applicable_post_types = apply_filters( 'lsx_health_plan_archive_template', array() ); |
|
50 | + if ( ! empty( $applicable_post_types ) && is_main_query() && is_post_type_archive( $applicable_post_types ) ) { |
|
51 | + $post_type = get_post_type(); |
|
52 | + if ( empty( locate_template( array( 'archive-' . $post_type . '.php' ) ) ) && file_exists( LSX_HEALTH_PLAN_PATH . 'templates/archive-' . $post_type . '.php' ) ) { |
|
53 | + $template = LSX_HEALTH_PLAN_PATH . 'templates/archive-' . $post_type . '.php'; |
|
54 | + } |
|
55 | + } |
|
56 | + return $template; |
|
57 | + } |
|
58 | 58 | |
59 | - /** |
|
60 | - * Single template. |
|
61 | - */ |
|
62 | - public function single_template_include( $template ) { |
|
63 | - $applicable_post_types = apply_filters( 'lsx_health_plan_single_template', array() ); |
|
64 | - if ( ! empty( $applicable_post_types ) && is_main_query() && is_singular( $applicable_post_types ) ) { |
|
65 | - $post_type = get_post_type(); |
|
66 | - if ( empty( locate_template( array( 'single-' . $post_type . '.php' ) ) ) && file_exists( LSX_HEALTH_PLAN_PATH . 'templates/single-' . $post_type . '.php' ) ) { |
|
67 | - $template = LSX_HEALTH_PLAN_PATH . 'templates/single-' . $post_type . '.php'; |
|
68 | - } |
|
69 | - } |
|
70 | - return $template; |
|
71 | - } |
|
59 | + /** |
|
60 | + * Single template. |
|
61 | + */ |
|
62 | + public function single_template_include( $template ) { |
|
63 | + $applicable_post_types = apply_filters( 'lsx_health_plan_single_template', array() ); |
|
64 | + if ( ! empty( $applicable_post_types ) && is_main_query() && is_singular( $applicable_post_types ) ) { |
|
65 | + $post_type = get_post_type(); |
|
66 | + if ( empty( locate_template( array( 'single-' . $post_type . '.php' ) ) ) && file_exists( LSX_HEALTH_PLAN_PATH . 'templates/single-' . $post_type . '.php' ) ) { |
|
67 | + $template = LSX_HEALTH_PLAN_PATH . 'templates/single-' . $post_type . '.php'; |
|
68 | + } |
|
69 | + } |
|
70 | + return $template; |
|
71 | + } |
|
72 | 72 | |
73 | - /** |
|
74 | - * Redirect WordPress to the taxonomy located in the plugin |
|
75 | - * |
|
76 | - * @param $template string |
|
77 | - * @return string |
|
78 | - */ |
|
79 | - public function taxonomy_template_include( $template ) { |
|
80 | - $applicable_taxonomies = apply_filters( 'lsx_health_plan_taxonomies_template', array() ); |
|
81 | - if ( is_main_query() && is_tax( $applicable_taxonomies ) ) { |
|
82 | - $current_taxonomy = get_query_var( 'taxonomy' ); |
|
83 | - if ( '' === locate_template( array( 'taxonomy-' . $current_taxonomy . '.php' ) ) && file_exists( LSX_HEALTH_PLAN_PATH . 'templates/taxonomy-' . $current_taxonomy . '.php' ) ) { |
|
84 | - $template = LSX_HEALTH_PLAN_PATH . 'templates/taxonomy-' . $current_taxonomy . '.php'; |
|
85 | - } |
|
86 | - } |
|
87 | - return $template; |
|
88 | - } |
|
73 | + /** |
|
74 | + * Redirect WordPress to the taxonomy located in the plugin |
|
75 | + * |
|
76 | + * @param $template string |
|
77 | + * @return string |
|
78 | + */ |
|
79 | + public function taxonomy_template_include( $template ) { |
|
80 | + $applicable_taxonomies = apply_filters( 'lsx_health_plan_taxonomies_template', array() ); |
|
81 | + if ( is_main_query() && is_tax( $applicable_taxonomies ) ) { |
|
82 | + $current_taxonomy = get_query_var( 'taxonomy' ); |
|
83 | + if ( '' === locate_template( array( 'taxonomy-' . $current_taxonomy . '.php' ) ) && file_exists( LSX_HEALTH_PLAN_PATH . 'templates/taxonomy-' . $current_taxonomy . '.php' ) ) { |
|
84 | + $template = LSX_HEALTH_PLAN_PATH . 'templates/taxonomy-' . $current_taxonomy . '.php'; |
|
85 | + } |
|
86 | + } |
|
87 | + return $template; |
|
88 | + } |
|
89 | 89 | |
90 | - /** |
|
91 | - * Disable WC Memberships restrictions for plan parents. We add our own custom |
|
92 | - * restriction functionality elsewhere. |
|
93 | - */ |
|
94 | - public function redirect_restrictions() { |
|
95 | - if ( function_exists( 'WC' ) && ! is_user_logged_in() ) { |
|
96 | - if ( is_post_type_archive( array( 'recipe', 'exercise', 'meal', 'workout' ) ) |
|
97 | - || is_tax( array( 'meal-type', 'workout-type', 'recipe-type', 'recipe-cuisine', 'exercise-type', 'equipment', 'muscle-group' ) ) |
|
98 | - || is_single( 'recipe', 'exercise' ) ) { |
|
90 | + /** |
|
91 | + * Disable WC Memberships restrictions for plan parents. We add our own custom |
|
92 | + * restriction functionality elsewhere. |
|
93 | + */ |
|
94 | + public function redirect_restrictions() { |
|
95 | + if ( function_exists( 'WC' ) && ! is_user_logged_in() ) { |
|
96 | + if ( is_post_type_archive( array( 'recipe', 'exercise', 'meal', 'workout' ) ) |
|
97 | + || is_tax( array( 'meal-type', 'workout-type', 'recipe-type', 'recipe-cuisine', 'exercise-type', 'equipment', 'muscle-group' ) ) |
|
98 | + || is_single( 'recipe', 'exercise' ) ) { |
|
99 | 99 | |
100 | - $redirect = \lsx_health_plan\functions\get_option( 'my_plan_slug', '/' ); |
|
101 | - if ( function_exists( 'wc_memberships' ) ) { |
|
102 | - $restriction_mode = wc_memberships()->get_restrictions_instance()->get_restriction_mode(); |
|
103 | - if ( 'redirect' === $restriction_mode ) { |
|
104 | - $page_id = wc_memberships()->get_restrictions_instance()->get_restricted_content_redirect_page_id(); |
|
105 | - $redirect = get_permalink( $page_id ); |
|
106 | - } |
|
107 | - } |
|
100 | + $redirect = \lsx_health_plan\functions\get_option( 'my_plan_slug', '/' ); |
|
101 | + if ( function_exists( 'wc_memberships' ) ) { |
|
102 | + $restriction_mode = wc_memberships()->get_restrictions_instance()->get_restriction_mode(); |
|
103 | + if ( 'redirect' === $restriction_mode ) { |
|
104 | + $page_id = wc_memberships()->get_restrictions_instance()->get_restricted_content_redirect_page_id(); |
|
105 | + $redirect = get_permalink( $page_id ); |
|
106 | + } |
|
107 | + } |
|
108 | 108 | |
109 | - wp_redirect( $redirect ); |
|
110 | - exit; |
|
111 | - } |
|
112 | - } |
|
113 | - } |
|
109 | + wp_redirect( $redirect ); |
|
110 | + exit; |
|
111 | + } |
|
112 | + } |
|
113 | + } |
|
114 | 114 | } |
@@ -21,10 +21,10 @@ discard block |
||
21 | 21 | * Constructor |
22 | 22 | */ |
23 | 23 | public function __construct() { |
24 | - add_filter( 'template_include', array( $this, 'archive_template_include' ), 99 ); |
|
25 | - add_filter( 'template_include', array( $this, 'single_template_include' ), 99 ); |
|
26 | - add_filter( 'template_include', array( $this, 'taxonomy_template_include' ), 99 ); |
|
27 | - add_action( 'wp', array( $this, 'redirect_restrictions' ), 99 ); |
|
24 | + add_filter('template_include', array($this, 'archive_template_include'), 99); |
|
25 | + add_filter('template_include', array($this, 'single_template_include'), 99); |
|
26 | + add_filter('template_include', array($this, 'taxonomy_template_include'), 99); |
|
27 | + add_action('wp', array($this, 'redirect_restrictions'), 99); |
|
28 | 28 | } |
29 | 29 | |
30 | 30 | /** |
@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | */ |
37 | 37 | public static function get_instance() { |
38 | 38 | // If the single instance hasn't been set, set it now. |
39 | - if ( null === self::$instance ) { |
|
39 | + if (null === self::$instance) { |
|
40 | 40 | self::$instance = new self(); |
41 | 41 | } |
42 | 42 | return self::$instance; |
@@ -45,11 +45,11 @@ discard block |
||
45 | 45 | /** |
46 | 46 | * Archive template. |
47 | 47 | */ |
48 | - public function archive_template_include( $template ) { |
|
49 | - $applicable_post_types = apply_filters( 'lsx_health_plan_archive_template', array() ); |
|
50 | - if ( ! empty( $applicable_post_types ) && is_main_query() && is_post_type_archive( $applicable_post_types ) ) { |
|
48 | + public function archive_template_include($template) { |
|
49 | + $applicable_post_types = apply_filters('lsx_health_plan_archive_template', array()); |
|
50 | + if ( ! empty($applicable_post_types) && is_main_query() && is_post_type_archive($applicable_post_types)) { |
|
51 | 51 | $post_type = get_post_type(); |
52 | - if ( empty( locate_template( array( 'archive-' . $post_type . '.php' ) ) ) && file_exists( LSX_HEALTH_PLAN_PATH . 'templates/archive-' . $post_type . '.php' ) ) { |
|
52 | + if (empty(locate_template(array('archive-' . $post_type . '.php'))) && file_exists(LSX_HEALTH_PLAN_PATH . 'templates/archive-' . $post_type . '.php')) { |
|
53 | 53 | $template = LSX_HEALTH_PLAN_PATH . 'templates/archive-' . $post_type . '.php'; |
54 | 54 | } |
55 | 55 | } |
@@ -59,11 +59,11 @@ discard block |
||
59 | 59 | /** |
60 | 60 | * Single template. |
61 | 61 | */ |
62 | - public function single_template_include( $template ) { |
|
63 | - $applicable_post_types = apply_filters( 'lsx_health_plan_single_template', array() ); |
|
64 | - if ( ! empty( $applicable_post_types ) && is_main_query() && is_singular( $applicable_post_types ) ) { |
|
62 | + public function single_template_include($template) { |
|
63 | + $applicable_post_types = apply_filters('lsx_health_plan_single_template', array()); |
|
64 | + if ( ! empty($applicable_post_types) && is_main_query() && is_singular($applicable_post_types)) { |
|
65 | 65 | $post_type = get_post_type(); |
66 | - if ( empty( locate_template( array( 'single-' . $post_type . '.php' ) ) ) && file_exists( LSX_HEALTH_PLAN_PATH . 'templates/single-' . $post_type . '.php' ) ) { |
|
66 | + if (empty(locate_template(array('single-' . $post_type . '.php'))) && file_exists(LSX_HEALTH_PLAN_PATH . 'templates/single-' . $post_type . '.php')) { |
|
67 | 67 | $template = LSX_HEALTH_PLAN_PATH . 'templates/single-' . $post_type . '.php'; |
68 | 68 | } |
69 | 69 | } |
@@ -76,11 +76,11 @@ discard block |
||
76 | 76 | * @param $template string |
77 | 77 | * @return string |
78 | 78 | */ |
79 | - public function taxonomy_template_include( $template ) { |
|
80 | - $applicable_taxonomies = apply_filters( 'lsx_health_plan_taxonomies_template', array() ); |
|
81 | - if ( is_main_query() && is_tax( $applicable_taxonomies ) ) { |
|
82 | - $current_taxonomy = get_query_var( 'taxonomy' ); |
|
83 | - if ( '' === locate_template( array( 'taxonomy-' . $current_taxonomy . '.php' ) ) && file_exists( LSX_HEALTH_PLAN_PATH . 'templates/taxonomy-' . $current_taxonomy . '.php' ) ) { |
|
79 | + public function taxonomy_template_include($template) { |
|
80 | + $applicable_taxonomies = apply_filters('lsx_health_plan_taxonomies_template', array()); |
|
81 | + if (is_main_query() && is_tax($applicable_taxonomies)) { |
|
82 | + $current_taxonomy = get_query_var('taxonomy'); |
|
83 | + if ('' === locate_template(array('taxonomy-' . $current_taxonomy . '.php')) && file_exists(LSX_HEALTH_PLAN_PATH . 'templates/taxonomy-' . $current_taxonomy . '.php')) { |
|
84 | 84 | $template = LSX_HEALTH_PLAN_PATH . 'templates/taxonomy-' . $current_taxonomy . '.php'; |
85 | 85 | } |
86 | 86 | } |
@@ -92,21 +92,21 @@ discard block |
||
92 | 92 | * restriction functionality elsewhere. |
93 | 93 | */ |
94 | 94 | public function redirect_restrictions() { |
95 | - if ( function_exists( 'WC' ) && ! is_user_logged_in() ) { |
|
96 | - if ( is_post_type_archive( array( 'recipe', 'exercise', 'meal', 'workout' ) ) |
|
97 | - || is_tax( array( 'meal-type', 'workout-type', 'recipe-type', 'recipe-cuisine', 'exercise-type', 'equipment', 'muscle-group' ) ) |
|
98 | - || is_single( 'recipe', 'exercise' ) ) { |
|
95 | + if (function_exists('WC') && ! is_user_logged_in()) { |
|
96 | + if (is_post_type_archive(array('recipe', 'exercise', 'meal', 'workout')) |
|
97 | + || is_tax(array('meal-type', 'workout-type', 'recipe-type', 'recipe-cuisine', 'exercise-type', 'equipment', 'muscle-group')) |
|
98 | + || is_single('recipe', 'exercise')) { |
|
99 | 99 | |
100 | - $redirect = \lsx_health_plan\functions\get_option( 'my_plan_slug', '/' ); |
|
101 | - if ( function_exists( 'wc_memberships' ) ) { |
|
100 | + $redirect = \lsx_health_plan\functions\get_option('my_plan_slug', '/'); |
|
101 | + if (function_exists('wc_memberships')) { |
|
102 | 102 | $restriction_mode = wc_memberships()->get_restrictions_instance()->get_restriction_mode(); |
103 | - if ( 'redirect' === $restriction_mode ) { |
|
103 | + if ('redirect' === $restriction_mode) { |
|
104 | 104 | $page_id = wc_memberships()->get_restrictions_instance()->get_restricted_content_redirect_page_id(); |
105 | - $redirect = get_permalink( $page_id ); |
|
105 | + $redirect = get_permalink($page_id); |
|
106 | 106 | } |
107 | 107 | } |
108 | 108 | |
109 | - wp_redirect( $redirect ); |
|
109 | + wp_redirect($redirect); |
|
110 | 110 | exit; |
111 | 111 | } |
112 | 112 | } |