Plugin Directory

Changeset 1348327

Timestamp:
02/11/2016 03:25:45 PM (8 years ago)
Author:
dougal
Message:

Update widget calendar checkbox generation to handle new get_field_name() changes in WP4.4. Also better handling of when 'all' is checked along with other calendars.

Location:
ft-calendar/trunk/classes
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • ft-calendar/trunk/classes/class-calendars.php

    r1307441 r1348327  
    294294                        "            || ( ftc.r_end = 0 || ( ftc.r_end = 1 && ftc.r_end_datetime <= '$end_date' ) ) ) ) ) " .
    295295                        " && posts.post_status = 'publish' ";
    296                    
     296
     297            // If 'all' was checked, we don't care about other options.
     298            $slugs = explode( ',', $calendar );
     299            if ( in_array( 'all', $slugs ) ) {
     300                $calendar = 'all';
     301            }
     302           
    297303            if ( 'all' != $calendar ) {
    298304                $where .= " && ( ";
  • ft-calendar/trunk/classes/class-widgets.php

    r1347833 r1348327  
    115115       
    116116        extract( wp_parse_args( (array) $instance, $defaults ) );
    117    
     117
    118118        $checked_calendars = explode( ',', $calendars );
    119119   
     
    136136                <br />
    137137                <?php /* This is a little tricksy, the get_field_name function gets a really long field name encapsulated with brackets, but this is a form that needs an HTML array... so I trick the fieldname into included an ending []... it's hacky but it works. */ ?>
    138                 <input type="checkbox" value="all" name="<?php echo $this->get_field_name('calendars]['); ?>" id="<?php echo $this->get_field_id( $calendar->slug ); ?>" <?php checked( in_array( 'all', $checked_calendars ) ) ?> class="checkbox" />
    139                 <label for="<?php echo $this->get_field_id( $calendar->slug ); ?>"><?php _e( 'All Calendars', 'ftcalendar' ); ?></label>
     138                <?php /* It's tricksier now, because as of WP 4.4 get_field_name accepts a proper array specifier. */ ?>
     139                <?php $ft_array_spec = version_compare(get_bloginfo('version'), '4.4', '<') ? '][' : '[]'; ?>
     140                <input type="checkbox" value="all" name="<?php echo $this->get_field_name('calendars' . $ft_array_spec); ?>" id="<?php echo $this->get_field_id( 'all' ); ?>" <?php checked( in_array( 'all', $checked_calendars ) ) ?> class="checkbox" />
     141                <label for="<?php echo $this->get_field_id( 'all' ); ?>"><?php _e( 'All Calendars', 'ftcalendar' ); ?></label>
    140142                <?php foreach ( (array)$available_calendars as $key => $calendar ) : ?>
    141143                    <br />
    142                     <input type="checkbox" value="<?php echo $calendar->slug; ?>" name="<?php echo $this->get_field_name('calendars]['); ?>" id="<?php echo $this->get_field_id( $calendar->slug ); ?>" <?php checked( in_array( $calendar->slug, $checked_calendars ) ) ?> class="checkbox" />
     144                    <input type="checkbox" value="<?php echo $calendar->slug; ?>" name="<?php echo $this->get_field_name('calendars); ?>" id="<?php echo $this->get_field_id( $calendar->slug ); ?>" <?php checked( in_array( $calendar->slug, $checked_calendars ) ) ?> class="checkbox" />
    143145                    <label for="<?php echo $this->get_field_id( $calendar->slug ); ?>"><?php echo $calendar->name ?></label>
    144146                <?php endforeach; ?>
     
    321323                <br />
    322324                <?php /* This is a little tricksy, the get_field_name function gets a really long field name encapsulated with brackets, but this is a form that needs an HTML array... so I trick the fieldname into included an ending []... it's hacky but it works. */ ?>
    323                 <input type="checkbox" value="all" name="<?php echo $this->get_field_name('calendars]['); ?>" id="<?php echo $this->get_field_id( $calendar->slug ); ?>" <?php checked( in_array( 'all', $checked_calendars ) ) ?> class="checkbox" />
    324                 <label for="<?php echo $this->get_field_id( $calendar->slug ); ?>"><?php _e( 'All Calendars', 'ftcalendar' ); ?></label>
     325                <?php /* It's tricksier now, because as of WP 4.4 get_field_name accepts a proper array specifier. */ ?>
     326                <?php $ft_array_spec = version_compare(get_bloginfo('version'), '4.4', '<') ? '][' : '[]'; ?>
     327                <input type="checkbox" value="all" name="<?php echo $this->get_field_name('calendars' . $ft_array_spec); ?>" id="<?php echo $this->get_field_id( 'all' ); ?>" <?php checked( in_array( 'all', $checked_calendars ) ) ?> class="checkbox" />
     328                <label for="<?php echo $this->get_field_id( 'all' ); ?>"><?php _e( 'All Calendars', 'ftcalendar' ); ?></label>
    325329                <?php foreach ( (array)$available_calendars as $key => $calendar ) : ?>
    326330                    <br />
    327                     <input type="checkbox" value="<?php echo $calendar->slug; ?>" name="<?php echo $this->get_field_name('calendars]['); ?>" id="<?php echo $this->get_field_id( $calendar->slug ); ?>" <?php checked( in_array( $calendar->slug, $checked_calendars ) ) ?> class="checkbox" />
     331                    <input type="checkbox" value="<?php echo $calendar->slug; ?>" name="<?php echo $this->get_field_name('calendars); ?>" id="<?php echo $this->get_field_id( $calendar->slug ); ?>" <?php checked( in_array( $calendar->slug, $checked_calendars ) ) ?> class="checkbox" />
    328332                    <label for="<?php echo $this->get_field_id( $calendar->slug ); ?>"><?php echo $calendar->name ?></label>
    329333                <?php endforeach; ?>
Note: See TracChangeset for help on using the changeset viewer.