Adding more images to vehicles
First of all you need to understand that you need 2 kind of fields, 1 for the submission and 1 for saving the image. 1) Open file class-wp-auto-manager-form-submit-auto.php into the folder /wp-content/plugins/wp-autotrader/includes/forms/ 2) Locate the following snippet around line 405
'additional_image_5' => array( 'label' => __( 'Additional Image 5', 'auto_manager' ), 'type' => 'file', 'required' => $is_image5, 'placeholder' => '', 'priority' => 6 ),
3) Just after the snippet mentioned above, replicate the same code, change the id and paste it just after the snippet mentioned above (at line 411 press enter button once, and paste the code there) so, your new snippet will look like this, this will create a new field.
'my_additional_image_1' => array( 'label' => __( 'My Additional Image 1', 'auto_manager' ), 'type' => 'file', 'required' => false, 'placeholder' => '', 'priority' => 7 ),
4) Now we need to make sure that the field is processed correctly, in the same file locate this snippet
case 'additional_image_5' : $image_url = self::upload_image( 'additional_image_5' ); if ( $image_url ) $values[ $group_key ][ $key ] = $image_url; break;
5) After the snippet above, replicate the same code and make sure you use the same field ID, so replace the words "additional_image_5" with "my_additional_image_1" like i did in the example above when i created the new field. So your snippet will look like this
case 'my_additional_image_1' : $image_url = self::upload_image( 'my_additional_image_1' ); if ( $image_url ) $values[ $group_key ][ $key ] = $image_url; break;
6) Now we need to save the processed image into the database, in the same file locate this snippet
update_post_meta( self::$auto_id, 'additional_image_5', $values['media_fields']['additional_image_5'] );
7) Replicate the same code and again, change the ids "additional_image_5" with "my_additional_image_1", so your snippet will look like this, add this snippet just below the line mentioned above at step 6
update_post_meta( self::$auto_id, 'my_additional_image_1', $values['media_fields']['my_additional_image_1'] );
8) Save the file, in this way you've added a new field to the submission form, now we need to add a new field to the backend in the wp dashboard. 9) Open file options.php into folder /wp-content/themes/autodealer/framework/extensions/ 10) Locate this snippet here
array ( 'key' => 'field_5284d3d25e695', 'label' => 'Additional Image 5', 'name' => 'additional_image_5', 'type' => 'image', 'save_format' => 'url', 'preview_size' => 'thumbnail', 'library' => 'all', ),
11) Just below that snippet add this, and make sure you change name parameter with the same name of the field you created above, you also need to make sure you change the key parameter to something random (but unique), in this example i've just changed the last 3 numbers of the same snippet mentioned at step 10
array ( 'key' => 'field_5284d3d25e111', 'label' => 'Additional Image 5', 'name' => 'my_additional_image_1', 'type' => 'image', 'save_format' => 'url', 'preview_size' => 'thumbnail', 'library' => 'all', ),
12) Save the file, now the new image is saved and can also be seen into the admin panel. 13) Now you need to show the additional image into the gallery of the vehicle, open file vehicle-gallery.php in folder /templates/vehicles (of the autodealer theme folder) and locate this snippet
14) Replicate the same code and again and add it below the snippet mentioned above, change the ids to match the name of the field you created.
15) Now you can also add additional thumbnails, simply locate the snippet at line 193 of the original unmodified file, where you will see an unordered list tag (ul) with all the list items. Replicate the same code, and underneath the last list item, add your new thumbnail code like this
If you've done everything correctly you should be able to see a new field and save it correctly :D, you can use the process over and over again to add new fields to the submission form.