Issues (4138)

includes/functions.php (189 issues)

1
<?php
0 ignored issues
show
This file is missing a doc comment.
Loading history...
2
namespace lsx_health_plan\functions;
3
4
/**
5
 * LSX Health Plan functions.
6
 *
7
 * @package lsx-health-plan
8
 */
9
10
11
/**
12
 * Checks to see if the current item has connected values.
13
 *
14
 * @param string $post_id
0 ignored issues
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
Expected 2 spaces after parameter type; 1 found
Loading history...
15
 * @param string $meta_key
0 ignored issues
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
Expected 2 spaces after parameter type; 1 found
Loading history...
16
 * @param boolean $single
0 ignored issues
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
17
 * @return boolean
18
 */
19
function has_attached_post( $post_id = '', $meta_key = '', $single = true ) {
20
	$has_post = false;
21
	if ( '' === $post_id ) {
22
		$post_id = get_the_ID();
23
	}
0 ignored issues
show
No blank line found after control structure
Loading history...
24
	$items = get_post_meta( $post_id, $meta_key, $single );
0 ignored issues
show
It seems like $post_id can also be of type false and string; 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

24
	$items = get_post_meta( /** @scrutinizer ignore-type */ $post_id, $meta_key, $single );
Loading history...
25
	if ( '' !== $items && false !== $items && 0 !== $items ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
26
		if ( ! is_array( $items ) ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
27
			$items = array( $items );
28
		}
0 ignored issues
show
No blank line found after control structure
Loading history...
29
		$items = check_posts_exist( $items );
30
		if ( ! empty( $items ) ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
31
			$has_post = true;
32
		}
33
	} else {
34
		// Check for defaults.
35
		$options = get_option( 'all' );
36
		if ( isset( $options[ $meta_key ] ) && '' !== $options[ $meta_key ] && ! empty( $options[ $meta_key ] ) ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
37
			$has_post = true;
38
		}
39
	}
0 ignored issues
show
No blank line found after control structure
Loading history...
40
	return $has_post;
41
}
0 ignored issues
show
Expected 2 blank lines after function; 1 found
Loading history...
Expected 1 blank line before closing function brace; 0 found
Loading history...
42
43
/**
44
 * Wrapper function around cmb2_get_option
45
 * @since  0.1.0
0 ignored issues
show
There must be exactly one blank line before the tags in a doc comment
Loading history...
46
 * @param  string $key     Options array key
0 ignored issues
show
Coding Style Documentation introduced by
Parameter comment must end with a full stop
Loading history...
47
 * @param  mixed  $default Optional default value
0 ignored issues
show
Coding Style Documentation introduced by
Parameter comment must end with a full stop
Loading history...
48
 * @return mixed           Option value
49
 */
50
function get_option( $key = '', $default = false ) {
51
	if ( function_exists( 'cmb2_get_option' ) ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
52
		return cmb2_get_option( 'lsx_health_plan_options', $key, $default );
53
	}
0 ignored issues
show
No blank line found after control structure
Loading history...
54
	// Fallback to get_option if CMB2 is not loaded yet.
55
	$opts = \get_option( 'lsx_health_plan_options', $default );
56
	$val  = $default;
57
	if ( 'all' === $key ) {
58
		$val = $opts;
59
	} elseif ( is_array( $opts ) && array_key_exists( $key, $opts ) && false !== $opts[ $key ] ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
60
		$val = $opts[ $key ];
61
	}
0 ignored issues
show
No blank line found after control structure
Loading history...
62
	return $val;
63
}
0 ignored issues
show
Expected 2 blank lines after function; 1 found
Loading history...
Expected 1 blank line before closing function brace; 0 found
Loading history...
64
65
/**
66
 * Returns the downloads attached to the items
67
 * @since  0.1.0
0 ignored issues
show
There must be exactly one blank line before the tags in a doc comment
Loading history...
68
 * @param  string $key     Options array key
0 ignored issues
show
Doc comment for parameter $key does not match actual variable name $type
Loading history...
Coding Style Documentation introduced by
Parameter comment must end with a full stop
Loading history...
69
 * @param  mixed  $default Optional default value
0 ignored issues
show
Doc comment for parameter $default does not match actual variable name $post_id
Loading history...
Coding Style Documentation introduced by
Parameter comment must end with a full stop
Loading history...
70
 * @return mixed           Option value
71
 */
