PluginProbe
Auto Listings – Car Listings & Car Dealership Plugin for WordPress / trunk
Auto Listings – Car Listings & Car Dealership Plugin for WordPress vtrunk
trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.1.0 2.1.1 2.1.2 All 81 releases
auto-listings / src / Installer.php

Installer.php in Auto Listings – Car Listings & Car Dealership Plugin for WordPress trunk, at src/Installer.php

175 lines 6.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace AutoListings;
3
4 class Installer {
5 public function __construct( $file ) {
6 register_activation_hook( $file, [ $this, 'install' ] );
7 }
8
9 public function install() {
10 $this->install_plugin_options();
11 wp_insert_term( __( 'SUV', 'auto-listings' ), 'body-type' );
12 $this->install_listings_page();
13 $this->install_sample_listing();
14
15 // Create Auto_Listings roles.
16 $roles = new Roles();
17 $roles->add_roles();
18 $roles->add_caps();
19
20 flush_rewrite_rules( false );
21 }
22
23 private function install_plugin_options() {
24 $options = get_option( 'auto_listings_options' );
25 if ( ! empty( $options ) ) {
26 return;
27 }
28
29 $options = [];
30 $options['search_country'] = 'US';
31 $options['map_zoom'] = '14';
32 $options['map_height'] = '300';
33
34 $options['display_condition'] = [
35 'New',
36 'Used',
37 ];
38 $options['highlight_new_days'] = '3';
39 $options['highlight_new_color'] = '#5ba533';
40
41 $options['button_bg_color'] = '#337ab7';
42 $options['button_text_color'] = '#ffffff';
43 $options['price_color'] = '#337ab7';
44
45 $options['grid_columns'] = '3';
46 $options['listing_status'] = [
47 [
48 'status' => __( 'Low Miles', 'auto-listings' ),
49 'bg_color' => '#1e73be',
50 'text_color' => '#ffffff',
51 'icon' => 'auto-icon-odometer',
52 ],
53 [
54 'status' => __( 'Fuel Efficient', 'auto-listings' ),
55 'bg_color' => '#dd3333',
56 'text_color' => '#ffffff',
57 ],
58 ];
59 $options['listing_state'] = [
60 [
61 'state' => __( 'Sold', 'auto-listings' ),
62 'text_color' => '#1e73be',
63 'hide_price' => true,
64 ],
65 [
66 'state' => __( 'Reserved', 'auto-listings' ),
67 'text_color' => '#dd3333',
68 'hide_price' => true,
69 ],
70 ];
71 $options['field_display'] = [
72 'model_year',
73 'make_display',
74 'model_name',
75 'model_vehicle',
76 'model_seats',
77 'model_doors',
78 'model_drive',
79 'model_transmission_type',
80 'model_engine_fuel',
81 ];
82
83 update_option( 'auto_listings_options', $options );
84 }
85
86 private function install_listings_page() {
87 $options = get_option( 'auto_listings_options' );
88 if ( ! empty( $options['archives_page'] ) ) {
89 return;
90 }
91
92 $page_content = '[auto_listings_search style="1"]';
93 $page_data = [
94 'post_status' => 'publish',
95 'post_type' => 'page',
96 'post_title' => __( 'Listings', 'auto-listings' ),
97 'post_content' => $page_content,
98 'comment_status' => 'closed',
99 ];
100
101 // Search for an existing page with the specified page content (typically a shortcode).
102 global $wpdb;
103 $valid_page_found = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_content LIKE %s LIMIT 1;", "%{$page_content}%" ) );
104 if ( $valid_page_found ) {
105 $options['archives_page'] = $valid_page_found;
106 update_option( 'auto_listings_options', $options );
107 return;
108 }
109
110 $page_id = wp_insert_post( $page_data );
111
112 $options['archives_page'] = $page_id;
113 update_option( 'auto_listings_options', $options );
114 }
115
116 private function install_sample_listing() {
117 // Search for an existing page with the specified page content (typically a shortcode).
118 global $wpdb;
119 $listing_id = $wpdb->get_var( "SELECT ID FROM $wpdb->posts WHERE post_type='auto-listing' LIMIT 1" );
120 if ( $listing_id ) {
121 return;
122 }
123
124 $listing_title = __( 'My Sample Listing', 'auto-listings' );
125 $listing_data = [
126 'post_status' => 'publish',
127 'post_type' => 'auto-listing',
128 'post_title' => $listing_title,
129 'post_content' => '<p>Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt.</p><p>Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur.</p>',
130 'post_excerpt' => 'Tenetur error sunt deserunt minus nam.',
131 'comment_status' => 'closed',
132 ];
133 $listing_id = wp_insert_post( $listing_data );
134
135 $prefix = '_al_listing_';
136 $save_meta = [
137 $prefix . 'status' => __( 'Low Miles', 'auto-listings' ),
138 $prefix . 'price' => '21000',
139 $prefix . 'price_suffix' => '',
140 $prefix . 'odometer' => '22590',
141 $prefix . 'registration' => 'DKW-202',
142 $prefix . 'condition' => 'Used',
143 $prefix . 'displayed_address' => 'Miami Shore Parade, Miami QLD 4220',
144 $prefix . 'route' => 'Miami Shore Parade',
145 $prefix . 'city' => 'Miami',
146 $prefix . 'state' => 'Queensland',
147 $prefix . 'zip' => '4220',
148 $prefix . 'country' => 'Australia',
149 $prefix . 'lat' => '-28.0710877',
150 $prefix . 'lng' => '153.44109830000002',
151 $prefix . 'model_year' => '2017',
152 $prefix . 'make_display' => 'Jeep',
153 $prefix . 'model_name' => 'Cherokee',
154 $prefix . 'model_vehicle' => 'Latitude 4dr SUV (2.4L 4cyl 9A)',
155 $prefix . 'model_seats' => '7',
156 $prefix . 'model_doors' => '4',
157 $prefix . 'model_drive' => 'Front Wheel Drive',
158 $prefix . 'model_transmission_type' => 'Automatic',
159 $prefix . 'model_engine_fuel' => 'Regular Unleaded',
160 $prefix . 'model_engine_l' => '2.4',
161 $prefix . 'model_engine_type' => 'Inline',
162 $prefix . 'model_engine_cyl' => '4',
163 $prefix . 'make_country' => 'USA',
164 $prefix . 'seller' => get_current_user_id(),
165 ];
166
167 // Save values from created array into db.
168 foreach ( $save_meta as $meta_key => $meta_value ) {
169 update_post_meta( $listing_id, $meta_key, $meta_value );
170 }
171
172 wp_set_object_terms( $listing_id, 'suv', 'body-type' );
173 }
174 }
175