PluginProbe
Smart Post – Post Grid, Post Carousel, Post Slider Gutenberg Blocks for Blog & News / 2.2.10
Smart Post – Post Grid, Post Carousel, Post Slider Gutenberg Blocks for Blog & News v2.2.10
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.2.10, at admin/views/sp-framework/classes/widgets.class.php

144 lines 3.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php if ( ! defined( 'ABSPATH' ) ) {
2 die; } // Cannot access directly.
3 /**
4 *
5 * Widgets Class
6 *
7 * @since 1.0.0
8 * @version 1.0.0
9 */
10 if ( ! class_exists( 'SP_PC_Widget' ) ) {
11 class SP_PC_Widget extends WP_Widget {
12
13 // constants.
14 public $unique = '';
15 public $args = array(
16 'title' => '',
17 'classname' => '',
18 'description' => '',
19 'width' => '',
20 'defaults' => array(),
21 'fields' => array(),
22 'class' => '',
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( "spf_{$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'] = $this->args['width'];
36 }
37
38 // Set widget options
39 if ( ! empty( $this->args['description'] ) ) {
40 $widget_ops['description'] = $this->args['description'];
41 }
42
43 if ( ! empty( $this->args['classname'] ) ) {
44 $widget_ops['classname'] = $this->args['classname'];
45 }
46
47 // Set filters
48 $widget_ops = apply_filters( "spf_{$this->unique}_widget_ops", $widget_ops, $this );
49 $control_ops = apply_filters( "spf_{$this->unique}_control_ops", $control_ops, $this );
50
51 parent::__construct( $this->unique, $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 /**
61 * Front-end display of widget.
62 *
63 * @param array $args The arguments.
64 * @param mixed $instance The widget instance.
65 * @return void
66 */
67 public function widget( $args, $instance ) {
68 call_user_func( $this->unique, $args, $instance );
69 }
70
71 /**
72 * Get default value
73 *
74 * @param mixed $field The fields.
75 * @param array $options The options.
76 * @return statement
77 */
78 public function get_default( $field, $options = array() ) {
79
80 $default = ( isset( $this->args['defaults'][ $field['id'] ] ) ) ? $this->args['defaults'][ $field['id'] ] : '';
81 $default = ( isset( $field['default'] ) ) ? $field['default'] : $default;
82 $default = ( isset( $options[ $field['id'] ] ) ) ? $options[ $field['id'] ] : $default;
83
84 return $default;
85
86 }
87
88 /**
89 * Back-end widget form.
90 *
91 * @param array $instance The form instance.
92 * @return void
93 */
94 public function form( $instance ) {
95
96 if ( ! empty( $this->args['fields'] ) ) {
97
98 $class = ( $this->args['class'] ) ? ' '. $this->args['class'] : '';
99 echo '<div class="spf spf-widgets spf-fields'. $class .'">';
100
101 foreach ( $this->args['fields'] as $field ) {
102
103 $field_value = '';
104 $field_unique = '';
105
106 if ( ! empty( $field['id'] ) ) {
107
108 $field_value = $this->get_default( $field, $instance );
109 $field_unique = 'widget-' . $this->unique . '[' . $this->number . ']';
110
111 if ( $field['id'] === 'title' ) {
112 $field['attributes']['id'] = 'widget-' . $this->unique . '-' . $this->number . '-title';
113 }
114 }
115
116 SP_PC::field( $field, $field_value, $field_unique );
117
118 }
119
120 echo '</div>';
121
122 }
123
124 }
125
126 /**
127 * Sanitize widget form values as they are saved
128 *
129 * @param mixed $new_instance The new instance.
130 * @param mixed $old_instance The old instance.
131 * @return statement
132 */
133 public function update( $new_instance, $old_instance ) {
134
135 $new_instance = apply_filters( "spf_{$this->unique}_save", $new_instance, $this->args, $this );
136
137 do_action( "spf_{$this->unique}_save_before", $new_instance, $this->args, $this );
138
139 return $new_instance;
140
141 }
142 }
143 }
144