Passed
Push — add/multiplan ( f49156...39ef50 )
by Virginia
06:22
created

lsx_health_plan_meal_main_content()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 18
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 13
nc 2
nop 0
dl 0
loc 18
rs 9.8333
c 0
b 0
f 0
1
<?php
2
/**
3
 * LSX Health Plan Template Tags.
4
 *
5
 * @package lsx-health-plan
6
 */
7
8
/**
9
 * Outputs the warmup box on the single plan page.
10
*
11
* @return void
12
*/
13
function lsx_health_plan_warmup_box() {
14
	?>
15
	<div class="col-md-4" >
16
		<div class="lsx-health-plan-box">
17
			<h3 class="title warm-up-title title-lined"><?php esc_html_e( 'Your Warm-up', 'lsx-health-plan' ); ?><?php lsx_get_svg_icon( 'warm.svg' ); ?></h3>
18
			<div class="spacer"></div>
19
			<?php
20
			$intro_text = \lsx_health_plan\functions\get_option( 'warmup_intro', false );
21
			if ( false !== $intro_text ) {
22
				?>
23
				<div class="excerpt">
24
					<p><?php echo wp_kses_post( $intro_text ); ?></p>
0 ignored issues
show
Bug introduced by
It seems like $intro_text can also be of type array; however, parameter $data of wp_kses_post() 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

24
					<p><?php echo wp_kses_post( /** @scrutinizer ignore-type */ $intro_text ); ?></p>
Loading history...
25
				</div>
26
				<?php
27
			}
28
			$warm_up = \lsx_health_plan\functions\get_option( 'endpoint_warm_up', false );
29
			if ( false === $warm_up ) {
30
				$warm_up = 'warm-up';
31
			}
32
			?>
33
			<a href="<?php the_permalink(); ?><?php echo esc_attr( $warm_up ); ?>/" class="btn"><?php esc_html_e( 'Start your warm-up', 'lsx-health-plan' ); ?></a>
34
		</div>
35
	</div>
36
<?php
37
}
38
39
/**
40
 * Outputs the workout box on the single plan page.
41
*
42
* @return void
43
*/
44
function lsx_health_plan_workout_box() {
45
	if ( ! post_type_exists( 'workout' ) ) {
46
		return;
47
	}
48
	?>
49
	<div class="col-md-4" >
50
		<div class="lsx-health-plan-box">
51
			<h3 class="title work-out-title title-lined"><?php esc_html_e( 'Your Workout', 'lsx-health-plan' ); ?><?php lsx_get_svg_icon( 'work.svg' ); ?></h3>
52
			<div class="spacer"></div>
53
			<?php
54
			$intro_text = \lsx_health_plan\functions\get_option( 'workout_intro', false );
55
			if ( false !== $intro_text ) {
56
				?>
57
				<div class="excerpt">
58
					<p><?php echo wp_kses_post( $intro_text ); ?></p>
0 ignored issues
show
Bug introduced by
It seems like $intro_text can also be of type array; however, parameter $data of wp_kses_post() 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

58
					<p><?php echo wp_kses_post( /** @scrutinizer ignore-type */ $intro_text ); ?></p>
Loading history...
59
				</div>
60
				<?php
61
			}
62
			$workout = \lsx_health_plan\functions\get_option( 'endpoint_workout', false );
63
			if ( false === $workout ) {
64
				$workout = 'workout';
65
			}
66
			?>
67
			<a href="<?php the_permalink(); ?><?php echo esc_attr( $workout ); ?>/" class="btn"><?php esc_html_e( 'Start your workout', 'lsx-health-plan' ); ?></a>
68
		</div>
69
	</div>
70
<?php
71
}
72
73
/**
74
 * Outputs the meal plan box on the single plan page.
75
*
76
* @return void
77
*/
78
function lsx_health_plan_meal_box() {
79
	if ( ! post_type_exists( 'meal' ) ) {
80
		return;
81
	}
82
	?>
83
	<div class="col-md-4" >
84
		<div class="lsx-health-plan-box">
85
			<h3 class="title meal-plan-title title-lined"><?php esc_html_e( 'Your Meal Plan', 'lsx-health-plan' ); ?><?php lsx_get_svg_icon( 'meal.svg' ); ?></h3>
86
			<div class="spacer"></div>
87
			<?php
88
			$intro_text = \lsx_health_plan\functions\get_option( 'meal_plan_intro', false );
89
			if ( false !== $intro_text ) {
90
				?>
91
				<div class="excerpt">
92
					<p><?php echo wp_kses_post( $intro_text ); ?></p>
0 ignored issues
show
Bug introduced by
It seems like $intro_text can also be of type array; however, parameter $data of wp_kses_post() 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

92
					<p><?php echo wp_kses_post( /** @scrutinizer ignore-type */ $intro_text ); ?></p>
Loading history...
93
				</div>
94
				<?php
95
			}
96
			$meal = \lsx_health_plan\functions\get_option( 'endpoint_meal', false );
97
			if ( false === $meal ) {
98
				$meal = 'meal';
99
			}
100
			?>
101
			<a href="<?php the_permalink(); ?><?php echo esc_attr( $meal ); ?>/" class="btn"><?php esc_html_e( 'View your meal plan', 'lsx-health-plan' ); ?></a>
102
		</div>
103
	</div>
104
<?php
105
}
106
107
/**
108
 * Outputs the recipe box on the single plan page.
109
*
110
* @return void
111
*/
112
function lsx_health_plan_recipe_box() {
113
	if ( ! post_type_exists( 'recipe' ) ) {
114
		return;
115
	}
116
	?>
117
	<div class="col-md-4" >
118
		<div class="lsx-health-plan-box">
119
			<h3 class="title recipes-title title-lined"><?php esc_html_e( 'Recipes', 'lsx-health-plan' ); ?><?php lsx_get_svg_icon( 'recipes.svg' ); ?></h3>
120
			<div class="spacer"></div>
121
			<?php
122
			$intro_text = \lsx_health_plan\functions\get_option( 'recipes_intro', false );
123
			if ( false !== $intro_text ) {
124
				?>
125
				<div class="excerpt">
126
					<p><?php echo wp_kses_post( $intro_text ); ?></p>
0 ignored issues
show
Bug introduced by
It seems like $intro_text can also be of type array; however, parameter $data of wp_kses_post() 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

126
					<p><?php echo wp_kses_post( /** @scrutinizer ignore-type */ $intro_text ); ?></p>
Loading history...
127
				</div>
128
				<?php
129
			}
130
			$recipes = \lsx_health_plan\functions\get_option( 'endpoint_recipe', false );
131
			if ( false === $recipes ) {
132
				$recipes = 'recipes';
133
			}
134
			?>
135
			<a href="<?php the_permalink(); ?><?php echo esc_attr( $recipes ); ?>/" class="btn"><?php esc_html_e( 'View all recipes', 'lsx-health-plan' ); ?></a>
136
		</div>
137
	</div>
138
<?php
139
}
140
141
/**
142
 * Outputs the downloads box on the single plan page.
143
*
144
* @return void
145
*/
146
function lsx_health_plan_downloads_box() {
147
	global $current_user;
148
	?>
149
	<div class="col-md-4 day-download-box" >
150
		<div class="lsx-health-plan-box">
151
			<h3 class="title downloads-title title-lined"><?php esc_html_e( 'Downloads', 'lsx-health-plan' ); ?><?php lsx_get_svg_icon( 'download.svg' ); ?></h3>
152
			<div class="spacer"></div>
153
			<div class="download-list">
154
				<ul>
155
					<?php
156
					$downloads = \lsx_health_plan\functions\get_downloads();
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $downloads is correct as get_downloads() seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
157
					if ( ! empty( $downloads ) ) {
158
						foreach ( $downloads as $download ) {
0 ignored issues
show
Bug introduced by
The expression $downloads of type void is not traversable.
Loading history...
159
							echo wp_kses_post( '<li><a href=""><i class="fa fa-file-pdf"></i>' . do_shortcode( '[download id="' . $download . '"]' ) . '</a></li>' );
160
						}
161
					}
162
					?>
163
				</ul>
164
			</div>
165
		</div>
166
	</div>
167
<?php
168
}
169
170
/**
171
 * outputs the dynamic classes for the nav tabs.
172
 *
173
 * @param string $tab
174
 * @return void
175
 */
