'', 'text' => '', 'fields' => array(), ); /* Widget setup */ function __construct() { /* Widget settings. */ $widget_ops = array( 'description' => _x( 'Progress bars', 'widget', 'the7mk2' ) ); /* Widget control settings. */ $control_ops = array( 'width' => 260 ); /* Create the widget. */ parent::__construct( 'presscore-progress-bars-widget', DT_WIDGET_PREFIX . _x( 'Progress bars', 'widget', 'the7mk2' ), $widget_ops, $control_ops ); } /* Display the widget */ function widget( $args, $instance ) { extract( $args ); $instance = wp_parse_args( (array) $instance, self::$widget_defaults ); /* Our variables from the widget settings. */ $title = apply_filters( 'widget_title', $instance['title'] ); $text = $instance['text']; $fields = $instance['fields']; /* translators: progress bar percents */ $percent_text = __( '%d%', 'the7mk2' ); echo $before_widget ; // title if ( $title ) { echo $before_title . $title . $after_title; } // content if ( $text ) { echo '
'; } // fields if ( !empty($fields) ) { echo '
'', 'percent' => 100, 'show_percent' => true, 'color' => '' ); unset( $field_defaults['show_percent'] ); foreach ( $fields as &$field ) { $field = array_intersect_key($field, $allowed_fields); $field = wp_parse_args($field, $field_defaults); $field['percent'] = absint($field['percent']); if ( $field['percent'] > 100 ) $field['percent'] = 100; $field['show_percent'] = isset($field['show_percent']); $field['title'] = esc_html($field['title']); $field['color'] = esc_attr($field['color']); } unset($field); return $fields; } public static function presscore_register_widget() { register_widget( get_class() ); add_action( 'admin_footer', array(__CLASS__, 'presscore_admin_add_widget_templates') ); } /** * Add template for widget. */ public static function presscore_admin_add_widget_templates() { if ( 'widgets.php' != $GLOBALS['hook_suffix'] ) { return; } ?>