72
function get_downloads( $type = 'all', $post_id = '' ) {
73
	$lsx_health_plan = \lsx_health_plan();
74
	$post_types      = $lsx_health_plan->get_post_types();
75
	if ( '' === $post_id ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
76
		$post_id = get_the_ID();
77
	}
0 ignored issues
show
No blank line found after control structure
Loading history...
78
	$downloads = array();
79
	$options   = get_option( 'all' );
80
81
	foreach ( $post_types as $post_type ) {
82
		if ( 'all' === $type || in_array( $type, $post_types, true ) ) {
83
84
			// Get the default downloads for this post type.
85
			$default_downloads = array();
86
			$new_downloads     = array();
87
			if ( isset( $options[ 'download_' . $post_type ] ) ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
88
				if ( is_array( $options[ 'download_' . $post_type ] ) ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
89
					$default_downloads = $options[ 'download_' . $post_type ];
90
				} else {
91
					$default_downloads[] = $options[ 'download_' . $post_type ];
92
				}
93
			}
94
95
			if ( 'page' === $post_type ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
96
				$key = 'plan_warmup';
97
			} else {
98
				$key = 'connected_' . $post_type . 's';
99
			}
100
101
			$connected_items = get_post_meta( $post_id, $key, true );
102
			if ( ! empty( $connected_items ) ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
103
				foreach ( $connected_items as $connected_item ) {
104
					$current_downloads = get_post_meta( $connected_item, 'connected_downloads', true );
105
					if ( false !== $current_downloads && ! empty( $current_downloads ) ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
106
						$new_downloads = array_merge( $new_downloads, $current_downloads );
0 ignored issues
show
It seems like $current_downloads can also be of type string; however, parameter $arrays of array_merge() 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

106
						$new_downloads = array_merge( $new_downloads, /** @scrutinizer ignore-type */ $current_downloads );
Loading history...
107
					}
108
				}
109
			}
110
111
			if ( ! empty( $new_downloads ) ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
112
				$downloads = array_merge( $downloads, $new_downloads );
113
			} elseif ( ! empty( $default_downloads ) ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
114
				$downloads = array_merge( $downloads, $default_downloads );
115
			}
0 ignored issues
show
No blank line found after control structure
Loading history...
116
			$downloads = array_unique( $downloads );
117
		}
118
	}
0 ignored issues
show
No blank line found after control structure
Loading history...
119
	$downloads = check_posts_exist( $downloads );
120
	return $downloads;
121
}
0 ignored issues
show
Expected 2 blank lines after function; 1 found
Loading history...
Expected 1 blank line before closing function brace; 0 found
Loading history...
122
123
/**
124
 * Returns the weekly downloads for the week name
125
 *
126
 * @param  string $week    Week name 'week-1'.
127
 * @return array           an array of the downloads or empty.
128
 */
129
function get_weekly_downloads( $week = '' ) {
130
	$downloads = array();
131
	if ( '' !== $week ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
132
		$saved_downloads = get_transient( 'lsx_hp_weekly_downloads_' . $week );
133
		if ( false !== $saved_downloads && ! empty( $saved_downloads ) ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
134
			$downloads = $saved_downloads;
135
		} else {
136
			$args = array(
0 ignored issues
show
Equals sign not aligned with surrounding assignments; expected 11 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
137
				'orderby'        => 'title',
138
				'order'          => 'ASC',
139
				'post_type'      => 'dlm_download',
140
				'posts_per_page' => -1,
141
				'nopagin'        => true,
142
				'fields'         => 'ids',
143
				'tax_query'      => array(
0 ignored issues
show
Detected usage of tax_query, possible slow query.
Loading history...
144
					array(
145
						'taxonomy' => 'dlm_download_category',
146
						'field'    => 'slug',
147
						'terms'    => array( $week ),
148
					),
149
				),
150
			);
151
			$download_query = new \WP_Query( $args );
152
			if ( $download_query->have_posts() ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
153
				$downloads = $download_query->posts;
154
			}
155
		}
156
	}
0 ignored issues
show
No blank line found after control structure
Loading history...
157
	$downloads = check_posts_exist( $downloads );
158
	return $downloads;
159
}
0 ignored issues
show
Expected 2 blank lines after function; 1 found
Loading history...
Expected 1 blank line before closing function brace; 0 found
Loading history...
160
161
/**
162
 * Checks to see if the downloads exist before adding them
163
 *
164
 * @param array $post_ids
0 ignored issues
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
165
 * @return void
0 ignored issues
show
Function return type is void, but function contains return statement
Loading history...
166
 */