176
function lsx_health_plan_nav_class( $tab = '' ) {
177
	$nav_classes = array();
178
	if ( function_exists( 'is_wc_endpoint_url' ) && 'edit-account' === $tab && is_wc_endpoint_url( 'edit-account' ) ) {
179
		$nav_classes[] = 'active';
180
	} elseif ( lsx_health_plan_is_current_tab( $tab ) ) {
181
		$nav_classes[] = 'active';
182
	}
183
	if ( ! empty( $nav_classes ) ) {
184
		echo wp_kses_post( implode( ' ', $nav_classes ) );
185
	}
186
}
187
188
/**
189
 * Outputs the my profile tabs
190
 *
191
 * @return void
192
 */
193
function lsx_health_plan_my_profile_tabs() {
194
	?>
195
	<div id="account-nav">
196
		<ul class="nav nav-pills">
197
			<li class="
198
			<?php
199
			if ( ( function_exists( 'is_wc_endpoint_url' ) && ! is_wc_endpoint_url( 'edit-account' ) ) || ! function_exists( 'is_wc_endpoint_url' ) ) {
200
				echo esc_attr( 'active' );
201
			}
202
			?>
203
			"><a class="my-plan-tab" href="<?php the_permalink(); ?>"><?php esc_html_e( 'My Plan', 'lsx-health-plan' ); ?></a></li>
204
			<li class="
205
			<?php
206
			if ( function_exists( 'is_wc_endpoint_url' ) && is_wc_endpoint_url( 'edit-account' ) ) {
207
				echo esc_attr( 'active' );
208
			}
209
			?>
210
			"><a class="account-details-tab" href="<?php the_permalink(); ?>edit-account/"><?php esc_html_e( 'Account Details', 'lsx-health-plan' ); ?></a></li>
211
			<li class=""><a class="logout-tab" href="<?php echo esc_url( wp_logout_url( get_permalink() ) ); ?>"><?php esc_html_e( 'Logout', 'lsx-health-plan' ); ?></a></li>
0 ignored issues
show
Bug introduced by
It seems like get_permalink() can also be of type false; however, parameter $redirect of wp_logout_url() 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

211
			<li class=""><a class="logout-tab" href="<?php echo esc_url( wp_logout_url( /** @scrutinizer ignore-type */ get_permalink() ) ); ?>"><?php esc_html_e( 'Logout', 'lsx-health-plan' ); ?></a></li>
Loading history...
212
		</ul>
213
	</div>
214
	<?php
215
}
216
217
/**
218
 * Outputs the my profile box
219
 *
220
 * @return void
221
 */
222
function lsx_health_plan_my_profile_box() {
223
	?>
224
	<div class="lsx-health-plan my-profile-block wp-block-cover alignfull">
225
		<div class="wp-block-cover__inner-container">
226
			<h2><?php esc_html_e( 'My Dashboard', 'lsx-health-plan' ); ?></h2>
227
			<section id="dashboard-card">
228
				<div class="profile-navigation">
229
					<div class="profile-photo">
230
					<?php
231
						global $current_user;
232
						get_current_user();
233
						echo get_avatar( $current_user->ID, 240 );
0 ignored issues
show
Bug introduced by
Are you sure get_avatar($current_user->ID, 240) of type false|string can be used in echo? ( Ignorable by Annotation )

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

233
						echo /** @scrutinizer ignore-type */ get_avatar( $current_user->ID, 240 );
Loading history...
234
						?>
235
					</div>
236
				</div>
237
				<div class="profile-details">
238
					<h1 class="title-lined has-text-color"><?php echo esc_html( $current_user->display_name ); ?></h1>
239
					<?php
240
					$disable_stats = \lsx_health_plan\functions\get_option( 'disable_all_stats', false );
241
					if ( 'on' !== $disable_stats ) {
242
243
						$is_weight_disabled  = \lsx_health_plan\functions\get_option( 'disable_weight_checkbox', false );
244
						$is_waist_disabled   = \lsx_health_plan\functions\get_option( 'disable_waist_checkbox', false );
245
						$is_fitness_disabled = \lsx_health_plan\functions\get_option( 'disable_fitness_checkbox', false );
246
247
						$weight = get_user_meta( get_current_user_id(), 'weight', true );
248
						$waist = get_user_meta( get_current_user_id(), 'waist', true );
249
						$height = get_user_meta( get_current_user_id(), 'height', true );
250
251
						$height_m = $height / 100;
252
253
						if ( 1 < $weight && 1 < $height_m ) {
254
							$bmi = $weight / ( $height_m * $height_m );
255
							$bmi = number_format( $bmi, 1 );
256
						} else {
257
							$bmi = __( 'Add more data', 'lsx-health-plan' );
258
						}
259
260
						?>
261
262
						<div>
263
							<?php if ( 'on' !== $is_weight_disabled ) { ?>
264
								<span><strong><?php esc_html_e( 'Weight:', 'lsx-health-plan' ); ?></strong>
265
								<?php
266
								if ( '' !== $weight ) {
267
									echo wp_kses_post( $weight . ' kg' );
268
								} else {
269
									echo '/';
270
								}
271
								?>
272
								</span>
273
							<?php }
274
							if ( 'on' !== $is_waist_disabled ) {
275
								?>
276
								<span><strong><?php esc_html_e( 'Waist:', 'lsx-health-plan' ); ?></strong>
277
								<?php
278
								if ( '' !== $waist ) {
279
									echo wp_kses_post( $waist . ' cm' );
280
								} else {
281
									echo '/';
282
								}
283
								?>
284
								</span>
285
							<?php } ?>
286
							<span><strong><?php esc_html_e( 'BMI:', 'lsx-health-plan' ); ?></strong> <?php echo esc_html( $bmi ); ?></span>
287
						</div>
288
					<?php
289
					}
290
					?>
291
					<div class="edit-profile">
292
						<?php
293
						if ( function_exists( 'wc_get_page_id' ) ) {
294
							$url_id = wc_get_page_id( 'myaccount' );
295
						} else {
296
							$url_id = '';
297
						}
298
						?>
299
						<a href="<?php echo esc_url( get_permalink( $url_id ) ); ?>edit-account/"><?php esc_html_e( 'Edit', 'lsx-health-plan' ); ?></a>
0 ignored issues
show
Bug introduced by
It seems like get_permalink($url_id) can also be of type false; however, parameter $url of esc_url() 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

299
						<a href="<?php echo esc_url( /** @scrutinizer ignore-type */ get_permalink( $url_id ) ); ?>edit-account/"><?php esc_html_e( 'Edit', 'lsx-health-plan' ); ?></a>
Loading history...
300
					</div>
301
				</div>
302
			</section>
303
		</div>
304
	</div>
305
	<?php
306
}
307
308
/**
309
 * Outputs the my profile list of plans box
310
 *
311
 * @return void
312
 */
