Plugin Directory

Changeset 1363313


Ignore:
Timestamp:
03/03/2016 10:54:07 AM (10 years ago)
Author:
alexitsios
Message:

-- Newer version 0.1.5 upload

Location:
listings-post-type-enable
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • listings-post-type-enable/tags/0.1.0/trunk/README.md

    r887382 r1363313  
    2727= 0.1.0 =
    2828* First release.
     29
     30= 0.1.5 =
     31* Added address metabox
  • listings-post-type-enable/tags/0.1.0/trunk/listings.php

    r887382 r1363313  
    33Plugin Name: Listings Post Type Enable
    44Description: This is a theme - specific plugin for the Directory WordPress Theme, that creates a custom post type called 'Listings' that is obligatory for this theme to  function.It also registers a widget,thar returns recent listings.
    5 Version: 0.1.0
     5Version: 0.1.5
    66Author: Alex Itsios
    77Author URI: http://ketchupthemes.com
     
    127127function directory_recent_listings_widget_init() {
    128128    register_widget('ketchupthemes_Widget_Recent_Listings');
     129    register_widget('KetchupThemes_Listing_Category_Widget');
    129130}
    130131add_action('widgets_init', 'directory_recent_listings_widget_init');
     
    243244    }
    244245}
     246/*
     247 * Listing categories widgets
     248 */
     249
     250class KetchupThemes_Listing_Category_Widget extends WP_Widget
     251{
     252
     253    function __construct()
     254    {
     255        parent::__construct(
     256
     257            'directory_listings_category_widget',
     258
     259            __('Directory Listing Category', 'directory'),
     260
     261            array(
     262                'description' => __('Select a parent category and show its child categories with their links.',   'directory'),
     263            )
     264        );
     265    }
     266
     267    public function widget($args,
     268        $instance)
     269    {
     270
     271        $title = apply_filters('widget_title', $instance['title']);
     272        $taxonomy = 'listing-category';
     273        $parent_term_id = $instance['parent_term_id'];
     274
     275        echo $args['before_widget'];
     276
     277        if (!empty($title))
     278            echo $args['before_title'] . $title . $args['after_title'];
     279
     280        ob_start();
     281
     282        $parent_term = get_terms('listing-category',
     283            array('parent' => 0, 'include' => $parent_term_id, 'hide_empty' => false));
     284
     285        $term_args = array(
     286            'child_of' => $parent_term_id,
     287            'hide_empty' => false);
     288
     289        $terms = get_terms($taxonomy, $term_args);
     290        ?>
     291        <div class="category-list-container matchHeight">
     292            <?php foreach ($parent_term as $pt) { ?>
     293
     294            <h4 class="category-title"><a href="<?php echo esc_url(get_term_link($pt)); ?>"><?php echo $pt->name; ?></a></h4>
     295
     296            <?php } ?>
     297
     298            <ul class="category-list">
     299            <?php
     300                foreach ($terms as $t) {
     301                $term_link = get_term_link($t); ?>
     302
     303               <li><a href="<?php echo esc_url($term_link); ?>"> <?php echo $t->name;?></a> <span class="category-count">(<?php echo $t->count; ?>)</span></li>
     304            <?php  } ?>
     305
     306            </ul>
     307
     308        </div>
     309        <?php
     310        echo $args['after_widget'];
     311    }
     312
     313    public function form($instance)
     314    {
     315        if (isset($instance['title'])) {
     316            $title = $instance['title'];
     317        } else {
     318            $title = '';
     319        }
     320
     321        if(isset($instance['parent_term_id']) || $instance['parent_term_id'] != ''):
     322            $parent_term_id = $instance['parent_term_id'];
     323        else:
     324            $parent_term_id = '';
     325        endif;
     326
     327        ?>
     328
     329        <p>
     330            <label
     331                for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title: * You dont have to add a title !',
     332                    'directory');
     333                ?></label>
     334            <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>"
     335                   name="<?php echo $this->get_field_name('title'); ?>" type="text"
     336                   value="<?php echo esc_attr($title); ?>"/>
     337        </p>
     338
     339
     340        <?php $parent_terms = get_terms('listing-category', array('parent' => 0, 'hide_empty' => false)); ?>
     341        <p>
     342            <label
     343                for="<?php echo $this->get_field_id('parent_term_id'); ?>"><?php _e('Select a category:',
     344                    'directory');
     345                ?></label>
     346            <select name="<?php echo esc_attr( $this->get_field_name( 'parent_term_id' ) ); ?>" id="<?php echo esc_attr( $this->get_field_id( 'parent_term_id' ) ); ?>" class="widefat">
     347                <?php foreach($parent_terms as $pt): ?>
     348
     349                <option value="<?php echo $pt->term_id; ?>"<?php selected( $instance['parent_term_id'], $pt->term_id ); ?>><?php echo $pt->name; ?></option>
     350
     351                <?php endforeach; ?>
     352            </select>
     353        </p>
     354
     355
     356        <?php
     357    }
     358
     359    public function update($new_instance,
     360        $old_instance)
     361    {
     362        $instance = array();
     363        $instance['title'] = (!empty($new_instance['title'])) ? strip_tags($new_instance['title']) : '';
     364        $instance['parent_term_id'] = (!empty($new_instance['parent_term_id'])) ? strip_tags($new_instance['parent_term_id']) : '';
     365
     366        return $instance;
     367    }
     368}
     369
     370
     371
     372function ketchupthemes_add_listing_address_meta( $value ) {
     373    global $post;
     374
     375    $field = get_post_meta( $post->ID, $value, true );
     376    if ( ! empty( $field ) ) {
     377        return is_array( $field ) ? stripslashes_deep( $field ) : stripslashes( wp_kses_decode_entities( $field ) );
     378    } else {
     379        return false;
     380    }
     381}
     382
     383function add_listing_address_add_meta_box() {
     384    add_meta_box(
     385        'add_listing_address-add-listing-address',
     386        __( 'Add listing address', 'directory' ),
     387        'add_listing_address_html',
     388        'listing',
     389        'normal',
     390        'core'
     391    );
     392}
     393add_action( 'add_meta_boxes', 'add_listing_address_add_meta_box' );
     394
     395function add_listing_address_html( $post) {
     396    wp_nonce_field( '_add_listing_address_nonce', 'add_listing_address_nonce' ); ?>
     397
     398    <p><?php echo __('Please add it like this eg. 120 Hawthorn Ave
     399        Colchester, Essex CO4 3QF','directory'); ?></p>
     400
     401    <p>
     402    <label for="add_listing_address_listing_address"><?php _e( 'Listing Address', 'directory' ); ?></label><br>
     403    <input type="text" name="add_listing_address_listing_address" id="add_listing_address_listing_address" value="<?php echo ketchupthemes_add_listing_address_meta( 'add_listing_address_listing_address' ); ?>">
     404    </p><?php
     405}
     406
     407function add_listing_address_save( $post_id ) {
     408    if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return;
     409    if ( ! isset( $_POST['add_listing_address_nonce'] ) || ! wp_verify_nonce( $_POST['add_listing_address_nonce'], '_add_listing_address_nonce' ) ) return;
     410    if ( ! current_user_can( 'edit_post', $post_id ) ) return;
     411
     412    if ( isset( $_POST['add_listing_address_listing_address'] ) )
     413        update_post_meta( $post_id, 'add_listing_address_listing_address', esc_attr( $_POST['add_listing_address_listing_address'] ) );
     414}
     415add_action( 'save_post', 'add_listing_address_save' );
     416
     417/*
     418    Usage: ketchupthemes_add_listing_address_meta( 'add_listing_address_listing_address' )
     419*/
  • listings-post-type-enable/tags/0.1.0/trunk/readme.txt

    r887382 r1363313  
    33Tags: custom post type, listings post type, directory post type, custom widget
    44Requires at least: 3.0.1
    5 Tested up to: 3.8.1
     5Tested up to: 4.4.2
    66Stable tag: trunk
    77License: GPLv2 or later
    88License URI: http://www.gnu.org/licenses/gpl-2.0.html
    99
    10 A simple plugin that creates a "listings" custom post type. It is also add a recent listings custom widget, in the widget dashboard.
     10A simple plugin that creates a "listings" custom post type. It is also add a recent listings custom widget and a new category listings widget, in the widget dashboard.
    1111
    1212== Description ==
     
    3131= 0.1.0 =
    3232* First release.
     33
     34= 0.1.5 =
     35* Added address metabox
     36* Added category listings widget
  • listings-post-type-enable/trunk/README.md

    r887382 r1363313  
    2727= 0.1.0 =
    2828* First release.
     29
     30= 0.1.5 =
     31* Added address metabox
  • listings-post-type-enable/trunk/listings.php

    r887382 r1363313  
    33Plugin Name: Listings Post Type Enable
    44Description: This is a theme - specific plugin for the Directory WordPress Theme, that creates a custom post type called 'Listings' that is obligatory for this theme to  function.It also registers a widget,thar returns recent listings.
    5 Version: 0.1.0
     5Version: 0.1.5
    66Author: Alex Itsios
    77Author URI: http://ketchupthemes.com
     
    127127function directory_recent_listings_widget_init() {
    128128    register_widget('ketchupthemes_Widget_Recent_Listings');
     129    register_widget('KetchupThemes_Listing_Category_Widget');
    129130}
    130131add_action('widgets_init', 'directory_recent_listings_widget_init');
     
    243244    }
    244245}
     246/*
     247 * Listing categories widgets
     248 */
     249
     250class KetchupThemes_Listing_Category_Widget extends WP_Widget
     251{
     252
     253    function __construct()
     254    {
     255        parent::__construct(
     256
     257            'directory_listings_category_widget',
     258
     259            __('Directory Listing Category', 'directory'),
     260
     261            array(
     262                'description' => __('Select a parent category and show its child categories with their links.',   'directory'),
     263            )
     264        );
     265    }
     266
     267    public function widget($args,
     268        $instance)
     269    {
     270
     271        $title = apply_filters('widget_title', $instance['title']);
     272        $taxonomy = 'listing-category';
     273        $parent_term_id = $instance['parent_term_id'];
     274
     275        echo $args['before_widget'];
     276
     277        if (!empty($title))
     278            echo $args['before_title'] . $title . $args['after_title'];
     279
     280        ob_start();
     281
     282        $parent_term = get_terms('listing-category',
     283            array('parent' => 0, 'include' => $parent_term_id, 'hide_empty' => false));
     284
     285        $term_args = array(
     286            'child_of' => $parent_term_id,
     287            'hide_empty' => false);
     288
     289        $terms = get_terms($taxonomy, $term_args);
     290        ?>
     291        <div class="category-list-container matchHeight">
     292            <?php foreach ($parent_term as $pt) { ?>
     293
     294            <h4 class="category-title"><a href="<?php echo esc_url(get_term_link($pt)); ?>"><?php echo $pt->name; ?></a></h4>
     295
     296            <?php } ?>
     297
     298            <ul class="category-list">
     299            <?php
     300                foreach ($terms as $t) {
     301                $term_link = get_term_link($t); ?>
     302
     303               <li><a href="<?php echo esc_url($term_link); ?>"> <?php echo $t->name;?></a> <span class="category-count">(<?php echo $t->count; ?>)</span></li>
     304            <?php  } ?>
     305
     306            </ul>
     307
     308        </div>
     309        <?php
     310        echo $args['after_widget'];
     311    }
     312
     313    public function form($instance)
     314    {
     315        if (isset($instance['title'])) {
     316            $title = $instance['title'];
     317        } else {
     318            $title = '';
     319        }
     320
     321        if(isset($instance['parent_term_id']) || $instance['parent_term_id'] != ''):
     322            $parent_term_id = $instance['parent_term_id'];
     323        else:
     324            $parent_term_id = '';
     325        endif;
     326
     327        ?>
     328
     329        <p>
     330            <label
     331                for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title: * You dont have to add a title !',
     332                    'directory');
     333                ?></label>
     334            <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>"
     335                   name="<?php echo $this->get_field_name('title'); ?>" type="text"
     336                   value="<?php echo esc_attr($title); ?>"/>
     337        </p>
     338
     339
     340        <?php $parent_terms = get_terms('listing-category', array('parent' => 0, 'hide_empty' => false)); ?>
     341        <p>
     342            <label
     343                for="<?php echo $this->get_field_id('parent_term_id'); ?>"><?php _e('Select a category:',
     344                    'directory');
     345                ?></label>
     346            <select name="<?php echo esc_attr( $this->get_field_name( 'parent_term_id' ) ); ?>" id="<?php echo esc_attr( $this->get_field_id( 'parent_term_id' ) ); ?>" class="widefat">
     347                <?php foreach($parent_terms as $pt): ?>
     348
     349                <option value="<?php echo $pt->term_id; ?>"<?php selected( $instance['parent_term_id'], $pt->term_id ); ?>><?php echo $pt->name; ?></option>
     350
     351                <?php endforeach; ?>
     352            </select>
     353        </p>
     354
     355
     356        <?php
     357    }
     358
     359    public function update($new_instance,
     360        $old_instance)
     361    {
     362        $instance = array();
     363        $instance['title'] = (!empty($new_instance['title'])) ? strip_tags($new_instance['title']) : '';
     364        $instance['parent_term_id'] = (!empty($new_instance['parent_term_id'])) ? strip_tags($new_instance['parent_term_id']) : '';
     365
     366        return $instance;
     367    }
     368}
     369
     370
     371
     372function ketchupthemes_add_listing_address_meta( $value ) {
     373    global $post;
     374
     375    $field = get_post_meta( $post->ID, $value, true );
     376    if ( ! empty( $field ) ) {
     377        return is_array( $field ) ? stripslashes_deep( $field ) : stripslashes( wp_kses_decode_entities( $field ) );
     378    } else {
     379        return false;
     380    }
     381}
     382
     383function add_listing_address_add_meta_box() {
     384    add_meta_box(
     385        'add_listing_address-add-listing-address',
     386        __( 'Add listing address', 'directory' ),
     387        'add_listing_address_html',
     388        'listing',
     389        'normal',
     390        'core'
     391    );
     392}
     393add_action( 'add_meta_boxes', 'add_listing_address_add_meta_box' );
     394
     395function add_listing_address_html( $post) {
     396    wp_nonce_field( '_add_listing_address_nonce', 'add_listing_address_nonce' ); ?>
     397
     398    <p><?php echo __('Please add it like this eg. 120 Hawthorn Ave
     399        Colchester, Essex CO4 3QF','directory'); ?></p>
     400
     401    <p>
     402    <label for="add_listing_address_listing_address"><?php _e( 'Listing Address', 'directory' ); ?></label><br>
     403    <input type="text" name="add_listing_address_listing_address" id="add_listing_address_listing_address" value="<?php echo ketchupthemes_add_listing_address_meta( 'add_listing_address_listing_address' ); ?>">
     404    </p><?php
     405}
     406
     407function add_listing_address_save( $post_id ) {
     408    if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return;
     409    if ( ! isset( $_POST['add_listing_address_nonce'] ) || ! wp_verify_nonce( $_POST['add_listing_address_nonce'], '_add_listing_address_nonce' ) ) return;
     410    if ( ! current_user_can( 'edit_post', $post_id ) ) return;
     411
     412    if ( isset( $_POST['add_listing_address_listing_address'] ) )
     413        update_post_meta( $post_id, 'add_listing_address_listing_address', esc_attr( $_POST['add_listing_address_listing_address'] ) );
     414}
     415add_action( 'save_post', 'add_listing_address_save' );
     416
     417/*
     418    Usage: ketchupthemes_add_listing_address_meta( 'add_listing_address_listing_address' )
     419*/
  • listings-post-type-enable/trunk/readme.txt

    r887393 r1363313  
    33Tags: custom post type, listings post type, directory post type, custom widget
    44Requires at least: 3.0.1
    5 Tested up to: 3.8.1
     5Tested up to: 4.4.2
    66Stable tag: trunk
    77License: GPLv2 or later
    88License URI: http://www.gnu.org/licenses/gpl-2.0.html
    99
    10 A simple plugin that creates a "listings" custom post type. It is also add a recent listings custom widget, in the widget dashboard.
     10A simple plugin that creates a "listings" custom post type. It is also add a recent listings custom widget and a new category listings widget, in the widget dashboard.
    1111
    1212== Description ==
     
    3131= 0.1.0 =
    3232* First release.
     33
     34= 0.1.5 =
     35* Added address metabox
     36* Added category listings widget
Note: See TracChangeset for help on using the changeset viewer.