@@ -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 | } |
@@ -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 | } |
@@ -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' ) ) |
|
97 | - || is_tax( array( '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' ) ) |
|
97 | + || is_tax( array( '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 | } |
@@ -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 | } |
@@ -10,8 +10,8 @@ discard block |
||
10 | 10 | <?php lsx_content_wrap_before(); ?> |
11 | 11 | |
12 | 12 | <?php |
13 | - $page_id = get_the_ID(); |
|
14 | - $redirect = '/content-restricted/?r=' . $page_id . '&wcm_redirect_to=archive&wcm_redirect_id=' . $page_id; |
|
13 | + $page_id = get_the_ID(); |
|
14 | + $redirect = '/content-restricted/?r=' . $page_id . '&wcm_redirect_to=archive&wcm_redirect_id=' . $page_id; |
|
15 | 15 | ?> |
16 | 16 | |
17 | 17 | <div id="primary" class="content-area <?php echo esc_attr( lsx_main_class() ); ?>"> |
@@ -20,8 +20,8 @@ discard block |
||
20 | 20 | |
21 | 21 | <!-- Begining restricted content --> |
22 | 22 | <?php |
23 | - if ( ! function_exists( 'wc_memberships_view_restricted_post_content' ) || current_user_can( 'wc_memberships_view_restricted_post_content', $page_id ) ) { |
|
24 | - ?> |
|
23 | + if ( ! function_exists( 'wc_memberships_view_restricted_post_content' ) || current_user_can( 'wc_memberships_view_restricted_post_content', $page_id ) ) { |
|
24 | + ?> |
|
25 | 25 | <main id="main" role="main"> |
26 | 26 | |
27 | 27 | <?php lsx_content_top(); ?> |
@@ -30,9 +30,9 @@ discard block |
||
30 | 30 | <div class="row"> |
31 | 31 | <?php if ( have_posts() ) : ?> |
32 | 32 | <?php |
33 | - while ( have_posts() ) : |
|
34 | - the_post(); |
|
35 | - ?> |
|
33 | + while ( have_posts() ) : |
|
34 | + the_post(); |
|
35 | + ?> |
|
36 | 36 | |
37 | 37 | <?php include LSX_HEALTH_PLAN_PATH . '/templates/content-archive-meal.php'; ?> |
38 | 38 | |
@@ -51,11 +51,11 @@ discard block |
||
51 | 51 | </main><!-- #main --> |
52 | 52 | |
53 | 53 | <?php |
54 | - } else { |
|
55 | - wp_redirect( $redirect ); |
|
56 | - exit; |
|
57 | - } |
|
58 | - ?> |
|
54 | + } else { |
|
55 | + wp_redirect( $redirect ); |
|
56 | + exit; |
|
57 | + } |
|
58 | + ?> |
|
59 | 59 | |
60 | 60 | <?php lsx_content_after(); ?> |
61 | 61 |
@@ -10,8 +10,8 @@ discard block |
||
10 | 10 | <?php lsx_content_wrap_before(); ?> |
11 | 11 | |
12 | 12 | <?php |
13 | - $page_id = get_the_ID(); |
|
14 | - $redirect = '/content-restricted/?r=' . $page_id . '&wcm_redirect_to=archive&wcm_redirect_id=' . $page_id; |
|
13 | + $page_id = get_the_ID(); |
|
14 | + $redirect = '/content-restricted/?r=' . $page_id . '&wcm_redirect_to=archive&wcm_redirect_id=' . $page_id; |
|
15 | 15 | ?> |
16 | 16 | |
17 | 17 | <div id="primary" class="content-area <?php echo esc_attr( lsx_main_class() ); ?>"> |
@@ -20,8 +20,8 @@ discard block |
||
20 | 20 | |
21 | 21 | <!-- Begining restricted content --> |
22 | 22 | <?php |
23 | - if ( ! function_exists( 'wc_memberships_view_restricted_post_content' ) || current_user_can( 'wc_memberships_view_restricted_post_content', $post_id ) ) { |
|
24 | - ?> |
|
23 | + if ( ! function_exists( 'wc_memberships_view_restricted_post_content' ) || current_user_can( 'wc_memberships_view_restricted_post_content', $post_id ) ) { |
|
24 | + ?> |
|
25 | 25 | <main id="main" role="main"> |
26 | 26 | |
27 | 27 | <?php lsx_content_top(); ?> |
@@ -30,9 +30,9 @@ discard block |
||
30 | 30 | <div class="row"> |
31 | 31 | <?php if ( have_posts() ) : ?> |
32 | 32 | <?php |
33 | - while ( have_posts() ) : |
|
34 | - the_post(); |
|
35 | - ?> |
|
33 | + while ( have_posts() ) : |
|
34 | + the_post(); |
|
35 | + ?> |
|
36 | 36 | |
37 | 37 | <?php include LSX_HEALTH_PLAN_PATH . '/templates/content-archive-exercise.php'; ?> |
38 | 38 | |
@@ -51,11 +51,11 @@ discard block |
||
51 | 51 | </main><!-- #main --> |
52 | 52 | |
53 | 53 | <?php |
54 | - } else { |
|
55 | - wp_redirect( $redirect ); |
|
56 | - exit; |
|
57 | - } |
|
58 | - ?> |
|
54 | + } else { |
|
55 | + wp_redirect( $redirect ); |
|
56 | + exit; |
|
57 | + } |
|
58 | + ?> |
|
59 | 59 | |
60 | 60 | <?php lsx_content_after(); ?> |
61 | 61 |
@@ -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 |
@@ -10,8 +10,8 @@ discard block |
||
10 | 10 | <?php lsx_content_wrap_before(); ?> |
11 | 11 | |
12 | 12 | <?php |
13 | - $page_id = get_the_ID(); |
|
14 | - $redirect = '/content-restricted/?r=' . $page_id . '&wcm_redirect_to=archive&wcm_redirect_id=' . $page_id; |
|
13 | + $page_id = get_the_ID(); |
|
14 | + $redirect = '/content-restricted/?r=' . $page_id . '&wcm_redirect_to=archive&wcm_redirect_id=' . $page_id; |
|
15 | 15 | ?> |
16 | 16 | |
17 | 17 | <div id="primary" class="content-area <?php echo esc_attr( lsx_main_class() ); ?>"> |
@@ -20,8 +20,8 @@ discard block |
||
20 | 20 | |
21 | 21 | <!-- Begining restricted content --> |
22 | 22 | <?php |
23 | - if ( ! function_exists( 'wc_memberships_view_restricted_post_content' ) || current_user_can( 'wc_memberships_view_restricted_post_content', $page_id ) ) { |
|
24 | - ?> |
|
23 | + if ( ! function_exists( 'wc_memberships_view_restricted_post_content' ) || current_user_can( 'wc_memberships_view_restricted_post_content', $page_id ) ) { |
|
24 | + ?> |
|
25 | 25 | <main id="main" role="main"> |
26 | 26 | |
27 | 27 | <?php lsx_content_top(); ?> |
@@ -30,9 +30,9 @@ discard block |
||
30 | 30 | <div class="row"> |
31 | 31 | <?php if ( have_posts() ) : ?> |
32 | 32 | <?php |
33 | - while ( have_posts() ) : |
|
34 | - the_post(); |
|
35 | - ?> |
|
33 | + while ( have_posts() ) : |
|
34 | + the_post(); |
|
35 | + ?> |
|
36 | 36 | |
37 | 37 | <?php include LSX_HEALTH_PLAN_PATH . '/templates/content-archive-workout.php'; ?> |
38 | 38 | |
@@ -51,11 +51,11 @@ discard block |
||
51 | 51 | </main><!-- #main --> |
52 | 52 | |
53 | 53 | <?php |
54 | - } else { |
|
55 | - wp_redirect( $redirect ); |
|
56 | - exit; |
|
57 | - } |
|
58 | - ?> |
|
54 | + } else { |
|
55 | + wp_redirect( $redirect ); |
|
56 | + exit; |
|
57 | + } |
|
58 | + ?> |
|
59 | 59 | |
60 | 60 | <?php lsx_content_after(); ?> |
61 | 61 |
@@ -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 |