WordPress.org

Plugin Directory

Changeset 634092


Ignore:
Timestamp:
12/04/12 17:01:26 (17 months ago)
Author:
mitchoyoshitaka
Message:

fix widget options

File:
1 edited

Legend:

Unmodified
Added
Removed
  • yet-another-related-posts-plugin/trunk/class-widget.php

    r633259 r634092  
    7979            $instance['template'] = $instance['template_file']; 
    8080     
     81        $choice = false === $instance['template'] ? 'builtin' : 
     82            ( $instance['template'] == 'thumbnails' ? 'thumbnails' : 'custom' ); 
     83 
    8184        // if there are YARPP templates installed... 
    8285        $templates = $yarpp->admin->get_templates(); 
    83         if ( count($templates) ):  
    84             $choice = false === $instance['template'] ? 'builtin' : 
    85                 ( $instance['template'] == 'thumbnails' ? 'thumbnails' : 'custom' ); 
    86             ?> 
     86        if ( !count($templates) && $choice == 'custom' ) 
     87            $choice = 'builtin'; 
     88         
     89        ?> 
    8790 
    88             <p> 
    89                 <label style="padding-right: 10px;" for="<?php echo $this->get_field_id('use_template_builtin'); ?>"><input id="<?php echo $this->get_field_id('use_template_builtin'); ?>" name="<?php echo $this->get_field_name('use_template'); ?>" type="radio" value="builtin" <?php checked( $choice == 'builtin' ) ?> /> <?php _e( "List", 'yarpp' ); ?></label> 
     91        <p> 
     92            <label style="padding-right: 10px;" for="<?php echo $this->get_field_id('use_template_builtin'); ?>"><input id="<?php echo $this->get_field_id('use_template_builtin'); ?>" name="<?php echo $this->get_field_name('use_template'); ?>" type="radio" value="builtin" <?php checked( $choice == 'builtin' ) ?> /> <?php _e( "List", 'yarpp' ); ?></label> 
     93         
     94            <label style="padding-right: 10px;" for="<?php echo $this->get_field_id('use_template_thumbnails'); ?>"><input id="<?php echo $this->get_field_id('use_template_thumbnails'); ?>" name="<?php echo $this->get_field_name('use_template'); ?>" type="radio" value="thumbnails" <?php checked( $choice == 'thumbnails' ) ?> /> <?php _e( "Thumbnails", 'yarpp' ); ?></label> 
    9095             
    91                 <label style="padding-right: 10px;" for="<?php echo $this->get_field_id('use_template_thumbnails'); ?>"><input id="<?php echo $this->get_field_id('use_template_thumbnails'); ?>" name="<?php echo $this->get_field_name('use_template'); ?>" type="radio" value="thumbnails" <?php checked( $choice == 'thumbnails' ) ?> /> <?php _e( "Thumbnails", 'yarpp' ); ?></label> 
    92                  
    93                 <label style="padding-right: 10px;" for="<?php echo $this->get_field_id('use_template_custom'); ?>"><input id="<?php echo $this->get_field_id('use_template_custom'); ?>" name="<?php echo $this->get_field_name('use_template'); ?>" type="radio" value="custom" <?php checked( $choice == 'custom' ) ?> /> <?php _e( "Custom", 'yarpp' ); ?></label> 
    94             </p> 
     96            <label style="padding-right: 10px;" for="<?php echo $this->get_field_id('use_template_custom'); ?>"><input id="<?php echo $this->get_field_id('use_template_custom'); ?>" name="<?php echo $this->get_field_name('use_template'); ?>" type="radio" value="custom" <?php checked( $choice == 'custom' ); disabled( !count($templates) ); ?> /> <?php _e( "Custom", 'yarpp' ); ?></label> 
     97        </p> 
    9598 
    96             <p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?> <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($instance['title']); ?>" /></label></p> 
     99        <p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?> <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($instance['title']); ?>" /></label></p> 
    97100 
    98             <p><label for="<?php echo $this->get_field_id('template_file'); ?>"><?php _e("Template file:",'yarpp');?></label> <select name="<?php echo $this->get_field_name('template_file'); ?>" id="<?php echo $this->get_field_id('template_file'); ?>"> 
    99                 <?php foreach ($templates as $template): ?> 
    100                 <option value='<?php echo esc_attr($template['basename']); ?>'<?php selected($template['basename'], $instance['template']);?>><?php echo esc_html($template['name']); ?></option> 
    101                 <?php endforeach; ?> 
    102             </select><p> 
    103             <script type="text/javascript"> 
    104             jQuery(function($) { 
    105                 function ensureTemplateChoice() { 
    106                     var custom = $('#<?php echo $this->get_field_id('use_template_custom'); ?>').prop('checked'); 
    107                     var builtin = $('#<?php echo $this->get_field_id('use_template_builtin'); ?>').prop('checked'); 
    108                     $('#<?php echo $this->get_field_id('title'); ?>').closest('p').toggle(!!builtin); 
    109                     $('#<?php echo $this->get_field_id('template_file'); ?>').closest('p').toggle(!!custom); 
    110                 } 
    111                 $('input[name="<?php echo $this->get_field_name('use_template'); ?>"]').change(ensureTemplateChoice); 
    112                 ensureTemplateChoice(); 
    113             }); 
    114             </script> 
    115     <?php endif; ?> 
     101        <p><label for="<?php echo $this->get_field_id('template_file'); ?>"><?php _e("Template file:",'yarpp');?></label> <select name="<?php echo $this->get_field_name('template_file'); ?>" id="<?php echo $this->get_field_id('template_file'); ?>"> 
     102            <?php foreach ($templates as $template): ?> 
     103            <option value='<?php echo esc_attr($template['basename']); ?>'<?php selected($template['basename'], $instance['template']);?>><?php echo esc_html($template['name']); ?></option> 
     104            <?php endforeach; ?> 
     105        </select><p> 
     106        <script type="text/javascript"> 
     107        jQuery(function($) { 
     108            function ensureTemplateChoice() { 
     109                var custom = $('#<?php echo $this->get_field_id('use_template_custom'); ?>').prop('checked'); 
     110                var builtin = $('#<?php echo $this->get_field_id('use_template_builtin'); ?>').prop('checked'); 
     111                $('#<?php echo $this->get_field_id('title'); ?>').closest('p').toggle(!!builtin); 
     112                $('#<?php echo $this->get_field_id('template_file'); ?>').closest('p').toggle(!!custom); 
     113            } 
     114            $('input[name="<?php echo $this->get_field_name('use_template'); ?>"]').change(ensureTemplateChoice); 
     115            ensureTemplateChoice(); 
     116        }); 
     117        </script> 
    116118 
    117119        <p><input class="checkbox" id="<?php echo $this->get_field_id('promote_yarpp'); ?>" name="<?php echo $this->get_field_name('promote_yarpp'); ?>" type="checkbox" <?php checked($instance['promote_yarpp']) ?> /> <label for="<?php echo $this->get_field_id('promote_yarpp'); ?>"><?php _e("Help promote Yet Another Related Posts Plugin?",'yarpp'); ?></label></p> 
Note: See TracChangeset for help on using the changeset viewer.