'', 'fields' => array(), ); /* Widget setup */ function __construct() { /* Widget settings. */ $widget_ops = array( 'description' => _x( 'Accordion', 'widget', 'the7mk2' ) ); /* Widget control settings. */ $control_ops = array( 'width' => 226 ); /* Create the widget. */ parent::__construct( 'presscore-accordion-widget', DT_WIDGET_PREFIX . _x( 'Accordion', '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'] ); $fields = $instance['fields']; echo $before_widget ; // title if ( $title ) { echo $before_title . $title . $after_title; } // fields if ( !empty($fields) ) { echo '
'; } echo $after_widget; } /* Update the widget settings */ function update( $new_instance, $old_instance ) { $instance = $old_instance; $instance['title'] = strip_tags($new_instance['title']); $instance['fields'] = $this->presscore_validate_fields( $new_instance['fields'] ); return $instance; } /** * Displays the widget settings controls on the widget panel. * Make use of the get_field_id() and get_field_name() function * when creating your form elements. This handles the confusing stuff. */ function form( $instance ) { /* Set up some default widget settings. */ $instance = wp_parse_args( (array) $instance, self::$widget_defaults ); $fields = empty( $instance['fields'] ) ? array() : $instance['fields']; ?>

'', 'content' => '', ); foreach ( $fields as &$field ) { $field = array_intersect_key( $field, $allowed_fields ); $field = wp_parse_args( $field, $field_defaults ); $field['title'] = esc_html( $field['title'] ); $field['content'] = wp_kses_post( $field['content'] ); } unset($field); return $fields; } public static function presscore_render_accordion_item( $item ) { if ( empty( $item ) ) { return ''; } $html = sprintf( '%1$s
%2$s
', $item['title'], wpautop( do_shortcode($item['content']) ) ); return $html; } 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; } ?>