Plugin Directory

Changeset 3066192


Ignore:
Timestamp:
04/07/2024 08:20:14 AM (2 years ago)
Author:
addonspress
Message:

2.3.4

Location:
taxonomy-term-widget
Files:
3 added
2 edited

Legend:

Unmodified
Added
Removed
  • taxonomy-term-widget/trunk/readme.txt

    r2672972 r3066192  
    44Requires at least: 3.0
    55Tested up to: 5.9
    6 Stable tag: 2.3.3
     6Stable tag: 2.3.4
    77License: GPLv3 or later
    88License URI: http://www.gnu.org/licenses/gpl.html
     
    3636== Changelog ==
    3737
    38 = 2.3.3 – 2022-02-04 =
     38= 2.3.4 – 2024-04-07 =
    3939* Updated : Latest version test
    4040
  • taxonomy-term-widget/trunk/taxonomy-term-widget.php

    r2672972 r3066192  
    44Plugin URI: https://www.addonspress.com/wordpress-plugins/taxonomy-term-widget/
    55Description: Add an advanced widget to your WordPress blog,like an extension of the Categories widget
    6 Version: 2.3.3
     6Version: 2.3.4
    77Author: addonspress
    88Author URI: https://www.addonspress.com/
     
    1111*/
    1212/*Make sure we don't expose any info if called directly*/
    13 if ( !function_exists( 'add_action' ) ) {
    14     echo 'Hi there!  I\'m just a plugin, not much I can do when called directly.';
    15     exit;
     13if ( ! function_exists( 'add_action' ) ) {
     14    echo 'Hi there!  I\'m just a plugin, not much I can do when called directly.';
     15    exit;
    1616}
    1717if ( ! class_exists( 'Coder_Taxonomy_Term' ) ) {
    18     /**
    19      * Class for adding widget
    20      *
    21      * @package Coder Customizer Framework
    22      * @since 1.0
    23      */
    24     class Coder_Taxonomy_Term extends WP_Widget {
    25         function __construct() {
    26             parent::__construct(
    27             /*Base ID of your widget*/
    28                 'taxonomy_term_widget',
    29                 /*Widget name will appear in UI*/
    30                 __('Taxonomy Term Widget', 'coder_taxonomy_term_domain'),
    31                 /*Widget description*/
    32                 array( 'description' => __( 'Add advanced widget to your wordpress blog,like an extension of Categories widget', 'coder_taxonomy_term_domain' ), )
    33             );
    34         }
    35         /*Widget Backend*/
    36         public function form( $instance ) {
    37             if ( isset( $instance[ 'title' ] ) ) {
    38                 $title = $instance[ 'title' ];
    39             }
    40             else {
    41                 $title = __( 'New title', 'coder_taxonomy_term_domain' );
    42             }
    43             if ( isset( $instance[ 'taxonomy' ] ) ) {
    44                 $selected_taxonomy = $instance[ 'taxonomy' ];
    45             }
    46             else {
    47                 $selected_taxonomy = '';
    48             }
    49             if ( isset( $instance[ 'tax_is_display_dropdown' ] ) ) {
    50                 $tax_is_display_dropdown = $instance[ 'tax_is_display_dropdown' ];
    51             }
    52             else {
    53                 $tax_is_display_dropdown = '';
    54             }
    55             if ( isset( $instance[ 'tax_is_show_posts_count' ] ) ) {
    56                 $tax_is_show_posts_count = $instance[ 'tax_is_show_posts_count' ];
    57             }
    58             else {
    59                 $tax_is_show_posts_count = '';
    60             }
    61             if ( isset( $instance[ 'tax_is_show_hierarchy' ] ) ) {
    62                 $tax_is_show_hierarchy = $instance[ 'tax_is_show_hierarchy' ];
    63             }
    64             else {
    65                 $tax_is_show_hierarchy = '';
    66             }
    67             if ( isset( $instance[ 'tax_orderby' ] ) ) {
    68                 $tax_orderby = $instance[ 'tax_orderby' ];
    69             }
    70             else {
    71                 $tax_orderby = '';
    72             }
    73             if ( isset( $instance[ 'tax_order' ] ) ) {
    74                 $tax_order = $instance[ 'tax_order' ];
    75             }
    76             else {
    77                 $tax_order = '';
    78             }
    79             if ( isset( $instance[ 'child_of' ] ) ) {
    80                 $child_of = $instance[ 'child_of' ];
    81             }
    82             else {
    83                 $child_of = '';
    84             }
    85             if ( isset( $instance[ 'tax_exclude' ] ) ) {
    86                 $tax_exclude = $instance[ 'tax_exclude' ];
    87             }
    88             else {
    89                 $tax_exclude = '';
    90             }
    91             if ( isset( $instance[ 'tax_hidempty' ] ) ) {
    92                 $tax_hidempty = $instance[ 'tax_hidempty' ];
    93             }
    94             else {
    95                 $tax_hidempty = '';
    96             }
    97             if ( isset( $instance[ 'tax_firstoption' ] ) ) {
    98                 $tax_firstoption = $instance[ 'tax_firstoption' ];
    99             }
    100             else {
    101                 $tax_firstoption = '';
    102             }
    103             /*Widget admin form*/
    104             ?>
    105             <p>
    106                 <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Enter title:' ,'coder_taxonomy_term_domain'); ?></label>
    107                 <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo esc_attr( $title ); ?>" />
    108             </p>
    109             <p>
    110                 <label for="<?php echo $this->get_field_id('taxonomy'); ?>"><?php _e('Select Taxonomy', 'coder_taxonomy_term_domain'); ?></label>
    111                 <select name="<?php echo $this->get_field_name('taxonomy'); ?>" id="<?php echo $this->get_field_id('taxonomy'); ?>" class="widefat">
    112                     <?php
    113                     $args = array(
    114                         'public'   => true,
    115                     );
    116                     $taxonomies=get_taxonomies($args, 'objects');
    117                     foreach ($taxonomies as $taxonomy) {
    118                         if('post_format' == $taxonomy->name ) {
    119                             continue;
    120                         }
    121                         echo '<option value="' . $taxonomy->name . '" id="' . $taxonomy->name . '"', $selected_taxonomy == $taxonomy->name ? ' selected="selected"' : '', '>', $taxonomy->labels->name, '</option>';
    122                     }
    123                     ?>
    124                 </select>
    125             </p>
    126             <p>
    127                 <input id="<?php echo $this->get_field_id('tax_is_display_dropdown'); ?>" name="<?php echo $this->get_field_name('tax_is_display_dropdown'); ?>" type="checkbox" value="1" <?php checked( '1', $tax_is_display_dropdown ); ?> />
    128                 <label for="<?php echo $this->get_field_id('tax_is_display_dropdown'); ?>"><?php _e('Display as dropdown', 'coder_taxonomy_term_domain'); ?></label><br>
    129 
    130                 <input id="<?php echo $this->get_field_id('tax_is_show_posts_count'); ?>" name="<?php echo $this->get_field_name('tax_is_show_posts_count'); ?>" type="checkbox" value="1" <?php checked( '1', $tax_is_show_posts_count ); ?> />
    131                 <label for="<?php echo $this->get_field_id('tax_is_show_posts_count'); ?>"><?php _e('Show post counts', 'coder_taxonomy_term_domain'); ?></label><br>
    132 
    133                 <input id="<?php echo $this->get_field_id('tax_is_show_hierarchy'); ?>" name="<?php echo $this->get_field_name('tax_is_show_hierarchy'); ?>" type="checkbox" value="1" <?php checked( '1', $tax_is_show_hierarchy ); ?> />
    134                 <label for="<?php echo $this->get_field_id('tax_is_show_hierarchy'); ?>"><?php _e('Show hierarchy', 'coder_taxonomy_term_domain'); ?></label><br>
    135 
    136                 <input id="<?php echo $this->get_field_id('tax_hidempty'); ?>" name="<?php echo $this->get_field_name('tax_hidempty'); ?>" type="checkbox" value="1" <?php checked( '1', $tax_hidempty ); ?> />
    137                 <label for="<?php echo $this->get_field_id('tax_hidempty'); ?>"><?php _e('Hide empty', 'coder_taxonomy_term_domain'); ?></label><br>
    138             </p>
    139             <p>
    140                 <label for="<?php echo $this->get_field_id('tax_orderby'); ?>"><?php _e('Select Order By', 'coder_taxonomy_term_domain'); ?></label>
    141                 <select name="<?php echo $this->get_field_name('tax_orderby'); ?>" id="<?php echo $this->get_field_id('tax_orderby'); ?>" class="widefat">
    142                     <?php
    143                     $options_orderby = array('ID', 'NAME', 'SLUG','COUNT');
    144                     foreach ($options_orderby as $option_orderby) {
    145                         echo '<option value="' . $option_orderby . '" id="' . $option_orderby . '"', $tax_orderby == $option_orderby ? ' selected="selected"' : '', '>', $option_orderby, '</option>';
    146                     }
    147                     ?>
    148                 </select>
    149             </p>
    150             <p>
    151                 <label for="<?php echo $this->get_field_id('tax_order'); ?>"><?php _e('Select Order', 'coder_taxonomy_term_domain'); ?></label>
    152                 <select name="<?php echo $this->get_field_name('tax_order'); ?>" id="<?php echo $this->get_field_id('tax_order'); ?>" class="widefat">
    153                     <?php
    154                     $options_order = array('ASC', 'DESC');
    155                     foreach ($options_order as $option_order) {
    156                         echo '<option value="' . $option_order . '" id="' . $option_order . '"', $tax_order == $option_order ? ' selected="selected"' : '', '>', $option_order, '</option>';
    157                     }
    158                     ?>
    159                 </select>
    160             </p>
    161             <p>
    162                 <label for="<?php echo $this->get_field_id( 'child_of' ); ?>"><?php _e( 'Enter parent term id ( Only display terms that are children of this ):' ,'coder_taxonomy_term_domain'); ?></label>
    163                 <input class="widefat" id="<?php echo $this->get_field_id( 'child_of' ); ?>" name="<?php echo $this->get_field_name( 'child_of' ); ?>" type="text" value="<?php echo esc_attr( $child_of ); ?>" placeholder="<?php _e( '12' ,'coder_taxonomy_term_domain'); ?>"/>
    164                 <br>
    165                 <small>Left empty for show all terms, also make sure if the term have any child. For finding id, edit term, in the address bar you will see tag_ID=3 or others number, the number is id of any term.</small>
    166             </p>
    167             <p>
    168                 <label for="<?php echo $this->get_field_id( 'tax_exclude' ); ?>"><?php _e( 'Enter comma separated id/ids to exclude:' ,'coder_taxonomy_term_domain'); ?></label>
    169                 <input class="widefat" id="<?php echo $this->get_field_id( 'tax_exclude' ); ?>" name="<?php echo $this->get_field_name( 'tax_exclude' ); ?>" type="text" value="<?php echo esc_attr( $tax_exclude ); ?>" placeholder="<?php _e( '1,25,9' ,'coder_taxonomy_term_domain'); ?>"/>
    170                 <br>
    171                 <small>Left empty for show all terms without excluding any</small>
    172             </p>
    173             <p>
    174                 <label for="<?php echo $this->get_field_id( 'tax_firstoption' ); ?>"><?php _e( 'Enter first option value to display only if you have checked- Display as dropdown' ,'coder_taxonomy_term_domain'); ?></label>
    175                 <input class="widefat" id="<?php echo $this->get_field_id( 'tax_firstoption' ); ?>" name="<?php echo $this->get_field_name( 'tax_firstoption' ); ?>" type="text" value="<?php echo esc_attr( $tax_firstoption ); ?>" placeholder="<?php _e( 'Select option' ,'coder_taxonomy_term_domain'); ?>"/>
    176             </p>
    177         <?php
    178         }
    179 
    180         /**
    181          * Function to Updating widget replacing old instances with new
    182          *
    183          * @access public
    184          * @since 1.0
    185          *
    186          * @param array $new_instance new arrays value
    187          * @param array $old_instance old arrays value
    188          * @return array
    189          *
    190          */
    191         public function update( $new_instance, $old_instance ) {
    192             $instance = array();
    193             $instance['title'] = ( ! empty( $new_instance['title'] ) ) ? strip_tags( $new_instance['title'] ) : '';
    194             $instance['taxonomy'] = ( ! empty( $new_instance['taxonomy'] ) ) ? strip_tags( $new_instance['taxonomy'] ) : '';
    195             $instance['tax_is_display_dropdown'] = ( ! empty( $new_instance['tax_is_display_dropdown'] ) ) ? strip_tags( $new_instance['tax_is_display_dropdown'] ) : '';
    196             $instance['tax_is_show_posts_count'] = ( ! empty( $new_instance['tax_is_show_posts_count'] ) ) ? strip_tags( $new_instance['tax_is_show_posts_count'] ) : '';
    197             $instance['tax_is_show_hierarchy'] = ( ! empty( $new_instance['tax_is_show_hierarchy'] ) ) ? strip_tags( $new_instance['tax_is_show_hierarchy'] ) : '';
    198             $instance['tax_hidempty'] = ( ! empty( $new_instance['tax_hidempty'] ) ) ? strip_tags( $new_instance['tax_hidempty'] ) : '';
    199             $instance['tax_orderby'] = ( ! empty( $new_instance['tax_orderby'] ) ) ? sanitize_text_field( $new_instance['tax_orderby'] ) : '';
    200             $instance['child_of'] = ( ! empty( $new_instance['child_of'] ) ) ? sanitize_text_field( $new_instance['child_of'] ) : '';
    201             $instance['tax_order'] = ( ! empty( $new_instance['tax_order'] ) ) ? sanitize_text_field( $new_instance['tax_order'] ) : '';
    202             $instance['tax_exclude'] = ( ! empty( $new_instance['tax_exclude'] ) ) ? sanitize_text_field( $new_instance['tax_exclude'] ) : '';
    203             $instance['tax_firstoption'] = ( ! empty( $new_instance['tax_firstoption'] ) ) ? sanitize_text_field( $new_instance['tax_firstoption'] ) : '';
    204 
    205             return $instance;
    206         }
    207         /**
    208          * Function to Creating widget front-end. This is where the action happens
    209          *
    210          * @access public
    211          * @since 1.0
    212          *
    213          * @param array $args widget setting
    214          * @param array $instance saved values
    215          * @return array
    216          *
    217          */
    218         public function widget( $args, $instance ) {
    219             $title = apply_filters( 'widget_title', $instance['title'] );
    220             $taxonomy = $instance['taxonomy'];
    221             $tax_is_display_dropdown = $instance['tax_is_display_dropdown'];
    222             $tax_is_show_posts_count = $instance['tax_is_show_posts_count'];
    223             $tax_is_show_hierarchy = $instance['tax_is_show_hierarchy'];
    224             $tax_hidempty = $instance['tax_hidempty'];
    225             if(empty($tax_hidempty)) $tax_hidempty = 0;
    226             $tax_orderby = $instance['tax_orderby'];
    227             $tax_order = $instance['tax_order'];
    228             $child_of = $instance['child_of'];
    229             $tax_exclude = $instance['tax_exclude'];
    230             $tax_firstoption = $instance['tax_firstoption'];
    231             // before and after widget arguments are defined by themes
    232             echo $args['before_widget'];
    233             if ( ! empty( $title ) )
    234                 echo $args['before_title'] . $title . $args['after_title'];
    235             if( $tax_is_display_dropdown == 1){
    236                 $args1 = array(
    237                     'show_option_none'   => $tax_firstoption,
    238                     'orderby'            => $tax_orderby,
    239                     'order'              => $tax_order,
    240                     'show_count'         => $tax_is_show_posts_count,
    241                     'hide_empty'         => $tax_hidempty,
    242                     'child_of'          => $child_of,
    243                     'exclude'            => $tax_exclude,
    244                     'echo'               => 1,
    245                     'hierarchical'       => $tax_is_show_hierarchy,
    246                     'name'               => 'coder_taxonomy',
    247                     'id'                 => 'coder_taxonomy',
    248                     'class'              => 'postform coder_taxonomy',
    249                     'taxonomy'           => $taxonomy,
    250                     'hide_if_empty'      => false,
    251                 );
    252                 ?>
    253                 <?php
    254                 wp_dropdown_categories($args1);
    255                 echo "<input type='hidden' id='coder_term_widget_current_taxonomy' value='{$taxonomy}'>";
    256                 ?>
    257 
    258             <?php
    259             }
    260             else {
    261                 $args2 = array(
    262                     'show_option_all'    => '',
    263                     'orderby'            => $tax_orderby,
    264                     'order'              => $tax_order,
    265                     'style'              => 'list',
    266                     'show_count'         => $tax_is_show_posts_count,
    267                     'hide_empty'         => $tax_hidempty,
    268                     'use_desc_for_title' => 1,
    269                     'child_of'          => $child_of,
    270                     'exclude'            => $tax_exclude,
    271                     'hierarchical'       => $tax_is_show_hierarchy,
    272                     'title_li'           => __( '' ),
    273                     'show_option_none'   => __('No Terms'),
    274                     'number'             => null,
    275                     'echo'               => 1,
    276                     'taxonomy'           => $taxonomy,
    277                 );
    278                 echo "<ul>";
    279                 wp_list_categories( $args2 );
    280                 echo "</ul>";
    281             }
    282             echo $args['after_widget'];
    283         }
    284     } // Class coder_taxonomy_term ends here
     18    /**
     19     * Class for adding widget
     20     *
     21     * @package Coder Customizer Framework
     22     * @since 1.0
     23     */
     24    class Coder_Taxonomy_Term extends WP_Widget {
     25        function __construct() {
     26            parent::__construct(
     27            /*Base ID of your widget*/
     28                'taxonomy_term_widget',
     29                /*Widget name will appear in UI*/
     30                __( 'Taxonomy Term Widget', 'coder_taxonomy_term_domain' ),
     31                /*Widget description*/
     32                array( 'description' => __( 'Add advanced widget to your wordpress blog,like an extension of Categories widget', 'coder_taxonomy_term_domain' ) )
     33            );
     34        }
     35        /*Widget Backend*/
     36        public function form( $instance ) {
     37            if ( isset( $instance['title'] ) ) {
     38                $title = $instance['title'];
     39            } else {
     40                $title = __( 'New title', 'coder_taxonomy_term_domain' );
     41            }
     42            if ( isset( $instance['taxonomy'] ) ) {
     43                $selected_taxonomy = $instance['taxonomy'];
     44            } else {
     45                $selected_taxonomy = '';
     46            }
     47            if ( isset( $instance['tax_is_display_dropdown'] ) ) {
     48                $tax_is_display_dropdown = $instance['tax_is_display_dropdown'];
     49            } else {
     50                $tax_is_display_dropdown = '';
     51            }
     52            if ( isset( $instance['tax_is_show_posts_count'] ) ) {
     53                $tax_is_show_posts_count = $instance['tax_is_show_posts_count'];
     54            } else {
     55                $tax_is_show_posts_count = '';
     56            }
     57            if ( isset( $instance['tax_is_show_hierarchy'] ) ) {
     58                $tax_is_show_hierarchy = $instance['tax_is_show_hierarchy'];
     59            } else {
     60                $tax_is_show_hierarchy = '';
     61            }
     62            if ( isset( $instance['tax_orderby'] ) ) {
     63                $tax_orderby = $instance['tax_orderby'];
     64            } else {
     65                $tax_orderby = '';
     66            }
     67            if ( isset( $instance['tax_order'] ) ) {
     68                $tax_order = $instance['tax_order'];
     69            } else {
     70                $tax_order = '';
     71            }
     72            if ( isset( $instance['child_of'] ) ) {
     73                $child_of = $instance['child_of'];
     74            } else {
     75                $child_of = '';
     76            }
     77            if ( isset( $instance['tax_exclude'] ) ) {
     78                $tax_exclude = $instance['tax_exclude'];
     79            } else {
     80                $tax_exclude = '';
     81            }
     82            if ( isset( $instance['tax_hidempty'] ) ) {
     83                $tax_hidempty = $instance['tax_hidempty'];
     84            } else {
     85                $tax_hidempty = '';
     86            }
     87            if ( isset( $instance['tax_firstoption'] ) ) {
     88                $tax_firstoption = $instance['tax_firstoption'];
     89            } else {
     90                $tax_firstoption = '';
     91            }
     92            /*Widget admin form*/
     93            ?>
     94            <p>
     95                <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Enter title:', 'coder_taxonomy_term_domain' ); ?></label>
     96                <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo esc_attr( $title ); ?>" />
     97            </p>
     98            <p>
     99                <label for="<?php echo $this->get_field_id( 'taxonomy' ); ?>"><?php _e( 'Select Taxonomy', 'coder_taxonomy_term_domain' ); ?></label>
     100                <select name="<?php echo $this->get_field_name( 'taxonomy' ); ?>" id="<?php echo $this->get_field_id( 'taxonomy' ); ?>" class="widefat">
     101                    <?php
     102                    $args       = array(
     103                        'public' => true,
     104                    );
     105                    $taxonomies = get_taxonomies( $args, 'objects' );
     106                    foreach ( $taxonomies as $taxonomy ) {
     107                        if ( 'post_format' == $taxonomy->name ) {
     108                            continue;
     109                        }
     110                        echo '<option value="' . $taxonomy->name . '" id="' . $taxonomy->name . '"', $selected_taxonomy == $taxonomy->name ? ' selected="selected"' : '', '>', $taxonomy->labels->name, '</option>';
     111                    }
     112                    ?>
     113                </select>
     114            </p>
     115            <p>
     116                <input id="<?php echo $this->get_field_id( 'tax_is_display_dropdown' ); ?>" name="<?php echo $this->get_field_name( 'tax_is_display_dropdown' ); ?>" type="checkbox" value="1" <?php checked( '1', $tax_is_display_dropdown ); ?> />
     117                <label for="<?php echo $this->get_field_id( 'tax_is_display_dropdown' ); ?>"><?php _e( 'Display as dropdown', 'coder_taxonomy_term_domain' ); ?></label><br>
     118
     119                <input id="<?php echo $this->get_field_id( 'tax_is_show_posts_count' ); ?>" name="<?php echo $this->get_field_name( 'tax_is_show_posts_count' ); ?>" type="checkbox" value="1" <?php checked( '1', $tax_is_show_posts_count ); ?> />
     120                <label for="<?php echo $this->get_field_id( 'tax_is_show_posts_count' ); ?>"><?php _e( 'Show post counts', 'coder_taxonomy_term_domain' ); ?></label><br>
     121
     122                <input id="<?php echo $this->get_field_id( 'tax_is_show_hierarchy' ); ?>" name="<?php echo $this->get_field_name( 'tax_is_show_hierarchy' ); ?>" type="checkbox" value="1" <?php checked( '1', $tax_is_show_hierarchy ); ?> />
     123                <label for="<?php echo $this->get_field_id( 'tax_is_show_hierarchy' ); ?>"><?php _e( 'Show hierarchy', 'coder_taxonomy_term_domain' ); ?></label><br>
     124
     125                <input id="<?php echo $this->get_field_id( 'tax_hidempty' ); ?>" name="<?php echo $this->get_field_name( 'tax_hidempty' ); ?>" type="checkbox" value="1" <?php checked( '1', $tax_hidempty ); ?> />
     126                <label for="<?php echo $this->get_field_id( 'tax_hidempty' ); ?>"><?php _e( 'Hide empty', 'coder_taxonomy_term_domain' ); ?></label><br>
     127            </p>
     128            <p>
     129                <label for="<?php echo $this->get_field_id( 'tax_orderby' ); ?>"><?php _e( 'Select Order By', 'coder_taxonomy_term_domain' ); ?></label>
     130                <select name="<?php echo $this->get_field_name( 'tax_orderby' ); ?>" id="<?php echo $this->get_field_id( 'tax_orderby' ); ?>" class="widefat">
     131                    <?php
     132                    $options_orderby = array( 'ID', 'NAME', 'SLUG', 'COUNT' );
     133                    foreach ( $options_orderby as $option_orderby ) {
     134                        echo '<option value="' . $option_orderby . '" id="' . $option_orderby . '"', $tax_orderby == $option_orderby ? ' selected="selected"' : '', '>', $option_orderby, '</option>';
     135                    }
     136                    ?>
     137                </select>
     138            </p>
     139            <p>
     140                <label for="<?php echo $this->get_field_id( 'tax_order' ); ?>"><?php _e( 'Select Order', 'coder_taxonomy_term_domain' ); ?></label>
     141                <select name="<?php echo $this->get_field_name( 'tax_order' ); ?>" id="<?php echo $this->get_field_id( 'tax_order' ); ?>" class="widefat">
     142                    <?php
     143                    $options_order = array( 'ASC', 'DESC' );
     144                    foreach ( $options_order as $option_order ) {
     145                        echo '<option value="' . $option_order . '" id="' . $option_order . '"', $tax_order == $option_order ? ' selected="selected"' : '', '>', $option_order, '</option>';
     146                    }
     147                    ?>
     148                </select>
     149            </p>
     150            <p>
     151                <label for="<?php echo $this->get_field_id( 'child_of' ); ?>"><?php _e( 'Enter parent term id ( Only display terms that are children of this ):', 'coder_taxonomy_term_domain' ); ?></label>
     152                <input class="widefat" id="<?php echo $this->get_field_id( 'child_of' ); ?>" name="<?php echo $this->get_field_name( 'child_of' ); ?>" type="text" value="<?php echo esc_attr( $child_of ); ?>" placeholder="<?php _e( '12', 'coder_taxonomy_term_domain' ); ?>"/>
     153                <br>
     154                <small>Left empty for show all terms, also make sure if the term have any child. For finding id, edit term, in the address bar you will see tag_ID=3 or others number, the number is id of any term.</small>
     155            </p>
     156            <p>
     157                <label for="<?php echo $this->get_field_id( 'tax_exclude' ); ?>"><?php _e( 'Enter comma separated id/ids to exclude:', 'coder_taxonomy_term_domain' ); ?></label>
     158                <input class="widefat" id="<?php echo $this->get_field_id( 'tax_exclude' ); ?>" name="<?php echo $this->get_field_name( 'tax_exclude' ); ?>" type="text" value="<?php echo esc_attr( $tax_exclude ); ?>" placeholder="<?php _e( '1,25,9', 'coder_taxonomy_term_domain' ); ?>"/>
     159                <br>
     160                <small>Left empty for show all terms without excluding any</small>
     161            </p>
     162            <p>
     163                <label for="<?php echo $this->get_field_id( 'tax_firstoption' ); ?>"><?php _e( 'Enter first option value to display only if you have checked- Display as dropdown', 'coder_taxonomy_term_domain' ); ?></label>
     164                <input class="widefat" id="<?php echo $this->get_field_id( 'tax_firstoption' ); ?>" name="<?php echo $this->get_field_name( 'tax_firstoption' ); ?>" type="text" value="<?php echo esc_attr( $tax_firstoption ); ?>" placeholder="<?php _e( 'Select option', 'coder_taxonomy_term_domain' ); ?>"/>
     165            </p>
     166            <?php
     167        }
     168
     169        /**
     170         * Function to Updating widget replacing old instances with new
     171         *
     172         * @access public
     173         * @since 1.0
     174         *
     175         * @param array $new_instance new arrays value
     176         * @param array $old_instance old arrays value
     177         * @return array
     178         */
     179        public function update( $new_instance, $old_instance ) {
     180            $instance                            = array();
     181            $instance['title']                   = ( ! empty( $new_instance['title'] ) ) ? strip_tags( $new_instance['title'] ) : '';
     182            $instance['taxonomy']                = ( ! empty( $new_instance['taxonomy'] ) ) ? strip_tags( $new_instance['taxonomy'] ) : '';
     183            $instance['tax_is_display_dropdown'] = ( ! empty( $new_instance['tax_is_display_dropdown'] ) ) ? strip_tags( $new_instance['tax_is_display_dropdown'] ) : '';
     184            $instance['tax_is_show_posts_count'] = ( ! empty( $new_instance['tax_is_show_posts_count'] ) ) ? strip_tags( $new_instance['tax_is_show_posts_count'] ) : '';
     185            $instance['tax_is_show_hierarchy']   = ( ! empty( $new_instance['tax_is_show_hierarchy'] ) ) ? strip_tags( $new_instance['tax_is_show_hierarchy'] ) : '';
     186            $instance['tax_hidempty']            = ( ! empty( $new_instance['tax_hidempty'] ) ) ? strip_tags( $new_instance['tax_hidempty'] ) : '';
     187            $instance['tax_orderby']             = ( ! empty( $new_instance['tax_orderby'] ) ) ? sanitize_text_field( $new_instance['tax_orderby'] ) : '';
     188            $instance['child_of']                = ( ! empty( $new_instance['child_of'] ) ) ? sanitize_text_field( $new_instance['child_of'] ) : '';
     189            $instance['tax_order']               = ( ! empty( $new_instance['tax_order'] ) ) ? sanitize_text_field( $new_instance['tax_order'] ) : '';
     190            $instance['tax_exclude']             = ( ! empty( $new_instance['tax_exclude'] ) ) ? sanitize_text_field( $new_instance['tax_exclude'] ) : '';
     191            $instance['tax_firstoption']         = ( ! empty( $new_instance['tax_firstoption'] ) ) ? sanitize_text_field( $new_instance['tax_firstoption'] ) : '';
     192
     193            return $instance;
     194        }
     195        /**
     196         * Function to Creating widget front-end. This is where the action happens
     197         *
     198         * @access public
     199         * @since 1.0
     200         *
     201         * @param array $args widget setting
     202         * @param array $instance saved values
     203         * @return array
     204         */
     205        public function widget( $args, $instance ) {
     206            $title                   = apply_filters( 'widget_title', $instance['title'] );
     207            $taxonomy                = $instance['taxonomy'];
     208            $tax_is_display_dropdown = $instance['tax_is_display_dropdown'];
     209            $tax_is_show_posts_count = $instance['tax_is_show_posts_count'];
     210            $tax_is_show_hierarchy   = $instance['tax_is_show_hierarchy'];
     211            $tax_hidempty            = $instance['tax_hidempty'];
     212            if ( empty( $tax_hidempty ) ) {
     213                $tax_hidempty = 0;
     214            }
     215            $tax_orderby     = $instance['tax_orderby'];
     216            $tax_order       = $instance['tax_order'];
     217            $child_of        = $instance['child_of'];
     218            $tax_exclude     = $instance['tax_exclude'];
     219            $tax_firstoption = $instance['tax_firstoption'];
     220            // before and after widget arguments are defined by themes
     221            echo $args['before_widget'];
     222            if ( ! empty( $title ) ) {
     223                echo $args['before_title'] . $title . $args['after_title'];
     224            }
     225            if ( $tax_is_display_dropdown == 1 ) {
     226                $args1 = array(
     227                    'show_option_none' => $tax_firstoption,
     228                    'orderby'          => $tax_orderby,
     229                    'order'            => $tax_order,
     230                    'show_count'       => $tax_is_show_posts_count,
     231                    'hide_empty'       => $tax_hidempty,
     232                    'child_of'         => $child_of,
     233                    'exclude'          => $tax_exclude,
     234                    'echo'             => 1,
     235                    'hierarchical'     => $tax_is_show_hierarchy,
     236                    'name'             => 'coder_taxonomy',
     237                    'id'               => 'coder_taxonomy',
     238                    'class'            => 'postform coder_taxonomy',
     239                    'taxonomy'         => $taxonomy,
     240                    'hide_if_empty'    => false,
     241                );
     242                ?>
     243                <?php
     244                wp_dropdown_categories( $args1 );
     245                echo "<input type='hidden' id='coder_term_widget_current_taxonomy' value='{$taxonomy}'>";
     246                ?>
     247
     248                <?php
     249            } else {
     250                $args2 = array(
     251                    'show_option_all'    => '',
     252                    'orderby'            => $tax_orderby,
     253                    'order'              => $tax_order,
     254                    'style'              => 'list',
     255                    'show_count'         => $tax_is_show_posts_count,
     256                    'hide_empty'         => $tax_hidempty,
     257                    'use_desc_for_title' => 1,
     258                    'child_of'           => $child_of,
     259                    'exclude'            => $tax_exclude,
     260                    'hierarchical'       => $tax_is_show_hierarchy,
     261                    'title_li'           => __( '' ),
     262                    'show_option_none'   => __( 'No Terms' ),
     263                    'number'             => null,
     264                    'echo'               => 1,
     265                    'taxonomy'           => $taxonomy,
     266                );
     267                echo '<ul>';
     268                wp_list_categories( $args2 );
     269                echo '</ul>';
     270            }
     271            echo $args['after_widget'];
     272        }
     273    } // Class coder_taxonomy_term ends here
    285274
    286275}
     
    288277
    289278if ( ! function_exists( 'coder_taxonomy_term_widget' ) ) :
    290     /**
    291      * Function to Register and load the widget
    292      *
    293      * @since 1.0
    294      *
    295      * @param null
    296      * @return null
    297      *
    298      */
    299     function coder_taxonomy_term_widget() {
    300         register_widget( 'coder_taxonomy_term' );
    301     }
     279    /**
     280     * Function to Register and load the widget
     281     *
     282     * @since 1.0
     283     *
     284     * @param null
     285     * @return null
     286     */
     287    function coder_taxonomy_term_widget() {
     288        register_widget( 'coder_taxonomy_term' );
     289    }
    302290endif;
    303291add_action( 'widgets_init', 'coder_taxonomy_term_widget' );
    304292
    305293if ( ! function_exists( 'coder_taxonomy_term_widget_footer_assets' ) ) :
    306     /**
    307     * Function to Register and load the widget
    308     *
    309     * @since 2.0
    310     *
    311     * @param null
    312     * @return null
    313      *
    314      */
    315     function coder_taxonomy_term_widget_footer_assets() { ?>
    316         <script type="text/javascript">
    317             jQuery(document).ready(function(){
    318                 jQuery('.coder_taxonomy').change(function(){
    319                     var taxonomy_term_id = jQuery(this).val();
    320                     var taxonomy = jQuery(this).next().val();
    321                     jQuery.ajax({
    322                         type: "POST",
    323                         url: "<?php echo admin_url('admin-ajax.php'); ?>",
    324                         data: {
    325                             action: 'coder_taxonomy_term_widget_ajax',
    326                             taxonomy_term_id: taxonomy_term_id,
    327                             taxonomy: taxonomy
    328                         },
    329                         beforeSend: function(){
    330                             console.log('coder-taxonomy-term-widget ajax running')
    331                         },
    332                         success:function(response){
    333                             window.location.replace(response);
    334                         }
    335                     })
    336                 })
    337             })
    338         </script>
    339         <?php
    340         register_widget( 'coder_taxonomy_term' );
    341     }
     294    /**
     295    * Function to Register and load the widget
     296    *
     297    * @since 2.0
     298    *
     299    * @param null
     300    * @return null
     301     */
     302    function coder_taxonomy_term_widget_footer_assets() {
     303        ?>
     304        <script type="text/javascript">
     305            jQuery(document).ready(function(){
     306                jQuery('.coder_taxonomy').change(function(){
     307                    var taxonomy_term_id = jQuery(this).val();
     308                    var taxonomy = jQuery(this).next().val();
     309                    jQuery.ajax({
     310                        type: "POST",
     311                        url: "<?php echo admin_url( 'admin-ajax.php' ); ?>",
     312                        data: {
     313                            action: 'coder_taxonomy_term_widget_ajax',
     314                            taxonomy_term_id: taxonomy_term_id,
     315                            taxonomy: taxonomy
     316                        },
     317                        beforeSend: function(){
     318                            console.log('coder-taxonomy-term-widget ajax running')
     319                        },
     320                        success:function(response){
     321                            window.location.replace(response);
     322                        }
     323                    })
     324                })
     325            })
     326        </script>
     327        <?php
     328        register_widget( 'coder_taxonomy_term' );
     329    }
    342330endif;
    343 add_action('wp_footer', 'coder_taxonomy_term_widget_footer_assets');
     331add_action( 'wp_footer', 'coder_taxonomy_term_widget_footer_assets' );
    344332
    345333add_action( 'wp_ajax_coder_taxonomy_term_widget_ajax', 'coder_taxonomy_term_widget_ajax_callback' );
    346334
    347335if ( ! function_exists( 'coder_taxonomy_term_widget_ajax_callback' ) ) :
    348     /**
    349      * Function to handle callback ajax
    350      *
    351      * @since 2.0
    352      *
    353      * @param null
    354      * @return null
    355      *
    356      */
    357     function coder_taxonomy_term_widget_ajax_callback(){
    358         $taxonomy_term_id = $_POST['taxonomy_term_id'];
    359         $taxonomy = $_POST['taxonomy'];
    360         echo get_term_link( (int)$taxonomy_term_id, $taxonomy );
    361         exit;
    362     }
     336    /**
     337     * Function to handle callback ajax
     338     *
     339     * @since 2.0
     340     *
     341     * @param null
     342     * @return null
     343     */
     344    function coder_taxonomy_term_widget_ajax_callback() {
     345        $taxonomy_term_id = $_POST['taxonomy_term_id'];
     346        $taxonomy         = $_POST['taxonomy'];
     347        echo get_term_link( (int) $taxonomy_term_id, $taxonomy );
     348        exit;
     349    }
    363350endif;
    364351add_action( 'wp_ajax_nopriv_coder_taxonomy_term_widget_ajax', 'coder_taxonomy_term_widget_ajax_callback' );
Note: See TracChangeset for help on using the changeset viewer.