PluginProbe
Cool Timeline (Horizontal & Vertical Timeline) / trunk
Cool Timeline (Horizontal & Vertical Timeline) vtrunk
3.4.0 3.3.6 3.3.5 3.3.4 3.3.3 3.3.2 2.2.3 2.3.3 2.4 2.4.1 2.4.2 2.4.3 2.4.4 2.4.5 2.6.1 2.7.1 2.8.3 2.9.3 2.9.4 2.9.5 2.9.6 2.9.7 2.9.8 2.9.9 3.0.0 All 79 releases
cool-timeline / admin / codestar-framework / classes / widget-options.class.php

widget-options.class.php in Cool Timeline (Horizontal & Vertical Timeline) trunk, at admin/codestar-framework/classes/widget-options.class.php

145 lines 4.4 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( 'CSF_Widget' ) ) {
11 // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedClassFound
12 class CSF_Widget extends WP_Widget {
13
14 // constans
15 public $unique = '';
16 public $args = array(
17 'title' => '',
18 'classname' => '',
19 'description' => '',
20 'width' => '',
21 'class' => '',
22 'fields' => array(),
23 'defaults' => array(),
24 );
25
26 public function __construct( $key, $params ) {
27
28 $widget_ops = array();
29 $control_ops = array();
30
31 $this->unique = $key;
32 // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound
33 $this->args = apply_filters( "csf_{$this->unique}_args", wp_parse_args( $params, $this->args ), $this );
34
35 // Set control options
36 if ( ! empty( $this->args['width'] ) ) {
37 $control_ops['width'] = esc_attr( $this->args['width'] );
38 }
39
40 // Set widget options
41 if ( ! empty( $this->args['description'] ) ) {
42 $widget_ops['description'] = esc_attr( $this->args['description'] );
43 }
44
45 if ( ! empty( $this->args['classname'] ) ) {
46 $widget_ops['classname'] = esc_attr( $this->args['classname'] );
47 }
48
49 // Set filters
50 // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound
51 $widget_ops = apply_filters( "csf_{$this->unique}_widget_ops", $widget_ops, $this );
52 // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound
53 $control_ops = apply_filters( "csf_{$this->unique}_control_ops", $control_ops, $this );
54
55 parent::__construct( $this->unique, esc_attr( $this->args['title'] ), $widget_ops, $control_ops );
56
57 }
58
59 // Register widget with WordPress
60 public static function instance( $key, $params = array() ) {
61 return new self( $key, $params );
62 }
63
64 // Front-end display of widget.
65 public function widget( $args, $instance ) {
66 call_user_func( $this->unique, $args, $instance );
67 }
68
69 // get default value
70 public function get_default( $field ) {
71
72 $default = ( isset( $field['default'] ) ) ? $field['default'] : '';
73 $default = ( isset( $this->args['defaults'][$field['id']] ) ) ? $this->args['defaults'][$field['id']] : $default;
74
75 return $default;
76
77 }
78
79 // get widget value
80 public function get_widget_value( $instance, $field ) {
81
82 $default = ( isset( $field['id'] ) ) ? $this->get_default( $field ) : '';
83 $value = ( isset( $field['id'] ) && isset( $instance[$field['id']] ) ) ? $instance[$field['id']] : $default;
84
85 return $value;
86
87 }
88
89 // Back-end widget form.
90 public function form( $instance ) {
91
92 if ( ! empty( $this->args['fields'] ) ) {
93
94 $class = ( $this->args['class'] ) ? ' '. $this->args['class'] : '';
95
96 echo '<div class="csf csf-widgets csf-fields'. esc_attr( $class ) .'">';
97
98 foreach ( $this->args['fields'] as $field ) {
99
100 $field_unique = '';
101
102 if ( ! empty( $field['id'] ) ) {
103
104 $field_unique = 'widget-' . $this->unique . '[' . $this->number . ']';
105
106 if ( $field['id'] === 'title' ) {
107 $field['attributes']['id'] = 'widget-'. $this->unique .'-'. $this->number .'-title';
108 }
109
110 $field['default'] = $this->get_default( $field );
111
112 }
113
114 CSF::field( $field, $this->get_widget_value( $instance, $field ), $field_unique );
115
116 }
117
118 echo '</div>';
119
120 }
121
122 }
123
124 // Sanitize widget form values as they are saved.
125 public function update( $new_instance, $old_instance ) {
126
127 // auto sanitize
128 foreach ( $this->args['fields'] as $field ) {
129 if ( ! empty( $field['id'] ) && ( ! isset( $new_instance[$field['id']] ) || is_null( $new_instance[$field['id']] ) ) ) {
130 $new_instance[$field['id']] = '';
131 }
132 }
133
134 // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound
135 $new_instance = apply_filters( "csf_{$this->unique}_save", $new_instance, $this->args, $this );
136
137 // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound
138 do_action( "csf_{$this->unique}_save_before", $new_instance, $this->args, $this );
139
140 return $new_instance;
141
142 }
143 }
144 }
145