PluginProbe ʕ •ᴥ•ʔ
Widget Options – Advanced Conditional Visibility for Gutenberg Blocks & Classic Widgets / 3.9.3
Widget Options – Advanced Conditional Visibility for Gutenberg Blocks & Classic Widgets v3.9.3
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 3 years ago pagebuilders 3 years ago widgets 3 years ago ajax-functions.php 8 years ago extras.php 4 years ago install.php 4 years ago scripts.php 3 years ago transient.php 8 years ago
extras.php
187 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 if( empty( $types ) ) {
72 $types = get_post_types( array(
73 'public' => true,
74 ), 'object' );
75 // Let's let devs alter that value coming in
76 $types = apply_filters( 'widgetopts_update_global_types', $types );
77 update_option( 'widgetopts_global_types', $types );
78 }*/
79
80 $types = get_post_types(array('public' => true), 'object');
81 $types = apply_filters('widgetopts_update_global_types', $types);
82
83 return apply_filters( 'widgetopts_get_global_types', $types );
84 }
85
86 function widgetopts_global_pages() {
87 $pages = get_option( 'widgetopts_global_all_pages' );
88
89 //old pages object
90 // if( empty( $pages ) ) {
91 // $pages = get_posts( array(
92 // 'post_type' => 'page',
93 // 'post_status' => 'publish',
94 // 'numberposts' => -1,
95 // 'orderby' => 'title',
96 // 'order' => 'ASC',
97 // 'fields' => array('ID', 'name')
98 // ));
99 //
100 // // Let's let devs alter that value coming in
101 // $pages = apply_filters( 'widgetopts_update_global_pages', $pages );
102 // update_option( 'widgetopts_global_pages', $pages );
103 // }
104
105 //create new pages object
106 if( empty( $pages ) ) {
107 global $wpdb;
108
109 $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 ");
110
111 // Let's let devs alter that value coming in
112 $pages = apply_filters( 'widgetopts_update_global_pages', $pages );
113 update_option( 'widgetopts_global_all_pages', $pages );
114 }
115
116 return apply_filters( 'widgetopts_get_global_pages', $pages );
117 }
118
119 function widgetopts_global_categories(){
120 $categories = get_option( 'widgetopts_global_categories' );
121
122 if( empty( $categories ) ) {
123 $categories = get_categories( array(
124 'hide_empty' => false
125 ) );
126
127 // Let's let devs alter that value coming in
128 $categories = apply_filters( 'widgetopts_update_global_categories', $categories );
129 update_option( 'widgetopts_global_categories', $categories );
130 }
131
132 return apply_filters( 'widgetopts_global_categories', $categories );
133 }
134
135 /*
136 Page Walker Class
137 */
138 if( !class_exists( 'WidgetOpts_Pages_Checkboxes' ) ):
139 class WidgetOpts_Pages_Checkboxes extends Walker_Page {
140
141 function start_lvl( &$output, $depth = 0, $args = array() ) {
142 $output .= "\n<div class='widgetopts-chldrn'>\n";
143 }
144
145 function end_lvl( &$output, $depth = 0, $args = array() ) {
146 $output .= "</div>\n";
147 }
148
149 function start_el( &$output, $page, $depth = 0, $args = array(), $current_page = 0 ) {
150 if ( $depth ){
151 $indent = str_repeat( '&mdash; ', $depth );
152 }else{
153 $indent = '';
154 }
155
156
157
158 if ( '' === $page->post_title ) {
159 $page->post_title = sprintf( __( '#%d (no title)', 'widget-options' ), $page->ID );
160 }
161
162 $pages_values = array();
163 if( isset( $args['params']['visibility']['pages'] ) ){
164 $pages_values = $args['params']['visibility']['pages'];
165 }
166
167 if( isset( $pages_values[ $page->ID ] ) && $pages_values[ $page->ID ] == '1' ){
168 $checked = 'checked="checked"';
169 }else{
170 $checked = '';
171 }
172
173 $output .= '<p>' . $indent;
174
175 $output .= '<input type="checkbox" name="'. $args['namespace'] .'[extended_widget_opts][visibility][pages]['. $page->ID .']" id="'. $args['id'] .'-opts-pages-'. $page->ID .'" value="1" '. $checked .'/>';
176
177 $output .= '<label for="'. $args['id'] .'-opts-pages-'. $page->ID .'">'. $page->post_title .'</label>';
178 }
179
180 function end_el( &$output, $page, $depth = 0, $args = array() ) {
181 $output .= "</p>\n";
182 }
183
184 }
185 endif;
186 ?>
187