PluginProbe ʕ •ᴥ•ʔ
Widget Options – Advanced Conditional Visibility for Gutenberg Blocks & Classic Widgets / 3.8.1
Widget Options – Advanced Conditional Visibility for Gutenberg Blocks & Classic Widgets v3.8.1
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 / admin / settings / register-settings.php
widget-options / includes / admin / settings Last commit date
modules 4 years ago display-settings.php 4 years ago register-settings.php 4 years ago
register-settings.php
182 lines
1 <?php
2 /**
3 * Register Settings
4 * @since 4.1
5 */
6
7 // Exit if accessed directly
8 if ( !defined( 'ABSPATH' ) ) exit;
9
10 /**
11 * Get an option
12 *
13 * Looks to see if the specified setting exists, returns default if not
14 *
15 * @since 4.1
16 * @global $widget_options Array of all the Widget Options
17 * @return mixed
18 */
19 if( !function_exists( 'widgetopts_get_option' ) ):
20 function widgetopts_get_option( $key = '', $default = false ) {
21 global $widget_options;
22
23 $value = ! empty( $widget_options[ $key ] ) ? $widget_options[ $key ] : $default;
24 $value = apply_filters( 'widgetopts_get_option', $value, $key, $default );
25
26 return apply_filters( 'widgetopts_get_option_' . $key, $value, $key, $default );
27 }
28 endif;
29
30 /**
31 * Update an option
32 *
33 * Updates an widgetopts setting value in both the db and the global variable.
34 * Warning: Passing in an empty, false or null string value will remove
35 * the key from the widget_options array.
36 *
37 * @since 4.1
38 * @param string $key The Key to update
39 * @param string|bool|int $value The value to set the key to
40 * @global $widget_options Array of all the Widget Options
41 * @return boolean True if updated, false if not.
42 */
43 if( !function_exists( 'widgetopts_update_option' ) ):
44 function widgetopts_update_option( $key = '', $value = false ) {
45
46 // If no key, exit
47 if ( empty( $key ) ){
48 return false;
49 }
50
51 if ( empty( $value ) ) {
52 $remove_option = widgetopts_delete_option( $key );
53 return $remove_option;
54 }
55
56 // First let's grab the current settings
57 $options = get_option( 'widgetopts_settings' );
58
59 // Let's let devs alter that value coming in
60 $value = apply_filters( 'widgetopts_update_option', $value, $key );
61
62 // Next let's try to update the value
63 $options[ $key ] = $value;
64
65 $did_update = update_option( 'widgetopts_settings', $options );
66 // If it updated, let's update the global variable
67 if ( $did_update ){
68 global $widget_options;
69 $widget_options[ $key ] = $value;
70 }
71 return $did_update;
72 }
73 endif;
74
75 /**
76 * Remove an option
77 *
78 * Removes widget options setting value in both the db and the global variable.
79 *
80 * @since 4.1
81 * @param string $key The Key to delete
82 * @global $widget_options Array of all the Widget Options
83 * @return boolean True if removed, false if not.
84 */
85 if( !function_exists( 'widgetopts_delete_option' ) ):
86 function widgetopts_delete_option( $key = '' ) {
87 // If no key, exit
88 if ( empty( $key ) ){
89 return false;
90 }
91 // First let's grab the current settings
92 $options = get_option( 'widgetopts_settings' );
93
94 // Next let's try to update the value
95 if( isset( $options[ $key ] ) ) {
96 unset( $options[ $key ] );
97 }
98 $did_update = update_option( 'widgetopts_settings', $options );
99
100 // If it updated, let's update the global variable
101 if ( $did_update ){
102 global $edd_options;
103 $edd_options = $options;
104 }
105 return $did_update;
106 }
107 endif;
108
109 /**
110 * Get Settings
111 *
112 * Retrieves all plugin settings
113 *
114 * @since 4.1
115 * @return array WIDGETOPTS settings
116 */
117 if( !function_exists( 'widgetopts_get_settings' ) ):
118 function widgetopts_get_settings() {
119 if (is_multisite()) {
120 $settings = get_blog_option(get_current_blog_id(), 'widgetopts_settings');
121 } else {
122 $settings = get_option( 'widgetopts_settings' );
123 }
124
125 if( empty( $settings ) ) {
126
127 $opts_settings = get_option( 'widgetopts_tabmodule-settings' );
128 //fallback to prevent error
129 if( is_serialized( $opts_settings ) ){
130 $opts_settings = maybe_unserialize( $opts_settings );
131 }
132
133 // Update old settings with new single option
134 $settings = !empty( $opts_settings ) ? $opts_settings : array();
135 $visibility = array( 'visibility' => get_option( 'widgetopts_tabmodule-visibility' ) );
136 $devices = array( 'devices' => get_option( 'widgetopts_tabmodule-devices' ) );
137 $alignment = array( 'alignment' => get_option( 'widgetopts_tabmodule-alignment' ) );
138 $hide_title = array( 'hide_title' => get_option( 'widgetopts_tabmodule-hide_title' ) );
139 $classes = array( 'classes' => get_option( 'widgetopts_tabmodule-classes' ) );
140 $logic = array( 'logic' => get_option( 'widgetopts_tabmodule-logic' ) );
141 $siteorigin = array( 'siteorigin' => get_option( 'widgetopts_tabmodule-siteorigin' ) );
142 $search = array( 'search' => get_option( 'widgetopts_tabmodule-search' ) );
143 $move = array( 'move' => get_option( 'widgetopts_tabmodule-move' ) );
144 $elementor = array( 'elementor' => get_option( 'widgetopts_tabmodule-elementor' ) );
145 $widget_area = array( 'widget_area' => get_option( 'widgetopts_tabmodule-widget_area' ) );
146 $import_export = array( 'import_export' => get_option( 'widgetopts_tabmodule-import_export' ) );
147 $beaver = array( 'beaver' => get_option( 'widgetopts_tabmodule-beaver' ) );
148 $acf = array( 'acf' => get_option( 'widgetopts_tabmodule-acf' ) );
149 $state = array( 'state' => get_option( 'widgetopts_tabmodule-state' ) );
150 $classic_widgets_screen = array( 'state' => get_option( 'widgetopts_tabmodule-classic_widgets_screen' ) );
151 /*
152 * Available only on Extended version
153 */
154 // $columns = array( 'columns' => get_option( 'widgetopts_tabmodule-columns' ) );
155 // $dates = array( 'dates' => get_option( 'widgetopts_tabmodule-dates' ) );
156 // $styling = array( 'styling' => get_option( 'widgetopts_tabmodule-styling' ) );
157 // $roles = array( 'roles' => get_option( 'widgetopts_tabmodule-roles' ) );
158 // $links = array( 'links' => get_option( 'widgetopts_tabmodule-links' ) );
159 // $fixed = array( 'fixed' => get_option( 'widgetopts_tabmodule-fixed' ) );
160 // $taxonomies = array( 'taxonomies' => get_option( 'widgetopts_tabmodule-taxonomies' ) );
161 // $animation = array( 'animation' => get_option( 'widgetopts_tabmodule-animation' ) );
162 // $shortcodes = array( 'shortcodes' => get_option( 'widgetopts_tabmodule-shortcodes' ) );
163 // $cache = array( 'cache' => get_option( 'widgetopts_tabmodule-cache' ) );
164 // $disable_widgets = array( 'disable_widgets' => get_option( 'widgetopts_tabmodule-disable_widgets' ) );
165 // $permission = array( 'permission' => get_option( 'widgetopts_tabmodule-permission' ) );
166
167 $settings = array_merge( array( 'settings' => $settings ), $visibility, $devices, $alignment, $hide_title, $classes, $logic, $siteorigin, $search, $move, $elementor, $widget_area, $import_export, $beaver, $acf, $state,$classic_widgets_screen );
168
169 // Let's let devs alter that value coming in
170 $value = apply_filters( 'widgetopts_update_settings', $settings );
171
172 update_option( 'widgetopts_settings', $settings );
173 }
174
175 $default = array('settings' => array(), 'visibility' => '', 'devices' => '', 'alignment' => '', 'columns' => '', 'dates' => '', 'styling' => '', 'roles' => '', 'hide_title' => '', 'classes' => '', 'logic' => '', 'links' => '', 'fixed' => '', 'taxonomies' => '', 'animation' => '', 'shortcodes' => '', 'cache' => '', 'siteorigin' => '', 'search' => '', 'disable_widgets' => '', 'permission' => '', 'move' => '', 'clone' => '', 'elementor' => '', 'widget_area' => '', 'import_export' => '', 'urls' => '', 'beaver' => '', 'acf' => '', 'state' => '', 'sliding' => '','classic_widgets_screen'=>'activate');
176 $settings = shortcode_atts($default, $settings);
177
178 return apply_filters( 'widgetopts_get_settings', $settings );
179 }
180 endif;
181 ?>
182