@@ -8,245 +8,245 @@ 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; |
|
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 | 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'; |
|
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 | 28 | |
29 | - /** |
|
30 | - * Holds post_type labels |
|
31 | - * |
|
32 | - * @since 1.0.0 |
|
33 | - * |
|
34 | - * @var string |
|
35 | - */ |
|
36 | - public $labels = array(); |
|
29 | + /** |
|
30 | + * Holds post_type labels |
|
31 | + * |
|
32 | + * @since 1.0.0 |
|
33 | + * |
|
34 | + * @var string |
|
35 | + */ |
|
36 | + public $labels = array(); |
|
37 | 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' ) ); |
|
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 | 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' ) ); |
|
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 | 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 | - add_filter( 'woocommerce_get_breadcrumb', array( $this, 'recipes_breadcrumb_filter' ), 30, 1 ); |
|
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 | + add_filter( 'woocommerce_get_breadcrumb', array( $this, 'recipes_breadcrumb_filter' ), 30, 1 ); |
|
56 | 56 | |
57 | - // Backend Actions and Filters. |
|
58 | - add_action( 'cmb2_admin_init', array( $this, 'featured_metabox' ) ); |
|
59 | - add_action( 'cmb2_admin_init', array( $this, 'details_metaboxes' ) ); |
|
60 | - } |
|
57 | + // Backend Actions and Filters. |
|
58 | + add_action( 'cmb2_admin_init', array( $this, 'featured_metabox' ) ); |
|
59 | + add_action( 'cmb2_admin_init', array( $this, 'details_metaboxes' ) ); |
|
60 | + } |
|
61 | 61 | |
62 | - /** |
|
63 | - * Return an instance of this class. |
|
64 | - * |
|
65 | - * @since 1.0.0 |
|
66 | - * |
|
67 | - * @return object \lsx_health_plan\classes\Recipe() A single instance of this class. |
|
68 | - */ |
|
69 | - public static function get_instance() { |
|
62 | + /** |
|
63 | + * Return an instance of this class. |
|
64 | + * |
|
65 | + * @since 1.0.0 |
|
66 | + * |
|
67 | + * @return object \lsx_health_plan\classes\Recipe() A single instance of this class. |
|
68 | + */ |
|
69 | + public static function get_instance() { |
|
70 | 70 | |
71 | - // If the single instance hasn't been set, set it now. |
|
72 | - if ( null === self::$instance ) { |
|
73 | - self::$instance = new self(); |
|
74 | - } |
|
71 | + // If the single instance hasn't been set, set it now. |
|
72 | + if ( null === self::$instance ) { |
|
73 | + self::$instance = new self(); |
|
74 | + } |
|
75 | 75 | |
76 | - return self::$instance; |
|
76 | + return self::$instance; |
|
77 | 77 | |
78 | - } |
|
78 | + } |
|
79 | 79 | |
80 | - /** |
|
81 | - * Register the post type. |
|
82 | - */ |
|
83 | - public function register_post_type() { |
|
84 | - $this->labels = array( |
|
85 | - 'name' => esc_html__( 'Recipes', 'lsx-health-plan' ), |
|
86 | - 'singular_name' => esc_html__( 'Recipe', 'lsx-health-plan' ), |
|
87 | - 'add_new' => esc_html_x( 'Add New', 'post type general name', 'lsx-health-plan' ), |
|
88 | - 'add_new_item' => esc_html__( 'Add New', 'lsx-health-plan' ), |
|
89 | - 'edit_item' => esc_html__( 'Edit', 'lsx-health-plan' ), |
|
90 | - 'new_item' => esc_html__( 'New', 'lsx-health-plan' ), |
|
91 | - 'all_items' => esc_html__( 'All Recipes', 'lsx-health-plan' ), |
|
92 | - 'view_item' => esc_html__( 'View', 'lsx-health-plan' ), |
|
93 | - 'search_items' => esc_html__( 'Search', 'lsx-health-plan' ), |
|
94 | - 'not_found' => esc_html__( 'None found', 'lsx-health-plan' ), |
|
95 | - 'not_found_in_trash' => esc_html__( 'None found in Trash', 'lsx-health-plan' ), |
|
96 | - 'parent_item_colon' => '', |
|
97 | - 'menu_name' => esc_html__( 'Recipes', 'lsx-health-plan' ), |
|
98 | - ); |
|
99 | - $args = array( |
|
100 | - 'labels' => $this->labels, |
|
101 | - 'public' => true, |
|
102 | - 'publicly_queryable' => true, |
|
103 | - 'show_ui' => true, |
|
104 | - 'show_in_menu' => 'edit.php?post_type=meal-pseudo', |
|
105 | - 'show_in_rest' => true, |
|
106 | - 'menu_icon' => 'dashicons-editor-ul', |
|
107 | - 'query_var' => true, |
|
108 | - 'rewrite' => array( |
|
109 | - 'slug' => 'recipe', |
|
110 | - ), |
|
111 | - 'capability_type' => 'post', |
|
112 | - 'has_archive' => 'recipes', |
|
113 | - 'hierarchical' => false, |
|
114 | - 'menu_position' => null, |
|
115 | - 'supports' => array( |
|
116 | - 'title', |
|
117 | - 'editor', |
|
118 | - 'thumbnail', |
|
119 | - 'custom-fields', |
|
120 | - ), |
|
121 | - ); |
|
122 | - register_post_type( 'recipe', $args ); |
|
123 | - } |
|
80 | + /** |
|
81 | + * Register the post type. |
|
82 | + */ |
|
83 | + public function register_post_type() { |
|
84 | + $this->labels = array( |
|
85 | + 'name' => esc_html__( 'Recipes', 'lsx-health-plan' ), |
|
86 | + 'singular_name' => esc_html__( 'Recipe', 'lsx-health-plan' ), |
|
87 | + 'add_new' => esc_html_x( 'Add New', 'post type general name', 'lsx-health-plan' ), |
|
88 | + 'add_new_item' => esc_html__( 'Add New', 'lsx-health-plan' ), |
|
89 | + 'edit_item' => esc_html__( 'Edit', 'lsx-health-plan' ), |
|
90 | + 'new_item' => esc_html__( 'New', 'lsx-health-plan' ), |
|
91 | + 'all_items' => esc_html__( 'All Recipes', 'lsx-health-plan' ), |
|
92 | + 'view_item' => esc_html__( 'View', 'lsx-health-plan' ), |
|
93 | + 'search_items' => esc_html__( 'Search', 'lsx-health-plan' ), |
|
94 | + 'not_found' => esc_html__( 'None found', 'lsx-health-plan' ), |
|
95 | + 'not_found_in_trash' => esc_html__( 'None found in Trash', 'lsx-health-plan' ), |
|
96 | + 'parent_item_colon' => '', |
|
97 | + 'menu_name' => esc_html__( 'Recipes', 'lsx-health-plan' ), |
|
98 | + ); |
|
99 | + $args = array( |
|
100 | + 'labels' => $this->labels, |
|
101 | + 'public' => true, |
|
102 | + 'publicly_queryable' => true, |
|
103 | + 'show_ui' => true, |
|
104 | + 'show_in_menu' => 'edit.php?post_type=meal-pseudo', |
|
105 | + 'show_in_rest' => true, |
|
106 | + 'menu_icon' => 'dashicons-editor-ul', |
|
107 | + 'query_var' => true, |
|
108 | + 'rewrite' => array( |
|
109 | + 'slug' => 'recipe', |
|
110 | + ), |
|
111 | + 'capability_type' => 'post', |
|
112 | + 'has_archive' => 'recipes', |
|
113 | + 'hierarchical' => false, |
|
114 | + 'menu_position' => null, |
|
115 | + 'supports' => array( |
|
116 | + 'title', |
|
117 | + 'editor', |
|
118 | + 'thumbnail', |
|
119 | + 'custom-fields', |
|
120 | + ), |
|
121 | + ); |
|
122 | + register_post_type( 'recipe', $args ); |
|
123 | + } |
|
124 | 124 | |
125 | - /** |
|
126 | - * Registers the Recipes under the Meals Post type menu. |
|
127 | - * |
|
128 | - * @return void |
|
129 | - */ |
|
130 | - public function register_menus() { |
|
131 | - 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' ); |
|
132 | - 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' ); |
|
133 | - 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 | - } |
|
125 | + /** |
|
126 | + * Registers the Recipes under the Meals Post type menu. |
|
127 | + * |
|
128 | + * @return void |
|
129 | + */ |
|
130 | + public function register_menus() { |
|
131 | + 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' ); |
|
132 | + 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' ); |
|
133 | + 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 | + } |
|
135 | 135 | |
136 | - /** |
|
137 | - * Register the Cuisine taxonomy. |
|
138 | - */ |
|
139 | - public function taxonomy_setup() { |
|
140 | - $labels = array( |
|
141 | - 'name' => esc_html_x( 'Cuisine', 'taxonomy general name', 'lsx-health-plan' ), |
|
142 | - 'singular_name' => esc_html_x( 'Cuisines', 'taxonomy singular name', 'lsx-health-plan' ), |
|
143 | - 'search_items' => esc_html__( 'Search', 'lsx-health-plan' ), |
|
144 | - 'all_items' => esc_html__( 'All', 'lsx-health-plan' ), |
|
145 | - 'parent_item' => esc_html__( 'Parent', 'lsx-health-plan' ), |
|
146 | - 'parent_item_colon' => esc_html__( 'Parent:', 'lsx-health-plan' ), |
|
147 | - 'edit_item' => esc_html__( 'Edit', 'lsx-health-plan' ), |
|
148 | - 'update_item' => esc_html__( 'Update', 'lsx-health-plan' ), |
|
149 | - 'add_new_item' => esc_html__( 'Add New', 'lsx-health-plan' ), |
|
150 | - 'new_item_name' => esc_html__( 'New Name', 'lsx-health-plan' ), |
|
151 | - 'menu_name' => esc_html__( 'Cuisines', 'lsx-health-plan' ), |
|
152 | - ); |
|
153 | - $args = array( |
|
154 | - 'hierarchical' => true, |
|
155 | - 'labels' => $labels, |
|
156 | - 'show_ui' => true, |
|
157 | - 'show_admin_column' => true, |
|
158 | - 'show_in_menu' => 'edit.php?post_type=meal', |
|
159 | - 'query_var' => true, |
|
160 | - 'rewrite' => array( |
|
161 | - 'slug' => 'recipe-cuisine', |
|
162 | - ), |
|
163 | - ); |
|
164 | - register_taxonomy( 'recipe-cuisine', array( $this->slug ), $args ); |
|
136 | + /** |
|
137 | + * Register the Cuisine taxonomy. |
|
138 | + */ |
|
139 | + public function taxonomy_setup() { |
|
140 | + $labels = array( |
|
141 | + 'name' => esc_html_x( 'Cuisine', 'taxonomy general name', 'lsx-health-plan' ), |
|
142 | + 'singular_name' => esc_html_x( 'Cuisines', 'taxonomy singular name', 'lsx-health-plan' ), |
|
143 | + 'search_items' => esc_html__( 'Search', 'lsx-health-plan' ), |
|
144 | + 'all_items' => esc_html__( 'All', 'lsx-health-plan' ), |
|
145 | + 'parent_item' => esc_html__( 'Parent', 'lsx-health-plan' ), |
|
146 | + 'parent_item_colon' => esc_html__( 'Parent:', 'lsx-health-plan' ), |
|
147 | + 'edit_item' => esc_html__( 'Edit', 'lsx-health-plan' ), |
|
148 | + 'update_item' => esc_html__( 'Update', 'lsx-health-plan' ), |
|
149 | + 'add_new_item' => esc_html__( 'Add New', 'lsx-health-plan' ), |
|
150 | + 'new_item_name' => esc_html__( 'New Name', 'lsx-health-plan' ), |
|
151 | + 'menu_name' => esc_html__( 'Cuisines', 'lsx-health-plan' ), |
|
152 | + ); |
|
153 | + $args = array( |
|
154 | + 'hierarchical' => true, |
|
155 | + 'labels' => $labels, |
|
156 | + 'show_ui' => true, |
|
157 | + 'show_admin_column' => true, |
|
158 | + 'show_in_menu' => 'edit.php?post_type=meal', |
|
159 | + 'query_var' => true, |
|
160 | + 'rewrite' => array( |
|
161 | + 'slug' => 'recipe-cuisine', |
|
162 | + ), |
|
163 | + ); |
|
164 | + register_taxonomy( 'recipe-cuisine', array( $this->slug ), $args ); |
|
165 | 165 | |
166 | - $labels = array( |
|
167 | - 'name' => esc_html_x( 'Recipe Type', 'taxonomy general name', 'lsx-health-plan' ), |
|
168 | - 'singular_name' => esc_html_x( 'Recipe Types', 'taxonomy singular name', 'lsx-health-plan' ), |
|
169 | - 'search_items' => esc_html__( 'Search', 'lsx-health-plan' ), |
|
170 | - 'all_items' => esc_html__( 'All', 'lsx-health-plan' ), |
|
171 | - 'parent_item' => esc_html__( 'Parent', 'lsx-health-plan' ), |
|
172 | - 'parent_item_colon' => esc_html__( 'Parent:', 'lsx-health-plan' ), |
|
173 | - 'edit_item' => esc_html__( 'Edit', 'lsx-health-plan' ), |
|
174 | - 'update_item' => esc_html__( 'Update', 'lsx-health-plan' ), |
|
175 | - 'add_new_item' => esc_html__( 'Add New', 'lsx-health-plan' ), |
|
176 | - 'new_item_name' => esc_html__( 'New Name', 'lsx-health-plan' ), |
|
177 | - 'menu_name' => esc_html__( 'Types', 'lsx-health-plan' ), |
|
178 | - ); |
|
179 | - $args = array( |
|
180 | - 'hierarchical' => true, |
|
181 | - 'labels' => $labels, |
|
182 | - 'show_ui' => true, |
|
183 | - 'show_in_menu' => 'edit.php?post_type=meal', |
|
184 | - 'show_admin_column' => true, |
|
185 | - 'query_var' => true, |
|
186 | - 'rewrite' => array( |
|
187 | - 'slug' => 'recipe-type', |
|
188 | - ), |
|
189 | - ); |
|
190 | - register_taxonomy( 'recipe-type', array( $this->slug ), $args ); |
|
191 | - } |
|
166 | + $labels = array( |
|
167 | + 'name' => esc_html_x( 'Recipe Type', 'taxonomy general name', 'lsx-health-plan' ), |
|
168 | + 'singular_name' => esc_html_x( 'Recipe Types', 'taxonomy singular name', 'lsx-health-plan' ), |
|
169 | + 'search_items' => esc_html__( 'Search', 'lsx-health-plan' ), |
|
170 | + 'all_items' => esc_html__( 'All', 'lsx-health-plan' ), |
|
171 | + 'parent_item' => esc_html__( 'Parent', 'lsx-health-plan' ), |
|
172 | + 'parent_item_colon' => esc_html__( 'Parent:', 'lsx-health-plan' ), |
|
173 | + 'edit_item' => esc_html__( 'Edit', 'lsx-health-plan' ), |
|
174 | + 'update_item' => esc_html__( 'Update', 'lsx-health-plan' ), |
|
175 | + 'add_new_item' => esc_html__( 'Add New', 'lsx-health-plan' ), |
|
176 | + 'new_item_name' => esc_html__( 'New Name', 'lsx-health-plan' ), |
|
177 | + 'menu_name' => esc_html__( 'Types', 'lsx-health-plan' ), |
|
178 | + ); |
|
179 | + $args = array( |
|
180 | + 'hierarchical' => true, |
|
181 | + 'labels' => $labels, |
|
182 | + 'show_ui' => true, |
|
183 | + 'show_in_menu' => 'edit.php?post_type=meal', |
|
184 | + 'show_admin_column' => true, |
|
185 | + 'query_var' => true, |
|
186 | + 'rewrite' => array( |
|
187 | + 'slug' => 'recipe-type', |
|
188 | + ), |
|
189 | + ); |
|
190 | + register_taxonomy( 'recipe-type', array( $this->slug ), $args ); |
|
191 | + } |
|
192 | 192 | |
193 | - /** |
|
194 | - * Adds the post type to the different arrays. |
|
195 | - * |
|
196 | - * @param array $post_types |
|
197 | - * @return array |
|
198 | - */ |
|
199 | - public function enable_post_type( $post_types = array() ) { |
|
200 | - $post_types[] = $this->slug; |
|
201 | - return $post_types; |
|
202 | - } |
|
193 | + /** |
|
194 | + * Adds the post type to the different arrays. |
|
195 | + * |
|
196 | + * @param array $post_types |
|
197 | + * @return array |
|
198 | + */ |
|
199 | + public function enable_post_type( $post_types = array() ) { |
|
200 | + $post_types[] = $this->slug; |
|
201 | + return $post_types; |
|
202 | + } |
|
203 | 203 | |
204 | - /** |
|
205 | - * Enables the Bi Directional relationships |
|
206 | - * |
|
207 | - * @param array $connections |
|
208 | - * @return void |
|
209 | - */ |
|
210 | - public function enable_connections( $connections = array() ) { |
|
211 | - $connections['recipe']['connected_plans'] = 'connected_recipes'; |
|
212 | - $connections['plan']['connected_recipes'] = 'connected_plans'; |
|
213 | - return $connections; |
|
214 | - } |
|
204 | + /** |
|
205 | + * Enables the Bi Directional relationships |
|
206 | + * |
|
207 | + * @param array $connections |
|
208 | + * @return void |
|
209 | + */ |
|
210 | + public function enable_connections( $connections = array() ) { |
|
211 | + $connections['recipe']['connected_plans'] = 'connected_recipes'; |
|
212 | + $connections['plan']['connected_recipes'] = 'connected_plans'; |
|
213 | + return $connections; |
|
214 | + } |
|
215 | 215 | |
216 | - /** |
|
217 | - * Remove the "Archives:" from the post type recipes. |
|
218 | - * |
|
219 | - * @param string $title the term title. |
|
220 | - * @return string |
|
221 | - */ |
|
222 | - public function get_the_archive_title( $title ) { |
|
223 | - if ( is_post_type_archive( 'recipe' ) ) { |
|
224 | - $title = __( 'Recipes', 'lsx-health-plan' ); |
|
225 | - } |
|
226 | - if ( is_post_type_archive( 'exercise' ) ) { |
|
227 | - $title = __( 'Exercises', 'lsx-health-plan' ); |
|
228 | - } |
|
229 | - if ( is_tax( 'recipe-type' ) ) { |
|
230 | - $queried_object = get_queried_object(); |
|
231 | - if ( isset( $queried_object->name ) ) { |
|
232 | - $title = $queried_object->name . ' ' . __( 'Recipes', 'lsx-health-plan' ); |
|
233 | - } |
|
234 | - } |
|
235 | - return $title; |
|
236 | - } |
|
216 | + /** |
|
217 | + * Remove the "Archives:" from the post type recipes. |
|
218 | + * |
|
219 | + * @param string $title the term title. |
|
220 | + * @return string |
|
221 | + */ |
|
222 | + public function get_the_archive_title( $title ) { |
|
223 | + if ( is_post_type_archive( 'recipe' ) ) { |
|
224 | + $title = __( 'Recipes', 'lsx-health-plan' ); |
|
225 | + } |
|
226 | + if ( is_post_type_archive( 'exercise' ) ) { |
|
227 | + $title = __( 'Exercises', 'lsx-health-plan' ); |
|
228 | + } |
|
229 | + if ( is_tax( 'recipe-type' ) ) { |
|
230 | + $queried_object = get_queried_object(); |
|
231 | + if ( isset( $queried_object->name ) ) { |
|
232 | + $title = $queried_object->name . ' ' . __( 'Recipes', 'lsx-health-plan' ); |
|
233 | + } |
|
234 | + } |
|
235 | + return $title; |
|
236 | + } |
|
237 | 237 | |
238 | - public function remove_archive_original_header() { |
|
239 | - if ( is_post_type_archive( 'recipe' ) || is_post_type_archive( 'exercise' ) ) { |
|
240 | - remove_action( 'lsx_content_wrap_before', 'lsx_global_header' ); |
|
241 | - } |
|
242 | - if ( ! is_post_type_archive() ) { |
|
243 | - add_action( 'lsx_content_wrap_before', 'lsx_health_plan_recipe_archive_description', 11 ); |
|
244 | - } |
|
245 | - } |
|
238 | + public function remove_archive_original_header() { |
|
239 | + if ( is_post_type_archive( 'recipe' ) || is_post_type_archive( 'exercise' ) ) { |
|
240 | + remove_action( 'lsx_content_wrap_before', 'lsx_global_header' ); |
|
241 | + } |
|
242 | + if ( ! is_post_type_archive() ) { |
|
243 | + add_action( 'lsx_content_wrap_before', 'lsx_health_plan_recipe_archive_description', 11 ); |
|
244 | + } |
|
245 | + } |
|
246 | 246 | |
247 | - public function hp_lsx_archive_header() { |
|
248 | - if ( is_post_type_archive( 'recipe' ) || is_post_type_archive( 'exercise' ) ) { |
|
249 | - ?> |
|
247 | + public function hp_lsx_archive_header() { |
|
248 | + if ( is_post_type_archive( 'recipe' ) || is_post_type_archive( 'exercise' ) ) { |
|
249 | + ?> |
|
250 | 250 | <div class="archive-header-wrapper banner-archive"> |
251 | 251 | <?php lsx_global_header_inner_bottom(); ?> |
252 | 252 | <header class="archive-header"> |
@@ -259,205 +259,205 @@ discard block |
||
259 | 259 | </h1> |
260 | 260 | |
261 | 261 | <?php |
262 | - lsx_health_plan_recipe_archive_description(); |
|
263 | - ?> |
|
262 | + lsx_health_plan_recipe_archive_description(); |
|
263 | + ?> |
|
264 | 264 | </header> |
265 | 265 | </div> |
266 | 266 | <?php |
267 | - } |
|
268 | - } |
|
267 | + } |
|
268 | + } |
|
269 | 269 | |
270 | - /** |
|
271 | - * Disables the global header description |
|
272 | - * |
|
273 | - * @param boolean $disable |
|
274 | - * @return boolean |
|
275 | - */ |
|
276 | - public function disable_global_header_description( $disable ) { |
|
277 | - if ( is_tax( 'recipe-type' ) ) { |
|
278 | - $disable = true; |
|
279 | - } |
|
280 | - return $disable; |
|
281 | - } |
|
270 | + /** |
|
271 | + * Disables the global header description |
|
272 | + * |
|
273 | + * @param boolean $disable |
|
274 | + * @return boolean |
|
275 | + */ |
|
276 | + public function disable_global_header_description( $disable ) { |
|
277 | + if ( is_tax( 'recipe-type' ) ) { |
|
278 | + $disable = true; |
|
279 | + } |
|
280 | + return $disable; |
|
281 | + } |
|
282 | 282 | |
283 | - /** |
|
284 | - * Holds the array for the breadcrumbs. |
|
285 | - * |
|
286 | - * @var array $crumbs |
|
287 | - * @return array |
|
288 | - */ |
|
289 | - public function recipes_breadcrumb_filter( $crumbs ) { |
|
290 | - $recipe = \lsx_health_plan\functions\get_option( 'endpoint_recipe', 'recipe' ); |
|
291 | - $recipes = \lsx_health_plan\functions\get_option( 'endpoint_recipe_archive', 'recipes' ); |
|
292 | - $url = get_post_type_archive_link( 'recipe' ); |
|
283 | + /** |
|
284 | + * Holds the array for the breadcrumbs. |
|
285 | + * |
|
286 | + * @var array $crumbs |
|
287 | + * @return array |
|
288 | + */ |
|
289 | + public function recipes_breadcrumb_filter( $crumbs ) { |
|
290 | + $recipe = \lsx_health_plan\functions\get_option( 'endpoint_recipe', 'recipe' ); |
|
291 | + $recipes = \lsx_health_plan\functions\get_option( 'endpoint_recipe_archive', 'recipes' ); |
|
292 | + $url = get_post_type_archive_link( 'recipe' ); |
|
293 | 293 | |
294 | - if ( is_singular( 'recipe' ) ) { |
|
295 | - $recipe_name = get_the_title(); |
|
296 | - $term_obj_list = get_the_terms( get_the_ID(), 'recipe-type' ); |
|
297 | - $recipe_type = $term_obj_list[0]->name; |
|
298 | - $recipe_type_url = get_term_link( $term_obj_list[0]->term_id ); |
|
294 | + if ( is_singular( 'recipe' ) ) { |
|
295 | + $recipe_name = get_the_title(); |
|
296 | + $term_obj_list = get_the_terms( get_the_ID(), 'recipe-type' ); |
|
297 | + $recipe_type = $term_obj_list[0]->name; |
|
298 | + $recipe_type_url = get_term_link( $term_obj_list[0]->term_id ); |
|
299 | 299 | |
300 | - $crumbs[1] = array( |
|
301 | - 0 => $recipes, |
|
302 | - 1 => $url, |
|
303 | - ); |
|
304 | - $crumbs[2] = array( |
|
305 | - 0 => $recipe_type, |
|
306 | - 1 => $recipe_type_url, |
|
307 | - ); |
|
308 | - $crumbs[3] = array( |
|
309 | - 0 => $recipe_name, |
|
310 | - ); |
|
311 | - } |
|
312 | - if ( is_tax( 'recipe-type' ) || is_tax( 'recipe-cuisine' ) ) { |
|
313 | - $term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) ); |
|
300 | + $crumbs[1] = array( |
|
301 | + 0 => $recipes, |
|
302 | + 1 => $url, |
|
303 | + ); |
|
304 | + $crumbs[2] = array( |
|
305 | + 0 => $recipe_type, |
|
306 | + 1 => $recipe_type_url, |
|
307 | + ); |
|
308 | + $crumbs[3] = array( |
|
309 | + 0 => $recipe_name, |
|
310 | + ); |
|
311 | + } |
|
312 | + if ( is_tax( 'recipe-type' ) || is_tax( 'recipe-cuisine' ) ) { |
|
313 | + $term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) ); |
|
314 | 314 | |
315 | - $single_term_title = str_replace( '-', ' ', $term->taxonomy ) . ': ' . $term->name; |
|
315 | + $single_term_title = str_replace( '-', ' ', $term->taxonomy ) . ': ' . $term->name; |
|
316 | 316 | |
317 | - $crumbs[1] = array( |
|
318 | - 0 => $recipes, |
|
319 | - 1 => $url, |
|
320 | - ); |
|
321 | - $crumbs[2] = array( |
|
322 | - 0 => $single_term_title, |
|
323 | - ); |
|
324 | - } |
|
325 | - return $crumbs; |
|
326 | - } |
|
317 | + $crumbs[1] = array( |
|
318 | + 0 => $recipes, |
|
319 | + 1 => $url, |
|
320 | + ); |
|
321 | + $crumbs[2] = array( |
|
322 | + 0 => $single_term_title, |
|
323 | + ); |
|
324 | + } |
|
325 | + return $crumbs; |
|
326 | + } |
|
327 | 327 | |
328 | - /** |
|
329 | - * Define the metabox and field configurations. |
|
330 | - */ |
|
331 | - public function featured_metabox() { |
|
332 | - $cmb = new_cmb2_box( |
|
333 | - array( |
|
334 | - 'id' => $this->slug . '_featured_metabox', |
|
335 | - 'title' => __( 'Featured', 'lsx-health-plan' ), |
|
336 | - 'object_types' => array( $this->slug ), |
|
337 | - 'context' => 'side', |
|
338 | - 'priority' => 'high', |
|
339 | - 'show_names' => true, |
|
340 | - ) |
|
341 | - ); |
|
342 | - $cmb->add_field( |
|
343 | - array( |
|
344 | - 'name' => __( 'Featured', 'lsx-health-plan' ), |
|
345 | - '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' ), |
|
346 | - 'id' => $this->slug . '_featured', |
|
347 | - 'type' => 'checkbox', |
|
348 | - 'show_on_cb' => 'cmb2_hide_if_no_cats', |
|
349 | - ) |
|
350 | - ); |
|
351 | - } |
|
328 | + /** |
|
329 | + * Define the metabox and field configurations. |
|
330 | + */ |
|
331 | + public function featured_metabox() { |
|
332 | + $cmb = new_cmb2_box( |
|
333 | + array( |
|
334 | + 'id' => $this->slug . '_featured_metabox', |
|
335 | + 'title' => __( 'Featured', 'lsx-health-plan' ), |
|
336 | + 'object_types' => array( $this->slug ), |
|
337 | + 'context' => 'side', |
|
338 | + 'priority' => 'high', |
|
339 | + 'show_names' => true, |
|
340 | + ) |
|
341 | + ); |
|
342 | + $cmb->add_field( |
|
343 | + array( |
|
344 | + 'name' => __( 'Featured', 'lsx-health-plan' ), |
|
345 | + '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' ), |
|
346 | + 'id' => $this->slug . '_featured', |
|
347 | + 'type' => 'checkbox', |
|
348 | + 'show_on_cb' => 'cmb2_hide_if_no_cats', |
|
349 | + ) |
|
350 | + ); |
|
351 | + } |
|
352 | 352 | |
353 | - /** |
|
354 | - * Define the metabox and field configurations. |
|
355 | - */ |
|
356 | - public function details_metaboxes() { |
|
357 | - $cmb = new_cmb2_box( |
|
358 | - array( |
|
359 | - 'id' => $this->slug . '_details_metabox', |
|
360 | - 'title' => __( 'Cooking Info', 'lsx-health-plan' ), |
|
361 | - 'object_types' => array( $this->slug ), // Post type |
|
362 | - 'context' => 'normal', |
|
363 | - 'priority' => 'high', |
|
364 | - 'show_names' => true, |
|
365 | - ) |
|
366 | - ); |
|
367 | - $cmb->add_field( |
|
368 | - array( |
|
369 | - 'name' => __( 'Prep Time', 'lsx-health-plan' ), |
|
370 | - 'id' => $this->slug . '_prep_time', |
|
371 | - 'desc' => __( 'Add the preparation time for the entire meal i.e: 25 mins', 'lsx-health-plan' ), |
|
372 | - 'type' => 'text', |
|
373 | - 'show_on_cb' => 'cmb2_hide_if_no_cats', |
|
374 | - ) |
|
375 | - ); |
|
376 | - $cmb->add_field( |
|
377 | - array( |
|
378 | - 'name' => __( 'Cooking Time', 'lsx-health-plan' ), |
|
379 | - 'id' => $this->slug . '_cooking_time', |
|
380 | - 'desc' => __( 'Add the cooking time i.e: 15 mins', 'lsx-health-plan' ), |
|
381 | - 'type' => 'text', |
|
382 | - 'show_on_cb' => 'cmb2_hide_if_no_cats', |
|
383 | - ) |
|
384 | - ); |
|
385 | - $cmb->add_field( |
|
386 | - array( |
|
387 | - 'name' => __( 'Serves', 'lsx-health-plan' ), |
|
388 | - 'id' => $this->slug . '_serves', |
|
389 | - 'desc' => __( 'Add the recommended serving size i.e: 6', 'lsx-health-plan' ), |
|
390 | - 'type' => 'text', |
|
391 | - 'show_on_cb' => 'cmb2_hide_if_no_cats', |
|
392 | - 'attributes' => array( |
|
393 | - 'type' => 'number', |
|
394 | - 'pattern' => '\d*', |
|
395 | - ), |
|
396 | - ) |
|
397 | - ); |
|
398 | - $cmb->add_field( |
|
399 | - array( |
|
400 | - 'name' => __( 'Portion', 'lsx-health-plan' ), |
|
401 | - 'desc' => __( 'Add the recommended portion size i.e: 200mg', 'lsx-health-plan' ), |
|
402 | - 'id' => $this->slug . '_portion', |
|
403 | - 'type' => 'text', |
|
404 | - 'show_on_cb' => 'cmb2_hide_if_no_cats', |
|
405 | - ) |
|
406 | - ); |
|
407 | - $cmb = new_cmb2_box( |
|
408 | - array( |
|
409 | - 'id' => $this->slug . '_nutritional_metabox', |
|
410 | - 'title' => __( 'Nutritional Info', 'lsx-health-plan' ), |
|
411 | - 'object_types' => array( $this->slug ), // Post type |
|
412 | - 'context' => 'normal', |
|
413 | - 'priority' => 'high', |
|
414 | - 'show_names' => true, |
|
415 | - ) |
|
416 | - ); |
|
417 | - $cmb->add_field( |
|
418 | - array( |
|
419 | - 'name' => __( 'Energy', 'lsx-health-plan' ), |
|
420 | - 'id' => $this->slug . '_energy', |
|
421 | - 'desc' => __( 'Add the energy amount for the entire meal i.e: 700 kj', 'lsx-health-plan' ), |
|
422 | - 'type' => 'text', |
|
423 | - 'show_on_cb' => 'cmb2_hide_if_no_cats', |
|
424 | - ) |
|
425 | - ); |
|
426 | - $cmb->add_field( |
|
427 | - array( |
|
428 | - 'name' => __( 'Protein', 'lsx-health-plan' ), |
|
429 | - 'id' => $this->slug . '_protein', |
|
430 | - 'desc' => __( 'Add the protein amount for the entire meal i.e: 50 g', 'lsx-health-plan' ), |
|
431 | - 'type' => 'text', |
|
432 | - 'show_on_cb' => 'cmb2_hide_if_no_cats', |
|
433 | - ) |
|
434 | - ); |
|
435 | - $cmb->add_field( |
|
436 | - array( |
|
437 | - 'name' => __( 'Carbohydrates', 'lsx-health-plan' ), |
|
438 | - 'id' => $this->slug . '_carbohydrates', |
|
439 | - 'desc' => __( 'Add the carbohydrates amount for the entire meal i.e: 5 g', 'lsx-health-plan' ), |
|
440 | - 'type' => 'text', |
|
441 | - 'show_on_cb' => 'cmb2_hide_if_no_cats', |
|
442 | - ) |
|
443 | - ); |
|
444 | - $cmb->add_field( |
|
445 | - array( |
|
446 | - 'name' => __( 'Fibre', 'lsx-health-plan' ), |
|
447 | - 'id' => $this->slug . '_fibre', |
|
448 | - 'desc' => __( 'Add the fibre amount for the entire meal i.e: 5 g', 'lsx-health-plan' ), |
|
449 | - 'type' => 'text', |
|
450 | - 'show_on_cb' => 'cmb2_hide_if_no_cats', |
|
451 | - ) |
|
452 | - ); |
|
453 | - $cmb->add_field( |
|
454 | - array( |
|
455 | - 'name' => __( 'Fat', 'lsx-health-plan' ), |
|
456 | - 'id' => $this->slug . '_fat', |
|
457 | - 'desc' => __( 'Add the fat amount for the entire meal i.e: 20 g', 'lsx-health-plan' ), |
|
458 | - 'type' => 'text', |
|
459 | - 'show_on_cb' => 'cmb2_hide_if_no_cats', |
|
460 | - ) |
|
461 | - ); |
|
462 | - } |
|
353 | + /** |
|
354 | + * Define the metabox and field configurations. |
|
355 | + */ |
|
356 | + public function details_metaboxes() { |
|
357 | + $cmb = new_cmb2_box( |
|
358 | + array( |
|
359 | + 'id' => $this->slug . '_details_metabox', |
|
360 | + 'title' => __( 'Cooking Info', 'lsx-health-plan' ), |
|
361 | + 'object_types' => array( $this->slug ), // Post type |
|
362 | + 'context' => 'normal', |
|
363 | + 'priority' => 'high', |
|
364 | + 'show_names' => true, |
|
365 | + ) |
|
366 | + ); |
|
367 | + $cmb->add_field( |
|
368 | + array( |
|
369 | + 'name' => __( 'Prep Time', 'lsx-health-plan' ), |
|
370 | + 'id' => $this->slug . '_prep_time', |
|
371 | + 'desc' => __( 'Add the preparation time for the entire meal i.e: 25 mins', 'lsx-health-plan' ), |
|
372 | + 'type' => 'text', |
|
373 | + 'show_on_cb' => 'cmb2_hide_if_no_cats', |
|
374 | + ) |
|
375 | + ); |
|
376 | + $cmb->add_field( |
|
377 | + array( |
|
378 | + 'name' => __( 'Cooking Time', 'lsx-health-plan' ), |
|
379 | + 'id' => $this->slug . '_cooking_time', |
|
380 | + 'desc' => __( 'Add the cooking time i.e: 15 mins', 'lsx-health-plan' ), |
|
381 | + 'type' => 'text', |
|
382 | + 'show_on_cb' => 'cmb2_hide_if_no_cats', |
|
383 | + ) |
|
384 | + ); |
|
385 | + $cmb->add_field( |
|
386 | + array( |
|
387 | + 'name' => __( 'Serves', 'lsx-health-plan' ), |
|
388 | + 'id' => $this->slug . '_serves', |
|
389 | + 'desc' => __( 'Add the recommended serving size i.e: 6', 'lsx-health-plan' ), |
|
390 | + 'type' => 'text', |
|
391 | + 'show_on_cb' => 'cmb2_hide_if_no_cats', |
|
392 | + 'attributes' => array( |
|
393 | + 'type' => 'number', |
|
394 | + 'pattern' => '\d*', |
|
395 | + ), |
|
396 | + ) |
|
397 | + ); |
|
398 | + $cmb->add_field( |
|
399 | + array( |
|
400 | + 'name' => __( 'Portion', 'lsx-health-plan' ), |
|
401 | + 'desc' => __( 'Add the recommended portion size i.e: 200mg', 'lsx-health-plan' ), |
|
402 | + 'id' => $this->slug . '_portion', |
|
403 | + 'type' => 'text', |
|
404 | + 'show_on_cb' => 'cmb2_hide_if_no_cats', |
|
405 | + ) |
|
406 | + ); |
|
407 | + $cmb = new_cmb2_box( |
|
408 | + array( |
|
409 | + 'id' => $this->slug . '_nutritional_metabox', |
|
410 | + 'title' => __( 'Nutritional Info', 'lsx-health-plan' ), |
|
411 | + 'object_types' => array( $this->slug ), // Post type |
|
412 | + 'context' => 'normal', |
|
413 | + 'priority' => 'high', |
|
414 | + 'show_names' => true, |
|
415 | + ) |
|
416 | + ); |
|
417 | + $cmb->add_field( |
|
418 | + array( |
|
419 | + 'name' => __( 'Energy', 'lsx-health-plan' ), |
|
420 | + 'id' => $this->slug . '_energy', |
|
421 | + 'desc' => __( 'Add the energy amount for the entire meal i.e: 700 kj', 'lsx-health-plan' ), |
|
422 | + 'type' => 'text', |
|
423 | + 'show_on_cb' => 'cmb2_hide_if_no_cats', |
|
424 | + ) |
|
425 | + ); |
|
426 | + $cmb->add_field( |
|
427 | + array( |
|
428 | + 'name' => __( 'Protein', 'lsx-health-plan' ), |
|
429 | + 'id' => $this->slug . '_protein', |
|
430 | + 'desc' => __( 'Add the protein amount for the entire meal i.e: 50 g', 'lsx-health-plan' ), |
|
431 | + 'type' => 'text', |
|
432 | + 'show_on_cb' => 'cmb2_hide_if_no_cats', |
|
433 | + ) |
|
434 | + ); |
|
435 | + $cmb->add_field( |
|
436 | + array( |
|
437 | + 'name' => __( 'Carbohydrates', 'lsx-health-plan' ), |
|
438 | + 'id' => $this->slug . '_carbohydrates', |
|
439 | + 'desc' => __( 'Add the carbohydrates amount for the entire meal i.e: 5 g', 'lsx-health-plan' ), |
|
440 | + 'type' => 'text', |
|
441 | + 'show_on_cb' => 'cmb2_hide_if_no_cats', |
|
442 | + ) |
|
443 | + ); |
|
444 | + $cmb->add_field( |
|
445 | + array( |
|
446 | + 'name' => __( 'Fibre', 'lsx-health-plan' ), |
|
447 | + 'id' => $this->slug . '_fibre', |
|
448 | + 'desc' => __( 'Add the fibre amount for the entire meal i.e: 5 g', 'lsx-health-plan' ), |
|
449 | + 'type' => 'text', |
|
450 | + 'show_on_cb' => 'cmb2_hide_if_no_cats', |
|
451 | + ) |
|
452 | + ); |
|
453 | + $cmb->add_field( |
|
454 | + array( |
|
455 | + 'name' => __( 'Fat', 'lsx-health-plan' ), |
|
456 | + 'id' => $this->slug . '_fat', |
|
457 | + 'desc' => __( 'Add the fat amount for the entire meal i.e: 20 g', 'lsx-health-plan' ), |
|
458 | + 'type' => 'text', |
|
459 | + 'show_on_cb' => 'cmb2_hide_if_no_cats', |
|
460 | + ) |
|
461 | + ); |
|
462 | + } |
|
463 | 463 | } |
@@ -8,428 +8,428 @@ |
||
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( 'woocommerce_get_breadcrumb', array( $this, 'exercise_breadcrumb_filter' ), 30, 1 ); |
|
53 | - |
|
54 | - } |
|
55 | - |
|
56 | - } |
|
57 | - |
|
58 | - |
|
59 | - /** |
|
60 | - * Return an instance of this class. |
|
61 | - * |
|
62 | - * @since 1.0.0 |
|
63 | - * |
|
64 | - * @return object \lsx_health_plan\classes\Exercise() A single instance of this class. |
|
65 | - */ |
|
66 | - public static function get_instance() { |
|
67 | - // If the single instance hasn't been set, set it now. |
|
68 | - if ( null === self::$instance ) { |
|
69 | - self::$instance = new self(); |
|
70 | - } |
|
71 | - return self::$instance; |
|
72 | - } |
|
73 | - /** |
|
74 | - * Register the post type. |
|
75 | - */ |
|
76 | - public function register_post_type() { |
|
77 | - $labels = array( |
|
78 | - 'name' => esc_html__( 'Exercises', 'lsx-health-plan' ), |
|
79 | - 'singular_name' => esc_html__( 'Exercise', 'lsx-health-plan' ), |
|
80 | - 'add_new' => esc_html_x( 'Add New', 'post type general name', 'lsx-health-plan' ), |
|
81 | - 'add_new_item' => esc_html__( 'Add New', 'lsx-health-plan' ), |
|
82 | - 'edit_item' => esc_html__( 'Edit', 'lsx-health-plan' ), |
|
83 | - 'new_item' => esc_html__( 'New', 'lsx-health-plan' ), |
|
84 | - 'all_items' => esc_html__( 'All Exercises', 'lsx-health-plan' ), |
|
85 | - 'view_item' => esc_html__( 'View', 'lsx-health-plan' ), |
|
86 | - 'search_items' => esc_html__( 'Search', 'lsx-health-plan' ), |
|
87 | - 'not_found' => esc_html__( 'None found', 'lsx-health-plan' ), |
|
88 | - 'not_found_in_trash' => esc_html__( 'None found in Trash', 'lsx-health-plan' ), |
|
89 | - 'parent_item_colon' => '', |
|
90 | - 'menu_name' => esc_html__( 'Exercises', 'lsx-health-plan' ), |
|
91 | - ); |
|
92 | - $args = array( |
|
93 | - 'labels' => $labels, |
|
94 | - 'public' => true, |
|
95 | - 'publicly_queryable' => true, |
|
96 | - 'show_ui' => true, |
|
97 | - 'show_in_menu' => 'edit.php?post_type=workout-pseudo', |
|
98 | - 'show_in_rest' => true, |
|
99 | - 'menu_icon' => 'dashicons-universal-access', |
|
100 | - 'query_var' => true, |
|
101 | - 'rewrite' => array( |
|
102 | - 'slug' => \lsx_health_plan\functions\get_option( 'endpoint_exercise_single', 'exercise' ), |
|
103 | - ), |
|
104 | - 'capability_type' => 'page', |
|
105 | - 'has_archive' => \lsx_health_plan\functions\get_option( 'endpoint_exercise_archive', 'exercises' ), |
|
106 | - 'hierarchical' => false, |
|
107 | - 'menu_position' => null, |
|
108 | - 'supports' => array( |
|
109 | - 'title', |
|
110 | - 'thumbnail', |
|
111 | - 'editor', |
|
112 | - 'excerpt', |
|
113 | - 'custom-fields', |
|
114 | - ), |
|
115 | - ); |
|
116 | - register_post_type( 'exercise', $args ); |
|
117 | - } |
|
118 | - |
|
119 | - /** |
|
120 | - * Register the Exercise taxonomy. |
|
121 | - * |
|
122 | - * @return void |
|
123 | - */ |
|
124 | - public function exercise_type_taxonomy_setup() { |
|
125 | - $labels = array( |
|
126 | - 'name' => esc_html_x( 'Exercise Type', 'taxonomy general name', 'lsx-health-plan' ), |
|
127 | - 'singular_name' => esc_html_x( 'Exercise Type', 'taxonomy singular name', 'lsx-health-plan' ), |
|
128 | - 'search_items' => esc_html__( 'Search', 'lsx-health-plan' ), |
|
129 | - 'all_items' => esc_html__( 'All', 'lsx-health-plan' ), |
|
130 | - 'parent_item' => esc_html__( 'Parent', 'lsx-health-plan' ), |
|
131 | - 'parent_item_colon' => esc_html__( 'Parent:', 'lsx-health-plan' ), |
|
132 | - 'edit_item' => esc_html__( 'Edit', 'lsx-health-plan' ), |
|
133 | - 'update_item' => esc_html__( 'Update', 'lsx-health-plan' ), |
|
134 | - 'add_new_item' => esc_html__( 'Add New', 'lsx-health-plan' ), |
|
135 | - 'new_item_name' => esc_html__( 'New Name', 'lsx-health-plan' ), |
|
136 | - 'menu_name' => esc_html__( 'Exercise Types', 'lsx-health-plan' ), |
|
137 | - ); |
|
138 | - |
|
139 | - $args = array( |
|
140 | - 'hierarchical' => true, |
|
141 | - 'labels' => $labels, |
|
142 | - 'show_ui' => true, |
|
143 | - 'show_admin_column' => true, |
|
144 | - 'query_var' => true, |
|
145 | - 'rewrite' => array( |
|
146 | - 'slug' => \lsx_health_plan\functions\get_option( 'endpoint_exercise_type', 'exercise-type' ), |
|
147 | - ), |
|
148 | - 'show_in_rest' => true, |
|
149 | - ); |
|
150 | - |
|
151 | - register_taxonomy( 'exercise-type', array( 'exercise' ), $args ); |
|
152 | - } |
|
153 | - |
|
154 | - /** |
|
155 | - * Register the Exercise taxonomy. |
|
156 | - * |
|
157 | - * @return void |
|
158 | - */ |
|
159 | - public function equipment_taxonomy_setup() { |
|
160 | - $labels = array( |
|
161 | - 'name' => esc_html_x( 'Equipment', 'taxonomy general name', 'lsx-health-plan' ), |
|
162 | - 'singular_name' => esc_html_x( 'Equipment', 'taxonomy singular name', 'lsx-health-plan' ), |
|
163 | - 'search_items' => esc_html__( 'Search', 'lsx-health-plan' ), |
|
164 | - 'all_items' => esc_html__( 'All', 'lsx-health-plan' ), |
|
165 | - 'parent_item' => esc_html__( 'Parent', 'lsx-health-plan' ), |
|
166 | - 'parent_item_colon' => esc_html__( 'Parent:', 'lsx-health-plan' ), |
|
167 | - 'edit_item' => esc_html__( 'Edit', 'lsx-health-plan' ), |
|
168 | - 'update_item' => esc_html__( 'Update', 'lsx-health-plan' ), |
|
169 | - 'add_new_item' => esc_html__( 'Add New', 'lsx-health-plan' ), |
|
170 | - 'new_item_name' => esc_html__( 'New Name', 'lsx-health-plan' ), |
|
171 | - 'menu_name' => esc_html__( 'Equipment', 'lsx-health-plan' ), |
|
172 | - ); |
|
173 | - |
|
174 | - $args = array( |
|
175 | - 'hierarchical' => true, |
|
176 | - 'labels' => $labels, |
|
177 | - 'show_ui' => true, |
|
178 | - 'show_admin_column' => true, |
|
179 | - 'query_var' => true, |
|
180 | - 'rewrite' => array( |
|
181 | - 'slug' => \lsx_health_plan\functions\get_option( 'endpoint_exercise_equipment', 'equipment' ), |
|
182 | - ), |
|
183 | - 'show_in_rest' => true, |
|
184 | - ); |
|
185 | - |
|
186 | - register_taxonomy( 'equipment', array( 'exercise' ), $args ); |
|
187 | - } |
|
188 | - |
|
189 | - /** |
|
190 | - * Register the Muscle Group taxonomy. |
|
191 | - * |
|
192 | - * @return void |
|
193 | - */ |
|
194 | - public function muscle_group_taxonomy_setup() { |
|
195 | - $labels = array( |
|
196 | - 'name' => esc_html_x( 'Muscle Groups', 'taxonomy general name', 'lsx-health-plan' ), |
|
197 | - 'singular_name' => esc_html_x( 'Muscle Group', 'taxonomy singular name', 'lsx-health-plan' ), |
|
198 | - 'search_items' => esc_html__( 'Search', 'lsx-health-plan' ), |
|
199 | - 'all_items' => esc_html__( 'All', 'lsx-health-plan' ), |
|
200 | - 'parent_item' => esc_html__( 'Parent', 'lsx-health-plan' ), |
|
201 | - 'parent_item_colon' => esc_html__( 'Parent:', 'lsx-health-plan' ), |
|
202 | - 'edit_item' => esc_html__( 'Edit', 'lsx-health-plan' ), |
|
203 | - 'update_item' => esc_html__( 'Update', 'lsx-health-plan' ), |
|
204 | - 'add_new_item' => esc_html__( 'Add New', 'lsx-health-plan' ), |
|
205 | - 'new_item_name' => esc_html__( 'New Name', 'lsx-health-plan' ), |
|
206 | - 'menu_name' => esc_html__( 'Muscle Groups', 'lsx-health-plan' ), |
|
207 | - ); |
|
208 | - |
|
209 | - $args = array( |
|
210 | - 'hierarchical' => true, |
|
211 | - 'labels' => $labels, |
|
212 | - 'show_ui' => true, |
|
213 | - 'show_admin_column' => true, |
|
214 | - 'query_var' => true, |
|
215 | - 'rewrite' => array( |
|
216 | - 'slug' => \lsx_health_plan\functions\get_option( 'endpoint_exercise_muscle_group', 'muscle-group' ), |
|
217 | - ), |
|
218 | - 'show_in_rest' => true, |
|
219 | - ); |
|
220 | - |
|
221 | - register_taxonomy( 'muscle-group', array( 'exercise' ), $args ); |
|
222 | - } |
|
223 | - |
|
224 | - /** |
|
225 | - * Registers the Recipes under the Meals Post type menu. |
|
226 | - * |
|
227 | - * @return void |
|
228 | - */ |
|
229 | - public function register_menus() { |
|
230 | - 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' ); |
|
231 | - 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' ); |
|
232 | - 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' ); |
|
233 | - 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' ); |
|
234 | - } |
|
235 | - |
|
236 | - /** |
|
237 | - * Adds the post type to the different arrays. |
|
238 | - * |
|
239 | - * @param array $post_types |
|
240 | - * @return array |
|
241 | - */ |
|
242 | - public function enable_post_type( $post_types = array() ) { |
|
243 | - $post_types[] = $this->slug; |
|
244 | - return $post_types; |
|
245 | - } |
|
246 | - |
|
247 | - /** |
|
248 | - * Enables the Bi Directional relationships |
|
249 | - * |
|
250 | - * @param array $connections |
|
251 | - * @return void |
|
252 | - */ |
|
253 | - public function enable_connections( $connections = array() ) { |
|
254 | - $connections['exercise']['connected_workouts'] = 'connected_exercises'; |
|
255 | - $connections['workout']['connected_exercises'] = 'connected_workouts'; |
|
256 | - return $connections; |
|
257 | - } |
|
258 | - |
|
259 | - /** |
|
260 | - * Define the metabox and field configurations. |
|
261 | - */ |
|
262 | - public function gallery_metabox() { |
|
263 | - $cmb = new_cmb2_box( |
|
264 | - array( |
|
265 | - 'id' => $this->slug . '_gallery_details_metabox', |
|
266 | - 'title' => __( 'Exercise Gallery', 'lsx-health-plan' ), |
|
267 | - 'object_types' => array( $this->slug ), |
|
268 | - 'context' => 'normal', |
|
269 | - 'priority' => 'low', |
|
270 | - 'show_names' => true, |
|
271 | - ) |
|
272 | - ); |
|
273 | - |
|
274 | - $cmb->add_field( |
|
275 | - array( |
|
276 | - 'name' => __( 'Layout', 'lsx-health-plan' ), |
|
277 | - 'id' => $this->slug . '_gallery_layout', |
|
278 | - 'type' => 'radio', |
|
279 | - 'options' => array( |
|
280 | - 'slider' => __( 'Slider', 'lsx-health-plan' ) . ' {#}', // {#} gets replaced by row number |
|
281 | - 'grid' => __( 'Grid', 'lsx-health-plan' ), |
|
282 | - ), |
|
283 | - 'default' => 'grid', |
|
284 | - ) |
|
285 | - ); |
|
286 | - |
|
287 | - $cmb->add_field( |
|
288 | - array( |
|
289 | - 'name' => __( 'Grid Columns', 'lsx-health-plan' ), |
|
290 | - 'id' => $this->slug . '_gallery_columns', |
|
291 | - 'type' => 'select', |
|
292 | - 'options' => array( |
|
293 | - '3' => __( '2 Columns', 'lsx-health-plan' ), |
|
294 | - '4' => __( '3 Columns', 'lsx-health-plan' ), |
|
295 | - ), |
|
296 | - 'default' => '1', |
|
297 | - ) |
|
298 | - ); |
|
299 | - |
|
300 | - // Repeatable group. |
|
301 | - $gallery_group = $cmb->add_field( |
|
302 | - array( |
|
303 | - 'id' => $this->slug . '_gallery', |
|
304 | - 'type' => 'group', |
|
305 | - 'options' => array( |
|
306 | - 'group_title' => __( 'Gallery', 'lsx-health-plan' ) . ' {#}', // {#} gets replaced by row number |
|
307 | - 'add_button' => __( 'Add Item', 'lsx-health-plan' ), |
|
308 | - 'remove_button' => __( 'Remove Item', 'lsx-health-plan' ), |
|
309 | - 'sortable' => true, |
|
310 | - ), |
|
311 | - 'classes' => 'lsx-admin-row', |
|
312 | - ) |
|
313 | - ); |
|
314 | - |
|
315 | - // Title. |
|
316 | - $cmb->add_group_field( |
|
317 | - $gallery_group, |
|
318 | - array( |
|
319 | - 'name' => __( 'Image', 'lsx-health-plan' ), |
|
320 | - 'id' => $this->slug . '_gallery_image', |
|
321 | - 'type' => 'file', |
|
322 | - 'text' => array( |
|
323 | - 'add_upload_file_text' => __( 'Add File', 'lsx-health-plan' ), |
|
324 | - ), |
|
325 | - 'desc' => __( 'Upload an image a minimum of 800px x 600px in size.', 'lsx-health-plan' ), |
|
326 | - 'query_args' => array( |
|
327 | - 'type' => array( |
|
328 | - 'image/gif', |
|
329 | - 'image/jpeg', |
|
330 | - 'image/png', |
|
331 | - ), |
|
332 | - ), |
|
333 | - 'preview_size' => 'lsx-thumbnail-wide', |
|
334 | - ) |
|
335 | - ); |
|
336 | - |
|
337 | - // Title. |
|
338 | - $cmb->add_group_field( |
|
339 | - $gallery_group, |
|
340 | - array( |
|
341 | - 'name' => __( 'oEmbed', 'lsx-health-plan' ), |
|
342 | - 'id' => $this->slug . '_gallery_embed', |
|
343 | - 'type' => 'text', |
|
344 | - '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' ), |
|
345 | - ) |
|
346 | - ); |
|
347 | - |
|
348 | - $cmb->add_group_field( |
|
349 | - $gallery_group, |
|
350 | - array( |
|
351 | - 'name' => __( 'External Media', 'lsx-health-plan' ), |
|
352 | - 'id' => $this->slug . '_gallery_external', |
|
353 | - 'type' => 'textarea_code', |
|
354 | - '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' ), |
|
355 | - ) |
|
356 | - ); |
|
357 | - } |
|
358 | - |
|
359 | - /** |
|
360 | - * Registers the general settings for the exercise. |
|
361 | - * |
|
362 | - * @return void |
|
363 | - */ |
|
364 | - public function exercise_details() { |
|
365 | - $cmb = new_cmb2_box( |
|
366 | - array( |
|
367 | - 'id' => $this->slug . '_general_details_metabox', |
|
368 | - 'title' => __( 'Details', 'lsx-health-plan' ), |
|
369 | - 'object_types' => array( $this->slug ), |
|
370 | - 'context' => 'normal', |
|
371 | - 'priority' => 'high', |
|
372 | - 'show_names' => true, |
|
373 | - ) |
|
374 | - ); |
|
375 | - |
|
376 | - $cmb->add_field( |
|
377 | - array( |
|
378 | - 'name' => __( 'Side', 'lsx-health-plan' ), |
|
379 | - 'id' => $this->slug . '_side', |
|
380 | - 'type' => 'select', |
|
381 | - 'options' => array( |
|
382 | - '' => __( 'Select', 'lsx-health-plan' ), |
|
383 | - 'left' => __( 'Left', 'lsx-health-plan' ), |
|
384 | - 'right' => __( 'Right', 'lsx-health-plan' ), |
|
385 | - ), |
|
386 | - 'desc' => __( 'Select which side this exercise uses. ', 'lsx-health-plan' ), |
|
387 | - ) |
|
388 | - ); |
|
389 | - } |
|
390 | - |
|
391 | - /** |
|
392 | - * Holds the array for the single exercise breadcrumbs. |
|
393 | - * |
|
394 | - * @var array $crumbs |
|
395 | - * @return array |
|
396 | - */ |
|
397 | - public function exercise_breadcrumb_filter( $crumbs ) { |
|
398 | - $exercise = \lsx_health_plan\functions\get_option( 'endpoint_exercise', 'exercise' ); |
|
399 | - $exercises = \lsx_health_plan\functions\get_option( 'endpoint_exercise_archive', 'exercise' ); |
|
400 | - $url = get_post_type_archive_link( $exercise ); |
|
401 | - |
|
402 | - if ( is_singular( 'exercise' ) ) { |
|
403 | - $exercise_name = get_the_title(); |
|
404 | - $term_obj_list = get_the_terms( get_the_ID(), 'exercise-type' ); |
|
405 | - $exercise_type = $term_obj_list[0]->name; |
|
406 | - $exercise_type_url = get_term_link( $term_obj_list[0]->term_id ); |
|
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( 'woocommerce_get_breadcrumb', array( $this, 'exercise_breadcrumb_filter' ), 30, 1 ); |
|
53 | + |
|
54 | + } |
|
55 | + |
|
56 | + } |
|
57 | + |
|
58 | + |
|
59 | + /** |
|
60 | + * Return an instance of this class. |
|
61 | + * |
|
62 | + * @since 1.0.0 |
|
63 | + * |
|
64 | + * @return object \lsx_health_plan\classes\Exercise() A single instance of this class. |
|
65 | + */ |
|
66 | + public static function get_instance() { |
|
67 | + // If the single instance hasn't been set, set it now. |
|
68 | + if ( null === self::$instance ) { |
|
69 | + self::$instance = new self(); |
|
70 | + } |
|
71 | + return self::$instance; |
|
72 | + } |
|
73 | + /** |
|
74 | + * Register the post type. |
|
75 | + */ |
|
76 | + public function register_post_type() { |
|
77 | + $labels = array( |
|
78 | + 'name' => esc_html__( 'Exercises', 'lsx-health-plan' ), |
|
79 | + 'singular_name' => esc_html__( 'Exercise', 'lsx-health-plan' ), |
|
80 | + 'add_new' => esc_html_x( 'Add New', 'post type general name', 'lsx-health-plan' ), |
|
81 | + 'add_new_item' => esc_html__( 'Add New', 'lsx-health-plan' ), |
|
82 | + 'edit_item' => esc_html__( 'Edit', 'lsx-health-plan' ), |
|
83 | + 'new_item' => esc_html__( 'New', 'lsx-health-plan' ), |
|
84 | + 'all_items' => esc_html__( 'All Exercises', 'lsx-health-plan' ), |
|
85 | + 'view_item' => esc_html__( 'View', 'lsx-health-plan' ), |
|
86 | + 'search_items' => esc_html__( 'Search', 'lsx-health-plan' ), |
|
87 | + 'not_found' => esc_html__( 'None found', 'lsx-health-plan' ), |
|
88 | + 'not_found_in_trash' => esc_html__( 'None found in Trash', 'lsx-health-plan' ), |
|
89 | + 'parent_item_colon' => '', |
|
90 | + 'menu_name' => esc_html__( 'Exercises', 'lsx-health-plan' ), |
|
91 | + ); |
|
92 | + $args = array( |
|
93 | + 'labels' => $labels, |
|
94 | + 'public' => true, |
|
95 | + 'publicly_queryable' => true, |
|
96 | + 'show_ui' => true, |
|
97 | + 'show_in_menu' => 'edit.php?post_type=workout-pseudo', |
|
98 | + 'show_in_rest' => true, |
|
99 | + 'menu_icon' => 'dashicons-universal-access', |
|
100 | + 'query_var' => true, |
|
101 | + 'rewrite' => array( |
|
102 | + 'slug' => \lsx_health_plan\functions\get_option( 'endpoint_exercise_single', 'exercise' ), |
|
103 | + ), |
|
104 | + 'capability_type' => 'page', |
|
105 | + 'has_archive' => \lsx_health_plan\functions\get_option( 'endpoint_exercise_archive', 'exercises' ), |
|
106 | + 'hierarchical' => false, |
|
107 | + 'menu_position' => null, |
|
108 | + 'supports' => array( |
|
109 | + 'title', |
|
110 | + 'thumbnail', |
|
111 | + 'editor', |
|
112 | + 'excerpt', |
|
113 | + 'custom-fields', |
|
114 | + ), |
|
115 | + ); |
|
116 | + register_post_type( 'exercise', $args ); |
|
117 | + } |
|
118 | + |
|
119 | + /** |
|
120 | + * Register the Exercise taxonomy. |
|
121 | + * |
|
122 | + * @return void |
|
123 | + */ |
|
124 | + public function exercise_type_taxonomy_setup() { |
|
125 | + $labels = array( |
|
126 | + 'name' => esc_html_x( 'Exercise Type', 'taxonomy general name', 'lsx-health-plan' ), |
|
127 | + 'singular_name' => esc_html_x( 'Exercise Type', 'taxonomy singular name', 'lsx-health-plan' ), |
|
128 | + 'search_items' => esc_html__( 'Search', 'lsx-health-plan' ), |
|
129 | + 'all_items' => esc_html__( 'All', 'lsx-health-plan' ), |
|
130 | + 'parent_item' => esc_html__( 'Parent', 'lsx-health-plan' ), |
|
131 | + 'parent_item_colon' => esc_html__( 'Parent:', 'lsx-health-plan' ), |
|
132 | + 'edit_item' => esc_html__( 'Edit', 'lsx-health-plan' ), |
|
133 | + 'update_item' => esc_html__( 'Update', 'lsx-health-plan' ), |
|
134 | + 'add_new_item' => esc_html__( 'Add New', 'lsx-health-plan' ), |
|
135 | + 'new_item_name' => esc_html__( 'New Name', 'lsx-health-plan' ), |
|
136 | + 'menu_name' => esc_html__( 'Exercise Types', 'lsx-health-plan' ), |
|
137 | + ); |
|
138 | + |
|
139 | + $args = array( |
|
140 | + 'hierarchical' => true, |
|
141 | + 'labels' => $labels, |
|
142 | + 'show_ui' => true, |
|
143 | + 'show_admin_column' => true, |
|
144 | + 'query_var' => true, |
|
145 | + 'rewrite' => array( |
|
146 | + 'slug' => \lsx_health_plan\functions\get_option( 'endpoint_exercise_type', 'exercise-type' ), |
|
147 | + ), |
|
148 | + 'show_in_rest' => true, |
|
149 | + ); |
|
150 | + |
|
151 | + register_taxonomy( 'exercise-type', array( 'exercise' ), $args ); |
|
152 | + } |
|
153 | + |
|
154 | + /** |
|
155 | + * Register the Exercise taxonomy. |
|
156 | + * |
|
157 | + * @return void |
|
158 | + */ |
|
159 | + public function equipment_taxonomy_setup() { |
|
160 | + $labels = array( |
|
161 | + 'name' => esc_html_x( 'Equipment', 'taxonomy general name', 'lsx-health-plan' ), |
|
162 | + 'singular_name' => esc_html_x( 'Equipment', 'taxonomy singular name', 'lsx-health-plan' ), |
|
163 | + 'search_items' => esc_html__( 'Search', 'lsx-health-plan' ), |
|
164 | + 'all_items' => esc_html__( 'All', 'lsx-health-plan' ), |
|
165 | + 'parent_item' => esc_html__( 'Parent', 'lsx-health-plan' ), |
|
166 | + 'parent_item_colon' => esc_html__( 'Parent:', 'lsx-health-plan' ), |
|
167 | + 'edit_item' => esc_html__( 'Edit', 'lsx-health-plan' ), |
|
168 | + 'update_item' => esc_html__( 'Update', 'lsx-health-plan' ), |
|
169 | + 'add_new_item' => esc_html__( 'Add New', 'lsx-health-plan' ), |
|
170 | + 'new_item_name' => esc_html__( 'New Name', 'lsx-health-plan' ), |
|
171 | + 'menu_name' => esc_html__( 'Equipment', 'lsx-health-plan' ), |
|
172 | + ); |
|
173 | + |
|
174 | + $args = array( |
|
175 | + 'hierarchical' => true, |
|
176 | + 'labels' => $labels, |
|
177 | + 'show_ui' => true, |
|
178 | + 'show_admin_column' => true, |
|
179 | + 'query_var' => true, |
|
180 | + 'rewrite' => array( |
|
181 | + 'slug' => \lsx_health_plan\functions\get_option( 'endpoint_exercise_equipment', 'equipment' ), |
|
182 | + ), |
|
183 | + 'show_in_rest' => true, |
|
184 | + ); |
|
185 | + |
|
186 | + register_taxonomy( 'equipment', array( 'exercise' ), $args ); |
|
187 | + } |
|
188 | + |
|
189 | + /** |
|
190 | + * Register the Muscle Group taxonomy. |
|
191 | + * |
|
192 | + * @return void |
|
193 | + */ |
|
194 | + public function muscle_group_taxonomy_setup() { |
|
195 | + $labels = array( |
|
196 | + 'name' => esc_html_x( 'Muscle Groups', 'taxonomy general name', 'lsx-health-plan' ), |
|
197 | + 'singular_name' => esc_html_x( 'Muscle Group', 'taxonomy singular name', 'lsx-health-plan' ), |
|
198 | + 'search_items' => esc_html__( 'Search', 'lsx-health-plan' ), |
|
199 | + 'all_items' => esc_html__( 'All', 'lsx-health-plan' ), |
|
200 | + 'parent_item' => esc_html__( 'Parent', 'lsx-health-plan' ), |
|
201 | + 'parent_item_colon' => esc_html__( 'Parent:', 'lsx-health-plan' ), |
|
202 | + 'edit_item' => esc_html__( 'Edit', 'lsx-health-plan' ), |
|
203 | + 'update_item' => esc_html__( 'Update', 'lsx-health-plan' ), |
|
204 | + 'add_new_item' => esc_html__( 'Add New', 'lsx-health-plan' ), |
|
205 | + 'new_item_name' => esc_html__( 'New Name', 'lsx-health-plan' ), |
|
206 | + 'menu_name' => esc_html__( 'Muscle Groups', 'lsx-health-plan' ), |
|
207 | + ); |
|
208 | + |
|
209 | + $args = array( |
|
210 | + 'hierarchical' => true, |
|
211 | + 'labels' => $labels, |
|
212 | + 'show_ui' => true, |
|
213 | + 'show_admin_column' => true, |
|
214 | + 'query_var' => true, |
|
215 | + 'rewrite' => array( |
|
216 | + 'slug' => \lsx_health_plan\functions\get_option( 'endpoint_exercise_muscle_group', 'muscle-group' ), |
|
217 | + ), |
|
218 | + 'show_in_rest' => true, |
|
219 | + ); |
|
220 | + |
|
221 | + register_taxonomy( 'muscle-group', array( 'exercise' ), $args ); |
|
222 | + } |
|
223 | + |
|
224 | + /** |
|
225 | + * Registers the Recipes under the Meals Post type menu. |
|
226 | + * |
|
227 | + * @return void |
|
228 | + */ |
|
229 | + public function register_menus() { |
|
230 | + 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' ); |
|
231 | + 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' ); |
|
232 | + 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' ); |
|
233 | + 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' ); |
|
234 | + } |
|
235 | + |
|
236 | + /** |
|
237 | + * Adds the post type to the different arrays. |
|
238 | + * |
|
239 | + * @param array $post_types |
|
240 | + * @return array |
|
241 | + */ |
|
242 | + public function enable_post_type( $post_types = array() ) { |
|
243 | + $post_types[] = $this->slug; |
|
244 | + return $post_types; |
|
245 | + } |
|
246 | + |
|
247 | + /** |
|
248 | + * Enables the Bi Directional relationships |
|
249 | + * |
|
250 | + * @param array $connections |
|
251 | + * @return void |
|
252 | + */ |
|
253 | + public function enable_connections( $connections = array() ) { |
|
254 | + $connections['exercise']['connected_workouts'] = 'connected_exercises'; |
|
255 | + $connections['workout']['connected_exercises'] = 'connected_workouts'; |
|
256 | + return $connections; |
|
257 | + } |
|
258 | + |
|
259 | + /** |
|
260 | + * Define the metabox and field configurations. |
|
261 | + */ |
|
262 | + public function gallery_metabox() { |
|
263 | + $cmb = new_cmb2_box( |
|
264 | + array( |
|
265 | + 'id' => $this->slug . '_gallery_details_metabox', |
|
266 | + 'title' => __( 'Exercise Gallery', 'lsx-health-plan' ), |
|
267 | + 'object_types' => array( $this->slug ), |
|
268 | + 'context' => 'normal', |
|
269 | + 'priority' => 'low', |
|
270 | + 'show_names' => true, |
|
271 | + ) |
|
272 | + ); |
|
273 | + |
|
274 | + $cmb->add_field( |
|
275 | + array( |
|
276 | + 'name' => __( 'Layout', 'lsx-health-plan' ), |
|
277 | + 'id' => $this->slug . '_gallery_layout', |
|
278 | + 'type' => 'radio', |
|
279 | + 'options' => array( |
|
280 | + 'slider' => __( 'Slider', 'lsx-health-plan' ) . ' {#}', // {#} gets replaced by row number |
|
281 | + 'grid' => __( 'Grid', 'lsx-health-plan' ), |
|
282 | + ), |
|
283 | + 'default' => 'grid', |
|
284 | + ) |
|
285 | + ); |
|
286 | + |
|
287 | + $cmb->add_field( |
|
288 | + array( |
|
289 | + 'name' => __( 'Grid Columns', 'lsx-health-plan' ), |
|
290 | + 'id' => $this->slug . '_gallery_columns', |
|
291 | + 'type' => 'select', |
|
292 | + 'options' => array( |
|
293 | + '3' => __( '2 Columns', 'lsx-health-plan' ), |
|
294 | + '4' => __( '3 Columns', 'lsx-health-plan' ), |
|
295 | + ), |
|
296 | + 'default' => '1', |
|
297 | + ) |
|
298 | + ); |
|
299 | + |
|
300 | + // Repeatable group. |
|
301 | + $gallery_group = $cmb->add_field( |
|
302 | + array( |
|
303 | + 'id' => $this->slug . '_gallery', |
|
304 | + 'type' => 'group', |
|
305 | + 'options' => array( |
|
306 | + 'group_title' => __( 'Gallery', 'lsx-health-plan' ) . ' {#}', // {#} gets replaced by row number |
|
307 | + 'add_button' => __( 'Add Item', 'lsx-health-plan' ), |
|
308 | + 'remove_button' => __( 'Remove Item', 'lsx-health-plan' ), |
|
309 | + 'sortable' => true, |
|
310 | + ), |
|
311 | + 'classes' => 'lsx-admin-row', |
|
312 | + ) |
|
313 | + ); |
|
314 | + |
|
315 | + // Title. |
|
316 | + $cmb->add_group_field( |
|
317 | + $gallery_group, |
|
318 | + array( |
|
319 | + 'name' => __( 'Image', 'lsx-health-plan' ), |
|
320 | + 'id' => $this->slug . '_gallery_image', |
|
321 | + 'type' => 'file', |
|
322 | + 'text' => array( |
|
323 | + 'add_upload_file_text' => __( 'Add File', 'lsx-health-plan' ), |
|
324 | + ), |
|
325 | + 'desc' => __( 'Upload an image a minimum of 800px x 600px in size.', 'lsx-health-plan' ), |
|
326 | + 'query_args' => array( |
|
327 | + 'type' => array( |
|
328 | + 'image/gif', |
|
329 | + 'image/jpeg', |
|
330 | + 'image/png', |
|
331 | + ), |
|
332 | + ), |
|
333 | + 'preview_size' => 'lsx-thumbnail-wide', |
|
334 | + ) |
|
335 | + ); |
|
336 | + |
|
337 | + // Title. |
|
338 | + $cmb->add_group_field( |
|
339 | + $gallery_group, |
|
340 | + array( |
|
341 | + 'name' => __( 'oEmbed', 'lsx-health-plan' ), |
|
342 | + 'id' => $this->slug . '_gallery_embed', |
|
343 | + 'type' => 'text', |
|
344 | + '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' ), |
|
345 | + ) |
|
346 | + ); |
|
347 | + |
|
348 | + $cmb->add_group_field( |
|
349 | + $gallery_group, |
|
350 | + array( |
|
351 | + 'name' => __( 'External Media', 'lsx-health-plan' ), |
|
352 | + 'id' => $this->slug . '_gallery_external', |
|
353 | + 'type' => 'textarea_code', |
|
354 | + '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' ), |
|
355 | + ) |
|
356 | + ); |
|
357 | + } |
|
358 | + |
|
359 | + /** |
|
360 | + * Registers the general settings for the exercise. |
|
361 | + * |
|
362 | + * @return void |
|
363 | + */ |
|
364 | + public function exercise_details() { |
|
365 | + $cmb = new_cmb2_box( |
|
366 | + array( |
|
367 | + 'id' => $this->slug . '_general_details_metabox', |
|
368 | + 'title' => __( 'Details', 'lsx-health-plan' ), |
|
369 | + 'object_types' => array( $this->slug ), |
|
370 | + 'context' => 'normal', |
|
371 | + 'priority' => 'high', |
|
372 | + 'show_names' => true, |
|
373 | + ) |
|
374 | + ); |
|
375 | + |
|
376 | + $cmb->add_field( |
|
377 | + array( |
|
378 | + 'name' => __( 'Side', 'lsx-health-plan' ), |
|
379 | + 'id' => $this->slug . '_side', |
|
380 | + 'type' => 'select', |
|
381 | + 'options' => array( |
|
382 | + '' => __( 'Select', 'lsx-health-plan' ), |
|
383 | + 'left' => __( 'Left', 'lsx-health-plan' ), |
|
384 | + 'right' => __( 'Right', 'lsx-health-plan' ), |
|
385 | + ), |
|
386 | + 'desc' => __( 'Select which side this exercise uses. ', 'lsx-health-plan' ), |
|
387 | + ) |
|
388 | + ); |
|
389 | + } |
|
390 | + |
|
391 | + /** |
|
392 | + * Holds the array for the single exercise breadcrumbs. |
|
393 | + * |
|
394 | + * @var array $crumbs |
|
395 | + * @return array |
|
396 | + */ |
|
397 | + public function exercise_breadcrumb_filter( $crumbs ) { |
|
398 | + $exercise = \lsx_health_plan\functions\get_option( 'endpoint_exercise', 'exercise' ); |
|
399 | + $exercises = \lsx_health_plan\functions\get_option( 'endpoint_exercise_archive', 'exercise' ); |
|
400 | + $url = get_post_type_archive_link( $exercise ); |
|
401 | + |
|
402 | + if ( is_singular( 'exercise' ) ) { |
|
403 | + $exercise_name = get_the_title(); |
|
404 | + $term_obj_list = get_the_terms( get_the_ID(), 'exercise-type' ); |
|
405 | + $exercise_type = $term_obj_list[0]->name; |
|
406 | + $exercise_type_url = get_term_link( $term_obj_list[0]->term_id ); |
|
407 | 407 | |
408 | - $crumbs[1] = array( |
|
409 | - 0 => $exercises, |
|
410 | - 1 => $url, |
|
411 | - ); |
|
412 | - $crumbs[2] = array( |
|
413 | - 0 => $exercise_type, |
|
414 | - 1 => $exercise_type_url, |
|
415 | - ); |
|
416 | - $crumbs[3] = array( |
|
417 | - 0 => $exercise_name, |
|
418 | - ); |
|
419 | - } |
|
420 | - if ( is_tax( 'exercise-type' ) || is_tax( 'muscle-group' ) || is_tax( 'equipment' ) ) { |
|
421 | - $term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) ); |
|
422 | - |
|
423 | - $single_term_title = str_replace( '-', ' ', $term->taxonomy ) . ': ' . $term->name; |
|
424 | - |
|
425 | - $crumbs[1] = array( |
|
426 | - 0 => $exercises, |
|
427 | - 1 => $url, |
|
428 | - ); |
|
429 | - $crumbs[2] = array( |
|
430 | - 0 => $single_term_title, |
|
431 | - ); |
|
432 | - } |
|
433 | - return $crumbs; |
|
434 | - } |
|
408 | + $crumbs[1] = array( |
|
409 | + 0 => $exercises, |
|
410 | + 1 => $url, |
|
411 | + ); |
|
412 | + $crumbs[2] = array( |
|
413 | + 0 => $exercise_type, |
|
414 | + 1 => $exercise_type_url, |
|
415 | + ); |
|
416 | + $crumbs[3] = array( |
|
417 | + 0 => $exercise_name, |
|
418 | + ); |
|
419 | + } |
|
420 | + if ( is_tax( 'exercise-type' ) || is_tax( 'muscle-group' ) || is_tax( 'equipment' ) ) { |
|
421 | + $term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) ); |
|
422 | + |
|
423 | + $single_term_title = str_replace( '-', ' ', $term->taxonomy ) . ': ' . $term->name; |
|
424 | + |
|
425 | + $crumbs[1] = array( |
|
426 | + 0 => $exercises, |
|
427 | + 1 => $url, |
|
428 | + ); |
|
429 | + $crumbs[2] = array( |
|
430 | + 0 => $single_term_title, |
|
431 | + ); |
|
432 | + } |
|
433 | + return $crumbs; |
|
434 | + } |
|
435 | 435 | } |
@@ -12,10 +12,10 @@ discard block |
||
12 | 12 | * @return boolean |
13 | 13 | */ |
14 | 14 | function lsx_health_plan_has_warmup( $post_id = '' ) { |
15 | - if ( '' === $post_id ) { |
|
16 | - $post_id = get_the_ID(); |
|
17 | - } |
|
18 | - return \lsx_health_plan\functions\has_attached_post( $post_id, 'plan_warmup' ); |
|
15 | + if ( '' === $post_id ) { |
|
16 | + $post_id = get_the_ID(); |
|
17 | + } |
|
18 | + return \lsx_health_plan\functions\has_attached_post( $post_id, 'plan_warmup' ); |
|
19 | 19 | } |
20 | 20 | |
21 | 21 | /** |
@@ -25,25 +25,25 @@ discard block |
||
25 | 25 | * @return boolean |
26 | 26 | */ |
27 | 27 | function lsx_health_plan_has_workout( $post_id = '' ) { |
28 | - if ( ! post_type_exists( 'workout' ) ) { |
|
29 | - return false; |
|
30 | - } |
|
31 | - if ( '' === $post_id ) { |
|
32 | - $post_id = get_the_ID(); |
|
33 | - } |
|
34 | - $has_workouts = false; |
|
35 | - |
|
36 | - $section_key = get_query_var( 'section', false ); |
|
37 | - if ( false !== $section_key ) { |
|
38 | - $section_info = \lsx_health_plan\functions\plan\get_section_info( $section_key ); |
|
39 | - if ( isset( $section_info['connected_workouts'] ) && ! empty( $section_info['connected_workouts'] ) ) { |
|
40 | - $has_workouts = true; |
|
41 | - } |
|
42 | - } elseif ( \lsx_health_plan\functions\has_attached_post( $post_id, 'connected_workouts' ) ) { |
|
43 | - $has_workouts = true; |
|
44 | - } |
|
45 | - |
|
46 | - return $has_workouts; |
|
28 | + if ( ! post_type_exists( 'workout' ) ) { |
|
29 | + return false; |
|
30 | + } |
|
31 | + if ( '' === $post_id ) { |
|
32 | + $post_id = get_the_ID(); |
|
33 | + } |
|
34 | + $has_workouts = false; |
|
35 | + |
|
36 | + $section_key = get_query_var( 'section', false ); |
|
37 | + if ( false !== $section_key ) { |
|
38 | + $section_info = \lsx_health_plan\functions\plan\get_section_info( $section_key ); |
|
39 | + if ( isset( $section_info['connected_workouts'] ) && ! empty( $section_info['connected_workouts'] ) ) { |
|
40 | + $has_workouts = true; |
|
41 | + } |
|
42 | + } elseif ( \lsx_health_plan\functions\has_attached_post( $post_id, 'connected_workouts' ) ) { |
|
43 | + $has_workouts = true; |
|
44 | + } |
|
45 | + |
|
46 | + return $has_workouts; |
|
47 | 47 | } |
48 | 48 | |
49 | 49 | /** |
@@ -53,14 +53,14 @@ discard block |
||
53 | 53 | * @return boolean |
54 | 54 | */ |
55 | 55 | function lsx_health_plan_has_meal( $post_id = '' ) { |
56 | - if ( ! post_type_exists( 'meal' ) ) { |
|
57 | - return false; |
|
58 | - } |
|
59 | - if ( '' === $post_id ) { |
|
60 | - $post_id = get_the_ID(); |
|
61 | - } |
|
62 | - |
|
63 | - return \lsx_health_plan\functions\has_attached_post( $post_id, 'connected_meals' ); |
|
56 | + if ( ! post_type_exists( 'meal' ) ) { |
|
57 | + return false; |
|
58 | + } |
|
59 | + if ( '' === $post_id ) { |
|
60 | + $post_id = get_the_ID(); |
|
61 | + } |
|
62 | + |
|
63 | + return \lsx_health_plan\functions\has_attached_post( $post_id, 'connected_meals' ); |
|
64 | 64 | } |
65 | 65 | |
66 | 66 | /** |
@@ -70,13 +70,13 @@ discard block |
||
70 | 70 | * @return boolean |
71 | 71 | */ |
72 | 72 | function lsx_health_plan_has_recipe( $post_id = '' ) { |
73 | - if ( ! post_type_exists( 'recipe' ) ) { |
|
74 | - return false; |
|
75 | - } |
|
76 | - if ( '' === $post_id ) { |
|
77 | - $post_id = get_the_ID(); |
|
78 | - } |
|
79 | - return \lsx_health_plan\functions\has_attached_post( $post_id, 'connected_recipes' ); |
|
73 | + if ( ! post_type_exists( 'recipe' ) ) { |
|
74 | + return false; |
|
75 | + } |
|
76 | + if ( '' === $post_id ) { |
|
77 | + $post_id = get_the_ID(); |
|
78 | + } |
|
79 | + return \lsx_health_plan\functions\has_attached_post( $post_id, 'connected_recipes' ); |
|
80 | 80 | } |
81 | 81 | |
82 | 82 | /** |
@@ -86,15 +86,15 @@ discard block |
||
86 | 86 | * @return boolean |
87 | 87 | */ |
88 | 88 | function lsx_health_plan_has_downloads( $post_id = '' ) { |
89 | - $has_downloads = false; |
|
90 | - if ( '' === $post_id ) { |
|
91 | - $post_id = get_the_ID(); |
|
92 | - } |
|
93 | - $downloads = \lsx_health_plan\functions\get_downloads( 'all', $post_id ); |
|
94 | - if ( ! empty( $downloads ) ) { |
|
95 | - $has_downloads = true; |
|
96 | - } |
|
97 | - return $has_downloads; |
|
89 | + $has_downloads = false; |
|
90 | + if ( '' === $post_id ) { |
|
91 | + $post_id = get_the_ID(); |
|
92 | + } |
|
93 | + $downloads = \lsx_health_plan\functions\get_downloads( 'all', $post_id ); |
|
94 | + if ( ! empty( $downloads ) ) { |
|
95 | + $has_downloads = true; |
|
96 | + } |
|
97 | + return $has_downloads; |
|
98 | 98 | } |
99 | 99 | |
100 | 100 | /** |
@@ -104,13 +104,13 @@ discard block |
||
104 | 104 | * @return boolean |
105 | 105 | */ |
106 | 106 | function lsx_health_plan_has_tip( $post_id = '' ) { |
107 | - if ( ! post_type_exists( 'tip' ) ) { |
|
108 | - return false; |
|
109 | - } |
|
110 | - if ( '' === $post_id ) { |
|
111 | - $post_id = get_the_ID(); |
|
112 | - } |
|
113 | - return \lsx_health_plan\functions\has_attached_post( $post_id, 'connected_tips' ); |
|
107 | + if ( ! post_type_exists( 'tip' ) ) { |
|
108 | + return false; |
|
109 | + } |
|
110 | + if ( '' === $post_id ) { |
|
111 | + $post_id = get_the_ID(); |
|
112 | + } |
|
113 | + return \lsx_health_plan\functions\has_attached_post( $post_id, 'connected_tips' ); |
|
114 | 114 | } |
115 | 115 | |
116 | 116 | /** |
@@ -120,13 +120,13 @@ discard block |
||
120 | 120 | * @return boolean |
121 | 121 | */ |
122 | 122 | function lsx_health_plan_has_video( $post_id = '' ) { |
123 | - if ( ! post_type_exists( 'video' ) ) { |
|
124 | - return false; |
|
125 | - } |
|
126 | - if ( '' === $post_id ) { |
|
127 | - $post_id = get_the_ID(); |
|
128 | - } |
|
129 | - return \lsx_health_plan\functions\has_attached_post( $post_id, 'connected_videos' ); |
|
123 | + if ( ! post_type_exists( 'video' ) ) { |
|
124 | + return false; |
|
125 | + } |
|
126 | + if ( '' === $post_id ) { |
|
127 | + $post_id = get_the_ID(); |
|
128 | + } |
|
129 | + return \lsx_health_plan\functions\has_attached_post( $post_id, 'connected_videos' ); |
|
130 | 130 | } |
131 | 131 | |
132 | 132 | /** |
@@ -135,16 +135,16 @@ discard block |
||
135 | 135 | * @return boolean |
136 | 136 | */ |
137 | 137 | function lsx_health_plan_user_has_purchase() { |
138 | - $valid_order = false; |
|
139 | - $product_id = \lsx_health_plan\functions\get_option( 'membership_product', false ); |
|
140 | - |
|
141 | - if ( is_user_logged_in() && false !== $product_id ) { |
|
142 | - $current_user = wp_get_current_user(); |
|
143 | - if ( wc_customer_bought_product( $current_user->user_email, $current_user->ID, $product_id ) ) { |
|
144 | - $valid_order = true; |
|
145 | - } |
|
146 | - } |
|
147 | - return $valid_order; |
|
138 | + $valid_order = false; |
|
139 | + $product_id = \lsx_health_plan\functions\get_option( 'membership_product', false ); |
|
140 | + |
|
141 | + if ( is_user_logged_in() && false !== $product_id ) { |
|
142 | + $current_user = wp_get_current_user(); |
|
143 | + if ( wc_customer_bought_product( $current_user->user_email, $current_user->ID, $product_id ) ) { |
|
144 | + $valid_order = true; |
|
145 | + } |
|
146 | + } |
|
147 | + return $valid_order; |
|
148 | 148 | } |
149 | 149 | |
150 | 150 | /** |
@@ -154,18 +154,18 @@ discard block |
||
154 | 154 | * @return boolean |
155 | 155 | */ |
156 | 156 | function lsx_health_plan_is_current_tab( $needle = '' ) { |
157 | - $is_tab = false; |
|
158 | - $plan_slug = \lsx_health_plan\functions\get_option( 'my_plan_slug', false ); |
|
159 | - if ( false === $plan_slug ) { |
|
160 | - $plan_slug = 'my-plan'; |
|
161 | - } |
|
162 | - if ( is_singular( 'plan' ) || is_page( $plan_slug ) ) { |
|
163 | - $endpoint = get_query_var( 'endpoint' ); |
|
164 | - if ( false !== $endpoint && $needle === $endpoint ) { |
|
165 | - $is_tab = true; |
|
166 | - } |
|
167 | - } |
|
168 | - return $is_tab; |
|
157 | + $is_tab = false; |
|
158 | + $plan_slug = \lsx_health_plan\functions\get_option( 'my_plan_slug', false ); |
|
159 | + if ( false === $plan_slug ) { |
|
160 | + $plan_slug = 'my-plan'; |
|
161 | + } |
|
162 | + if ( is_singular( 'plan' ) || is_page( $plan_slug ) ) { |
|
163 | + $endpoint = get_query_var( 'endpoint' ); |
|
164 | + if ( false !== $endpoint && $needle === $endpoint ) { |
|
165 | + $is_tab = true; |
|
166 | + } |
|
167 | + } |
|
168 | + return $is_tab; |
|
169 | 169 | } |
170 | 170 | |
171 | 171 | /** |
@@ -175,22 +175,22 @@ discard block |
||
175 | 175 | * @return boolean |
176 | 176 | */ |
177 | 177 | function lsx_health_plan_is_day_complete( $post_id = '', $section_key = '' ) { |
178 | - $is_complete = false; |
|
179 | - if ( '' === $post_id ) { |
|
180 | - $post_id = get_the_ID(); |
|
181 | - } |
|
182 | - $key = \lsx_health_plan\functions\plan\generate_section_id( $section_key ); |
|
183 | - $is_day_complete = get_user_meta( get_current_user_id(), 'day_' . $key . '_complete', true ); |
|
184 | - if ( false !== $is_day_complete && '' !== $is_day_complete ) { |
|
185 | - $is_complete = true; |
|
186 | - } |
|
187 | - |
|
188 | - return $is_complete; |
|
178 | + $is_complete = false; |
|
179 | + if ( '' === $post_id ) { |
|
180 | + $post_id = get_the_ID(); |
|
181 | + } |
|
182 | + $key = \lsx_health_plan\functions\plan\generate_section_id( $section_key ); |
|
183 | + $is_day_complete = get_user_meta( get_current_user_id(), 'day_' . $key . '_complete', true ); |
|
184 | + if ( false !== $is_day_complete && '' !== $is_day_complete ) { |
|
185 | + $is_complete = true; |
|
186 | + } |
|
187 | + |
|
188 | + return $is_complete; |
|
189 | 189 | } |
190 | 190 | |
191 | 191 | function lsx_health_plan_is_plan_complete() { |
192 | - $complete = false; |
|
193 | - return $complete; |
|
192 | + $complete = false; |
|
193 | + return $complete; |
|
194 | 194 | } |
195 | 195 | |
196 | 196 | /** |
@@ -200,14 +200,14 @@ discard block |
||
200 | 200 | * @return boolean |
201 | 201 | */ |
202 | 202 | function lsx_health_plan_week_has_downloads( $week = '' ) { |
203 | - $has_downloads = false; |
|
204 | - if ( '' !== $week ) { |
|
205 | - $downloads = \lsx_health_plan\functions\get_weekly_downloads( $week ); |
|
206 | - if ( ! empty( $downloads ) ) { |
|
207 | - $has_downloads = true; |
|
208 | - } |
|
209 | - } |
|
210 | - return $has_downloads; |
|
203 | + $has_downloads = false; |
|
204 | + if ( '' !== $week ) { |
|
205 | + $downloads = \lsx_health_plan\functions\get_weekly_downloads( $week ); |
|
206 | + if ( ! empty( $downloads ) ) { |
|
207 | + $has_downloads = true; |
|
208 | + } |
|
209 | + } |
|
210 | + return $has_downloads; |
|
211 | 211 | } |
212 | 212 | |
213 | 213 | /** |
@@ -217,15 +217,15 @@ discard block |
||
217 | 217 | * @return boolean |
218 | 218 | */ |
219 | 219 | function lsx_health_plan_has_tips( $post_id = '' ) { |
220 | - $has_tips = false; |
|
221 | - if ( '' === $post_id ) { |
|
222 | - $post_id = get_the_ID(); |
|
223 | - } |
|
224 | - $post_type = get_post_type( $post_id ); |
|
225 | - $connected_tips = get_post_meta( get_the_ID(), $post_type . '_connected_tips', true ); |
|
226 | - $connected_tips = \lsx_health_plan\functions\check_posts_exist( $connected_tips ); |
|
227 | - if ( ! empty( $connected_tips ) ) { |
|
228 | - $has_tips = true; |
|
229 | - } |
|
230 | - return $has_tips; |
|
220 | + $has_tips = false; |
|
221 | + if ( '' === $post_id ) { |
|
222 | + $post_id = get_the_ID(); |
|
223 | + } |
|
224 | + $post_type = get_post_type( $post_id ); |
|
225 | + $connected_tips = get_post_meta( get_the_ID(), $post_type . '_connected_tips', true ); |
|
226 | + $connected_tips = \lsx_health_plan\functions\check_posts_exist( $connected_tips ); |
|
227 | + if ( ! empty( $connected_tips ) ) { |
|
228 | + $has_tips = true; |
|
229 | + } |
|
230 | + return $has_tips; |
|
231 | 231 | } |