PluginProbe ʕ •ᴥ•ʔ
Widget Options – Advanced Conditional Visibility for Gutenberg Blocks & Classic Widgets / 3.7.7
Widget Options – Advanced Conditional Visibility for Gutenberg Blocks & Classic Widgets v3.7.7
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 / extras.php
widget-options / includes Last commit date
admin 5 years ago pagebuilders 4 years ago widgets 5 years ago ajax-functions.php 5 years ago extras.php 5 years ago install.php 5 years ago scripts.php 5 years ago transient.php 5 years ago
extras.php
188 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 function widgetopts_sanitize_array( &$array ) {
12 foreach ($array as &$value) {
13 if( !is_array($value) ) {
14 // sanitize if value is not an array
15 $value = sanitize_text_field( $value );
16 }else{
17 // go inside this function again
18 widgetopts_sanitize_array($value);
19 }
20 }
21
22 return $array;
23 }
24
25 function widgetopts_is_checked( $array, $key ){
26 return ( isset( $array[$key] ) && '1' == $array[$key] ) ? 'checked="checked"' : '';
27 }
28
29 /*
30 * Check if http or https available on link
31 */
32 function widgetopts_addhttp($url) {
33 if (!preg_match("~^(?:f|ht)tps?://~i", $url)) {
34 $url = "http://" . $url;
35 }
36 return $url;
37 }
38
39
40 /**
41 * Register Global Variables for easier access
42 *
43 *
44 * @since 5.0
45 * @return array
46 */
47 function widgetopts_global_taxonomies() {
48 $taxonomies = get_option( 'widgetopts_global_taxonomies' );
49
50 if( empty( $taxonomies ) ) {
51
52 $tax_args = array(
53 'public' => true
54 );
55 $tax_output = 'objects'; // or objects
56 $tax_operator = 'and'; // 'and' or 'or'
57 $taxonomies = get_taxonomies( $tax_args, $tax_output, $tax_operator );
58 unset( $taxonomies['post_format'] );
59
60 // Let's let devs alter that value coming in
61 $taxonomies = apply_filters( 'widgetopts_update_global_taxonomies', $taxonomies );
62 update_option( 'widgetopts_global_taxonomies', $taxonomies );
63
64 }
65
66 return apply_filters( 'widgetopts_get_global_taxonomies', $taxonomies );
67 }
68
69 function widgetopts_global_types() {
70 $types = get_option( 'widgetopts_global_types' );
71
72 if( empty( $types ) ) {
73
74 $types = get_post_types( array(
75 'public' => true,
76 ), 'object' );
77
78 // Let's let devs alter that value coming in
79 $types = apply_filters( 'widgetopts_update_global_types', $types );
80 update_option( 'widgetopts_global_types', $types );
81
82 }
83
84 return apply_filters( 'widgetopts_get_global_types', $types );
85 }
86
87 function widgetopts_global_pages() {
88 $pages = get_option( 'widgetopts_global_all_pages' );
89
90 //old pages object
91 // if( empty( $pages ) ) {
92 // $pages = get_posts( array(
93 // 'post_type' => 'page',
94 // 'post_status' => 'publish',
95 // 'numberposts' => -1,
96 // 'orderby' => 'title',
97 // 'order' => 'ASC',
98 // 'fields' => array('ID', 'name')
99 // ));
100 //
101 // // Let's let devs alter that value coming in
102 // $pages = apply_filters( 'widgetopts_update_global_pages', $pages );
103 // update_option( 'widgetopts_global_pages', $pages );
104 // }
105
106 //create new pages object
107 if( empty( $pages ) ) {
108 global $wpdb;
109
110 $pages = $wpdb->get_results("SELECT ID, post_title, post_parent FROM $wpdb->posts WHERE post_type = 'page' AND post_status = 'publish' ORDER BY post_title ASC ");
111
112 // Let's let devs alter that value coming in
113 $pages = apply_filters( 'widgetopts_update_global_pages', $pages );
114 update_option( 'widgetopts_global_all_pages', $pages );
115 }
116
117 return apply_filters( 'widgetopts_get_global_pages', $pages );
118 }
119
120 function widgetopts_global_categories(){
121 $categories = get_option( 'widgetopts_global_categories' );
122
123 if( empty( $categories ) ) {
124 $categories = get_categories( array(
125 'hide_empty' => false
126 ) );
127
128 // Let's let devs alter that value coming in
129 $categories = apply_filters( 'widgetopts_update_global_categories', $categories );
130 update_option( 'widgetopts_global_categories', $categories );
131 }
132
133 return apply_filters( 'widgetopts_global_categories', $categories );
134 }
135
136 /*
137 Page Walker Class
138 */
139 if( !class_exists( 'WidgetOpts_Pages_Checkboxes' ) ):
140 class WidgetOpts_Pages_Checkboxes extends Walker_Page {
141
142 function start_lvl( &$output, $depth = 0, $args = array() ) {
143 $output .= "\n<div class='widgetopts-chldrn'>\n";
144 }
145
146 function end_lvl( &$output, $depth = 0, $args = array() ) {
147 $output .= "</div>\n";
148 }
149
150 function start_el( &$output, $page, $depth = 0, $args = array(), $current_page = 0 ) {
151 if ( $depth ){
152 $indent = str_repeat( '&mdash; ', $depth );
153 }else{
154 $indent = '';
155 }
156
157
158
159 if ( '' === $page->post_title ) {
160 $page->post_title = sprintf( __( '#%d (no title)', 'widget-options' ), $page->ID );
161 }
162
163 $pages_values = array();
164 if( isset( $args['params']['visibility']['pages'] ) ){
165 $pages_values = $args['params']['visibility']['pages'];
166 }
167
168 if( isset( $pages_values[ $page->ID ] ) && $pages_values[ $page->ID ] == '1' ){
169 $checked = 'checked="checked"';
170 }else{
171 $checked = '';
172 }
173
174 $output .= '<p>' . $indent;
175
176 $output .= '<input type="checkbox" name="'. $args['namespace'] .'[extended_widget_opts][visibility][pages]['. $page->ID .']" id="'. $args['id'] .'-opts-pages-'. $page->ID .'" value="1" '. $checked .'/>';
177
178 $output .= '<label for="'. $args['id'] .'-opts-pages-'. $page->ID .'">'. $page->post_title .'</label>';
179 }
180
181 function end_el( &$output, $page, $depth = 0, $args = array() ) {
182 $output .= "</p>\n";
183 }
184
185 }
186 endif;
187 ?>
188