PluginProbe
Adminify – White Label, Admin Menu Editor, Login Customizer / 3.1.7
Adminify – White Label, Admin Menu Editor, Login Customizer v3.1.7
4.3.1 4.3.0 4.2.26 4.2.25 4.2.24 4.2.23 4.2.22 4.2.21 4.2.20 4.2.19 4.2.18 4.2.17 4.2.16 4.2.15 4.2.14 4.2.13 4.2.12 4.2.11 4.2.10 4.2.9 4.2.8 4.2.7 4.2.6 4.2.5 4.1.17 All 164 releases
adminify / Libs / adminify-framework / classes / widget-options.class.php

widget-options.class.php in Adminify – White Label, Admin Menu Editor, Login Customizer 3.1.7, at Libs/adminify-framework/classes/widget-options.class.php

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