PluginProbe
Adminify – White Label, Admin Menu Editor, Login Customizer / 3.2.4.1
Adminify – White Label, Admin Menu Editor, Login Customizer v3.2.4.1
4.3.2 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 All 165 releases
← All changes | Libs/adminify-framework/classes/widget-options.class.php +87 -102 4.2.93.2.4.1 View file →
@@ -1,5 +1,6 @@
1 -<?php if ( ! defined( 'ABSPATH' ) ) { die; } // Cannot access directly.
1 +<?php if ( ! defined( 'ABSPATH' ) ) {
2 + die; } // Cannot access directly.
2 3 /**
3 4 *
4 5 * Widgets Class
5 6 *
@@ -4,135 +5,119 @@
4 5 * Widgets Class
5 6 *
6 7 * @since 1.0.0
7 8 * @version 1.0.0
8 - *
9 9 */
10 10 if ( ! class_exists( 'ADMINIFY_Widget' ) ) {
11 - class ADMINIFY_Widget extends WP_Widget {
11 + class ADMINIFY_Widget extends WP_Widget {
12 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 - );
13 + // constans
14 + public $unique = '';
15 + public $args = [
16 + 'title' => '',
17 + 'classname' => '',
18 + 'description' => '',
19 + 'width' => '',
20 + 'class' => '',
21 + 'fields' => [],
22 + 'defaults' => [],
23 + ];
24 24
25 - public function __construct( $key, $params ) {
25 + public function __construct( $key, $params ) {
26 + $widget_ops = [];
27 + $control_ops = [];
26 28
27 - $widget_ops = array();
28 - $control_ops = array();
29 + $this->unique = $key;
30 + $this->args = apply_filters( "adminify_{$this->unique}_args", wp_parse_args( $params, $this->args ), $this );
29 31
30 - $this->unique = $key;
31 - $this->args = apply_filters( "adminify_{$this->unique}_args", wp_parse_args( $params, $this->args ), $this );
32 + // Set control options
33 + if ( ! empty( $this->args['width'] ) ) {
34 + $control_ops['width'] = esc_attr( $this->args['width'] );
35 + }
32 36
33 - // Set control options
34 - if ( ! empty( $this->args['width'] ) ) {
35 - $control_ops['width'] = esc_attr( $this->args['width'] );
36 - }
37 + // Set widget options
38 + if ( ! empty( $this->args['description'] ) ) {
39 + $widget_ops['description'] = esc_attr( $this->args['description'] );
40 + }
37 41
38 - // Set widget options
39 - if ( ! empty( $this->args['description'] ) ) {
40 - $widget_ops['description'] = esc_attr( $this->args['description'] );
41 - }
42 + if ( ! empty( $this->args['classname'] ) ) {
43 + $widget_ops['classname'] = esc_attr( $this->args['classname'] );
44 + }
42 45
43 - if ( ! empty( $this->args['classname'] ) ) {
44 - $widget_ops['classname'] = esc_attr( $this->args['classname'] );
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 );
46 49
47 - // Set filters
48 - $widget_ops = apply_filters( "adminify_{$this->unique}_widget_ops", $widget_ops, $this );
49 - $control_ops = apply_filters( "adminify_{$this->unique}_control_ops", $control_ops, $this );
50 + parent::__construct( $this->unique, esc_attr( $this->args['title'] ), $widget_ops, $control_ops );
51 + }
50 52
51 - parent::__construct( $this->unique, esc_attr( $this->args['title'] ), $widget_ops, $control_ops );
53 + // Register widget with WordPress
54 + public static function instance( $key, $params = [] ) {
55 + return new self( $key, $params );
56 + }
52 57
53 - }
58 + // Front-end display of widget.
59 + public function widget( $args, $instance ) {
60 + call_user_func( $this->unique, $args, $instance );
61 + }
54 62
55 - // Register widget with WordPress
56 - public static function instance( $key, $params = array() ) {
57 - return new self( $key, $params );
58 - }
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;
59 67
60 - // Front-end display of widget.
61 - public function widget( $args, $instance ) {
62 - call_user_func( $this->unique, $args, $instance );
63 - }
68 + return $default;
69 + }
64 70
65 - // get default value
66 - public function get_default( $field ) {
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;
67 75
68 - $default = ( isset( $field['default'] ) ) ? $field['default'] : '';
69 - $default = ( isset( $this->args['defaults'][$field['id']] ) ) ? $this->args['defaults'][$field['id']] : $default;
76 + return $value;
77 + }
70 78
71 - return $default;
79 + // Back-end widget form.
80 + public function form( $instance ) {
81 + if ( ! empty( $this->args['fields'] ) ) {
82 + $class = ( $this->args['class'] ) ? ' ' . $this->args['class'] : '';
72 83
73 - }
84 + echo '<div class="adminify adminify-widgets adminify-fields' . esc_attr( $class ) . '">';
74 85
75 - // get widget value
76 - public function get_widget_value( $instance, $field ) {
86 + foreach ( $this->args['fields'] as $field ) {
87 + $field_unique = '';
77 88
78 - $default = ( isset( $field['id'] ) ) ? $this->get_default( $field ) : '';
79 - $value = ( isset( $field['id'] ) && isset( $instance[$field['id']] ) ) ? $instance[$field['id']] : $default;
89 + if ( ! empty( $field['id'] ) ) {
90 + $field_unique = 'widget-' . $this->unique . '[' . $this->number . ']';
80 91
81 - return $value;
92 + if ( $field['id'] === 'title' ) {
93 + $field['attributes']['id'] = 'widget-' . $this->unique . '-' . $this->number . '-title';
94 + }
82 95
83 - }
96 + $field['default'] = $this->get_default( $field );
97 + }
84 98
85 - // Back-end widget form.
86 - public function form( $instance ) {
99 + ADMINIFY::field( $field, $this->get_widget_value( $instance, $field ), $field_unique );
100 + }
87 101
88 - if ( ! empty( $this->args['fields'] ) ) {
102 + echo '</div>';
103 + }
104 + }
89 105
90 - $class = ( $this->args['class'] ) ? ' '. $this->args['class'] : '';
106 + // Sanitize widget form values as they are saved.
107 + public function update( $new_instance, $old_instance ) {
91 108
92 - echo '<div class="adminify adminify-widgets adminify-fields'. esc_attr( $class ) .'">';
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 + }
93 115
94 - foreach ( $this->args['fields'] as $field ) {
116 + $new_instance = apply_filters( "adminify_{$this->unique}_save", $new_instance, $this->args, $this );
95 117
96 - $field_unique = '';
118 + do_action( "adminify_{$this->unique}_save_before", $new_instance, $this->args, $this );
97 119
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 - ADMINIFY::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( "adminify_{$this->unique}_save", $new_instance, $this->args, $this );
131 -
132 - do_action( "adminify_{$this->unique}_save_before", $new_instance, $this->args, $this );
133 -
134 - return $new_instance;
135 -
136 - }
137 - }
120 + return $new_instance;
121 + }
122 + }
138 123 }