Issues (617)

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

1
<?php
2
/**
3
 * LSX_TO_Vehicles_Admin
4
 *
5
 * @package   LSX_TO_Vehicles_Admin
6
 * @author    LightSpeed
7
 * @license   GPL-3.0+
8
 * @link
9
 * @copyright 2016 LightSpeedDevelopment
10
 */
11
12
/**
13
 * Main plugin class.
14
 *
15
 * @package LSX_TO_Vehicles_Admin
16
 * @author  LightSpeed
17
 */
18
19
class LSX_TO_Vehicles_Admin extends LSX_TO_Vehicles {
20
21
	/**
22
	 * Constructor
23
	 */
24
	public function __construct() {
25
		add_action( 'init', array( $this, 'register_post_types' ) );
26
		add_filter( 'cmb_meta_boxes', array( $this, 'register_metaboxes' ) );
27
28
		//add_filter( 'lsx_get_post-types_configs', array( $this, 'post_type_config' ), 10, 1 );
0 ignored issues
show
Unused Code Comprehensibility introduced by
61% 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...
No space found before comment text; expected "// add_filter( 'lsx_get_post-types_configs', array( $this, 'post_type_config' ), 10, 1 );" but found "//add_filter( 'lsx_get_post-types_configs', array( $this, 'post_type_config' ), 10, 1 );"
Loading history...
29
		//add_filter( 'lsx_get_metaboxes_configs', array( $this, 'meta_box_config' ), 10, 1 );
0 ignored issues
show
No space found before comment text; expected "// add_filter( 'lsx_get_metaboxes_configs', array( $this, 'meta_box_config' ), 10, 1 );" but found "//add_filter( 'lsx_get_metaboxes_configs', array( $this, 'meta_box_config' ), 10, 1 );"
Loading history...
Inline comments must end in full-stops, exclamation marks, or question marks
Loading history...
30
31
		add_filter( 'lsx_to_destination_custom_fields', array( $this, 'custom_fields' ) );
32
		add_filter( 'lsx_to_tour_custom_fields', array( $this, 'custom_fields' ) );
33
		add_filter( 'lsx_to_accommodation_custom_fields', array( $this, 'custom_fields' ) );
34
		add_filter( 'lsx_to_team_custom_fields', array( $this, 'custom_fields' ) );
35
		add_filter( 'lsx_to_special_custom_fields', array( $this, 'custom_fields' ) );
36
		add_filter( 'lsx_to_activity_custom_fields', array( $this, 'custom_fields' ) );
37
	}
38
39
	/**
40
	 * Register the activity post type config
41
	 *
42
	 * @param  $objects
43
	 * @return   array
44
	 */
45
	public function post_type_config( $objects ) {
46
47
		foreach ( $this->post_types as $key => $label ) {
48
			if ( file_exists( LSX_TO_VEHICLES_PATH . 'includes/post-types/config-' . $key . '.php' ) ) {
49
				$objects[ $key ] = include LSX_TO_VEHICLES_PATH . 'includes/post-types/config-' . $key . '.php';
50
			}
51
		}
52
53
		return 	$objects;
54
	}
55
56
	/**
57
	 * Register the activity metabox config
58
	 *
59
	 * @param  $meta_boxes
60
	 * @return   array
61
	 */
62
	public function meta_box_config( $meta_boxes ) {
63
		foreach ( $this->post_types as $key => $label ) {
64
			if ( file_exists( LSX_TO_VEHICLES_PATH . 'includes/metaboxes/config-' . $key . '.php' ) ) {
65
				$meta_boxes[ $key ] = include LSX_TO_VEHICLES_PATH . 'includes/metaboxes/config-' . $key . '.php';
66
			}
67
		}
68
		return 	$meta_boxes;
69
	}
70
71
	/**
72
	 * Register the landing pages post type.
73
	 */
74
	public function register_post_types() {
75
76
		$labels = array(
77
			'name'               => _x( 'Vehicles', 'to-vehicles' ),
78
			'singular_name'      => _x( 'Vehicle', 'to-vehicles' ),
79
			'add_new'            => _x( 'Add New', 'to-vehicles' ),
80
			'add_new_item'       => _x( 'Add New Vehicle', 'to-vehicles' ),
81
			'edit_item'          => _x( 'Edit Vehicle', 'to-vehicles' ),
82
			'new_item'           => _x( 'New Vehicle', 'to-vehicles' ),
83
			'all_items'          => _x( 'Vehicles', 'to-vehicles' ),
84
			'view_item'          => _x( 'View Vehicle', 'to-vehicles' ),
85
			'search_items'       => _x( 'Search Vehicles', 'to-vehicles' ),
86
			'not_found'          => _x( 'No vehicles found', 'to-vehicles' ),
87
			'not_found_in_trash' => _x( 'No vehicles found in Trash', 'to-vehicles' ),
88
			'parent_item_colon'  => '',
89
			'menu_name'          => _x( 'Vehicles', 'to-vehicles' ),
90
		);
91
92
		$args = array(
93
			'menu_icon'          => 'dashicons-performance',
94
			'labels'             => $labels,
95
			'public'             => true,
96
			'publicly_queryable' => true,
97
			'show_ui'            => true,
98
			'show_in_menu'       => 'tour-operator',
99
			'menu_position'      => 80,
100
			'query_var'          => true,
101
			'rewrite'            => array(
102
				'slug' => 'vehicle',
103
			),
104
			'capability_type'    => 'post',
105
			'has_archive'        => 'vehicles',
106
			'hierarchical'       => true,
107
			'show_in_rest'       => true,
108
			'supports'           => array( 'title', 'editor', 'thumbnail', 'excerpt', 'custom-fields' ),
109
		);
110
111
		register_post_type( 'vehicle', $args );
112
113
	}
114
115
	function register_metaboxes( array $meta_boxes ) {
116
117
		$fields[] = array(
118
			'id'   => 'title',
119
			'name' => 'General',
120
			'type' => 'title',
121
		);
122
		$fields[] = array(
123
			'id'   => 'featured',
124
			'name' => 'Featured',
125
			'type' => 'checkbox',
126
		);
127
		if ( ! class_exists( 'LSX_Banners' ) ) {
128
			$fields[] = array(
129
				'id'   => 'tagline',
130
				'name' => 'Tagline',
131
				'type' => 'text',
132
			);
133
		}
134
		$fields[] = array(
135
			'id'   => 'code',
136
			'name' => 'Code',
137
			'type' => 'text',
138
		);
139
		$fields[] = array(
140
			'id'      => 'gearbox',
141
			'name'    => 'Gearbox Type',
142
			'type'    => 'radio',
143
			'options' => array(
144
				'Automatic' => 'Automatic',
145
				'Manual'    => 'Manual',
146
			),
147
		);
148
		$fields[] = array(
149
			'id'      => 'gears',
150
			'name'    => 'Gears',
151
			'type'    => 'radio',
152
			'options' => array(
153
				'4',
154
				'5',
155
				'6',
156
				'7',
157
			),
158
		);
159
		$fields[] = array(
160
			'id'   => 'vehicle_type',
161
			'name' => 'Vehicle Type',
162
			'type' => 'text',
163
		);
164
		$fields[] = array(
165
			'id'   => 'price',
166
			'name' => 'Price Guide',
167
			'type' => 'text',
168
		);
169
		$fields[] = array(
170
			'id'      => 'engine_type',
171
			'name'    => 'Engine Type',
172
			'type'    => 'radio',
173
			'options' => array(
174
				'Diesel' => 'Diesel',
175
				'Petrol' => 'Petrol',
176
			),
177
		);
178
		$fields[] = array(
179
			'id'   => 'engine_size',
180
			'name' => 'Engine Size',
181
			'type' => 'text',
182
		);
183
		$fields[] = array(
184
			'id'   => 'seating',
185
			'name' => 'Seats',
186
			'type' => 'text',
187
		);
188
		$fields[] = array(
189
			'id'      => 'features',
190
			'name'    => 'Features',
191
			'type'    => 'wysiwyg',
192
			'options' => array(
193
				'editor_height' => '100',
194
			),
195
		);
196
		$fields[] = array(
197
			'id'   => 'gallery_title',
198
			'name' => 'Gallery',
199
			'type' => 'title',
200
		);
201
202
		//Galleries Block
203
		$fields[] = array(
204
			'id'   => 'gallery_title',
205
			'name' => esc_html__( 'Gallery', 'tour-operator' ),
206
			'type' => 'title',
207
		);
208
		$fields[] = array(
209
			'id'                  => 'gallery',
210
			'name'                => '',
211
			'type'                => 'image',
212
			'repeatable'          => true,
213
			'show_size'           => false,
214
			'sortable'            => true,
215
			'string-repeat-field' => esc_html__( 'Add new image', 'tour-operator' ),
216
		);
217
		if ( class_exists( 'Envira_Gallery' ) ) {
218
			$fields[] = array(
219
				'id'   => 'envira_title',
220
				'name' => esc_html__( 'Envira Gallery', 'tour-operator' ),
221
				'type' => 'title',
222
			);
223
			$fields[] = array(
224
				'id'         => 'envira_gallery',
225
				'name'       => esc_html__( 'Envira Gallery', 'to-galleries' ),
226
				'type'       => 'post_select',
227
				'use_ajax'   => false,
228
				'query'      => array(
229
					'post_type'      => 'envira',
230
					'nopagin'        => true,
231
					'posts_per_page' => '-1',
232
					'orderby'        => 'title',
233
					'order'          => 'ASC',
234
				),
235
				'allow_none' => true,
236
			);
237
			if ( class_exists( 'Envira_Videos' ) ) {
238
				$fields[] = array(
239
					'id'         => 'envira_video',
240
					'name'       => esc_html__( 'Envira Video Gallery', 'to-galleries' ),
241
					'type'       => 'post_select',
242
					'use_ajax'   => false,
243
					'query'      => array(
244
						'post_type'      => 'envira',
245
						'nopagin'        => true,
246
						'posts_per_page' => '-1',
247
						'orderby'        => 'title',
248
						'order'          => 'ASC',
249
					),
250
					'allow_none' => true,
251
				);
252
			}
253
		}
254
255
		if ( class_exists( 'LSX_Field_Pattern' ) ) {
256
			$fields = array_merge( $fields, LSX_Field_Pattern::videos() );
257
		}
258
259
		$fields[] = array(
260
			'id'   => 'accommodation_title',
261
			'name' => 'Accommodation',
262
			'type' => 'title',
263
		);
264
		$fields[] = array(
265
			'id'         => 'accommodation_to_vehicle',
266
			'name'       => 'Accommodations related with this vehicle',
267
			'type'       => 'post_select',
268
			'use_ajax'   => false,
269
			'query'      => array(
270
				'post_type'      => 'accommodation',
271
				'nopagin'        => true,
272
				'posts_per_page' => 1000,
273
				'orderby'        => 'title',
274
				'order'          => 'ASC',
275
			),
276
			'repeatable' => true,
277
			'sortable'   => true,
278
			'allow_none' => true,
279
		);
280
		$fields[] = array(
281
			'id'   => 'activity_title',
282
			'name' => 'Activities',
283
			'type' => 'title',
284
		);
285
		$fields[] = array(
286
			'id'         => 'activity_to_vehicle',
287
			'name'       => 'Activities related with this vehicle',
288
			'type'       => 'post_select',
289
			'use_ajax'   => false,
290
			'query'      => array(
291
				'post_type'      => 'activity',
292
				'nopagin'        => true,
293
				'posts_per_page' => 1000,
294
				'orderby'        => 'title',
295
				'order'          => 'ASC',
296
			),
297
			'repeatable' => true,
298
			'sortable'   => true,
299
			'allow_none' => true,
300
		);
301
		$fields[] = array(
302
			'id'   => 'destinations_title',
303
			'name' => 'Destinations',
304
			'type' => 'title',
305
		);
306
		$fields[] = array(
307
			'id'         => 'destination_to_vehicle',
308
			'name'       => 'Destinations related with this vehicle',
309
			'type'       => 'post_select',
310
			'use_ajax'   => false,
311
			'query'      => array(
312
				'post_type'      => 'destination',
313
				'nopagin'        => true,
314
				'posts_per_page' => 1000,
315
				'orderby'        => 'title',
316
				'order'          => 'ASC',
317
			),
318
			'repeatable' => true,
319
			'sortable'   => true,
320
			'allow_none' => true,
321
		);
322
		$fields[] = array(
323
			'id'   => 'review_title',
324
			'name' => 'Reviews',
325
			'type' => 'title',
326
		);
327
		$fields[] = array(
328
			'id'         => 'review_to_vehicle',
329
			'name'       => 'Reviews related with this vehicle',
330
			'type'       => 'post_select',
331
			'use_ajax'   => false,
332
			'query'      => array(
333
				'post_type'      => 'reviews',
334
				'nopagin'        => true,
335
				'posts_per_page' => 1000,
336
				'orderby'        => 'title',
337
				'order'          => 'ASC',
338
			),
339
			'repeatable' => true,
340
			'sortable'   => true,
341
			'allow_none' => true,
342
		);
343
		$fields[] = array(
344
			'id'   => 'specials_title',
345
			'name' => 'Specials',
346
			'type' => 'title',
347
		);
348
		$fields[] = array(
349
			'id'         => 'special_to_vehicle',
350
			'name'       => 'Specials related with this vehicle',
351
			'type'       => 'post_select',
352
			'use_ajax'   => false,
353
			'query'      => array(
354
				'post_type'      => 'special',
355
				'nopagin'        => true,
356
				'posts_per_page' => 1000,
357
				'orderby'        => 'title',
358
				'order'          => 'ASC',
359
			),
360
			'repeatable' => true,
361
			'sortable'   => true,
362
			'allow_none' => true,
363
		);
364
		$fields[] = array(
365
			'id'   => 'team_title',
366
			'name' => 'Team Members',
367
			'type' => 'title',
368
		);
369
		$fields[] = array(
370
			'id'         => 'team_to_vehicle',
371
			'name'       => 'Team members related with this vehicle',
372
			'type'       => 'post_select',
373
			'use_ajax'   => false,
374
			'query'      => array(
375
				'post_type'      => 'team',
376
				'nopagin'        => true,
377
				'posts_per_page' => 1000,
378
				'orderby'        => 'title',
379
				'order'          => 'ASC',
380
			),
381
			'repeatable' => true,
382
			'sortable'   => true,
383
			'allow_none' => true,
384
		);
385
		$fields[] = array(
386
			'id'   => 'tours_title',
387
			'name' => 'Tours',
388
			'type' => 'title',
389
		);
390
		$fields[] = array(
391
			'id'         => 'tour_to_vehicle',
392
			'name'       => 'Tours related with this vehicle',
393
			'type'       => 'post_select',
394
			'use_ajax'   => false,
395
			'query'      => array(
396
				'post_type'      => 'tour',
397
				'nopagin'        => true,
398
				'posts_per_page' => 1000,
399
				'orderby'        => 'title',
400
				'order'          => 'ASC',
401
			),
402
			'repeatable' => true,
403
			'sortable'   => true,
404
			'allow_none' => true,
405
		);
406
407
		$fields = apply_filters( 'lsx_to_vehicle_custom_fields', $fields );
408
409
		$meta_boxes[] = array(
410
			'title'  => 'Tour Operator Plugin',
411
			'pages'  => 'vehicle',
412
			'fields' => $fields,
413
		);
414
		return $meta_boxes;
415
416
	}
417
418
	/**
419
	 * Adds in the gallery fields to the Tour Operators Post Types.
420
	 */
421
	public function custom_fields( $fields ) {
422
		global $post, $typenow, $current_screen;
423
424
		$post_type = false;
425
		if ( $post && $post->post_type ) {
426
			$post_type = $post->post_type;
427
		} elseif ( $typenow ) {
428
			$post_type = $typenow;
429
		} elseif ( $current_screen && $current_screen->post_type ) {
430
			$post_type = $current_screen->post_type;
431
		} elseif ( isset( $_REQUEST['post_type'] ) ) {
432
			$post_type = sanitize_key( $_REQUEST['post_type'] );
433
		} elseif ( isset( $_REQUEST['post'] ) ) {
434
			$post_type = get_post_type( sanitize_key( $_REQUEST['post'] ) );
435
		}
436
		//$post_type = get_post_type();
437
		if ( false !== $post_type ) {
438
			$fields[]  = array(
439
				'id'   => 'vehicle_title',
440
				'name' => 'Vehicles',
441
				'type' => 'title',
442
				'cols' => 12,
443
			);
444
			$fields[]  = array(
445
				'id'         => 'vehicle_to_' . $post_type,
446
				'name'       => 'Vehicles related with this ' . $post_type,
447
				'type'       => 'post_select',
448
				'use_ajax'   => false,
449
				'query'      => array(
450
					'post_type'      => 'vehicle',
451
					'nopagin'        => true,
452
					'posts_per_page' => '-1',
453
					'orderby'        => 'title',
454
					'order'          => 'ASC',
455
				),
456
				'repeatable' => true,
457
				'allow_none' => true,
458
				'cols'       => 12,
459
			);
460
		}
461
		return $fields;
462
	}
463
}
464
new LSX_TO_Vehicles_Admin();
465