313
function lsx_health_plan_all_plans_block() {
314
	global $post, $product;
315
316
	$args = array(
317
		'orderby'        => 'menu_order',
318
		'order'          => 'ASC',
319
		'post_type'      => 'plan',
320
		'nopagin'        => true,
321
		'post_parent'    => 0,
322
	);
323
324
	$product_ids = \lsx_health_plan\functions\woocommerce\get_membership_products();
325
	if ( ! empty( $product_ids ) ) {
326
		$args['meta_query'] = array(
327
			'relation' => 'OR',
328
			array(
329
				'key'     => '_plan_product_id',
330
				'value'   => $product_ids,
331
				'compare' => 'IN',
332
			),
333
			array(
334
				'key'     => '_plan_product_id',
335
				'compare' => 'NOT EXISTS',
336
			),
337
		);
338
	}
339
340
	$the_query = new WP_Query( $args );
341
	?>
342
	<div class="all-plans-block plan-grid block-all-plans-block">
343
		<div class="row">
344
			<?php
345
			if ( $the_query->have_posts() ) :
346
				while ( $the_query->have_posts() ) :
347
					$the_query->the_post();
348
					lsx_entry_before();
0 ignored issues
show
Bug introduced by
The function lsx_entry_before was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

348
					/** @scrutinizer ignore-call */ 
349
     lsx_entry_before();
Loading history...
349
					$completed_class = '';
350
					$linked_product  = false;
351
					$restricted      = false;
352
					$product         = null;
353
					if ( \lsx_health_plan\functions\woocommerce\plan_has_products() ) {
354
						$products       = \lsx_health_plan\functions\woocommerce\get_plan_products();
355
						$linked_product = wc_get_product( $products[0] );
0 ignored issues
show
Bug introduced by
The function wc_get_product was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

355
						$linked_product = /** @scrutinizer ignore-call */ wc_get_product( $products[0] );
Loading history...
356
						$product        = $linked_product;
357
					}
358
					if ( function_exists( 'wc_memberships_is_post_content_restricted' ) ) {
359
						$restricted = wc_memberships_is_post_content_restricted( get_the_ID() ) && ! current_user_can( 'wc_memberships_view_restricted_post_content', get_the_ID() );
360
					}
361
362
					if ( lsx_health_plan_is_day_complete() ) {
363
						$completed_class = 'completed';
364
					}
365
					?>
366
					<div class="col-xs-12 col-sm-6 col-md-4">
367
						<article class="lsx-slot lsx-hp-shadow">
368
							<div class="plan-feature-img">
369
								<a href="<?php echo esc_url( get_permalink() ); ?>">
0 ignored issues
show
Bug introduced by
It seems like get_permalink() can also be of type false; however, parameter $url of esc_url() 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

369
								<a href="<?php echo esc_url( /** @scrutinizer ignore-type */ get_permalink() ); ?>">
Loading history...
370
								<?php
371
								$featured_image = get_the_post_thumbnail();
372
								if ( ! empty( $featured_image ) && '' !== $featured_image ) {
373
									the_post_thumbnail( 'lsx-thumbnail', array(
374
										'class' => 'aligncenter',
375
									) );
376
								} else {
377
									?>
378
									<img loading="lazy"  class="placeholder" src="<?php echo esc_attr( plugin_dir_url( __FILE__ ) . '../assets/images/placeholder.jpg' ); ?>">
379
									<?php
380
								}
381
								?>
382
								</a>
383
							</div>
384
							<div class="content-box plan-content-box">
385
								<h3 class="plan id-<?php the_ID(); ?> <?php echo esc_attr( $completed_class ); ?>"><a href="<?php echo esc_url( get_permalink() ); ?>"><?php the_title(); ?></a></h3>
386
								<?php
387
									echo wp_kses_post( \lsx_health_plan\functions\hp_get_plan_type_meta( $post ) );
0 ignored issues
show
Bug introduced by
hp_get_plan_type_meta($post) of type void is incompatible with the type string expected by parameter $data of wp_kses_post(). ( Ignorable by Annotation )

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

387
									echo wp_kses_post( /** @scrutinizer ignore-type */ \lsx_health_plan\functions\hp_get_plan_type_meta( $post ) );
Loading history...
Bug introduced by
Are you sure the usage of hp_get_plan_type_meta($post) is correct as it seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
388
								?>
389
								<?php
390
								if ( false !== $linked_product && false !== $restricted ) {
391
									echo wp_kses_post( $linked_product->get_price_html() );
392
								}
393
								?>
394
								<div class="excerpt">
395
									<?php
396
									if ( ! has_excerpt() ) {
397
										$content = wp_trim_words( get_the_content(), 20 );
398
										$content = '<p>' . $content . '</pre>';
399
									} else {
400
										$content = apply_filters( 'the_excerpt', get_the_excerpt() );
401
									}
402
									echo wp_kses_post( $content );
403
									?>
404
								</div>
405
								<?php
406
								if ( false === $restricted ) {
407
									echo wp_kses_post( '<span class="progress"><progress class="bar" value="' . \lsx_health_plan\functions\get_progress( get_the_ID() ) . '" max="100"> ' . \lsx_health_plan\functions\get_progress( get_the_ID() ) . '% </progress><span>' . \lsx_health_plan\functions\get_progress( get_the_ID() ) . '%</span></span>' );
0 ignored issues
show
Bug introduced by
It seems like get_the_ID() can also be of type false; however, parameter $plan_id of lsx_health_plan\functions\get_progress() does only seem to accept 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

407
									echo wp_kses_post( '<span class="progress"><progress class="bar" value="' . \lsx_health_plan\functions\get_progress( /** @scrutinizer ignore-type */ get_the_ID() ) . '" max="100"> ' . \lsx_health_plan\functions\get_progress( get_the_ID() ) . '% </progress><span>' . \lsx_health_plan\functions\get_progress( get_the_ID() ) . '%</span></span>' );
Loading history...
408
								}
409
								?>
410
							</div>
411
						</article>
412
					</div>
413
				<?php endwhile; ?>
414
			<?php endif; ?>
415
		</div>
416
		<?php wp_reset_postdata(); ?>
417
	</div>
418
419
<?php
420
}
421
422
/**
423
 * Outputs the my profile day view box
424
 *
425
 * @return void
426
 */
