Plugin Directory

Changeset 1447608


Ignore:
Timestamp:
07/02/2016 03:46:49 AM (10 years ago)
Author:
jacking83
Message:

add new option in widget

Location:
links-dropdown-widget
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • links-dropdown-widget/trunk/css/widget.css

    r844340 r1447608  
    1010#link-dropdown-widget option{
    1111    font-size: 1em !important;
     12    padding: 2px 4px;
    1213}
  • links-dropdown-widget/trunk/plugin.php

    r844340 r1447608  
    22/*
    33Plugin Name: Links Dropdown Widget
    4 Plugin URI: http://someblog.vv.si/
     4Plugin URI: http://sihung.net/plugins/links-dropdown-widget
    55Description: Display links as dropdown
    6 Version: 1.0
    7 Author: Trang Si Hung
    8 Author URI: http://someblog.vv.si/
     6Version: 1.1
     7Author: Hung Trang Si
     8Author URI: http://sihung.net
    99Author Email: trangsihung@gmail.com
    1010License: GPLv2 or later
    1111License URI: http://www.gnu.org/licenses/gpl-2.0.html
     12Text Domain: linkdrop
    1213
    13 Copyright 2013 Someblog
     14Copyright 2016 Hung Trang Si
    1415
    1516This program is free software; you can redistribute it and/or modify
     
    7172        $title = apply_filters('widget_title', empty( $instance['title'] ) ? __( 'Links' ) : $instance['title'], $instance, $this->id_base);
    7273        $default_option = $instance['default_option'];
     74        $link_cat = $instance['link_cat'];
     75        $open_same_window = $instance['open_same_window'];
     76
    7377        echo $before_widget;
    7478
     
    9397        $instance['title'] = strip_tags($new_instance['title']);
    9498        $instance['default_option'] = strip_tags($new_instance['default_option']);
     99        $instance['link_cat'] = (int)($new_instance['link_cat']);
     100        $instance['open_same_window'] = $new_instance['open_same_window'];
    95101
    96102        return $instance;
     
    107113        $instance = wp_parse_args(
    108114            (array) $instance,
    109             array( 'title' => '', 'default_option' => 'Select Option')
     115            array(
     116                'title' => '',
     117                'default_option' => 'Select Option',
     118                'link_cat' => 0
     119            )
    110120        );
    111121
    112122        $title = esc_attr( $instance['title'] );
    113123        $default_option = esc_attr( $instance['default_option'] );
     124        $link_cat = (int) $instance['link_cat'];
     125        $open_same_window = $instance['open_same_window'];
    114126
    115127        // Display the admin form
     
    130142
    131143add_action( 'widgets_init', create_function( '', 'register_widget("Links_Dropdown_Widget");' ) );
     144
     145
     146function linkdrop_categories_to_array($taxonomy){
     147    $terms = get_terms($taxonomy,array(
     148        'hide_empty'=>false
     149    ));
     150    $terms_production = array();
     151    foreach ($terms as $key=>$term){
     152        $terms_production[$term->term_id] = $term->name;
     153    }
     154    $terms_production[0] = __('All', 'linkdrop');
     155    return $terms_production;
     156}
  • links-dropdown-widget/trunk/readme.txt

    r857943 r1447608  
    11=== Dropdown Links Widget ===
    22Contributors: jacking83
    3 Donate link: 
     3Donate link:
    44Tags: widget, links manager, links
    55Requires at least: 3.3
    6 Tested up to: 3.8
    7 Stable tag: 1.0
     6Tested up to: 4.5.3
     7Stable tag: 1.1
    88License: GPLv2 or later
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    24241. Widget Ready
    25252. Display on front-end
     26
     27== Changelog ==
     28
     29= v1.1 =
     30
     31* Allow choose links category on widget panel
     32* Open links in new tab (or new windows) by default
  • links-dropdown-widget/trunk/views/admin.php

    r844340 r1447608  
    1 <p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?></label> <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo $title; ?>" /></p>
    2 <p><label for="<?php echo $this->get_field_id('default_option'); ?>"><?php _e('Default Option:'); ?></label> <input class="widefat" id="<?php echo $this->get_field_id('default_option'); ?>" name="<?php echo $this->get_field_name('default_option'); ?>" type="text" value="<?php echo $default_option; ?>" /></p>
     1<?php
     2    $links_category = linkdrop_categories_to_array('link_category');
     3    ksort($links_category);
     4?>
     5
     6<p>
     7    <label for="<?php echo $this->get_field_id('title'); ?>">
     8        <?php _e('Title:', 'linkdrop'); ?></label>
     9    <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo $title; ?>" />
     10</p>
     11
     12<p>
     13    <label for="<?php echo $this->get_field_id('default_option'); ?>">
     14        <?php _e('Default Option:', 'linkdrop'); ?></label>
     15    <input class="widefat" id="<?php echo $this->get_field_id('default_option'); ?>" name="<?php echo $this->get_field_name('default_option'); ?>" type="text" value="<?php echo $default_option; ?>" />
     16</p>
     17
     18<p>
     19    <label for="<?php echo $this->get_field_id('link_cat'); ?>">
     20        <?php _e('Link Category:', 'linkdrop'); ?></label>
     21    <select class="widefat"
     22        id="<?php echo $this->get_field_id('link_cat'); ?>"
     23        name="<?php echo $this->get_field_name('link_cat'); ?>">
     24            <?php foreach ($links_category as $key => $cat ): ?>
     25                <option <?php selected($link_cat, $key) ?> value="<?php echo $key ?>"><?php echo $cat ?></option>
     26            <?php endforeach ?>
     27        </select>
     28    </select>
     29</p>
     30
     31<p>
     32    <label for="<?php echo $this->get_field_id('open_same_window'); ?>">
     33        <input <?php checked($open_same_window, 1) ?>
     34        type="checkbox" name="<?php echo $this->get_field_name('open_same_window') ?>"
     35        id="<?php echo $this->get_field_id('open_same_window') ?>" value="1">
     36        <?php _e('Open links in same window', 'linkdrop'); ?></label>
     37</p>
  • links-dropdown-widget/trunk/views/widget.php

    r844340 r1447608  
    11<?php
    2     $output = ''; $bookmarks = get_bookmarks();
     2    $output = '';
     3
     4    if ( $link_cat == 0 ) {
     5        $bookmarks = get_bookmarks();
     6    } else {
     7        $bookmarks = get_bookmarks(array('category' => $link_cat));
     8    }
     9
    310    foreach ($bookmarks as $bookmark) { $output .= '<option value="'.$bookmark->link_url.'">'.$bookmark->link_name.'</option>'; }
     11
     12    $target = $open_same_window == 1 ? '_self' : '_blank';
    413?>
    514
    6 <select id="link-dropdown-widget" onchange="document.location.href=this.options[this.selectedIndex].value;" name="link-dropdown">
     15<select id="link-dropdown-widget" name="link-dropdown">
    716    <option value=""><?php echo $default_option ?></option>
    817    <?php echo $output ?>
    918</select>
     19
     20<script type="text/javascript">
     21    var selectLink = document.getElementById( 'link-dropdown-widget' );
     22    selectLink.onchange = function() {
     23        window.open( this.options[ this.selectedIndex ].value , '<?php echo $target ?>');
     24    };
     25</script>
Note: See TracChangeset for help on using the changeset viewer.