function tdd_pb_get_bars($args) { $args = wp_parse_args($args, $defaults = array('ids' => array(), 'width' => 'auto', 'height' => '', 'class' => '', 'default_color' => 'tdd_pb_red')); $tdd_pb_options = get_option('tdd_pb_options'); //Filter the array to ensure we're getting things that look like integers. Will also filter out blank array items $idsarr = array_filter($args['ids'], 'is_numeric'); //count if this is a race (more than one progress bar being displayed. The race format can also be forced by passing "tdd_pb_race" in the $class argument) if (count($idsarr) > 1) { $race = 'tdd_pb_race'; if (!$args['height']) { $args['height'] = $tdd_pb_options['race_height'] . 'px'; } } else { $race = ''; if (!$args['height']) { $args['height'] = $tdd_pb_options['single_height'] . 'px'; } } $race = count($idsarr) > 1 ? 'tdd_pb_race' : ''; //Set up our global container $return = '<div class="tdd_pb_global_container ' . $race . ' ' . sanitize_html_class($args['class']); $return .= '" style="width:' . esc_attr(strip_tags($args['width'])) . '">'; //If there are no ids to display, this is kind of a moot proccess - so let's say so: if (count($idsarr) <= 0) { $return .= '<p>' . __('No progress bars were set, so there is nothing to display', 'tdd_pb') . '</p></div>'; return $return; } //Setup a new WP_Query for our progress bars. $tdd_pb_query = new WP_Query(); $tdd_pb_query->query(array('post_type' => 'tdd_pb', 'posts_per_page' => 100, 'post__in' => $idsarr, 'no_found_rows' => true)); //If there were no posts to display, again, this is moot, so let's say so: if (!$tdd_pb_query->have_posts()) { $return .= '<p>' . __('No progress bars found', 'tdd_pb') . '</p></div>'; return $return; } while ($tdd_pb_query->have_posts()) { $tdd_pb_query->the_post(); $color = get_post_meta(get_the_ID(), '_tdd_pb_color', true); $custom_color = get_post_meta(get_the_ID(), '_tdd_pb_custom_color', true); $percentage = get_post_meta(get_the_ID(), '_tdd_pb_percentage', true); $start = get_post_meta(get_the_ID(), '_tdd_pb_start', true); $end = get_post_meta(get_the_ID(), '_tdd_pb_end', true); $input_method = get_post_meta(get_the_ID(), '_tdd_pb_input_method', true); $percentage_display = get_post_meta(get_the_ID(), '_tdd_pb_percentage_display', true); $xofy_display = get_post_meta(get_the_ID(), '_tdd_pb_xofy_display', true); //Get the calculated percentage if ($input_method == 'xofy' && $end > 0) { $start = floatval($start); $end = floatval($end); $calcpercentage = round($start / $end * 100, 2); } else { $calcpercentage = $percentage; } //This filter allows you to hook in and modify the percentage, perhaps based on a fancy API call... $calcpercentage = apply_filters('tdd_pb_calculated_percentage', $calcpercentage, get_the_ID()); //Fallback to default bar color $color_class = $color ? sanitize_html_class('tdd_pb_' . $color) : $args['default_color']; //Are we displaying text on the bar? Potentially... (there's a global setting that can override this) $text_on_bar = ''; if ($percentage_display == 'on' || $percentage_display === '') { $text_on_bar .= round(floatval($calcpercentage), 2) . '%'; } if ($xofy_display == 'on') { $text_on_bar .= ' ' . intval($start) . ' ' . __('of', 'tdd_pb') . ' ' . intval($end); } $barargs = array('percentage' => $calcpercentage, 'text_on_bar' => $text_on_bar, 'title' => get_the_title(), 'classes' => array(), 'width' => esc_attr($args['width']), 'height' => esc_attr($args['height']), 'color_class' => $color_class, 'custom_color' => tdd_pb_sanitize_color_hex_raw($custom_color)); $return .= tdd_pb_render_bar($barargs); } //Close the progress bar container, and return everything to screen. $return .= '</div>'; return $return; }
function validate($input) { //whitelist checkboxes (add them back in, even if false) $output['display_percentage'] = isset($input['display_percentage']) ? true : false; $output['animate'] = isset($input['animate']) ? true : false; $output['default_css'] = isset($input['default_css']) ? true : false; //Sanitize other options if (!empty($input['bar_background_color'])) { $output['bar_background_color'] = tdd_pb_sanitize_color_hex_raw($input['bar_background_color']); } else { unset($output['bar_background_color']); } if (!empty($input['single_height'])) { $output['single_height'] = absint($input['single_height']); } else { unset($output['single_height']); } if (!empty($input['race_height'])) { $output['race_height'] = absint($input['race_height']); } else { unset($output['race_height']); } if (!empty($input['percentage_color'])) { $output['percentage_color'] = tdd_pb_sanitize_color_hex_raw($input['percentage_color']); } else { unset($output['percentage_color']); } //We now need to set all the array indexes that are blank to their default values. $mergedoutput = $this->get_options($output); return $mergedoutput; }