Issues (617)

classes/class-lsx-to-vehicles.php (6 issues)

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
 */
11
if ( ! class_exists( 'LSX_TO_Vehicles' ) ) {
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
		 */
23
		public $plugin_slug = 'to-vehicles';
24
25
		/**
26
		 * The post types the plugin registers
27
		 */
28
		public $post_types = false;
29
30
		/**
31
		 * The singular post types the plugin registers
32
		 */
33
		public $post_types_singular = false;
34
35
		/**
36
		 * An array of the post types slugs plugin registers
37
		 */
38
		public $post_type_slugs = false;
39
40
		/**
41
		 * The taxonomies the plugin registers
42
		 */
43
		public $taxonomies = false;
44
45
		/**
46
		 * The taxonomies the plugin registers (plural)
47
		 */
48
		public $taxonomies_plural = false;
49
50
		/**
51
		 * Constructor
52
		 */
53
		public function __construct() {
54
			//Set the variables
55
			$this->set_vars();
56
			$this->lsx_to_search_integration();
57
58
			// Make TO last plugin to load
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 ) {
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
			}
69
			if ( false !== $this->taxonomies ) {
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' );
75
			require_once( LSX_TO_VEHICLES_PATH . '/classes/class-lsx-to-vehicles-frontend.php' );
76
			require_once( LSX_TO_VEHICLES_PATH . '/includes/template-tags.php' );
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.

Loading history...
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
		}
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
		}
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
		}
97
98
		/**
99
		 * Sets the plugins variables
100
		 */
101
		public function set_vars() {
102
			$this->post_types = array(
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 );
109
		}
110
111
		/**
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 ignore-type  annotation

115
			if ( false !== $this->post_types && array_key_exists( $post_type, /** @scrutinizer ignore-type */ $this->post_types ) ) {
Loading history...
116
				$path = LSX_TO_VEHICLES_PATH;
117
			}
118
			return $path;
119
		}
120
121
		/**
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 ) ) {
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 ignore-type  annotation

126
				$post_types = array_merge( $post_types, /** @scrutinizer ignore-type */ $this->post_type_slugs );
Loading history...
127
			} else {
128
				$post_types = $this->post_type_slugs;
129
			}
130
			return $post_types;
131
		}
132
133
		/**
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 ) ) {
138
				$post_types = array_merge( $post_types, $this->post_types );
139
			} elseif ( is_array( $this->post_types ) ) {
140
				$post_types = $this->post_types;
141
			}
142
			return $post_types;
143
		}
144
145
		/**
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 ) ) {
150
				$post_types_singular = array_merge( $post_types_singular, $this->post_types_singular );
151
			} elseif ( is_array( $this->post_types_singular ) ) {
152
				$post_types_singular = $this->post_types_singular;
153
			}
154
			return $post_types_singular;
155
		}
156
157
		/**
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 ) ) {
162
				$taxonomies = array_merge( $taxonomies, $this->taxonomies );
163
			} elseif ( is_array( $this->taxonomies ) ) {
164
				$taxonomies = $this->taxonomies;
165
			}
166
			return $taxonomies;
167
		}
168
169
		/**
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 ) ) {
174
				$taxonomies_plural = array_merge( $taxonomies_plural, $this->taxonomies_plural );
175
			} elseif ( is_array( $this->taxonomies_plural ) ) {
176
				$taxonomies_plural = $this->taxonomies_plural;
177
			}
178
			return $taxonomies_plural;
179
		}
180
181
		/**
182
		 * Make TO last plugin to load.
183
		 */
184
		public function activated_plugin() {
185
			if ( get_option( 'active_plugins' ) === $plugins ) {
186
				$search = preg_grep( '/.*\/tour-operator\.php/', $plugins );
187
				$key = array_search( $search, $plugins );
188
189
				if ( is_array( $search ) && count( $search ) ) {
190
					foreach ( $search as $key => $path ) {
191
						array_splice( $plugins, $key, 1 );
192
						array_push( $plugins, $path );
193
						update_option( 'active_plugins', $plugins );
194
					}
195
				}
196
			}
197
		}
198
199
		/**
200
		 * On plugin activation
201
		 */
202
		public function register_activation_hook() {
203
			if ( ! is_network_admin() && ! isset( $_GET['activate-multi'] ) ) {
204
				set_transient( '_tour_operators_vehicles_flush_rewrite_rules', 1, 30 );
205
			}
206
		}
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' ) ) {
213
				return;
214
			}
215
216
			delete_transient( '_tour_operators_vehicles_flush_rewrite_rules' );
217
			flush_rewrite_rules();
218
		}
219
220
		/**
221
		 * Enabled banners for the additional post types
222
		 *
223
		 * @package    theme
224
		 * @subpackage setup
225
		 * @category   banners
226
		 *
227
		 * @param   $post_types array()
228
		 * @return  $post_types array()
0 ignored issues
show
Documentation Bug introduced by
The doc comment $post_types at position 0 could not be parsed: Unknown type name '$post_types' at position 0 in $post_types.
Loading history...
229
		 */
230
		function theme_allowed_post_type_banners( $post_types ) {
0 ignored issues
show
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
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 private, and only raise it to protected if a sub-class needs to have access, or public if an external class needs access.

Loading history...
231
			$post_types[] = 'summary';
232
			$post_types[] = 'gallery';
233
			$post_types[] = 'video';
234
			return $post_types;
235
		}
236
237
	}
238
	new LSX_TO_Vehicles();
239
}
240