167
function check_posts_exist( $post_ids = array() ) {
168
	$new_ids = array();
169
	global $wpdb;
170
	if ( is_array( $post_ids ) && ! empty( $post_ids ) ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
171
		$post_ids = "'" . implode( "','", $post_ids ) . "'";
172
		$query    = "
173
			SELECT `ID` 
174
			FROM `{$wpdb->posts}`
175
			WHERE `ID` IN ({$post_ids})
176
			AND `post_status` != 'trash'
177
		";
178
		$results = $wpdb->get_results( $query ); // WPCS: unprepared SQL
0 ignored issues
show
Equals sign not aligned with surrounding assignments; expected 2 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
Usage of a direct database call is discouraged.
Loading history...
Direct database call without caching detected. Consider using wp_cache_get() / wp_cache_set() or wp_cache_delete().
Loading history...
Inline comments must end in full-stops, exclamation marks, or question marks
Loading history...
Using the WPCS native whitelist comments is deprecated. Please use the PHPCS native "phpcs:ignore Standard.Category.SniffName.ErrorCode" annotations instead. Found: // WPCS: unprepared SQL
Loading history...
179
		if ( ! empty( $results ) ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
180
			$new_ids = wp_list_pluck( $results, 'ID' );
181
		}
182
	}
0 ignored issues
show
No blank line found after control structure
Loading history...
183
	return $new_ids;
184
}
0 ignored issues
show
Expected 2 blank lines after function; 1 found
Loading history...
Expected 1 blank line before closing function brace; 0 found
Loading history...
185
186
/**
187
 * Registered the modal to be outputted
188
 *
189
 * @param string $id
0 ignored issues
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
190
 * @param string $title
0 ignored issues
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
191
 * @param string $body
0 ignored issues
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
192
 * @return void
193
 */
194
function register_modal( $id = '', $title = '', $body = '' ) {
195
	lsx_health_plan()->frontend->modals->register_modal(
196
		array(
197
			'title' => $title,
198
			'body'  => $body,
199
		),
200
		$id
201
	);
202
}
0 ignored issues
show
Expected 2 blank lines after function; 1 found
Loading history...
Expected 1 blank line before closing function brace; 0 found
Loading history...
203
204
/**
205
 * Outputs the modal HTML
206
 *
207
 * @param array $args
0 ignored issues
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
208
 * @return void
209
 */
210
function output_modal( $args = array() ) {
211
	$defaults = array(
212
		'id'    => '',
213
		'title' => '',
214
		'body'  => '',
215
	);
216
	$args     = wp_parse_args( $args, $defaults );
217
	?>
218
	<!-- Modal -->
219
	<div class="modal fade lsx-health-plan-modal" id="<?php echo esc_html( $args['id'] ); ?>" tabindex="-1" role="dialog" aria-labelledby="<?php echo esc_html( $args['id'] ); ?>"  aria-hidden="true">
220
		<div class="modal-dialog" role="document">
221
			<div class="modal-content">
222
			<button type="button" class="close" data-dismiss="modal">&times;</button>			
223
				<div class="modal-header">
224
					<?php
225
					if ( '' !== $args['title'] ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
226
						echo wp_kses_post( '<h2>' . $args['title'] . '</h2>' );
227
					}
228
					?>
229
				</div>
230
				<div class="modal-body">
231
				<?php
232
				if ( '' !== $args['body'] ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
233
					$allowed_html = array(
234
						'iframe' => array(
235
							'data-src'        => array(),
236
							'src'             => array(),
237
							'width'           => array(),
238
							'height'          => array(),
239
							'frameBorder'     => array( '0' ),
240
							'class'           => array(),
241
							'allowFullScreen' => array(),
242
							'style'           => array(),
243
						),
244
						'h5'     => array(
245
							'class' => array(),
246
						),
247
					);
248
					if ( false !== \lsx_health_plan\functions\get_option( 'exercise_enabled', false ) ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
249
						echo wp_kses_post( $args['body'] );
250
					} else {
251
						echo wp_kses( $args['body'], $allowed_html );
252
					}
253
				}
254
				?>
255
				</div>
256
			</div>
257
		</div>
258
	</div>
259
	<!-- End Modal -->
260
	<?php
261
}
0 ignored issues
show
Expected 2 blank lines after function; 1 found
Loading history...
Expected 1 blank line before closing function brace; 0 found
Loading history...
262
263
/**
264
 * Gets the src attribute from an iframe embed.
265
 *
266
 * @param [type] $embed
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...
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
267
 * @return void
0 ignored issues
show
Function return type is void, but function contains return statement
Loading history...
268
 */
