Changeset 1066808
- Timestamp:
- 01/13/2015 09:13:45 AM (11 years ago)
- Location:
- autostock/trunk
- Files:
-
- 1 added
- 3 edited
-
autostock.php (modified) (1 diff)
-
includes/Car_Post_Type.php (modified) (6 diffs)
-
includes/admin_settings.php (added)
-
readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
autostock/trunk/autostock.php
r1059356 r1066808 32 32 // Plugin definitions. 33 33 define( 'AUTO', 'autostock' ); 34 define( 'PHP_MIN_VERSION', '5.3.6' ); 35 36 /** 37 * Before we allow this plugin to be activated we must test the php version against the minimum requirements 38 */ 39 function autostock_activation() { 40 41 if (version_compare( PHP_MIN_VERSION, PHP_VERSION ) >= 0) { 42 wp_die('Sorry your php version is ' . PHP_VERSION . ' and you need a minimum of ' . PHP_MIN_VERSION ); 43 } 44 45 } 46 register_activation_hook(__FILE__, __NAMESPACE__ . '\autostock_activation' ); 34 47 35 48 // include files 36 49 function load_includes() { 37 50 include 'includes/Car_Post_Type.php'; 51 52 // includes for admin pages only 53 if ( is_admin() ) { 54 include 'includes/admin_settings.php'; 55 } 38 56 } 39 57 add_action( 'init', __NAMESPACE__ .'\load_includes' ); 40 -
autostock/trunk/includes/Car_Post_Type.php
r1059356 r1066808 10 10 class Car_Post_Type { 11 11 12 /** 13 * Admin options 14 * @var 15 */ 16 private $options; 12 17 private $screen; 13 18 19 14 20 /** 15 21 * Construct function for car post types. 16 22 */ 17 23 public function __construct() { 24 18 25 $this->register_post_type(); 26 $this->register_taxonomies(); 19 27 add_filter( 'enter_title_here', array( $this, 'change_title_input' ) ); 20 28 add_action( 'edit_form_after_title', array( $this, 'reorder_meta_box' ) ); 21 29 add_action( 'admin_head', array( $this, 'remove_media_button' ) ); 22 30 add_filter( 'gettext', array( $this, 'change_text' ) ); 31 add_action( 'save_post', array( $this, 'vehicle_details_save_meta_box' ) ); 32 23 33 } 24 34 … … 67 77 68 78 /** 79 * Function to create taxonomies for car post type 80 */ 81 public function register_taxonomies() { 82 83 $labels = array( 84 'name' => _x( 'Vehicle Makes and Models', 'taxonomy general name', AUTO ), 85 'singular' => _x( 'Make and Model', 'taxonomy singular name', AUTO ), 86 'search_items' => __( 'Search Makes/Models', AUTO ), 87 'all_items' => __( 'All Makes and Models', AUTO ), 88 'parent_item' => __( 'Parent Make and Model', AUTO ), 89 'parent_item_colon' => __( 'Parent Make and Model', AUTO ), 90 'edit_item' => __( 'Edit Make and Model', AUTO ), 91 'update_item' => __( 'update Make and Model', AUTO ), 92 'add_new_item' => __( 'Add New Make or Model', AUTO ), 93 'new_item_name' => __( 'New Make or Model', AUTO ), 94 'menu_name' => __( 'Makes and Models', AUTO ), 95 'popular_items' => __( 'Popular Makes and Models', AUTO ), 96 'not_found' => __( 'Make or Model not found', AUTO ) 97 ); 98 $args = array( 99 'hierarchical' => true, 100 'labels' => $labels, 101 'show_ui' => true, 102 'show_admin_column' => true, 103 'query_var' => true, 104 'rewrite' => array( 'slug', 'vehicle_makes_models' ), 105 'show_cloud' => true, 106 'show_admin_column' 107 ); 108 register_taxonomy( 109 'car_make_model', 110 'cars', 111 $args 112 ); 113 } 114 115 /** 69 116 * callback function for register_post_type to generate 70 * meta boxes for cars post type. 71 * 72 * @param $post 117 * meta boxes for cars post type. Possible required for others. 73 118 */ 74 119 public function register_meta_box() { 120 // Options set in admin page 121 $this->options = get_option( 'car_details_options' ); 75 122 76 123 add_meta_box( 77 124 'stock_number_meta_box', 78 125 __( 'Vehicle Details', AUTO ), 79 array( $this, 'render_vehicle_details_meta_box' ),126 array( $this, 'render_vehicle_details_meta_box' ), 80 127 'cars', 81 128 'car_meta_box_position', … … 100 147 * 101 148 * @param $translation 102 * @param null $original103 149 * 104 150 * @return string|void 105 */ 106 public function change_text( $translation, $original = null ) { 107 108 if ( 'Author' == $translation) { 151 * @internal param null $original 152 * 153 */ 154 public function change_text( $translation ) { 155 156 if ( 'Author' == $translation ) { 109 157 return __( 'Sales Person' ); 110 158 } 111 159 112 160 if ( 'Excerpt' == $translation ) { 113 return __( 'Short Description', AUTO );114 } else{115 $pos = strpos( $translation, 'Excerpts are optional hand-crafted summaries of your');116 if ( $pos !== false) {117 return __( 'Short Descriptions are powerful SEO elements.', AUTO );161 return __( 'Short Description', AUTO ); 162 } else { 163 $pos = strpos( $translation, 'Excerpts are optional hand-crafted summaries of your' ); 164 if ( $pos !== false ) { 165 return __( 'Short Descriptions are powerful SEO elements.', AUTO ); 118 166 } 119 167 } 168 120 169 return $translation; 121 170 } … … 128 177 public function render_vehicle_details_meta_box( $post ) { 129 178 130 echo '<p>' . __('Enter a unique stock number for this vehicle', AUTO) . '</p>'; 131 echo '<input type="text" id="stock_no" name="stock_number">'; 132 echo '<p>' . __('Enter the VIN for this vehicle', AUTO) . '</p>'; 133 echo '<input type="text" id="vin" name="vin">'; 134 echo '<p>' . __('Enter the chassis number for this vehicle', AUTO) . '</p>'; 135 echo '<input type="text" id="chassis" name="chassis">'; 136 137 138 } 139 140 public function register_taxonomies() { 141 142 } 179 wp_nonce_field( 'vehicle_details_meta_box', 'vehicle_details_nonce' ); 180 181 182 $value = get_post_meta( $post->ID, '_vehicle_details', true ); 183 184 echo '<p>' . __( 'Enter a unique stock number for this vehicle', AUTO ) . '</p>'; 185 $stock_no = isset( $value['stock_no'] ) ? esc_attr( $value['stock_no'] ) : ''; 186 echo '<input type="text" id="stock_no" name="stock_no" value="' . $stock_no . '">'; 187 188 echo '<p>' . __( 'You can optionally add a sub title here' ) . '</p>'; 189 $sub_title = isset( $value['sub_title'] ) ? esc_attr( $value['sub_title'] ) : ''; 190 echo '<input type="text" id="sub_title" name="sub_title" value="' . $sub_title . '">'; 191 192 echo '<p>' . __( 'Enter the VIN for this vehicle', AUTO ) . '</p>'; 193 $vin = isset( $value['vin'] ) ? esc_attr( $value['vin'] ) : ''; 194 echo '<input type="text" id="vin" name="vin" value="' . $vin . '">'; 195 196 echo '<p>' . __( 'Enter the chassis number for this vehicle', AUTO ) . '</p>'; 197 $chassis = isset( $value['chassis'] ) ? esc_attr( $value['chassis'] ) : ''; 198 echo '<input type="text" id="chassis" name="chassis" value="' . $chassis . '">'; 199 200 // lets use the oop way 201 202 // check to see if we have latest year 203 if ( $this->options['latest_year'] ) { 204 $latest_year = esc_attr( $this->options['latest_year'] ); 205 } else { 206 $latest_year = ( new \DateTime() )->format( 'Y' ); 207 } 208 if ( $this->options['earliest_year'] ) { 209 $earliest_year = esc_attr( $this->options['earliest_year'] ); 210 } else { 211 $earliest_year = $latest_year - 20; 212 } 213 214 echo '<p>' . __( 'Select vehicle year', AUTO ) . '</p>'; 215 echo '<select name="vehicle_year" id="vehicle_year">'; 216 /** @noinspection PhpExpressionResultUnusedInspection */ 217 for ( $latest_year; $latest_year >= $earliest_year; $latest_year -- ) { 218 echo '<option value="' . $latest_year . '" ' . selected( $value['vehicle_year'], $latest_year ) . '>' . $latest_year . '</option>'; 219 } 220 echo '</select>'; 221 222 $odometer_type = isset( $this->options['odometer'][0] ) ? esc_attr( $this->options['odometer'][0] ) : 'kilometres'; 223 224 echo '<p>' . __( ucfirst( $odometer_type ), AUTO ) . __( ' (use only digits)', AUTO ) . '</p>'; 225 $odometer = isset( $value['odometer'] ) ? esc_attr( $value['odometer'] ) : ''; 226 echo '<input type="text" name="odometer" id="odometer" value="' . $odometer . '" >'; 227 228 } 229 230 231 /** 232 * WordPress hook add_action on save post. 233 * 234 * @param $post_id 235 */ 236 public function vehicle_details_save_meta_box( $post_id ) { 237 238 // Check nonce is set 239 if ( ! isset( $_POST['vehicle_details_nonce'] ) ) { 240 return; 241 } 242 243 // Verify nonce 244 if ( ! wp_verify_nonce( $_POST['vehicle_details_nonce'], 'vehicle_details_meta_box' ) ) { 245 return; 246 } 247 248 // Check that this is not an autosave. 249 if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) { 250 return; 251 } 252 253 // Check user has permission to edit or create a car type 254 if ( ! current_user_can( 'edit_post', $post_id ) ) { 255 return; 256 } 257 258 // Should be safe to save the post meta. 259 // TODO probably a good idea to create some options as set fields compulsory. 260 261 // Sanitize data and put into an array. 262 $data = array(); 263 264 $data['stock_no'] = sanitize_text_field( $_POST['stock_no'] ); 265 $data['sub_title'] = sanitize_text_field( $_POST['sub_title'] ); 266 $data['vin'] = sanitize_text_field( $_POST['vin'] ); 267 268 $data['chassis'] = sanitize_text_field( $_POST['chassis'] ); 269 $data['vehicle_year'] = sanitize_text_field( $_POST['vehicle_year'] ); 270 $data['odometer'] = preg_replace( '/\D/', '', $_POST['odometer'] ); 271 272 // if the data array is not empty then save the meta data array. 273 if ( ! empty( $data ) ) { 274 update_post_meta( $post_id, '_vehicle_details', $data ); 275 } 276 277 } 278 143 279 144 280 /** 145 281 * Function to change the title input field placeholder text 282 * 146 283 * @param $title 147 284 * … … 163 300 global $post; 164 301 165 if ( isset( $post ) && 'cars' == $post->post_type ) {302 if ( isset( $post ) && 'cars' == $post->post_type ) { 166 303 remove_action( 'media_buttons', 'media_buttons' ); 167 304 } … … 170 307 } 171 308 172 new Car_Post_ Type();309 new Car_Post_type(); -
autostock/trunk/readme.txt
r1059370 r1066808 1 1 === Autostock === 2 2 Contributors: dollar_dad 3 Donate link: http://kevinphillips.co.nz/plugin-support/ 3 4 Tags: auto dealer, automotive, car dealer, car lots, car sales 4 5 Requires at least: 4.1 5 6 Tested up to: 4.1 6 Stable tag: 1.0. 07 License: GPLv 2or later8 License URI: http://www.gnu.org/licenses/gpl -2.0.html7 Stable tag: 1.0.1 8 License: GPLv3 or later 9 License URI: http://www.gnu.org/licenses/gpl.html 9 10 10 11 AutoStock is a Plugin for car dealers, or developers/designers that build websites for clients that host car dealer websites. … … 49 50 50 51 == Changelog == 51 52 1.0.1 Added settings options and taxonomy for makes and models 52 53 53 54 == Upgrade Notice ==
Note: See TracChangeset
for help on using the changeset viewer.