PluginProbe ʕ •ᴥ•ʔ
Widget Options – Advanced Conditional Visibility for Gutenberg Blocks & Classic Widgets / 3.8
Widget Options – Advanced Conditional Visibility for Gutenberg Blocks & Classic Widgets v3.8
4.2.5 4.2.4 trunk 3.7.10 3.7.11 3.7.12 3.7.13 3.7.14 3.7.2 3.7.5 3.7.6 3.7.7 3.7.8 3.7.9 3.8 3.8.1 3.8.10 3.8.2 3.8.3 3.8.4 3.8.5 3.8.6 3.8.7 3.8.8 3.8.9 3.8.9.1 3.9.0 3.9.1 3.9.2 3.9.3 3.9.4 3.9.5 3.9.6 4.0.0 4.0.1 4.0.2 4.0.3 4.0.4 4.0.5 4.0.5.1 4.0.6 4.0.6.1 4.0.7 4.0.8 4.0.9 4.1.0 4.1.1 4.1.2 4.1.3 4.2.0 4.2.1 4.2.2 4.2.3
widget-options / includes / widgets / extras.php
widget-options / includes / widgets Last commit date
option-tabs 4 years ago display.php 4 years ago extras.php 4 years ago widgets.php 7 years ago
extras.php
172 lines
1 <?php
2 /**
3 * Extra Functions
4 *
5 * Collections of extra functions to avoid repeatition
6 *
7 * @copyright Copyright (c) 2016, Jeffrey Carandang
8 * @since 4.0
9 */
10
11 //create separate function returning classes for reuse
12 if( !function_exists( 'widgetopts_classes_generator' ) ){
13 function widgetopts_classes_generator( $opts, $tabs, $settings, $so = false ){
14 if( !empty( $opts ) && is_array( $opts ) ){
15 $classes = array();
16 $devices = isset( $opts['devices'] ) ? $opts['devices'] : '';
17 $alignment = isset( $opts['alignment'] ) ? $opts['alignment'] : '';
18 $columns = isset( $opts['column'] ) ? $opts['column'] : '';
19 $clearfix = isset( $opts['clearfix'] ) ? $opts['clearfix'] : '';
20 $custom_class = isset( $opts['class'] ) ? $opts['class'] : '';
21 $abbr = array(
22 'mobile' => 'xs',
23 'tablet' => 'sm',
24 'desktop' => 'md',
25 );
26 if( isset( $devices['options'] ) ){
27 unset( $devices['options'] );
28 }
29
30 if( 'activate' == $tabs['devices'] ){
31 //devices visibility
32 if( !empty( $devices ) ){
33 $device_opts = ( isset( $opts['devices']['options'] ) ) ? $opts['devices']['options'] : 'hide';
34 $classes[] = 'extendedwopts-' . $device_opts ;
35
36 foreach ($devices as $key => $value) {
37 $classes[] = 'extendedwopts-' . $key;
38 }
39 }
40 }
41
42 if( 'activate' == $tabs['alignment'] ){
43 //alignment
44 if( !empty( $alignment ) ){
45 foreach ($alignment as $k => $v) {
46 if( 'default' != $v ){
47 $classes[] = 'extendedwopts-' . $abbr[ $k ] . '-'. $v ;
48 }
49 }
50 }
51 }
52
53 if( 'activate' == $tabs['classes'] && isset( $settings['classes'] ) ){
54 //classes & ID
55 // $options = get_option('extwopts_class_settings');
56 $predefined = array();
57 if( isset( $settings['classes'] ) && isset( $settings['classes']['classlists'] ) && !empty( $settings['classes']['classlists'] ) ){
58 $predefined = $settings['classes']['classlists'];
59 }
60
61 //don't add any classes when settings is set to predefined or hide
62 if( !isset( $settings['classes']['type'] ) ||
63 ( isset( $settings['classes']['type'] ) && !in_array( $settings['classes']['type'] , array( 'hide', 'predefined' ) ) ) ){
64 if( is_array( $custom_class ) && isset( $custom_class['classes'] ) && !empty( $custom_class['classes'] ) ){
65 $classes[] = $custom_class['classes'];
66 }
67 }
68
69 //don't add any classes when settings is set to text or hide
70 if( !isset( $settings['classes']['type'] ) ||
71 ( isset( $settings['classes']['type'] ) && !in_array( $settings['classes']['type'] , array( 'hide', 'text' ) ) ) ){
72 if( is_array( $predefined ) && !empty( $predefined ) ){
73 $predefined = array_unique( $predefined );
74 if( isset( $custom_class['predefined'] ) && is_array( $custom_class['predefined'] ) ){
75 $filtered = array_intersect( $predefined, $custom_class['predefined'] );
76 if( !empty( $filtered ) ){
77 $classes = array_merge( $classes, $filtered );
78 // $classes[] = implode( ' ', $filtered );
79 // $classes[] = ' ';
80 }
81 }
82 }
83 }
84 }
85
86 if( $so && 'activate' == $tabs['hide_title'] ){
87 //add fixed class to widget
88 if( isset( $custom_class['title'] ) && !empty( $custom_class['title'] ) ){
89 $classes[] = 'widgetopts-hide_title';
90 }
91 }
92
93 return apply_filters( 'widgetopts_get_classes', $classes );
94 }
95 }
96 }
97
98 //add is_active_sidebar support
99 if( !function_exists( 'widgetopts_sidebars_widgets' ) ){
100 add_action( 'wp_loaded', 'widgetopts_sidebars_widgets_action' );
101 function widgetopts_sidebars_widgets_action() {
102 if( apply_filters( 'widgetopts_is_active_sidebar_support', true ) ){
103 add_filter( 'sidebars_widgets', 'widgetopts_sidebars_widgets' );
104 }
105 }
106 function widgetopts_sidebars_widgets( $sidebars ) {
107 if ( is_admin() ) {
108 return $sidebars;
109 }
110
111 global $wp_registered_widgets;
112 $checked = array();
113
114 foreach ( $sidebars as $s => $sidebar ) {
115 if ( $s == 'wp_inactive_widgets' || strpos( $s, 'orphaned_widgets' ) === 0 || empty( $sidebar ) ) {
116 continue;
117 }
118
119 foreach ( $sidebar as $w => $widget ) {
120 // $widget is the id of the widget
121 if ( ! isset( $wp_registered_widgets[ $widget ] ) ) {
122 continue;
123 }
124
125 if ( isset( $checked[ $widget ] ) ) {
126 $show = $checked[ $widget ];
127 } else {
128 $opts = $wp_registered_widgets[ $widget ];
129 $id_base = is_array( $opts['callback'] ) || $opts['callback'] instanceof ArrayAccess ? $opts['callback'][0]->id_base : $opts['callback'];
130
131 if ( ! is_string( $id_base ) ) {
132 continue;
133 }
134
135 $instance = get_option( 'widget_' . $id_base );
136
137 if ( ! $instance || ! is_array( $instance ) ) {
138 continue;
139 }
140
141 if ( isset( $instance['_multiwidget'] ) && $instance['_multiwidget'] ) {
142 $number = $opts['params'][0]['number'];
143 if ( ! isset( $instance[ $number ] ) ) {
144 continue;
145 }
146
147 $instance = $instance[ $number ];
148 unset( $number );
149 }
150
151 unset( $opts );
152
153 $show = widgetopts_display_callback( $instance, (object) array( 'id' => $widget ), '' );
154
155 $checked[ $widget ] = $show ? true : false;
156 }
157
158 if ( ! $show ) {
159 unset( $sidebars[ $s ][ $w ] );
160 }
161
162 unset( $widget );
163 }
164 unset( $sidebar );
165 }
166
167 return $sidebars;
168 }
169 }
170
171 ?>
172