269
function get_video_url( $embed ) {
270
	$url = '';
271
	if ( false !== stripos( $embed, '<iframe' ) ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
272
		preg_match( '/src="([^"]+)"/', $embed, $match );
273
		if ( is_array( $match ) && isset( $match[1] ) ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
274
			$url = '<iframe data-src="' . $match[1] . '" style="border: 0;" frameBorder="0" class="giphy-embed" allowFullScreen height="300" width="100%"></iframe>';
275
		} else {
276
			$url = $embed;
277
		}
278
	} else {
279
		$url = $embed;
280
	}
0 ignored issues
show
No blank line found after control structure
Loading history...
281
	return $url;
282
}
0 ignored issues
show
Expected 2 blank lines after function; 1 found
Loading history...
Expected 1 blank line before closing function brace; 0 found
Loading history...
283
284
/**
0 ignored issues
show
Coding Style Documentation introduced by
Doc comment for parameter "$section_keys" missing
Loading history...
Coding Style Documentation introduced by
Doc comment for parameter "$group_title" missing
Loading history...
285
 * Takes the Week ID and sees if it is complete
286
 *
287
 * @param boolean $term_id
0 ignored issues
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
288
 * @param array $post_ids
0 ignored issues
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
Expected 3 spaces after parameter type; 1 found
Loading history...
Doc comment for parameter $post_ids does not match actual variable name $section_keys
Loading history...
289
 * @return boolean
290
 */
291
function is_week_complete( $term_id = false, $section_keys = array(), $group_title = '' ) {
292
	$return = false;
293
	if ( ! empty( $section_keys ) ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
294
		$group_count = count( $section_keys );
295
		foreach ( $section_keys as &$pid ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
296
			$pid = 'day_' . \lsx_health_plan\functions\plan\generate_section_id( $pid ) . '_complete';
297
		}
0 ignored issues
show
No blank line found after control structure
Loading history...
298
		$days_complete = get_meta_amounts( $section_keys );
299
		if ( (int) $group_count === (int) $days_complete ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
300
			$return = true;
301
		}
302
	}
0 ignored issues
show
No blank line found after control structure
Loading history...
303
	return $return;
304
}
0 ignored issues
show
Expected 2 blank lines after function; 1 found
Loading history...
Expected 1 blank line before closing function brace; 0 found
Loading history...
305
306
/**
0 ignored issues
show
Coding Style Documentation introduced by
Doc comment for parameter "$post_ids" missing
Loading history...
307
 * Gets the values straight from the DB
308
 *
309
 * @param integer $week
0 ignored issues
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
Doc comment for parameter $week does not match actual variable name $post_ids
Loading history...
310
 * @param string $key
0 ignored issues
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
Expected 2 spaces after parameter type; 1 found
Loading history...
Superfluous parameter comment
Loading history...
311
 * @return void
312
 */
