Issues (4138)

classes/frontend/class-general.php (69 issues)

1
<?php
0 ignored issues
show
This file is missing a doc comment.
Loading history...
2
namespace lsx_health_plan\classes\frontend;
3
4
/**
5
 * Holds the functions and actions which are shared accross the post types.
6
 *
7
 * @package lsx-health-plan
8
 */
9
class General {
10
11
	/**
12
	 * Holds class instance
13
	 *
14
	 * @since 1.0.0
15
	 *
16
	 * @var      object \lsx_health_plan\classes\frontend\General()
17
	 */
18
	protected static $instance = null;
19
20
	/**
21
	 * Constructor
22
	 */
23
	public function __construct() {
0 ignored issues
show
Expected 2 blank lines before function; 1 found
Loading history...
24
		// Before Output.
25
		add_action( 'wp_enqueue_scripts', array( $this, 'assets' ), 5 );
26
		add_filter( 'wp_kses_allowed_html', array( $this, 'allow_html_tags_attributes' ), 100, 2 );
27
28
		// Output.
29
		add_action( 'body_class', array( $this, 'body_classes' ) );
30
		add_filter( 'lsx_global_header_title',  array( $this, 'single_title' ), 200, 1 );
0 ignored issues
show
Expected 1 space after comma in argument list; 2 found
Loading history...
31
		add_action( 'wp_head', array( $this, 'remove_single_footer' ), 99 );
32
		add_filter( 'get_the_archive_title', array( $this, 'get_the_archive_title' ), 9 );
33
	}
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...
34
35
	/**
36
	 * Return an instance of this class.
37
	 *
38
	 * @since 1.0.0
39
	 *
40
	 * @return    object \lsx_health_plan\classes\frontend\General()    A single instance of this class.
41
	 */
42
	public static function get_instance() {
43
		// If the single instance hasn't been set, set it now.
44
		if ( null === self::$instance ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
45
			self::$instance = new self();
46
		}
0 ignored issues
show
No blank line found after control structure
Loading history...
47
		return self::$instance;
48
	}
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...
49
50
	/**
51
	 * Registers the plugin frontend assets
52
	 *
53
	 * @return void
54
	 */
55
	public function assets() {
0 ignored issues
show
Expected 0 blank lines after opening function brace; 1 found
Loading history...
56
57
		if ( is_post_type_archive( 'plan' ) && false === \lsx_health_plan\functions\plan\is_filters_disabled() ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
58
			wp_enqueue_script( 'isotope', LSX_HEALTH_PLAN_URL . 'assets/js/vendor/isotope.pkgd.min.js', array( 'jquery' ), null, LSX_HEALTH_PLAN_URL, true );
0 ignored issues
show
The call to wp_enqueue_script() has too many arguments starting with true. ( Ignorable by Annotation )

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

58
			/** @scrutinizer ignore-call */ 
59
   wp_enqueue_script( 'isotope', LSX_HEALTH_PLAN_URL . 'assets/js/vendor/isotope.pkgd.min.js', array( 'jquery' ), null, LSX_HEALTH_PLAN_URL, true );

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
Resource version not set in call to wp_enqueue_script(). This means new versions of the script will not always be loaded due to browser caching.
Loading history...
59
		}
60
61
		wp_enqueue_style( 'lsx-health-plan', LSX_HEALTH_PLAN_URL . 'assets/css/lsx-health-plan.css', array(), LSX_HEALTH_PLAN_VER );
62
		wp_style_add_data( 'lsx-health-plan', 'rtl', 'replace' );
63
		wp_enqueue_script( 'lsx-health-plan-scripts', LSX_HEALTH_PLAN_URL . 'assets/js/src/lsx-health-plan-admin.js', array( 'jquery' ) );
0 ignored issues
show
In footer ($in_footer) is not set explicitly wp_enqueue_script; It is recommended to load scripts in the footer. Please set this value to true to load it in the footer, or explicitly false if it should be loaded in the header.
Loading history...
Resource version not set in call to wp_enqueue_script(). This means new versions of the script will not always be loaded due to browser caching.
Loading history...
64
65
	}
0 ignored issues
show
Expected 2 blank lines after function; 1 found
Loading history...
66
67
	/**
0 ignored issues
show
Coding Style Documentation introduced by
Doc comment for parameter "$tags" missing
Loading history...
Coding Style Documentation introduced by
Doc comment for parameter "$context" missing
Loading history...
68
	 * Adds the iframe and the progress HTML tags to the allowed WordPress list.
69
	 */
70
	public function allow_html_tags_attributes( $tags, $context ) {
71
		if ( 'post' === $context ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
72
			$tags['iframe'] = array(
73
				'src'             => true,
74
				'height'          => true,
75
				'width'           => true,
76
				'frameborder'     => true,
77
				'allowfullscreen' => true,
78
			);
79
		}
0 ignored issues
show
No blank line found after control structure
Loading history...
80
		$tags['progress'] = array(
81
			'id'    => true,
82
			'value' => true,
83
			'max'   => true,
84
		);
85
		return $tags;
86
	}
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...
87
88
	/**
89
	 * Add body classes to body.
90
	 *
91
	 * @param array $classes
0 ignored issues
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
92
	 * @return void
0 ignored issues
show
Function return type is void, but function contains return statement
Loading history...
93
	 */
94
	public function body_classes( $classes = array() ) {
95
		global $post;
96
97
		if ( isset( $post->post_content ) && has_shortcode( $post->post_content, 'lsx_health_plan_my_profile_block' ) ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
98
			$classes[] = 'my-plan-shortcode';
99
		}
100
101
		if ( is_single() && is_singular( 'plan' ) ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
102
			$args = array(
103
				'post_parent' => get_the_ID(),
104
				'post_type'   => 'plan',
105
			);
106
107
			$post_id      = get_the_ID();
108
			$has_children = get_children( $args );
109
			$has_parent   = wp_get_post_parent_id( $post_id );
0 ignored issues
show
It seems like $post_id can also be of type false; however, parameter $post of wp_get_post_parent_id() does only seem to accept WP_Post|integer|null, 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

109
			$has_parent   = wp_get_post_parent_id( /** @scrutinizer ignore-type */ $post_id );
Loading history...
110
111
			if ( ! empty( $has_children ) ) {
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
				$plan_type_class = 'parent-plan-page';
113
				if ( 0 !== $has_parent ) {
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
					$plan_type_class = 'parent-sub-plan-page';
115
				}
116
			} else {
117
				$plan_type_class = 'unique-plan-page';
118
				if ( 0 !== $has_parent ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
119
					$plan_type_class = 'child-plan-page';
120
				}
121
			}
0 ignored issues
show
No blank line found after control structure
Loading history...
122
			$classes[] = $plan_type_class;
123
		}
0 ignored issues
show
No blank line found after control structure
Loading history...
124
		return $classes;
125
	}
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...
126
127
	/**
0 ignored issues
show
Coding Style Documentation introduced by
Doc comment for parameter "$title" missing
Loading history...
128
	 * Remove the single recipe and exercise title
129
	 */
130
	public function single_title( $title ) {
0 ignored issues
show
Expected 0 blank lines after opening function brace; 1 found
Loading history...
131
132
		if ( is_single() && is_singular( 'recipe' ) ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
Blank line found at start of control structure
Loading history...
133
134
			$title = __( 'Recipe', 'lsx-health-plan' );
135
		}
136
137
		if ( is_single() && is_singular( 'exercise' ) ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
Blank line found at start of control structure
Loading history...
138
139
			$title = __( 'Exercise', 'lsx-health-plan' );
140
		}
141
142
		return $title;
143
	}
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...
144
145
	/**
146
	 * Removing footer for HP single pages.
147
	 *
148
	 * @return void
149
	 */
150
	public function remove_single_footer() {
151
		if ( ( is_single() && is_singular( array( 'exercise', 'recipe', 'workout', 'meal' ) ) ) || ( is_archive() && is_post_type_archive( array( 'exercise', 'recipe', 'workout', 'meal' ) ) )) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
No space before closing parenthesis is prohibited
Loading history...
152
			remove_action( 'lsx_footer_before', 'lsx_add_footer_sidebar_area' );
153
		}
154
	}
0 ignored issues
show
Expected 2 blank lines after function; 0 found
Loading history...
Expected 1 blank line before closing function brace; 0 found
Loading history...
155
	/**
156
	 * Remove the "Archives:" from the post type recipes.
157
	 *
158
	 * @param string $title the term title.
159
	 * @return string
160
	 */
161
	public function get_the_archive_title( $title ) {
162
		if ( is_post_type_archive( 'recipe' ) ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
163
			$title = __( 'Recipes', 'lsx-health-plan' );
164
		}
0 ignored issues
show
No blank line found after control structure
Loading history...
165
		if ( is_post_type_archive( 'exercise' ) ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
166
			$title = __( 'Exercises', 'lsx-health-plan' );
167
		}
0 ignored issues
show
No blank line found after control structure
Loading history...
168
		if ( is_tax() ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
169
			$queried_object = get_queried_object();
170
			if ( isset( $queried_object->name ) ) {
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
				$title = $queried_object->name;
172
			}
173
		}
0 ignored issues
show
No blank line found after control structure
Loading history...
174
		return $title;
175
	}
0 ignored issues
show
Expected 2 blank lines after function; 0 found
Loading history...
Expected 1 blank line before closing function brace; 0 found
Loading history...
176
}
177