427
function lsx_health_plan_day_plan_block( $args = array() ) {
428
	$defaults = array(
429
		'plan' => '',
430
	);
431
	$args     = wp_parse_args( $args, $defaults );
432
433
	if ( isset( $args['plan'] ) && '' !== $args['plan'] && \lsx_health_plan\functions\plan\has_sections( $args['plan'] ) ) {
434
		$sections = \lsx_health_plan\functions\plan\get_sections( $args['plan'] );
435
		?>
436
		<div class="daily-plan-block day-grid">
437
			<?php
438
			foreach ( $sections as $section_key => $section_values ) {
439
				$defaults    = array(
440
					'title' => __( 'Day', 'lsx-health-plan' ) . ' ' . ( $section_key + 1 ),
441
				);
442
				$section_args = wp_parse_args( $section_values, $defaults );
443
444
				$completed_class = '';
445
				if ( lsx_health_plan_is_day_complete() ) {
446
					$completed_class = 'completed';
447
				}
448
				?>
449
				<a href="<?php echo esc_attr( \lsx_health_plan\functions\plan\get_permalink( $args['plan'], $section_args['title'] ) ); ?>" class="day id-<?php echo esc_attr( $section_key + 1 ); ?> <?php echo esc_attr( $completed_class ); ?>">
0 ignored issues
show
Bug introduced by
get_permalink($args['pla...$section_args['title']) of type array is incompatible with the type string expected by parameter $text of esc_attr(). ( Ignorable by Annotation )

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

449
				<a href="<?php echo esc_attr( /** @scrutinizer ignore-type */ \lsx_health_plan\functions\plan\get_permalink( $args['plan'], $section_args['title'] ) ); ?>" class="day id-<?php echo esc_attr( $section_key + 1 ); ?> <?php echo esc_attr( $completed_class ); ?>">
Loading history...
450
					<div class="plan-content"><?php echo esc_attr( $section_args['title'] ); ?></div>
451
				</a>
452
				<?php
453
			}
454
			?>
455
		</div>
456
		<?php
457
	}
458
}
459
460
/**
461
 * Outputs the my profile week view box
462
 *
463
 * @param  array $args An array of arguments.
464
 * @return void
465
 */
466
function lsx_health_plan_week_plan_block( $args = array() ) {
467
	$defaults = array(
468
		'show_downloads' => false,
469
		'plan'           => '',
470
	);
471
	$args     = wp_parse_args( $args, $defaults );
472
473
	if ( isset( $args['plan'] ) && '' !== $args['plan'] && \lsx_health_plan\functions\plan\has_sections( $args['plan'] ) ) {
474
		$groups = \lsx_health_plan\functions\plan\get_sections( $args['plan'], true );
475
476
		if ( ! empty( $groups ) ) {
477
			$counter    = 1;
478
			$group_open = false;
479
480
			foreach ( $groups as $group_key => $sections ) {
481
				$collapse_class = '';
482
				// Determine if the current week is complete.
483
484
				$day_ids = wp_list_pluck( $sections, 'title' );
485
486
				if ( false === $group_open ) {
487
					if ( 1 === $counter && ! \lsx_health_plan\functions\is_week_complete( false, $day_ids ) ) {
488
						$collapse_class = 'in';
489
						$group_open   = true;
490
					} elseif ( ! \lsx_health_plan\functions\is_week_complete( false, $day_ids ) ) {
491
						$collapse_class = 'in';
492
						$group_open   = true;
493
					}
494
				}
495
496
				// Determine if there are any weekly downloads.
497
				$week_downloads_view = '';
498
				/*if ( isset( $args['show_downloads'] ) && false !== $args['show_downloads'] ) {
499
					$weekly_downloads = \lsx_health_plan\functions\get_weekly_downloads( $group_key );
500
					if ( ! empty( $weekly_downloads ) ) {
501
						$week_downloads_view = 'week-downloads-view-on';
502
					}
503
				}*/
504
				?>
505
				<div class="daily-plan-block week-grid">
506
					<a href="#group-<?php echo esc_attr( $group_key ); ?>" data-toggle="collapse" class="week-title"><?php echo esc_attr( \lsx_health_plan\functions\plan\get_group_title( $sections ) ); ?></a>
0 ignored issues
show
Bug introduced by
get_group_title($sections) of type array is incompatible with the type string expected by parameter $text of esc_attr(). ( Ignorable by Annotation )

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

506
					<a href="#group-<?php echo esc_attr( $group_key ); ?>" data-toggle="collapse" class="week-title"><?php echo esc_attr( /** @scrutinizer ignore-type */ \lsx_health_plan\functions\plan\get_group_title( $sections ) ); ?></a>
Loading history...
507
					<div id="group-<?php echo esc_attr( $group_key ); ?>" class="week-row collapse <?php echo esc_attr( $collapse_class ); ?>">
508
						<div class="week-row-inner <?php echo esc_html( $week_downloads_view ); ?>">
509
							<div class="week-meals-recipes-box">
510
511
								<?php if ( ! empty( $week_downloads_view ) ) { ?>
512
									<h3 class="title"><?php lsx_get_svg_icon( 'daily-plan.svg' ); ?><?php echo esc_html_e( 'Daily Plan', 'lsx-health-plan' ); ?></h3>
0 ignored issues
show
Bug introduced by
Are you sure the usage of esc_html_e('Daily Plan', 'lsx-health-plan') is correct as it seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
513
								<?php } ?>
514
515
								<div class="week-meals-recipes-box-inner">
516
								<?php
517
518
								foreach ( $sections as $section_key => $section_values ) {
519
520
									$defaults    = array(
521
										'title' => __( 'Day', 'lsx-health-plan' ) . ' ' . ( $section_key + 1 ),
522
									);
523
									$section_args = wp_parse_args( $section_values, $defaults );
524
525
									$completed_class = '';
526
									if ( lsx_health_plan_is_day_complete() ) {
527
										$completed_class = 'completed';
528
									}
529
									?>
530
									<a href="<?php echo esc_attr( \lsx_health_plan\functions\plan\get_permalink( $args['plan'], $section_args['title'] ) ); ?>" class="day id-<?php echo esc_attr( $section_key + 1 ); ?> <?php echo esc_attr( $completed_class ); ?>">
531
										<div class="plan-content"><?php echo esc_attr( $section_args['title'] ); ?></div>
532
									</a>
533
									<?php
534
								}
535
								?>
536
								</div>
537
							</div>
538
							<?php
539
							if ( ! empty( $week_downloads_view ) ) {
540
								//lsx_health_plan_weekly_downloads( $weekly_downloads );
541
							}
542
							?>
543
						</div>
544
					</div>
545
				</div>
546
				<?php
547
			}
548
		}
549
	}
550
}
551
552
/**
553
 * Outputs the weekly downloads box.
554
 *
555
 * @param array $weekly_downloads An array of the download ids.
556
 * @return void
557
 */
558
function lsx_health_plan_weekly_downloads( $weekly_downloads = array() ) {
559
	if ( ! empty( $weekly_downloads ) ) {
560
		?>
561
		<div class="week-download-box">
562
			<h3 class="title"><?php lsx_get_svg_icon( 'download.svg' ); ?><?php echo esc_html_e( 'Downloads', 'lsx-health-plan' ); ?></h3>
0 ignored issues
show
Bug introduced by
Are you sure the usage of esc_html_e('Downloads', 'lsx-health-plan') is correct as it seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
563
			<ul class="week-download-box-list">
564
				<?php
565
				foreach ( $weekly_downloads as $weekly_download ) {
566
					?>
567
					<li><?php echo wp_kses_post( do_shortcode( '[download id="' . $weekly_download . '"]' ) ); ?></li>
568
					<?php
569
				}
570
				?>
571
			</ul>
572
		</div>
573
		<?php
574
	}
575
}
576
577
/**
578
 * Outputs the featured items of any type shortcode (intended for exercises)
579
 *
580
 * @return void
581
 */
582
function lsx_health_plan_items( $args = array() ) {
583
	global $shortcode_args;
584
	$shortcode_args = $args;
585
	include LSX_HEALTH_PLAN_PATH . '/templates/partials/shortcode-loop.php';
586
}
587
588
/**
589
 * Outputs the featured video shortcode
590
 *
591
 * @return void
592
 */
593
function lsx_health_plan_featured_video_block() {
594
	if ( ! post_type_exists( 'video' ) ) {
595
		return;
596
	}
597
	include LSX_HEALTH_PLAN_PATH . '/templates/featured-videos.php';
598
}
599
600
/**
601
 * Outputs the featured recipes shortcode
602
 *
603
 * @return void
604
 */
605
function lsx_health_plan_featured_recipes_block() {
606
	if ( ! post_type_exists( 'recipe' ) ) {
607
		return;
608
	}
609
	include LSX_HEALTH_PLAN_PATH . '/templates/featured-recipes.php';
610
}
611
612
/**
613
 * Outputs the featured tips shortcode
614
 *
615
 * @return void
616
 */
617
function lsx_health_plan_featured_tips_block() {
618
	include LSX_HEALTH_PLAN_PATH . '/templates/featured-tips.php';
619
}
620
621
/**
622
 * Outputs the Health Plan Buttons
623
 *
624
 * @param string $button
625
 * @return void
626
 */
627
function lsx_health_plan_day_button() {
628
	if ( lsx_health_plan_is_day_complete() ) {
629
		lsx_health_plan_unlock_button();
630
	} else {
631
		lsx_health_plan_complete_button();
632
	}
633
}
634
635
/**
636
 * Outputs the health plan complete button.
637
 *
638
 * @return void
639
 */
640
function lsx_health_plan_complete_button() {
641
	?>
642
	<div class="single-plan-inner-buttons">
643
		<form action="<?php the_permalink(); ?>" method="post" class="form-complete-day complete-plan-btn">
644
			<?php wp_nonce_field( 'complete', 'lsx-health-plan-actions' ); ?>
645
			<input type="hidden" name="lsx-health-plan-id" value="<?php echo esc_attr( get_the_ID() ); ?>" />
0 ignored issues
show
Bug introduced by
It seems like get_the_ID() can also be of type false; however, parameter $text of esc_attr() 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

645
			<input type="hidden" name="lsx-health-plan-id" value="<?php echo esc_attr( /** @scrutinizer ignore-type */ get_the_ID() ); ?>" />
Loading history...
646
			<button class="btn cta-btn" type="submit"><?php esc_html_e( 'Complete Day', 'lsx-health-plan' ); ?></button>
647
		</form>
648
		<?php lsx_health_plan_back_to_plan_button(); ?>
649
	</div>
650
	<?php
651
}
652
653
/**
654
 * Outputs the health plan unlock button.
655
 *
656
 * @return void
657
 */
658
function lsx_health_plan_unlock_button() {
659
	?>
660
	<div class="single-plan-inner-buttons">
661
		<form action="<?php the_permalink(); ?>" method="post" class="form-complete-day complete-plan-btn">
662
			<?php wp_nonce_field( 'unlock', 'lsx-health-plan-actions' ); ?>
663
			<input type="hidden" name="lsx-health-plan-id" value="<?php echo esc_attr( get_the_ID() ); ?>" />
0 ignored issues
show
Bug introduced by
It seems like get_the_ID() can also be of type false; however, parameter $text of esc_attr() 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

663
			<input type="hidden" name="lsx-health-plan-id" value="<?php echo esc_attr( /** @scrutinizer ignore-type */ get_the_ID() ); ?>" />
Loading history...
664
			<button class="btn secondary-btn" type="submit"><?php esc_html_e( 'Im not done!', 'lsx-health-plan' ); ?></button>
665
		</form>
666
		<?php lsx_health_plan_back_to_plan_button(); ?>
667
	</div>
668
	<?php
669
}
670
671
/**
672
 * Outputs the Single Plan Endpoint Tabs
673
 *
674
 * @param string $button
675
 * @return void
676
 */
677
function lsx_health_plan_single_nav() {
678
	$tab_template_path = apply_filters( 'lsx_health_plan_single_nav_path', LSX_HEALTH_PLAN_PATH . '/templates/single-plan-tabs.php' );
679
	if ( '' !== $tab_template_path ) {
680
		require $tab_template_path;
681
	}
682
}
683
684
/**
685
 * Outputs the Single Plan Tab based on the endpoint
686
 *
687
 * @param string $button
688
 * @return void
689
 */
690
function lsx_health_plan_single_tabs() {
691
	$endpoint = get_query_var( 'endpoint' );
692
	switch ( $endpoint ) {
693
		case 'meal':
694
			$tab_template_path = LSX_HEALTH_PLAN_PATH . '/templates/tab-content-meal.php';
695
			break;
696
697
		case 'recipes':
698
			$tab_template_path = LSX_HEALTH_PLAN_PATH . '/templates/tab-content-recipes.php';
699
			break;
700
701
		case 'workout':
702
			$tab_template_path = LSX_HEALTH_PLAN_PATH . '/templates/tab-content-workout.php';
703
			break;
704
705
		case 'warm-up':
706
			$tab_template_path = LSX_HEALTH_PLAN_PATH . '/templates/tab-content-warm-up.php';
707
			break;
708
709
		default:
710
			$tab_template_path = LSX_HEALTH_PLAN_PATH . '/templates/tab-content-plan.php';
711
			break;
712
	}
713
	$tab_template_path = apply_filters( 'lsx_health_plan_single_tab_path', $tab_template_path );
714
	if ( '' !== $tab_template_path ) {
715
		include $tab_template_path;
716
	}
717
}
718
719
/**
720
 * Outputs the recipe info on a table.
721
 *
722
 * @return void
723
 */
724
function lsx_health_plan_recipe_data() {
725
	include LSX_HEALTH_PLAN_PATH . '/templates/table-recipe-data.php';
726
}
727
728
/**
729
 * Outputs the recipe type.
730
 *
731
 * @return recipe_type
0 ignored issues
show
Bug introduced by
The type recipe_type was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
732
 */
733
function lsx_health_plan_recipe_type() {
734
	$term_obj_list = get_the_terms( get_the_ID(), 'recipe-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

734
	$term_obj_list = get_the_terms( /** @scrutinizer ignore-type */ get_the_ID(), 'recipe-type' );
Loading history...
735
	$recipe_type   = $term_obj_list[0]->name;
736
	if ( ! empty( $recipe_type ) ) {
737
		return $recipe_type;
738
	}
739
}
740
741
/**
742
 * Outputs the modal button and registers the video modal to show.
743
 *
744
 * @param int $m
745
 * @param array $group
746
 * @return void
747
 */
748
function lsx_health_plan_workout_video_play_button( $m, $group, $echo = true ) {
749
	$workout_video = '';
750
	$giphy         = '';
751
	$youtube       = '';
752
	if ( isset( $group['connected_videos'] ) && '' !== $group['connected_videos'] ) {
753
		$workout_video = esc_html( $group['connected_videos'] );
754
		$giphy         = get_post_meta( $workout_video, 'video_giphy_source', true );
0 ignored issues
show
Bug introduced by
$workout_video of type string is incompatible with the type integer expected by parameter $post_id of get_post_meta(). ( Ignorable by Annotation )

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

754
		$giphy         = get_post_meta( /** @scrutinizer ignore-type */ $workout_video, 'video_giphy_source', true );
Loading history...
755
		$youtube       = esc_url( get_post_meta( $workout_video, 'video_youtube_source', 1 ) );
756
		$content       = get_post_field( 'post_content', $workout_video );
0 ignored issues
show
Bug introduced by
$workout_video of type string is incompatible with the type WP_Post|integer expected by parameter $post of get_post_field(). ( Ignorable by Annotation )

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

756
		$content       = get_post_field( 'post_content', /** @scrutinizer ignore-type */ $workout_video );
Loading history...
757
		$play_button   = '<button data-toggle="modal" data-target="#workout-video-modal-' . $m . '"><span class="fa fa-play-circle"></span></button>';
758
759
		$modal_body = '';
760
		if ( ! empty( $giphy ) ) {
761
			$giphy      = \lsx_health_plan\functions\get_video_url( $giphy );
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $giphy is correct as get_video_url($giphy) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
762
			$modal_body = $giphy; // WPCS: XSS OK.
763
		} elseif ( ! empty( $youtube ) ) {
764
			$modal_body = wp_oembed_get( $youtube, array( // WPCS: XSS OK.
765
				'width' => 480,
766
			) );
767
		}
768
		$modal_body .= '<h5 class="modal-title title-lined">' . $group['name'] . '</h5>';
769
		$modal_body .= $content;
770
		\lsx_health_plan\functions\register_modal( 'workout-video-modal-' . $m, '', $modal_body );
771
772
		if ( true === $echo ) {
773
			echo wp_kses_post( $play_button );
774
		} else {
775
			return $play_button;
776
		}
777
	}
778
}
779
780
/**
781
 * Outputs the recipe description if it is included.
782
 *
783
 * @return void
784
 */
785
function lsx_health_plan_recipe_archive_description() {
786
	$description = '';
787
	if ( is_post_type_archive( 'recipe' ) ) {
788
		$description = \lsx_health_plan\functions\get_option( 'recipe_archive_description', '' );
789
	} elseif ( is_post_type_archive( 'exercise' ) ) {
790
		$description = \lsx_health_plan\functions\get_option( 'exercise_archive_description', '' );
791
	} elseif ( is_tax() ) {
792
		$description = get_the_archive_description();
793
	}
794
	if ( '' !== $description ) {
795
		?>
796
		<div class="lsx-hp-archive-description row">
797
			<div class="col-xs-12 description-wrapper"><?php echo wp_kses_post( $description ); ?></div>
798
		</div>
799
		<?php
800
	}
801
}
802
803
/**
804
 * Outputs the Single Plan Workout main content.
805
 *
806
 * @return void
807
 */
808
function lsx_health_plan_workout_main_content() {
809
	// Getting translated endpoint.
810
	$workout = \lsx_health_plan\functions\get_option( 'endpoint_workout', 'workout' );
811
812
	$connected_members = get_post_meta( get_the_ID(), ( $workout . '_connected_team_member' ), true );
0 ignored issues
show
Bug introduced by
It seems like get_the_ID() can also be of type false; however, parameter $post_id of get_post_meta() does only seem to accept 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

812
	$connected_members = get_post_meta( /** @scrutinizer ignore-type */ get_the_ID(), ( $workout . '_connected_team_member' ), true );
Loading history...
Bug introduced by
Are you sure $workout of type array|mixed can be used in concatenation? ( Ignorable by Annotation )

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

812
	$connected_members = get_post_meta( get_the_ID(), ( /** @scrutinizer ignore-type */ $workout . '_connected_team_member' ), true );
Loading history...
813
	$small_description = get_post_meta( get_the_ID(), ( $workout . '_short_description' ), true );
814
815
	$content = '';
816
	if ( get_the_content() || $connected_members ) {
817
		$content .= '<div class="set-box set content-box entry-content">';
818
		$content .= '<div class="the-content">';
819
		$content .= lsx_hp_member_connected( $connected_members, $workout );
0 ignored issues
show
Bug introduced by
Are you sure the usage of lsx_hp_member_connected(...cted_members, $workout) is correct as it seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
820
		$content .= '<span>' . $small_description . '</span>';
821
		$content .= '</div>';
822
		$content .= do_shortcode( '[lsx_health_plan_featured_tips_block]' );
823
		$content .= '</div>';
824
	}
825
	return $content;
826
}
827
828
/**
829
 * Outputs the Single Plan Workout main content.
830
 *
831
 * @return void
832
 */
833
function lsx_health_plan_meal_main_content() {
834
	// Getting translated endpoint.
835
	$meal = \lsx_health_plan\functions\get_option( 'endpoint_meal', 'meal' );
836
837
	$connected_members = get_post_meta( get_the_ID(), ( $meal . '_connected_team_member' ), true );
0 ignored issues
show
Bug introduced by
It seems like get_the_ID() can also be of type false; however, parameter $post_id of get_post_meta() does only seem to accept 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

837
	$connected_members = get_post_meta( /** @scrutinizer ignore-type */ get_the_ID(), ( $meal . '_connected_team_member' ), true );
Loading history...
Bug introduced by
Are you sure $meal of type array|mixed can be used in concatenation? ( Ignorable by Annotation )

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

837
	$connected_members = get_post_meta( get_the_ID(), ( /** @scrutinizer ignore-type */ $meal . '_connected_team_member' ), true );
Loading history...
838
	$small_description = get_post_meta( get_the_ID(), ( $meal . '_short_description' ), true );
839
840
	$content_meal = '';
841
	if ( $small_description || $connected_members ) {
842
		$content_meal .= '<div class="set-box set content-box entry-content">';
843
		$content_meal .= '<div class="the-content">';
844
		$content_meal .= lsx_hp_member_connected( $connected_members, $meal );
0 ignored issues
show
Bug introduced by
Are you sure the usage of lsx_hp_member_connected($connected_members, $meal) is correct as it seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
845
		$content_meal .= '<span>' . $small_description . '</span>';
846
		$content_meal .= '</div>';
847
		$content_meal .= do_shortcode( '[lsx_health_plan_featured_tips_block]' );
848
		$content_meal .= '</div>';
849
	}
850
	return $content_meal;
851
}
852
853
854
/**
855
 * Outputs the Single Plan Workout Tab based on the layout selected.
856
 *
857
 * @param  string $index
858
 * @return void
859
 */
860
function lsx_health_plan_workout_tab_content( $index = 1 ) {
861
	global $group_name,$shortcode_args;
862
	$group_name = 'workout_section_' . $index;
863
	if ( false !== \lsx_health_plan\functions\get_option( 'exercise_enabled', false ) ) {
864
		$layout = strtolower( \lsx_health_plan\functions\get_option( 'workout_tab_layout', 'table' ) );
0 ignored issues
show
Bug introduced by
It seems like get_option('workout_tab_layout', 'table') can also be of type array; however, parameter $str of strtolower() 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

864
		$layout = strtolower( /** @scrutinizer ignore-type */ \lsx_health_plan\functions\get_option( 'workout_tab_layout', 'table' ) );
Loading history...
865
866
		// Check for shortcode overrides.
867
		if ( null !== $shortcode_args && isset( $shortcode_args['layout'] ) ) {
868
			$layout = $shortcode_args['layout'];
869
		}
870
	} else {
871
		$layout = 'table';
872
	}
873
874
	switch ( $layout ) {
875
		case 'list':
876
			$tab_template_path = LSX_HEALTH_PLAN_PATH . 'templates/partials/workout-list.php';
877
			break;
878
879
		case 'grid':
880
			$tab_template_path = LSX_HEALTH_PLAN_PATH . 'templates/partials/workout-grid.php';
881
			break;
882
883
		case 'table':
884
			$tab_template_path = LSX_HEALTH_PLAN_PATH . 'templates/partials/workout-table.php';
885
			break;
886
	}
887
	$tab_template_path = apply_filters( 'lsx_health_plan_workout_tab_content_path', $tab_template_path );
888
	if ( '' !== $tab_template_path ) {
889
		include $tab_template_path;
890
	}
891
}
892
893
/**
894
 * This will detect and include the Workout sets loop.
895
 *
896
 * @return void
897
 */
898
function lsx_health_plan_workout_sets() {
899
	if ( is_singular( 'workout' ) ) {
900
		global $connected_workouts;
901
		$connected_workouts = array( get_the_ID() );
902
	}
903
	if ( is_singular( 'plan' ) ) {
904
905
		global $connected_workouts;
906
907
		$section_key  = get_query_var( 'section' );
908
		if ( '' !== $section && \lsx_health_plan\functions\plan\has_sections() ) {
909
			$section_info = \lsx_health_plan\functions\plan\get_section_info( $section_key );
910
			if ( isset( $section_info['connected_workouts'] ) && '' !== $section_info['connected_workouts'] ) {
911
912
				$connected_workouts = \lsx_health_plan\functions\prep_array( $section_info['connected_workouts'] );
913
			}
914
		}
915
	}
916
	$template_path = LSX_HEALTH_PLAN_PATH . 'templates/partials/workout-sets.php';
917
	$template_path = apply_filters( 'lsx_health_plan_workout_set_template_path', $template_path );
918
	if ( '' !== $template_path && ! empty( $template_path ) ) {
919
		include $template_path;
920
	}
921
}
922
923
/**
924
 * Outputs the recipes connected to the meal plan.
925
 *
926
 * @param array $args
927
 * @return void
928
 */
929
function lsx_hp_meal_plan_recipes( $args = array() ) {
930
	$defaults = array(
931
		'meal_id'   => false,
932
		'meal_time' => '',
933
		'modal'     => true,
934
	);
935
	$args     = wp_parse_args( $args, $defaults );
936
	// Looking for recipes.
937
	$connected_recipes = get_post_meta( $args['meal_id'], $args['meal_time'] . '_recipes', true );
938
	if ( ! empty( $connected_recipes ) ) {
939
		$query_args    = array(
940
			'orderby'   => 'date',
941
			'order'     => 'DESC',
942
			'post_type' => 'recipe',
943
			'post__in'  => $connected_recipes,
944
		);
945
		$recipes = new WP_Query( $query_args );
946
		?>
947
		<div class="recipes">
948
			<div class="row eating-row">
949
			<?php
950
			if ( $recipes->have_posts() ) {
951
				while ( $recipes->have_posts() ) {
952
					$recipes->the_post();
953
					if ( false !== $args['modal'] ) {
954
						\lsx_health_plan\functions\recipes\register_recipe_modal();
955
					}
956
					?>
957
					<div class="recipe-column">
958
						<a data-toggle="modal" data-target="#recipe-modal-<?php echo esc_attr( get_the_ID() ); ?>" href="#recipe-modal-<?php echo esc_attr( get_the_ID() ); ?>" class="recipe-box box-shadow">
0 ignored issues
show
Bug introduced by
It seems like get_the_ID() can also be of type false; however, parameter $text of esc_attr() 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

958
						<a data-toggle="modal" data-target="#recipe-modal-<?php echo esc_attr( /** @scrutinizer ignore-type */ get_the_ID() ); ?>" href="#recipe-modal-<?php echo esc_attr( get_the_ID() ); ?>" class="recipe-box box-shadow">
Loading history...
959
							<div class="recipe-feature-img">
960
								<?php
961
								$featured_image = get_the_post_thumbnail();
962
								if ( ! empty( $featured_image ) && '' !== $featured_image ) {
963
									the_post_thumbnail( 'lsx-thumbnail-square', array(
964
										'class' => 'aligncenter',
965
									) );
966
								} else {
967
									?>
968
									<img loading="lazy" src="<?php echo esc_attr( plugin_dir_url( __DIR__ ) . 'assets/images/placeholder.jpg' ); ?>">
969
									<?php
970
								}
971
								?>
972
							</div>
973
							<div class="recipe-content">
974
								<h3 class="recipe-title"><?php the_title(); ?></h3>
975
								<?php lsx_health_plan_recipe_data(); ?>
976
							</div>
977
						</a>
978
					</div>
979
				<?php
980
				}
981
			}
982
			wp_reset_postdata();
983
			?>
984
			</div>
985
		</div>
986
		<?php
987
988
	}
989
}
990
991
/**
992
 * Output the connected.
993
 */
994
function lsx_hp_recipe_plan_meta( $args = array() ) {
0 ignored issues
show
Unused Code introduced by
The parameter $args is not used and could be removed. ( Ignorable by Annotation )

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

994
function lsx_hp_recipe_plan_meta( /** @scrutinizer ignore-unused */ $args = array() ) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
995
	$defaults = array();
996
	$top_level_plans = array();
997
	// Get meals this exercise is connected to.
998
	$plans = get_post_meta( get_the_ID(), 'connected_plans', true );
0 ignored issues
show
Bug introduced by
It seems like get_the_ID() can also be of type false; however, parameter $post_id of get_post_meta() does only seem to accept 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

998
	$plans = get_post_meta( /** @scrutinizer ignore-type */ get_the_ID(), 'connected_plans', true );
Loading history...
999
	if ( ! empty( $plans ) ) {
1000
		$plan       = end( $plans );
0 ignored issues
show
Bug introduced by
It seems like $plans can also be of type string; however, parameter $array of end() does only seem to accept array, 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

1000
		$plan       = end( /** @scrutinizer ignore-type */ $plans );
Loading history...
1001
		$has_parent = wp_get_post_parent_id( $plan );
1002
		if ( 0 === $has_parent ) {
1003
			$top_level_plans[] = $plan;
1004
		} elseif ( false !== $top_level_plans ) {
0 ignored issues
show
introduced by
The condition false !== $top_level_plans is always true.
Loading history...
1005
			$top_level_plans[] = $has_parent;
1006
		}
1007
	}
1008
	if ( ! empty( $top_level_plans ) && ( '' !== $top_level_plans ) ) {
1009
		$top_level_plans = array_unique( $top_level_plans );
1010
		$top_level_plan  = end( $top_level_plans );
1011
		?>
1012
			<span class="recipe-type recipe-parent"><?php echo esc_html( get_the_title( $top_level_plan ) ); ?></span>
1013
		<?php
1014
	}
1015
}
1016
1017
/**
1018
 * Output the connected.
1019
 */
1020
function lsx_hp_exercise_plan_meta() {
1021
1022
	$top_level_plans = array();
1023
1024
	// Get workouts this exercise is connected to.
1025
	$workouts = get_post_meta( get_the_ID(), 'connected_workouts', true );
0 ignored issues
show
Bug introduced by
It seems like get_the_ID() can also be of type false; however, parameter $post_id of get_post_meta() does only seem to accept 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

1025
	$workouts = get_post_meta( /** @scrutinizer ignore-type */ get_the_ID(), 'connected_workouts', true );
Loading history...
1026
1027
	if ( '' !== $workouts && ! is_array( $workouts ) ) {
1028
		$workouts = array( $workouts );
1029
	}
1030
	if ( ! empty( $workouts ) ) {
1031
		foreach ( $workouts as $workout ) {
1032
			// Get the plans this workout is connected to.
1033
			$plans = get_post_meta( $workout, 'connected_plans', true );
1034
1035
			if ( '' !== $plans && ! is_array( $plans ) ) {
1036
				$plans = array( $plans );
1037
			}
1038
			if ( ! empty( $plans ) ) {
1039
				foreach ( $plans as $plan ) {
1040
					$has_parent = wp_get_post_parent_id( $plan );
1041
					if ( 0 === $has_parent ) {
1042
						$top_level_plans = $plan;
1043
					} else {
1044
						$top_level_plans = $has_parent;
1045
					}
1046
				}
1047
			}
1048
		}
1049
	}
1050
1051
	if ( ! empty( $top_level_plans ) && ( '' !== $top_level_plans ) ) {
1052
		$top_level_plans = array_unique( $top_level_plans );
1053
		$top_level_plan  = end( $top_level_plans );
1054
		?>
1055
			<span class="recipe-type recipe-parent"><?php echo esc_html( get_the_title( $top_level_plan ) ); ?></span>
1056
		<?php
1057
	}
1058
}
1059
1060
/**
1061
 * Template for related content box for all singles.
1062
 *
1063
 * @param [type] $related_content
0 ignored issues
show
Documentation Bug introduced by
The doc comment [type] at position 0 could not be parsed: Unknown type name '[' at position 0 in [type].
Loading history...
1064
 * @return void
1065
 */
1066
function lsx_hp_single_related( $related_content, $post_type_text ) {
1067
	?>
1068
	<section id="lsx-hp-related">
1069
		<div class="row lsx-related-posts lsx-related-posts-title">
1070
			<div class="col-xs-12">
1071
				<h2 class="lsx-related-posts-headline"><?php echo esc_html( $post_type_text ); ?></h2>
1072
			</div>
1073
		</div>
1074
		<div class="row lsx-related-posts lsx-related-posts-content">
1075
			<div class="col-xs-12">
1076
				<div class="lsx-related-posts-wrapper">
1077
					<?php
1078
					foreach ( $related_content as $article ) {
1079
						$post_title      = get_the_title( $article );
1080
						$post_categories = wp_get_post_categories( $article );
1081
						$post_link       = get_permalink( $article );
1082
1083
						$cats = array();
1084
						?>
1085
						<article id="post-<?php echo esc_html( $article ); ?>" class="lsx-slot post">
1086
							<div class="entry-layout lsx-hp-shadow">
1087
								<div class="entry-layout-content">
1088
									<header class="entry-header">
1089
										<div class="entry-image">
1090
											<a href="<?php echo esc_url( $post_link ); ?>" class="thumbnail">
0 ignored issues
show
Bug introduced by
It seems like $post_link can also be of type false; however, parameter $url of esc_url() 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

1090
											<a href="<?php echo esc_url( /** @scrutinizer ignore-type */ $post_link ); ?>" class="thumbnail">
Loading history...
1091
											<?php
1092
											$featured_image = get_the_post_thumbnail( $article, 'lsx-thumbnail-wide' );
1093
											if ( ! empty( $featured_image ) && '' !== $featured_image ) {
1094
												echo wp_kses_post( $featured_image );
1095
											} else {
1096
												?>
1097
												<img loading="lazy" class="placeholder" src="<?php echo esc_attr( plugin_dir_url( __FILE__ ) . '../assets/images/placeholder.jpg' ); ?>">
1098
												<?php
1099
											}
1100
											?>
1101
											</a>
1102
										</div>
1103
										<div class="entry-meta">
1104
										<?php
1105
										foreach ( $post_categories as $c ) {
1106
											$cat = get_category( $c );
1107
											/* Translators: %s: category name */
1108
											$cats[] = '<a href="' . esc_url( get_category_link( $cat->term_id ) ) . '" title="' . sprintf( esc_html__( 'Posts in %s', 'lsx-blog-customizer' ), $cat->name ) . '">' . $cat->name . '</a>';
0 ignored issues
show
Bug introduced by
The property name does not seem to exist on WP_Error.
Loading history...
Bug introduced by
The property term_id does not seem to exist on WP_Error.
Loading history...
1109
										}
1110
										if ( ! empty( $cats ) ) { ?>
1111
											<div class="post-categories"><span></span><?php echo wp_kses_post( implode( ', ', $cats ) ); ?></div>
1112
										<?php } ?>
1113
										</div>
1114
										<h2 class="entry-title">
1115
											<a href="<?php echo esc_url( $post_link ); ?>">
1116
												<?php echo esc_html( $post_title ); ?>
1117
											</a>
1118
										</h2>
1119
									</header>
1120
								</div>
1121
							</div>
1122
						</article>
1123
1124
					<?php } ?>
1125
				</div>
1126
			</div>
1127
		</div>
1128
	</section>
1129
	<?php
1130
}
1131
1132
/**
1133
 * Template for connected members.
1134
 *
1135
 * @param [type] $connected_members
0 ignored issues
show
Documentation Bug introduced by
The doc comment [type] at position 0 could not be parsed: Unknown type name '[' at position 0 in [type].
Loading history...
1136
 * @return void
1137
 */
1138
function lsx_hp_member_connected( $connected_members, $post_type ) {
1139
	if ( ! empty( $connected_members ) ) {
1140
		$content = '<div id="hp-connected-members" class="hp-connected-members connected-' . $post_type . '">';
1141
		foreach ( $connected_members as $member ) {
1142
			$post_link   = get_permalink( $member );
1143
			$member_name = get_the_title( $member );
1144
			$member_name = '<span class="lsx-team-name">' . $member_name . '</span>';
1145
1146
			$member_link = '<a href="' . $post_link . '" >' . $member_name . '</a>';
0 ignored issues
show
Bug introduced by
Are you sure $post_link of type false|string can be used in concatenation? ( Ignorable by Annotation )

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

1146
			$member_link = '<a href="' . /** @scrutinizer ignore-type */ $post_link . '" >' . $member_name . '</a>';
Loading history...
1147
1148
			$roles = '';
1149
			$terms = get_the_terms( $member, 'team_role' );
1150
1151
			if ( $terms && ! is_wp_error( $terms ) ) {
1152
				$roles = array();
1153
1154
				foreach ( $terms as $term ) {
1155
					$roles[] = $term->name;
1156
				}
1157
1158
				$roles = join( ', ', $roles );
1159
			}
1160
			$member_roles = '' !== $roles ? "<small class='lsx-team-roles'>$roles</small>" : '';
1161
1162
			$content .= '<p>' . $member_roles . ': ' . $member_link . '</p>';
1163
		}
1164
		$content .= '</div>';
1165
		return $content;
1166
	}
1167
}
1168