PluginProbe
Smart Post – Post Grid, Post Carousel, Post Slider Gutenberg Blocks for Blog & News / 2.4.26
Smart Post – Post Grid, Post Carousel, Post Slider Gutenberg Blocks for Blog & News v2.4.26
4.0.8 4.0.7 4.0.6 4.0.5 4.0.4 4.0.3 4.0.2 4.0.1 2.3.5 2.3.6 2.4.0 2.4.1 2.4.10 2.4.11 2.4.12 2.4.13 2.4.14 2.4.15 2.4.16 2.4.17 2.4.18 2.4.19 2.4.2 2.4.20 2.4.21 All 88 releases
post-carousel / admin / views / sp-framework / classes / widgets.class.php

widgets.class.php in Smart Post – Post Grid, Post Carousel, Post Slider Gutenberg Blocks for Blog & News 2.4.26, at admin/views/sp-framework/classes/widgets.class.php

175 lines 4.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * The widget class of the plugin.
4 *
5 * @package Smart_Post_Show
6 * @subpackage Smart_Post_Show/views/sp-framework/classes
7 */
8
9 if ( ! defined( 'ABSPATH' ) ) {
10 die; } // Cannot access directly.
11
12 if ( ! class_exists( 'SP_PC_Widget' ) ) {
13 /**
14 *
15 * Widgets Class
16 *
17 * @since 1.0.0
18 * @version 1.0.0
19 */
20 class SP_PC_Widget extends WP_Widget {
21
22 /**
23 * Unique ID/Name
24 *
25 * @var string
26 */
27 public $unique = '';
28
29 /**
30 * Arguments.
31 *
32 * @var array
33 */
34 public $args = array(
35 'title' => '',
36 'classname' => '',
37 'description' => '',
38 'width' => '',
39 'defaults' => array(),
40 'fields' => array(),
41 'class' => '',
42 );
43
44 /**
45 * Constructor.
46 *
47 * @param string $key the key.
48 * @param array $params The parameters.
49 */
50 public function __construct( $key, $params ) {
51
52 $widget_ops = array();
53 $control_ops = array();
54
55 $this->unique = $key;
56 $this->args = apply_filters( "spf_{$this->unique}_args", wp_parse_args( $params, $this->args ), $this );
57
58 // Set control options.
59 if ( ! empty( $this->args['width'] ) ) {
60 $control_ops['width'] = $this->args['width'];
61 }
62
63 // Set widget options.
64 if ( ! empty( $this->args['description'] ) ) {
65 $widget_ops['description'] = $this->args['description'];
66 }
67
68 if ( ! empty( $this->args['classname'] ) ) {
69 $widget_ops['classname'] = $this->args['classname'];
70 }
71
72 // Set filters.
73 $widget_ops = apply_filters( "spf_{$this->unique}_widget_ops", $widget_ops, $this );
74 $control_ops = apply_filters( "spf_{$this->unique}_control_ops", $control_ops, $this );
75
76 parent::__construct( $this->unique, $this->args['title'], $widget_ops, $control_ops );
77
78 }
79
80 /**
81 * Register widget with WordPress.
82 *
83 * @param string $key The key.
84 * @param array $params The parameters.
85 * @return object
86 */
87 public static function instance( $key, $params = array() ) {
88 return new self( $key, $params );
89 }
90
91 /**
92 * Front-end display of widget.
93 *
94 * @param array $args The arguments.
95 * @param mixed $instance The widget instance.
96 * @return void
97 */
98 public function widget( $args, $instance ) {
99 call_user_func( $this->unique, $args, $instance );
100 }
101
102 /**
103 * Get default value
104 *
105 * @param mixed $field The fields.
106 * @param array $options The options.
107 * @return statement
108 */
109 public function get_default( $field, $options = array() ) {
110
111 $default = ( isset( $this->args['defaults'][ $field['id'] ] ) ) ? $this->args['defaults'][ $field['id'] ] : '';
112 $default = ( isset( $field['default'] ) ) ? $field['default'] : $default;
113 $default = ( isset( $options[ $field['id'] ] ) ) ? $options[ $field['id'] ] : $default;
114
115 return $default;
116
117 }
118
119 /**
120 * Back-end widget form.
121 *
122 * @param array $instance The form instance.
123 * @return void
124 */
125 public function form( $instance ) {
126
127 if ( ! empty( $this->args['fields'] ) ) {
128
129 $class = ( $this->args['class'] ) ? ' ' . $this->args['class'] : '';
130 echo '<div class="spf spf-widgets spf-fields' . esc_attr( $class ) . '">';
131
132 foreach ( $this->args['fields'] as $field ) {
133
134 $field_value = '';
135 $field_unique = '';
136
137 if ( ! empty( $field['id'] ) ) {
138
139 $field_value = $this->get_default( $field, $instance );
140 $field_unique = 'widget-' . $this->unique . '[' . $this->number . ']';
141
142 if ( 'title' === $field['id'] ) {
143 $field['attributes']['id'] = 'widget-' . $this->unique . '-' . $this->number . '-title';
144 }
145 }
146
147 SP_PC::field( $field, $field_value, $field_unique );
148
149 }
150
151 echo '</div>';
152
153 }
154
155 }
156
157 /**
158 * Sanitize widget form values as they are saved
159 *
160 * @param mixed $new_instance The new instance.
161 * @param mixed $old_instance The old instance.
162 * @return statement
163 */
164 public function update( $new_instance, $old_instance ) {
165
166 $new_instance = apply_filters( "spf_{$this->unique}_save", $new_instance, $this->args, $this );
167
168 do_action( "spf_{$this->unique}_save_before", $new_instance, $this->args, $this );
169
170 return $new_instance;
171
172 }
173 }
174 }
175