313
function get_meta_amounts( $post_ids = array() ) {
314
	global $wpdb;
315
	$amount       = 0;
316
	$current_user = wp_get_current_user();
317
	if ( false !== $current_user && ! empty( $post_ids ) ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
318
		$post_ids = "'" . implode( "','", $post_ids ) . "'";
319
		$query    = "
320
			SELECT COUNT(`meta_value`) 
321
			FROM `{$wpdb->usermeta}`
322
			WHERE `meta_key` IN ({$post_ids})
323
			AND `user_id` = '{$current_user->ID}'
324
		";
325
		$results  = $wpdb->get_var( $query ); // WPCS: unprepared SQL
326
		if ( ! empty( $results ) ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
327
			$amount = $results;
328
		}
329
	}
0 ignored issues
show
No blank line found after control structure
Loading history...
330
	return $amount;
331
}
0 ignored issues
show
Expected 2 blank lines after function; 1 found
Loading history...
Expected 1 blank line before closing function brace; 0 found
Loading history...
332
333
/**
334
 * Get the taxonomy plans type meta.
335
 *
336
 * @param [type] $post
337
 * @return void
338
 */
339
function hp_get_plan_type_meta( $post ) {
340
	$plan_meta = '';
341
342
	$term_obj_list = get_the_terms( $post->ID, 'plan-type' );
343
	if ( false !== $term_obj_list ) {
0 ignored issues
show
The condition false !== $term_obj_list is always false.
Loading history...
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
344
		$terms_string = '';
345
		$terms_ids    = wp_list_pluck( $term_obj_list, 'term_id' );
346
		
347
		foreach ( $term_obj_list as $term ) {
348
			$term_link = get_term_link( $term );
349
			$term_name = '<a href="' . $term_link . '">' .$term->name . '<span>, </span></a>';
350
			
351
			$terms_string .= $term_name;
352
		}
353
		
354
		foreach ( $terms_ids as $terms_id ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
355
			$term_thumbnail_id = get_term_meta( $terms_id, 'thumbnail', true );
356
			$img               = wp_get_attachment_image_src( $term_thumbnail_id, 'thumbnail' );
357
			if ( ! empty( $img ) ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
358
				$image_url = $img[0];
359
				$img       = '<img loading="lazy" alt="thumbnail" style="width:24px; height: auto;" class="attachment-responsive wp-post-image lsx-responsive" src="' . esc_url( $image_url ) . '" />';
360
			}
361
362
			$plan_meta .= $img;
363
		}
364
365
		$plan_meta = '<div class="plan-meta">' . $plan_meta . '<span>' . $terms_string . '</span></div>';
366
	}
367
368
	return $plan_meta;
369
}
370
371
/**
372
 * Limit media library access
373
 */
374
function set_only_author( $wp_query ) {
375
	global $current_user;
376
	if ( is_admin() && ! current_user_can( 'edit_others_posts' ) ) {
377
		$wp_query->set( 'administrator', $current_user->ID );
378
		add_filter( 'views_upload', 'fix_media_counts' );
379
	}
380
}
381
add_action( 'pre_get_posts', '\lsx_health_plan\functions\set_only_author' );
382
383
/**
384
 * Outputs an excerpt even if there is not excerpt.
385
 *
386
 * @param [type] $post_id
387
 * @return void
388
 */
389
function hp_excerpt( $post_id ) {
390
	if ( ! has_excerpt( $post_id ) ) {
391
		$content = wp_trim_words( get_post_field( 'post_content', $post_id ), 10 );
392
	} else {
393
		$content = get_the_excerpt( $post_id );
394
	}
395
	return $content;
396
}
397
398
/**
399
 * Get the columns class for bootstrap.
400
 *
401
 * @param string $columns
0 ignored issues
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
402
 * @return void
0 ignored issues
show
Function return type is void, but function contains return statement
Loading history...
403
 */
404
function column_class( $columns = '3' ) {
405
	$cols  = '';
406
	$cols .= '5' === $columns ? '15' : 12 / $columns;
407
	return $cols;
408
}
0 ignored issues
show
Expected 1 blank line before closing function brace; 0 found
Loading history...
Expected 2 blank lines after function; 1 found
Loading history...
409
410
/**
411
 * Gets the exercises by the workout ID.
412
 *
413
 * @param string $workout
0 ignored issues
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
414
 * @return void
0 ignored issues
show
Function return type is void, but function contains return statement
Loading history...
415
 */
