1 | <?php |
||||||
0 ignored issues
–
show
Coding Style
introduced
by
![]() |
|||||||
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
|
|||||||
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
|
|||||||
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
|
|||||||
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
|
|||||||
45 | self::$instance = new self(); |
||||||
46 | } |
||||||
0 ignored issues
–
show
|
|||||||
47 | return self::$instance; |
||||||
48 | } |
||||||
0 ignored issues
–
show
|
|||||||
49 | |||||||
50 | /** |
||||||
51 | * Registers the plugin frontend assets |
||||||
52 | * |
||||||
53 | * @return void |
||||||
54 | */ |
||||||
55 | public function assets() { |
||||||
0 ignored issues
–
show
|
|||||||
56 | |||||||
57 | if ( is_post_type_archive( 'plan' ) && false === \lsx_health_plan\functions\plan\is_filters_disabled() ) { |
||||||
0 ignored issues
–
show
|
|||||||
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
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. ![]() |
|||||||
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
|
|||||||
64 | |||||||
65 | } |
||||||
0 ignored issues
–
show
|
|||||||
66 | |||||||
67 | /** |
||||||
0 ignored issues
–
show
|
|||||||
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
|
|||||||
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
|
|||||||
80 | $tags['progress'] = array( |
||||||
81 | 'id' => true, |
||||||
82 | 'value' => true, |
||||||
83 | 'max' => true, |
||||||
84 | ); |
||||||
85 | return $tags; |
||||||
86 | } |
||||||
0 ignored issues
–
show
|
|||||||
87 | |||||||
88 | /** |
||||||
89 | * Add body classes to body. |
||||||
90 | * |
||||||
91 | * @param array $classes |
||||||
0 ignored issues
–
show
|
|||||||
92 | * @return void |
||||||
0 ignored issues
–
show
|
|||||||
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
|
|||||||
98 | $classes[] = 'my-plan-shortcode'; |
||||||
99 | } |
||||||
100 | |||||||
101 | if ( is_single() && is_singular( 'plan' ) ) { |
||||||
0 ignored issues
–
show
|
|||||||
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
![]() |
|||||||
110 | |||||||
111 | if ( ! empty( $has_children ) ) { |
||||||
0 ignored issues
–
show
|
|||||||
112 | $plan_type_class = 'parent-plan-page'; |
||||||
113 | if ( 0 !== $has_parent ) { |
||||||
0 ignored issues
–
show
|
|||||||
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
|
|||||||
119 | $plan_type_class = 'child-plan-page'; |
||||||
120 | } |
||||||
121 | } |
||||||
0 ignored issues
–
show
|
|||||||
122 | $classes[] = $plan_type_class; |
||||||
123 | } |
||||||
0 ignored issues
–
show
|
|||||||
124 | return $classes; |
||||||
125 | } |
||||||
0 ignored issues
–
show
|
|||||||
126 | |||||||
127 | /** |
||||||
0 ignored issues
–
show
|
|||||||
128 | * Remove the single recipe and exercise title |
||||||
129 | */ |
||||||
130 | public function single_title( $title ) { |
||||||
0 ignored issues
–
show
|
|||||||
131 | |||||||
132 | if ( is_single() && is_singular( 'recipe' ) ) { |
||||||
0 ignored issues
–
show
|
|||||||
133 | |||||||
134 | $title = __( 'Recipe', 'lsx-health-plan' ); |
||||||
135 | } |
||||||
136 | |||||||
137 | if ( is_single() && is_singular( 'exercise' ) ) { |
||||||
0 ignored issues
–
show
|
|||||||
138 | |||||||
139 | $title = __( 'Exercise', 'lsx-health-plan' ); |
||||||
140 | } |
||||||
141 | |||||||
142 | return $title; |
||||||
143 | } |
||||||
0 ignored issues
–
show
|
|||||||
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
|
|||||||
152 | remove_action( 'lsx_footer_before', 'lsx_add_footer_sidebar_area' ); |
||||||
153 | } |
||||||
154 | } |
||||||
0 ignored issues
–
show
|
|||||||
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
|
|||||||
163 | $title = __( 'Recipes', 'lsx-health-plan' ); |
||||||
164 | } |
||||||
0 ignored issues
–
show
|
|||||||
165 | if ( is_post_type_archive( 'exercise' ) ) { |
||||||
0 ignored issues
–
show
|
|||||||
166 | $title = __( 'Exercises', 'lsx-health-plan' ); |
||||||
167 | } |
||||||
0 ignored issues
–
show
|
|||||||
168 | if ( is_tax() ) { |
||||||
0 ignored issues
–
show
|
|||||||
169 | $queried_object = get_queried_object(); |
||||||
170 | if ( isset( $queried_object->name ) ) { |
||||||
0 ignored issues
–
show
|
|||||||
171 | $title = $queried_object->name; |
||||||
172 | } |
||||||
173 | } |
||||||
0 ignored issues
–
show
|
|||||||
174 | return $title; |
||||||
175 | } |
||||||
0 ignored issues
–
show
|
|||||||
176 | } |
||||||
177 |