Meal   A
last analyzed

Complexity

Total Complexity 25

Size/Duplication

Total Lines 474
Duplicated Lines 0 %

Importance

Changes 4
Bugs 0 Features 0
Metric Value
eloc 281
dl 0
loc 474
rs 10
c 4
b 0
f 0
wmc 25

11 Methods

Rating   Name   Duplication   Size   Complexity  
A enable_post_type() 0 3 1
A set_parent_only() 0 3 5
B details_metaboxes() 0 190 4
A __construct() 0 18 1
A get_instance() 0 6 2
A taxonomy_setup() 0 26 1
A featured_metabox() 0 18 1
A get_the_archive_title() 0 5 2
B meal_breadcrumb_filter() 0 62 6
A enable_connections() 0 4 1
A register_post_type() 0 41 1
1
<?php
0 ignored issues
show
Coding Style introduced by
This file is missing a doc comment.
Loading history...
2
namespace lsx_health_plan\classes;
3
4
/**
5
 * Contains the day post type
6
 *
7
 * @package lsx-health-plan
8
 */
9
class Meal {
10
11
	/**
12
	 * Holds class instance
13
	 *
14
	 * @since 1.0.0
15
	 *
16
	 * @var      object \lsx_health_plan\classes\Meal()
17
	 */
18
	protected static $instance = null;
19
20
	/**
21
	 * Holds post_type slug used as an index
22
	 *
23
	 * @since 1.0.0
24
	 *
25
	 * @var      string
26
	 */
27
	public $slug = 'meal';
28
29
	/**
30
	 * Constructor
31
	 */
32
	public function __construct() {
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines before function; 1 found
Loading history...
33
		add_action( 'init', array( $this, 'register_post_type' ) );
34
		add_action( 'init', array( $this, 'taxonomy_setup' ) );
35
		
36
		add_filter( 'lsx_health_plan_connections', array( $this, 'enable_connections' ), 10, 1 );
37
		add_action( 'cmb2_admin_init', array( $this, 'featured_metabox' ), 5 );
38
		add_action( 'cmb2_admin_init', array( $this, 'details_metaboxes' ) );
39
40
		// Template Redirects.
41
		add_filter( 'lsx_health_plan_single_template', array( $this, 'enable_post_type' ), 10, 1 );
42
		add_filter( 'lsx_health_plan_archive_template', array( $this, 'enable_post_type' ), 10, 1 );
43
44
		add_action( 'pre_get_posts', array( $this, 'set_parent_only' ), 10, 1 );
45
		add_filter( 'get_the_archive_title', array( $this, 'get_the_archive_title' ), 100 );
46
47
		//Breadcrumbs
0 ignored issues
show
Coding Style introduced by
No space found before comment text; expected "// Breadcrumbs" but found "//Breadcrumbs"
Loading history...
Coding Style introduced by
Inline comments must end in full-stops, exclamation marks, or question marks
Loading history...
48
		add_filter( 'wpseo_breadcrumb_links', array( $this, 'meal_breadcrumb_filter' ), 30, 1 );
49
		add_filter( 'woocommerce_get_breadcrumb', array( $this, 'meal_breadcrumb_filter' ), 30, 1 );
50
	}
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
51
52
	/**
53
	 * Return an instance of this class.
54
	 *
55
	 * @since 1.0.0
56
	 *
57
	 * @return    object \lsx_health_plan\classes\Day()    A single instance of this class.
58
	 */
59
	public static function get_instance() {
60
		// If the single instance hasn't been set, set it now.
61
		if ( null === self::$instance ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
62
			self::$instance = new self();
63
		}
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
64
		return self::$instance;
65
	}
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected 2 blank lines after function; 0 found
Loading history...
66
	/**
67
	 * Register the post type.
68
	 */
69
	public function register_post_type() {
70
		$labels = array(
71
			'name'               => esc_html__( 'Meals', 'lsx-health-plan' ),
72
			'singular_name'      => esc_html__( 'Meal', 'lsx-health-plan' ),
73
			'add_new'            => esc_html_x( 'Add New', 'post type general name', 'lsx-health-plan' ),
74
			'add_new_item'       => esc_html__( 'Add New', 'lsx-health-plan' ),
75
			'edit_item'          => esc_html__( 'Edit', 'lsx-health-plan' ),
76
			'new_item'           => esc_html__( 'New', 'lsx-health-plan' ),
77
			'all_items'          => esc_html__( 'All Meals', 'lsx-health-plan' ),
78
			'view_item'          => esc_html__( 'View', 'lsx-health-plan' ),
79
			'search_items'       => esc_html__( 'Search', 'lsx-health-plan' ),
80
			'not_found'          => esc_html__( 'None found', 'lsx-health-plan' ),
81
			'not_found_in_trash' => esc_html__( 'None found in Trash', 'lsx-health-plan' ),
82
			'parent_item_colon'  => esc_html__( 'Parent:', 'lsx-health-plan' ),
83
			'menu_name'          => esc_html__( 'Meals', 'lsx-health-plan' ),
84
		);
85
		$args   = array(
86
			'labels'             => $labels,
87
			'public'             => true,
88
			'publicly_queryable' => true,
89
			'show_ui'            => true,
90
			'show_in_menu'       => true,
91
			'show_in_rest'       => true,
92
			'menu_icon'          => 'dashicons-carrot',
93
			'query_var'          => true,
94
			'rewrite'            => array(
95
				'slug' => \lsx_health_plan\functions\get_option( 'meal_single_slug', 'meal' ),
96
			),
97
			'capability_type'    => 'page',
98
			'has_archive'        => \lsx_health_plan\functions\get_option( 'endpoint_meal_archive', 'meals' ),
99
			'hierarchical'       => true,
100
			'menu_position'      => null,
101
			'supports'           => array(
102
				'title',
103
				'editor',
104
				'thumbnail',
105
				'page-attributes',
106
				'custom-fields',
107
			),
108
		);
109
		register_post_type( 'meal', $args );
110
	}
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
111
112
	/**
113
	 * Register the Meal Type taxonomy.
114
	 */
115
	public function taxonomy_setup() {
116
		$labels = array(
117
			'name'              => esc_html_x( 'Meal Type', 'taxonomy general name', 'lsx-health-plan' ),
118
			'singular_name'     => esc_html_x( 'Meal Types', 'taxonomy singular name', 'lsx-health-plan' ),
119
			'search_items'      => esc_html__( 'Search', 'lsx-health-plan' ),
120
			'all_items'         => esc_html__( 'All', 'lsx-health-plan' ),
121
			'parent_item'       => esc_html__( 'Parent', 'lsx-health-plan' ),
122
			'parent_item_colon' => esc_html__( 'Parent:', 'lsx-health-plan' ),
123
			'edit_item'         => esc_html__( 'Edit', 'lsx-health-plan' ),
124
			'update_item'       => esc_html__( 'Update', 'lsx-health-plan' ),
125
			'add_new_item'      => esc_html__( 'Add New', 'lsx-health-plan' ),
126
			'new_item_name'     => esc_html__( 'New Name', 'lsx-health-plan' ),
127
			'menu_name'         => esc_html__( 'Meal Types', 'lsx-health-plan' ),
128
		);
129
		$args   = array(
130
			'hierarchical'      => true,
131
			'labels'            => $labels,
132
			'show_ui'           => true,
133
			'show_in_menu'      => 'edit.php?post_type=meal',
134
			'show_admin_column' => true,
135
			'query_var'         => true,
136
			'rewrite'           => array(
137
				'slug' => 'meal-type',
138
			),
139
		);
140
		register_taxonomy( 'meal-type', array( $this->slug ), $args );
141
	}
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
142
143
	/**
144
	 * Adds the post type to the different arrays.
145
	 *
146
	 * @param array $post_types
0 ignored issues
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
147
	 * @return array
148
	 */
149
	public function enable_post_type( $post_types = array() ) {
150
		$post_types[] = $this->slug;
151
		return $post_types;
152
	}
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
153
154
	/**
155
	 * Enables the Bi Directional relationships
156
	 *
157
	 * @param array $connections
0 ignored issues
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
158
	 * @return void
0 ignored issues
show
Coding Style introduced by
Function return type is void, but function contains return statement
Loading history...
159
	 */
160
	public function enable_connections( $connections = array() ) {
161
		$connections['meal']['connected_plans'] = 'connected_meals';
162
		$connections['plan']['connected_meals'] = 'connected_plans';
163
		return $connections;
164
	}
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
165
166
	/**
167
	 * Remove the "Archives:" from the post type meal.
168
	 *
169
	 * @param string $title the term title.
170
	 * @return string
171
	 */
172
	public function get_the_archive_title( $title ) {
173
		if ( is_post_type_archive( 'meal' ) ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
174
			$title = __( 'Meals', 'lsx-health-plan' );
175
		}
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
176
		return $title;
177
	}
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
178
179
	/**
180
	 * Define the metabox and field configurations.
181
	 */
182
	public function featured_metabox() {
183
		$cmb = new_cmb2_box(
184
			array(
185
				'id'           => $this->slug . '_featured_metabox_meal',
186
				'title'        => __( 'Featured Meal', 'lsx-health-plan' ),
187
				'object_types' => array( $this->slug ), // Post type
0 ignored issues
show
Coding Style introduced by
Inline comments must end in full-stops, exclamation marks, or question marks
Loading history...
188
				'context'      => 'side',
189
				'priority'     => 'high',
190
				'show_names'   => true,
191
			)
192
		);
193
		$cmb->add_field(
194
			array(
195
				'name'       => __( 'Featured Meal', 'lsx-health-plan' ),
196
				'desc'       => __( 'Enable a featured meal' ),
197
				'id'         => $this->slug . '_featured_meal',
198
				'type'       => 'checkbox',
199
				'show_on_cb' => 'cmb2_hide_if_no_cats',
200
			)
201
		);
202
	}
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
203
204
	/**
205
	 * Define the metabox and field configurations.
206
	 */
207
	public function details_metaboxes() {
208
		$cmb = new_cmb2_box( array(
0 ignored issues
show
Coding Style introduced by
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
209
			'id'           => $this->slug . '_shopping_list_metabox',
210
			'title'        => __( 'Shopping List', 'lsx-health-plan' ),
211
			'object_types' => array( $this->slug ), // Post type
0 ignored issues
show
Coding Style introduced by
Inline comments must end in full-stops, exclamation marks, or question marks
Loading history...
212
			'context'      => 'normal',
213
			'priority'     => 'high',
214
			'show_names'   => true,
215
		) );
0 ignored issues
show
Coding Style introduced by
For multi-line function calls, the closing parenthesis should be on a new line.

If a function call spawns multiple lines, the coding standard suggests to move the closing parenthesis to a new line:

someFunctionCall(
    $firstArgument,
    $secondArgument,
    $thirdArgument
); // Closing parenthesis on a new line.
Loading history...
216
		$cmb->add_field( array(
0 ignored issues
show
Coding Style introduced by
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
217
			'name'       => __( 'Shopping List', 'lsx-health-plan' ),
218
			'desc'       => __( 'Connect the shopping list page that applies to this meal by entering the name of the page in the field provided.' ),
219
			'id'         => $this->slug . '_shopping_list',
220
			'type'       => 'post_search_ajax',
221
			// Optional :
0 ignored issues
show
Coding Style introduced by
Inline comments must end in full-stops, exclamation marks, or question marks
Loading history...
222
			'limit'      => 1,  // Limit selection to X items only (default 1)
0 ignored issues
show
Coding Style introduced by
Inline comments must end in full-stops, exclamation marks, or question marks
Loading history...
223
			'sortable'   => true, // Allow selected items to be sortable (default false)
0 ignored issues
show
Coding Style introduced by
Inline comments must end in full-stops, exclamation marks, or question marks
Loading history...
224
			'query_args' => array(
225
				'post_type'      => array( 'page' ),
226
				'post_status'    => array( 'publish' ),
227
				'posts_per_page' => -1,
228
			),
229
		) );
0 ignored issues
show
Coding Style introduced by
For multi-line function calls, the closing parenthesis should be on a new line.

If a function call spawns multiple lines, the coding standard suggests to move the closing parenthesis to a new line:

someFunctionCall(
    $firstArgument,
    $secondArgument,
    $thirdArgument
); // Closing parenthesis on a new line.
Loading history...
230
		$cmb = new_cmb2_box( array(
0 ignored issues
show
Coding Style introduced by
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
231
			'id'           => $this->slug . '_details_metabox',
232
			'title'        => __( 'Meal Details', 'lsx-health-plan' ),
233
			'object_types' => array( $this->slug ), // Post type
0 ignored issues
show
Coding Style introduced by
Inline comments must end in full-stops, exclamation marks, or question marks
Loading history...
234
			'context'      => 'normal',
235
			'priority'     => 'high',
236
			'show_names'   => true,
237
		) );
0 ignored issues
show
Coding Style introduced by
For multi-line function calls, the closing parenthesis should be on a new line.

If a function call spawns multiple lines, the coding standard suggests to move the closing parenthesis to a new line:

someFunctionCall(
    $firstArgument,
    $secondArgument,
    $thirdArgument
); // Closing parenthesis on a new line.
Loading history...
238
239
		$cmb->add_field( array(
0 ignored issues
show
Coding Style introduced by
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
240
			'name' => __( 'Meal Short Description', 'lsx-health-plan' ),
241
			'id'   => $this->slug . '_short_description',
242
			'type' => 'textarea_small',
243
			'desc' => __( 'Add a small description for this meal (optional)', 'lsx-health-plan' ),
244
		) );
0 ignored issues
show
Coding Style introduced by
For multi-line function calls, the closing parenthesis should be on a new line.

If a function call spawns multiple lines, the coding standard suggests to move the closing parenthesis to a new line:

someFunctionCall(
    $firstArgument,
    $secondArgument,
    $thirdArgument
); // Closing parenthesis on a new line.
Loading history...
245
246
		$cmb->add_field( array(
0 ignored issues
show
Coding Style introduced by
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
247
			'name'       => __( 'Pre Breakfast Snack', 'lsx-health-plan' ),
248
			'id'         => $this->slug . '_pre_breakfast_snack',
249
			'type'       => 'wysiwyg',
250
			'show_on_cb' => 'cmb2_hide_if_no_cats',
251
			'options'    => array(
252
				'textarea_rows' => 5,
253
			),
254
		) );
0 ignored issues
show
Coding Style introduced by
For multi-line function calls, the closing parenthesis should be on a new line.

If a function call spawns multiple lines, the coding standard suggests to move the closing parenthesis to a new line:

someFunctionCall(
    $firstArgument,
    $secondArgument,
    $thirdArgument
); // Closing parenthesis on a new line.
Loading history...
255
		$cmb->add_field( array(
0 ignored issues
show
Coding Style introduced by
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
256
			'name'       => __( 'Breakfast', 'lsx-health-plan' ),
257
			'id'         => $this->slug . '_breakfast',
258
			'type'       => 'wysiwyg',
259
			'show_on_cb' => 'cmb2_hide_if_no_cats',
260
			'options'    => array(
261
				'textarea_rows' => 5,
262
			),
263
		) );
0 ignored issues
show
Coding Style introduced by
For multi-line function calls, the closing parenthesis should be on a new line.

If a function call spawns multiple lines, the coding standard suggests to move the closing parenthesis to a new line:

someFunctionCall(
    $firstArgument,
    $secondArgument,
    $thirdArgument
); // Closing parenthesis on a new line.
Loading history...
264
265
		$cmb->add_field(
266
			array(
267
				'name'       => __( 'Post Breakfast Snack', 'lsx-health-plan' ),
268
				'id'         => $this->slug . '_breakfast_snack',
269
				'type'       => 'wysiwyg',
270
				'show_on_cb' => 'cmb2_hide_if_no_cats',
271
				'options'    => array(
272
					'textarea_rows' => 5,
273
				),
274
			)
275
		);
276
277
		if ( post_type_exists( 'recipe' ) ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
278
			$cmb->add_field(
279
				array(
280
					'name'       => __( 'Breakfast Recipes', 'lsx-health-plan' ),
281
					'desc'       => __( 'Connect additional recipes options for breakfast.', 'lsx-health-plan' ),
282
					'id'         => 'breakfast_recipes',
283
					'type'       => 'post_search_ajax',
284
					// Optional :
0 ignored issues
show
Coding Style introduced by
Inline comments must end in full-stops, exclamation marks, or question marks
Loading history...
285
					'limit'      => 15,  // Limit selection to X items only (default 1)
0 ignored issues
show
Coding Style introduced by
Inline comments must end in full-stops, exclamation marks, or question marks
Loading history...
286
					'sortable'   => true, // Allow selected items to be sortable (default false)
0 ignored issues
show
Coding Style introduced by
Inline comments must end in full-stops, exclamation marks, or question marks
Loading history...
287
					'query_args' => array(
288
						'post_type'      => array( 'recipe' ),
289
						'post_status'    => array( 'publish' ),
290
						'posts_per_page' => -1,
291
					),
292
				)
293
			);
294
		}
295
296
		$cmb->add_field(
297
			array(
298
				'name'       => __( 'Pre Lunch Snack', 'lsx-health-plan' ),
299
				'id'         => $this->slug . '_pre_lunch_snack',
300
				'type'       => 'wysiwyg',
301
				'show_on_cb' => 'cmb2_hide_if_no_cats',
302
				'options'    => array(
303
					'textarea_rows' => 5,
304
				),
305
			)
306
		);
307
		$cmb->add_field(
308
			array(
309
				'name'       => __( 'Lunch', 'lsx-health-plan' ),
310
				'id'         => $this->slug . '_lunch',
311
				'type'       => 'wysiwyg',
312
				'show_on_cb' => 'cmb2_hide_if_no_cats',
313
				'options'    => array(
314
					'textarea_rows' => 5,
315
				),
316
			)
317
		);
318
		$cmb->add_field(
319
			array(
320
				'name'       => __( 'Post Lunch Snack', 'lsx-health-plan' ),
321
				'id'         => $this->slug . '_lunch_snack',
322
				'type'       => 'wysiwyg',
323
				'show_on_cb' => 'cmb2_hide_if_no_cats',
324
				'options'    => array(
325
					'textarea_rows' => 5,
326
				),
327
			)
328
		);
329
330
		if ( post_type_exists( 'recipe' ) ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
331
			$cmb->add_field(
332
				array(
333
					'name'       => __( 'Lunch Recipes', 'lsx-health-plan' ),
334
					'desc'       => __( 'Connect additional recipes options for lunch.', 'lsx-health-plan' ),
335
					'id'         => 'lunch_recipes',
336
					'type'       => 'post_search_ajax',
337
					// Optional :
0 ignored issues
show
Coding Style introduced by
Inline comments must end in full-stops, exclamation marks, or question marks
Loading history...
338
					'limit'      => 15,  // Limit selection to X items only (default 1)
0 ignored issues
show
Coding Style introduced by
Inline comments must end in full-stops, exclamation marks, or question marks
Loading history...
339
					'sortable'   => true, // Allow selected items to be sortable (default false)
0 ignored issues
show
Coding Style introduced by
Inline comments must end in full-stops, exclamation marks, or question marks
Loading history...
340
					'query_args' => array(
341
						'post_type'      => array( 'recipe' ),
342
						'post_status'    => array( 'publish' ),
343
						'posts_per_page' => -1,
344
					),
345
				)
346
			);
347
		}
348
349
		$cmb->add_field(
350
			array(
351
				'name'       => __( 'Pre Dinner Snack', 'lsx-health-plan' ),
352
				'id'         => $this->slug . '_pre_dinner_snack',
353
				'type'       => 'wysiwyg',
354
				'show_on_cb' => 'cmb2_hide_if_no_cats',
355
				'options'    => array(
356
					'textarea_rows' => 5,
357
				),
358
			)
359
		);
360
		$cmb->add_field(
361
			array(
362
				'name'       => __( 'Dinner', 'lsx-health-plan' ),
363
				'id'         => $this->slug . '_dinner',
364
				'type'       => 'wysiwyg',
365
				'show_on_cb' => 'cmb2_hide_if_no_cats',
366
				'options'    => array(
367
					'textarea_rows' => 5,
368
				),
369
			)
370
		);
371
		$cmb->add_field(
372
			array(
373
				'name'       => __( 'Post Dinner Snack', 'lsx-health-plan' ),
374
				'id'         => $this->slug . '_dinner_snack',
375
				'type'       => 'wysiwyg',
376
				'show_on_cb' => 'cmb2_hide_if_no_cats',
377
				'options'    => array(
378
					'textarea_rows' => 5,
379
				),
380
			)
381
		);
382
383
		if ( post_type_exists( 'recipe' ) ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
384
			$cmb->add_field(
385
				array(
386
					'name'       => __( 'Dinner Recipes', 'lsx-health-plan' ),
387
					'desc'       => __( 'Connect additional recipes options for dinner.', 'lsx-health-plan' ),
388
					'id'         => 'dinner_recipes',
389
					'type'       => 'post_search_ajax',
390
					// Optional :
0 ignored issues
show
Coding Style introduced by
Inline comments must end in full-stops, exclamation marks, or question marks
Loading history...
391
					'limit'      => 15,  // Limit selection to X items only (default 1)
0 ignored issues
show
Coding Style introduced by
Inline comments must end in full-stops, exclamation marks, or question marks
Loading history...
392
					'sortable'   => true, // Allow selected items to be sortable (default false)
0 ignored issues
show
Coding Style introduced by
Inline comments must end in full-stops, exclamation marks, or question marks
Loading history...
393
					'query_args' => array(
394
						'post_type'      => array( 'recipe' ),
395
						'post_status'    => array( 'publish' ),
396
						'posts_per_page' => -1,
397
					),
398
				)
399
			);
400
		}
401
	}
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 0 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
402
	/**
403
	 * Set the post type archive to show the parent plans only.
404
	 *
405
	 * @param object $wp_query
0 ignored issues
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
406
	 * @return array
0 ignored issues
show
Coding Style introduced by
Function return type is not void, but function has no return statement
Loading history...
407
	 */
408
	public function set_parent_only( $wp_query ) {
409
		if ( ! is_admin() && $wp_query->is_main_query() && ( $wp_query->is_post_type_archive( 'meal' ) || $wp_query->is_tax( array( 'meal-type' ) ) ) ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
410
			$wp_query->set( 'post_parent', '0' );
411
		}
412
	}
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
413
414
415
	/**
0 ignored issues
show
Coding Style Documentation introduced by
Doc comment for parameter "$crumbs" missing
Loading history...
416
	 * Holds the array for the single meal breadcrumbs.
417
	 *
418
	 * @var array $crumbs
419
	 * @return array
420
	 */
421
	public function meal_breadcrumb_filter( $crumbs ) {
422
		$meal  = \lsx_health_plan\functions\get_option( 'endpoint_meal', 'meal' );
423
		$meals = \lsx_health_plan\functions\get_option( 'endpoint_meal_archive', 'meal' );
424
425
		if ( is_singular( 'meal' ) ) {	
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
introduced by
Spaces must be used for mid-line alignment; tabs are not allowed
Loading history...
426
			$meal_name     = get_the_title();
427
			$url           = get_post_type_archive_link( $meal );
0 ignored issues
show
Bug introduced by
It seems like $meal can also be of type array; however, parameter $post_type of get_post_type_archive_link() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

427
			$url           = get_post_type_archive_link( /** @scrutinizer ignore-type */ $meal );
Loading history...
428
			$term_obj_list = get_the_terms( get_the_ID(), 'meal-type' );
0 ignored issues
show
Bug introduced by
It seems like get_the_ID() can also be of type false; however, parameter $post of get_the_terms() does only seem to accept WP_Post|integer, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

428
			$term_obj_list = get_the_terms( /** @scrutinizer ignore-type */ get_the_ID(), 'meal-type' );
Loading history...
429
			$meal_type     = $term_obj_list[0]->name;
430
			if ( empty( $meal_type ) ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
431
				$meal_type = __( 'Meal', 'lsx-health-plan' );
432
			}
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
433
			$meal_type_url = get_term_link( $term_obj_list[0]->term_id );
434
435
			$new_crumbs    = array();
436
			$new_crumbs[0] = $crumbs[0];
437
438
			if ( function_exists( 'woocommerce_breadcrumb' ) ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
439
				$new_crumbs[1] = array(
440
					0 => $meals,
441
					1 => $url,
442
				);
443
				$new_crumbs[2] = array(
444
					0 => $meal_type,
445
					1 => $meal_type_url,
446
				);
447
				$new_crumbs[3] = array(
448
					0 => $meal_name,
449
				);
450
			} else {
451
				$new_crumbs[1] = array(
452
					'text' => $meals,
453
					'url'  => $url,
454
				);
455
				$new_crumbs[2] = array(
456
					'text' => $meal_type,
457
					'url'  => $meal_type_url,
458
				);
459
				$new_crumbs[3] = array(
460
					'text' => $meal_name,
461
				);
462
			}
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
463
			$crumbs = $new_crumbs;
464
0 ignored issues
show
Coding Style introduced by
Blank line found at end of control structure
Loading history...
465
		}
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
466
		if ( is_post_type_archive( 'meal' ) ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
Coding Style introduced by
Blank line found at start of control structure
Loading history...
467
468
			$new_crumbs    = array();
469
			$new_crumbs[0] = $crumbs[0];
470
471
			if ( function_exists( 'woocommerce_breadcrumb' ) ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
472
				$new_crumbs[1] = array(
473
					0 => $meals,
474
				);
475
			} else {
476
				$new_crumbs[1] = array(
477
					'text' => $meals,
478
				);
479
			}
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
480
			$crumbs = $new_crumbs;
481
		}
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
482
		return $crumbs;
483
	}
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 0 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
484
}
485