1 | <?php |
||||
2 | /** |
||||
3 | * LSX_TO_Vehicles |
||||
4 | * |
||||
5 | * @package LSX_TO_Vehicles |
||||
6 | * @author LightSpeed |
||||
7 | * @license GPL-3.0+ |
||||
8 | * @link |
||||
9 | * @copyright 2016 LightSpeedDevelopment |
||||
10 | */ |
||||
0 ignored issues
–
show
Coding Style
introduced
by
![]() |
|||||
11 | if ( ! class_exists( 'LSX_TO_Vehicles' ) ) { |
||||
0 ignored issues
–
show
|
|||||
12 | /** |
||||
13 | * Main plugin class. |
||||
14 | * |
||||
15 | * @package LSX_TO_Vehicles |
||||
16 | * @author LightSpeed |
||||
17 | */ |
||||
18 | class LSX_TO_Vehicles { |
||||
19 | |||||
20 | /** |
||||
21 | * The plugins id |
||||
22 | */ |
||||
0 ignored issues
–
show
|
|||||
23 | public $plugin_slug = 'to-vehicles'; |
||||
24 | |||||
25 | /** |
||||
26 | * The post types the plugin registers |
||||
27 | */ |
||||
0 ignored issues
–
show
|
|||||
28 | public $post_types = false; |
||||
29 | |||||
30 | /** |
||||
31 | * The singular post types the plugin registers |
||||
32 | */ |
||||
0 ignored issues
–
show
|
|||||
33 | public $post_types_singular = false; |
||||
34 | |||||
35 | /** |
||||
36 | * An array of the post types slugs plugin registers |
||||
37 | */ |
||||
0 ignored issues
–
show
|
|||||
38 | public $post_type_slugs = false; |
||||
39 | |||||
40 | /** |
||||
41 | * The taxonomies the plugin registers |
||||
42 | */ |
||||
0 ignored issues
–
show
|
|||||
43 | public $taxonomies = false; |
||||
44 | |||||
45 | /** |
||||
46 | * The taxonomies the plugin registers (plural) |
||||
47 | */ |
||||
0 ignored issues
–
show
|
|||||
48 | public $taxonomies_plural = false; |
||||
49 | |||||
50 | /** |
||||
51 | * Constructor |
||||
52 | */ |
||||
53 | public function __construct() { |
||||
0 ignored issues
–
show
|
|||||
54 | //Set the variables |
||||
0 ignored issues
–
show
|
|||||
55 | $this->set_vars(); |
||||
56 | $this->lsx_to_search_integration(); |
||||
57 | |||||
58 | // Make TO last plugin to load |
||||
0 ignored issues
–
show
|
|||||
59 | add_action( 'activated_plugin', array( $this, 'activated_plugin' ) ); |
||||
60 | |||||
61 | add_action( 'init', array( $this, 'load_plugin_textdomain' ) ); |
||||
62 | |||||
63 | if ( false !== $this->post_types ) { |
||||
0 ignored issues
–
show
|
|||||
64 | add_filter( 'lsx_to_framework_post_types', array( $this, 'post_types_filter' ) ); |
||||
65 | add_filter( 'lsx_to_post_types', array( $this, 'post_types_filter' ) ); |
||||
66 | add_filter( 'lsx_to_post_types_singular', array( $this, 'post_types_singular_filter' ) ); |
||||
67 | add_filter( 'lsx_to_settings_path', array( $this, 'plugin_path' ), 10, 2 ); |
||||
68 | } |
||||
0 ignored issues
–
show
|
|||||
69 | if ( false !== $this->taxonomies ) { |
||||
0 ignored issues
–
show
|
|||||
70 | add_filter( 'lsx_to_framework_taxonomies', array( $this, 'taxonomies_filter' ) ); |
||||
71 | add_filter( 'lsx_to_framework_taxonomies_plural', array( $this, 'taxonomies_plural_filter' ) ); |
||||
72 | } |
||||
73 | |||||
74 | require_once( LSX_TO_VEHICLES_PATH . '/classes/class-lsx-to-vehicles-admin.php' ); |
||||
0 ignored issues
–
show
|
|||||
75 | require_once( LSX_TO_VEHICLES_PATH . '/classes/class-lsx-to-vehicles-frontend.php' ); |
||||
0 ignored issues
–
show
|
|||||
76 | require_once( LSX_TO_VEHICLES_PATH . '/includes/template-tags.php' ); |
||||
0 ignored issues
–
show
|
|||||
77 | |||||
78 | // flush_rewrite_rules() |
||||
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
67% of this comment could be valid code. Did you maybe forget this after debugging?
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it. The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production. This check looks for comments that seem to be mostly valid code and reports them. ![]() |
|||||
79 | register_activation_hook( LSX_TO_VEHICLES_CORE, array( $this, 'register_activation_hook' ) ); |
||||
80 | add_action( 'admin_init', array( $this, 'register_activation_hook_check' ) ); |
||||
81 | } |
||||
0 ignored issues
–
show
|
|||||
82 | |||||
83 | /** |
||||
84 | * Include the post type for the search integration |
||||
85 | */ |
||||
86 | public function lsx_to_search_integration() { |
||||
87 | add_filter( 'lsx_to_search_post_types', array( $this, 'post_types_filter' ) ); |
||||
88 | add_filter( 'lsx_to_search_taxonomies', array( $this, 'taxonomies_filter' ) ); |
||||
89 | } |
||||
0 ignored issues
–
show
|
|||||
90 | |||||
91 | /** |
||||
92 | * Load the plugin text domain for translation. |
||||
93 | */ |
||||
94 | public function load_plugin_textdomain() { |
||||
95 | load_plugin_textdomain( 'to-vehicles', false, basename( LSX_TO_VEHICLES_PATH ) . '/languages' ); |
||||
96 | } |
||||
0 ignored issues
–
show
|
|||||
97 | |||||
98 | /** |
||||
99 | * Sets the plugins variables |
||||
100 | */ |
||||
101 | public function set_vars() { |
||||
102 | $this->post_types = array( |
||||
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 10 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. ![]() |
|||||
103 | 'vehicle' => __( 'Vehicles', 'to-vehicles' ), |
||||
104 | ); |
||||
105 | $this->post_types_singular = array( |
||||
106 | 'vehicle' => __( 'Vehicle', 'to-vehicles' ), |
||||
107 | ); |
||||
108 | $this->post_type_slugs = array_keys( $this->post_types ); |
||||
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 5 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. ![]() |
|||||
109 | } |
||||
0 ignored issues
–
show
|
|||||
110 | |||||
111 | /** |
||||
0 ignored issues
–
show
|
|||||
112 | * Adds our post types to an array via a filter |
||||
113 | */ |
||||
114 | public function plugin_path( $path, $post_type ) { |
||||
115 | if ( false !== $this->post_types && array_key_exists( $post_type, $this->post_types ) ) { |
||||
0 ignored issues
–
show
$this->post_types of type true is incompatible with the type ArrayObject|array expected by parameter $array of array_key_exists() .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
116 | $path = LSX_TO_VEHICLES_PATH; |
||||
117 | } |
||||
0 ignored issues
–
show
|
|||||
118 | return $path; |
||||
119 | } |
||||
0 ignored issues
–
show
|
|||||
120 | |||||
121 | /** |
||||
0 ignored issues
–
show
|
|||||
122 | * Adds our post types to an array via a filter |
||||
123 | */ |
||||
124 | public function post_types_slugs_filter( $post_types ) { |
||||
125 | if ( is_array( $post_types ) ) { |
||||
0 ignored issues
–
show
|
|||||
126 | $post_types = array_merge( $post_types, $this->post_type_slugs ); |
||||
0 ignored issues
–
show
$this->post_type_slugs of type boolean is incompatible with the type array expected by parameter $arrays of array_merge() .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
127 | } else { |
||||
128 | $post_types = $this->post_type_slugs; |
||||
129 | } |
||||
0 ignored issues
–
show
|
|||||
130 | return $post_types; |
||||
131 | } |
||||
0 ignored issues
–
show
|
|||||
132 | |||||
133 | /** |
||||
0 ignored issues
–
show
|
|||||
134 | * Adds our post types to an array via a filter |
||||
135 | */ |
||||
136 | public function post_types_filter( $post_types ) { |
||||
137 | if ( is_array( $post_types ) && is_array( $this->post_types ) ) { |
||||
0 ignored issues
–
show
|
|||||
138 | $post_types = array_merge( $post_types, $this->post_types ); |
||||
139 | } elseif ( is_array( $this->post_types ) ) { |
||||
0 ignored issues
–
show
|
|||||
140 | $post_types = $this->post_types; |
||||
141 | } |
||||
0 ignored issues
–
show
|
|||||
142 | return $post_types; |
||||
143 | } |
||||
0 ignored issues
–
show
|
|||||
144 | |||||
145 | /** |
||||
0 ignored issues
–
show
|
|||||
146 | * Adds our post types to an array via a filter |
||||
147 | */ |
||||
148 | public function post_types_singular_filter( $post_types_singular ) { |
||||
149 | if ( is_array( $post_types_singular ) && is_array( $this->post_types_singular ) ) { |
||||
0 ignored issues
–
show
|
|||||
150 | $post_types_singular = array_merge( $post_types_singular, $this->post_types_singular ); |
||||
151 | } elseif ( is_array( $this->post_types_singular ) ) { |
||||
0 ignored issues
–
show
|
|||||
152 | $post_types_singular = $this->post_types_singular; |
||||
153 | } |
||||
0 ignored issues
–
show
|
|||||
154 | return $post_types_singular; |
||||
155 | } |
||||
0 ignored issues
–
show
|
|||||
156 | |||||
157 | /** |
||||
0 ignored issues
–
show
|
|||||
158 | * Adds our taxonomies to an array via a filter |
||||
159 | */ |
||||
160 | public function taxonomies_filter( $taxonomies ) { |
||||
161 | if ( is_array( $taxonomies ) && is_array( $this->taxonomies ) ) { |
||||
0 ignored issues
–
show
|
|||||
162 | $taxonomies = array_merge( $taxonomies, $this->taxonomies ); |
||||
163 | } elseif ( is_array( $this->taxonomies ) ) { |
||||
0 ignored issues
–
show
|
|||||
164 | $taxonomies = $this->taxonomies; |
||||
165 | } |
||||
0 ignored issues
–
show
|
|||||
166 | return $taxonomies; |
||||
167 | } |
||||
0 ignored issues
–
show
|
|||||
168 | |||||
169 | /** |
||||
0 ignored issues
–
show
|
|||||
170 | * Adds our taxonomies_plural to an array via a filter |
||||
171 | */ |
||||
172 | public function taxonomies_plural_filter( $taxonomies_plural ) { |
||||
173 | if ( is_array( $taxonomies_plural ) && is_array( $this->taxonomies_plural ) ) { |
||||
0 ignored issues
–
show
|
|||||
174 | $taxonomies_plural = array_merge( $taxonomies_plural, $this->taxonomies_plural ); |
||||
175 | } elseif ( is_array( $this->taxonomies_plural ) ) { |
||||
0 ignored issues
–
show
|
|||||
176 | $taxonomies_plural = $this->taxonomies_plural; |
||||
177 | } |
||||
0 ignored issues
–
show
|
|||||
178 | return $taxonomies_plural; |
||||
179 | } |
||||
0 ignored issues
–
show
|
|||||
180 | |||||
181 | /** |
||||
182 | * Make TO last plugin to load. |
||||
183 | */ |
||||
184 | public function activated_plugin() { |
||||
185 | if ( get_option( 'active_plugins' ) === $plugins ) { |
||||
0 ignored issues
–
show
|
|||||
186 | $search = preg_grep( '/.*\/tour-operator\.php/', $plugins ); |
||||
187 | $key = array_search( $search, $plugins ); |
||||
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 4 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. ![]() |
|||||
188 | |||||
189 | if ( is_array( $search ) && count( $search ) ) { |
||||
0 ignored issues
–
show
|
|||||
190 | foreach ( $search as $key => $path ) { |
||||
0 ignored issues
–
show
|
|||||
191 | array_splice( $plugins, $key, 1 ); |
||||
192 | array_push( $plugins, $path ); |
||||
193 | update_option( 'active_plugins', $plugins ); |
||||
194 | } |
||||
195 | } |
||||
196 | } |
||||
197 | } |
||||
0 ignored issues
–
show
|
|||||
198 | |||||
199 | /** |
||||
200 | * On plugin activation |
||||
201 | */ |
||||
202 | public function register_activation_hook() { |
||||
203 | if ( ! is_network_admin() && ! isset( $_GET['activate-multi'] ) ) { |
||||
0 ignored issues
–
show
|
|||||
204 | set_transient( '_tour_operators_vehicles_flush_rewrite_rules', 1, 30 ); |
||||
205 | } |
||||
206 | } |
||||
0 ignored issues
–
show
|
|||||
207 | |||||
208 | /** |
||||
209 | * On plugin activation (check) |
||||
210 | */ |
||||
211 | public function register_activation_hook_check() { |
||||
212 | if ( ! get_transient( '_tour_operators_vehicles_flush_rewrite_rules' ) ) { |
||||
0 ignored issues
–
show
|
|||||
213 | return; |
||||
214 | } |
||||
215 | |||||
216 | delete_transient( '_tour_operators_vehicles_flush_rewrite_rules' ); |
||||
217 | flush_rewrite_rules(); |
||||
218 | } |
||||
0 ignored issues
–
show
|
|||||
219 | |||||
220 | /** |
||||
0 ignored issues
–
show
|
|||||
221 | * Enabled banners for the additional post types |
||||
222 | * |
||||
223 | * @package theme |
||||
224 | * @subpackage setup |
||||
225 | * @category banners |
||||
226 | * |
||||
227 | * @param $post_types array() |
||||
0 ignored issues
–
show
|
|||||
228 | * @return $post_types array() |
||||
0 ignored issues
–
show
|
|||||
229 | */ |
||||
230 | function theme_allowed_post_type_banners( $post_types ) { |
||||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
It is recommend to declare an explicit visibility for
theme_allowed_post_type_banners .
Generally, we recommend to declare visibility for all methods in your source code. This has the advantage of clearly communication to other developers, and also yourself, how this method should be consumed. If you are not sure which visibility to choose, it is a good idea to start with
the most restrictive visibility, and then raise visibility as needed, i.e.
start with ![]() |
|||||
231 | $post_types[] = 'summary'; |
||||
232 | $post_types[] = 'gallery'; |
||||
233 | $post_types[] = 'video'; |
||||
234 | return $post_types; |
||||
235 | } |
||||
0 ignored issues
–
show
|
|||||
236 | |||||
237 | } |
||||
238 | new LSX_TO_Vehicles(); |
||||
239 | } |
||||
240 |