Plugin Directory

Changeset 1066808


Ignore:
Timestamp:
01/13/2015 09:13:45 AM (11 years ago)
Author:
dollar_dad
Message:

Changed contributors name to correct spelling

Location:
autostock/trunk
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • autostock/trunk/autostock.php

    r1059356 r1066808  
    3232// Plugin definitions.
    3333define( 'AUTO', 'autostock' );
     34define( '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 */
     39function 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}
     46register_activation_hook(__FILE__, __NAMESPACE__ . '\autostock_activation' );
    3447
    3548// include files
    3649function load_includes() {
    3750    include 'includes/Car_Post_Type.php';
     51
     52    // includes for admin pages only
     53    if ( is_admin() ) {
     54        include 'includes/admin_settings.php';
     55    }
    3856}
    3957add_action( 'init', __NAMESPACE__ .'\load_includes' );
    40 
  • autostock/trunk/includes/Car_Post_Type.php

    r1059356 r1066808  
    1010class Car_Post_Type {
    1111
     12    /**
     13     * Admin options
     14     * @var
     15     */
     16    private $options;
    1217    private $screen;
    1318
     19
    1420    /**
    1521     * Construct function for car post types.
    1622     */
    1723    public function __construct() {
     24
    1825        $this->register_post_type();
     26        $this->register_taxonomies();
    1927        add_filter( 'enter_title_here', array( $this, 'change_title_input' ) );
    2028        add_action( 'edit_form_after_title', array( $this, 'reorder_meta_box' ) );
    2129        add_action( 'admin_head', array( $this, 'remove_media_button' ) );
    2230        add_filter( 'gettext', array( $this, 'change_text' ) );
     31        add_action( 'save_post', array( $this, 'vehicle_details_save_meta_box' ) );
     32
    2333    }
    2434
     
    6777
    6878    /**
     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    /**
    69116     * 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.
    73118     */
    74119    public function register_meta_box() {
     120        // Options set in admin page
     121        $this->options = get_option( 'car_details_options' );
    75122
    76123        add_meta_box(
    77124            'stock_number_meta_box',
    78125            __( 'Vehicle Details', AUTO ),
    79             array( $this, 'render_vehicle_details_meta_box'),
     126            array( $this, 'render_vehicle_details_meta_box' ),
    80127            'cars',
    81128            'car_meta_box_position',
     
    100147     *
    101148     * @param $translation
    102      * @param null $original
    103149     *
    104150     * @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 ) {
    109157            return __( 'Sales Person' );
    110158        }
    111159
    112160        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 );
    118166            }
    119167        }
     168
    120169        return $translation;
    121170    }
     
    128177    public function render_vehicle_details_meta_box( $post ) {
    129178
    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
    143279
    144280    /**
    145281     * Function to change the title input field placeholder text
     282     *
    146283     * @param $title
    147284     *
     
    163300        global $post;
    164301
    165         if ( isset($post ) && 'cars' == $post->post_type ) {
     302        if ( isset( $post ) && 'cars' == $post->post_type ) {
    166303            remove_action( 'media_buttons', 'media_buttons' );
    167304        }
     
    170307}
    171308
    172 new Car_Post_Type();
     309new Car_Post_type();
  • autostock/trunk/readme.txt

    r1059370 r1066808  
    11=== Autostock ===
    22Contributors: dollar_dad
     3Donate link: http://kevinphillips.co.nz/plugin-support/
    34Tags:  auto dealer, automotive, car dealer, car lots, car sales
    45Requires at least: 4.1
    56Tested up to: 4.1
    6 Stable tag: 1.0.0
    7 License: GPLv2 or later
    8 License URI: http://www.gnu.org/licenses/gpl-2.0.html
     7Stable tag: 1.0.1
     8License: GPLv3 or later
     9License URI: http://www.gnu.org/licenses/gpl.html
    910
    1011AutoStock is a Plugin for car dealers, or developers/designers that build websites for clients that host car dealer websites.
     
    4950
    5051== Changelog ==
    51 
     521.0.1 Added settings options and taxonomy for makes and models
    5253
    5354== Upgrade Notice ==
Note: See TracChangeset for help on using the changeset viewer.