PluginProbe
StreamCast – bring live radio to your site with a sleek player / trunk
StreamCast – bring live radio to your site with a sleek player vtrunk
2.4.5 2.4.4 trunk 1.0 1.1 2.0.0 2.1.10 2.1.2 2.1.4 2.1.5 2.1.8 2.2.1 2.2.3 2.2.4 2.2.5 2.3.0 2.3.1 2.3.2 2.3.3 2.3.4 2.3.5 2.3.6 2.3.7 2.3.8 2.3.9 All 29 releases
streamcast / vendor / codestar-framework / classes / widget-options.class.php

widget-options.class.php in StreamCast – bring live radio to your site with a sleek player trunk, at vendor/codestar-framework/classes/widget-options.class.php

139 lines 4.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php if ( ! defined( 'ABSPATH' ) ) { die; } // Cannot access directly.
2 /**
3 *
4 * Widgets Class
5 *
6 * @since 1.0.0
7 * @version 1.0.0
8 *
9 */
10 if ( ! class_exists( 'STREAMCAST_STREAMCAST_CSF_Widget' ) ) {
11 class STREAMCAST_STREAMCAST_CSF_Widget extends WP_Widget {
12
13 // constans
14 public $unique = '';
15 public $args = array(
16 'title' => '',
17 'classname' => '',
18 'description' => '',
19 'width' => '',
20 'class' => '',
21 'fields' => array(),
22 'defaults' => array(),
23 );
24
25 public function __construct( $key, $params ) {
26
27 $widget_ops = array();
28 $control_ops = array();
29
30 $this->unique = $key;
31 $this->args = apply_filters( "streamcast_csf_{$this->unique}_args", wp_parse_args( $params, $this->args ), $this );
32
33 // Set control options
34 if ( ! empty( $this->args['width'] ) ) {
35 $control_ops['width'] = esc_attr( $this->args['width'] );
36 }
37
38 // Set widget options
39 if ( ! empty( $this->args['description'] ) ) {
40 $widget_ops['description'] = esc_attr( $this->args['description'] );
41 }
42
43 if ( ! empty( $this->args['classname'] ) ) {
44 $widget_ops['classname'] = esc_attr( $this->args['classname'] );
45 }
46
47 // Set filters
48 $widget_ops = apply_filters( "streamcast_csf_{$this->unique}_widget_ops", $widget_ops, $this );
49 $control_ops = apply_filters( "streamcast_csf_{$this->unique}_control_ops", $control_ops, $this );
50
51 parent::__construct( $this->unique, esc_attr( $this->args['title'] ), $widget_ops, $control_ops );
52
53 }
54
55 // Register widget with WordPress
56 public static function instance( $key, $params = array() ) {
57 return new self( $key, $params );
58 }
59
60 // Front-end display of widget.
61 public function widget( $args, $instance ) {
62 call_user_func( $this->unique, $args, $instance );
63 }
64
65 // get default value
66 public function get_default( $field ) {
67
68 $default = ( isset( $field['default'] ) ) ? $field['default'] : '';
69 $default = ( isset( $this->args['defaults'][$field['id']] ) ) ? $this->args['defaults'][$field['id']] : $default;
70
71 return $default;
72
73 }
74
75 // get widget value
76 public function get_widget_value( $instance, $field ) {
77
78 $default = ( isset( $field['id'] ) ) ? $this->get_default( $field ) : '';
79 $value = ( isset( $field['id'] ) && isset( $instance[$field['id']] ) ) ? $instance[$field['id']] : $default;
80
81 return $value;
82
83 }
84
85 // Back-end widget form.
86 public function form( $instance ) {
87
88 if ( ! empty( $this->args['fields'] ) ) {
89
90 $class = ( $this->args['class'] ) ? ' '. $this->args['class'] : '';
91
92 echo '<div class="streamcast-csf streamcast-csf-widgets streamcast-csf-fields'. esc_attr( $class ) .'">';
93
94 foreach ( $this->args['fields'] as $field ) {
95
96 $field_unique = '';
97
98 if ( ! empty( $field['id'] ) ) {
99
100 $field_unique = 'widget-' . $this->unique . '[' . $this->number . ']';
101
102 if ( $field['id'] === 'title' ) {
103 $field['attributes']['id'] = 'widget-'. $this->unique .'-'. $this->number .'-title';
104 }
105
106 $field['default'] = $this->get_default( $field );
107
108 }
109
110 STREAMCAST_STREAMCAST_CSF::field( $field, $this->get_widget_value( $instance, $field ), $field_unique );
111
112 }
113
114 echo '</div>';
115
116 }
117
118 }
119
120 // Sanitize widget form values as they are saved.
121 public function update( $new_instance, $old_instance ) {
122
123 // auto sanitize
124 foreach ( $this->args['fields'] as $field ) {
125 if ( ! empty( $field['id'] ) && ( ! isset( $new_instance[$field['id']] ) || is_null( $new_instance[$field['id']] ) ) ) {
126 $new_instance[$field['id']] = '';
127 }
128 }
129
130 $new_instance = apply_filters( "streamcast_csf_{$this->unique}_save", $new_instance, $this->args, $this );
131
132 do_action( "streamcast_csf_{$this->unique}_save_before", $new_instance, $this->args, $this );
133
134 return $new_instance;
135
136 }
137 }
138 }
139