416
function get_exercises_by_workout( $workout = '' ) {
417
	$exercises = array();
0 ignored issues
show
Equals sign not aligned with surrounding assignments; expected 7 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
418
	$i               = 1;
419
	$section_counter = 6;
420
	while ( $i <= $section_counter ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
421
		$group_name = 'workout_section_' . $i;
422
		$groups     = get_post_meta( $workout, $group_name, true );
0 ignored issues
show
$workout 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

422
		$groups     = get_post_meta( /** @scrutinizer ignore-type */ $workout, $group_name, true );
Loading history...
423
		if ( ! empty( $groups ) ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
424
			foreach ( $groups as $group ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
425
				if ( isset( $group['connected_exercises'] ) ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
426
					$exercises[] = $group['connected_exercises'];
427
				}
428
			}
429
		}
0 ignored issues
show
No blank line found after control structure
Loading history...
430
		$i++;
431
	}
0 ignored issues
show
No blank line found after control structure
Loading history...
432
	return $exercises;
433
}
0 ignored issues
show
Expected 1 blank line before closing function brace; 0 found
Loading history...
434
435
436
/**
437
 * Gets the current users progress on a plan.
438
 *
439
 * @param  int $plan_id
0 ignored issues
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
440
 * @return int
441
 */
442
function get_progress( $plan_id = false ) {
443
	$progress = 0;
444
	$complete = array();
445
	$count    = 0;
446
	if ( false !== $plan_id &&  \lsx_health_plan\functions\plan\has_sections( $plan_id ) ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 1 space after "&&"; 2 found
Loading history...
Expected 1 space after logical operator; 2 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
447
		$sections = \lsx_health_plan\functions\plan\get_sections();
0 ignored issues
show
Equals sign not aligned with surrounding assignments; expected 2 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
448
		$all_count = count( $sections );
449
		$rest_days = 0;
450
		foreach ( $sections as $section_key => $section_values ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
451
			if ( false !== $section_values['rest_day_enabled'] && ! $section_values['connected_meals'] ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
452
				$rest_days++;
453
			} else if ( lsx_health_plan_is_day_complete( $plan_id, $section_values['title'] ) ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
454
				$complete[] = true;
455
			}
456
		}
0 ignored issues
show
No blank line found after control structure
Loading history...
457
		$all_count = $all_count - $rest_days;
458
		$progress  = (int) count( $complete ) / (int) $all_count * 100;
459
	}
0 ignored issues
show
No blank line found after control structure
Loading history...
460
	return $progress;
461
}
0 ignored issues
show
Expected 2 blank lines after function; 3 found
Loading history...
Expected 1 blank line before closing function brace; 0 found
Loading history...
462
463
464
465
/**
466
 * Link to back to archive for taxonomy pages
467
 *
468
 * @return void
469
 */
470
function hp_back_archive_link() {
471
	global $wp_taxonomies;
472
	$post_type = get_queried_object()->taxonomy;
473
474
	if ( is_tax() && isset( $wp_taxonomies[ $post_type ] ) ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
475
		$post_type = $wp_taxonomies[ $post_type ]->object_type;
476
		?>
477
		<div class="archive-category-title hp-archive-category-title">
478
			<a class="back-to-blog" href="<?php echo ( esc_url( get_post_type_archive_link( $post_type[0] ) ) ); ?>"><?php echo esc_html__( 'Back To ', 'lsx' ) . esc_html( $post_type[0] ) . 's'; ?></a>
479
		</div>
480
		<?php
481
	}
482
}
483
add_action( 'lsx_content_wrap_before', '\lsx_health_plan\functions\hp_back_archive_link', 20 );
484
485
/**
486
 * Returns an array.
487
 *
488
 * @param  mixed $item
0 ignored issues
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
489
 * @return array
490
 */
491
function prep_array( $item ) {
0 ignored issues
show
Expected 2 blank lines before function; 1 found
Loading history...
492
	if ( ! is_array( $item ) ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
493
		$item = explode( ',', $item );
494
		if ( ! is_array( $item ) ) {
0 ignored issues
show
The condition is_array($item) is always true.
Loading history...
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
495
			$item = array( $item );
496
		}
497
	}
0 ignored issues
show
No blank line found after control structure
Loading history...
498
	return $item;
499
}
0 ignored issues
show
Expected 1 blank line before closing function brace; 0 found
Loading history...
500